How do you use multiple events in 1 event method

Discussion in 'Plugin Development' started by kingmo100, Mar 21, 2017.

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

    kingmo100

    Code:
    package org.kingmo100.Kingmo100.HackTest;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    
    import net.md_5.bungee.api.ChatColor;
    import net.minecraft.server.v1_8_R3.EntityPlayer;
    
    public class Reach implements Listener{
        public int getPing(Player p3) { CraftPlayer cp = (CraftPlayer) p3; EntityPlayer ep = cp.getHandle(); return ep.ping; }
    
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onClickEvent(PlayerInteractEvent e, EntityDamageByEntityEvent e2, EntityDamageEvent e3){
          
            Player p = e.getPlayer();
          
            Player p2 = (Player) e2.getDamager();
            Player me =  Bukkit.getServer().getPlayer("Kingmo100");
            if(e.getAction().equals(Action.LEFT_CLICK_AIR) || e.getAction().equals(Action.LEFT_CLICK_BLOCK)){
                Location location = p2.getLocation();
                Location location2 = p.getLocation();
                int x1 = location.getBlockX();
                int y1 = location.getBlockY();
                int z1 = location.getBlockZ();
                int x2 = location2.getBlockX();
                int y2 = location2.getBlockY();
              
                int z2 = location2.getBlockZ();
                int ping = getPing(p2);
                if(ping <= 300){
        
                }else{
                    for(int x = 0; x < 10; x++)
                    p2.sendMessage(ChatColor.RED + "Playing with high ping will factor into gameplay please try not to, Your ping is at " + ping);
                  
                }
          
            }
        }
    }
    
    Please help Idk what to do
    I cut some code out because Im working on a custom anti cheat
     
  2. Offline

    mehboss

    You can't
     
  3. Offline

    Zombie_Striker

    @kingmo100
    As has already been posted, you cant. You can store variables in hashmaps or arrays to transfer objects between events, but you can't actually put events together.

    Also, why are you on 1.8? Please read this.
     
  4. Offline

    kingmo100

    thanks I thought you could. so could I put a boolean like this
    Code:
    public boolean test = false;
    
    @EventHandler
    public void onasjuf(PlayerInteractEvent e){
    if(test = true){
    
    }
    
    }
    
    @EventHandler
    public void ofhdsaf(EnitityDamageByEntityEvent e){
    if(e.fdahsdf){
    test = true;
    }
    
    }
     
  5. Offline

    Zombie_Striker

    @kingmo100
    Sort of. First, by only using a field for the boolean instead of an array/hashmap for each indevidual player, that boolean can be accessed any player at any time across the whole server. This may not be what you want.

    Also, you don't need the "== true" bit. As long as test is a boolean, you can just provide that instance without comparing it.
     
Thread Status:
Not open for further replies.

Share This Page