mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 04:20:41 +00:00
Some fixes to the time code by me
This commit is contained in:
parent
f75390bd3f
commit
a117080b32
4 changed files with 136 additions and 108 deletions
|
@ -3,8 +3,6 @@ package com.earth2me.essentials;
|
||||||
import com.earth2me.essentials.commands.Commandtime;
|
import com.earth2me.essentials.commands.Commandtime;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +14,7 @@ import java.util.logging.Logger;
|
||||||
*
|
*
|
||||||
* @author Olof Larsson
|
* @author Olof Larsson
|
||||||
*/
|
*/
|
||||||
public class DescParseTickFormat
|
public final class DescParseTickFormat
|
||||||
{
|
{
|
||||||
// ============================================
|
// ============================================
|
||||||
// First some information vars. TODO: Should this be in a config file?
|
// First some information vars. TODO: Should this be in a config file?
|
||||||
|
@ -64,6 +62,10 @@ public class DescParseTickFormat
|
||||||
resetAliases.add("default");
|
resetAliases.add("default");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DescParseTickFormat()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// PARSE. From describing String to int
|
// PARSE. From describing String to int
|
||||||
// --------------------------------------------
|
// --------------------------------------------
|
||||||
|
@ -71,8 +73,8 @@ public class DescParseTickFormat
|
||||||
{
|
{
|
||||||
Long ret;
|
Long ret;
|
||||||
|
|
||||||
// Only look at alphanumeric and lowercase
|
// Only look at alphanumeric and lowercase and : for 24:00
|
||||||
desc = desc.toLowerCase().replaceAll("[^A-Za-z0-9]", "");
|
desc = desc.toLowerCase().replaceAll("[^A-Za-z0-9:]", "");
|
||||||
|
|
||||||
// Detect ticks format
|
// Detect ticks format
|
||||||
try
|
try
|
||||||
|
@ -140,8 +142,8 @@ public class DescParseTickFormat
|
||||||
throw new NumberFormatException();
|
throw new NumberFormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
int hours = Integer.parseInt(desc.substring(0, 2));
|
final int hours = Integer.parseInt(desc.substring(0, 2));
|
||||||
int minutes = Integer.parseInt(desc.substring(2, 4));
|
final int minutes = Integer.parseInt(desc.substring(2, 4));
|
||||||
|
|
||||||
return hoursMinutesToTicks(hours, minutes);
|
return hoursMinutesToTicks(hours, minutes);
|
||||||
}
|
}
|
||||||
|
@ -193,7 +195,7 @@ public class DescParseTickFormat
|
||||||
return hoursMinutesToTicks(hours, minutes);
|
return hoursMinutesToTicks(hours, minutes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long hoursMinutesToTicks(int hours, int minutes)
|
public static long hoursMinutesToTicks(final int hours, final int minutes)
|
||||||
{
|
{
|
||||||
long ret = ticksAtMidnight;
|
long ret = ticksAtMidnight;
|
||||||
ret += (hours - 1) * ticksPerHour;
|
ret += (hours - 1) * ticksPerHour;
|
||||||
|
@ -204,9 +206,9 @@ public class DescParseTickFormat
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long parseAlias(String desc) throws NumberFormatException
|
public static long parseAlias(final String desc) throws NumberFormatException
|
||||||
{
|
{
|
||||||
Integer ret = nameToTicks.get(desc);
|
final Integer ret = nameToTicks.get(desc);
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
{
|
{
|
||||||
throw new NumberFormatException();
|
throw new NumberFormatException();
|
||||||
|
@ -215,7 +217,7 @@ public class DescParseTickFormat
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean meansReset(String desc)
|
public static boolean meansReset(final String desc)
|
||||||
{
|
{
|
||||||
return resetAliases.contains(desc);
|
return resetAliases.contains(desc);
|
||||||
}
|
}
|
||||||
|
@ -223,9 +225,9 @@ public class DescParseTickFormat
|
||||||
// ============================================
|
// ============================================
|
||||||
// FORMAT. From int to describing String
|
// FORMAT. From int to describing String
|
||||||
// --------------------------------------------
|
// --------------------------------------------
|
||||||
public static String format(long ticks)
|
public static String format(final long ticks)
|
||||||
{
|
{
|
||||||
StringBuilder msg = new StringBuilder();
|
final StringBuilder msg = new StringBuilder();
|
||||||
msg.append(Commandtime.colorHighlight1);
|
msg.append(Commandtime.colorHighlight1);
|
||||||
msg.append(format24(ticks));
|
msg.append(format24(ticks));
|
||||||
msg.append(Commandtime.colorDefault);
|
msg.append(Commandtime.colorDefault);
|
||||||
|
@ -239,24 +241,30 @@ public class DescParseTickFormat
|
||||||
return msg.toString();
|
return msg.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String formatTicks(long ticks)
|
public static String formatTicks(final long ticks)
|
||||||
{
|
{
|
||||||
return "" + ticks % ticksPerDay + "ticks";
|
return (ticks % ticksPerDay) + "ticks";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String format24(long ticks)
|
public static String format24(final long ticks)
|
||||||
{
|
{
|
||||||
return formatDateFormat(ticks, SDFTwentyFour);
|
synchronized (SDFTwentyFour)
|
||||||
|
{
|
||||||
|
return formatDateFormat(ticks, SDFTwentyFour);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String format12(long ticks)
|
public static String format12(final long ticks)
|
||||||
{
|
{
|
||||||
return formatDateFormat(ticks, SDFTwelve);
|
synchronized (SDFTwelve)
|
||||||
|
{
|
||||||
|
return formatDateFormat(ticks, SDFTwelve);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String formatDateFormat(long ticks, SimpleDateFormat format)
|
public static String formatDateFormat(final long ticks, final SimpleDateFormat format)
|
||||||
{
|
{
|
||||||
Date date = ticksToDate(ticks);
|
final Date date = ticksToDate(ticks);
|
||||||
return format.format(date);
|
return format.format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,18 +279,18 @@ public class DescParseTickFormat
|
||||||
ticks = ticks - days * ticksPerDay;
|
ticks = ticks - days * ticksPerDay;
|
||||||
|
|
||||||
// How many hours on the last day?
|
// How many hours on the last day?
|
||||||
long hours = ticks / ticksPerHour;
|
final long hours = ticks / ticksPerHour;
|
||||||
ticks = ticks - hours * ticksPerHour;
|
ticks = ticks - hours * ticksPerHour;
|
||||||
|
|
||||||
// How many minutes on the last day?
|
// How many minutes on the last day?
|
||||||
long minutes = (long)Math.floor(ticks / ticksPerMinute);
|
final long minutes = (long)Math.floor(ticks / ticksPerMinute);
|
||||||
double dticks = ticks - minutes * ticksPerMinute;
|
final double dticks = ticks - minutes * ticksPerMinute;
|
||||||
|
|
||||||
// How many seconds on the last day?
|
// How many seconds on the last day?
|
||||||
long seconds = (long)Math.floor(dticks / ticksPerSecond);
|
final long seconds = (long)Math.floor(dticks / ticksPerSecond);
|
||||||
|
|
||||||
// Now we create an english GMT calendar (We wan't no daylight savings)
|
// Now we create an english GMT calendar (We wan't no daylight savings)
|
||||||
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ENGLISH);
|
final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ENGLISH);
|
||||||
cal.setLenient(true);
|
cal.setLenient(true);
|
||||||
|
|
||||||
// And we set the time to 0! And append the time that passed!
|
// And we set the time to 0! And append the time that passed!
|
||||||
|
|
|
@ -4,8 +4,13 @@ import com.earth2me.essentials.DescParseTickFormat;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import java.util.*;
|
import java.util.Collection;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,7 +22,7 @@ public class Commandptime extends EssentialsCommand
|
||||||
public static final ChatColor colorLogo = ChatColor.GREEN;
|
public static final ChatColor colorLogo = ChatColor.GREEN;
|
||||||
public static final ChatColor colorHighlight1 = ChatColor.AQUA;
|
public static final ChatColor colorHighlight1 = ChatColor.AQUA;
|
||||||
public static final ChatColor colorBad = ChatColor.RED;
|
public static final ChatColor colorBad = ChatColor.RED;
|
||||||
|
|
||||||
public Commandptime()
|
public Commandptime()
|
||||||
{
|
{
|
||||||
super("ptime");
|
super("ptime");
|
||||||
|
@ -32,8 +37,12 @@ public class Commandptime extends EssentialsCommand
|
||||||
{
|
{
|
||||||
userSelector = args[1];
|
userSelector = args[1];
|
||||||
}
|
}
|
||||||
|
if (args.length == 3)
|
||||||
|
{
|
||||||
|
userSelector = args[2];
|
||||||
|
}
|
||||||
Set<User> users = getUsers(server, sender, userSelector);
|
Set<User> users = getUsers(server, sender, userSelector);
|
||||||
|
|
||||||
// If no arguments we are reading the time
|
// If no arguments we are reading the time
|
||||||
if (args.length == 0)
|
if (args.length == 0)
|
||||||
{
|
{
|
||||||
|
@ -42,16 +51,16 @@ public class Commandptime extends EssentialsCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
User user = ess.getUser(sender);
|
User user = ess.getUser(sender);
|
||||||
if ( user != null && ! user.isAuthorized("essentials.ptime.others"))
|
if (user != null && !user.isAuthorized("essentials.ptime.others"))
|
||||||
{
|
{
|
||||||
// TODO should not be hardcoded !!
|
// TODO should not be hardcoded !!
|
||||||
sender.sendMessage(colorBad + "You are not authorized to set others PlayerTime");
|
throw new Exception(colorBad + "You are not authorized to set others PlayerTime");
|
||||||
return; // TODO: How to not just die silently? in a good way??
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Long ticks;
|
Long ticks;
|
||||||
// Parse the target time int ticks from args[0]
|
// Parse the target time int ticks from args[0]
|
||||||
if (DescParseTickFormat.meansReset(args[0]))
|
String timeParam = args.length == 2 ? args[0] : args[0] + args[1];
|
||||||
|
if (DescParseTickFormat.meansReset(timeParam))
|
||||||
{
|
{
|
||||||
ticks = null;
|
ticks = null;
|
||||||
}
|
}
|
||||||
|
@ -59,57 +68,53 @@ public class Commandptime extends EssentialsCommand
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ticks = DescParseTickFormat.parse(args[0]);
|
ticks = DescParseTickFormat.parse(timeParam);
|
||||||
}
|
}
|
||||||
catch (NumberFormatException e)
|
catch (NumberFormatException e)
|
||||||
{
|
{
|
||||||
// TODO: Display an error with help included... on how to specify the time
|
throw new NotEnoughArgumentsException();
|
||||||
sender.sendMessage(colorBad + "Unknown time descriptor... brlalidididiablidadadibibibiiba!! TODO");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setUsersTime(sender, users, ticks);
|
setUsersTime(sender, users, ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to get the time and inform
|
* Used to get the time and inform
|
||||||
*/
|
*/
|
||||||
private void getUsersTime(CommandSender sender, Collection<User> users)
|
private void getUsersTime(final CommandSender sender, final Collection<User> users)
|
||||||
{
|
{
|
||||||
if (users.size() == 1)
|
if (users.size() == 1)
|
||||||
{
|
{
|
||||||
Iterator<User> iter = users.iterator();
|
final User user = users.iterator().next();
|
||||||
User user = iter.next();
|
|
||||||
|
|
||||||
if (user.isPlayerTimeRelative())
|
if (user.isPlayerTimeRelative())
|
||||||
{
|
{
|
||||||
sender.sendMessage(colorDefault + user.getName() + "'s time is normal. Time is the same as on the server.");
|
sender.sendMessage(colorDefault + user.getName() + "'s time is normal. Time is the same as on the server.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sender.sendMessage(colorDefault + user.getName() + "'s time is fixed to: "+DescParseTickFormat.format(user.getPlayerTime()));
|
sender.sendMessage(colorDefault + user.getName() + "'s time is fixed to: " + DescParseTickFormat.format(user.getPlayerTime()));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(colorDefault + "These players have fixed time:");
|
sender.sendMessage(colorDefault + "These players have fixed time:");
|
||||||
|
|
||||||
for (User user : users)
|
for (User user : users)
|
||||||
{
|
{
|
||||||
if ( ! user.isPlayerTimeRelative())
|
if (!user.isPlayerTimeRelative())
|
||||||
{
|
{
|
||||||
sender.sendMessage(colorDefault + user.getName() + ": "+DescParseTickFormat.format(user.getPlayerTime()));
|
sender.sendMessage(colorDefault + user.getName() + ": " + DescParseTickFormat.format(user.getPlayerTime()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to set the time and inform of the change
|
* Used to set the time and inform of the change
|
||||||
*/
|
*/
|
||||||
private void setUsersTime(CommandSender sender, Collection<User> users, Long ticks)
|
private void setUsersTime(final CommandSender sender, final Collection<User> users, final Long ticks)
|
||||||
{
|
{
|
||||||
// Update the time
|
// Update the time
|
||||||
if (ticks == null)
|
if (ticks == null)
|
||||||
|
@ -125,30 +130,33 @@ public class Commandptime extends EssentialsCommand
|
||||||
// Set
|
// Set
|
||||||
for (User user : users)
|
for (User user : users)
|
||||||
{
|
{
|
||||||
user.setPlayerTime(ticks, false);
|
long time = user.getPlayerTime();
|
||||||
|
time -= time % 24000;
|
||||||
|
final World world = user.getWorld();
|
||||||
|
user.setPlayerTime(time + 24000 + ticks - world.getTime(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Inform the sender of the change
|
// Inform the sender of the change
|
||||||
sender.sendMessage("");
|
sender.sendMessage("");
|
||||||
StringBuilder msg = new StringBuilder();
|
final StringBuilder msg = new StringBuilder();
|
||||||
if (ticks == null)
|
if (ticks == null)
|
||||||
{
|
{
|
||||||
sender.sendMessage(colorDefault + "The PlayerTime was reset for:");
|
sender.sendMessage(colorDefault + "The players time was reset for:");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sender.sendMessage(colorDefault + "The PlayerTime was fixed to:");
|
sender.sendMessage(colorDefault + "The players time was fixed to:");
|
||||||
sender.sendMessage(DescParseTickFormat.format(ticks));
|
sender.sendMessage(DescParseTickFormat.format(ticks));
|
||||||
msg.append(colorDefault);
|
msg.append(colorDefault);
|
||||||
msg.append("For: ");
|
msg.append("For: ");
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (User user : users)
|
for (User user : users)
|
||||||
{
|
{
|
||||||
if ( ! first)
|
if (!first)
|
||||||
{
|
{
|
||||||
msg.append(colorDefault);
|
msg.append(colorDefault);
|
||||||
msg.append(", ");
|
msg.append(", ");
|
||||||
|
@ -157,28 +165,30 @@ public class Commandptime extends EssentialsCommand
|
||||||
{
|
{
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.append(colorHighlight1);
|
msg.append(colorHighlight1);
|
||||||
msg.append(user.getName());
|
msg.append(user.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(msg.toString());
|
sender.sendMessage(msg.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to parse an argument of the type "users(s) selector"
|
* Used to parse an argument of the type "users(s) selector"
|
||||||
*/
|
*/
|
||||||
private Set<User> getUsers(Server server, CommandSender sender, String selector) throws Exception
|
private Set<User> getUsers(final Server server, final CommandSender sender, final String selector) throws Exception
|
||||||
{
|
{
|
||||||
Set<User> users = new TreeSet<User>(new UserNameComparator());
|
final Set<User> users = new TreeSet<User>(new UserNameComparator());
|
||||||
Player[] players;
|
|
||||||
// If there is no selector we want the sender itself. Or all users if sender isn't a user.
|
// If there is no selector we want the sender itself. Or all users if sender isn't a user.
|
||||||
if (selector == null)
|
if (selector == null)
|
||||||
{
|
{
|
||||||
User user = ess.getUser(sender);
|
final User user = ess.getUser(sender);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
users.addAll(ess.getAllOnlineUsers().values());
|
for (Player player : server.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
users.add(ess.getUser(player));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -186,15 +196,15 @@ public class Commandptime extends EssentialsCommand
|
||||||
}
|
}
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to find the user with name = selector
|
// Try to find the user with name = selector
|
||||||
User user = null;
|
User user = null;
|
||||||
List<Player> matchedPlayers = server.matchPlayer(selector);
|
final List<Player> matchedPlayers = server.matchPlayer(selector);
|
||||||
if (matchedPlayers.size() > 0)
|
if (!matchedPlayers.isEmpty())
|
||||||
{
|
{
|
||||||
user = ess.getUser(matchedPlayers.get(0));
|
user = ess.getUser(matchedPlayers.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user != null)
|
if (user != null)
|
||||||
{
|
{
|
||||||
users.add(user);
|
users.add(user);
|
||||||
|
@ -202,19 +212,24 @@ public class Commandptime extends EssentialsCommand
|
||||||
// If that fails, Is the argument something like "*" or "all"?
|
// If that fails, Is the argument something like "*" or "all"?
|
||||||
else if (selector.equalsIgnoreCase("*") || selector.equalsIgnoreCase("all"))
|
else if (selector.equalsIgnoreCase("*") || selector.equalsIgnoreCase("all"))
|
||||||
{
|
{
|
||||||
users.addAll(ess.getAllOnlineUsers().values());
|
for (Player player : server.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
users.add(ess.getUser(player));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// We failed to understand the world target...
|
// We failed to understand the world target...
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new Exception("Could not find the player(s) \""+selector+"\"");
|
throw new Exception("Could not find the player(s) \"" + selector + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserNameComparator implements Comparator<User> {
|
|
||||||
|
class UserNameComparator implements Comparator<User>
|
||||||
|
{
|
||||||
public int compare(User a, User b)
|
public int compare(User a, User b)
|
||||||
{
|
{
|
||||||
return a.getName().compareTo(b.getName());
|
return a.getName().compareTo(b.getName());
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class Commandtime extends EssentialsCommand
|
||||||
public static final ChatColor colorLogo = ChatColor.GREEN;
|
public static final ChatColor colorLogo = ChatColor.GREEN;
|
||||||
public static final ChatColor colorHighlight1 = ChatColor.AQUA;
|
public static final ChatColor colorHighlight1 = ChatColor.AQUA;
|
||||||
public static final ChatColor colorBad = ChatColor.RED;
|
public static final ChatColor colorBad = ChatColor.RED;
|
||||||
|
|
||||||
public Commandtime()
|
public Commandtime()
|
||||||
{
|
{
|
||||||
super("time");
|
super("time");
|
||||||
|
@ -32,8 +32,12 @@ public class Commandtime extends EssentialsCommand
|
||||||
{
|
{
|
||||||
worldSelector = args[1];
|
worldSelector = args[1];
|
||||||
}
|
}
|
||||||
|
if (args.length == 3)
|
||||||
|
{
|
||||||
|
worldSelector = args[2];
|
||||||
|
}
|
||||||
Set<World> worlds = getWorlds(server, sender, worldSelector);
|
Set<World> worlds = getWorlds(server, sender, worldSelector);
|
||||||
|
|
||||||
// If no arguments we are reading the time
|
// If no arguments we are reading the time
|
||||||
if (args.length == 0)
|
if (args.length == 0)
|
||||||
{
|
{
|
||||||
|
@ -42,29 +46,26 @@ public class Commandtime extends EssentialsCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
User user = ess.getUser(sender);
|
User user = ess.getUser(sender);
|
||||||
if ( user != null && ! user.isAuthorized("essentials.time.set"))
|
if (user != null && !user.isAuthorized("essentials.time.set"))
|
||||||
{
|
{
|
||||||
// TODO should not be hardcoded !!
|
// TODO should not be hardcoded !!
|
||||||
sender.sendMessage(colorBad + "You are not authorized to set the time");
|
throw new Exception(colorBad + "You are not authorized to set the time");
|
||||||
return; // TODO: How to not just die silently? in a good way??
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the target time int ticks from args[0]
|
// Parse the target time int ticks from args[0]
|
||||||
long ticks;
|
long ticks;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ticks = DescParseTickFormat.parse(args[0]);
|
ticks = DescParseTickFormat.parse(args.length == 2 ? args[0] : args[0] + args[1]);
|
||||||
}
|
}
|
||||||
catch (NumberFormatException e)
|
catch (NumberFormatException e)
|
||||||
{
|
{
|
||||||
// TODO: Display an error with help included... on how to specify the time
|
throw new NotEnoughArgumentsException();
|
||||||
sender.sendMessage(colorBad + "Unknown time descriptor... brlalidididiablidadadibibibiiba!! TODO");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setWorldsTime(sender, worlds, ticks);
|
setWorldsTime(sender, worlds, ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to get the time and inform
|
* Used to get the time and inform
|
||||||
*/
|
*/
|
||||||
|
@ -77,14 +78,14 @@ public class Commandtime extends EssentialsCommand
|
||||||
sender.sendMessage(DescParseTickFormat.format(iter.next().getTime()));
|
sender.sendMessage(DescParseTickFormat.format(iter.next().getTime()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (World world : worlds)
|
for (World world : worlds)
|
||||||
{
|
{
|
||||||
sender.sendMessage(colorDefault + world.getName()+": " + DescParseTickFormat.format(world.getTime()));
|
sender.sendMessage(colorDefault + world.getName() + ": " + DescParseTickFormat.format(world.getTime()));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to set the time and inform of the change
|
* Used to set the time and inform of the change
|
||||||
*/
|
*/
|
||||||
|
@ -95,19 +96,19 @@ public class Commandtime extends EssentialsCommand
|
||||||
{
|
{
|
||||||
world.setTime(ticks);
|
world.setTime(ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inform the sender of the change
|
// Inform the sender of the change
|
||||||
sender.sendMessage("");
|
sender.sendMessage("");
|
||||||
sender.sendMessage(colorDefault + "The time was set to");
|
sender.sendMessage(colorDefault + "The time was set to");
|
||||||
sender.sendMessage(DescParseTickFormat.format(ticks));
|
sender.sendMessage(DescParseTickFormat.format(ticks));
|
||||||
|
|
||||||
StringBuilder msg = new StringBuilder();
|
StringBuilder msg = new StringBuilder();
|
||||||
msg.append(colorDefault);
|
msg.append(colorDefault);
|
||||||
msg.append("In ");
|
msg.append("In ");
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (World world : worlds)
|
for (World world : worlds)
|
||||||
{
|
{
|
||||||
if ( ! first)
|
if (!first)
|
||||||
{
|
{
|
||||||
msg.append(colorDefault);
|
msg.append(colorDefault);
|
||||||
msg.append(", ");
|
msg.append(", ");
|
||||||
|
@ -116,21 +117,21 @@ public class Commandtime extends EssentialsCommand
|
||||||
{
|
{
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.append(colorHighlight1);
|
msg.append(colorHighlight1);
|
||||||
msg.append(world.getName());
|
msg.append(world.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(msg.toString());
|
sender.sendMessage(msg.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to parse an argument of the type "world(s) selector"
|
* Used to parse an argument of the type "world(s) selector"
|
||||||
*/
|
*/
|
||||||
private Set<World> getWorlds(Server server, CommandSender sender, String selector) throws Exception
|
private Set<World> getWorlds(Server server, CommandSender sender, String selector) throws Exception
|
||||||
{
|
{
|
||||||
Set<World> worlds = new TreeSet<World>(new WorldNameComparator());
|
Set<World> worlds = new TreeSet<World>(new WorldNameComparator());
|
||||||
|
|
||||||
// If there is no selector we want the world the user is currently in. Or all worlds if it isn't a user.
|
// If there is no selector we want the world the user is currently in. Or all worlds if it isn't a user.
|
||||||
if (selector == null)
|
if (selector == null)
|
||||||
{
|
{
|
||||||
|
@ -145,7 +146,7 @@ public class Commandtime extends EssentialsCommand
|
||||||
}
|
}
|
||||||
return worlds;
|
return worlds;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to find the world with name = selector
|
// Try to find the world with name = selector
|
||||||
World world = server.getWorld(selector);
|
World world = server.getWorld(selector);
|
||||||
if (world != null)
|
if (world != null)
|
||||||
|
@ -160,16 +161,16 @@ public class Commandtime extends EssentialsCommand
|
||||||
// We failed to understand the world target...
|
// We failed to understand the world target...
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new Exception("Could not find the world(s) \""+selector+"\"");
|
throw new Exception("Could not find the world(s) \"" + selector + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
return worlds;
|
return worlds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class WorldNameComparator implements Comparator<World>
|
||||||
class WorldNameComparator implements Comparator<World> {
|
{
|
||||||
public int compare(World a, World b)
|
public int compare(World a, World b)
|
||||||
{
|
{
|
||||||
return a.getName().compareTo(b.getName());
|
return a.getName().compareTo(b.getName());
|
||||||
|
|
|
@ -206,6 +206,10 @@ commands:
|
||||||
description: Assigns a command to the item in hand, {player} will be replaced by the name of the player that you click.
|
description: Assigns a command to the item in hand, {player} will be replaced by the name of the player that you click.
|
||||||
usage: /<command> [command] <arguments>
|
usage: /<command> [command] <arguments>
|
||||||
aliases: [pt,epowertool,ept]
|
aliases: [pt,epowertool,ept]
|
||||||
|
ptime:
|
||||||
|
description: Set or reset the playertime for yourself or the player(s) specified.
|
||||||
|
usage: /<command> [reset|day|night|dawn|17:30|4pm|4000ticks] <playername|all>
|
||||||
|
aliases: [eptime]
|
||||||
r:
|
r:
|
||||||
description: Quickly reply to the last player to message you.
|
description: Quickly reply to the last player to message you.
|
||||||
usage: /<command> [message]
|
usage: /<command> [message]
|
||||||
|
@ -271,8 +275,8 @@ commands:
|
||||||
usage: /<command> <true/false> [duration]
|
usage: /<command> <true/false> [duration]
|
||||||
aliases: [ethunder]
|
aliases: [ethunder]
|
||||||
time:
|
time:
|
||||||
description: Change the time to day or night of the player (default) or world (essentials.time.world permission).
|
description: Change the time in the world where you are (default) or in the world(s) specified
|
||||||
usage: /<command> [day|night|reset] <playername>
|
usage: /<command> [day|night|dawn|17:30|4pm|4000ticks] <worldname|all>
|
||||||
aliases: [etime, day, night, playertime]
|
aliases: [etime, day, night, playertime]
|
||||||
togglejail:
|
togglejail:
|
||||||
description: Prevents a player from interacting with the world and teleports him/her to the the jail specified
|
description: Prevents a player from interacting with the world and teleports him/her to the the jail specified
|
||||||
|
|
Loading…
Reference in a new issue