Telling me something changed but I don't know what. Will revert if it is

something breaking.
This commit is contained in:
graywolf336 2014-06-12 10:15:11 -05:00
parent 7ad5fedfd1
commit a442887b36
2 changed files with 239 additions and 239 deletions

View File

@ -1,144 +1,144 @@
package com.graywolf336.jail.beans; package com.graywolf336.jail.beans;
import java.util.HashSet; import java.util.HashSet;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
/** Represents a Cell inside of a {@link Jail}. /** Represents a Cell inside of a {@link Jail}.
* *
* @author graywolf336 * @author graywolf336
* @since 3.0.0 * @since 3.0.0
* @version 1.1.2 * @version 1.1.2
*/ */
public class Cell { public class Cell {
private String name; private String name;
private Prisoner p; private Prisoner p;
private HashSet<SimpleLocation> signs; private HashSet<SimpleLocation> signs;
private SimpleLocation teleport, chest; private SimpleLocation teleport, chest;
/** Creates a new Cell with the given name /** Creates a new Cell with the given name
* *
* @param name The name of the cell. * @param name The name of the cell.
*/ */
public Cell(String name) { public Cell(String name) {
this.name = name; this.name = name;
this.signs = new HashSet<SimpleLocation>(); this.signs = new HashSet<SimpleLocation>();
} }
/** Gets the name of the cell. */ /** Gets the name of the cell. */
public String getName() { public String getName() {
return this.name; return this.name;
} }
/** Updates the signs of the cell, with the player name and time and such. TODO */ /** Updates the signs of the cell, with the player name and time and such. TODO */
public void update() { public void update() {
//TODO: Update the signs //TODO: Update the signs
} }
/** Sets the prisoner in this cell. */ /** Sets the prisoner in this cell. */
public void setPrisoner(Prisoner prisoner) { public void setPrisoner(Prisoner prisoner) {
this.p = prisoner; this.p = prisoner;
} }
/** Gets the prisoner being held in this cell. */ /** Gets the prisoner being held in this cell. */
public Prisoner getPrisoner() { public Prisoner getPrisoner() {
return this.p; return this.p;
} }
/** Nullifies the prisoner data. */ /** Nullifies the prisoner data. */
public void removePrisoner() { public void removePrisoner() {
this.p = null; this.p = null;
} }
/** Returns true if there is currently a prisoner in this cell. */ /** Returns true if there is currently a prisoner in this cell. */
public boolean hasPrisoner() { public boolean hasPrisoner() {
return this.p != null; //Return true if prison is not null, as when it isn't null we have a prisoner in this cell return this.p != null; //Return true if prison is not null, as when it isn't null we have a prisoner in this cell
} }
/** Adds all the given signs to the cell. */ /** Adds all the given signs to the cell. */
public void addAllSigns(HashSet<SimpleLocation> signs) { public void addAllSigns(HashSet<SimpleLocation> signs) {
this.signs.addAll(signs); this.signs.addAll(signs);
} }
/** Adds a sign to the cell. */ /** Adds a sign to the cell. */
public void addSign(SimpleLocation sign) { public void addSign(SimpleLocation sign) {
this.signs.add(sign); this.signs.add(sign);
} }
/** Returns all the signs for this cell. */ /** Returns all the signs for this cell. */
public HashSet<SimpleLocation> getSigns() { public HashSet<SimpleLocation> getSigns() {
return this.signs; return this.signs;
} }
/** Returns the entire list of signs in a string. */ /** Returns the entire list of signs in a string. */
public String getSignString() { public String getSignString() {
String r = ""; String r = "";
for(SimpleLocation s : signs) { for(SimpleLocation s : signs) {
if(r.isEmpty()) { if(r.isEmpty()) {
r = s.toString(); r = s.toString();
}else { }else {
r += ";" + s.toString(); r += ";" + s.toString();
} }
} }
return r; return r;
} }
/** Sets the location of where the prisoner will be teleported at when jailed here. */ /** Sets the location of where the prisoner will be teleported at when jailed here. */
public void setTeleport(SimpleLocation location) { public void setTeleport(SimpleLocation location) {
this.teleport = location; this.teleport = location;
} }
/** Gets the teleport location where the prisoner will be teleported at when jailed here. */ /** Gets the teleport location where the prisoner will be teleported at when jailed here. */
public Location getTeleport() { public Location getTeleport() {
return this.teleport.getLocation(); return this.teleport.getLocation();
} }
/** Sets the location of the chest. */ /** Sets the location of the chest. */
public void setChestLocation(Location location) { public void setChestLocation(Location location) {
this.chest = new SimpleLocation(location); this.chest = new SimpleLocation(location);
} }
/** /**
* Gets the location of the chest, returns null if no chest is stored at this cell. * Gets the location of the chest, returns null if no chest is stored at this cell.
* *
* @return The location of the chest, null if none. * @return The location of the chest, null if none.
*/ */
public Location getChestLocation() { public Location getChestLocation() {
return this.chest.getLocation(); return this.chest.getLocation();
} }
/** /**
* Gets the chest for this cell, returns null if there is no chest or the location we have is not a chest. * Gets the chest for this cell, returns null if there is no chest or the location we have is not a chest.
* *
* @return The chest and its state. * @return The chest and its state.
*/ */
public Chest getChest() { public Chest getChest() {
if(this.chest == null) return null; if(this.chest == null) return null;
if((this.chest.getLocation().getBlock() == null) || (this.chest.getLocation().getBlock().getType() != Material.CHEST)) return null; if((this.chest.getLocation().getBlock() == null) || (this.chest.getLocation().getBlock().getType() != Material.CHEST)) return null;
return (Chest) this.chest.getLocation().getBlock().getState(); return (Chest) this.chest.getLocation().getBlock().getState();
} }
/** /**
* Checks if the chest location doesn't equal null and if it is a double chest. * Checks if the chest location doesn't equal null and if it is a double chest.
* *
* @return true if there is a chest, false if there isn't. * @return true if there is a chest, false if there isn't.
*/ */
public boolean hasChest() { public boolean hasChest() {
Chest c = getChest(); Chest c = getChest();
if(c != null) { if(c != null) {
if(c.getInventory().getSize() >= 40) if(c.getInventory().getSize() >= 40)
return true; return true;
else { else {
Bukkit.getLogger().severe("The cell " + this.name + " has chest that isn't a double chest, please fix."); Bukkit.getLogger().severe("The cell " + this.name + " has chest that isn't a double chest, please fix.");
return false; return false;
} }
}else }else
return false; return false;
} }
} }

View File

@ -1,95 +1,95 @@
package test.java.com.graywolf336.jail; package test.java.com.graywolf336.jail;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import java.util.Random; import java.util.Random;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import com.carrotsearch.junitbenchmarks.AbstractBenchmark; import com.carrotsearch.junitbenchmarks.AbstractBenchmark;
import com.carrotsearch.junitbenchmarks.BenchmarkOptions; import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
import com.graywolf336.jail.JailMain; import com.graywolf336.jail.JailMain;
import com.graywolf336.jail.beans.Jail; import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.beans.Prisoner; import com.graywolf336.jail.beans.Prisoner;
import test.java.com.graywolf336.jail.util.TestInstanceCreator; import test.java.com.graywolf336.jail.util.TestInstanceCreator;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({ JailMain.class, PluginDescriptionFile.class }) @PrepareForTest({ JailMain.class, PluginDescriptionFile.class })
public class BenchmarkTest extends AbstractBenchmark { public class BenchmarkTest extends AbstractBenchmark {
private static TestInstanceCreator creator; private static TestInstanceCreator creator;
private static JailMain main; private static JailMain main;
private static UUID use; private static UUID use;
private static Random r; private static Random r;
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
creator = new TestInstanceCreator(); creator = new TestInstanceCreator();
assertNotNull("The instance creator is null.", creator); assertNotNull("The instance creator is null.", creator);
assertTrue(creator.setup()); assertTrue(creator.setup());
main = creator.getMain(); main = creator.getMain();
assertNotNull("The JailMain class is null.", main); assertNotNull("The JailMain class is null.", main);
Jail j = new Jail(main, "testingJail"); Jail j = new Jail(main, "testingJail");
j.setWorld("world"); j.setWorld("world");
j.setMaxPoint(new int[] { 9, 63, -238 }); j.setMaxPoint(new int[] { 9, 63, -238 });
j.setMinPoint(new int[] { 23, 70, -242 }); j.setMinPoint(new int[] { 23, 70, -242 });
j.setTeleportIn(new Location(main.getServer().getWorld("world"), 11.469868464778077, 65.0, -239.27944647045672, Float.valueOf("38.499817"), Float.valueOf("2.0000453"))); j.setTeleportIn(new Location(main.getServer().getWorld("world"), 11.469868464778077, 65.0, -239.27944647045672, Float.valueOf("38.499817"), Float.valueOf("2.0000453")));
j.setTeleportFree(new Location(main.getServer().getWorld("world"), 27.947015843504765, 65.0, -218.8108042076112, Float.valueOf("90.54981"), Float.valueOf("12.500043"))); j.setTeleportFree(new Location(main.getServer().getWorld("world"), 27.947015843504765, 65.0, -218.8108042076112, Float.valueOf("90.54981"), Float.valueOf("12.500043")));
main.getJailManager().addJail(j, false); main.getJailManager().addJail(j, false);
assertEquals("There is no jail.", 1, main.getJailManager().getJails().size()); assertEquals("There is no jail.", 1, main.getJailManager().getJails().size());
for(int i = 0; i < 1000; i++) { for(int i = 0; i < 1000; i++) {
if(i == 555) if(i == 555)
use = UUID.randomUUID(); use = UUID.randomUUID();
main.getPrisonerManager().prepareJail(main.getJailManager().getJail("testingJail"), null, null, new Prisoner(i == 555 ? use.toString() : UUID.randomUUID().toString(), "mockPlayer" + i, true, 100000L, "testJailer", "Test jailing " + i)); main.getPrisonerManager().prepareJail(main.getJailManager().getJail("testingJail"), null, null, new Prisoner(i == 555 ? use.toString() : UUID.randomUUID().toString(), "mockPlayer" + i, true, 100000L, "testJailer", "Test jailing " + i));
} }
r = new Random(); r = new Random();
} }
@AfterClass @AfterClass
public static void tearDown() throws Exception { public static void tearDown() throws Exception {
creator.tearDown(); creator.tearDown();
main = null; main = null;
} }
@BenchmarkOptions(benchmarkRounds = 1000, warmupRounds = 0) @BenchmarkOptions(benchmarkRounds = 1000, warmupRounds = 0)
@Test @Test
public void testPrisonerSizeAndJailed() { public void testPrisonerSizeAndJailed() {
assertEquals("Prisoners not jailed?", 1000, main.getJailManager().getAllPrisoners().size()); assertEquals("Prisoners not jailed?", 1000, main.getJailManager().getAllPrisoners().size());
assertTrue("Prisoner 555 is not jailed", main.getJailManager().isPlayerJailed(use)); assertTrue("Prisoner 555 is not jailed", main.getJailManager().isPlayerJailed(use));
} }
@BenchmarkOptions(benchmarkRounds = 5000, warmupRounds = 0) @BenchmarkOptions(benchmarkRounds = 5000, warmupRounds = 0)
@Test @Test
public void testPlayerMoveEvent() { public void testPlayerMoveEvent() {
Player p = mock(Player.class); Player p = mock(Player.class);
when(p.getUniqueId()).thenReturn(use); when(p.getUniqueId()).thenReturn(use);
when(p.getName()).thenReturn("mockPlayer555"); when(p.getName()).thenReturn("mockPlayer555");
when(p.teleport(any(Location.class))).thenReturn(true); when(p.teleport(any(Location.class))).thenReturn(true);
Location from = new Location(main.getServer().getWorld("world"), 15, 64, -239); Location from = new Location(main.getServer().getWorld("world"), 15, 64, -239);
Location to = new Location(main.getServer().getWorld("world"), r.nextInt(), r.nextInt(), r.nextInt()); Location to = new Location(main.getServer().getWorld("world"), r.nextInt(), r.nextInt(), r.nextInt());
PlayerMoveEvent e = new PlayerMoveEvent(p, from, to); PlayerMoveEvent e = new PlayerMoveEvent(p, from, to);
main.getPlayerMoveListener().moveProtection(e); main.getPlayerMoveListener().moveProtection(e);
} }
} }