summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormd_5 <git@md-5.net>2017-11-07 17:28:28 +1100
committermd_5 <git@md-5.net>2017-11-07 17:28:28 +1100
commit931e7ed751b113c198cc66dddd239f0ab91ac20a (patch)
tree42b91e85c77103f265b477b6ff855582c14447ca
parentcef79e55153e438d9ef4b87f4de45cd59233f01e (diff)
downloadbukkit-931e7ed751b113c198cc66dddd239f0ab91ac20a.tar
bukkit-931e7ed751b113c198cc66dddd239f0ab91ac20a.tar.gz
bukkit-931e7ed751b113c198cc66dddd239f0ab91ac20a.tar.lz
bukkit-931e7ed751b113c198cc66dddd239f0ab91ac20a.tar.xz
bukkit-931e7ed751b113c198cc66dddd239f0ab91ac20a.zip
Some minor improvements from static analysis
-rw-r--r--src/main/java/org/bukkit/FireworkEffect.java3
-rw-r--r--src/main/java/org/bukkit/command/FormattedCommandAlias.java13
-rw-r--r--src/main/java/org/bukkit/command/SimpleCommandMap.java5
-rw-r--r--src/main/java/org/bukkit/event/block/BlockFormEvent.java3
-rw-r--r--src/main/java/org/bukkit/help/GenericCommandHelpTopic.java6
-rw-r--r--src/main/java/org/bukkit/help/HelpTopicComparator.java12
-rw-r--r--src/main/java/org/bukkit/material/Vine.java2
-rw-r--r--src/main/java/org/bukkit/metadata/LazyMetadataValue.java2
-rw-r--r--src/main/java/org/bukkit/permissions/PermissibleBase.java8
-rw-r--r--src/main/java/org/bukkit/plugin/SimplePluginManager.java19
-rw-r--r--src/main/java/org/bukkit/plugin/messaging/StandardMessenger.java6
-rw-r--r--src/main/java/org/bukkit/potion/Potion.java4
-rw-r--r--src/main/java/org/bukkit/util/NumberConversions.java12
-rw-r--r--src/main/java/org/bukkit/util/noise/SimplexNoiseGenerator.java2
-rw-r--r--src/test/java/org/bukkit/conversations/ConversationTest.java3
15 files changed, 44 insertions, 56 deletions
diff --git a/src/main/java/org/bukkit/FireworkEffect.java b/src/main/java/org/bukkit/FireworkEffect.java
index e565a2b7..f1fec892 100644
--- a/src/main/java/org/bukkit/FireworkEffect.java
+++ b/src/main/java/org/bukkit/FireworkEffect.java
@@ -356,9 +356,6 @@ public final class FireworkEffect implements ConfigurationSerializable {
*/
public static ConfigurationSerializable deserialize(Map<String, Object> map) {
Type type = Type.valueOf((String) map.get(TYPE));
- if (type == null) {
- throw new IllegalArgumentException(map.get(TYPE) + " is not a valid Type");
- }
return builder()
.flicker((Boolean) map.get(FLICKER))
diff --git a/src/main/java/org/bukkit/command/FormattedCommandAlias.java b/src/main/java/org/bukkit/command/FormattedCommandAlias.java
index 3f07d7f4..50257883 100644
--- a/src/main/java/org/bukkit/command/FormattedCommandAlias.java
+++ b/src/main/java/org/bukkit/command/FormattedCommandAlias.java
@@ -1,13 +1,8 @@
package org.bukkit.command;
import java.util.ArrayList;
-import java.util.logging.Level;
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 {
private final String[] formatStrings;
@@ -42,13 +37,13 @@ public class FormattedCommandAlias extends Command {
}
private String buildCommand(String formatString, String[] args) {
- int index = formatString.indexOf("$");
+ int index = formatString.indexOf('$');
while (index != -1) {
int start = index;
if (index > 0 && formatString.charAt(start - 1) == '\\') {
formatString = formatString.substring(0, start - 1) + formatString.substring(start);
- index = formatString.indexOf("$", index);
+ index = formatString.indexOf('$', index);
continue;
}
@@ -72,7 +67,7 @@ public class FormattedCommandAlias extends Command {
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
if (position == 0) {
@@ -112,7 +107,7 @@ public class FormattedCommandAlias extends Command {
index = start + replacement.length();
// Move to the next replacement token
- index = formatString.indexOf("$", index);
+ index = formatString.indexOf('$', index);
}
return formatString;
diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java
index 9969185c..f81ae85d 100644
--- a/src/main/java/org/bukkit/command/SimpleCommandMap.java
+++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java
@@ -225,13 +225,14 @@ public class SimpleCommandMap implements CommandMap {
public void registerServerAliases() {
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(" ")) {
server.getLogger().warning("Could not register alias " + alias + " because it contains illegal characters");
continue;
}
- String[] commandStrings = values.get(alias);
+ String[] commandStrings = entry.getValue();
List<String> targets = new ArrayList<String>();
StringBuilder bad = new StringBuilder();
diff --git a/src/main/java/org/bukkit/event/block/BlockFormEvent.java b/src/main/java/org/bukkit/event/block/BlockFormEvent.java
index 64af5b0f..e765a4ea 100644
--- a/src/main/java/org/bukkit/event/block/BlockFormEvent.java
+++ b/src/main/java/org/bukkit/event/block/BlockFormEvent.java
@@ -2,7 +2,6 @@ package org.bukkit.event.block;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
-import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
/**
@@ -23,7 +22,7 @@ import org.bukkit.event.HandlerList;
*
* @see BlockSpreadEvent
*/
-public class BlockFormEvent extends BlockGrowEvent implements Cancellable {
+public class BlockFormEvent extends BlockGrowEvent {
private static final HandlerList handlers = new HandlerList();
public BlockFormEvent(final Block block, final BlockState newState) {
diff --git a/src/main/java/org/bukkit/help/GenericCommandHelpTopic.java b/src/main/java/org/bukkit/help/GenericCommandHelpTopic.java
index 5156bdf4..8f9a25c1 100644
--- a/src/main/java/org/bukkit/help/GenericCommandHelpTopic.java
+++ b/src/main/java/org/bukkit/help/GenericCommandHelpTopic.java
@@ -5,8 +5,6 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.apache.commons.lang.StringUtils;
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
@@ -28,7 +26,7 @@ public class GenericCommandHelpTopic extends HelpTopic {
}
// 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) {
shortText = command.getDescription().substring(0, i - 1);
} else {
@@ -36,7 +34,7 @@ public class GenericCommandHelpTopic extends HelpTopic {
}
// Build full text
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
sb.append(ChatColor.GOLD);
sb.append("Description: ");
diff --git a/src/main/java/org/bukkit/help/HelpTopicComparator.java b/src/main/java/org/bukkit/help/HelpTopicComparator.java
index 3e43eb36..3e62e91b 100644
--- a/src/main/java/org/bukkit/help/HelpTopicComparator.java
+++ b/src/main/java/org/bukkit/help/HelpTopicComparator.java
@@ -1,7 +1,5 @@
package org.bukkit.help;
-import org.bukkit.help.HelpTopic;
-
import java.util.Comparator;
/**
@@ -11,18 +9,18 @@ import java.util.Comparator;
* slash come after topics that don't.
*/
public class HelpTopicComparator implements Comparator<HelpTopic> {
-
+
// Singleton implementations
private static final TopicNameComparator tnc = new TopicNameComparator();
public static TopicNameComparator topicNameComparatorInstance() {
return tnc;
}
-
+
private static final HelpTopicComparator htc = new HelpTopicComparator();
public static HelpTopicComparator helpTopicComparatorInstance() {
return htc;
}
-
+
private HelpTopicComparator() {}
public int compare(HelpTopic lhs, HelpTopic rhs) {
@@ -31,11 +29,11 @@ public class HelpTopicComparator implements Comparator<HelpTopic> {
public static class TopicNameComparator implements Comparator<String> {
private TopicNameComparator(){}
-
+
public int compare(String lhs, String rhs) {
boolean lhsStartSlash = lhs.startsWith("/");
boolean rhsStartSlash = rhs.startsWith("/");
-
+
if (lhsStartSlash && !rhsStartSlash) {
return 1;
} else if (!lhsStartSlash && rhsStartSlash) {
diff --git a/src/main/java/org/bukkit/material/Vine.java b/src/main/java/org/bukkit/material/Vine.java
index f58be9df..da84d419 100644
--- a/src/main/java/org/bukkit/material/Vine.java
+++ b/src/main/java/org/bukkit/material/Vine.java
@@ -14,7 +14,7 @@ public class Vine extends MaterialData {
private static final int VINE_EAST = 0x8;
private static final int VINE_WEST = 0x2;
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() {
super(Material.VINE);
diff --git a/src/main/java/org/bukkit/metadata/LazyMetadataValue.java b/src/main/java/org/bukkit/metadata/LazyMetadataValue.java
index 564d0fab..da5e9f3a 100644
--- a/src/main/java/org/bukkit/metadata/LazyMetadataValue.java
+++ b/src/main/java/org/bukkit/metadata/LazyMetadataValue.java
@@ -17,7 +17,7 @@ import org.bukkit.plugin.Plugin;
* level. Once invalidated, the LazyMetadataValue will recompute its value
* when asked.
*/
-public class LazyMetadataValue extends MetadataValueAdapter implements MetadataValue {
+public class LazyMetadataValue extends MetadataValueAdapter {
private Callable<Object> lazyValue;
private CacheStrategy cacheStrategy;
private SoftReference<Object> internalValue;
diff --git a/src/main/java/org/bukkit/permissions/PermissibleBase.java b/src/main/java/org/bukkit/permissions/PermissibleBase.java
index bc772e5b..d4cb00a8 100644
--- a/src/main/java/org/bukkit/permissions/PermissibleBase.java
+++ b/src/main/java/org/bukkit/permissions/PermissibleBase.java
@@ -176,11 +176,11 @@ public class PermissibleBase implements Permissible {
}
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);
- boolean value = children.get(name) ^ invert;
+ boolean value = entry.getValue() ^ invert;
String lname = name.toLowerCase(java.util.Locale.ENGLISH);
permissions.put(lname, new PermissionAttachmentInfo(parent, lname, attachment, value));
@@ -232,7 +232,7 @@ public class PermissibleBase implements Permissible {
return new HashSet<PermissionAttachmentInfo>(permissions.values());
}
- private class RemoveAttachmentRunnable implements Runnable {
+ private static class RemoveAttachmentRunnable implements Runnable {
private PermissionAttachment attachment;
public RemoveAttachmentRunnable(PermissionAttachment attachment) {
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
index b9015eee..60b23995 100644
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
@@ -42,7 +42,7 @@ public final class SimplePluginManager implements PluginManager {
private final Map<Pattern, PluginLoader> fileAssociations = new HashMap<Pattern, PluginLoader>();
private final List<Plugin> plugins = new ArrayList<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 Map<String, Permission> permissions = new HashMap<String, 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()) {
boolean missingDependency = true;
- Iterator<String> pluginIterator = plugins.keySet().iterator();
+ Iterator<Map.Entry<String, File>> pluginIterator = plugins.entrySet().iterator();
while (pluginIterator.hasNext()) {
- String plugin = pluginIterator.next();
+ Map.Entry<String, File> entry = pluginIterator.next();
+ String plugin = entry.getKey();
if (dependencies.containsKey(plugin)) {
Iterator<String> dependencyIterator = dependencies.get(plugin).iterator();
@@ -205,14 +206,13 @@ public final class SimplePluginManager implements PluginManager {
// We have a dependency not found
} else if (!plugins.containsKey(dependency)) {
missingDependency = false;
- File file = plugins.get(plugin);
pluginIterator.remove();
softDependencies.remove(plugin);
dependencies.remove(plugin);
server.getLogger().log(
Level.SEVERE,
- "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "'",
+ "Could not load '" + entry.getValue().getPath() + "' in folder '" + directory.getPath() + "'",
new UnknownDependencyException(dependency));
break;
}
@@ -257,15 +257,16 @@ public final class SimplePluginManager implements PluginManager {
if (missingDependency) {
// We now iterate over plugins until something loads
// This loop will ignore soft dependencies
- pluginIterator = plugins.keySet().iterator();
+ pluginIterator = plugins.entrySet().iterator();
while (pluginIterator.hasNext()) {
- String plugin = pluginIterator.next();
+ Map.Entry<String, File> entry = pluginIterator.next();
+ String plugin = entry.getKey();
if (!dependencies.containsKey(plugin)) {
softDependencies.remove(plugin);
missingDependency = false;
- File file = plugins.get(plugin);
+ File file = entry.getValue();
pluginIterator.remove();
try {
@@ -358,7 +359,7 @@ public final class SimplePluginManager implements PluginManager {
}
public synchronized Plugin[] getPlugins() {
- return plugins.toArray(new Plugin[0]);
+ return plugins.toArray(new Plugin[plugins.size()]);
}
/**
diff --git a/src/main/java/org/bukkit/plugin/messaging/StandardMessenger.java b/src/main/java/org/bukkit/plugin/messaging/StandardMessenger.java
index a906f8dd..29bcb39c 100644
--- a/src/main/java/org/bukkit/plugin/messaging/StandardMessenger.java
+++ b/src/main/java/org/bukkit/plugin/messaging/StandardMessenger.java
@@ -68,7 +68,7 @@ public class StandardMessenger implements Messenger {
Set<String> channels = outgoingByPlugin.get(plugin);
if (channels != null) {
- String[] toRemove = channels.toArray(new String[0]);
+ String[] toRemove = channels.toArray(new String[channels.size()]);
outgoingByPlugin.remove(plugin);
@@ -138,7 +138,7 @@ public class StandardMessenger implements Messenger {
Set<PluginMessageListenerRegistration> registrations = incomingByPlugin.get(plugin);
if (registrations != null) {
- PluginMessageListenerRegistration[] toRemove = registrations.toArray(new PluginMessageListenerRegistration[0]);
+ PluginMessageListenerRegistration[] toRemove = registrations.toArray(new PluginMessageListenerRegistration[registrations.size()]);
for (PluginMessageListenerRegistration registration : toRemove) {
if (registration.getChannel().equals(channel)) {
@@ -154,7 +154,7 @@ public class StandardMessenger implements Messenger {
Set<PluginMessageListenerRegistration> registrations = incomingByPlugin.get(plugin);
if (registrations != null) {
- PluginMessageListenerRegistration[] toRemove = registrations.toArray(new PluginMessageListenerRegistration[0]);
+ PluginMessageListenerRegistration[] toRemove = registrations.toArray(new PluginMessageListenerRegistration[registrations.size()]);
incomingByPlugin.remove(plugin);
diff --git a/src/main/java/org/bukkit/potion/Potion.java b/src/main/java/org/bukkit/potion/Potion.java
index 7aa5a2d1..1413b361 100644
--- a/src/main/java/org/bukkit/potion/Potion.java
+++ b/src/main/java/org/bukkit/potion/Potion.java
@@ -345,10 +345,10 @@ public class Potion {
level++;
potion = new Potion(type, level);
}
- if ((damage & SPLASH_BIT) > 0) {
+ if ((damage & SPLASH_BIT) != 0) {
potion = potion.splash();
}
- if ((damage & EXTENDED_BIT) > 0) {
+ if ((damage & EXTENDED_BIT) != 0) {
potion = potion.extend();
}
return potion;
diff --git a/src/main/java/org/bukkit/util/NumberConversions.java b/src/main/java/org/bukkit/util/NumberConversions.java
index e6af9ec7..440d2798 100644
--- a/src/main/java/org/bukkit/util/NumberConversions.java
+++ b/src/main/java/org/bukkit/util/NumberConversions.java
@@ -30,7 +30,7 @@ public final class NumberConversions {
}
try {
- return Integer.valueOf(object.toString());
+ return Integer.parseInt(object.toString());
} catch (NumberFormatException e) {
} catch (NullPointerException e) {
}
@@ -43,7 +43,7 @@ public final class NumberConversions {
}
try {
- return Float.valueOf(object.toString());
+ return Float.parseFloat(object.toString());
} catch (NumberFormatException e) {
} catch (NullPointerException e) {
}
@@ -56,7 +56,7 @@ public final class NumberConversions {
}
try {
- return Double.valueOf(object.toString());
+ return Double.parseDouble(object.toString());
} catch (NumberFormatException e) {
} catch (NullPointerException e) {
}
@@ -69,7 +69,7 @@ public final class NumberConversions {
}
try {
- return Long.valueOf(object.toString());
+ return Long.parseLong(object.toString());
} catch (NumberFormatException e) {
} catch (NullPointerException e) {
}
@@ -82,7 +82,7 @@ public final class NumberConversions {
}
try {
- return Short.valueOf(object.toString());
+ return Short.parseShort(object.toString());
} catch (NumberFormatException e) {
} catch (NullPointerException e) {
}
@@ -95,7 +95,7 @@ public final class NumberConversions {
}
try {
- return Byte.valueOf(object.toString());
+ return Byte.parseByte(object.toString());
} catch (NumberFormatException e) {
} catch (NullPointerException e) {
}
diff --git a/src/main/java/org/bukkit/util/noise/SimplexNoiseGenerator.java b/src/main/java/org/bukkit/util/noise/SimplexNoiseGenerator.java
index b052f3c3..7dac89b0 100644
--- a/src/main/java/org/bukkit/util/noise/SimplexNoiseGenerator.java
+++ b/src/main/java/org/bukkit/util/noise/SimplexNoiseGenerator.java
@@ -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},
{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}};
- protected static double offsetW;
+ protected double offsetW;
private static final SimplexNoiseGenerator instance = new SimplexNoiseGenerator();
protected SimplexNoiseGenerator() {
diff --git a/src/test/java/org/bukkit/conversations/ConversationTest.java b/src/test/java/org/bukkit/conversations/ConversationTest.java
index 732caab2..814d7f5d 100644
--- a/src/test/java/org/bukkit/conversations/ConversationTest.java
+++ b/src/test/java/org/bukkit/conversations/ConversationTest.java
@@ -27,7 +27,7 @@ public class ConversationTest {
assertEquals("SecondPrompt", forWhom.lastSentMessage);
assertEquals(conversation, forWhom.abandonedConverstion);
}
-
+
@Test
public void testConversationFactory() {
FakeConversable forWhom = new FakeConversable();
@@ -75,7 +75,6 @@ public class ConversationTest {
@Test
public void testNotPlayer() {
FakeConversable forWhom = new FakeConversable();
- NullConversationPrefix prefix = new NullConversationPrefix();
ConversationFactory factory = new ConversationFactory(null)
.thatExcludesNonPlayersWithMessage("bye");
Conversation conversation = factory.buildConversation(forWhom);