mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-07-31 18:01:42 +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
This commit is contained in:
parent
03fd6249fc
commit
224c18348a
126 changed files with 3542 additions and 3145 deletions
|
@ -39,7 +39,6 @@ public class EssentialsTest extends TestCase
|
|||
Settings settings = null;
|
||||
Spawn spawn = null;
|
||||
TargetBlock targetBlock = null;
|
||||
TeleportTimer teleportTimer = null;
|
||||
User user = null;
|
||||
assertNull(itemDb);
|
||||
assertNull(mob);
|
||||
|
@ -48,7 +47,6 @@ public class EssentialsTest extends TestCase
|
|||
assertNull(settings);
|
||||
assertNull(spawn);
|
||||
assertNull(targetBlock);
|
||||
assertNull(teleportTimer);
|
||||
assertNull(user);
|
||||
}
|
||||
catch (Throwable ex)
|
||||
|
|
|
@ -1,18 +1,31 @@
|
|||
package com.earth2me.essentials;
|
||||
|
||||
import java.io.IOException;
|
||||
import junit.framework.TestCase;
|
||||
import net.minecraft.server.WorldServer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.plugin.InvalidDescriptionException;
|
||||
|
||||
|
||||
public class UserTest extends TestCase
|
||||
{
|
||||
private OfflinePlayer base1;
|
||||
private Essentials ess;
|
||||
|
||||
public UserTest(String testName)
|
||||
{
|
||||
super(testName);
|
||||
ess = new Essentials();
|
||||
try
|
||||
{
|
||||
ess.setupForTesting();
|
||||
}
|
||||
catch (InvalidDescriptionException ex)
|
||||
{
|
||||
fail("InvalidDescriptionException");
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
fail("IOException");
|
||||
}
|
||||
base1 = new OfflinePlayer("TestPlayer1");
|
||||
}
|
||||
|
||||
|
@ -36,26 +49,25 @@ public class UserTest extends TestCase
|
|||
public void testUpdate()
|
||||
{
|
||||
should("update an existing player with the same name, rather than creating a new player");
|
||||
User.get(base1);
|
||||
int size1 = User.size();
|
||||
ess.getUser(base1);
|
||||
//int size1 = User.size();
|
||||
OfflinePlayer base1alt = new OfflinePlayer(base1.getName());
|
||||
assertEquals(base1alt, User.get(base1alt).getBase());
|
||||
assertTrue(size1 == User.size());
|
||||
assertEquals(base1alt, ess.getUser(base1alt).getBase());
|
||||
//assertTrue(size1 == User.size());
|
||||
}
|
||||
|
||||
/*public void testHome() throws Exception
|
||||
{
|
||||
should("return the home set by setHome");
|
||||
Location home = new Location(null, 1, 2, 3, 4, 5);
|
||||
User user = User.get(base1);
|
||||
user.setHome(home);
|
||||
assertEquals(user.getHome(), home);
|
||||
should("return the home set by setHome");
|
||||
Location home = new Location(null, 1, 2, 3, 4, 5);
|
||||
User user = User.get(base1);
|
||||
user.setHome(home);
|
||||
assertEquals(user.getHome(), home);
|
||||
}*/
|
||||
|
||||
public void testMoney()
|
||||
{
|
||||
should("properly set, take, give, and get money");
|
||||
User user = User.get(base1);
|
||||
User user = ess.getUser(base1);
|
||||
double i;
|
||||
user.setMoney(i = 100.5);
|
||||
user.takeMoney(50);
|
||||
|
@ -64,11 +76,11 @@ public class UserTest extends TestCase
|
|||
i += 25;
|
||||
assertEquals(user.getMoney(), i);
|
||||
}
|
||||
|
||||
|
||||
public void testGetGroup()
|
||||
{
|
||||
should("return the default group");
|
||||
User user = User.get(base1);
|
||||
User user = ess.getUser(base1);
|
||||
assertEquals(user.getGroup(), "default");
|
||||
}
|
||||
}
|
||||
|
|
143
Essentials/test/com/earth2me/essentials/UtilTest.java
Normal file
143
Essentials/test/com/earth2me/essentials/UtilTest.java
Normal file
|
@ -0,0 +1,143 @@
|
|||
package com.earth2me.essentials;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
public class UtilTest extends TestCase
|
||||
{
|
||||
public void testFDDnow() {
|
||||
Calendar c = new GregorianCalendar();
|
||||
String resp = Util.formatDateDiff(c, c);
|
||||
assertEquals(resp, "now");
|
||||
}
|
||||
|
||||
public void testFDDfuture() {
|
||||
Calendar a, b;
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 10, 0, 1);
|
||||
assertEquals(" 1 second", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 10, 0, 2);
|
||||
assertEquals(" 2 seconds", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 10, 0, 3);
|
||||
assertEquals(" 3 seconds", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 10, 1, 0);
|
||||
assertEquals(" 1 minute", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 10, 2, 0);
|
||||
assertEquals(" 2 minutes", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 10, 3, 0);
|
||||
assertEquals(" 3 minutes", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 11, 0, 0);
|
||||
assertEquals(" 1 hour", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 12, 0, 0);
|
||||
assertEquals(" 2 hours", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 13, 0, 0);
|
||||
assertEquals(" 3 hours", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 2, 10, 0, 0);
|
||||
assertEquals(" 1 day", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 3, 10, 0, 0);
|
||||
assertEquals(" 2 days", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 4, 10, 0, 0);
|
||||
assertEquals(" 3 days", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 2, 1, 10, 0, 0);
|
||||
assertEquals(" 1 month", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 3, 1, 10, 0, 0);
|
||||
assertEquals(" 2 months", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 4, 1, 10, 0, 0);
|
||||
assertEquals(" 3 months", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2011, 1, 1, 10, 0, 0);
|
||||
assertEquals(" 1 year", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2012, 1, 1, 10, 0, 0);
|
||||
assertEquals(" 2 years", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2013, 1, 1, 10, 0, 0);
|
||||
assertEquals(" 3 years", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2011, 4, 5, 23, 38, 12);
|
||||
assertEquals(" 1 year 3 months 4 days 13 hours 38 minutes 12 seconds", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 9, 17, 23, 45, 45);
|
||||
b = new GregorianCalendar(2015, 3, 7, 10, 0, 0);
|
||||
assertEquals(" 4 years 5 months 20 days 10 hours 14 minutes 15 seconds", Util.formatDateDiff(a, b));
|
||||
}
|
||||
|
||||
public void testFDDpast() {
|
||||
Calendar a, b;
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 9, 59, 59);
|
||||
assertEquals(" 1 second", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 9, 59, 58);
|
||||
assertEquals(" 2 seconds", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 9, 59, 57);
|
||||
assertEquals(" 3 seconds", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 9, 59, 0);
|
||||
assertEquals(" 1 minute", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 9, 58, 0);
|
||||
assertEquals(" 2 minutes", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 9, 57, 0);
|
||||
assertEquals(" 3 minutes", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 9, 0, 0);
|
||||
assertEquals(" 1 hour", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 8, 0, 0);
|
||||
assertEquals(" 2 hours", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 1, 7, 0, 0);
|
||||
assertEquals(" 3 hours", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 5, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 4, 10, 0, 0);
|
||||
assertEquals(" 1 day", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 5, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 3, 10, 0, 0);
|
||||
assertEquals(" 2 days", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 5, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 1, 2, 10, 0, 0);
|
||||
assertEquals(" 3 days", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 5, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 4, 1, 10, 0, 0);
|
||||
assertEquals(" 1 month", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 5, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 3, 1, 10, 0, 0);
|
||||
assertEquals(" 2 months", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 5, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2010, 2, 1, 10, 0, 0);
|
||||
assertEquals(" 3 months", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2009, 1, 1, 10, 0, 0);
|
||||
assertEquals(" 1 year", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2008, 1, 1, 10, 0, 0);
|
||||
assertEquals(" 2 years", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2007, 1, 1, 10, 0, 0);
|
||||
assertEquals(" 3 years", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
|
||||
b = new GregorianCalendar(2009, 4, 5, 23, 38, 12);
|
||||
assertEquals(" 8 months 26 days 10 hours 21 minutes 48 seconds", Util.formatDateDiff(a, b));
|
||||
a = new GregorianCalendar(2010, 9, 17, 23, 45, 45);
|
||||
b = new GregorianCalendar(2000, 3, 7, 10, 0, 0);
|
||||
assertEquals(" 10 years 6 months 10 days 13 hours 45 minutes 45 seconds", Util.formatDateDiff(a, b));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue