Solved Checking for assists

Discussion in 'Spigot Plugin Development' started by DatsMaboi, Mar 17, 2019.

  1. Hey guys so i want to make a plugin where a player gets a reward for an assist.


    this is what i have done so far
    Code (Java):
    @EventHandler
        public void onDamage (EntityDamageByEntityEvent e) {
         
            Player p = (Player) e.getEntity();
            Player k = (Player) e.getDamager();
         
            assist.add(k);
            Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                public void run() {
                    assist.remove(k);
            }
            } , 100);
         
        }
    However i am clueless as to get the players that damaged the player after he dies and if they are still on the list reward them

    i believe i need some kind of loop when the players dies to loop through all players i the array list
     
    #1 DatsMaboi, Mar 17, 2019
    Last edited: Mar 17, 2019
  2. Well I think the problem is the following line

    Code (Java):
    //your line
    assist.add(k);


    //try this
    assist.add(k.getName());

    //or this should also be fine
    assist.add(k.getUniqueId().toString());
    //edit: I've read something wrong yes need to loop through the Players and use a HashMap then you can store the damaged Entity and the damager.
     
    #2 dmmk218, Mar 17, 2019
    Last edited: Mar 17, 2019
  3. Could u give me a basic outline
     
  4. Can you show ur ArrayList or HashSet line?
     
  5. I would try to setup a HashMap with an String and an Object. Just like this

    Code (Java):
    HashMap<String, Object> assists = new HashMap<String, Object>();
     
        @EventHandler
        public void onEntityDamage(EntityDamageByEntityEvent e) {
         
            Player p = (Player)e.getEntity();
            Player d = (Player)e.getDamager();
         
            assists.put(p.getUniqueId().toString(), d.getUniqueId().toString());
         
            Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
             
                @Override
                public void run() {
                 
                    assists.remove(p.getUniqueId().toString());
                 
                }
            }, 100L);
         
        }
     
        @EventHandler
        public void onEntityDeath(EntityDeathEvent e) {
         
            Player p = (Player)e.getEntity();
         
            if (assists.containsKey(p.getUniqueId().toString())) {
             
                String assistant = (String)assists.get(p.getUniqueId().toString());
             
                //then do what you want assistant contains the UUID of the assist
             
            }
        }
    You could now loop through the online player and check if all.getUniqueId().equals(assistant)
     
    • Informative Informative x 1

Share This Page