[solved]Acting on an event after it has happened.

Discussion in 'Plugin Development' started by Trc202, May 9, 2011.

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

    Trc202

    I am working on adding extra functionality to World Guards built in stack command such as automatically stacking upon picking up certain items (cooked pork). When I use my method using "onPlayerPickupItem" it executes my code before the event has occurred. This causes stack to be called then the item placed into the inventory. Is there anyway to let the event pass then act upon it?
    My current code
    Main Class
    Code:
            pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM, PlayerListener, Event.Priority.Monitor, this);
    
    Code:
        public class ItemPickup extends PlayerListener {
    
        public static AutoStack plugin;
        public ItemPickup(AutoStack id){
            plugin = id;
        }
    
        public void onPlayerPickupItem(PlayerPickupItemEvent event){ //Overrides the default Item drop event
            Player player = event.getPlayer(); //Creates object player from class Player, Retrieves player who triggered event
            if(plugin.isEnabled())
            {
                if(plugin.Autostacke.contains(player)){
                    if(plugin.blockauto.contains(event.getItem().getItemStack().getTypeId()))
                    {
                        player.performCommand("stack");
                        return;
                    }
                }
                }
            }
    
    }
     
  2. Offline

    Reil

    My first instinct would be to use the scheduler to schedule whatever it is you want to do on the immediately following tick.
     
    Trc202 likes this.
  3. Offline

    Trc202

    Thanks, that's exactly what I needed.
     
  4. Offline

    Reil

    Cool! Glad I could be of help. :3
     
Thread Status:
Not open for further replies.

Share This Page