[BREAKING] Change up cell selection.

In the PrisonerManager you can now provide either AnyCell or NoCell and
it'll select a cell or not based upon the provided one. This is breaking
because it changes the required types in the methods and the new cells
don't have anything implemented and throw exceptions.
This commit is contained in:
graywolf336 2015-05-22 15:41:54 -05:00
parent 1f9035646d
commit 3eedc4904f
9 changed files with 249 additions and 53 deletions

View File

@ -0,0 +1,74 @@
package com.graywolf336.jail.beans;
import java.util.HashSet;
import org.bukkit.Location;
import org.bukkit.block.Chest;
import com.graywolf336.jail.interfaces.ICell;
public class AnyCell implements ICell {
public String getName() {
throw new UnsupportedOperationException();
}
public void setPrisoner(Prisoner prisoner) {
throw new UnsupportedOperationException();
}
public Prisoner getPrisoner() {
throw new UnsupportedOperationException();
}
public void removePrisoner() {
throw new UnsupportedOperationException();
}
public boolean hasPrisoner() {
throw new UnsupportedOperationException();
}
public void addAllSigns(HashSet<SimpleLocation> signs) {
throw new UnsupportedOperationException();
}
public void addSign(SimpleLocation sign) {
throw new UnsupportedOperationException();
}
public HashSet<SimpleLocation> getSigns() {
throw new UnsupportedOperationException();
}
public boolean hasSigns() {
throw new UnsupportedOperationException();
}
public String getSignString() {
throw new UnsupportedOperationException();
}
public void setTeleport(SimpleLocation location) {
throw new UnsupportedOperationException();
}
public Location getTeleport() {
throw new UnsupportedOperationException();
}
public void setChestLocation(SimpleLocation simpleLocation) {
throw new UnsupportedOperationException();
}
public Location getChestLocation() {
throw new UnsupportedOperationException();
}
public Chest getChest() {
throw new UnsupportedOperationException();
}
public boolean hasChest() {
throw new UnsupportedOperationException();
}
}

View File

@ -7,20 +7,22 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Chest;
import com.graywolf336.jail.interfaces.ICell;
/** Represents a Cell inside of a {@link Jail}.
*
*
* @author graywolf336
* @since 3.0.0
* @version 1.1.3
* @version 1.1.4
*/
public class Cell {
public class Cell implements ICell {
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) {
@ -28,52 +30,42 @@ public class Cell {
this.signs = new HashSet<SimpleLocation>();
}
/** Gets the name of the cell. */
public String getName() {
return this.name;
}
/** 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;
}
/** Checks if there are any signs for this cell. */
public boolean hasSigns() {
return !this.signs.isEmpty();
return !this.signs.isEmpty();
}
/** Returns the entire list of signs in a string. */
public String getSignString() {
String r = "";
@ -88,47 +80,29 @@ public class Cell {
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(SimpleLocation simpleLocation) {
this.chest = simpleLocation;
}
/**
* 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 == null ? null : 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;
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) {

View File

@ -0,0 +1,74 @@
package com.graywolf336.jail.beans;
import java.util.HashSet;
import org.bukkit.Location;
import org.bukkit.block.Chest;
import com.graywolf336.jail.interfaces.ICell;
public class NoCell implements ICell {
public String getName() {
throw new UnsupportedOperationException();
}
public void setPrisoner(Prisoner prisoner) {
throw new UnsupportedOperationException();
}
public Prisoner getPrisoner() {
throw new UnsupportedOperationException();
}
public void removePrisoner() {
throw new UnsupportedOperationException();
}
public boolean hasPrisoner() {
throw new UnsupportedOperationException();
}
public void addAllSigns(HashSet<SimpleLocation> signs) {
throw new UnsupportedOperationException();
}
public void addSign(SimpleLocation sign) {
throw new UnsupportedOperationException();
}
public HashSet<SimpleLocation> getSigns() {
throw new UnsupportedOperationException();
}
public boolean hasSigns() {
throw new UnsupportedOperationException();
}
public String getSignString() {
throw new UnsupportedOperationException();
}
public void setTeleport(SimpleLocation location) {
throw new UnsupportedOperationException();
}
public Location getTeleport() {
throw new UnsupportedOperationException();
}
public void setChestLocation(SimpleLocation simpleLocation) {
throw new UnsupportedOperationException();
}
public Location getChestLocation() {
throw new UnsupportedOperationException();
}
public Chest getChest() {
throw new UnsupportedOperationException();
}
public boolean hasChest() {
throw new UnsupportedOperationException();
}
}

View File

@ -19,6 +19,7 @@ import com.graywolf336.jail.command.commands.jewels.Jailing;
import com.graywolf336.jail.enums.Lang;
import com.graywolf336.jail.enums.Settings;
import com.graywolf336.jail.events.PrePrisonerJailedEvent;
import com.graywolf336.jail.interfaces.ICell;
import com.lexicalscope.jewel.cli.ArgumentValidationException;
import com.lexicalscope.jewel.cli.CliFactory;
@ -126,7 +127,7 @@ public class JailCommand implements Command {
return true;
}
Cell c = null;
ICell c = null;
//Check if the cell is defined
if(params.isCell()) {
//Check if it is a valid cell

View File

@ -9,6 +9,7 @@ import com.graywolf336.jail.beans.Cell;
import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.beans.Prisoner;
import com.graywolf336.jail.beans.Stick;
import com.graywolf336.jail.interfaces.ICell;
/**
* Event thrown before we a player is jailed by someone hitting them with a {@link Stick jail stick}.
@ -25,7 +26,7 @@ public class PrePrisonerJailedByJailStickEvent extends Event implements Cancella
private static final HandlerList handlers = new HandlerList();
private boolean cancelled = false;
private Jail jail;
private Cell cell;
private ICell cell;
private Prisoner prisoner;
private Player player;
private String jailer, cancelMsg;
@ -41,7 +42,7 @@ public class PrePrisonerJailedByJailStickEvent extends Event implements Cancella
* @param jailer The name of what jailed this prisoner.
* @param stick The {@link Stick jail stick} used.
*/
public PrePrisonerJailedByJailStickEvent(Jail jail, Cell cell, Prisoner prisoner, Player player, String jailer, Stick stick) {
public PrePrisonerJailedByJailStickEvent(Jail jail, ICell cell, Prisoner prisoner, Player player, String jailer, Stick stick) {
this.jail = jail;
this.cell = cell;
this.prisoner = prisoner;
@ -57,7 +58,7 @@ public class PrePrisonerJailedByJailStickEvent extends Event implements Cancella
}
/** Gets the cell we're going to be sending the prisoner to. */
public Cell getCell() {
public ICell getCell() {
return this.cell;
}

View File

@ -8,6 +8,7 @@ import org.bukkit.event.HandlerList;
import com.graywolf336.jail.beans.Cell;
import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.beans.Prisoner;
import com.graywolf336.jail.interfaces.ICell;
/**
* Event thrown before we are jailing a player, both offline and online players.
@ -25,7 +26,7 @@ public class PrePrisonerJailedEvent extends Event implements Cancellable {
private boolean cancelled = false;
private boolean online;
private Jail jail;
private Cell cell;
private ICell cell;
private Prisoner prisoner;
private Player player;
private String jailer, cancelMsg;
@ -34,15 +35,15 @@ public class PrePrisonerJailedEvent extends Event implements Cancellable {
* Creates a new {@link PrePrisonerJailedEvent prisoner jailed event} for the given player before they get sent to jail.
*
* @param jail The jail the prisoner will be jailed at.
* @param cell The cell we're going to be sending the prisoner to, can be null.
* @param c The cell we're going to be sending the prisoner to, can be null.
* @param prisoner The prisoner data.
* @param player The player being jailed.
* @param online Whether the player is online or not.
* @param jailer The name of what jailed this prisoner.
*/
public PrePrisonerJailedEvent(Jail jail, Cell cell, Prisoner prisoner, Player player, boolean online, String jailer) {
public PrePrisonerJailedEvent(Jail jail, ICell c, Prisoner prisoner, Player player, boolean online, String jailer) {
this.jail = jail;
this.cell = cell;
this.cell = c;
this.prisoner = prisoner;
this.player = player;
this.online = online;
@ -56,7 +57,7 @@ public class PrePrisonerJailedEvent extends Event implements Cancellable {
}
/** Gets the cell we're going to be sending the prisoner to. */
public Cell getCell() {
public ICell getCell() {
return this.cell;
}

View File

@ -4,9 +4,9 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.graywolf336.jail.beans.Cell;
import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.beans.Prisoner;
import com.graywolf336.jail.interfaces.ICell;
/**
* Event thrown after a prisoner is released.
@ -24,7 +24,7 @@ import com.graywolf336.jail.beans.Prisoner;
public class PrePrisonerReleasedEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private Jail jail;
private Cell cell;
private ICell cell;
private Prisoner prisoner;
private Player player;
@ -36,7 +36,7 @@ public class PrePrisonerReleasedEvent extends Event {
* @param prisoner The prisoner data.
* @param player The player being jailed.
*/
public PrePrisonerReleasedEvent(Jail jail, Cell cell, Prisoner prisoner, Player player) {
public PrePrisonerReleasedEvent(Jail jail, ICell cell, Prisoner prisoner, Player player) {
this.jail = jail;
this.cell = cell;
this.prisoner = prisoner;
@ -49,7 +49,7 @@ public class PrePrisonerReleasedEvent extends Event {
}
/** Gets the cell where the prisoner was jailed in, null if they weren't in one. */
public Cell getCell() {
public ICell getCell() {
return this.cell;
}

View File

@ -0,0 +1,71 @@
package com.graywolf336.jail.interfaces;
import java.util.HashSet;
import org.bukkit.Location;
import org.bukkit.block.Chest;
import com.graywolf336.jail.beans.Prisoner;
import com.graywolf336.jail.beans.SimpleLocation;
public interface ICell {
/** Gets the name of the cell. */
public String getName();
/** Sets the prisoner in this cell. */
public void setPrisoner(Prisoner prisoner);
/** Gets the prisoner being held in this cell. */
public Prisoner getPrisoner();
/** Nullifies the prisoner data. */
public void removePrisoner();
/** Returns true if there is currently a prisoner in this cell. */
public boolean hasPrisoner();
/** Adds all the given signs to the cell. */
public void addAllSigns(HashSet<SimpleLocation> signs);
/** Adds a sign to the cell. */
public void addSign(SimpleLocation sign);
/** Returns all the signs for this cell. */
public HashSet<SimpleLocation> getSigns();
/** Checks if there are any signs for this cell. */
public boolean hasSigns();
/** Returns the entire list of signs in a string. */
public String getSignString();
/** Sets the location of where the prisoner will be teleported at when jailed here. */
public void setTeleport(SimpleLocation location);
/** Gets the teleport location where the prisoner will be teleported at when jailed here. */
public Location getTeleport();
/** Sets the location of the chest. */
public void setChestLocation(SimpleLocation simpleLocation);
/**
* 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();
/**
* 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();
/**
* 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();
}

View File

@ -23,6 +23,7 @@ import org.bukkit.event.player.PlayerRespawnEvent;
import com.graywolf336.jail.JailMain;
import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.Util;
import com.graywolf336.jail.beans.AnyCell;
import com.graywolf336.jail.beans.Cell;
import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.beans.Prisoner;
@ -31,6 +32,7 @@ import com.graywolf336.jail.enums.Lang;
import com.graywolf336.jail.enums.Settings;
import com.graywolf336.jail.events.PrePrisonerJailedByJailStickEvent;
import com.graywolf336.jail.events.PrisonerDeathEvent;
import com.graywolf336.jail.interfaces.ICell;
public class PlayerListener implements Listener {
private JailMain pl;
@ -239,10 +241,8 @@ public class PlayerListener implements Listener {
pl.getConfig().getBoolean(Settings.AUTOMATICMUTE.getPath()),
s.getTime(), attacker.getName(), s.getReason());
Jail j = pl.getJailManager().getJail(s.getJail());
Cell c = j.getFirstEmptyCell();
PrePrisonerJailedByJailStickEvent jEvent = new PrePrisonerJailedByJailStickEvent(
j, c, p, player, attacker.getName(), s);
pl.getJailManager().getJail(s.getJail()), new AnyCell(), p, player, attacker.getName(), s);
pl.getServer().getPluginManager().callEvent(jEvent);
@ -253,8 +253,8 @@ public class PlayerListener implements Listener {
attacker.sendMessage(jEvent.getCancelledMessage());
}else {
//recall data from the event
j = jEvent.getJail();
c = jEvent.getCell();
Jail j = jEvent.getJail();
ICell c = jEvent.getCell();
p = jEvent.getPrisoner();
player = jEvent.getPlayer();