#Gameisntover help
1 messages ยท Page 1 of 1 (latest)
store it using a HashMap
in fact I dont really know about the hashmaps since im newbie
is there any related document?
yeah the javadocs
but they are very in depth
into the techinal side
also can you resend your code using https://paste.md-5.net/
its much faster to use
just paste code and save
and then copy the link in the browser
oh ok
testhashmap.keySet(damagerPlayer.getUniqueId());
Cant i use it like 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
its the old one
@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
also to set you use
map.put(key, value)
and to get
map.get(key)
to remove
map.remove(key)
oh
So all you need to do is create a new hashmap outside both functions
i recommend you to learn basic java before attempting plugins
damagerPlayer.getUniqueId();
``` that aint doing anything
i knew C#
and they're similar
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
bro
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
wait i cant use map.put for the datas
map.put(damager.getUniqueId());
whats wrong with this
uh
I already created a new hashmap
but the problem is from inside the map
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
oh guess i didnt created a right hashmap
dont just copy it yet
read the whole thing
including the comments
especially the comments
im not gonna copy for sure
just wanna try to know the code's logic
it would be more helpful
good exercise
So that even when players go offline and come online it still works
Exactly
i gtg
im not that really bad to not know the events description ๐
i am following a spigot plugin tutorial in youtube too
ill probably be back soon
i mean it might be helpful
yee
i dont know your level of experience with java and bukkit/spigot
but anyways dcya
i may be back soon
thats right however
k im gonna go to bed too...
its 12:11 AM here
I may need to copy this and bring it for next day however gtg
ty
uhhh
the code had some few problems...
i mean at first you coded
Map<Player, Player> damagers = new HashMap<>();
but i was using entity and you also tried putting entity in hashmap so yeah it was the first error that i fixed by myself by editing hashMap values
another one is i cant get the values in hashmap void playerdeathevent wtf
Player damager = damagers.get(player, damager);
damagers.clear(player);
i tried these but doesnt working either
nvm i've fixed them