Don't edit the jail signs async, as that is bad and causes #36.

This should fix the Asynchronous entity world add exception being thrown
This commit is contained in:
graywolf336 2015-01-13 01:13:22 -06:00
parent e84452bfd8
commit 84b6505ae3

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import com.graywolf336.jail.JailMain;
@ -19,39 +20,45 @@ import com.graywolf336.jail.events.PrisonerTransferredEvent;
public class CellSignListener implements Listener {
private String lineOne, lineTwo, lineThree, lineFour;
private JailMain pl;
public CellSignListener(JailMain plugin) {
List<String> lines = plugin.getConfig().getStringList(Settings.CELLSIGNLINES.getPath());
pl = plugin;
List<String> lines = pl.getConfig().getStringList(Settings.CELLSIGNLINES.getPath());
lineOne = lines.get(0);
lineTwo = lines.get(1);
lineThree = lines.get(2);
lineFour = lines.get(3);
}
@EventHandler
public void changeTheCellSigns(PrisonerTimeChangeEvent event) {
if (event.hasCell() && event.getCell().hasSigns()) {
HashSet<SimpleLocation> signs = event.getCell().getSigns();
String s1 = Util.replaceAllVariables(event.getPrisoner(), lineOne);
String s2 = Util.replaceAllVariables(event.getPrisoner(), lineTwo);
String s3 = Util.replaceAllVariables(event.getPrisoner(), lineThree);
String s4 = Util.replaceAllVariables(event.getPrisoner(), lineFour);
@EventHandler(ignoreCancelled=true, priority = EventPriority.MONITOR)
public void changeTheCellSigns(final PrisonerTimeChangeEvent event) {
pl.getServer().getScheduler().scheduleSyncDelayedTask(pl, new Runnable() {
public void run() {
if (event.hasCell() && event.getCell().hasSigns()) {
HashSet<SimpleLocation> signs = event.getCell().getSigns();
String s1 = Util.replaceAllVariables(event.getPrisoner(), lineOne);
String s2 = Util.replaceAllVariables(event.getPrisoner(), lineTwo);
String s3 = Util.replaceAllVariables(event.getPrisoner(), lineThree);
String s4 = Util.replaceAllVariables(event.getPrisoner(), lineFour);
for (SimpleLocation s : signs) {
if (s.getLocation().getBlock().getState() instanceof Sign) {
Sign sign = (Sign) s.getLocation().getBlock().getState();
sign.setLine(0, s1);
sign.setLine(1, s2);
sign.setLine(2, s3);
sign.setLine(3, s4);
sign.update();
} else {
// Remove the sign from the cell since it isn't
// a valid sign
event.getCell().getSigns().remove(s);
for (SimpleLocation s : signs) {
if (s.getLocation().getBlock().getState() instanceof Sign) {
Sign sign = (Sign) s.getLocation().getBlock().getState();
sign.setLine(0, s1);
sign.setLine(1, s2);
sign.setLine(2, s3);
sign.setLine(3, s4);
sign.update();
} else {
// Remove the sign from the cell since it isn't
// a valid sign
event.getCell().getSigns().remove(s);
}
}
}
}
}
});
}
@EventHandler