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

View File

@ -1,95 +1,95 @@
package test.java.com.graywolf336.jail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Matchers.any;
import java.util.Random;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
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 com.carrotsearch.junitbenchmarks.AbstractBenchmark;
import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
import com.graywolf336.jail.JailMain;
import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.beans.Prisoner;
import test.java.com.graywolf336.jail.util.TestInstanceCreator;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ JailMain.class, PluginDescriptionFile.class })
public class BenchmarkTest extends AbstractBenchmark {
private static TestInstanceCreator creator;
private static JailMain main;
private static UUID use;
private static Random r;
@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);
Jail j = new Jail(main, "testingJail");
j.setWorld("world");
j.setMaxPoint(new int[] { 9, 63, -238 });
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.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);
assertEquals("There is no jail.", 1, main.getJailManager().getJails().size());
for(int i = 0; i < 1000; i++) {
if(i == 555)
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));
}
r = new Random();
}
@AfterClass
public static void tearDown() throws Exception {
creator.tearDown();
main = null;
}
@BenchmarkOptions(benchmarkRounds = 1000, warmupRounds = 0)
@Test
public void testPrisonerSizeAndJailed() {
assertEquals("Prisoners not jailed?", 1000, main.getJailManager().getAllPrisoners().size());
assertTrue("Prisoner 555 is not jailed", main.getJailManager().isPlayerJailed(use));
}
@BenchmarkOptions(benchmarkRounds = 5000, warmupRounds = 0)
@Test
public void testPlayerMoveEvent() {
Player p = mock(Player.class);
when(p.getUniqueId()).thenReturn(use);
when(p.getName()).thenReturn("mockPlayer555");
when(p.teleport(any(Location.class))).thenReturn(true);
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());
PlayerMoveEvent e = new PlayerMoveEvent(p, from, to);
main.getPlayerMoveListener().moveProtection(e);
}
}
package test.java.com.graywolf336.jail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Matchers.any;
import java.util.Random;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
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 com.carrotsearch.junitbenchmarks.AbstractBenchmark;
import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
import com.graywolf336.jail.JailMain;
import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.beans.Prisoner;
import test.java.com.graywolf336.jail.util.TestInstanceCreator;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ JailMain.class, PluginDescriptionFile.class })
public class BenchmarkTest extends AbstractBenchmark {
private static TestInstanceCreator creator;
private static JailMain main;
private static UUID use;
private static Random r;
@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);
Jail j = new Jail(main, "testingJail");
j.setWorld("world");
j.setMaxPoint(new int[] { 9, 63, -238 });
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.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);
assertEquals("There is no jail.", 1, main.getJailManager().getJails().size());
for(int i = 0; i < 1000; i++) {
if(i == 555)
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));
}
r = new Random();
}
@AfterClass
public static void tearDown() throws Exception {
creator.tearDown();
main = null;
}
@BenchmarkOptions(benchmarkRounds = 1000, warmupRounds = 0)
@Test
public void testPrisonerSizeAndJailed() {
assertEquals("Prisoners not jailed?", 1000, main.getJailManager().getAllPrisoners().size());
assertTrue("Prisoner 555 is not jailed", main.getJailManager().isPlayerJailed(use));
}
@BenchmarkOptions(benchmarkRounds = 5000, warmupRounds = 0)
@Test
public void testPlayerMoveEvent() {
Player p = mock(Player.class);
when(p.getUniqueId()).thenReturn(use);
when(p.getName()).thenReturn("mockPlayer555");
when(p.teleport(any(Location.class))).thenReturn(true);
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());
PlayerMoveEvent e = new PlayerMoveEvent(p, from, to);
main.getPlayerMoveListener().moveProtection(e);
}
}