From ade39333229b021a6dd90c41d45edb134428c6c2 Mon Sep 17 00:00:00 2001 From: StevenLawson Date: Wed, 20 Aug 2014 13:46:50 -0400 Subject: [PATCH] Switch popup to XML Player Command Entry. --- .../BukkitTelnetClient/BTC_MainPanel.java | 51 +++---------------- .../BTC_PlayerListDecoder.java | 8 +-- .../BukkitTelnetClient/PlayerInfo.java | 36 +------------ 3 files changed, 10 insertions(+), 85 deletions(-) diff --git a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.java b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.java index 30bfca5..05f226a 100644 --- a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.java +++ b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.java @@ -235,43 +235,6 @@ public class BTC_MainPanel extends javax.swing.JFrame }); } - public static enum ServerCommand - { - BAN("Ban", "glist ban %s"), - MUTE("Toggle Mute", "mute %s"), - KICK("Kick", "tempban %s 10s Kicked"), - TEMPBAN("Tempban 5m", "tempban %s 5m"), - SMITE("Smite", "smite %s"), - OP("Op", "op %s"), - DEOP("Deop", "deop %s"), - GTFO("GTFO", "gtfo %s"), - FREEZE("Toggle Freeze", "fr %s"), - CAGE("Cage", "cage %s"), - UNCAGE("Uncage", "cage %s off"), - DOOM("Doom", "doom %s"), - CREATIVE("Creative", "creative %s"), - SURVIVAL("Survival", "survival %s"); - - private final String commandName; - private final String commandFormat; - - private ServerCommand(String commandName, String commandFormat) - { - this.commandName = commandName; - this.commandFormat = commandFormat; - } - - public String getCommandName() - { - return commandName; - } - - public String getCommandFormat() - { - return commandFormat; - } - } - public static class PlayerListPopupItem extends JMenuItem { private final PlayerInfo player; @@ -290,15 +253,15 @@ public class BTC_MainPanel extends javax.swing.JFrame public static class PlayerListPopupItem_Command extends PlayerListPopupItem { - private final ServerCommand command; + private final PlayerCommandEntry command; - public PlayerListPopupItem_Command(String text, PlayerInfo player, ServerCommand command) + public PlayerListPopupItem_Command(String text, PlayerInfo player, PlayerCommandEntry command) { super(text, player); this.command = command; } - public ServerCommand getCommand() + public PlayerCommandEntry getCommand() { return command; } @@ -352,9 +315,9 @@ public class BTC_MainPanel extends javax.swing.JFrame final PlayerListPopupItem_Command source = (PlayerListPopupItem_Command) _source; final PlayerInfo _player = source.getPlayer(); - final ServerCommand _command = source.getCommand(); + final PlayerCommandEntry _command = source.getCommand(); - final String output = String.format(_command.getCommandFormat(), _player.getName()); + final String output = String.format(_command.getFormat(), _player.getName()); BTC_MainPanel.this.connectionManager.sendDelayedCommand(output, true, 100); } @@ -383,9 +346,9 @@ public class BTC_MainPanel extends javax.swing.JFrame } }; - for (final ServerCommand command : ServerCommand.values()) + for (final PlayerCommandEntry command : BukkitTelnetClient.config.getCommands()) { - final PlayerListPopupItem_Command item = new PlayerListPopupItem_Command(command.getCommandName(), player, command); + final PlayerListPopupItem_Command item = new PlayerListPopupItem_Command(command.getName(), player, command); item.addActionListener(popupAction); popup.add(item); } diff --git a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_PlayerListDecoder.java b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_PlayerListDecoder.java index 12dbed5..0f5fd17 100644 --- a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_PlayerListDecoder.java +++ b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_PlayerListDecoder.java @@ -1,13 +1,9 @@ package me.StevenLawson.BukkitTelnetClient; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; +import org.json.*; public class BTC_PlayerListDecoder { diff --git a/src/main/java/me/StevenLawson/BukkitTelnetClient/PlayerInfo.java b/src/main/java/me/StevenLawson/BukkitTelnetClient/PlayerInfo.java index 3007eea..c54abc2 100644 --- a/src/main/java/me/StevenLawson/BukkitTelnetClient/PlayerInfo.java +++ b/src/main/java/me/StevenLawson/BukkitTelnetClient/PlayerInfo.java @@ -1,9 +1,6 @@ package me.StevenLawson.BukkitTelnetClient; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; - -public final class PlayerInfo +public class PlayerInfo { private final String name; private final String ip; @@ -31,37 +28,6 @@ public final class PlayerInfo return displayName; } - @Override - public int hashCode() - { - return new HashCodeBuilder(17, 31). - append(name). - append(ip). - append(displayName). - toHashCode(); - } - - @Override - public boolean equals(Object obj) - { - if (!(obj instanceof PlayerInfo)) - { - return false; - } - - if (obj == this) - { - return true; - } - - PlayerInfo rhs = (PlayerInfo) obj; - return new EqualsBuilder(). - append(name, rhs.name). - append(ip, rhs.ip). - append(displayName, rhs.displayName). - isEquals(); - } - @Override public String toString() {