From f0b3d781b2917c07406e9547cc22106e2220f7be Mon Sep 17 00:00:00 2001 From: simon987 Date: Thu, 11 Apr 2019 18:34:05 -0400 Subject: [PATCH] Code style --- .../java/net/simon987/cubotplugin/Cubot.java | 11 ++++------- .../cubotplugin/event/CubotWalkEvent.java | 17 +++++++++++++++++ .../cubotplugin/event/DeathListener.java | 4 +--- .../simon987/cubotplugin/event/WalkEvent.java | 17 ----------------- .../cubotplugin/event/WalkListener.java | 14 +++----------- 5 files changed, 25 insertions(+), 38 deletions(-) create mode 100644 Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/CubotWalkEvent.java delete mode 100644 Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/WalkEvent.java diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java index d4134d8..97710bc 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java @@ -1,5 +1,7 @@ package net.simon987.cubotplugin; +import net.simon987.cubotplugin.event.CubotWalkEvent; +import net.simon987.cubotplugin.event.DeathEvent; import net.simon987.server.GameServer; import net.simon987.server.IServerConfiguration; import net.simon987.server.assembly.CPU; @@ -7,12 +9,11 @@ import net.simon987.server.assembly.HardwareModule; import net.simon987.server.assembly.Memory; import net.simon987.server.assembly.Status; import net.simon987.server.assembly.exception.CancelledException; +import net.simon987.server.event.GameEvent; import net.simon987.server.game.item.Item; import net.simon987.server.game.item.ItemVoid; import net.simon987.server.game.objects.*; import net.simon987.server.user.User; -import net.simon987.server.event.GameEvent; -import net.simon987.cubotplugin.event.*; import org.bson.Document; import org.json.simple.JSONObject; @@ -154,9 +155,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me return MAP_INFO; } - /** - * Called every tick - */ @Override public void update() { if (currentAction == Action.WALKING) { @@ -165,8 +163,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me //Couldn't walk currentAction = Action.IDLE; }else{ - GameEvent event2 = new WalkEvent(this); - GameServer.INSTANCE.getEventDispatcher().dispatch(event2); + GameServer.INSTANCE.getEventDispatcher().dispatch(new CubotWalkEvent(this)); } } else { currentAction = Action.IDLE; diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/CubotWalkEvent.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/CubotWalkEvent.java new file mode 100644 index 0000000..e183f1c --- /dev/null +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/CubotWalkEvent.java @@ -0,0 +1,17 @@ +package net.simon987.cubotplugin.event; + +import net.simon987.cubotplugin.Cubot; +import net.simon987.server.event.GameEvent; + +public class CubotWalkEvent extends GameEvent { + + public CubotWalkEvent(Cubot cubot) { + setSource(cubot); + } + + @Override + public Cubot getSource() { + return (Cubot) super.getSource(); + } + +} \ No newline at end of file diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/DeathListener.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/DeathListener.java index 35cdd1d..cf438c9 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/DeathListener.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/DeathListener.java @@ -4,7 +4,6 @@ import net.simon987.server.event.GameEvent; import net.simon987.server.event.GameEventListener; import net.simon987.server.game.objects.ControllableUnit; import net.simon987.server.game.objects.GameObject; -import net.simon987.server.logging.LogManager; public class DeathListener implements GameEventListener { @@ -18,8 +17,7 @@ public class DeathListener implements GameEventListener { DeathEvent DeathEvent = (DeathEvent) event; GameObject object = DeathEvent.getSource(); if (object instanceof ControllableUnit) { - ((ControllableUnit) object).getParent().getStats().incrementStat("death", - 1); + ((ControllableUnit) object).getParent().getStats().incrementStat("death", 1); } } } \ No newline at end of file diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/WalkEvent.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/WalkEvent.java deleted file mode 100644 index f95c7e1..0000000 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/WalkEvent.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.simon987.cubotplugin.event; - -import net.simon987.server.event.GameEvent; -import net.simon987.server.game.objects.GameObject; - -public class WalkEvent extends GameEvent { - - public WalkEvent(GameObject object) { - setSource(object); - } - - @Override - public GameObject getSource() { - return (GameObject) super.getSource(); - } - -} \ No newline at end of file diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/WalkListener.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/WalkListener.java index 9ffdc9a..fd2e96e 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/WalkListener.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/WalkListener.java @@ -2,25 +2,17 @@ package net.simon987.cubotplugin.event; import net.simon987.server.event.GameEvent; import net.simon987.server.event.GameEventListener; -import net.simon987.server.game.objects.ControllableUnit; -import net.simon987.server.game.objects.GameObject; -import net.simon987.server.logging.LogManager; -import net.simon987.server.user.UserStats; public class WalkListener implements GameEventListener { @Override public Class getListenedEventType() { - return WalkEvent.class; + return CubotWalkEvent.class; } @Override public void handle(GameEvent event) { - WalkEvent WalkEvent = (WalkEvent) event; - GameObject object = WalkEvent.getSource(); - if (object instanceof ControllableUnit) { - ((ControllableUnit) object).getParent().getStats().incrementStat("walkDistance", - 1); - } + CubotWalkEvent walkEvent = (CubotWalkEvent) event; + walkEvent.getSource().getParent().getStats().incrementStat("walkDistance", 1); } } \ No newline at end of file