diff --git a/src/main/java/com/comandante/creeper/command/CastCommand.java b/src/main/java/com/comandante/creeper/command/CastCommand.java index ee7da4e6e6ed4708d53476ed9691cb30244f396f..4509b6ee62e35789358970b5ed676299b4598086 100644 --- a/src/main/java/com/comandante/creeper/command/CastCommand.java +++ b/src/main/java/com/comandante/creeper/command/CastCommand.java @@ -27,8 +27,7 @@ public class CastCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - try { - ; + this.execCommand(ctx, e, () -> { if (player.getCurrentHealth() <= 0) { write("You have no health and as such you can not attack."); return; @@ -81,8 +80,6 @@ public class CastCommand extends Command { return; } } - } finally { - super.messageReceived(ctx, e); - } + }); } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/command/ColorsCommand.java b/src/main/java/com/comandante/creeper/command/ColorsCommand.java index cae99b1a21598c3e400369544522d07e7fa9b212..576e3ef2eb53aacbe8af004c4ddec0581f15c23d 100644 --- a/src/main/java/com/comandante/creeper/command/ColorsCommand.java +++ b/src/main/java/com/comandante/creeper/command/ColorsCommand.java @@ -21,27 +21,24 @@ public class ColorsCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { - write ("BLACK: " + Color.BLACK + "This is an example of the color." + Color.RESET + "\r\n"); - write ("BLUE: " + Color.BLUE + "This is an example of the color." + Color.RESET + "\r\n"); - write ("CYAN: " + Color.CYAN + "This is an example of the color." + Color.RESET + "\r\n"); - write ("GREEN: " + Color.GREEN + "This is an example of the color." + Color.RESET + "\r\n"); - write ("MAGENTA: " + Color.MAGENTA + "This is an example of the color." + Color.RESET + "\r\n"); - write ("RED: " + Color.RED + "This is an example of the color." + Color.RESET + "\r\n"); - write ("WHITE: " + Color.WHITE + "This is an example of the color." + Color.RESET + "\r\n"); - write ("YELLOW: " + Color.YELLOW + "This is an example of the color." + Color.RESET + "\r\n"); - write ("\r\n\r\nBOLD COLORS\r\n"); - write ("BLACK: " + Color.BOLD_ON + Color.BLACK + "This is an example of the color." + Color.RESET + "\r\n"); - write ("BLUE: " + Color.BOLD_ON + Color.BLUE + "This is an example of the color." + Color.RESET + "\r\n"); - write ("CYAN: " + Color.BOLD_ON + Color.CYAN + "This is an example of the color." + Color.RESET + "\r\n"); - write ("GREEN: " + Color.BOLD_ON + Color.GREEN + "This is an example of the color." + Color.RESET + "\r\n"); - write ("MAGENTA: " + Color.BOLD_ON + Color.MAGENTA + "This is an example of the color." + Color.RESET + "\r\n"); - write ("RED: " + Color.BOLD_ON + Color.RED + "This is an example of the color." + Color.RESET + "\r\n"); - write ("WHITE: " + Color.BOLD_ON + Color.WHITE + "This is an example of the color." + Color.RESET + "\r\n"); - write ("YELLOW: " + Color.BOLD_ON + Color.YELLOW + "This is an example of the color." + Color.RESET + "\r\n"); - } finally { - super.messageReceived(ctx, e); - } + execCommand(ctx, e, () -> { + write("BLACK: " + Color.BLACK + "This is an example of the color." + Color.RESET + "\r\n"); + write("BLUE: " + Color.BLUE + "This is an example of the color." + Color.RESET + "\r\n"); + write("CYAN: " + Color.CYAN + "This is an example of the color." + Color.RESET + "\r\n"); + write("GREEN: " + Color.GREEN + "This is an example of the color." + Color.RESET + "\r\n"); + write("MAGENTA: " + Color.MAGENTA + "This is an example of the color." + Color.RESET + "\r\n"); + write("RED: " + Color.RED + "This is an example of the color." + Color.RESET + "\r\n"); + write("WHITE: " + Color.WHITE + "This is an example of the color." + Color.RESET + "\r\n"); + write("YELLOW: " + Color.YELLOW + "This is an example of the color." + Color.RESET + "\r\n"); + write("\r\n\r\nBOLD COLORS\r\n"); + write("BLACK: " + Color.BOLD_ON + Color.BLACK + "This is an example of the color." + Color.RESET + "\r\n"); + write("BLUE: " + Color.BOLD_ON + Color.BLUE + "This is an example of the color." + Color.RESET + "\r\n"); + write("CYAN: " + Color.BOLD_ON + Color.CYAN + "This is an example of the color." + Color.RESET + "\r\n"); + write("GREEN: " + Color.BOLD_ON + Color.GREEN + "This is an example of the color." + Color.RESET + "\r\n"); + write("MAGENTA: " + Color.BOLD_ON + Color.MAGENTA + "This is an example of the color." + Color.RESET + "\r\n"); + write("RED: " + Color.BOLD_ON + Color.RED + "This is an example of the color." + Color.RESET + "\r\n"); + write("WHITE: " + Color.BOLD_ON + Color.WHITE + "This is an example of the color." + Color.RESET + "\r\n"); + write("YELLOW: " + Color.BOLD_ON + Color.YELLOW + "This is an example of the color." + Color.RESET + "\r\n"); + }); } } diff --git a/src/main/java/com/comandante/creeper/command/Command.java b/src/main/java/com/comandante/creeper/command/Command.java index 09e7ef689de1b80e79559f6cc5f1582864fcc80f..b6f302627cacd73d07189dfcf91e054a5b5f50c8 100644 --- a/src/main/java/com/comandante/creeper/command/Command.java +++ b/src/main/java/com/comandante/creeper/command/Command.java @@ -43,6 +43,7 @@ public abstract class Command extends SimpleChannelUpstreamHandler { public List<String> originalMessageParts; public WorldExporter worldExporter; public static final Logger log = Logger.getLogger(Command.class); + public String rootCommand; protected Command(GameManager gameManager, List<String> validTriggers, String description, String correctUsage) { this(gameManager, validTriggers, description, correctUsage, Sets.<PlayerRole>newHashSet()); @@ -64,54 +65,83 @@ public abstract class Command extends SimpleChannelUpstreamHandler { this.roles = roles; } + private void init(MessageEvent e) { + this.creeperSession = (CreeperSession) e.getChannel().getAttachment();; + this.originalMessageParts = getOriginalMessageParts(e); + this.rootCommand = getRootCommand(e); + this.player = playerManager.getPlayer(Main.createPlayerId(creeperSession.getUsername().get())); + this.playerId = player.getPlayerId(); + this.currentRoom = gameManager.getRoomManager().getPlayerCurrentRoom(player).get(); + this.mapMatrix = mapsManager.getFloorMatrixMaps().get(currentRoom.getFloorId()); + this.currentRoomCoords = mapMatrix.getCoords(currentRoom.getRoomId()); + } + @Override public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception { try { if (e instanceof MessageEvent) { - this.creeperSession = extractCreeperSession(e.getChannel()); - this.originalMessageParts = getOriginalMessageParts((MessageEvent) e); - this.player = playerManager.getPlayer(extractPlayerId(creeperSession)); - this.playerId = player.getPlayerId(); - this.currentRoom = gameManager.getRoomManager().getPlayerCurrentRoom(player).get(); - this.mapMatrix = mapsManager.getFloorMatrixMaps().get(currentRoom.getFloorId()); - this.currentRoomCoords = mapMatrix.getCoords(currentRoom.getRoomId()); + init((MessageEvent) e); } } finally { super.handleUpstream(ctx, e); } } - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - try { - CreeperSession creeperSession = extractCreeperSession(e.getChannel()); - e.getChannel().getPipeline().remove(ctx.getHandler()); - if (creeperSession.getGrabMerchant().isPresent()) { - return; + public void execCommandThreadSafe(ChannelHandlerContext ctx, MessageEvent e, Class c, CommandRunnable commandRunnable) throws Exception { + synchronized (c) { + try { + commandRunnable.run(); + } catch (Exception ex) { + log.error("Problem running command.", ex); + } finally { + removeCurrentHandlerAndWritePrompt(ctx, e); + ctx.sendUpstream(e); } - String playerId = extractPlayerId(creeperSession); - String prompt = gameManager.buildPrompt(playerId); - gameManager.getChannelUtils().write(playerId, prompt, true); + } + } + + public void execCommandBackgroundThread(ChannelHandlerContext ctx, MessageEvent e, CommandRunnable commandRunnable) throws Exception { + try { + new Thread(() -> { + try { + commandRunnable.run(); + } catch (Exception ex) { + log.error("Problem running command.", ex); + } + }).start(); } finally { - super.messageReceived(ctx, e); + removeCurrentHandlerAndWritePrompt(ctx, e); + ctx.sendUpstream(e); } } - public CreeperSession extractCreeperSession(Channel channel) { - return (CreeperSession) channel.getAttachment(); + public void execCommand(ChannelHandlerContext ctx, MessageEvent e, CommandRunnable commandRunnable) throws Exception { + try { + commandRunnable.run(); + } finally { + removeCurrentHandlerAndWritePrompt(ctx, e); + ctx.sendUpstream(e); + } } + private void removeCurrentHandlerAndWritePrompt(ChannelHandlerContext ctx, MessageEvent e) { + removeCurrentHandlerAndWritePrompt(ctx, e, true); + } - public String extractPlayerId(CreeperSession creeperSession) { - return Main.createPlayerId(creeperSession.getUsername().get()); + public void removeCurrentHandlerAndWritePrompt(ChannelHandlerContext ctx, MessageEvent e, boolean newLine) { + e.getChannel().getPipeline().remove(ctx.getHandler()); + if (creeperSession.getGrabMerchant().isPresent()) { + return; + } + gameManager.getChannelUtils().write(playerId, getPrompt(), newLine); } - public String getRootCommand(MessageEvent e) { + private String getRootCommand(MessageEvent e) { String origMessage = (String) e.getMessage(); return origMessage.split(" ")[0].toLowerCase(); } - public List<String> getOriginalMessageParts(MessageEvent e) { + private List<String> getOriginalMessageParts(MessageEvent e) { String origMessage = (String) e.getMessage(); return new ArrayList<>(Arrays.asList(origMessage.split(" "))); } @@ -128,11 +158,11 @@ public abstract class Command extends SimpleChannelUpstreamHandler { gameManager.writeToPlayerCurrentRoom(playerId, msg); } - public void currentRoomLogic() { + public void printCurrentRoomInformation() { gameManager.currentRoomLogic(playerId); } - public void currentRoomLogic(Room playerCurrentRoom) { + public void printCurrentRoomInformation(Room playerCurrentRoom) { gameManager.currentRoomLogic(playerId, playerCurrentRoom); } @@ -144,42 +174,10 @@ public abstract class Command extends SimpleChannelUpstreamHandler { return description; } - public static boolean isInteger(String s) { - try { - Integer.parseInt(s); - } catch(NumberFormatException e) { - return false; - } catch(NullPointerException e) { - return false; - } - // only got here if we didn't return false - return true; - } - public Command copy() throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { Class<Command> clazz = (Class<Command>) this.getClass(); return clazz.getConstructor(GameManager.class).newInstance(gameManager); } - public <T> T createObj(String nameclass) throws ClassNotFoundException, - InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { - - Class<T> clazz = (Class<T>) Class.forName(nameclass); - - // assumes the target class has a no-args Constructor - return clazz.getConstructor(GameManager.class).newInstance(gameManager); - } - - public static boolean isLong(String s) { - try { - Long.parseLong(s); - } catch(NumberFormatException e) { - return false; - } catch(NullPointerException e) { - return false; - } - // only got here if we didn't return false - return true; - } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/command/CommandRunnable.java b/src/main/java/com/comandante/creeper/command/CommandRunnable.java new file mode 100644 index 0000000000000000000000000000000000000000..2389edbe270db49b79869e96932abd3d64a31e62 --- /dev/null +++ b/src/main/java/com/comandante/creeper/command/CommandRunnable.java @@ -0,0 +1,6 @@ +package com.comandante.creeper.command; + + +public interface CommandRunnable { + void run() throws java.lang.Exception; +} diff --git a/src/main/java/com/comandante/creeper/command/CoolDownCommand.java b/src/main/java/com/comandante/creeper/command/CoolDownCommand.java index da6f57c1db0f584d1f1e65af0245765e65e73920..7dace727f1ec9578d14c494e24eecf8f0dc280b0 100644 --- a/src/main/java/com/comandante/creeper/command/CoolDownCommand.java +++ b/src/main/java/com/comandante/creeper/command/CoolDownCommand.java @@ -19,15 +19,13 @@ public class CoolDownCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { if (player.isActiveCoolDown()) { write(gameManager.renderCoolDownString(player.getCoolDowns())); } else { write("No active cooldowns.\r\n"); } - } finally { - super.messageReceived(ctx, e); - } + }); + } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/command/CountdownCommand.java b/src/main/java/com/comandante/creeper/command/CountdownCommand.java index 9151639aab9bffaa6ae5b58402b076edcf49b5b7..155e7190c50db9642547f389fd9ef9312314e232 100644 --- a/src/main/java/com/comandante/creeper/command/CountdownCommand.java +++ b/src/main/java/com/comandante/creeper/command/CountdownCommand.java @@ -10,6 +10,8 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; import java.util.*; +import java.util.function.BiConsumer; +import java.util.function.Consumer; public class CountdownCommand extends Command { @@ -23,39 +25,29 @@ public class CountdownCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { - new Thread(new PrintCountdown(playerManager, channelUtils)).start(); - } finally { - super.messageReceived(ctx, e); - } - } - - public static class PrintCountdown implements Runnable { - - private PlayerManager playerManager; - private ChannelCommunicationUtils channelUtils; - - public PrintCountdown(PlayerManager playerManager, ChannelCommunicationUtils channelUtils) { - this.playerManager = playerManager; - this.channelUtils = channelUtils; - } - - @Override - public void run() { - ArrayList<String> strings = Lists.newArrayList("... ***** COUNTDOWN ***** ...", ". 5 .", ". 4 .", ". 3 .", ". 2 .", ". 1 .", "... ***** SMOKE! ***** ..."); - for (String s : strings) { - Iterator<Map.Entry<String, Player>> players = playerManager.getPlayers(); - while (players.hasNext()) { - Map.Entry<String, Player> next = players.next(); - channelUtils.write(next.getValue().getPlayerId(), Color.BOLD_ON + Color.GREEN + s + Color.RESET + "\r\n", true); - } + execCommandBackgroundThread(ctx, e, () -> { + ArrayList<String> countDownMessages = + Lists.newArrayList("... ***** COUNTDOWN ***** ...", + ". 5 .", + ". 4 .", + ". 3 .", + ". 2 .", + ". 1 .", + "... ***** SMOKE! ***** ..."); + + + countDownMessages.forEach(message -> { + writeMessageToEveryPlayer(message); try { Thread.sleep(900); - } catch (InterruptedException e) { - e.printStackTrace(); + } catch (InterruptedException ex) { + log.error("Problem while printing countdown message", ex); } - } - } + }); + }); + } + + private void writeMessageToEveryPlayer(String message) { + playerManager.getAllPlayersMap().forEach((playerId1, player1) -> channelUtils.write(playerId1, Color.BOLD_ON + Color.GREEN + message + Color.RESET + "\r\n", true)); } } diff --git a/src/main/java/com/comandante/creeper/command/DelCommand.java b/src/main/java/com/comandante/creeper/command/DelCommand.java index 32c8a17681b6dbcd1db5d0aa34c51ad1bf93340f..d25cc8ba65e3dec50fffe536473867900efbe16f 100644 --- a/src/main/java/com/comandante/creeper/command/DelCommand.java +++ b/src/main/java/com/comandante/creeper/command/DelCommand.java @@ -22,7 +22,12 @@ public class DelCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; + execCommand(ctx, e, new CommandRunnable() { + @Override + public void run() { + + } + }); try { if (originalMessageParts.size() <= 1) { write(returnAllSettings()); diff --git a/src/main/java/com/comandante/creeper/command/DropCommand.java b/src/main/java/com/comandante/creeper/command/DropCommand.java index b35c743077b98568dc98f1acd6583b7e64e42ab3..0f90e752defa7c89904950544041ee6c5f6fc68d 100644 --- a/src/main/java/com/comandante/creeper/command/DropCommand.java +++ b/src/main/java/com/comandante/creeper/command/DropCommand.java @@ -21,8 +21,7 @@ public class DropCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { if (originalMessageParts.size() == 1) { write("No item specified."); return; @@ -40,8 +39,6 @@ public class DropCommand extends Command { return; } } - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/EquipCommand.java b/src/main/java/com/comandante/creeper/command/EquipCommand.java index 1db17521e8c7857fd659613b5aaef15aa71e403c..eba3949e713809c3a6a27953fe7388d39ef9893f 100644 --- a/src/main/java/com/comandante/creeper/command/EquipCommand.java +++ b/src/main/java/com/comandante/creeper/command/EquipCommand.java @@ -21,8 +21,7 @@ public class EquipCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { if (originalMessageParts.size() == 1) { write("No equipment item specified."); return; @@ -44,8 +43,6 @@ public class EquipCommand extends Command { } else { write("Your inventory is empty."); } - } finally { - super.messageReceived(ctx, e); - } + }); } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/command/FightKillCommand.java b/src/main/java/com/comandante/creeper/command/FightKillCommand.java index e7d91f5a30aa1c317f4379885ebddb36e4226a56..6abad3319e571df2343078f174c16c2d5d4c5096 100644 --- a/src/main/java/com/comandante/creeper/command/FightKillCommand.java +++ b/src/main/java/com/comandante/creeper/command/FightKillCommand.java @@ -23,8 +23,7 @@ public class FightKillCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { if (player.getCurrentHealth() <= 0) { write("You have no health and as such you can not attack."); return; @@ -57,8 +56,6 @@ public class FightKillCommand extends Command { } } write("There's no NPC here to fight by that name."); - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/ForageCommand.java b/src/main/java/com/comandante/creeper/command/ForageCommand.java index 0315af61f65108fcfb737c5a6f4610d4f83e8eb7..dd05e16e04e380715cc2f029623c6436a464c9e0 100644 --- a/src/main/java/com/comandante/creeper/command/ForageCommand.java +++ b/src/main/java/com/comandante/creeper/command/ForageCommand.java @@ -19,11 +19,6 @@ public class ForageCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - try { - ; - gameManager.getForageManager().getForageForRoom(currentRoom, player); - } finally { - super.messageReceived(ctx, e); - } + execCommand(ctx, e, () -> gameManager.getForageManager().getForageForRoom(currentRoom, player)); } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/command/GoldCommand.java b/src/main/java/com/comandante/creeper/command/GoldCommand.java index 117390fcf56c8e96024f9b3c456079c8d035c66b..a407223dc78b4fe7a44d7c205b24a3c6a09f6b6b 100644 --- a/src/main/java/com/comandante/creeper/command/GoldCommand.java +++ b/src/main/java/com/comandante/creeper/command/GoldCommand.java @@ -23,11 +23,6 @@ public class GoldCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { - write("You have " + NumberFormat.getNumberInstance(Locale.US).format(playerManager.getPlayerMetadata(playerId).getGold()) + Color.YELLOW + " gold." + Color.RESET); - } finally { - super.messageReceived(ctx, e); - } + execCommand(ctx, e, () -> write("You have " + NumberFormat.getNumberInstance(Locale.US).format(playerManager.getPlayerMetadata(playerId).getGold()) + Color.YELLOW + " gold." + Color.RESET)); } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/command/GossipCommand.java b/src/main/java/com/comandante/creeper/command/GossipCommand.java index 8f17295f257038d4efc9c388e1a1798dd75ca1b0..a3e312fc502e929c9128c865bbd41e37a34c8db1 100644 --- a/src/main/java/com/comandante/creeper/command/GossipCommand.java +++ b/src/main/java/com/comandante/creeper/command/GossipCommand.java @@ -10,6 +10,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; import java.util.*; +import java.util.function.BiConsumer; import static com.comandante.creeper.server.Color.*; @@ -25,8 +26,7 @@ public class GossipCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { if (originalMessageParts.size() == 1) { write("Nothing to gossip about?"); return; @@ -41,21 +41,16 @@ public class GossipCommand extends Command { } catch (Exception ex) { log.error("Problem executing bot command from gossip channel!", ex); } - Iterator<Map.Entry<String, Player>> players = playerManager.getPlayers(); - String gossipMessage = null; - while (players.hasNext()) { - final Player next = players.next().getValue(); - gossipMessage = WHITE + "[" + RESET + MAGENTA + player.getPlayerName() + WHITE + "] " + RESET + CYAN + msg + RESET; - if (next.getPlayerId().equals(playerId)) { + String gossipMessage = WHITE + "[" + RESET + MAGENTA + this.player.getPlayerName() + WHITE + "] " + RESET + CYAN + msg + RESET; + playerManager.getAllPlayersMap().forEach((s, destinationPlayer) -> { + if (destinationPlayer.getPlayerId().equals(playerId)) { write(gossipMessage); } else { - channelUtils.write(next.getPlayerId(), gossipMessage + "\r\n", true); + channelUtils.write(destinationPlayer.getPlayerId(), gossipMessage + "\r\n", true); } - } + }); gameManager.getGossipCache().addGossipLine(gossipMessage); - } finally { - super.messageReceived(ctx, e); - } + }); } private String getBotCommandOutput(String cmd) { diff --git a/src/main/java/com/comandante/creeper/command/HelpCommand.java b/src/main/java/com/comandante/creeper/command/HelpCommand.java index 6dd31b1424ba98b086b9dd2f67fb36400b4238d9..57c162ff19fcc4da635d4b159b920054888b5066 100644 --- a/src/main/java/com/comandante/creeper/command/HelpCommand.java +++ b/src/main/java/com/comandante/creeper/command/HelpCommand.java @@ -27,8 +27,7 @@ public class HelpCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { StringBuilder sb = new StringBuilder(); Table t = new Table(2, BorderStyle.CLASSIC_COMPATIBLE, ShownBorders.HEADER_FIRST_AND_LAST_COLLUMN); @@ -52,8 +51,6 @@ public class HelpCommand extends Command { sb.append(t.render()); sb.append("\r\n"); write(sb.toString()); - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/InventoryCommand.java b/src/main/java/com/comandante/creeper/command/InventoryCommand.java index 482680f3b288bba879f807269676baaba5c66b18..118faaddae4c84bc5c7e6be775e3a500df186f64 100644 --- a/src/main/java/com/comandante/creeper/command/InventoryCommand.java +++ b/src/main/java/com/comandante/creeper/command/InventoryCommand.java @@ -24,8 +24,7 @@ public class InventoryCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + this.execCommand(ctx, e, () -> { List<Item> inventory = player.getInventory(); if (inventory == null) { write("You aren't carrying anything."); @@ -37,8 +36,6 @@ public class InventoryCommand extends Command { String join = StringUtils.join(player.getRolledUpIntentory().toArray(), "\r\n"); inventoryString.append(join); write(inventoryString.toString()); - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/LookCommand.java b/src/main/java/com/comandante/creeper/command/LookCommand.java index c62f2d910ee23adab279de58c299273c621525c2..8c3709804659a90d10dba2e218d5a887230cd091 100644 --- a/src/main/java/com/comandante/creeper/command/LookCommand.java +++ b/src/main/java/com/comandante/creeper/command/LookCommand.java @@ -23,10 +23,9 @@ public class LookCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { if (originalMessageParts.size() == 1) { - currentRoomLogic(); + printCurrentRoomInformation(); return; } originalMessageParts.remove(0); @@ -57,8 +56,6 @@ public class LookCommand extends Command { write(gameManager.getLookString(currentNpc, Levels.getLevel(gameManager.getStatsModifierFactory().getStatsModifier(player).getExperience())) + "\r\n"); } } - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/LootCommand.java b/src/main/java/com/comandante/creeper/command/LootCommand.java index d3878dde2bc19605cda1e5b6f9e1ea326f9bc188..68ede92d144e441bb4ef843f80c38a89df22b852 100644 --- a/src/main/java/com/comandante/creeper/command/LootCommand.java +++ b/src/main/java/com/comandante/creeper/command/LootCommand.java @@ -12,6 +12,7 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; import java.util.Set; +import java.util.function.Consumer; public class LootCommand extends Command { @@ -25,10 +26,9 @@ public class LootCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { if (originalMessageParts.size() > 1) { - for (Item item : player.getInventory()) { + player.getInventory().forEach(item -> { if (item.getItemTypeId() == Item.CORPSE_ID_RESERVED) { Loot loot = item.getLoot(); if (loot != null) { @@ -38,22 +38,19 @@ public class LootCommand extends Command { player.incrementGold(gold); } Set<Item> items = lootManager.lootItemsReturn(loot); - for (Item i: items) { - gameManager.acquireItem(player, i.getItemId()); - write("You looted " + i.getItemName() + " from a " + item.getItemName() + ".\r\n"); - } + items.forEach(i -> { + gameManager.acquireItem(player, i.getItemId()); + write("You looted " + i.getItemName() + " from a " + item.getItemName() + ".\r\n"); + }); if (gold < 0 && items.size() == 0) { write("You looted nothing from " + item.getItemName() + "\r\n"); } } player.removeInventoryId(item.getItemId()); entityManager.removeItem(item); - return; } - } + }); } - } finally { - super.messageReceived(ctx, e); - } + }); } -} \ No newline at end of file +} diff --git a/src/main/java/com/comandante/creeper/command/MapCommand.java b/src/main/java/com/comandante/creeper/command/MapCommand.java index f896400aeddae6cd6581a1d939bccfa010d2ed11..769779c8b27b8c6cecb15b584ed93963655c9af6 100644 --- a/src/main/java/com/comandante/creeper/command/MapCommand.java +++ b/src/main/java/com/comandante/creeper/command/MapCommand.java @@ -5,6 +5,7 @@ import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.player.Player; import com.comandante.creeper.world.Coords; import com.comandante.creeper.world.Room; +import org.apache.commons.lang.math.NumberUtils; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; @@ -24,26 +25,23 @@ public class MapCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { - if (originalMessageParts.size() > 1 && isInteger(originalMessageParts.get(1))) { + execCommand(ctx, e, () -> { + if (originalMessageParts.size() > 1 && NumberUtils.isNumber(originalMessageParts.get(1))) { int max = Integer.parseInt(originalMessageParts.get(1)); write(mapsManager.drawMap(currentRoom.getRoomId(), new Coords(max, max))); } else { - Player player = playerManager.getPlayer(playerId); - final Room playerCurrentRoom = roomManager.getPlayerCurrentRoom(player).get(); + Player player1 = playerManager.getPlayer(playerId); + final Room playerCurrentRoom = roomManager.getPlayerCurrentRoom(player1).get(); StringBuilder sb = new StringBuilder(); if (playerCurrentRoom.getMapData().isPresent()) { sb.append(playerCurrentRoom.getMapData().get()).append("\r\n"); - channelUtils.write(player.getPlayerId(), sb.toString()); + channelUtils.write(player1.getPlayerId(), sb.toString()); } else { - channelUtils.write(player.getPlayerId(), "No map data."); + channelUtils.write(player1.getPlayerId(), "No map data."); } } - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/MovementCommand.java b/src/main/java/com/comandante/creeper/command/MovementCommand.java index 4a1e28127c62ec9a38704b055e1ba5cd32c98f23..6fac2a96ec4bee83ad485018731dbb5aa99bf3f2 100644 --- a/src/main/java/com/comandante/creeper/command/MovementCommand.java +++ b/src/main/java/com/comandante/creeper/command/MovementCommand.java @@ -35,66 +35,63 @@ public class MovementCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - try { - ; + this.execCommand(ctx, e, () -> { if (player.isActiveFights()) { - write("You can't move while in a fight!"); + MovementCommand.this.write("You can't move while in a fight!"); return; } if (player.isActive(CoolDownType.DEATH)) { - write("You are dead and can not move."); + MovementCommand.this.write("You are dead and can not move."); return; } for (String effectId : playerManager.getPlayerMetadata(playerId).getEffects()) { Effect effect = gameManager.getEntityManager().getEffectEntity(effectId); if (effect.isFrozenMovement()) { - write("You are frozen and can not move."); + MovementCommand.this.write("You are frozen and can not move."); return; } } - final String command = getRootCommand(e); + final String command = rootCommand; PlayerMovement playerMovement = null; if (!validTriggers.contains(command.toLowerCase())) { throw new RuntimeException("Malformed movement command."); } else if (northTriggers.contains(command.toLowerCase()) && currentRoom.getNorthId().isPresent()) { Room destinationRoom = roomManager.getRoom(currentRoom.getNorthId().get()); - playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), this, "exited to the north.", "south"); + playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), "exited to the north.", "south"); } else if (southTriggers.contains(command.toLowerCase()) && currentRoom.getSouthId().isPresent()) { Room destinationRoom = roomManager.getRoom(currentRoom.getSouthId().get()); - playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), this, "exited to the south.", "north"); + playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), "exited to the south.", "north"); } else if (eastTriggers.contains(command.toLowerCase()) && currentRoom.getEastId().isPresent()) { Room destinationRoom = roomManager.getRoom(currentRoom.getEastId().get()); - playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), this, "exited to the east.", "west"); + playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), "exited to the east.", "west"); } else if (westTriggers.contains(command.toLowerCase()) && currentRoom.getWestId().isPresent()) { Room destinationRoom = roomManager.getRoom(currentRoom.getWestId().get()); - playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), this, "exited to the west.", "east"); + playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), "exited to the west.", "east"); } else if (upTriggers.contains(command.toLowerCase()) && currentRoom.getUpId().isPresent()) { Room destinationRoom = roomManager.getRoom(currentRoom.getUpId().get()); - playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), this, "exited up.", "down"); + playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), "exited up.", "down"); } else if (downTriggers.contains(command.toLowerCase()) && currentRoom.getDownId().isPresent()) { Room destinationRoom = roomManager.getRoom(currentRoom.getDownId().get()); - playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), this, "exited down.", "up"); + playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), "exited down.", "up"); } else if (enterTriggers.contains(command.toLowerCase())) { - Optional<RemoteExit> remoteExitOptional = doesEnterExitExist(); + Optional<RemoteExit> remoteExitOptional = MovementCommand.this.doesEnterExitExist(); if (remoteExitOptional.isPresent()) { Room destinationRoom = roomManager.getRoom(remoteExitOptional.get().getRoomId()); - playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), this, "entered " + remoteExitOptional.get().getExitDetail() + ".", "N/A"); + playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), "entered " + remoteExitOptional.get().getExitDetail() + ".", "N/A"); } else { - write("There's no where to go with that name. (" + command + ")"); + MovementCommand.this.write("There's no where to go with that name. (" + command + ")"); return; } } else { - write("There's no exit in that direction. (" + command + ")"); + MovementCommand.this.write("There's no exit in that direction. (" + command + ")"); return; } player.movePlayer(playerMovement); if (playerMovement != null) { player.setReturnDirection(Optional.of(playerMovement.getReturnDirection())); - currentRoomLogic(roomManager.getRoom(playerMovement.getDestinationRoomId())); + MovementCommand.this.printCurrentRoomInformation(roomManager.getRoom(playerMovement.getDestinationRoomId())); } - } finally { - super.messageReceived(ctx, e); - } + }); } private Optional<RemoteExit> doesEnterExitExist() { diff --git a/src/main/java/com/comandante/creeper/command/NexusCommand.java b/src/main/java/com/comandante/creeper/command/NexusCommand.java index 6be9c002be3a871cab22bdfe6ca8dba9fd69fbda..be8c757e23542ac2efcb2afd999d9a4a50a43bb3 100644 --- a/src/main/java/com/comandante/creeper/command/NexusCommand.java +++ b/src/main/java/com/comandante/creeper/command/NexusCommand.java @@ -20,8 +20,7 @@ public class NexusCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { if (gameManager.getCreeperConfiguration().isIrcEnabled) { originalMessageParts.remove(0); String transferPhrase = Joiner.on(" ").join(originalMessageParts); @@ -29,8 +28,6 @@ public class NexusCommand extends Command { gameManager.getIrcBotService().getBot().getUserChannelDao().getChannel(gameManager.getCreeperConfiguration().ircChannel).send().message(player.getPlayerName() + ": " + transferPhrase); } } - } finally { - super.messageReceived(ctx, e); - } + }); } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/command/OpCommand.java b/src/main/java/com/comandante/creeper/command/OpCommand.java index 45bac4b2e87f12008b57bb7d133412acd286d9e1..4088c41b7a89f902e0a72ec91870d824c5ca9b61 100644 --- a/src/main/java/com/comandante/creeper/command/OpCommand.java +++ b/src/main/java/com/comandante/creeper/command/OpCommand.java @@ -32,8 +32,7 @@ public class OpCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { //ghetto and will only work for one channel bots. if (originalMessageParts.size() <= 1) { return; @@ -48,11 +47,9 @@ public class OpCommand extends Command { } ImmutableSortedSet<Channel> channels = user.getChannels(); for (Channel channel : channels) { - channel.send().op(user); - write("Ops given in channel " + channel.getName()); - } - } finally { - super.messageReceived(ctx, e); - } + channel.send().op(user); + write("Ops given in channel " + channel.getName()); + } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/OpenCommand.java b/src/main/java/com/comandante/creeper/command/OpenCommand.java index bd6aee759ca893813ac36af77a5c35d1a3c6e687..6c2a1ac21f9e50f0a0b098f6936b18b88424b8ee 100644 --- a/src/main/java/com/comandante/creeper/command/OpenCommand.java +++ b/src/main/java/com/comandante/creeper/command/OpenCommand.java @@ -5,18 +5,14 @@ import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.merchant.Merchant; import com.comandante.creeper.merchant.lockers.LockerCommand; import com.google.common.base.Joiner; -import com.google.common.base.Optional; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; -import org.jboss.netty.channel.SimpleChannelUpstreamHandler; import java.util.Arrays; import java.util.List; +import java.util.Optional; import java.util.Set; -/** - * Created by kearney on 6/12/15. - */ public class OpenCommand extends Command { final static List<String> validTriggers = Arrays.asList("open", "o"); @@ -29,10 +25,10 @@ public class OpenCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + OpenCommand openCommand = this; + execCommand(ctx, e, () -> { if (creeperSession.getGrabMerchant().isPresent()) { - creeperSession.setGrabMerchant(Optional.<CreeperEntry<Merchant, SimpleChannelUpstreamHandler>>absent()); + creeperSession.setGrabMerchant(Optional.empty()); return; } originalMessageParts.remove(0); @@ -45,12 +41,9 @@ public class OpenCommand extends Command { if (merchant.getValidTriggers().contains(desiredMerchantTalk)) { write(merchant.getWelcomeMessage() + "\r\n"); write(LockerCommand.getPrompt()); - creeperSession.setGrabMerchant(Optional.of( - new CreeperEntry<Merchant, SimpleChannelUpstreamHandler>(merchant, this))); + creeperSession.setGrabMerchant(Optional.of(new CreeperEntry<>(merchant, openCommand))); } } - } finally { - super.messageReceived(ctx, e); - } + }); } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/command/PickUpCommand.java b/src/main/java/com/comandante/creeper/command/PickUpCommand.java index cb72513542363045192c7b20bab45d4b8ddd0ebf..6a8614dbc4aa1f8a19aff2431008c2dd33d23324 100644 --- a/src/main/java/com/comandante/creeper/command/PickUpCommand.java +++ b/src/main/java/com/comandante/creeper/command/PickUpCommand.java @@ -22,7 +22,7 @@ public class PickUpCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - try { + execCommand(ctx, e, () -> { Set<String> itemIds = currentRoom.getItemIds(); originalMessageParts.remove(0); String desiredPickUpItem = Joiner.on(" ").join(originalMessageParts); @@ -38,8 +38,6 @@ public class PickUpCommand extends Command { } } } - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/QuitCommand.java b/src/main/java/com/comandante/creeper/command/QuitCommand.java index 2d0c398c6416661604f37909c8250fb0ddb639fa..f21ee77d6055b839e2d0cd75c617465a61fce33d 100644 --- a/src/main/java/com/comandante/creeper/command/QuitCommand.java +++ b/src/main/java/com/comandante/creeper/command/QuitCommand.java @@ -19,11 +19,12 @@ public class QuitCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - if (player.getActiveFights().size() > 0) { - write("You can't quit in the middle of a fight!"); - } else { - gameManager.getPlayerManager().removePlayer(creeperSession.getUsername().get()); - } + execCommand(ctx, e, () -> { + if (player.getActiveFights().size() > 0) { + write("You can't quit in the middle of a fight!"); + } else { + gameManager.getPlayerManager().removePlayer(creeperSession.getUsername().get()); + } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/RecentChangesCommand.java b/src/main/java/com/comandante/creeper/command/RecentChangesCommand.java index c1a64a9acce8fbfa42cee219dabfc2022390a0ff..997b96600784e9ff88d70823ce74fcc459a7f12c 100644 --- a/src/main/java/com/comandante/creeper/command/RecentChangesCommand.java +++ b/src/main/java/com/comandante/creeper/command/RecentChangesCommand.java @@ -7,6 +7,7 @@ import org.jboss.netty.channel.MessageEvent; import java.util.Arrays; import java.util.List; +import java.util.concurrent.ExecutionException; public class RecentChangesCommand extends Command { @@ -20,11 +21,12 @@ public class RecentChangesCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { - write(RecentChangesManager.getRecentChanges()); - } finally { - super.messageReceived(ctx, e); - } + execCommandBackgroundThread(ctx, e, () -> { + try { + write(RecentChangesManager.getRecentChanges()); + } catch (ExecutionException ex) { + log.error("Unable to retrieve recent changes.", ex); + } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/RecentGossipCommand.java b/src/main/java/com/comandante/creeper/command/RecentGossipCommand.java index 6b7ddad0daabc34d9a58a66ccc8f7ff5bc3917d8..ea11c2fd0fa603f6a296a4c5032aabf5563e5bae 100644 --- a/src/main/java/com/comandante/creeper/command/RecentGossipCommand.java +++ b/src/main/java/com/comandante/creeper/command/RecentGossipCommand.java @@ -20,8 +20,7 @@ public class RecentGossipCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { List<String> recent = null; if (originalMessageParts.size() > 1) { String size = originalMessageParts.get(1); @@ -38,8 +37,6 @@ public class RecentGossipCommand extends Command { for (String line : recent) { write(line + "\r\n"); } - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/SayCommand.java b/src/main/java/com/comandante/creeper/command/SayCommand.java index 27c79df29c2f8cfc06b6d425be1792e202857c73..11715d00ade27391699e91415833ad14a9ea6c5b 100644 --- a/src/main/java/com/comandante/creeper/command/SayCommand.java +++ b/src/main/java/com/comandante/creeper/command/SayCommand.java @@ -26,20 +26,19 @@ public class SayCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { originalMessageParts.remove(0); String message = Joiner.on(" ").join(originalMessageParts); Set<Player> presentPlayers = roomManager.getPresentPlayers(currentRoom); for (Player presentPlayer : presentPlayers) { - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(RED); - stringBuilder.append("<").append(player.getPlayerName()).append("> ").append(message); - stringBuilder.append(RESET); + StringBuilder sb = new StringBuilder(); + sb.append(RED); + sb.append("<").append(player.getPlayerName()).append("> ").append(message); + sb.append(RESET); if (presentPlayer.getPlayerId().equals(playerId)) { - write(stringBuilder.toString()); + write(sb.toString()); } else { - channelUtils.write(presentPlayer.getPlayerId(), stringBuilder.append("\r\n").toString(), true); + channelUtils.write(presentPlayer.getPlayerId(), sb.append("\r\n").toString(), true); } } if (gameManager.getCreeperConfiguration().isIrcEnabled && (Objects.equals(gameManager.getCreeperConfiguration().ircBridgeRoomId, currentRoom.getRoomId()))) { @@ -47,8 +46,6 @@ public class SayCommand extends Command { gameManager.getIrcBotService().getBot().getUserChannelDao().getChannel(gameManager.getCreeperConfiguration().ircChannel).send().message(player.getPlayerName() + ": " + message); } } - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/SetCommand.java b/src/main/java/com/comandante/creeper/command/SetCommand.java index ab1e597a1c407bb215dd68a17e8cbcbbeb623070..e675700837ee38dd5c628d676b33d52bfcb181d7 100644 --- a/src/main/java/com/comandante/creeper/command/SetCommand.java +++ b/src/main/java/com/comandante/creeper/command/SetCommand.java @@ -21,8 +21,7 @@ public class SetCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { write("'set help' for full settings help.\r\n"); if (originalMessageParts.size() <= 1) { write(returnAllSettings()); @@ -42,9 +41,7 @@ public class SetCommand extends Command { } else { write ("Unknown Setting.\r\n"); } - } finally { - super.messageReceived(ctx, e); - } + }); } private String returnAllSettings() { diff --git a/src/main/java/com/comandante/creeper/command/ShowCommand.java b/src/main/java/com/comandante/creeper/command/ShowCommand.java index 0ef1a975ae13db73b16640ba32b6d1492215fefc..d60622c0edb7605022d7780758229c9d0df5e05e 100644 --- a/src/main/java/com/comandante/creeper/command/ShowCommand.java +++ b/src/main/java/com/comandante/creeper/command/ShowCommand.java @@ -19,8 +19,7 @@ public class ShowCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { if (originalMessageParts.size() <= 1) { return; } @@ -34,8 +33,6 @@ public class ShowCommand extends Command { } } } - } finally { - super.messageReceived(ctx, e); - } + }); } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/command/TalkCommand.java b/src/main/java/com/comandante/creeper/command/TalkCommand.java index a7eec7a0f1aca4483f489e3ff8fcc18b734d64ae..6abae37484b01e6f878277ec5979744ad4d31ed4 100644 --- a/src/main/java/com/comandante/creeper/command/TalkCommand.java +++ b/src/main/java/com/comandante/creeper/command/TalkCommand.java @@ -8,13 +8,13 @@ import com.comandante.creeper.merchant.MerchantCommandHandler; import com.comandante.creeper.merchant.bank.commands.BankCommand; import com.comandante.creeper.merchant.lockers.LockerCommand; import com.google.common.base.Joiner; -import com.google.common.base.Optional; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelUpstreamHandler; import java.util.Arrays; import java.util.List; +import java.util.Optional; import java.util.Set; public class TalkCommand extends Command { @@ -29,10 +29,10 @@ public class TalkCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + TalkCommand talkCommand = this; + execCommand(ctx, e, () -> { if (creeperSession.getGrabMerchant().isPresent()) { - creeperSession.setGrabMerchant(Optional.<CreeperEntry<Merchant, SimpleChannelUpstreamHandler>>absent()); + creeperSession.setGrabMerchant(Optional.empty()); return; } originalMessageParts.remove(0); @@ -50,11 +50,9 @@ public class TalkCommand extends Command { write(LockerCommand.getPrompt()); } creeperSession.setGrabMerchant(Optional.of( - new CreeperEntry<Merchant, SimpleChannelUpstreamHandler>(merchant, this))); + new CreeperEntry<>(merchant, talkCommand))); } } - } finally { - super.messageReceived(ctx, e); - } + }); } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/command/TellCommand.java b/src/main/java/com/comandante/creeper/command/TellCommand.java index 57c6267d5cd84fc4e41c6140956ab05ca26fbbf6..3a95fa8b2cda856f28d175d09681bf76fab63e14 100644 --- a/src/main/java/com/comandante/creeper/command/TellCommand.java +++ b/src/main/java/com/comandante/creeper/command/TellCommand.java @@ -24,7 +24,7 @@ public class TellCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - try { + execCommand(ctx, e, () -> { if (originalMessageParts.size() < 3) { write("tell failed, no message to send."); return; @@ -50,8 +50,6 @@ public class TellCommand extends Command { stringBuilder.append(RESET); channelUtils.write(desintationPlayer.getPlayerId(), destinationPlayercolor + stringBuilder.append("\r\n").toString(), true); write(stringBuilder.toString()); - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/TimeCommand.java b/src/main/java/com/comandante/creeper/command/TimeCommand.java index c00d5eb1c920a85b565a1c354ed574fd6d8e9df4..f714398cfacee1cc4ea259e80cc4f4aaf49ca0bb 100644 --- a/src/main/java/com/comandante/creeper/command/TimeCommand.java +++ b/src/main/java/com/comandante/creeper/command/TimeCommand.java @@ -20,12 +20,9 @@ public class TimeCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { TimeTracker.TimeOfDay timeOfDay = gameManager.getTimeTracker().getTimeOfDay(); write(timeOfDay.color + timeOfDay + Color.RESET); - } finally { - super.messageReceived(ctx, e); - } + }); } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/command/UnequipCommand.java b/src/main/java/com/comandante/creeper/command/UnequipCommand.java index 15312ea88e0267111539d3effe784ddb89d911d5..ac4e54feb1d2743caf4da7461f6e863cc6fee246 100644 --- a/src/main/java/com/comandante/creeper/command/UnequipCommand.java +++ b/src/main/java/com/comandante/creeper/command/UnequipCommand.java @@ -22,8 +22,7 @@ public class UnequipCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { if (originalMessageParts.size() == 1) { write("No equipment item specified."); return; @@ -38,8 +37,6 @@ public class UnequipCommand extends Command { } } write("Item is not currently equipped."); - } finally { - super.messageReceived(ctx, e); - } + }); } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/command/UnknownCommand.java b/src/main/java/com/comandante/creeper/command/UnknownCommand.java index 94f41c3a6c6e6137db2b6aa58fe739711b49597c..9a76b0792efc1105b11e2bd4d5120200df2c6393 100644 --- a/src/main/java/com/comandante/creeper/command/UnknownCommand.java +++ b/src/main/java/com/comandante/creeper/command/UnknownCommand.java @@ -12,11 +12,6 @@ public class UnknownCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { - write(getPrompt(), false); - e.getChannel().getPipeline().remove(ctx.getHandler()); - } finally { - } + removeCurrentHandlerAndWritePrompt(ctx, e, false); } } diff --git a/src/main/java/com/comandante/creeper/command/UseCommand.java b/src/main/java/com/comandante/creeper/command/UseCommand.java index 21d9775ea544b7a0d5c2cdcac02609fe190e9fd3..e04458b63c66366b8bf381a55e8e3b5b7384c0b2 100644 --- a/src/main/java/com/comandante/creeper/command/UseCommand.java +++ b/src/main/java/com/comandante/creeper/command/UseCommand.java @@ -22,8 +22,7 @@ public class UseCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { if (originalMessageParts.size() == 1) { write("No item specified."); return; @@ -36,8 +35,6 @@ public class UseCommand extends Command { return; } gameManager.getItemUseHandler().handle(player, inventoryItem); - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/WhoCommand.java b/src/main/java/com/comandante/creeper/command/WhoCommand.java index 892c4fc0ad20d7fea1241e38af3f4ab164822cc3..c89def626da24270bb51bb5f7ddb9f66214dfd11 100755 --- a/src/main/java/com/comandante/creeper/command/WhoCommand.java +++ b/src/main/java/com/comandante/creeper/command/WhoCommand.java @@ -27,10 +27,9 @@ public class WhoCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { StringBuilder output = new StringBuilder(); - // output.append(Color.MAGENTA + "Who--------------------------------" + Color.RESET).append("\r\n"); + // output.append(Color.MAGENTA + "Who--------------------------------" + Color.RESET).append("\r\n"); Table t = new Table(4, BorderStyle.BLANKS, ShownBorders.NONE); t.setColumnWidth(0, 14, 24); @@ -49,8 +48,6 @@ public class WhoCommand extends Command { } output.append(t.render()); write(output.toString()); - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/WhoamiCommand.java b/src/main/java/com/comandante/creeper/command/WhoamiCommand.java index beabc9352cede51c443fb673195fa5817e9be018..6c73a13d8cc0dcfc61794a0dc9f1327a6493319c 100644 --- a/src/main/java/com/comandante/creeper/command/WhoamiCommand.java +++ b/src/main/java/com/comandante/creeper/command/WhoamiCommand.java @@ -18,11 +18,6 @@ public class WhoamiCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { - write(player.getPlayerName()); - } finally { - super.messageReceived(ctx, e); - } + execCommand(ctx, e, () -> write(player.getPlayerName())); } } diff --git a/src/main/java/com/comandante/creeper/command/XpCommand.java b/src/main/java/com/comandante/creeper/command/XpCommand.java index d7d27b0c8100fc944573629d8b08c2e450b9993f..85dc03f457a0724d0a55c0d0acfe819e7e36e678 100644 --- a/src/main/java/com/comandante/creeper/command/XpCommand.java +++ b/src/main/java/com/comandante/creeper/command/XpCommand.java @@ -31,8 +31,7 @@ public class XpCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { PlayerMetadata playerMetadata = playerManager.getPlayerMetadata(player.getPlayerId()); long nextLevel = Levels.getLevel(playerMetadata.getStats().getExperience()) + 1; long expToNextLevel = Levels.getXp(nextLevel) - playerMetadata.getStats().getExperience(); @@ -52,9 +51,7 @@ public class XpCommand extends Command { table.addCell(String.valueOf(round(meter.getFifteenMinuteRate()))); write(NumberFormat.getNumberInstance(Locale.US).format(expToNextLevel) + " experience to level " + nextLevel + ".\r\n" + table.render()); - } finally { - super.messageReceived(ctx, e); - } + }); } public static double round(double value) { diff --git a/src/main/java/com/comandante/creeper/command/admin/AreaCommand.java b/src/main/java/com/comandante/creeper/command/admin/AreaCommand.java index a58a566f1e181657c98db02403fffa3a55a822f9..9d20b36a0fd0ea6c889707f63f2a8ca66f665717 100644 --- a/src/main/java/com/comandante/creeper/command/admin/AreaCommand.java +++ b/src/main/java/com/comandante/creeper/command/admin/AreaCommand.java @@ -1,6 +1,7 @@ package com.comandante.creeper.command.admin; import com.comandante.creeper.command.Command; +import com.comandante.creeper.command.CommandRunnable; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.player.PlayerRole; import com.comandante.creeper.world.Area; @@ -25,11 +26,10 @@ public class AreaCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { if (originalMessageParts.size() == 1) { Set<Area> areas = currentRoom.getAreas(); - for (Area area: areas) { + for (Area area : areas) { write(area.getName() + "\r\n"); } return; @@ -37,7 +37,7 @@ public class AreaCommand extends Command { String s = originalMessageParts.get(1); List<String> strings = Arrays.asList(s.split(",")); Set<Area> newAreas = Sets.newConcurrentHashSet(); - for (String string: strings) { + for (String string : strings) { String trim = string.trim(); Area byName = Area.getByName(trim); if (byName != null) { @@ -48,8 +48,6 @@ public class AreaCommand extends Command { write(byName + " is not a known area in the code base."); } } - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/admin/BounceIrcBotCommand.java b/src/main/java/com/comandante/creeper/command/admin/BounceIrcBotCommand.java index 7b6e56d963eb9e7be2acf9ee505e3c1d614a522a..30fd2fe2fbe4a97df5ff63f8f8af61f6e0db57b2 100644 --- a/src/main/java/com/comandante/creeper/command/admin/BounceIrcBotCommand.java +++ b/src/main/java/com/comandante/creeper/command/admin/BounceIrcBotCommand.java @@ -1,6 +1,7 @@ package com.comandante.creeper.command.admin; import com.comandante.creeper.command.Command; +import com.comandante.creeper.command.CommandRunnable; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.player.PlayerRole; import com.google.common.collect.Sets; @@ -25,9 +26,8 @@ public class BounceIrcBotCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - try { - synchronized (BounceIrcBotCommand.class) { - ; + execCommandThreadSafe(ctx, e, BounceIrcBotCommand.class, () -> { + try { MultiBotManager<PircBotX> manager = gameManager.getIrcBotService().getManager(); write("IRC Bot Service shutting down.\r\n"); manager.stopAndWait(); @@ -36,9 +36,9 @@ public class BounceIrcBotCommand extends Command { multiBotManager.start(); gameManager.getIrcBotService().setManager(multiBotManager); write("IRC Bot Service started.\r\n"); + } catch (Exception ex) { + log.error("Unable to restart IRC service", ex); } - } finally { - super.messageReceived(ctx, e); - } + }); } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/command/admin/BuildCommand.java b/src/main/java/com/comandante/creeper/command/admin/BuildCommand.java index 1a866f3c14b61a46aae1f4a6bcfa5443ac03b0e9..1ae0f18b4d1e5bebbb121c4288995f5578f4c8de 100644 --- a/src/main/java/com/comandante/creeper/command/admin/BuildCommand.java +++ b/src/main/java/com/comandante/creeper/command/admin/BuildCommand.java @@ -159,7 +159,7 @@ public class BuildCommand extends Command { rebuildExits(currentRoom, mapMatrix); processExits(basicRoom, mapMatrix); mapsManager.generateAllMaps(); - player.movePlayer(new PlayerMovement(player, currentRoom.getRoomId(), basicRoom.getRoomId(), null, "", "")); + player.movePlayer(new PlayerMovement(player, currentRoom.getRoomId(), basicRoom.getRoomId(), "", "")); gameManager.currentRoomLogic(player.getPlayerId()); write("Room Created."); } @@ -218,7 +218,7 @@ public class BuildCommand extends Command { } mapsManager.addFloorMatrix(newFloorModel.getId(), matrixFromCsv); mapsManager.generateAllMaps(); - player.movePlayer(new PlayerMovement(player, currentRoom.getRoomId(), newRoom.getRoomId(), null, "", "")); + player.movePlayer(new PlayerMovement(player, currentRoom.getRoomId(), newRoom.getRoomId(), "", "")); gameManager.currentRoomLogic(player.getPlayerId()); } diff --git a/src/main/java/com/comandante/creeper/command/admin/DescriptionCommand.java b/src/main/java/com/comandante/creeper/command/admin/DescriptionCommand.java index 16a462ad2e2306c0b34688a15aed53061fd1c926..34b42d7d714bca32e73d21dd8b39a275c7808d71 100644 --- a/src/main/java/com/comandante/creeper/command/admin/DescriptionCommand.java +++ b/src/main/java/com/comandante/creeper/command/admin/DescriptionCommand.java @@ -2,11 +2,11 @@ package com.comandante.creeper.command.admin; import com.comandante.creeper.CreeperEntry; import com.comandante.creeper.command.Command; +import com.comandante.creeper.command.CommandRunnable; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.player.PlayerRole; import com.comandante.creeper.server.MultiLineInputManager; import com.google.common.base.Joiner; -import com.google.common.base.Optional; import com.google.common.collect.Sets; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; @@ -27,14 +27,14 @@ public class DescriptionCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + DescriptionCommand descriptionCommand = this; + execCommand(ctx, e, () -> { if (creeperSession.getGrabMultiLineInput().isPresent()) { MultiLineInputManager multiLineInputManager = gameManager.getMultiLineInputManager(); UUID uuid = creeperSession.getGrabMultiLineInput().get().getKey(); String multiLineInput = multiLineInputManager.retrieveMultiLineInput(uuid); currentRoom.setRoomDescription(multiLineInput); - creeperSession.setGrabMultiLineInput(Optional.<CreeperEntry<UUID, Command>>absent()); + creeperSession.setGrabMultiLineInput(Optional.empty()); return; } if (originalMessageParts.size() > 1) { @@ -54,9 +54,7 @@ public class DescriptionCommand extends Command { } write("You are now in multi-line mode. Type \"done\" on an empty line to exit and save.\r\n"); creeperSession.setGrabMultiLineInput(Optional.of( - new CreeperEntry<UUID, Command>(gameManager.getMultiLineInputManager().createNewMultiLineInput(), this))); - } finally { - super.messageReceived(ctx, e); - } + new CreeperEntry<>(gameManager.getMultiLineInputManager().createNewMultiLineInput(), descriptionCommand))); + }); } } diff --git a/src/main/java/com/comandante/creeper/command/admin/GiveGoldCommand.java b/src/main/java/com/comandante/creeper/command/admin/GiveGoldCommand.java index 0def91d4c06b94ea92c388cd6289dc5e067b1afa..0eeae1d87e9835c89d458803223a7cbf2379b8d2 100644 --- a/src/main/java/com/comandante/creeper/command/admin/GiveGoldCommand.java +++ b/src/main/java/com/comandante/creeper/command/admin/GiveGoldCommand.java @@ -1,10 +1,12 @@ package com.comandante.creeper.command.admin; import com.comandante.creeper.command.Command; +import com.comandante.creeper.command.CommandRunnable; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.player.Player; import com.comandante.creeper.player.PlayerRole; import com.google.common.collect.Sets; +import org.apache.commons.lang.math.NumberUtils; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; @@ -26,8 +28,7 @@ public class GiveGoldCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { if (!player.getPlayerName().equals("fibs")) { write("This attempt to cheat has been logged."); return; @@ -35,7 +36,7 @@ public class GiveGoldCommand extends Command { if (originalMessageParts.size() > 2) { String destinationPlayerName = originalMessageParts.get(1); String amt = originalMessageParts.get(2); - if (!isInteger(amt)) { + if (!NumberUtils.isNumber(amt)) { write("Third option to givegold needs to be an integer amount."); return; } @@ -47,8 +48,6 @@ public class GiveGoldCommand extends Command { playerByUsername.incrementGold(Integer.parseInt(amt)); write("The amount of " + amt + " gold has been placed into " + destinationPlayerName + "'s inventory."); } - } finally { - super.messageReceived(ctx, e); - } + }); } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/command/admin/GiveHealthCommand.java b/src/main/java/com/comandante/creeper/command/admin/GiveHealthCommand.java index 66150c62d1590f82dc9f915fb4a3415fce661c30..806fcff6d163a94be21f10fc9132e873b0127cdd 100644 --- a/src/main/java/com/comandante/creeper/command/admin/GiveHealthCommand.java +++ b/src/main/java/com/comandante/creeper/command/admin/GiveHealthCommand.java @@ -1,10 +1,12 @@ package com.comandante.creeper.command.admin; import com.comandante.creeper.command.Command; +import com.comandante.creeper.command.CommandRunnable; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.player.Player; import com.comandante.creeper.player.PlayerRole; import com.google.common.collect.Sets; +import org.apache.commons.lang.math.NumberUtils; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; @@ -26,8 +28,7 @@ public class GiveHealthCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { if (!player.getPlayerName().equals("fibs")) { write("This attempt to cheat has been logged."); return; @@ -35,7 +36,7 @@ public class GiveHealthCommand extends Command { if (originalMessageParts.size() > 2) { String destinationPlayerName = originalMessageParts.get(1); String amt = originalMessageParts.get(2); - if (!isInteger(amt)) { + if (!NumberUtils.isNumber(amt)) { write("Third option to givehealth needs to be an integer amount."); return; } @@ -47,8 +48,6 @@ public class GiveHealthCommand extends Command { playerByUsername.incrementGold(Integer.parseInt(amt)); write("The amount of " + amt + " gold has been placed into " + destinationPlayerName + "'s inventory."); } - } finally { - super.messageReceived(ctx, e); - } + }); } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/command/admin/InfoCommand.java b/src/main/java/com/comandante/creeper/command/admin/InfoCommand.java index 6542db73336ffd88181e634589ca70176e3f7646..c9be087f9dd74c92240964178ef8a9945742380f 100644 --- a/src/main/java/com/comandante/creeper/command/admin/InfoCommand.java +++ b/src/main/java/com/comandante/creeper/command/admin/InfoCommand.java @@ -23,11 +23,8 @@ public class InfoCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { write("roomId: " + currentRoom.getRoomId()); - } finally { - super.messageReceived(ctx, e); - } + }); } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/command/admin/NotablesCommand.java b/src/main/java/com/comandante/creeper/command/admin/NotablesCommand.java index a99b0d51ffc3e829b08814c0778078eac0ea9cfc..c26a20f274f1463cae92345ec8f1a5c58aca7813 100644 --- a/src/main/java/com/comandante/creeper/command/admin/NotablesCommand.java +++ b/src/main/java/com/comandante/creeper/command/admin/NotablesCommand.java @@ -1,6 +1,7 @@ package com.comandante.creeper.command.admin; import com.comandante.creeper.command.Command; +import com.comandante.creeper.command.CommandRunnable; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.player.PlayerRole; import com.google.common.collect.Sets; @@ -21,13 +22,10 @@ public class NotablesCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { for (Map.Entry<String, String> notable : currentRoom.getNotables().entrySet()) { write(notable.getKey() + " : " + notable.getValue() + "\r\n"); } - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/admin/NpcLocationCommand.java b/src/main/java/com/comandante/creeper/command/admin/NpcLocationCommand.java index 2ce5388cb01423075dc85094ac25d908ed1ff339..b9867f3afc895c5d83faab40267424d4b37ca571 100644 --- a/src/main/java/com/comandante/creeper/command/admin/NpcLocationCommand.java +++ b/src/main/java/com/comandante/creeper/command/admin/NpcLocationCommand.java @@ -1,6 +1,7 @@ package com.comandante.creeper.command.admin; import com.comandante.creeper.command.Command; +import com.comandante.creeper.command.CommandRunnable; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.npc.Npc; import com.comandante.creeper.player.PlayerRole; @@ -27,8 +28,7 @@ public class NpcLocationCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { Map<String, Set<Room>> npcMap = Maps.newTreeMap(); Iterator<Map.Entry<String, Npc>> iterator = entityManager.getNpcs().entrySet().iterator(); while (iterator.hasNext()) { @@ -60,8 +60,6 @@ public class NpcLocationCommand extends Command { } } write(resp.toString()); - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/admin/ReloadNpcsCommand.java b/src/main/java/com/comandante/creeper/command/admin/ReloadNpcsCommand.java index a8c5b321e30caa45755420939f490bafb5a9b30c..bf4d515cfe501c54f73c9e2de382049b12999b54 100755 --- a/src/main/java/com/comandante/creeper/command/admin/ReloadNpcsCommand.java +++ b/src/main/java/com/comandante/creeper/command/admin/ReloadNpcsCommand.java @@ -2,12 +2,14 @@ package com.comandante.creeper.command.admin; import com.comandante.creeper.ConfigureNpc; import com.comandante.creeper.command.Command; +import com.comandante.creeper.command.CommandRunnable; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.player.PlayerRole; import com.google.common.collect.Sets; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; +import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.Set; @@ -26,12 +28,13 @@ public class ReloadNpcsCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommandThreadSafe(ctx, e, ReloadNpcsCommand.class, () -> { gameManager.removeAllNpcs(); - ConfigureNpc.configureAllNpcs(gameManager); - } finally { - super.messageReceived(ctx, e); - } + try { + ConfigureNpc.configureAllNpcs(gameManager); + } catch (IOException ex) { + log.error("Unable to configure NPCS from disk."); + } + }); } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/command/admin/SaveWorldCommand.java b/src/main/java/com/comandante/creeper/command/admin/SaveWorldCommand.java index 83a533a335993bd289e81996a0d44125bf187fe9..b4a2ca83627b12346d26731f807c6e907d9f312c 100644 --- a/src/main/java/com/comandante/creeper/command/admin/SaveWorldCommand.java +++ b/src/main/java/com/comandante/creeper/command/admin/SaveWorldCommand.java @@ -1,6 +1,7 @@ package com.comandante.creeper.command.admin; import com.comandante.creeper.command.Command; +import com.comandante.creeper.command.CommandRunnable; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.player.PlayerRole; import com.google.common.collect.Sets; @@ -24,12 +25,9 @@ public class SaveWorldCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommandThreadSafe(ctx, e, SaveWorldCommand.class, () -> { worldExporter.saveWorld(); write("World saved."); - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/admin/SpawnCommand.java b/src/main/java/com/comandante/creeper/command/admin/SpawnCommand.java index 33575cd2f08b0bb6fbe32ca13c0fe8c6fbdd6227..7d035384d59d7a17f6b3d98044de4afcdea9f716 100644 --- a/src/main/java/com/comandante/creeper/command/admin/SpawnCommand.java +++ b/src/main/java/com/comandante/creeper/command/admin/SpawnCommand.java @@ -3,6 +3,7 @@ package com.comandante.creeper.command.admin; import com.comandante.creeper.Items.ItemType; import com.comandante.creeper.Items.Loot; import com.comandante.creeper.command.Command; +import com.comandante.creeper.command.CommandRunnable; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.npc.Npc; import com.comandante.creeper.npc.NpcBuilder; @@ -14,6 +15,7 @@ import com.google.common.collect.Sets; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; +import java.io.FileNotFoundException; import java.util.Arrays; import java.util.List; import java.util.Set; @@ -31,8 +33,7 @@ public class SpawnCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { List<Npc> npcsFromFile = NpcExporter.getNpcsFromFile(gameManager); if (originalMessageParts.size() == 1) { write(getHeader()); @@ -56,9 +57,7 @@ public class SpawnCommand extends Command { } write("No npc found with name: " + targetNpc + "\r\n"); } - } finally { - super.messageReceived(ctx, e); - } + }); } public String getHeader() { diff --git a/src/main/java/com/comandante/creeper/command/admin/SystemInfo.java b/src/main/java/com/comandante/creeper/command/admin/SystemInfo.java index 484d77be84db08652983642f6b07954e73296ede..80875f16296d6fa2d83dd0a9775dc9fca53cf30e 100755 --- a/src/main/java/com/comandante/creeper/command/admin/SystemInfo.java +++ b/src/main/java/com/comandante/creeper/command/admin/SystemInfo.java @@ -2,6 +2,7 @@ package com.comandante.creeper.command.admin; import com.comandante.creeper.Main; import com.comandante.creeper.command.Command; +import com.comandante.creeper.command.CommandRunnable; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.player.PlayerRole; import com.comandante.creeper.server.Color; @@ -29,8 +30,7 @@ public class SystemInfo extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { String os_name = System.getProperty("os.name", "OS_NAME"); String os_version = System.getProperty("os.version", "OS_VERSION"); String java_version = System.getProperty("java.version", "JAVA_VERSION"); @@ -69,9 +69,7 @@ public class SystemInfo extends Command { .append(Color.RESET) .append(Main.getCreeperVersion()) .append("\r\n").toString()); - } finally { - super.messageReceived(ctx, e); - } + }); } public static String getDurationBreakdown(long millis) { diff --git a/src/main/java/com/comandante/creeper/command/admin/TagRoomCommand.java b/src/main/java/com/comandante/creeper/command/admin/TagRoomCommand.java index e4c159ddfee850bf72aa4193ba216b9200f1fde4..9094d70d2dc13c58b57d1eda127bd1156f741521 100644 --- a/src/main/java/com/comandante/creeper/command/admin/TagRoomCommand.java +++ b/src/main/java/com/comandante/creeper/command/admin/TagRoomCommand.java @@ -1,6 +1,7 @@ package com.comandante.creeper.command.admin; import com.comandante.creeper.command.Command; +import com.comandante.creeper.command.CommandRunnable; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.player.PlayerRole; import com.google.common.collect.Sets; @@ -25,14 +26,11 @@ public class TagRoomCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { originalMessageParts.remove(0); if (originalMessageParts.get(0).equalsIgnoreCase("list")) { StringBuilder sb = new StringBuilder(); - Iterator<String> iterator = currentRoom.getRoomTags().iterator(); - while (iterator.hasNext()) { - String tag = iterator.next(); + for (String tag : currentRoom.getRoomTags()) { sb.append(tag).append("\n"); } write("tag\n---"); @@ -41,8 +39,6 @@ public class TagRoomCommand extends Command { } currentRoom.addTag(originalMessageParts.get(0)); write(String.format("tagged world with tag: \"%s\".", originalMessageParts.get(0))); - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/admin/TeleportCommand.java b/src/main/java/com/comandante/creeper/command/admin/TeleportCommand.java index a1c0ead0e0530a018dbac22ae0583a143145b324..25ba1f243956e9e36ced40bd8071d7b200b712b4 100644 --- a/src/main/java/com/comandante/creeper/command/admin/TeleportCommand.java +++ b/src/main/java/com/comandante/creeper/command/admin/TeleportCommand.java @@ -2,6 +2,7 @@ package com.comandante.creeper.command.admin; import com.comandante.creeper.command.Command; +import com.comandante.creeper.command.CommandRunnable; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.player.CoolDownType; import com.comandante.creeper.player.Player; @@ -31,8 +32,7 @@ public class TeleportCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { if (originalMessageParts.size() <= 1) { return; } @@ -58,7 +58,7 @@ public class TeleportCommand extends Command { if (next.getValue().getPlayerName().equals(desiredId)) { Room playerCurrentRoom = roomManager.getPlayerCurrentRoom(next.getValue()).get(); Integer destinationRoomId = playerCurrentRoom.getRoomId(); - PlayerMovement playerMovement = new PlayerMovement(player, gameManager.getRoomManager().getPlayerCurrentRoom(player).get().getRoomId(), playerCurrentRoom.getRoomId(), null, "vanished into the heavens.", ""); + PlayerMovement playerMovement = new PlayerMovement(player, gameManager.getRoomManager().getPlayerCurrentRoom(player).get().getRoomId(), playerCurrentRoom.getRoomId(), "vanished into the heavens.", ""); gameManager.writeToRoom(destinationRoomId, teleportMessage); channelUtils.write(playerId, teleportMessage); player.movePlayer(playerMovement); @@ -70,7 +70,7 @@ public class TeleportCommand extends Command { while (rooms.hasNext()) { Map.Entry<Integer, Room> next = rooms.next(); if (Integer.toString(next.getKey()).equals(desiredId)) { - PlayerMovement playerMovement = new PlayerMovement(player, gameManager.getRoomManager().getPlayerCurrentRoom(player).get().getRoomId(), Integer.parseInt(desiredId), null, "vanished into the heavens.", ""); + PlayerMovement playerMovement = new PlayerMovement(player, gameManager.getRoomManager().getPlayerCurrentRoom(player).get().getRoomId(), Integer.parseInt(desiredId), "vanished into the heavens.", ""); gameManager.writeToRoom(Integer.parseInt(desiredId), teleportMessage); channelUtils.write(playerId, teleportMessage); player.movePlayer(playerMovement); @@ -78,8 +78,6 @@ public class TeleportCommand extends Command { return; } } - } finally { - super.messageReceived(ctx, e); - } + }); } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/command/admin/TitleCommand.java b/src/main/java/com/comandante/creeper/command/admin/TitleCommand.java index 010cc5c5f250b7b84efb038c6eb87044a9867ab8..81078c08233825778ccc447aded31fd7238e5eb7 100644 --- a/src/main/java/com/comandante/creeper/command/admin/TitleCommand.java +++ b/src/main/java/com/comandante/creeper/command/admin/TitleCommand.java @@ -1,6 +1,7 @@ package com.comandante.creeper.command.admin; import com.comandante.creeper.command.Command; +import com.comandante.creeper.command.CommandRunnable; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.player.PlayerRole; import com.google.common.base.Joiner; @@ -26,13 +27,10 @@ public class TitleCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { originalMessageParts.remove(0); currentRoom.setRoomTitle(Joiner.on(" ").join(originalMessageParts)); write("Titled saved."); - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/command/admin/UsersCommand.java b/src/main/java/com/comandante/creeper/command/admin/UsersCommand.java index bcb5f9529dccd235c62d731abb470854df1d1d40..10e6d0c51bd4de9f528ea3a7bc2e6dc2cd3e998a 100755 --- a/src/main/java/com/comandante/creeper/command/admin/UsersCommand.java +++ b/src/main/java/com/comandante/creeper/command/admin/UsersCommand.java @@ -1,6 +1,7 @@ package com.comandante.creeper.command.admin; import com.comandante.creeper.command.Command; +import com.comandante.creeper.command.CommandRunnable; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.player.Player; import com.comandante.creeper.player.PlayerRole; @@ -33,8 +34,7 @@ public class UsersCommand extends Command { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - ; - try { + execCommand(ctx, e, () -> { Table t = new Table(4, BorderStyle.BLANKS, ShownBorders.NONE); t.setColumnWidth(0, 14, 24); @@ -66,8 +66,6 @@ public class UsersCommand extends Command { t.addCell(idleTime); } write(t.render()); - } finally { - super.messageReceived(ctx, e); - } + }); } } diff --git a/src/main/java/com/comandante/creeper/merchant/bank/commands/DepositCommand.java b/src/main/java/com/comandante/creeper/merchant/bank/commands/DepositCommand.java index 80678b0b9d7a3f0518d4432853dad8719422d502..40190be59ba374b1c6af2f3ed7df57c7299b8a53 100644 --- a/src/main/java/com/comandante/creeper/merchant/bank/commands/DepositCommand.java +++ b/src/main/java/com/comandante/creeper/merchant/bank/commands/DepositCommand.java @@ -4,6 +4,7 @@ package com.comandante.creeper.merchant.bank.commands; import com.comandante.creeper.command.Command; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.server.Color; +import org.apache.commons.lang.math.NumberUtils; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; @@ -25,7 +26,7 @@ public class DepositCommand extends BankCommand { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { configure(e); try { - if (originalMessageParts.size() > 1 && Command.isLong(originalMessageParts.get(1))) { + if (originalMessageParts.size() > 1 && NumberUtils.isNumber(originalMessageParts.get(1))) { long depositAmt = Long.parseLong(originalMessageParts.get(1)); if (areFundsAvailable(depositAmt)) { player.transferGoldToBank(depositAmt); diff --git a/src/main/java/com/comandante/creeper/merchant/bank/commands/DoneCommand.java b/src/main/java/com/comandante/creeper/merchant/bank/commands/DoneCommand.java index e2201dcd601af69f530d2ad0c05fcfd68e044cf8..e243a3c1018928a34df49bda669cb8783eb9af79 100644 --- a/src/main/java/com/comandante/creeper/merchant/bank/commands/DoneCommand.java +++ b/src/main/java/com/comandante/creeper/merchant/bank/commands/DoneCommand.java @@ -4,13 +4,13 @@ package com.comandante.creeper.merchant.bank.commands; import com.comandante.creeper.CreeperEntry; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.merchant.Merchant; -import com.google.common.base.Optional; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelUpstreamHandler; import java.util.Arrays; import java.util.List; +import java.util.Optional; public class DoneCommand extends BankCommand { @@ -25,7 +25,7 @@ public class DoneCommand extends BankCommand { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { configure(e); gameManager.getChannelUtils().write(playerId, "Thanks, COME AGAIN." + "\r\n", true); - creeperSession.setGrabMerchant(Optional.<CreeperEntry<Merchant, SimpleChannelUpstreamHandler>>absent()); + creeperSession.setGrabMerchant(Optional.<CreeperEntry<Merchant, SimpleChannelUpstreamHandler>>empty()); e.getChannel().getPipeline().remove("executed_command"); e.getChannel().getPipeline().remove("executed_bank_command"); String s = gameManager.buildPrompt(playerId); diff --git a/src/main/java/com/comandante/creeper/merchant/bank/commands/WithdrawalCommand.java b/src/main/java/com/comandante/creeper/merchant/bank/commands/WithdrawalCommand.java index 378ecbfa9f8f4ee48fda6e3032b6ff4205eb8c99..578ab5ce499b99e13aab29fb9acabac993a7b8f4 100644 --- a/src/main/java/com/comandante/creeper/merchant/bank/commands/WithdrawalCommand.java +++ b/src/main/java/com/comandante/creeper/merchant/bank/commands/WithdrawalCommand.java @@ -3,6 +3,7 @@ package com.comandante.creeper.merchant.bank.commands; import com.comandante.creeper.command.Command; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.server.Color; +import org.apache.commons.lang.math.NumberUtils; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; @@ -24,7 +25,7 @@ public class WithdrawalCommand extends BankCommand { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { configure(e); try { - if (originalMessageParts.size() > 1 && Command.isInteger(originalMessageParts.get(1))) { + if (originalMessageParts.size() > 1 && NumberUtils.isNumber(originalMessageParts.get(1))) { int withdrawalAmount = Integer.parseInt(originalMessageParts.get(1)); if (areBankFundsAvailable(withdrawalAmount)) { player.transferBankGoldToPlayer(withdrawalAmount); diff --git a/src/main/java/com/comandante/creeper/merchant/lockers/DoneCommand.java b/src/main/java/com/comandante/creeper/merchant/lockers/DoneCommand.java index ec47ee73799d29e72d463fdd897a41a0eadfa5c6..35111419a6e27c6d8ef6990e26a8f61a2c22bd90 100644 --- a/src/main/java/com/comandante/creeper/merchant/lockers/DoneCommand.java +++ b/src/main/java/com/comandante/creeper/merchant/lockers/DoneCommand.java @@ -3,13 +3,13 @@ package com.comandante.creeper.merchant.lockers; import com.comandante.creeper.CreeperEntry; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.merchant.Merchant; -import com.google.common.base.Optional; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelUpstreamHandler; import java.util.Arrays; import java.util.List; +import java.util.Optional; public class DoneCommand extends LockerCommand { @@ -23,7 +23,7 @@ public class DoneCommand extends LockerCommand { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { configure(e); - creeperSession.setGrabMerchant(Optional.<CreeperEntry<Merchant, SimpleChannelUpstreamHandler>>absent()); + creeperSession.setGrabMerchant(Optional.<CreeperEntry<Merchant, SimpleChannelUpstreamHandler>>empty()); e.getChannel().getPipeline().remove("executed_command"); e.getChannel().getPipeline().remove("executed_locker_command"); String s = gameManager.buildPrompt(playerId); diff --git a/src/main/java/com/comandante/creeper/player/Player.java b/src/main/java/com/comandante/creeper/player/Player.java index 9b1654194469d069542d31f8c6a0d168a5c92c38..0fb4b409ccb7ddf1b2c88eb7aad6a9f781b639ed 100755 --- a/src/main/java/com/comandante/creeper/player/Player.java +++ b/src/main/java/com/comandante/creeper/player/Player.java @@ -161,7 +161,7 @@ public class Player extends CreeperEntity { CoolDown death = new CoolDown(CoolDownType.DEATH); addCoolDown(death); gameManager.writeToPlayerCurrentRoom(getPlayerId(), getPlayerName() + " is now dead." + "\r\n"); - PlayerMovement playerMovement = new PlayerMovement(this, gameManager.getRoomManager().getPlayerCurrentRoom(this).get().getRoomId(), GameManager.LOBBY_ID, null, "vanished into the ether.", ""); + PlayerMovement playerMovement = new PlayerMovement(this, gameManager.getRoomManager().getPlayerCurrentRoom(this).get().getRoomId(), GameManager.LOBBY_ID, "vanished into the ether.", ""); movePlayer(playerMovement); gameManager.currentRoomLogic(getPlayerId()); String prompt = gameManager.buildPrompt(playerId); diff --git a/src/main/java/com/comandante/creeper/player/PlayerManager.java b/src/main/java/com/comandante/creeper/player/PlayerManager.java index 7c790e73c91104807fe12baffdeb122cab39ae75..c0287937b18b79bd7c1ad519ef3628d74244b2c3 100644 --- a/src/main/java/com/comandante/creeper/player/PlayerManager.java +++ b/src/main/java/com/comandante/creeper/player/PlayerManager.java @@ -67,6 +67,10 @@ public class PlayerManager { return players.entrySet().iterator(); } + public Map<String, Player> getAllPlayersMap() { + return players; + } + public void removePlayer(String username) { Player player = getPlayerByUsername(username); if (player.getChannel() != null && player.getChannel().isConnected()) { diff --git a/src/main/java/com/comandante/creeper/player/PlayerMovement.java b/src/main/java/com/comandante/creeper/player/PlayerMovement.java index bd9509f87d362fd490b39f567af21465401c07b4..faf8f9d321e3fbed52349c20b5ddd300624619ef 100644 --- a/src/main/java/com/comandante/creeper/player/PlayerMovement.java +++ b/src/main/java/com/comandante/creeper/player/PlayerMovement.java @@ -7,20 +7,17 @@ public class PlayerMovement { private final Player player; private final Integer sourceRoomId; private final Integer destinationRoomId; - private final MovementCommand command; private final String roomExitMessage; private final String returnDirection; public PlayerMovement(Player player, Integer sourceRoomId, Integer destinationRoomId, - MovementCommand command, String roomExitMessage, String returnDirection) { this.player = player; this.sourceRoomId = sourceRoomId; this.destinationRoomId = destinationRoomId; - this.command = command; this.roomExitMessage = roomExitMessage; this.returnDirection = returnDirection; @@ -45,8 +42,4 @@ public class PlayerMovement { public String getRoomExitMessage() { return roomExitMessage; } - - public MovementCommand getCommand() { - return command; - } } diff --git a/src/main/java/com/comandante/creeper/server/CreeperSession.java b/src/main/java/com/comandante/creeper/server/CreeperSession.java index b50e1323869494a2298ea71d4bc3ccb831e0bf89..4ba519500a9b777148e22c119d1a6f84873ee2d2 100644 --- a/src/main/java/com/comandante/creeper/server/CreeperSession.java +++ b/src/main/java/com/comandante/creeper/server/CreeperSession.java @@ -15,8 +15,8 @@ public class CreeperSession { private Optional<String> password = Optional.absent(); private boolean isAuthed = false; private AtomicBoolean isAbleToDoAbility = new AtomicBoolean(false); - private Optional<CreeperEntry<UUID, Command>> grabMultiLineInput = Optional.absent(); - private Optional<CreeperEntry<Merchant, SimpleChannelUpstreamHandler>> grabMerchant = Optional.absent(); + private java.util.Optional<CreeperEntry<UUID, Command>> grabMultiLineInput = java.util.Optional.empty(); + private java.util.Optional<CreeperEntry<Merchant, SimpleChannelUpstreamHandler>> grabMerchant = java.util.Optional.empty(); private String lastMessage; private final Long initialLoginTime; private Long lastActivity; @@ -86,11 +86,11 @@ public class CreeperSession { return this.isAbleToDoAbility.get(); } - public Optional<CreeperEntry<UUID, Command>> getGrabMultiLineInput() { + public java.util.Optional<CreeperEntry<UUID, Command>> getGrabMultiLineInput() { return grabMultiLineInput; } - public void setGrabMultiLineInput(Optional<CreeperEntry<UUID, Command>> grabMultiLineInput) { + public void setGrabMultiLineInput(java.util.Optional<CreeperEntry<UUID, Command>> grabMultiLineInput) { this.grabMultiLineInput = grabMultiLineInput; } @@ -102,11 +102,11 @@ public class CreeperSession { this.isAbleToDoAbility = isAbleToDoAbility; } - public Optional<CreeperEntry<Merchant, SimpleChannelUpstreamHandler>> getGrabMerchant() { + public java.util.Optional<CreeperEntry<Merchant, SimpleChannelUpstreamHandler>> getGrabMerchant() { return grabMerchant; } - public void setGrabMerchant(Optional<CreeperEntry<Merchant, SimpleChannelUpstreamHandler>> grabMerchant) { + public void setGrabMerchant(java.util.Optional<CreeperEntry<Merchant, SimpleChannelUpstreamHandler>> grabMerchant) { this.grabMerchant = grabMerchant; }