Add an API class and also add some testing for it.
This commit is contained in:
parent
59c583e8b3
commit
709a06f330
@ -6,6 +6,20 @@ import java.util.UUID;
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
* Manages the handcuffing of players.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* Provides easy to use methods for adding,
|
||||
* removing, and checking if someone has
|
||||
* handcuffs.
|
||||
*
|
||||
* <ul>
|
||||
* <li>{@link #addHandCuffs(UUID, Location) addHandCuffs}</li>
|
||||
* <li>{@link #removeHandCuffs(UUID) removeHandCuffs}</li>
|
||||
* <li>{@link #isHandCuffed(UUID) isHandCuffed}</li>
|
||||
* <li>{@link #getLocation(UUID) getLocation}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 2.6.3
|
||||
|
@ -113,6 +113,7 @@ public class JailMain extends JavaPlugin {
|
||||
reloadJailPayManager();
|
||||
reloadUpdateCheck();
|
||||
|
||||
new JailsAPI(this);
|
||||
getLogger().info("Completed enablement.");
|
||||
}
|
||||
|
||||
@ -300,6 +301,12 @@ public class JailMain extends JavaPlugin {
|
||||
if(inDebug()) getLogger().info("[Debug]: " + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is only for testing, there is no need to use this.
|
||||
*
|
||||
* @return the move protection listener
|
||||
* @deprecated
|
||||
*/
|
||||
public MoveProtectionListener getPlayerMoveListener() {
|
||||
return this.mpl;
|
||||
}
|
||||
|
51
src/main/java/com/graywolf336/jail/JailsAPI.java
Normal file
51
src/main/java/com/graywolf336/jail/JailsAPI.java
Normal file
@ -0,0 +1,51 @@
|
||||
package com.graywolf336.jail;
|
||||
|
||||
/**
|
||||
* The static api interface for Jail plugin.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* If you're looking for non-static methods, please see the
|
||||
* {@link JailMain} interface.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @version 3.0.0
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class JailsAPI {
|
||||
private static JailMain pl;
|
||||
|
||||
public JailsAPI(JailMain plugin) {
|
||||
pl = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* The instance of the {@link JailManager} which contains all the jails and in return prisoners.
|
||||
*
|
||||
* @return instance of the {@link JailManager}
|
||||
* @see JailManager
|
||||
*/
|
||||
public static JailManager getJailManager() {
|
||||
return pl.getJailManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* The instance of the {@link PrisonerManager} which handles all the jailing of players.
|
||||
*
|
||||
* @return instance of the {@link PrisonerManager}
|
||||
* @see PrisonerManager
|
||||
*/
|
||||
public static PrisonerManager getPrisonerManager() {
|
||||
return pl.getPrisonerManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* The instance of the {@link HandCuffManager} which handles all the handcuffing of players.
|
||||
*
|
||||
* @return instance of the {@link HandCuffManager}
|
||||
* @see HandCuffManager
|
||||
*/
|
||||
public static HandCuffManager getHandCuffManager() {
|
||||
return pl.getHandCuffManager();
|
||||
}
|
||||
}
|
@ -22,7 +22,19 @@ import com.graywolf336.jail.events.PrisonerReleasedEvent;
|
||||
import com.graywolf336.jail.events.PrisonerTransferredEvent;
|
||||
|
||||
/**
|
||||
* Provides methods, non-statically, that do the preparing of jails and handle all the good stuff like that.
|
||||
* Provides methods, non-statically, that do the preparing of jails, jailing, etc.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* <ul>
|
||||
* <li>{@link #prepareJail(Jail, Cell, Player, Prisoner) preparejail}</li>
|
||||
* <li>{@link #jailPrisoner(Jail, Cell, Player, Prisoner) jailPrisoner}</li>
|
||||
* <li>{@link #schedulePrisonerRelease(Prisoner) schedulePrisonerRelease}</li>
|
||||
* <li>{@link #unJail(Jail, Cell, Player, Prisoner, CommandSender) unJail}</li>
|
||||
* <li>{@link #forceRelease(Prisoner, CommandSender) forceRelease}</li>
|
||||
* <li>{@link #forceUnJail(Jail, Cell, Player, Prisoner, CommandSender) forceUnJail}</li>
|
||||
* <li>{@link #transferPrisoner(Jail, Cell, Jail, Cell, Prisoner) transferPrisoner}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 2.x.x
|
||||
@ -112,6 +124,11 @@ public class PrisonerManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Jails the given player, <strong>only</strong> use when that player has offline data pending.
|
||||
*
|
||||
* @param uuid of the player to jail.
|
||||
*/
|
||||
public void jailPlayer(UUID uuid) {
|
||||
Jail j = pl.getJailManager().getJailPlayerIsIn(uuid);
|
||||
jailPrisoner(j, j.getCellPrisonerIsIn(uuid), pl.getServer().getPlayer(uuid), j.getPrisoner(uuid));
|
||||
@ -313,9 +330,10 @@ public class PrisonerManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a prisoner to be released.
|
||||
* Schedules a prisoner to be released, this method is to be used <strong>async</strong>.
|
||||
*
|
||||
* @param prisoner to be released.
|
||||
* @see {@link #unJail(Jail, Cell, Player, Prisoner, CommandSender)} - If you're wanting to unjail a prisoner.
|
||||
*/
|
||||
public void schedulePrisonerRelease(Prisoner prisoner) {
|
||||
releases.add(prisoner);
|
||||
@ -481,13 +499,55 @@ public class PrisonerManager {
|
||||
if(sender != null) sender.sendMessage(pl.getJailIO().getLanguageString(LangString.UNJAILSUCCESS, player.getName()));
|
||||
}
|
||||
|
||||
/** Forcefully releases a {@link Prisoner prisoner} from {@link Jail}. */
|
||||
/**
|
||||
* Forcefully unjails a {@link Prisoner prisoner} from {@link Jail}.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* This method forcefully removes all the references to this prisoner,
|
||||
* meaning if they're offline the following won't happened:
|
||||
* <ul>
|
||||
* <li>Inventory restored</li>
|
||||
* <li>Teleported anywhere</li>
|
||||
* <li>No messages sent, they'll be clueless.</li>
|
||||
* </ul>
|
||||
*
|
||||
* But if they're online, it goes through the regular unjailing methods.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* @param prisoner to release
|
||||
* @param sender who is releasing the prisoner, <em>can be null</em>
|
||||
*/
|
||||
public void forceRelease(Prisoner prisoner, CommandSender sender) {
|
||||
Jail j = pl.getJailManager().getJailPrisonerIsIn(prisoner);
|
||||
forceUnJail(j, j.getCellPrisonerIsIn(prisoner.getUUID()), pl.getServer().getPlayer(prisoner.getUUID()), prisoner, sender);
|
||||
}
|
||||
|
||||
/** Forcefully unjails a {@link Prisoner prisoner} from {@link Jail}. */
|
||||
/**
|
||||
* Forcefully unjails a {@link Prisoner prisoner} from {@link Jail}.
|
||||
*
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* This method forcefully removes all the references to this prisoner,
|
||||
* meaning if they're offline the following won't happened:
|
||||
* <ul>
|
||||
* <li>Inventory restored</li>
|
||||
* <li>Teleported anywhere</li>
|
||||
* <li>No messages sent, they'll be clueless.</li>
|
||||
* </ul>
|
||||
*
|
||||
* But if they're online, it goes through the regular unjailing methods.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* @param jail the prisoner is in
|
||||
* @param cell the prisoner is in, <em>can be null</em>
|
||||
* @param player of the prisoner, if this is null then the player won't be teleported when they come back on.
|
||||
* @param prisoner to release and remove data
|
||||
* @param sender who is releasing the prisoner, <em>can be null</em>
|
||||
*/
|
||||
public void forceUnJail(Jail jail, Cell cell, Player player, Prisoner prisoner, CommandSender sender) {
|
||||
if(player == null) {
|
||||
//Player is offline, we just forcefully remove them from the database
|
||||
|
@ -81,6 +81,7 @@ public class BenchmarkTest extends AbstractBenchmark {
|
||||
assertTrue("Prisoner 555 is not jailed", main.getJailManager().isPlayerJailed(use));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@BenchmarkOptions(benchmarkRounds = 5000, warmupRounds = 0)
|
||||
@Test
|
||||
public void testPlayerMoveEvent() {
|
||||
|
@ -0,0 +1,69 @@
|
||||
package test.java.com.graywolf336.jail;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import test.java.com.graywolf336.jail.util.TestInstanceCreator;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.JailsAPI;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ JailMain.class, PluginDescriptionFile.class })
|
||||
public class TestJailAPI {
|
||||
private static TestInstanceCreator creator;
|
||||
private static JailMain main;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
creator = new TestInstanceCreator();
|
||||
assertNotNull("The instance creator is null.", creator);
|
||||
assertTrue(creator.setup());
|
||||
main = creator.getMain();
|
||||
assertNotNull("The JailMain class is null.", main);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() throws Exception {
|
||||
creator.tearDown();
|
||||
main = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManagersAreThere() {
|
||||
assertNotNull(main.getHandCuffManager());
|
||||
assertNotNull(main.getJailManager());
|
||||
assertNotNull(main.getPrisonerManager());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandCuffManagerAPI() {
|
||||
UUID id = UUID.randomUUID();
|
||||
Location loc = new Location(main.getServer().getWorld("world"), 11.469868464778077, 65.0, -239.27944647045672, Float.valueOf("38.499817"), Float.valueOf("2.0000453"));
|
||||
assertThat("The HandCuff Managers are different.", JailsAPI.getHandCuffManager(), is(main.getHandCuffManager()));
|
||||
assertFalse("The test id of someone is already handcuffed.", JailsAPI.getHandCuffManager().isHandCuffed(id));
|
||||
|
||||
JailsAPI.getHandCuffManager().addHandCuffs(id, loc);
|
||||
assertTrue(JailsAPI.getHandCuffManager().isHandCuffed(id));
|
||||
assertThat(JailsAPI.getHandCuffManager().getLocation(id), is(loc));
|
||||
|
||||
JailsAPI.getHandCuffManager().removeHandCuffs(id);
|
||||
assertFalse(JailsAPI.getHandCuffManager().isHandCuffed(id));
|
||||
assertNull(JailsAPI.getHandCuffManager().getLocation(id));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user