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