Solved Cancel BlockRedstone event (So commandblock is not activating)

Discussion in 'Plugin Development' started by Bammerbom, Mar 18, 2014.

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

    Bammerbom

    I know the events PlayerCommandPreprocessEvent and ServerCommandEvent, but none of them is handling commands. Is there an event for commandblocks?
     
  2. Offline

    StealerSlain

    What the exactly you want to do with them? You can use PlayerCloseInventory or PlayerInteract events and do some checks for command block.
     
  3. Offline

    RawCode

    command block disabled by default, probably this is your case.
     
  4. Offline

    Bammerbom

    StealerSlain RawCode How to detect when CommandBlock is getting powered? (When command in commandblock is launched)
     
  5. Offline

    N00BHUN73R

    check if it is a console sender because command block counts as a console... so make command usable by console and walla
     
  6. Offline

    StealerSlain

    Jhtzb
    There is org.bukkit.command.BlockCommandSender.
    Go to documentation and learn how to work with it.
     
    Jhtzb likes this.
  7. Offline

    Bammerbom

    N00BHUN73R just tested it: ServerCommandEvent is not launching when I power a commandblock. I search a way to detect when a commandblock is launching. Any ideas?

    StealerSlain I didnt know about it, but still is there no event fired when commandblock is launching?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  8. Offline

    RawCode

    it does trigger redstone event, please read documentation first.
     
  9. Offline

    Bammerbom

    RawCode I got the code. But my last thing. I need to cancel the command (Not always just certain command I already have code for that). How?
     
  10. Offline

    RawCode

    post your code and we will discuss why it does not work.
     
  11. Offline

    Bammerbom

    RawCode My code works. But I have to cancel the BlockRedstone event. (So the command does not execute)
    How?
     
  12. Offline

    RawCode

    post your code and we will discuss why it does not work in some mysterious undescribed way you want.
     
  13. Offline

    Bammerbom

    RawCode I think you don't understand me. I have no idea how to cancel it. My question is just: "How to cancel a BlockRedstoneEvent so a commandblock won't execute his command?"
     
  14. Offline

    RawCode

    i can't tell you how you shoud cancel your event properly without your code.
    not everything can be done with event.setcancelled()
     
  15. Offline

    Bammerbom

    RawCode
    Code:java
    1. @EventHandler(priority = EventPriority.LOW)
    2. public void cmdblockActivate(BlockRedstoneEvent e){
    3. if(e.getBlock().getType().equals(Material.COMMAND)){ //Check if block is command
    4. if(!(e.getNewCurrent() == 0) && e.getOldCurrent() == 0){ //Check if block was not activated already
    5. Block b1 = e.getBlock();
    6. final CommandBlock b2 = (CommandBlock) b1.getState();
    7. final String command = b2.getCommand();
    8. //Doing stuff
    9. CANCEL
    10.  
    11. }
    12. }
    13. }

    This plugin has shortcut commands, handling them with events. But need to cancel event to override default commands.
     
  16. Offline

    RawCode

    this is code of BlockCommand worldupdate reaction
    alter your redstone event outcome to not meed first condition and block wont trigger command.
    you also can alter oldcurrent with reflection if needed, this wont effect stability of server.

    this is not spoonfeed forum, atleast try to do self before asking and dont forget debugoutput on conditions, your second check obviously never pass.

    Code:
                BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(bukkitBlock, old, current);
                world.getServer().getPluginManager().callEvent(eventRedstone);
                // CraftBukkit end
    
                if (eventRedstone.getNewCurrent() > 0 && !(eventRedstone.getOldCurrent() > 0)) { // CraftBukkit
                    world.setData(i, j, k, l | 1, 4);
                    world.a(i, j, k, this, this.a(world));
                } else if (!(eventRedstone.getNewCurrent() > 0) && eventRedstone.getOldCurrent() > 0) { // CraftBukkit
                    world.setData(i, j, k, l & -2, 4);
                }
    
     
    Jhtzb likes this.
  17. Offline

    Bammerbom

    RawCode My second check can pass, tested it.
    "When the new Current is not 0 and the old one is 0"

    - I see not a way in your code to cancel the event

    RawCode StealerSlain N00BHUN73R I was just testing everything and found an awnser by myself. Just
    Code:java
    1. event.setNewCurrent(0);

    SOLVED

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  18. Offline

    Garris0n

    The answer RawCode clearly pointed out right above you?
     
Thread Status:
Not open for further replies.

Share This Page