13
0
geforkt von Mirrors/Paper

Some minor improvements from static analysis

By: md_5 <git@md-5.net>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2017-11-07 17:28:28 +11:00
Ursprung 2a82e16c61
Commit 417599c2ab
15 geänderte Dateien mit 44 neuen und 56 gelöschten Zeilen

Datei anzeigen

@ -356,9 +356,6 @@ public final class FireworkEffect implements ConfigurationSerializable {
*/ */
public static ConfigurationSerializable deserialize(Map<String, Object> map) { public static ConfigurationSerializable deserialize(Map<String, Object> map) {
Type type = Type.valueOf((String) map.get(TYPE)); Type type = Type.valueOf((String) map.get(TYPE));
if (type == null) {
throw new IllegalArgumentException(map.get(TYPE) + " is not a valid Type");
}
return builder() return builder()
.flicker((Boolean) map.get(FLICKER)) .flicker((Boolean) map.get(FLICKER))

Datei anzeigen

@ -1,13 +1,8 @@
package org.bukkit.command; package org.bukkit.command;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.logging.Level;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.server.RemoteServerCommandEvent;
import org.bukkit.event.server.ServerCommandEvent;
public class FormattedCommandAlias extends Command { public class FormattedCommandAlias extends Command {
private final String[] formatStrings; private final String[] formatStrings;
@ -42,13 +37,13 @@ public class FormattedCommandAlias extends Command {
} }
private String buildCommand(String formatString, String[] args) { private String buildCommand(String formatString, String[] args) {
int index = formatString.indexOf("$"); int index = formatString.indexOf('$');
while (index != -1) { while (index != -1) {
int start = index; int start = index;
if (index > 0 && formatString.charAt(start - 1) == '\\') { if (index > 0 && formatString.charAt(start - 1) == '\\') {
formatString = formatString.substring(0, start - 1) + formatString.substring(start); formatString = formatString.substring(0, start - 1) + formatString.substring(start);
index = formatString.indexOf("$", index); index = formatString.indexOf('$', index);
continue; continue;
} }
@ -72,7 +67,7 @@ public class FormattedCommandAlias extends Command {
throw new IllegalArgumentException("Invalid replacement token"); throw new IllegalArgumentException("Invalid replacement token");
} }
int position = Integer.valueOf(formatString.substring(argStart, index)); int position = Integer.parseInt(formatString.substring(argStart, index));
// Arguments are not 0 indexed // Arguments are not 0 indexed
if (position == 0) { if (position == 0) {
@ -112,7 +107,7 @@ public class FormattedCommandAlias extends Command {
index = start + replacement.length(); index = start + replacement.length();
// Move to the next replacement token // Move to the next replacement token
index = formatString.indexOf("$", index); index = formatString.indexOf('$', index);
} }
return formatString; return formatString;

Datei anzeigen

@ -225,13 +225,14 @@ public class SimpleCommandMap implements CommandMap {
public void registerServerAliases() { public void registerServerAliases() {
Map<String, String[]> values = server.getCommandAliases(); Map<String, String[]> values = server.getCommandAliases();
for (String alias : values.keySet()) { for (Map.Entry<String, String[]> entry : values.entrySet()) {
String alias = entry.getKey();
if (alias.contains(" ")) { if (alias.contains(" ")) {
server.getLogger().warning("Could not register alias " + alias + " because it contains illegal characters"); server.getLogger().warning("Could not register alias " + alias + " because it contains illegal characters");
continue; continue;
} }
String[] commandStrings = values.get(alias); String[] commandStrings = entry.getValue();
List<String> targets = new ArrayList<String>(); List<String> targets = new ArrayList<String>();
StringBuilder bad = new StringBuilder(); StringBuilder bad = new StringBuilder();

Datei anzeigen

@ -2,7 +2,6 @@ package org.bukkit.event.block;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
/** /**
@ -23,7 +22,7 @@ import org.bukkit.event.HandlerList;
* *
* @see BlockSpreadEvent * @see BlockSpreadEvent
*/ */
public class BlockFormEvent extends BlockGrowEvent implements Cancellable { public class BlockFormEvent extends BlockGrowEvent {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
public BlockFormEvent(final Block block, final BlockState newState) { public BlockFormEvent(final Block block, final BlockState newState) {

Datei anzeigen

@ -5,8 +5,6 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.help.HelpTopic;
/** /**
* Lacking an alternative, the help system will create instances of * Lacking an alternative, the help system will create instances of
@ -28,7 +26,7 @@ public class GenericCommandHelpTopic extends HelpTopic {
} }
// The short text is the first line of the description // The short text is the first line of the description
int i = command.getDescription().indexOf("\n"); int i = command.getDescription().indexOf('\n');
if (i > 1) { if (i > 1) {
shortText = command.getDescription().substring(0, i - 1); shortText = command.getDescription().substring(0, i - 1);
} else { } else {
@ -36,7 +34,7 @@ public class GenericCommandHelpTopic extends HelpTopic {
} }
// Build full text // Build full text
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
sb.append(ChatColor.GOLD); sb.append(ChatColor.GOLD);
sb.append("Description: "); sb.append("Description: ");

Datei anzeigen

@ -1,7 +1,5 @@
package org.bukkit.help; package org.bukkit.help;
import org.bukkit.help.HelpTopic;
import java.util.Comparator; import java.util.Comparator;
/** /**
@ -11,18 +9,18 @@ import java.util.Comparator;
* slash come after topics that don't. * slash come after topics that don't.
*/ */
public class HelpTopicComparator implements Comparator<HelpTopic> { public class HelpTopicComparator implements Comparator<HelpTopic> {
// Singleton implementations // Singleton implementations
private static final TopicNameComparator tnc = new TopicNameComparator(); private static final TopicNameComparator tnc = new TopicNameComparator();
public static TopicNameComparator topicNameComparatorInstance() { public static TopicNameComparator topicNameComparatorInstance() {
return tnc; return tnc;
} }
private static final HelpTopicComparator htc = new HelpTopicComparator(); private static final HelpTopicComparator htc = new HelpTopicComparator();
public static HelpTopicComparator helpTopicComparatorInstance() { public static HelpTopicComparator helpTopicComparatorInstance() {
return htc; return htc;
} }
private HelpTopicComparator() {} private HelpTopicComparator() {}
public int compare(HelpTopic lhs, HelpTopic rhs) { public int compare(HelpTopic lhs, HelpTopic rhs) {
@ -31,11 +29,11 @@ public class HelpTopicComparator implements Comparator<HelpTopic> {
public static class TopicNameComparator implements Comparator<String> { public static class TopicNameComparator implements Comparator<String> {
private TopicNameComparator(){} private TopicNameComparator(){}
public int compare(String lhs, String rhs) { public int compare(String lhs, String rhs) {
boolean lhsStartSlash = lhs.startsWith("/"); boolean lhsStartSlash = lhs.startsWith("/");
boolean rhsStartSlash = rhs.startsWith("/"); boolean rhsStartSlash = rhs.startsWith("/");
if (lhsStartSlash && !rhsStartSlash) { if (lhsStartSlash && !rhsStartSlash) {
return 1; return 1;
} else if (!lhsStartSlash && rhsStartSlash) { } else if (!lhsStartSlash && rhsStartSlash) {

Datei anzeigen

@ -14,7 +14,7 @@ public class Vine extends MaterialData {
private static final int VINE_EAST = 0x8; private static final int VINE_EAST = 0x8;
private static final int VINE_WEST = 0x2; private static final int VINE_WEST = 0x2;
private static final int VINE_SOUTH = 0x1; private static final int VINE_SOUTH = 0x1;
EnumSet<BlockFace> possibleFaces = EnumSet.of(BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST); private static final EnumSet<BlockFace> possibleFaces = EnumSet.of(BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST);
public Vine() { public Vine() {
super(Material.VINE); super(Material.VINE);

Datei anzeigen

@ -17,7 +17,7 @@ import org.bukkit.plugin.Plugin;
* level. Once invalidated, the LazyMetadataValue will recompute its value * level. Once invalidated, the LazyMetadataValue will recompute its value
* when asked. * when asked.
*/ */
public class LazyMetadataValue extends MetadataValueAdapter implements MetadataValue { public class LazyMetadataValue extends MetadataValueAdapter {
private Callable<Object> lazyValue; private Callable<Object> lazyValue;
private CacheStrategy cacheStrategy; private CacheStrategy cacheStrategy;
private SoftReference<Object> internalValue; private SoftReference<Object> internalValue;

Datei anzeigen

@ -176,11 +176,11 @@ public class PermissibleBase implements Permissible {
} }
private void calculateChildPermissions(Map<String, Boolean> children, boolean invert, PermissionAttachment attachment) { private void calculateChildPermissions(Map<String, Boolean> children, boolean invert, PermissionAttachment attachment) {
Set<String> keys = children.keySet(); for (Map.Entry<String, Boolean> entry : children.entrySet()) {
String name = entry.getKey();
for (String name : keys) {
Permission perm = Bukkit.getServer().getPluginManager().getPermission(name); Permission perm = Bukkit.getServer().getPluginManager().getPermission(name);
boolean value = children.get(name) ^ invert; boolean value = entry.getValue() ^ invert;
String lname = name.toLowerCase(java.util.Locale.ENGLISH); String lname = name.toLowerCase(java.util.Locale.ENGLISH);
permissions.put(lname, new PermissionAttachmentInfo(parent, lname, attachment, value)); permissions.put(lname, new PermissionAttachmentInfo(parent, lname, attachment, value));
@ -232,7 +232,7 @@ public class PermissibleBase implements Permissible {
return new HashSet<PermissionAttachmentInfo>(permissions.values()); return new HashSet<PermissionAttachmentInfo>(permissions.values());
} }
private class RemoveAttachmentRunnable implements Runnable { private static class RemoveAttachmentRunnable implements Runnable {
private PermissionAttachment attachment; private PermissionAttachment attachment;
public RemoveAttachmentRunnable(PermissionAttachment attachment) { public RemoveAttachmentRunnable(PermissionAttachment attachment) {

Datei anzeigen

@ -42,7 +42,7 @@ public final class SimplePluginManager implements PluginManager {
private final Map<Pattern, PluginLoader> fileAssociations = new HashMap<Pattern, PluginLoader>(); private final Map<Pattern, PluginLoader> fileAssociations = new HashMap<Pattern, PluginLoader>();
private final List<Plugin> plugins = new ArrayList<Plugin>(); private final List<Plugin> plugins = new ArrayList<Plugin>();
private final Map<String, Plugin> lookupNames = new HashMap<String, Plugin>(); private final Map<String, Plugin> lookupNames = new HashMap<String, Plugin>();
private static File updateDirectory = null; private File updateDirectory;
private final SimpleCommandMap commandMap; private final SimpleCommandMap commandMap;
private final Map<String, Permission> permissions = new HashMap<String, Permission>(); private final Map<String, Permission> permissions = new HashMap<String, Permission>();
private final Map<Boolean, Set<Permission>> defaultPerms = new LinkedHashMap<Boolean, Set<Permission>>(); private final Map<Boolean, Set<Permission>> defaultPerms = new LinkedHashMap<Boolean, Set<Permission>>();
@ -187,10 +187,11 @@ public final class SimplePluginManager implements PluginManager {
while (!plugins.isEmpty()) { while (!plugins.isEmpty()) {
boolean missingDependency = true; boolean missingDependency = true;
Iterator<String> pluginIterator = plugins.keySet().iterator(); Iterator<Map.Entry<String, File>> pluginIterator = plugins.entrySet().iterator();
while (pluginIterator.hasNext()) { while (pluginIterator.hasNext()) {
String plugin = pluginIterator.next(); Map.Entry<String, File> entry = pluginIterator.next();
String plugin = entry.getKey();
if (dependencies.containsKey(plugin)) { if (dependencies.containsKey(plugin)) {
Iterator<String> dependencyIterator = dependencies.get(plugin).iterator(); Iterator<String> dependencyIterator = dependencies.get(plugin).iterator();
@ -205,14 +206,13 @@ public final class SimplePluginManager implements PluginManager {
// We have a dependency not found // We have a dependency not found
} else if (!plugins.containsKey(dependency)) { } else if (!plugins.containsKey(dependency)) {
missingDependency = false; missingDependency = false;
File file = plugins.get(plugin);
pluginIterator.remove(); pluginIterator.remove();
softDependencies.remove(plugin); softDependencies.remove(plugin);
dependencies.remove(plugin); dependencies.remove(plugin);
server.getLogger().log( server.getLogger().log(
Level.SEVERE, Level.SEVERE,
"Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "'", "Could not load '" + entry.getValue().getPath() + "' in folder '" + directory.getPath() + "'",
new UnknownDependencyException(dependency)); new UnknownDependencyException(dependency));
break; break;
} }
@ -257,15 +257,16 @@ public final class SimplePluginManager implements PluginManager {
if (missingDependency) { if (missingDependency) {
// We now iterate over plugins until something loads // We now iterate over plugins until something loads
// This loop will ignore soft dependencies // This loop will ignore soft dependencies
pluginIterator = plugins.keySet().iterator(); pluginIterator = plugins.entrySet().iterator();
while (pluginIterator.hasNext()) { while (pluginIterator.hasNext()) {
String plugin = pluginIterator.next(); Map.Entry<String, File> entry = pluginIterator.next();
String plugin = entry.getKey();
if (!dependencies.containsKey(plugin)) { if (!dependencies.containsKey(plugin)) {
softDependencies.remove(plugin); softDependencies.remove(plugin);
missingDependency = false; missingDependency = false;
File file = plugins.get(plugin); File file = entry.getValue();
pluginIterator.remove(); pluginIterator.remove();
try { try {
@ -358,7 +359,7 @@ public final class SimplePluginManager implements PluginManager {
} }
public synchronized Plugin[] getPlugins() { public synchronized Plugin[] getPlugins() {
return plugins.toArray(new Plugin[0]); return plugins.toArray(new Plugin[plugins.size()]);
} }
/** /**

Datei anzeigen

@ -68,7 +68,7 @@ public class StandardMessenger implements Messenger {
Set<String> channels = outgoingByPlugin.get(plugin); Set<String> channels = outgoingByPlugin.get(plugin);
if (channels != null) { if (channels != null) {
String[] toRemove = channels.toArray(new String[0]); String[] toRemove = channels.toArray(new String[channels.size()]);
outgoingByPlugin.remove(plugin); outgoingByPlugin.remove(plugin);
@ -138,7 +138,7 @@ public class StandardMessenger implements Messenger {
Set<PluginMessageListenerRegistration> registrations = incomingByPlugin.get(plugin); Set<PluginMessageListenerRegistration> registrations = incomingByPlugin.get(plugin);
if (registrations != null) { if (registrations != null) {
PluginMessageListenerRegistration[] toRemove = registrations.toArray(new PluginMessageListenerRegistration[0]); PluginMessageListenerRegistration[] toRemove = registrations.toArray(new PluginMessageListenerRegistration[registrations.size()]);
for (PluginMessageListenerRegistration registration : toRemove) { for (PluginMessageListenerRegistration registration : toRemove) {
if (registration.getChannel().equals(channel)) { if (registration.getChannel().equals(channel)) {
@ -154,7 +154,7 @@ public class StandardMessenger implements Messenger {
Set<PluginMessageListenerRegistration> registrations = incomingByPlugin.get(plugin); Set<PluginMessageListenerRegistration> registrations = incomingByPlugin.get(plugin);
if (registrations != null) { if (registrations != null) {
PluginMessageListenerRegistration[] toRemove = registrations.toArray(new PluginMessageListenerRegistration[0]); PluginMessageListenerRegistration[] toRemove = registrations.toArray(new PluginMessageListenerRegistration[registrations.size()]);
incomingByPlugin.remove(plugin); incomingByPlugin.remove(plugin);

Datei anzeigen

@ -345,10 +345,10 @@ public class Potion {
level++; level++;
potion = new Potion(type, level); potion = new Potion(type, level);
} }
if ((damage & SPLASH_BIT) > 0) { if ((damage & SPLASH_BIT) != 0) {
potion = potion.splash(); potion = potion.splash();
} }
if ((damage & EXTENDED_BIT) > 0) { if ((damage & EXTENDED_BIT) != 0) {
potion = potion.extend(); potion = potion.extend();
} }
return potion; return potion;

Datei anzeigen

@ -30,7 +30,7 @@ public final class NumberConversions {
} }
try { try {
return Integer.valueOf(object.toString()); return Integer.parseInt(object.toString());
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
} catch (NullPointerException e) { } catch (NullPointerException e) {
} }
@ -43,7 +43,7 @@ public final class NumberConversions {
} }
try { try {
return Float.valueOf(object.toString()); return Float.parseFloat(object.toString());
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
} catch (NullPointerException e) { } catch (NullPointerException e) {
} }
@ -56,7 +56,7 @@ public final class NumberConversions {
} }
try { try {
return Double.valueOf(object.toString()); return Double.parseDouble(object.toString());
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
} catch (NullPointerException e) { } catch (NullPointerException e) {
} }
@ -69,7 +69,7 @@ public final class NumberConversions {
} }
try { try {
return Long.valueOf(object.toString()); return Long.parseLong(object.toString());
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
} catch (NullPointerException e) { } catch (NullPointerException e) {
} }
@ -82,7 +82,7 @@ public final class NumberConversions {
} }
try { try {
return Short.valueOf(object.toString()); return Short.parseShort(object.toString());
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
} catch (NullPointerException e) { } catch (NullPointerException e) {
} }
@ -95,7 +95,7 @@ public final class NumberConversions {
} }
try { try {
return Byte.valueOf(object.toString()); return Byte.parseByte(object.toString());
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
} catch (NullPointerException e) { } catch (NullPointerException e) {
} }

Datei anzeigen

@ -41,7 +41,7 @@ public class SimplexNoiseGenerator extends PerlinNoiseGenerator {
{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0},
{2, 0, 1, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {3, 0, 1, 2}, {3, 0, 2, 1}, {0, 0, 0, 0}, {3, 1, 2, 0}, {2, 0, 1, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {3, 0, 1, 2}, {3, 0, 2, 1}, {0, 0, 0, 0}, {3, 1, 2, 0},
{2, 1, 0, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {3, 1, 0, 2}, {0, 0, 0, 0}, {3, 2, 0, 1}, {3, 2, 1, 0}}; {2, 1, 0, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {3, 1, 0, 2}, {0, 0, 0, 0}, {3, 2, 0, 1}, {3, 2, 1, 0}};
protected static double offsetW; protected double offsetW;
private static final SimplexNoiseGenerator instance = new SimplexNoiseGenerator(); private static final SimplexNoiseGenerator instance = new SimplexNoiseGenerator();
protected SimplexNoiseGenerator() { protected SimplexNoiseGenerator() {

Datei anzeigen

@ -27,7 +27,7 @@ public class ConversationTest {
assertEquals("SecondPrompt", forWhom.lastSentMessage); assertEquals("SecondPrompt", forWhom.lastSentMessage);
assertEquals(conversation, forWhom.abandonedConverstion); assertEquals(conversation, forWhom.abandonedConverstion);
} }
@Test @Test
public void testConversationFactory() { public void testConversationFactory() {
FakeConversable forWhom = new FakeConversable(); FakeConversable forWhom = new FakeConversable();
@ -75,7 +75,6 @@ public class ConversationTest {
@Test @Test
public void testNotPlayer() { public void testNotPlayer() {
FakeConversable forWhom = new FakeConversable(); FakeConversable forWhom = new FakeConversable();
NullConversationPrefix prefix = new NullConversationPrefix();
ConversationFactory factory = new ConversationFactory(null) ConversationFactory factory = new ConversationFactory(null)
.thatExcludesNonPlayersWithMessage("bye"); .thatExcludesNonPlayersWithMessage("bye");
Conversation conversation = factory.buildConversation(forWhom); Conversation conversation = factory.buildConversation(forWhom);