I know that you can have multiple events in the same class, but is it possible to use two events at the same time in that class? heres what i want (so its easier to explain) When a player drops an item, i want it to send the "dropper" a message saying who picked it up, like this Code:java player.sendMessage(ChatColor.YELLOW + "You gave " + <NameofPlayerWhoPickedUpItem> + " " +value + " " + item.getItemStack().getType().name().toLowerCase()); and when a player picks up an item, like this Code:java player.sendMessage(ChatColor.YELLOW + "You got " + ChatColor.DARK_GREEN + item.getItemStack().getType().name().toLowerCase() + " from " + <NameOfPlayerWhoDroppedItem>);
PlayerPickupItemEvent and PlayerDropItemEvent.... right? wouldnt i need both? or else how would i get who dropped the item AND who picked it up?
so that i can get the name of who dropped something and the name of who picked something up at the same time like this Code: player.sendMessage(ChatColor.YELLOW + "You gave " + <nameofplayrwhopickedup> + " " +value + " " + item.getItemStack().getType().name().toLowerCase()); in order for that to work (this is player drop event btw) i need to be able to get the name of who picked up the item, and i have yet to find a way to do it, so if you have one please tell me
You're thinking about this all wrong. You can't make those events work at the same time, because they happen at different times. They could be separated by a second, or by several minutes. Instead of thinking about how to get those two events to work at the same time, you should be thinking about how to transfer some bits of information from one event to the other.
You could use a HashMap to store the item that a player dropped and then cross check it when a player picks it up like this: Code: HashMap<Item, Player> hashmap = new HashMap<Item, Player>(); //on drop ..... hashmap.put(item, player); //on pickup ....... if(hashmap.contains(item) { player.sendMessage("Message"); hashmap.get(item).sendMessage("Message"); hashmap.remove(item); }
i give up on this i dont understand it and im in a terrible mood. i wont get it to work i dont even know why i tried. sorry for wasting your time.
looking at his code isnt going to help if i dont understand it. i tried do it and it doesnt work. looking at a tutorial wont help. they are too general.
Just ask about what you don't understand here. Many people will be happy to help unless it is something extremely basic like an if statement because you need to know at least the basics of java before you start trying to program for bukkit and even then people will typically point you in the direction of a good java tutorial. Anyways I'm getting a little off topic. What do you need explained.
im not sure exactly how to use the hashmap in the "on pickup" part when i do if(hashmap.contains(item)){ i get an error on contains (not sure how to fix that)
alright, how do i make it so that both players get a message? (the dropper of the item gets "you gave <playerwhopickedup> (itemname)!" and the player who picks it up gets "you got <item> from <droppingplayer>" ??
What I was saying is that the tutorial on the bukkit wiki has a great info on hashkeys! That is where I learned how to do mine... also the javadocs are amazing!! And as @Jogy34 said we are willing to help
I would say on the event with the drop... hashkey.put(event.getPlayer()) and the event with the pickup... hashkey2.put(event.getPlayer()) Bukkit.braodcastMessage(hashkey.get()+" has picked up an item from " + hashkey2.get())
It's just this: Code: if(hashmap.containsKey(item) //this checks to see if the item picked up was dropped by a player //assuming you stored it when the player dropped it { player.sendMessage("Message"); //player in this instance is the one you get from //event.getPlayer(); hashmap.get(item).sendMessage("Message"); //this gets the player that dropped the item //that was stored in the HashMap hashmap.remove(item);//this gets rid of the item to save memory allocation for other things } A HashMap, by the way, stores a Key and a Value to go with the key <Key, Value>. You can then get the Value by looking for the Key and use it to do many other things. Don't worry it took me a week or two to understand HashMaps when I was first using them.
but then how do i get "you got <item> from <player>" when a player picks it up?? :/ it sends the message but i cant get the name of who dropped it :/
It would be something like this: Code: player.sendMessage("You got " + event.getItem() + " from " + hashmap.get(event.getItem()).getName());
hmm, one last thing, how would i make it (i know how i just dont know EXACTLY what to put) so that if the player that picks it up is the player that drops it, it doesnt, send the message? Code:java if(!(something not sure what).equals(somethingnotsure what :3 ))){//send the messages}
would that need to be Code:java if(event.getPlayer() != hashmap.get(item).getPlayer()){//Stuff} so that it gets the player?