Skip to content

Instantly share code, notes, and snippets.

@Jozeth
Last active December 20, 2015 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jozeth/6114277 to your computer and use it in GitHub Desktop.
Save Jozeth/6114277 to your computer and use it in GitHub Desktop.
This code will stop signs from being destroyed if they contain a specific variable. Also this stops the surrounding blocks from being destroyed.
@EventHandler
public void blockSignBreak(BlockBreakEvent event) {
if(event.getBlock().getState() instanceof Sign) {
Sign sign = (Sign) event.getBlock().getState();
// Stop the destruction of signs all together, if they contain stuff on each line
if(sign.getLine(0).contains("VARIABLE")) {
// if(sign.getLine(LINE).equalsIgnoreCase(anotherString)) {
/*
* Sign lines:
* 0 = First line
* 1 = Second line
* 2 = Third line
* 3 = Forth line
*/
event.setCancelled(true);
}
}
// Stop the blocks the signs are touching from being destroyed
// We use 68 as the ID because the sign is a 'Wall Sign'
if(event.getBlock().getRelative(BlockFace.NORTH, 1).getTypeId() == 68) {
Sign sign = (Sign) event.getBlock().getRelative(BlockFace.NORTH, 1).getState();
if(sign.getLine(0).contains("VARIABLE")) {
event.setCancelled(true);
}
}
if(event.getBlock().getRelative(BlockFace.EAST, 1).getTypeId() == 68) {
Sign sign = (Sign) event.getBlock().getRelative(BlockFace.EAST, 1).getState();
if(sign.getLine(0).contains("VARIABLE")) {
event.setCancelled(true);
}
}
if(event.getBlock().getRelative(BlockFace.SOUTH, 1).getTypeId() == 68) {
Sign sign = (Sign) event.getBlock().getRelative(BlockFace.SOUTH, 1).getState();
if(sign.getLine(0).contains("VARIABLE")) {
event.setCancelled(true);
}
}
if(event.getBlock().getRelative(BlockFace.WEST, 1).getTypeId() == 68) {
Sign sign = (Sign) event.getBlock().getRelative(BlockFace.WEST, 1).getState();
if(sign.getLine(0).contains("VARIABLE")) {
event.setCancelled(true);
}
}
// We use 63 as the ID because this sign isn't placed on a wall, so it's a 'Sign Post'
if(event.getBlock().getRelative(BlockFace.UP, 1).getTypeId() == 63) {
Sign sign = (Sign) event.getBlock().getRelative(BlockFace.UP, 1).getState();
if(sign.getLine(0).contains("VARIABLE")) {
event.setCancelled(true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment