mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-05 18:27:17 +01:00
Some minor improvements from static analysis
By: md_5 <git@md-5.net>
This commit is contained in:
parent
2a82e16c61
commit
417599c2ab
15 changed files with 44 additions and 56 deletions
|
@ -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))
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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: ");
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue