#Gameisntover help

1 messages ยท Page 1 of 1 (latest)

severe bone
#

@upbeat patrol

upbeat patrol
#

so

#

i actually need the damager uuid in Death event

#

player death event*

severe bone
#

store it using a HashMap

upbeat patrol
#

in fact I dont really know about the hashmaps since im newbie
is there any related document?

severe bone
#

yeah the javadocs

#

but they are very in depth

#

into the techinal side

upbeat patrol
#

yup but it may takes some times

severe bone
#

its much faster to use

#

just paste code and save

#

and then copy the link in the browser

upbeat patrol
#

oh ok

#

testhashmap.keySet(damagerPlayer.getUniqueId());
Cant i use it like this?

#

@severe bone

severe bone
#

?

#

to do what?

#

get?

upbeat patrol
#

set the uuid in hashmap

#

to do this

severe bone
#
    @EventHandler
    public void DeathReason(EntityDamageByEntityEvent e) {
        if (e.getDamager() instanceof Player && e.getEntity() instanceof Player) {
           Entity  damager = e.getDamager();
        }
    }

    @EventHandler
    public void PlayervoidDeath(PlayerDeathEvent e) {
         e.setDeathMessage(ChatColor.GRAY+"[ "+ChatColor.RED+player.getDisplayName()+ChatColor.GRAY+" ]"+ChatColor.AQUA+" fell in void by " +ChatColor.GRAY+"[ "+ChatColor.AQUA+ killer.getDisplayName()+ChatColor.GRAY+" ]");
    }
#

i reposted ur code

#

in here

#

for quick access

severe bone
#

oh

#

send new

upbeat patrol
#
  @EventHandler
    public void lastEntityDamager(EntityDamageByEntityEvent e) {
        if (e.getDamager() instanceof Player && e.getEntity() instanceof Player) {
            Entity damager = e.getDamager();
            Player damagerPlayer = (Player) damager;
            damagerPlayer.getUniqueId();
        

        }
    }
        @EventHandler
        public void PlayervoidDeath(PlayerDeathEvent e){
            Player damagerPlayer = (Player) lastEntityDamager().damagerPlayer;
            damagerPlayer.getUniqueId();
            e.setDeathMessage(ChatColor.GRAY+"[ "+ChatColor.RED+player.getDisplayName()+ChatColor.GRAY+" ]"+ChatColor.AQUA+" fell in void by " +ChatColor.GRAY+"[ "+ChatColor.AQUA+ killer.getDisplayName()+ChatColor.GRAY+" ]");
        } ```
#

i need to use hashmap now

#

but

#

i have no idea for the usage

severe bone
#

also to set you use

map.put(key, value)

and to get

map.get(key)

to remove

map.remove(key)
upbeat patrol
#

oh

trail wadi
#

So all you need to do is create a new hashmap outside both functions

severe bone
#

i recommend you to learn basic java before attempting plugins

trail wadi
#

Yeah

#

It will make everything easier

severe bone
#
damagerPlayer.getUniqueId();
``` that aint doing anything
upbeat patrol
severe bone
#
Player damagerPlayer = (Player) lastEntityDamager().damagerPlayer;
// lastEntityDamager() is an event method, it takes a parameter.
// that should throw a compiler error wtf
// it also doesnt return shit
// should also throw a compiler error lol
severe bone
#

you are trying to access a field

#

on void

#

lastEntityDamager() returns void

#

because its an event method

#

it gets called by bukkit

#

when an entity is damaged

upbeat patrol
#

wait i cant use map.put for the datas

#

map.put(damager.getUniqueId());

#

whats wrong with this

#

uh

#

I already created a new hashmap

upbeat patrol
severe bone
#
Map<Player, Player> damagers = new HashMap<>(); // create HashMap

/**
* Event method. Gets automatically called by Bukkit every time an entity is 
* damaged. Don't forget to register the listener!
**/
@EventHandler // @EventHandler indicates that it's an event method.
public void damaged(EntityDamageByEntityEvent e) {
  // get victim and damager
  Entity victim  = e.getEntity();
  Entity damager = e.getDamager();
  
  // check if the victim and damager are players
  // if so, run the code inside the if statement
  if (vicitm instanceof Player && damager instanceof Player) {
    damagers.put(victim, damager); // map victim to damager
  }
}

@EventHandler 
public void death(PlayerDeathEvent e) {
  Player victim = e.getPlayer(); // get victim player (the player who died)
  
  // remember how we mapped the victims to the damagers using a HashMap?
  // lets retrieve this value
  Player damager = damagers.get(victim);
  // probably a good idea to clean up damagers, to prevent a memory leak
  damagers.remove(victim); 

  // do whatever you want with these values
  ...
}
#

read that

upbeat patrol
severe bone
#

dont just copy it yet

#

read the whole thing

#

including the comments

#

especially the comments

upbeat patrol
#

im not gonna copy for sure
just wanna try to know the code's logic

#

it would be more helpful

severe bone
#

yeah

#

i included comments

#

read those

trail wadi
#

After that it'd be better to do it using UUIDs

#

That's something you can do yourself

severe bone
#

good exercise

trail wadi
#

So that even when players go offline and come online it still works

trail wadi
severe bone
#

i gtg

upbeat patrol
severe bone
#

ill probably be back soon

upbeat patrol
severe bone
#

i dont know your level of experience with java and bukkit/spigot

#

but anyways dcya

#

i may be back soon

upbeat patrol
upbeat patrol
#

I may need to copy this and bring it for next day however gtg

#

ty

upbeat patrol
#
            Player damager = damagers.get(player, damager);
            damagers.clear(player);
#

i tried these but doesnt working either

#

nvm i've fixed them