New command for signs, closes #79

A new command for signs. Refreshing them, cleaning them, and verifying
them. Changed up some internal apis, if you were using them sorry for
breaking it. Also, really update the signs when we jail someone who is
offline via a new event.
This commit is contained in:
graywolf336
2015-06-05 18:01:31 -05:00
parent bd1b3ec04d
commit 384fa3601b
12 changed files with 487 additions and 201 deletions

View File

@ -1,13 +1,27 @@
package com.graywolf336.jail.beans;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.block.Chest;
import com.graywolf336.jail.interfaces.ICell;
/**
* Pass this an instance of this class into the jailing of a player and they go to any open cell.
*
* @author graywolf336
* @since 3.0.0
* @version 1.0.0
*
*/
public class AnyCell implements ICell {
public int getDatabaseID() {
throw new UnsupportedOperationException();
}
public String getName() {
throw new UnsupportedOperationException();
}
@ -48,6 +62,18 @@ public class AnyCell implements ICell {
throw new UnsupportedOperationException();
}
public List<String> getInvalidSigns() {
throw new UnsupportedOperationException();
}
public List<String> cleanSigns() {
throw new UnsupportedOperationException();
}
public HashMap<String, List<String>> updateSigns() {
throw new UnsupportedOperationException();
}
public void setTeleport(SimpleLocation location) {
throw new UnsupportedOperationException();
}

View File

@ -1,21 +1,29 @@
package com.graywolf336.jail.beans;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.block.Sign;
import com.graywolf336.jail.Util;
import com.graywolf336.jail.enums.Lang;
import com.graywolf336.jail.interfaces.ICell;
/** Represents a Cell inside of a {@link Jail}.
*
* @author graywolf336
* @since 3.0.0
* @version 1.1.4
* @version 1.2.0
*/
public class Cell implements ICell {
private int databaseid;
private String name;
private Prisoner p;
private HashSet<SimpleLocation> signs;
@ -27,10 +35,28 @@ public class Cell implements ICell {
* @param name The name of the cell.
*/
public Cell(String name) {
this.databaseid = -1;
this.name = name;
this.signs = new HashSet<SimpleLocation>();
this.changed = false;
}
/**
* Creates a new Cell with the id in the database and the name.
*
* @param id The id of the cell in the database.
* @param name The name of the cell.
*/
public Cell(int id, String name) {
this.databaseid = id;
this.name = name;
this.signs = new HashSet<SimpleLocation>();
this.changed = false;
}
public int getDatabaseID() {
return this.databaseid;
}
public String getName() {
return this.name;
@ -85,6 +111,75 @@ public class Cell implements ICell {
return r;
}
public List<String> getInvalidSigns() {
List<String> invalid = new ArrayList<String>();
for(SimpleLocation s : new HashSet<SimpleLocation>(signs))
if (s.getLocation().getBlock().getState() instanceof Sign)
continue;
else
invalid.add(s.toString());
return invalid;
}
public List<String> cleanSigns() {
List<String> cleaned = new ArrayList<String>();
for(SimpleLocation s : new HashSet<SimpleLocation>(signs)) {
if (s.getLocation().getBlock().getState() instanceof Sign) {
continue;
}else {
changed = true;
signs.remove(s);
cleaned.add(s.toString());
}
}
return cleaned;
}
public HashMap<String, List<String>> updateSigns() {
List<String> removed = new ArrayList<String>();
List<String> updated = new ArrayList<String>();
for(SimpleLocation s : new HashSet<SimpleLocation>(signs)) {
BlockState bs = s.getLocation().getBlock().getState();
if (bs instanceof Sign) {
Sign sign = (Sign) bs;
if(hasPrisoner()) {
String[] lines = Util.replaceAllVariables(p, Util.getSignLines());
sign.setLine(0, lines[0]);
sign.setLine(1, lines[1]);
sign.setLine(2, lines[2]);
sign.setLine(3, lines[3]);
sign.update(true, false);
}else {
sign.setLine(0, "");
sign.setLine(1, Lang.CELLEMPTYSIGN.get());
sign.setLine(2, "");
sign.setLine(3, "");
sign.update(true, false);
}
updated.add(s.toString());
}else {
changed = true;
signs.remove(s);
removed.add(s.toString());
}
}
HashMap<String, List<String>> results = new HashMap<String, List<String>>();
results.put("removed", removed);
results.put("updated", updated);
return results;
}
public void setTeleport(SimpleLocation location) {
this.teleport = location;
@ -123,11 +218,11 @@ public class Cell implements ICell {
}else
return false;
}
public boolean setChanged(boolean changed) {
return this.changed = changed;
}
public boolean hasChanged() {
return this.changed;
}

View File

@ -1,13 +1,27 @@
package com.graywolf336.jail.beans;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.block.Chest;
import com.graywolf336.jail.interfaces.ICell;
/**
* Pass this an instance of this class into the jailing of a player and they won't go into a cell.
*
* @author graywolf336
* @since 3.0.0
* @version 1.0.0
*
*/
public class NoCell implements ICell {
public int getDatabaseID() {
throw new UnsupportedOperationException();
}
public String getName() {
throw new UnsupportedOperationException();
}
@ -48,6 +62,18 @@ public class NoCell implements ICell {
throw new UnsupportedOperationException();
}
public List<String> getInvalidSigns() {
throw new UnsupportedOperationException();
}
public List<String> cleanSigns() {
throw new UnsupportedOperationException();
}
public HashMap<String, List<String>> updateSigns() {
throw new UnsupportedOperationException();
}
public void setTeleport(SimpleLocation location) {
throw new UnsupportedOperationException();
}