[Solved]How to insert a target to it?

Discussion in 'Plugin Development' started by MM1990d, Sep 15, 2012.

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

    MM1990d

    Hi, I know that it's very stupid, but how to insert target from here:
    Code:
        @EventHandler (priority = EventPriority.NORMAL)
        public void onEntityTarget (EntityTargetEvent event)
        {
                        Entity target = event.getTarget();
        }
     
        
    to here:

    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
        {
         
            if(sender instanceof Player)
            {
                Player player = (Player) sender;
             
                if(commandLabel.equalsIgnoreCase("test"))
                {
                 
                    if(perms.has(player, "test.test"))
                    {
                        //HERE !!!
                        target
                        //HERE !!!
                    }
     
                }
            }
            return false;
        }
    Can you please help me?
     
  2. Offline

    Wundsalz

    You could create an entity variable in the class your onCommand method is located in and use a public set method to change it in your event.
     
    MM1990d likes this.
  3. Offline

    sd5

    Add a static Entity entity to your listener class and set it to event.getTarget() when the event is called.
    You can then access it with YourListenerClass.entity

    Code:
    public class MyListener() implements Listener {
     
        public static Entity entity = null;
     
        public void onEntityTarget(EntityTargetEvent event) {
            entity = event.getTarget();
        }
     
    }
    Code:
    Entity theEntityFromTheListener = MyListener.entity;
    But check whether the entity is null before doing something with it!
     
    MM1990d likes this.
  4. Offline

    MM1990d

    Thanks :)
     
Thread Status:
Not open for further replies.

Share This Page