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 78c38ff..cbf80ef 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java @@ -103,6 +103,16 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me private Map hardwareAddresses = new HashMap<>(); private Map, Integer> hardwareModules = new HashMap<>(); + /** + * In game timer + */ + private int time; + + /** + * Real Life Timer for getting execution time + */ + private RealLifeTimer timer; + /** * Cubot's brain box */ @@ -130,6 +140,10 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me shield = document.getInteger("shield"); setDirection(Direction.getDirection(document.getInteger("direction"))); + timer = new RealLifeTimer(); + timer.run(); + time = timer.getTime(); + IServerConfiguration config = GameServer.INSTANCE.getConfig(); maxHp = config.getInt("cubot_max_hp"); maxShield = config.getInt("cubot_max_shield"); @@ -159,6 +173,12 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me */ @Override public void update() { + int executionTime = timer.getTime(); + if(executionTime > time && currentAction != Action.IDLE){ + GameEvent event1 = new ExecutionTimeEvent(this, executionTime - time); + GameServer.INSTANCE.getEventDispatcher().dispatch(event1); + } + time = executionTime; if (currentAction == Action.WALKING) { if (spendEnergy(100)) { @@ -166,8 +186,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me //Couldn't walk currentAction = Action.IDLE; }else{ - GameEvent event = new WalkDistanceEvent(this); - GameServer.INSTANCE.getEventDispatcher().dispatch(event); + GameEvent event2 = new WalkDistanceEvent(this); + GameServer.INSTANCE.getEventDispatcher().dispatch(event2); } } else { currentAction = Action.IDLE; @@ -269,6 +289,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me currentStatus = 0; lastStatus = 0; addStatus(CubotStatus.FACTORY_NEW); + time = timer.getTime(); for (HardwareModule module : hardwareAddresses.values()) { module.reset(); diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotPlugin.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotPlugin.java index 4187edb..ce6a8b9 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotPlugin.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotPlugin.java @@ -18,6 +18,7 @@ public class CubotPlugin extends ServerPlugin { listeners.add(new SetInventoryPosition()); listeners.add(new PutItemCommandListener()); listeners.add(new PopItemCommandListener()); + //Leaderboard listeners.add(new DeathCountListener()); listeners.add(new ExecutionTimeListener()); listeners.add(new WalkDistanceListener()); diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/ExecutionTimeEvent.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/ExecutionTimeEvent.java index 5552437..5125db8 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/ExecutionTimeEvent.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/ExecutionTimeEvent.java @@ -5,8 +5,15 @@ import net.simon987.server.game.objects.GameObject; public class ExecutionTimeEvent extends GameEvent { - public ExecutionTimeEvent(GameObject object) { + private int Time = 0; + + public ExecutionTimeEvent(GameObject object, int time) { setSource(object); + this.Time = time; + } + + public int getTime(){ + return this.Time; } @Override diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/ExecutionTimeListener.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/ExecutionTimeListener.java index 7df4540..99d7694 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/ExecutionTimeListener.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/ExecutionTimeListener.java @@ -21,7 +21,10 @@ public class ExecutionTimeListener implements GameEventListener { GameObject object = executionTimeEvent.getSource(); if (object instanceof ControllableUnit) { count = ((ControllableUnit) object).getParent().getStats().getInt("executionTime"); - count++; + count += executionTimeEvent.getTime(); + + LogManager.LOGGER.info(((ControllableUnit) object).getParent().getUsername() + " Execution Time " + + count); ((ControllableUnit) object).getParent().getStats().setInt("executionTime", count); diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/RealLifeTimer.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/RealLifeTimer.java new file mode 100644 index 0000000..8c238c0 --- /dev/null +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/RealLifeTimer.java @@ -0,0 +1,39 @@ +package net.simon987.cubotplugin.event; + +import java.util.Timer; +import java.util.TimerTask; + +public class RealLifeTimer{ + + private int time; + + private Timer timer; + + public RealLifeTimer(){ + timer = new Timer(); + time = 0; + } + + public RealLifeTimer(int startTime){ + timer = new Timer(); + time = startTime; + } + + public void run(){ + + timer.scheduleAtFixedRate(new TimerTask() { + public void run(){ + time++; + } + },0,1); + } + + public void stop(){ + timer.cancel(); + timer.purge(); + } + + public int getTime(){ + return this.time; + } +} \ No newline at end of file