From 215b70dcd78f38e5f2c3ba630cfe97ed9d0733d6 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 12 Jul 2014 19:30:00 +1000 Subject: [PATCH] Fix some more things picked up by static analysis. --- .../java/net/md_5/bungee/api/Favicon.java | 3 --- .../md_5/bungee/api/chat/BaseComponent.java | 8 ++------ .../net/md_5/bungee/api/chat/ClickEvent.java | 20 +++++++------------ .../bungee/api/chat/ComponentBuilder.java | 4 +--- .../net/md_5/bungee/api/chat/HoverEvent.java | 14 ++++--------- .../md_5/bungee/api/chat/TextComponent.java | 4 ++-- .../api/chat/TranslatableComponent.java | 11 +++------- .../net/md_5/bungee/api/plugin/Plugin.java | 1 - .../md_5/bungee/api/plugin/PluginManager.java | 8 ++++---- .../api/scheduler/GroupedThreadFactory.java | 2 +- .../md_5/bungee/chat/ComponentSerializer.java | 2 -- .../bungee/chat/TextComponentSerializer.java | 2 +- 12 files changed, 25 insertions(+), 54 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/Favicon.java b/api/src/main/java/net/md_5/bungee/api/Favicon.java index 0c9ec07e..564ca414 100644 --- a/api/src/main/java/net/md_5/bungee/api/Favicon.java +++ b/api/src/main/java/net/md_5/bungee/api/Favicon.java @@ -7,10 +7,7 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import javax.imageio.ImageIO; import lombok.AccessLevel; import lombok.Getter; diff --git a/api/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java b/api/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java index bd5b9178..793eec2a 100644 --- a/api/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java +++ b/api/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java @@ -8,8 +8,10 @@ import net.md_5.bungee.api.ChatColor; import java.util.ArrayList; import java.util.List; +import lombok.ToString; @Setter +@ToString @NoArgsConstructor public abstract class BaseComponent { @@ -370,10 +372,4 @@ public abstract class BaseComponent } } } - - @Override - public String toString() - { - return String.format( "BaseComponent{color=%s, bold=%b, italic=%b, underlined=%b, strikethrough=%b, obfuscated=%b, clickEvent=%s, hoverEvent=%s, extra=%s}", getColor().getName(), isBold(), isItalic(), isUnderlined(), isStrikethrough(), isObfuscated(), getClickEvent(), getHoverEvent(), getExtra() ); - } } diff --git a/api/src/main/java/net/md_5/bungee/api/chat/ClickEvent.java b/api/src/main/java/net/md_5/bungee/api/chat/ClickEvent.java index 769c8c26..c7942208 100644 --- a/api/src/main/java/net/md_5/bungee/api/chat/ClickEvent.java +++ b/api/src/main/java/net/md_5/bungee/api/chat/ClickEvent.java @@ -1,14 +1,14 @@ package net.md_5.bungee.api.chat; -import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.RequiredArgsConstructor; +import lombok.ToString; import net.md_5.bungee.api.chat.ClickEvent.Action; @Getter -@AllArgsConstructor -final public class ClickEvent +@ToString +@RequiredArgsConstructor +public final class ClickEvent { /** @@ -42,15 +42,9 @@ final public class ClickEvent RUN_COMMAND, /** * Inserts the string given by - * {@link net.md_5.bungee.api.chat.ClickEvent#value} into the - * players text box + * {@link net.md_5.bungee.api.chat.ClickEvent#value} into the players + * text box */ SUGGEST_COMMAND } - - @Override - public String toString() - { - return String.format( "ClickEvent{action=%s, value=%s}", action, value ); - } } diff --git a/api/src/main/java/net/md_5/bungee/api/chat/ComponentBuilder.java b/api/src/main/java/net/md_5/bungee/api/chat/ComponentBuilder.java index 007629c2..18d00bc0 100644 --- a/api/src/main/java/net/md_5/bungee/api/chat/ComponentBuilder.java +++ b/api/src/main/java/net/md_5/bungee/api/chat/ComponentBuilder.java @@ -1,8 +1,6 @@ package net.md_5.bungee.api.chat; -import lombok.NoArgsConstructor; import net.md_5.bungee.api.ChatColor; - import java.util.ArrayList; import java.util.List; @@ -28,7 +26,7 @@ public class ComponentBuilder { private TextComponent current; - private List parts = new ArrayList<>(); + private final List parts = new ArrayList<>(); /** * Creates a ComponentBuilder with the given text as the first part. diff --git a/api/src/main/java/net/md_5/bungee/api/chat/HoverEvent.java b/api/src/main/java/net/md_5/bungee/api/chat/HoverEvent.java index 651549f7..a8bfd789 100644 --- a/api/src/main/java/net/md_5/bungee/api/chat/HoverEvent.java +++ b/api/src/main/java/net/md_5/bungee/api/chat/HoverEvent.java @@ -1,12 +1,12 @@ package net.md_5.bungee.api.chat; -import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.RequiredArgsConstructor; +import lombok.ToString; @Getter -@AllArgsConstructor +@ToString +@RequiredArgsConstructor final public class HoverEvent { @@ -20,10 +20,4 @@ final public class HoverEvent SHOW_ACHIEVEMENT, SHOW_ITEM } - - @Override - public String toString() - { - return String.format( "HoverEvent{action=%s, value=%s}", action, value ); - } } diff --git a/api/src/main/java/net/md_5/bungee/api/chat/TextComponent.java b/api/src/main/java/net/md_5/bungee/api/chat/TextComponent.java index 01e1a3e9..251eaf5f 100644 --- a/api/src/main/java/net/md_5/bungee/api/chat/TextComponent.java +++ b/api/src/main/java/net/md_5/bungee/api/chat/TextComponent.java @@ -121,8 +121,8 @@ public class TextComponent extends BaseComponent components.add( component ); } - //The client will crash if the array is empty - if ( components.size() == 0 ) + // The client will crash if the array is empty + if ( components.isEmpty() ) { components.add( new TextComponent( "" ) ); } diff --git a/api/src/main/java/net/md_5/bungee/api/chat/TranslatableComponent.java b/api/src/main/java/net/md_5/bungee/api/chat/TranslatableComponent.java index bb162918..0f2d7602 100644 --- a/api/src/main/java/net/md_5/bungee/api/chat/TranslatableComponent.java +++ b/api/src/main/java/net/md_5/bungee/api/chat/TranslatableComponent.java @@ -4,16 +4,16 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import net.md_5.bungee.api.ChatColor; - import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.ResourceBundle; import java.util.regex.Matcher; import java.util.regex.Pattern; +import lombok.ToString; @Getter @Setter +@ToString @NoArgsConstructor public class TranslatableComponent extends BaseComponent { @@ -104,6 +104,7 @@ public class TranslatableComponent extends BaseComponent protected void toPlainText(StringBuilder builder) { String trans = locales.getString( translate ); + // TODO: Yell @ Thinkofdeath, this is impossible. getString(..) actually throws an exception when there is no string. if ( trans == null ) { builder.append( translate ); @@ -212,10 +213,4 @@ public class TranslatableComponent extends BaseComponent builder.append( ChatColor.MAGIC ); } } - - @Override - public String toString() - { - return String.format( "TranslatableComponent{translate=%s, with=%s, %s}", translate, with, super.toString() ); - } } diff --git a/api/src/main/java/net/md_5/bungee/api/plugin/Plugin.java b/api/src/main/java/net/md_5/bungee/api/plugin/Plugin.java index 98b3f57d..a62e38d1 100644 --- a/api/src/main/java/net/md_5/bungee/api/plugin/Plugin.java +++ b/api/src/main/java/net/md_5/bungee/api/plugin/Plugin.java @@ -5,7 +5,6 @@ import java.io.File; import java.io.InputStream; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.ThreadFactory; import java.util.logging.Logger; import lombok.Getter; import net.md_5.bungee.api.ProxyServer; diff --git a/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java b/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java index 413e5cff..e44e12af 100644 --- a/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java +++ b/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java @@ -49,8 +49,8 @@ public class PluginManager private final Map plugins = new LinkedHashMap<>(); private final Map commandMap = new HashMap<>(); private Map toLoad = new HashMap<>(); - private Multimap commandsByPlugin = ArrayListMultimap.create(); - private Multimap listenersByPlugin = ArrayListMultimap.create(); + private final Multimap commandsByPlugin = ArrayListMultimap.create(); + private final Multimap listenersByPlugin = ArrayListMultimap.create(); @SuppressWarnings("unchecked") public PluginManager(ProxyServer proxy) @@ -191,7 +191,7 @@ public class PluginManager PluginDescription plugin = entry.getValue(); if ( !enablePlugin( pluginStatuses, new Stack(), plugin ) ) { - ProxyServer.getInstance().getLogger().warning( "Failed to enable " + entry.getKey() ); + ProxyServer.getInstance().getLogger().log( Level.WARNING, "Failed to enable {0}", entry.getKey() ); } } toLoad.clear(); @@ -247,7 +247,7 @@ public class PluginManager dependencyGraph.append( element.getName() ).append( " -> " ); } dependencyGraph.append( plugin.getName() ).append( " -> " ).append( dependName ); - ProxyServer.getInstance().getLogger().log( Level.WARNING, "Circular dependency detected: " + dependencyGraph ); + ProxyServer.getInstance().getLogger().log( Level.WARNING, "Circular dependency detected: {0}", dependencyGraph ); status = false; } else { diff --git a/api/src/main/java/net/md_5/bungee/api/scheduler/GroupedThreadFactory.java b/api/src/main/java/net/md_5/bungee/api/scheduler/GroupedThreadFactory.java index 8bd65a99..4f7ba39b 100644 --- a/api/src/main/java/net/md_5/bungee/api/scheduler/GroupedThreadFactory.java +++ b/api/src/main/java/net/md_5/bungee/api/scheduler/GroupedThreadFactory.java @@ -11,7 +11,7 @@ public class GroupedThreadFactory implements ThreadFactory private final ThreadGroup group; - public class BungeeGroup extends ThreadGroup + public static class BungeeGroup extends ThreadGroup { private BungeeGroup(String name) diff --git a/api/src/main/java/net/md_5/bungee/chat/ComponentSerializer.java b/api/src/main/java/net/md_5/bungee/chat/ComponentSerializer.java index cb663bdb..b001ef85 100644 --- a/api/src/main/java/net/md_5/bungee/chat/ComponentSerializer.java +++ b/api/src/main/java/net/md_5/bungee/chat/ComponentSerializer.java @@ -7,8 +7,6 @@ import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TranslatableComponent; diff --git a/api/src/main/java/net/md_5/bungee/chat/TextComponentSerializer.java b/api/src/main/java/net/md_5/bungee/chat/TextComponentSerializer.java index 0092aaca..37c6e86d 100644 --- a/api/src/main/java/net/md_5/bungee/chat/TextComponentSerializer.java +++ b/api/src/main/java/net/md_5/bungee/chat/TextComponentSerializer.java @@ -31,7 +31,7 @@ public class TextComponentSerializer extends BaseComponentSerializer implements public JsonElement serialize(TextComponent src, Type typeOfSrc, JsonSerializationContext context) { List extra = src.getExtra(); - if ( !src.hasFormatting() && ( extra == null || extra.size() == 0 ) ) + if ( !src.hasFormatting() && ( extra == null || extra.isEmpty() ) ) { return new JsonPrimitive( src.getText() ); }