[SOLVED]Next problem : protection of [Protection] signs !

Discussion in 'Plugin Development' started by Ribesg, Oct 16, 2011.

Thread Status:
Not open for further replies.
  1. Hi !
    So, I've made a little plugin to protect chests with signs.
    I prevented not allowed players to open a protected chest, to break a protected chest, to break a protection sign, to break a block supporting a protection sign, to create a protection sign attached to a block like sand and gravel, but there is one problem left.
    If someone use a piston on the block where the sign is attached, the sign will be broken.
    This breaking doesn't call a BlockBreakEvent, right ?
    How to handle it ?
     
  2. Offline

    Darkman2412

    You could use the BlockPistonExtend event.
     
  3. I think this will be laggy.
    I just want to know, when a sign breaks, if the first line was [Protection].
    If yes, cancel the event. But when the sign break "alone" I don't know which event I must use.
     
  4. Offline

    Darkman2412

    You just loop through all pushed blocks and check if one is protected. If yes, cancel the event.
     
  5. Now, with this I should loop through all pushed blocks, check if they have a sign attached to them, then for each signs see if their first line is [Protection].
    I solved my problem, I found that the event was BlockPhysicsEvent.
    PHP:
        public void onBlockPhysics(BlockPhysicsEvent event) {
            
    Material material event.getBlock().getType();
            if (
    material.equals(Material.SIGN_POST) || material.equals(Material.WALL_SIGN)) {
                
    Sign sign = (Sign)event.getBlock().getState();
                if (
    ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("[PrivĂ©]")) {
                    
    event.setCancelled(true);
                }
            }
        }
    I think it's faster :)
     
Thread Status:
Not open for further replies.

Share This Page