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 #2365
This commit is contained in:
parent
5c1eea0953
commit
101ae201d6
@ -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,13 +40,28 @@ 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)
|
||||
{
|
||||
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);
|
||||
if (user != null && !user.isAuthorized("essentials.time.set"))
|
||||
@ -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();
|
||||
if (!add)
|
||||
{
|
||||
time -= time % 24000;
|
||||
world.setTime(time + 24000 + ticks);
|
||||
}
|
||||
world.setTime(time + (add ? 0 : 24000) + ticks);
|
||||
}
|
||||
|
||||
final StringBuilder output = new StringBuilder();
|
||||
|
@ -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)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
final boolean isStorm = args[0].equalsIgnoreCase("storm");
|
||||
}
|
||||
else
|
||||
{
|
||||
isStorm = args[0].equalsIgnoreCase("storm");
|
||||
}
|
||||
final World world = user.getWorld();
|
||||
if (args.length > 1)
|
||||
{
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user