1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-24 15:23:20 +02:00

Fix /day /night /sun and /storm aliases to actually set to the current status if used without parameters.

fixes #2365
This commit is contained in:
KHobbits
2012-08-08 00:52:43 +01:00
parent bdeb93a8d7
commit a9e527f4ee
3 changed files with 54 additions and 15 deletions

View File

@@ -20,10 +20,16 @@ public class Commandtime extends EssentialsCommand
@Override @Override
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{ {
boolean add = false;
final List<String> argList = new ArrayList<String>(Arrays.asList(args)); 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]); final String[] validArgs = argList.toArray(new String[0]);
@@ -34,12 +40,27 @@ public class Commandtime extends EssentialsCommand
worldSelector = validArgs[1]; worldSelector = validArgs[1];
} }
final Set<World> worlds = getWorlds(server, sender, worldSelector); final Set<World> worlds = getWorlds(server, sender, worldSelector);
final String setTime;
// If no arguments we are reading the time // If no arguments we are reading the time
if (validArgs.length == 0) if (validArgs.length == 0)
{ {
getWorldsTime(sender, worlds); if (commandLabel.equalsIgnoreCase("day") || commandLabel.equalsIgnoreCase("eday"))
return; {
setTime = "day";
}
else if (commandLabel.equalsIgnoreCase("night") || commandLabel.equalsIgnoreCase("enight"))
{
setTime = "night";
}
else
{
getWorldsTime(sender, worlds);
return;
}
}
else {
setTime = validArgs[0];
} }
final User user = ess.getUser(sender); final User user = ess.getUser(sender);
@@ -53,14 +74,14 @@ public class Commandtime extends EssentialsCommand
long ticks; long ticks;
try try
{ {
ticks = DescParseTickFormat.parse(validArgs[0]); ticks = DescParseTickFormat.parse(setTime);
} }
catch (NumberFormatException e) catch (NumberFormatException e)
{ {
throw new NotEnoughArgumentsException(e); throw new NotEnoughArgumentsException(e);
} }
setWorldsTime(sender, worlds, ticks); setWorldsTime(sender, worlds, ticks, add);
} }
/** /**
@@ -84,14 +105,17 @@ public class Commandtime extends EssentialsCommand
/** /**
* Used to set the time and inform of the change * 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 // Update the time
for (World world : worlds) for (World world : worlds)
{ {
long time = world.getTime(); long time = world.getTime();
time -= time % 24000; if (!add)
world.setTime(time + 24000 + ticks); {
time -= time % 24000;
}
world.setTime(time + (add ? 0 : 24000) + ticks);
} }
final StringBuilder output = new StringBuilder(); final StringBuilder output = new StringBuilder();
@@ -159,4 +183,4 @@ class WorldNameComparator implements Comparator<World>
{ {
return a.getName().compareTo(b.getName()); return a.getName().compareTo(b.getName());
} }
} }

View File

@@ -18,12 +18,27 @@ public class Commandweather extends EssentialsCommand
@Override @Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{ {
final boolean isStorm;
if (args.length < 1) if (args.length < 1)
{ {
throw new NotEnoughArgumentsException(); if (commandLabel.equalsIgnoreCase("sun") || commandLabel.equalsIgnoreCase("esun"))
{
isStorm = false;
}
else if (commandLabel.equalsIgnoreCase("storm") || commandLabel.equalsIgnoreCase("estorm")
|| commandLabel.equalsIgnoreCase("rain") || commandLabel.equalsIgnoreCase("erain"))
{
isStorm = true;
}
else
{
throw new NotEnoughArgumentsException();
}
}
else
{
isStorm = args[0].equalsIgnoreCase("storm");
} }
final boolean isStorm = args[0].equalsIgnoreCase("storm");
final World world = user.getWorld(); final World world = user.getWorld();
if (args.length > 1) if (args.length > 1)
{ {

View File

@@ -341,7 +341,7 @@ commands:
time: time:
description: Display/Change the world time. Defaults to current world. description: Display/Change the world time. Defaults to current world.
usage: /<command> [day|night|dawn|17:30|4pm|4000ticks] [worldname|all] usage: /<command> [day|night|dawn|17:30|4pm|4000ticks] [worldname|all]
aliases: [etime, day, night] aliases: [etime, day, night, eday, enight]
togglejail: togglejail:
description: Jails/Unjails a player and tp them to the jail specified. description: Jails/Unjails a player and tp them to the jail specified.
usage: /<command> <player> <jailname> [datediff] usage: /<command> <player> <jailname> [datediff]
@@ -425,7 +425,7 @@ commands:
weather: weather:
description: Setting the weather. description: Setting the weather.
usage: /<command> <storm/sun> [duration] usage: /<command> <storm/sun> [duration]
aliases: [sky,sun,storm,eweather,esky,esun,estorm] aliases: [sky,sun,storm,eweather,rain,erain,esky,esun,estorm]
whois: whois:
description: Determine the username behind a nickname. description: Determine the username behind a nickname.
usage: /<command> <nickname> usage: /<command> <nickname>