Here's a problem... (workaround for WorldGuard detection)

Discussion in 'Plugin Development' started by Jacob Litewski, Mar 26, 2011.

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

    Jacob Litewski

    Well, currently Pixl can bypass WorldGuard protections, which is a big big thing. I think I may of found a way to have WorldGuard detect Pixl, but I need some help implementing it.

    Firstly, I was going to create and throw a new BlockBreakEvent for the block being changed, and wait to see if the event was canceled. If it was, just return and don't worry about anything. If it wasn't, then execute as normal.

    Well, I need help setting up the fake BlockBreakEvent. I also need to know if this is a stupid idea or not, or if there is an actual way to listen for WorldGuard. Because I want to get this fixed before I release Pixl 1.4, since it is a major problem.
     
  2. Offline

    Edward Hand

    To fake an event:
    Code:
       BlockBreakEvent event = new BlockBreakEvent(someBlock, somePlayer);
       server.getPluginManager().callEvent(event);
    
       if (event.isCancelled()) {
          //do some stuff?
       }
    However, you can detect other plugins as follows:
    Code:
    Plugin test = this.getServer().getPluginManager().getPlugin("PluginName");
    
    if(test == null)
       //plugin not found
     
  3. Offline

    Jacob Litewski

    Well, with this way, It will only detect WorldGuard, which really isn't what I want. I want anything that prevents the breaking of Blocks to cancel out Pixl's cycles. And thank you, I was reading the wrong javadoc for what I was doing lol.

    Speaking of that, I also faked a BlockPlaceEvent so loggers like BigBrother can log Pixl. I'm not sure if, when BigBrother reverts changes, the block will go to the original color, but it logs changes to the block so it should.
     
  4. Offline

    Drakia

    It will only go back to the original color if you catch the result of the BlockChangeEvent and change it back yourself. Most plugins will just set the event.cancelled flag, and won't revert anything themselves as far as I know.
     
  5. Offline

    Jacob Litewski

    Well, this is how I did it:
    Code:
    public void pixlArt(Block b, Player p) {
            //Very hackish detection
            BlockBreakEvent event1 = new BlockBreakEvent(b, p);
            plugin.getServer().getPluginManager().callEvent(event1);
            if(event1.isCancelled()) {
                return;
            } else {
                Block previousBlock = b;
                //snip
                BlockPlaceEvent event2 = new BlockPlaceEvent(b, previousBlock.getState(), previousBlock, p.getItemInHand(), p, true);
                plugin.getServer().getPluginManager().callEvent(event2);
            }
    If it still does what you said @Drakia, then I have to approach it differently, because thats a HUGE problem.
     
Thread Status:
Not open for further replies.

Share This Page