1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-18 20:41:37 +02:00

Fix /time command

This commit is contained in:
snowleo
2012-07-12 12:13:05 +02:00
parent cfb93e97f0
commit c3e261d60a

View File

@@ -16,10 +16,16 @@ public class Commandtime extends EssentialsCommand
@Override
public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
boolean add = false;
final List<String> argList = new ArrayList<String>(Arrays.asList(args));
if ((argList.remove("set") || argList.remove("add")) && Util.isInt(argList.get(0)))
if (argList.remove("set") && !argList.isEmpty() && Util.isInt(argList.get(0)))
{
ess.getLogger().info("debug edited 0" + argList.get(0).toString());
argList.set(0, argList.get(0) + "t");
}
if (argList.remove("add") && !argList.isEmpty() && Util.isInt(argList.get(0)))
{
add = true;
argList.set(0, argList.get(0) + "t");
}
final String[] validArgs = argList.toArray(new String[0]);
@@ -55,7 +61,7 @@ public class Commandtime extends EssentialsCommand
throw new NotEnoughArgumentsException(e);
}
setWorldsTime(sender, worlds, ticks);
setWorldsTime(sender, worlds, ticks, add);
}
/**
@@ -79,14 +85,17 @@ public class Commandtime extends EssentialsCommand
/**
* Used to set the time and inform of the change
*/
private void setWorldsTime(final CommandSender sender, final Collection<World> worlds, final long ticks)
private void setWorldsTime(final CommandSender sender, final Collection<World> worlds, final long ticks, final boolean add)
{
// Update the time
for (World world : worlds)
{
long time = world.getTime();
time -= time % 24000;
world.setTime(time + 24000 + ticks);
if (!add)
{
time -= time % 24000;
}
world.setTime(time + (add ? 0 : 24000) + ticks);
}
final StringBuilder output = new StringBuilder();