[Bleeding] Cleaned up unsafe casts. Addresses BUKKIT-844

Removed internal collection leaks from PluginDescriptionFile
BREAKING: PluginDescriptionFile.getAuthors() now returns List instead of
ArrayList

Various places with unsafe generics, notably List<Object> getList() in
Configurations are now referenced as <?>. This is nonbreaking, but
sourcecode will need to be revised when compiled.

By: Wesley Wolfe <weswolf@aol.com>
This commit is contained in:
Bukkit/Spigot
2012-02-29 08:32:25 -06:00
parent e7c9a43100
commit 5906da7948
14 changed files with 174 additions and 183 deletions

View File

@@ -9,58 +9,54 @@ import org.bukkit.plugin.Plugin;
public class PluginCommandYamlParser {
@SuppressWarnings("unchecked")
public static List<Command> parse(Plugin plugin) {
List<Command> pluginCmds = new ArrayList<Command>();
Object object = plugin.getDescription().getCommands();
if (object == null) {
Map<String, Map<String, Object>> map = plugin.getDescription().getCommands();
if (map == null) {
return pluginCmds;
}
Map<String, Map<String, Object>> map = (Map<String, Map<String, Object>>) object;
for (Entry<String, Map<String, Object>> entry : map.entrySet()) {
Command newCmd = new PluginCommand(entry.getKey(), plugin);
Object description = entry.getValue().get("description");
Object usage = entry.getValue().get("usage");
Object aliases = entry.getValue().get("aliases");
Object permission = entry.getValue().get("permission");
Object permissionMessage = entry.getValue().get("permission-message");
if (map != null) {
for (Entry<String, Map<String, Object>> entry : map.entrySet()) {
Command newCmd = new PluginCommand(entry.getKey(), plugin);
Object description = entry.getValue().get("description");
Object usage = entry.getValue().get("usage");
Object aliases = entry.getValue().get("aliases");
Object permission = entry.getValue().get("permission");
Object permissionMessage = entry.getValue().get("permission-message");
if (description != null) {
newCmd.setDescription(description.toString());
}
if (usage != null) {
newCmd.setUsage(usage.toString());
}
if (aliases != null) {
List<String> aliasList = new ArrayList<String>();
if (aliases instanceof List) {
for (Object o : (List<Object>) aliases) {
aliasList.add(o.toString());
}
} else {
aliasList.add(aliases.toString());
}
newCmd.setAliases(aliasList);
}
if (permission != null) {
newCmd.setPermission(permission.toString());
}
if (permissionMessage != null) {
newCmd.setPermissionMessage(permissionMessage.toString());
}
pluginCmds.add(newCmd);
if (description != null) {
newCmd.setDescription(description.toString());
}
if (usage != null) {
newCmd.setUsage(usage.toString());
}
if (aliases != null) {
List<String> aliasList = new ArrayList<String>();
if (aliases instanceof List) {
for (Object o : (List<?>) aliases) {
aliasList.add(o.toString());
}
} else {
aliasList.add(aliases.toString());
}
newCmd.setAliases(aliasList);
}
if (permission != null) {
newCmd.setPermission(permission.toString());
}
if (permissionMessage != null) {
newCmd.setPermissionMessage(permissionMessage.toString());
}
pluginCmds.add(newCmd);
}
return pluginCmds;
}

View File

@@ -1,7 +1,8 @@
package org.bukkit.command.defaults;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
@@ -67,7 +68,7 @@ public class VersionCommand extends Command {
private String getAuthors(final PluginDescriptionFile desc) {
StringBuilder result = new StringBuilder();
ArrayList<String> authors = desc.getAuthors();
List<String> authors = desc.getAuthors();
for (int i = 0; i < authors.size(); i++) {
if (result.length() > 0) {