This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
package com.earth2me.essentials;
|
|
|
|
|
2011-05-15 13:18:38 +00:00
|
|
|
import java.io.BufferedReader;
|
2011-05-09 02:47:19 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
2011-05-15 13:18:38 +00:00
|
|
|
import java.io.FileReader;
|
2011-05-09 02:47:19 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.URL;
|
2011-05-02 18:22:17 +00:00
|
|
|
import java.text.DecimalFormat;
|
2011-05-13 19:18:22 +00:00
|
|
|
import java.text.DecimalFormatSymbols;
|
2011-05-09 02:47:19 +00:00
|
|
|
import java.text.MessageFormat;
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
import java.util.Calendar;
|
2011-05-09 02:47:19 +00:00
|
|
|
import java.util.Enumeration;
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
import java.util.GregorianCalendar;
|
2011-05-16 08:40:28 +00:00
|
|
|
import java.util.HashSet;
|
2011-05-09 02:47:19 +00:00
|
|
|
import java.util.Locale;
|
2011-05-16 08:40:28 +00:00
|
|
|
import java.util.MissingResourceException;
|
2011-05-09 02:47:19 +00:00
|
|
|
import java.util.ResourceBundle;
|
2011-05-16 08:40:28 +00:00
|
|
|
import java.util.Set;
|
2011-05-15 13:18:38 +00:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
|
|
|
|
|
|
|
|
public class Util
|
|
|
|
{
|
2011-05-16 08:40:28 +00:00
|
|
|
private final static Logger logger = Logger.getLogger("Minecraft");
|
|
|
|
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
public static String sanitizeFileName(String name)
|
|
|
|
{
|
|
|
|
return name.toLowerCase().replaceAll("[^a-z0-9]", "_");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String formatDateDiff(long date)
|
|
|
|
{
|
|
|
|
Calendar c = new GregorianCalendar();
|
|
|
|
c.setTimeInMillis(date);
|
|
|
|
Calendar now = new GregorianCalendar();
|
|
|
|
return Util.formatDateDiff(now, c);
|
|
|
|
}
|
2011-05-07 23:06:03 +00:00
|
|
|
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
public static String formatDateDiff(Calendar fromDate, Calendar toDate)
|
|
|
|
{
|
|
|
|
boolean future = false;
|
|
|
|
if (toDate.equals(fromDate))
|
|
|
|
{
|
2011-05-10 19:02:59 +00:00
|
|
|
return Util.i18n("now");
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
}
|
|
|
|
if (toDate.after(fromDate))
|
|
|
|
{
|
|
|
|
future = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
int[] types = new int[]
|
|
|
|
{
|
|
|
|
Calendar.YEAR,
|
|
|
|
Calendar.MONTH,
|
|
|
|
Calendar.DAY_OF_MONTH,
|
|
|
|
Calendar.HOUR_OF_DAY,
|
|
|
|
Calendar.MINUTE,
|
|
|
|
Calendar.SECOND
|
|
|
|
};
|
|
|
|
String[] names = new String[]
|
|
|
|
{
|
2011-05-10 19:02:59 +00:00
|
|
|
Util.i18n("year"),
|
|
|
|
Util.i18n("years"),
|
|
|
|
Util.i18n("month"),
|
|
|
|
Util.i18n("months"),
|
|
|
|
Util.i18n("day"),
|
|
|
|
Util.i18n("days"),
|
|
|
|
Util.i18n("hour"),
|
|
|
|
Util.i18n("hours"),
|
|
|
|
Util.i18n("minute"),
|
|
|
|
Util.i18n("minutes"),
|
|
|
|
Util.i18n("second"),
|
|
|
|
Util.i18n("seconds")
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
};
|
|
|
|
for (int i = 0; i < types.length; i++)
|
|
|
|
{
|
|
|
|
int diff = dateDiff(types[i], fromDate, toDate, future);
|
|
|
|
if (diff > 0)
|
|
|
|
{
|
2011-05-10 19:02:59 +00:00
|
|
|
sb.append(" ").append(diff).append(" ").append(names[i * 2 + (diff > 1 ? 1 : 0)]);
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sb.length() == 0)
|
|
|
|
{
|
|
|
|
return "now";
|
|
|
|
}
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future)
|
|
|
|
{
|
|
|
|
int diff = 0;
|
|
|
|
while ((future && !fromDate.after(toDate)) || (!future && !fromDate.before(toDate)))
|
|
|
|
{
|
|
|
|
fromDate.add(type, future ? 1 : -1);
|
|
|
|
diff++;
|
|
|
|
}
|
|
|
|
diff--;
|
|
|
|
fromDate.add(type, future ? -1 : 1);
|
|
|
|
return diff;
|
|
|
|
}
|
2011-05-15 12:23:47 +00:00
|
|
|
|
|
|
|
public static long parseDateDiff(String time, boolean future) throws Exception
|
|
|
|
{
|
|
|
|
Pattern timePattern = Pattern.compile(
|
2011-05-16 08:40:28 +00:00
|
|
|
"(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?"
|
|
|
|
+ "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?"
|
|
|
|
+ "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?"
|
|
|
|
+ "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?"
|
|
|
|
+ "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?"
|
|
|
|
+ "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?"
|
|
|
|
+ "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE);
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
Matcher m = timePattern.matcher(time);
|
|
|
|
int years = 0;
|
|
|
|
int months = 0;
|
|
|
|
int weeks = 0;
|
|
|
|
int days = 0;
|
|
|
|
int hours = 0;
|
|
|
|
int minutes = 0;
|
|
|
|
int seconds = 0;
|
|
|
|
boolean found = false;
|
|
|
|
while (m.find())
|
|
|
|
{
|
|
|
|
if (m.group() == null || m.group().isEmpty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < m.groupCount(); i++)
|
|
|
|
{
|
|
|
|
if (m.group(i) != null && !m.group(i).isEmpty())
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
if (m.group(1) != null && !m.group(1).isEmpty())
|
|
|
|
{
|
|
|
|
years = Integer.parseInt(m.group(1));
|
|
|
|
}
|
|
|
|
if (m.group(2) != null && !m.group(2).isEmpty())
|
|
|
|
{
|
|
|
|
months = Integer.parseInt(m.group(2));
|
|
|
|
}
|
|
|
|
if (m.group(3) != null && !m.group(3).isEmpty())
|
|
|
|
{
|
|
|
|
weeks = Integer.parseInt(m.group(3));
|
|
|
|
}
|
|
|
|
if (m.group(4) != null && !m.group(4).isEmpty())
|
|
|
|
{
|
|
|
|
days = Integer.parseInt(m.group(4));
|
|
|
|
}
|
|
|
|
if (m.group(5) != null && !m.group(5).isEmpty())
|
|
|
|
{
|
|
|
|
hours = Integer.parseInt(m.group(5));
|
|
|
|
}
|
|
|
|
if (m.group(6) != null && !m.group(6).isEmpty())
|
|
|
|
{
|
|
|
|
minutes = Integer.parseInt(m.group(6));
|
|
|
|
}
|
|
|
|
if (m.group(7) != null && !m.group(7).isEmpty())
|
|
|
|
{
|
|
|
|
seconds = Integer.parseInt(m.group(7));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
{
|
2011-05-15 12:23:47 +00:00
|
|
|
throw new Exception(Util.i18n("illegalDate"));
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
}
|
|
|
|
Calendar c = new GregorianCalendar();
|
|
|
|
if (years > 0)
|
|
|
|
{
|
|
|
|
c.add(Calendar.YEAR, years * (future ? 1 : -1));
|
|
|
|
}
|
|
|
|
if (months > 0)
|
|
|
|
{
|
|
|
|
c.add(Calendar.MONTH, months * (future ? 1 : -1));
|
|
|
|
}
|
|
|
|
if (weeks > 0)
|
|
|
|
{
|
|
|
|
c.add(Calendar.WEEK_OF_YEAR, weeks * (future ? 1 : -1));
|
|
|
|
}
|
|
|
|
if (days > 0)
|
|
|
|
{
|
|
|
|
c.add(Calendar.DAY_OF_MONTH, days * (future ? 1 : -1));
|
|
|
|
}
|
|
|
|
if (hours > 0)
|
|
|
|
{
|
|
|
|
c.add(Calendar.HOUR_OF_DAY, hours * (future ? 1 : -1));
|
|
|
|
}
|
|
|
|
if (minutes > 0)
|
|
|
|
{
|
|
|
|
c.add(Calendar.MINUTE, minutes * (future ? 1 : -1));
|
|
|
|
}
|
|
|
|
if (seconds > 0)
|
|
|
|
{
|
|
|
|
c.add(Calendar.SECOND, seconds * (future ? 1 : -1));
|
|
|
|
}
|
|
|
|
return c.getTimeInMillis();
|
|
|
|
}
|
2011-05-07 23:06:03 +00:00
|
|
|
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
public static Location getSafeDestination(Location loc) throws Exception
|
|
|
|
{
|
|
|
|
if (loc == null)
|
|
|
|
{
|
2011-05-10 19:02:59 +00:00
|
|
|
throw new Exception(Util.i18n("destinationNotSet"));
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
}
|
|
|
|
World world = loc.getWorld();
|
|
|
|
double x = Math.floor(loc.getX()) + 0.5;
|
|
|
|
double y = Math.floor(loc.getY());
|
|
|
|
double z = Math.floor(loc.getZ()) + 0.5;
|
|
|
|
|
|
|
|
while (isBlockAboveAir(world, x, y, z))
|
|
|
|
{
|
|
|
|
y -= 1.0D;
|
|
|
|
if (y < 0.0D)
|
|
|
|
{
|
2011-05-10 19:02:59 +00:00
|
|
|
throw new Exception(Util.i18n("holeInFloor"));
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (isBlockUnsafe(world, x, y, z))
|
|
|
|
{
|
|
|
|
y += 1.0D;
|
|
|
|
if (y >= 110.0D)
|
|
|
|
{
|
|
|
|
x += 1.0D;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (isBlockUnsafe(world, x, y, z))
|
|
|
|
{
|
|
|
|
y -= 1.0D;
|
|
|
|
if (y <= 1.0D)
|
|
|
|
{
|
|
|
|
y = 110.0D;
|
|
|
|
x += 1.0D;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new Location(world, x, y, z, loc.getYaw(), loc.getPitch());
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean isBlockAboveAir(World world, double x, double y, double z)
|
|
|
|
{
|
|
|
|
return world.getBlockAt((int)Math.floor(x), (int)Math.floor(y - 1.0D), (int)Math.floor(z)).getType() == Material.AIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isBlockUnsafe(World world, double x, double y, double z)
|
|
|
|
{
|
|
|
|
Block below = world.getBlockAt((int)Math.floor(x), (int)Math.floor(y - 1.0D), (int)Math.floor(z));
|
|
|
|
if (below.getType() == Material.LAVA || below.getType() == Material.STATIONARY_LAVA)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (below.getType() == Material.FIRE)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((world.getBlockAt((int)Math.floor(x), (int)Math.floor(y), (int)Math.floor(z)).getType() != Material.AIR)
|
|
|
|
|| (world.getBlockAt((int)Math.floor(x), (int)Math.floor(y + 1.0D), (int)Math.floor(z)).getType() != Material.AIR))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return isBlockAboveAir(world, x, y, z);
|
|
|
|
}
|
2011-05-13 19:18:22 +00:00
|
|
|
private static DecimalFormat df = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US));
|
2011-05-07 23:06:03 +00:00
|
|
|
|
|
|
|
public static String formatCurrency(double value)
|
|
|
|
{
|
2011-05-16 08:40:28 +00:00
|
|
|
String str = Essentials.getStatic().getSettings().getCurrencySymbol() + df.format(value);
|
|
|
|
if (str.endsWith(".00"))
|
|
|
|
{
|
|
|
|
str = str.substring(0, str.length() - 3);
|
2011-05-13 16:57:45 +00:00
|
|
|
}
|
|
|
|
return str;
|
2011-05-07 23:06:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static double roundDouble(double d)
|
|
|
|
{
|
2011-05-09 02:48:30 +00:00
|
|
|
return Math.round(d * 100.0) / 100.0;
|
2011-05-02 09:55:22 +00:00
|
|
|
}
|
2011-05-09 02:48:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
private static class ConfigClassLoader extends ClassLoader
|
|
|
|
{
|
2011-05-09 02:47:19 +00:00
|
|
|
private File dataFolder;
|
|
|
|
private ClassLoader cl;
|
|
|
|
|
|
|
|
public ConfigClassLoader(File dataFolder, ClassLoader cl)
|
|
|
|
{
|
|
|
|
this.dataFolder = dataFolder;
|
|
|
|
this.cl = cl;
|
|
|
|
}
|
2011-05-09 02:48:30 +00:00
|
|
|
|
2011-05-09 02:47:19 +00:00
|
|
|
@Override
|
|
|
|
public URL getResource(String string)
|
|
|
|
{
|
|
|
|
File file = new File(dataFolder, string);
|
|
|
|
if (file.exists())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return file.toURI().toURL();
|
|
|
|
}
|
|
|
|
catch (MalformedURLException ex)
|
|
|
|
{
|
|
|
|
return cl.getResource(string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cl.getResource(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public synchronized void clearAssertionStatus()
|
|
|
|
{
|
|
|
|
cl.clearAssertionStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public InputStream getResourceAsStream(String string)
|
|
|
|
{
|
|
|
|
File file = new File(dataFolder, string);
|
|
|
|
if (file.exists())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2011-05-15 13:18:38 +00:00
|
|
|
BufferedReader br = new BufferedReader(new FileReader(file));
|
|
|
|
String version = br.readLine();
|
2011-05-15 13:19:04 +00:00
|
|
|
br.close();
|
2011-05-16 08:40:28 +00:00
|
|
|
if (version == null || !version.equals("#version: " + Essentials.getStatic().getDescription().getVersion()))
|
|
|
|
{
|
|
|
|
logger.log(Level.WARNING, String.format("Translation file %s is not updated for Essentials version. Will use default.", file));
|
2011-05-15 13:18:38 +00:00
|
|
|
return cl.getResourceAsStream(string);
|
|
|
|
}
|
2011-05-09 02:47:19 +00:00
|
|
|
return new FileInputStream(file);
|
|
|
|
}
|
2011-05-15 13:18:38 +00:00
|
|
|
catch (IOException ex)
|
2011-05-09 02:47:19 +00:00
|
|
|
{
|
|
|
|
return cl.getResourceAsStream(string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cl.getResourceAsStream(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Enumeration<URL> getResources(String string) throws IOException
|
|
|
|
{
|
|
|
|
return cl.getResources(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<?> loadClass(String string) throws ClassNotFoundException
|
|
|
|
{
|
|
|
|
return cl.loadClass(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public synchronized void setClassAssertionStatus(String string, boolean bln)
|
|
|
|
{
|
|
|
|
cl.setClassAssertionStatus(string, bln);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public synchronized void setDefaultAssertionStatus(boolean bln)
|
|
|
|
{
|
|
|
|
cl.setDefaultAssertionStatus(bln);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public synchronized void setPackageAssertionStatus(String string, boolean bln)
|
|
|
|
{
|
|
|
|
cl.setPackageAssertionStatus(string, bln);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private static final Locale defaultLocale = Locale.getDefault();
|
|
|
|
public static Locale currentLocale = defaultLocale;
|
|
|
|
private static ResourceBundle bundle = ResourceBundle.getBundle("messages", defaultLocale);
|
2011-05-16 08:40:28 +00:00
|
|
|
private static ResourceBundle defaultBundle = ResourceBundle.getBundle("messages", Locale.US);
|
2011-05-09 02:48:30 +00:00
|
|
|
|
|
|
|
public static String i18n(String string)
|
|
|
|
{
|
2011-05-16 08:40:28 +00:00
|
|
|
try {
|
|
|
|
return bundle.getString(string);
|
|
|
|
}
|
|
|
|
catch (MissingResourceException ex)
|
|
|
|
{
|
|
|
|
logger.log(Level.WARNING, String.format("Missing translation key \"%s\" in translation file %s", ex.getKey(), bundle.getLocale().toString()));
|
|
|
|
return defaultBundle.getString(string);
|
|
|
|
}
|
2011-05-09 02:47:19 +00:00
|
|
|
}
|
2011-05-09 02:48:30 +00:00
|
|
|
|
|
|
|
public static String format(String string, Object... objects)
|
|
|
|
{
|
2011-05-09 02:47:19 +00:00
|
|
|
MessageFormat mf = new MessageFormat(i18n(string));
|
|
|
|
return mf.format(objects);
|
|
|
|
}
|
|
|
|
|
2011-05-09 02:48:30 +00:00
|
|
|
public static void updateLocale(String loc, File dataFolder)
|
|
|
|
{
|
|
|
|
if (loc == null || loc.isEmpty())
|
|
|
|
{
|
2011-05-09 02:47:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-05-16 08:40:28 +00:00
|
|
|
String[] parts = loc.split("[_\\.]");
|
2011-05-09 02:48:30 +00:00
|
|
|
if (parts.length == 1)
|
|
|
|
{
|
2011-05-09 02:47:19 +00:00
|
|
|
currentLocale = new Locale(parts[0]);
|
|
|
|
}
|
2011-05-09 02:48:30 +00:00
|
|
|
if (parts.length == 2)
|
|
|
|
{
|
2011-05-09 02:47:19 +00:00
|
|
|
currentLocale = new Locale(parts[0], parts[1]);
|
|
|
|
}
|
2011-05-16 08:40:28 +00:00
|
|
|
if (parts.length == 3)
|
|
|
|
{
|
|
|
|
currentLocale = new Locale(parts[0], parts[1], parts[2]);
|
|
|
|
}
|
|
|
|
logger.log(Level.INFO, String.format("Using locale %s", currentLocale.toString()));
|
2011-05-09 02:47:19 +00:00
|
|
|
bundle = ResourceBundle.getBundle("messages", currentLocale, new ConfigClassLoader(dataFolder, Util.class.getClassLoader()));
|
2011-05-16 08:40:28 +00:00
|
|
|
if (!bundle.keySet().containsAll(defaultBundle.keySet())) {
|
|
|
|
logger.log(Level.WARNING, String.format("Translation file %s does not contain all translation keys.", currentLocale.toString()));
|
|
|
|
}
|
2011-05-09 02:47:19 +00:00
|
|
|
}
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
}
|