Skip to content
Snippets Groups Projects
Commit 60b83235 authored by Chris Kearney's avatar Chris Kearney
Browse files

no longer need to "configure" commands, doing that by overriding the handleUpstream method

parent 8a225aa4
No related branches found
No related tags found
No related merge requests found
Showing
with 35 additions and 44 deletions
...@@ -28,7 +28,7 @@ public class CastCommand extends Command { ...@@ -28,7 +28,7 @@ public class CastCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
try { try {
configure(e); ;
if (player.getCurrentHealth() <= 0) { if (player.getCurrentHealth() <= 0) {
write("You have no health and as such you can not attack."); write("You have no health and as such you can not attack.");
return; return;
......
package com.comandante.creeper.command; package com.comandante.creeper.command;
import com.comandante.creeper.Items.Item;
import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.managers.GameManager;
import com.comandante.creeper.server.Color; import com.comandante.creeper.server.Color;
import com.google.common.base.Joiner;
import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.MessageEvent;
...@@ -23,7 +21,7 @@ public class ColorsCommand extends Command { ...@@ -23,7 +21,7 @@ public class ColorsCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
configure(e); ;
try { try {
write ("BLACK: " + Color.BLACK + "This is an example of the color." + Color.RESET + "\r\n"); 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 ("BLUE: " + Color.BLUE + "This is an example of the color." + Color.RESET + "\r\n");
......
...@@ -12,10 +12,7 @@ import com.comandante.creeper.server.CreeperSession; ...@@ -12,10 +12,7 @@ import com.comandante.creeper.server.CreeperSession;
import com.comandante.creeper.world.*; import com.comandante.creeper.world.*;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.*;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -67,14 +64,21 @@ public abstract class Command extends SimpleChannelUpstreamHandler { ...@@ -67,14 +64,21 @@ public abstract class Command extends SimpleChannelUpstreamHandler {
this.roles = roles; this.roles = roles;
} }
public void configure(MessageEvent e) { @Override
this.creeperSession = extractCreeperSession(e.getChannel()); public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
this.player = playerManager.getPlayer(extractPlayerId(creeperSession)); try {
this.playerId = player.getPlayerId(); if (e instanceof MessageEvent) {
this.currentRoom = gameManager.getRoomManager().getPlayerCurrentRoom(player).get(); this.creeperSession = extractCreeperSession(e.getChannel());
this.mapMatrix = mapsManager.getFloorMatrixMaps().get(currentRoom.getFloorId()); this.originalMessageParts = getOriginalMessageParts((MessageEvent) e);
this.currentRoomCoords = mapMatrix.getCoords(currentRoom.getRoomId()); this.player = playerManager.getPlayer(extractPlayerId(creeperSession));
this.originalMessageParts = getOriginalMessageParts(e); this.playerId = player.getPlayerId();
this.currentRoom = gameManager.getRoomManager().getPlayerCurrentRoom(player).get();
this.mapMatrix = mapsManager.getFloorMatrixMaps().get(currentRoom.getFloorId());
this.currentRoomCoords = mapMatrix.getCoords(currentRoom.getRoomId());
}
} finally {
super.handleUpstream(ctx, e);
}
} }
@Override @Override
......
package com.comandante.creeper.command; package com.comandante.creeper.command;
import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.managers.GameManager;
import com.comandante.creeper.server.Color;
import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.MessageEvent;
...@@ -20,7 +19,7 @@ public class CoolDownCommand extends Command { ...@@ -20,7 +19,7 @@ public class CoolDownCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
configure(e); ;
try { try {
if (player.isActiveCoolDown()) { if (player.isActiveCoolDown()) {
write(gameManager.renderCoolDownString(player.getCoolDowns())); write(gameManager.renderCoolDownString(player.getCoolDowns()));
......
...@@ -4,7 +4,6 @@ import com.comandante.creeper.managers.GameManager; ...@@ -4,7 +4,6 @@ import com.comandante.creeper.managers.GameManager;
import com.comandante.creeper.player.Player; import com.comandante.creeper.player.Player;
import com.comandante.creeper.player.PlayerManager; import com.comandante.creeper.player.PlayerManager;
import com.comandante.creeper.server.ChannelCommunicationUtils; import com.comandante.creeper.server.ChannelCommunicationUtils;
import com.comandante.creeper.server.ChannelUtils;
import com.comandante.creeper.server.Color; import com.comandante.creeper.server.Color;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelHandlerContext;
...@@ -24,7 +23,7 @@ public class CountdownCommand extends Command { ...@@ -24,7 +23,7 @@ public class CountdownCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
configure(e); ;
try { try {
new Thread(new PrintCountdown(playerManager, channelUtils)).start(); new Thread(new PrintCountdown(playerManager, channelUtils)).start();
} finally { } finally {
......
...@@ -2,9 +2,7 @@ package com.comandante.creeper.command; ...@@ -2,9 +2,7 @@ package com.comandante.creeper.command;
import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.managers.GameManager;
import com.comandante.creeper.player.PlayerSettings;
import com.google.api.client.util.Lists; import com.google.api.client.util.Lists;
import com.google.common.base.Joiner;
import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.MessageEvent;
...@@ -24,7 +22,7 @@ public class DelCommand extends Command { ...@@ -24,7 +22,7 @@ public class DelCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
configure(e); ;
try { try {
if (originalMessageParts.size() <= 1) { if (originalMessageParts.size() <= 1) {
write(returnAllSettings()); write(returnAllSettings());
......
...@@ -21,7 +21,7 @@ public class DropCommand extends Command { ...@@ -21,7 +21,7 @@ public class DropCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
configure(e); ;
try { try {
if (originalMessageParts.size() == 1) { if (originalMessageParts.size() == 1) {
write("No item specified."); write("No item specified.");
......
...@@ -21,7 +21,7 @@ public class EquipCommand extends Command { ...@@ -21,7 +21,7 @@ public class EquipCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
configure(e); ;
try { try {
if (originalMessageParts.size() == 1) { if (originalMessageParts.size() == 1) {
write("No equipment item specified."); write("No equipment item specified.");
......
...@@ -23,7 +23,7 @@ public class FightKillCommand extends Command { ...@@ -23,7 +23,7 @@ public class FightKillCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
configure(e); ;
try { try {
if (player.getCurrentHealth() <= 0) { if (player.getCurrentHealth() <= 0) {
write("You have no health and as such you can not attack."); write("You have no health and as such you can not attack.");
......
...@@ -20,7 +20,7 @@ public class ForageCommand extends Command { ...@@ -20,7 +20,7 @@ public class ForageCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
try { try {
configure(e); ;
gameManager.getForageManager().getForageForRoom(currentRoom, player); gameManager.getForageManager().getForageForRoom(currentRoom, player);
} finally { } finally {
super.messageReceived(ctx, e); super.messageReceived(ctx, e);
......
...@@ -23,7 +23,7 @@ public class GoldCommand extends Command { ...@@ -23,7 +23,7 @@ public class GoldCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
configure(e); ;
try { try {
write("You have " + NumberFormat.getNumberInstance(Locale.US).format(playerManager.getPlayerMetadata(playerId).getGold()) + Color.YELLOW + " gold." + Color.RESET); write("You have " + NumberFormat.getNumberInstance(Locale.US).format(playerManager.getPlayerMetadata(playerId).getGold()) + Color.YELLOW + " gold." + Color.RESET);
} finally { } finally {
......
...@@ -4,7 +4,6 @@ package com.comandante.creeper.command; ...@@ -4,7 +4,6 @@ package com.comandante.creeper.command;
import com.comandante.creeper.bot.commands.BotCommand; import com.comandante.creeper.bot.commands.BotCommand;
import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.managers.GameManager;
import com.comandante.creeper.player.Player; import com.comandante.creeper.player.Player;
import com.comandante.creeper.server.Color;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelHandlerContext;
...@@ -26,7 +25,7 @@ public class GossipCommand extends Command { ...@@ -26,7 +25,7 @@ public class GossipCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
configure(e); ;
try { try {
if (originalMessageParts.size() == 1) { if (originalMessageParts.size() == 1) {
write("Nothing to gossip about?"); write("Nothing to gossip about?");
......
...@@ -27,7 +27,7 @@ public class HelpCommand extends Command { ...@@ -27,7 +27,7 @@ public class HelpCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
configure(e); ;
try { try {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Table t = new Table(2, BorderStyle.CLASSIC_COMPATIBLE, Table t = new Table(2, BorderStyle.CLASSIC_COMPATIBLE,
......
...@@ -24,7 +24,7 @@ public class InventoryCommand extends Command { ...@@ -24,7 +24,7 @@ public class InventoryCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
configure(e); ;
try { try {
List<Item> inventory = player.getInventory(); List<Item> inventory = player.getInventory();
if (inventory == null) { if (inventory == null) {
......
...@@ -23,7 +23,7 @@ public class LookCommand extends Command { ...@@ -23,7 +23,7 @@ public class LookCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
configure(e); ;
try { try {
if (originalMessageParts.size() == 1) { if (originalMessageParts.size() == 1) {
currentRoomLogic(); currentRoomLogic();
......
...@@ -25,7 +25,7 @@ public class LootCommand extends Command { ...@@ -25,7 +25,7 @@ public class LootCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
configure(e); ;
try { try {
if (originalMessageParts.size() > 1) { if (originalMessageParts.size() > 1) {
for (Item item : player.getInventory()) { for (Item item : player.getInventory()) {
......
...@@ -24,7 +24,7 @@ public class MapCommand extends Command { ...@@ -24,7 +24,7 @@ public class MapCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
configure(e); ;
try { try {
if (originalMessageParts.size() > 1 && isInteger(originalMessageParts.get(1))) { if (originalMessageParts.size() > 1 && isInteger(originalMessageParts.get(1))) {
int max = Integer.parseInt(originalMessageParts.get(1)); int max = Integer.parseInt(originalMessageParts.get(1));
......
...@@ -36,7 +36,7 @@ public class MovementCommand extends Command { ...@@ -36,7 +36,7 @@ public class MovementCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
try { try {
configure(e); ;
if (player.isActiveFights()) { if (player.isActiveFights()) {
write("You can't move while in a fight!"); write("You can't move while in a fight!");
return; return;
......
...@@ -20,7 +20,7 @@ public class NexusCommand extends Command { ...@@ -20,7 +20,7 @@ public class NexusCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
configure(e); ;
try { try {
if (gameManager.getCreeperConfiguration().isIrcEnabled) { if (gameManager.getCreeperConfiguration().isIrcEnabled) {
originalMessageParts.remove(0); originalMessageParts.remove(0);
......
package com.comandante.creeper.command; package com.comandante.creeper.command;
import com.comandante.creeper.CreeperEntry;
import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.managers.GameManager;
import com.comandante.creeper.merchant.Merchant;
import com.comandante.creeper.merchant.lockers.LockerCommand;
import com.comandante.creeper.player.PlayerRole; import com.comandante.creeper.player.PlayerRole;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import org.pircbotx.Channel; import org.pircbotx.Channel;
import org.pircbotx.PircBotX;
import org.pircbotx.User; import org.pircbotx.User;
import org.pircbotx.UserChannelDao; import org.pircbotx.UserChannelDao;
...@@ -38,7 +32,7 @@ public class OpCommand extends Command { ...@@ -38,7 +32,7 @@ public class OpCommand extends Command {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
configure(e); ;
try { try {
//ghetto and will only work for one channel bots. //ghetto and will only work for one channel bots.
if (originalMessageParts.size() <= 1) { if (originalMessageParts.size() <= 1) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment