[Tutorial] Stop signs from being destroyed and the surrounding blocks

Discussion in 'Resources' started by Jozeth, Jul 30, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Jozeth

    I'm making a new plugin and did this to stop signs from being destroyed and the surrounding blocks, so I decided to share it.

    (Don't know why there's the colour tags)
    Code:java
    1. [COLOR=#000000] @EventHandler[/COLOR]
    2. [COLOR=#000000] public void blockSignBreak(BlockBreakEvent event) {
    3. if(event.getBlock().getState() instanceof Sign) {
    4. Sign sign = (Sign) event.getBlock().getState();
    5. // Stop the destruction of signs all together, if they contain stuff on each line
    6. if(sign.getLine(0).contains("VARIABLE")) {
    7. // if(sign.getLine(LINE).equalsIgnoreCase(anotherString)) {
    8. /*
    9.   * Sign lines:
    10.   * 0 = First line
    11.   * 1 = Second line
    12.   * 2 = Third line
    13.   * 3 = Forth line
    14.   */
    15. event.setCancelled(true);
    16. }
    17. }
    18.  
    19. // Stop the blocks the signs are touching from being destroyed
    20. // We use 68 as the ID because the sign is a 'Wall Sign'
    21. if(event.getBlock().getRelative(BlockFace.NORTH, 1).getTypeId() == 68) {
    22. Sign sign = (Sign) event.getBlock().getRelative(BlockFace.NORTH, 1).getState();
    23. if(sign.getLine(0).contains("VARIABLE")) {
    24. event.setCancelled(true);
    25. }
    26. }
    27. if(event.getBlock().getRelative(BlockFace.EAST, 1).getTypeId() == 68) {
    28. Sign sign = (Sign) event.getBlock().getRelative(BlockFace.EAST, 1).getState();
    29. if(sign.getLine(0).contains("VARIABLE")) {
    30. event.setCancelled(true);
    31. }
    32. }
    33. if(event.getBlock().getRelative(BlockFace.SOUTH, 1).getTypeId() == 68) {
    34. Sign sign = (Sign) event.getBlock().getRelative(BlockFace.SOUTH, 1).getState();
    35. if(sign.getLine(0).contains("VARIABLE")) {
    36. event.setCancelled(true);
    37. }
    38. }
    39. if(event.getBlock().getRelative(BlockFace.WEST, 1).getTypeId() == 68) {
    40. Sign sign = (Sign) event.getBlock().getRelative(BlockFace.WEST, 1).getState();
    41. if(sign.getLine(0).contains("VARIABLE")) {
    42. event.setCancelled(true);
    43. }
    44. }
    45. // We use 63 as the ID because this sign isn't placed on a wall, so it's a 'Sign Post'
    46. if(event.getBlock().getRelative(BlockFace.UP, 1).getTypeId() == 63) {
    47. Sign sign = (Sign) event.getBlock().getRelative(BlockFace.UP, 1).getState();
    48. if(sign.getLine(0).contains("VARIABLE")) {
    49. event.setCancelled(true);
    50. }
    51. } [/COLOR]
    52. [COLOR=#000000] }[/COLOR]

    Link: https://gist.github.com/Jozeth/6114277
    P.S If there's a better way of doing this, either leave a comment or fork the gist...
     
  2. Offline

    user_43347

    Just use a for loop and add to the location...
     
    chaseoes likes this.
Thread Status:
Not open for further replies.

Share This Page