1
0
mirror of https://github.com/EssentialsX/Essentials.git synced 2025-01-10 18:38:18 +01:00

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

fixes 
This commit is contained in:
KHobbits 2012-08-08 00:52:43 +01:00
parent 5c1eea0953
commit 101ae201d6
3 changed files with 54 additions and 15 deletions
Essentials/src
com/earth2me/essentials/commands
plugin.yml

View File

@ -20,10 +20,16 @@ public class Commandtime extends EssentialsCommand
@Override
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));
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]);
@ -34,12 +40,27 @@ public class Commandtime extends EssentialsCommand
worldSelector = validArgs[1];
}
final Set<World> worlds = getWorlds(server, sender, worldSelector);
final String setTime;
// If no arguments we are reading the time
if (validArgs.length == 0)
{
getWorldsTime(sender, worlds);
return;
if (commandLabel.equalsIgnoreCase("day") || commandLabel.equalsIgnoreCase("eday"))
{
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);
@ -53,14 +74,14 @@ public class Commandtime extends EssentialsCommand
long ticks;
try
{
ticks = DescParseTickFormat.parse(validArgs[0]);
ticks = DescParseTickFormat.parse(setTime);
}
catch (NumberFormatException 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
*/
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();
@ -159,4 +183,4 @@ class WorldNameComparator implements Comparator<World>
{
return a.getName().compareTo(b.getName());
}
}
}

View File

@ -18,12 +18,27 @@ public class Commandweather extends EssentialsCommand
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
final boolean isStorm;
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();
if (args.length > 1)
{

View File

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