From ca9364d25bc3c50698fc5a79b1d9916615c11851 Mon Sep 17 00:00:00 2001 From: snowleo Date: Thu, 23 Jun 2011 13:31:23 +0200 Subject: Update to /time command: Supports player time now. New permissions: essentials.time.world (if the user is allowed to change the time of the world) essentials.time.player (if the user is allowed to change his own time) Backwards incompatibility! --- .../earth2me/essentials/commands/Commandtime.java | 39 ++++++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java index 9c4aa8c74..71bfb5965 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java @@ -15,20 +15,45 @@ public class Commandtime extends EssentialsCommand } @Override - public void run(Server server, User user, String commandLabel, String[] args) throws Exception + public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { throw new NotEnoughArgumentsException(); } - World world = user.getWorld(); + if (user.isAuthorized("essentials.time.world")) + { + final World world = user.getWorld(); + + charge(user); + setWorldTime(world, args[0]); + } + else + { + if (user.isAuthorized("essentials.time.player")) + { - charge(user); - setWorldTime(world, args[0]); + long time = user.getPlayerTime(); + time -= time % 24000; + if ("day".equalsIgnoreCase(args[0])) + { + final World world = user.getWorld(); + user.setPlayerTime(time + 24000 - world.getTime(), true); + return; + } + if ("night".equalsIgnoreCase(args[0])) + { + final World world = user.getWorld(); + user.setPlayerTime(time + 37700 - world.getTime(), true); + return; + } + throw new Exception(Util.i18n("onlyDayNight")); + } + } } @Override - public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception + public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -42,10 +67,10 @@ public class Commandtime extends EssentialsCommand sender.sendMessage(Util.i18n("timeSet")); } - private void setWorldTime(World world, String timeString) throws Exception + private void setWorldTime(final World world, final String timeString) throws Exception { long time = world.getTime(); - time = time - time % 24000; + time -= time % 24000; if ("day".equalsIgnoreCase(timeString)) { world.setTime(time + 24000); -- cgit v1.2.3