2013-06-08 15:33:30 +00:00
|
|
|
package com.earth2me.essentials;
|
|
|
|
|
|
|
|
import com.earth2me.essentials.commands.IEssentialsCommand;
|
|
|
|
import com.earth2me.essentials.commands.NoChargeException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
import org.bukkit.World.Environment;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.plugin.InvalidDescriptionException;
|
|
|
|
|
|
|
|
|
|
|
|
public class ToggleTest extends TestCase
|
|
|
|
{
|
|
|
|
private final OfflinePlayer base1;
|
|
|
|
private final Essentials ess;
|
|
|
|
private final FakeServer server;
|
|
|
|
|
|
|
|
public ToggleTest(String testName)
|
|
|
|
{
|
|
|
|
super(testName);
|
|
|
|
server = new FakeServer();
|
|
|
|
server.createWorld("testWorld", Environment.NORMAL);
|
2014-01-20 10:20:13 +00:00
|
|
|
ess = new Essentials(server);
|
2013-06-08 15:33:30 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
ess.setupForTesting(server);
|
|
|
|
}
|
|
|
|
catch (InvalidDescriptionException ex)
|
|
|
|
{
|
|
|
|
fail("InvalidDescriptionException");
|
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
|
|
|
fail("IOException");
|
|
|
|
}
|
|
|
|
base1 = server.createPlayer("testPlayer1", ess);
|
|
|
|
server.addPlayer(base1);
|
|
|
|
ess.getUser(base1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void runCommand(String command, User user, String[] args) throws Exception
|
|
|
|
{
|
|
|
|
IEssentialsCommand cmd;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
cmd = (IEssentialsCommand)Essentials.class.getClassLoader().loadClass("com.earth2me.essentials.commands.Command" + command).newInstance();
|
|
|
|
cmd.setEssentials(ess);
|
|
|
|
cmd.run(server, user, command, null, args);
|
|
|
|
}
|
|
|
|
catch (NoChargeException ex)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void runConsoleCommand(String command, String[] args) throws Exception
|
|
|
|
{
|
|
|
|
IEssentialsCommand cmd;
|
|
|
|
|
|
|
|
CommandSender sender = server.getConsoleSender();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
cmd = (IEssentialsCommand)Essentials.class.getClassLoader().loadClass("com.earth2me.essentials.commands.Command" + command).newInstance();
|
|
|
|
cmd.setEssentials(ess);
|
2013-10-16 19:59:39 +00:00
|
|
|
cmd.run(server, new CommandSource(sender), command, null, args);
|
2013-06-08 15:33:30 +00:00
|
|
|
}
|
|
|
|
catch (NoChargeException ex)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testFlyToggle() throws Exception
|
|
|
|
{
|
|
|
|
User user = ess.getUser(base1);
|
|
|
|
|
2014-04-13 00:01:49 +00:00
|
|
|
assertFalse(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runCommand("fly", user, new String[]
|
|
|
|
{
|
|
|
|
"on"
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertTrue(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runCommand("fly", user, new String[]
|
|
|
|
{
|
|
|
|
"on"
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertTrue(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runCommand("fly", user, new String[]
|
|
|
|
{
|
|
|
|
"off"
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertFalse(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runCommand("fly", user, new String[]
|
|
|
|
{
|
|
|
|
"off"
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertFalse(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runCommand("fly", user, new String[]
|
|
|
|
{
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertTrue(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runCommand("fly", user, new String[]
|
|
|
|
{
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertFalse(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testFlyDisOnToggle() throws Exception
|
|
|
|
{
|
|
|
|
User user = ess.getUser(base1);
|
|
|
|
|
2014-04-13 00:01:49 +00:00
|
|
|
user.getBase().setAllowFlight(true);
|
|
|
|
user.getBase().setFlying(true);
|
|
|
|
assertTrue(user.getBase().isFlying());
|
2013-06-08 15:33:30 +00:00
|
|
|
runCommand("fly", user, new String[]
|
|
|
|
{
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertFalse(user.getBase().getAllowFlight());
|
|
|
|
assertFalse(user.getBase().isFlying());
|
2013-06-08 15:33:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testGodToggle() throws Exception
|
|
|
|
{
|
|
|
|
User user = ess.getUser(base1);
|
|
|
|
|
|
|
|
assertFalse(user.isGodModeEnabled());
|
|
|
|
|
|
|
|
runCommand("god", user, new String[]
|
|
|
|
{
|
|
|
|
"on"
|
|
|
|
});
|
|
|
|
assertTrue(user.isGodModeEnabled());
|
|
|
|
|
|
|
|
runCommand("god", user, new String[]
|
|
|
|
{
|
|
|
|
"on"
|
|
|
|
});
|
|
|
|
assertTrue(user.isGodModeEnabled());
|
|
|
|
|
|
|
|
runCommand("god", user, new String[]
|
|
|
|
{
|
|
|
|
"off"
|
|
|
|
});
|
|
|
|
assertFalse(user.isGodModeEnabled());
|
|
|
|
|
|
|
|
runCommand("god", user, new String[]
|
|
|
|
{
|
|
|
|
"off"
|
|
|
|
});
|
|
|
|
assertFalse(user.isGodModeEnabled());
|
|
|
|
|
|
|
|
runCommand("god", user, new String[]
|
|
|
|
{
|
|
|
|
});
|
|
|
|
assertTrue(user.isGodModeEnabled());
|
|
|
|
|
|
|
|
runCommand("god", user, new String[]
|
|
|
|
{
|
|
|
|
});
|
|
|
|
assertFalse(user.isGodModeEnabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testConsoleToggle() throws Exception
|
|
|
|
{
|
|
|
|
User user = ess.getUser(base1);
|
|
|
|
|
2014-04-13 00:01:49 +00:00
|
|
|
assertFalse(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runConsoleCommand("fly", new String[]
|
|
|
|
{
|
|
|
|
base1.getName(), "on"
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertTrue(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runConsoleCommand("fly", new String[]
|
|
|
|
{
|
|
|
|
base1.getName(), "on"
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertTrue(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runConsoleCommand("fly", new String[]
|
|
|
|
{
|
|
|
|
base1.getName(), "off"
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertFalse(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runConsoleCommand("fly", new String[]
|
|
|
|
{
|
|
|
|
base1.getName(), "off"
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertFalse(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runConsoleCommand("fly", new String[]
|
|
|
|
{
|
|
|
|
base1.getName()
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertTrue(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runConsoleCommand("fly", new String[]
|
|
|
|
{
|
|
|
|
base1.getName()
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertFalse(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testAliasesToggle() throws Exception
|
|
|
|
{
|
|
|
|
User user = ess.getUser(base1);
|
|
|
|
|
2014-04-13 00:01:49 +00:00
|
|
|
assertFalse(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runConsoleCommand("fly", new String[]
|
|
|
|
{
|
|
|
|
base1.getName(), "enable"
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertTrue(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runConsoleCommand("fly", new String[]
|
|
|
|
{
|
|
|
|
base1.getName(), "enable"
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertTrue(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runConsoleCommand("fly", new String[]
|
|
|
|
{
|
|
|
|
base1.getName(), "disable"
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertFalse(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runConsoleCommand("fly", new String[]
|
|
|
|
{
|
|
|
|
base1.getName(), "disable"
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertFalse(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runConsoleCommand("fly", new String[]
|
|
|
|
{
|
|
|
|
base1.getName(), "1"
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertTrue(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runConsoleCommand("fly", new String[]
|
|
|
|
{
|
|
|
|
base1.getName(), "1"
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertTrue(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runConsoleCommand("fly", new String[]
|
|
|
|
{
|
|
|
|
base1.getName(), "0"
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertFalse(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
runConsoleCommand("fly", new String[]
|
|
|
|
{
|
|
|
|
base1.getName(), "0"
|
|
|
|
});
|
2014-04-13 00:01:49 +00:00
|
|
|
assertFalse(user.getBase().getAllowFlight());
|
2013-06-08 15:33:30 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|