How can i create each hashmap for each player with this HashMap<String,Entity> antiaura = new HashMap<String, Entity>(); Every help will be appreciated
@ColaCraft, its must be like this <String, Entity> that i add a mob in the hashmap and the player and i want to have this for each player in the server
You mean make a separate map for each player? Or a separate value for each player that you put into a map? If it's the first, just create a new class that contains a map and hold a backreference to the player's uuid.
like this? HashMap<String, HashMap<Object, Entity>> Lol = new HashMap<String, HashMap<Object, Entity>>(); @mythbusterma, like this? Map<String, Map<Object, Entity>> Lol = new HashMap<String, Map<Object, Entity>>(); cause its errors me
@ChipDev, cannot cast to java.util.Map can you explain me more cause i didnt understand verywell? explain more EDIT by Timtower: merged posts
Code:java public class PlayerInfo { private final Map<Object, Entity> map = new HashMap<>(); public PlayerInfo(Player p) { //get any info you want from the p variable } //add methods } Code:java Player p;Map<UUID, PlayerInfo> playerInfos = new HashMap<>(); //wowPlayerInfo info = playerInfos.get(p.getUniqueId());//much infoinfo.someMethod();//very oop Edit: I see your last reply now. You essentially create a class to hold your information for you, and then keep a map of that class. Then in the class do whatever you want to the map. You can store whatever info you want as well if you need to get a reference to the player back (e.g. their UUID to get the object via Bukkit#getPlayer(UUID)).
@1Rogue, its will create separate HashMaps that if the player is in the hashmap of spectators(example) and if he hits a villager its will say him a message and if the others will hit hes villager from the Hashmap its will send him message? sorry for my bad grammar is this is ok? its will create a separate HashMap each player and each entityfor each player? Code: public class PlayerInfo { private final Map<Object, Entity> map = new HashMap<>(); public void checkVillager(Player p, Entity e) { if(!map.containsKey(p)) { map.put(p, e); } } }
uh its not works me i want to do that i addidng a player and villager to a separate HashMap and if the player hits the villager its will send him message and if the others will hit that villager its wont send them message no meter what @ChipDev @nverdier @1Rogue @mythbusterma
@ProStriker123 Wait.. you want a separate HashMap for every player? Or you just want a different entry for each player?
i want separate each player with a villager in the hashmap and when he hits the villager will send him a message that hes kool
@ProStriker123 What exactly are you trying to accomplish? How do you decide the villager for each player? Can it be any player? Any villager?
well i want to make each HashMap thats will contain a player and villager(Example method addNewHashMap(player, villager)) when you spawn him of course and when you hit your villager in your HashMap its will send you message and if the others will hit him its wont send him message no metter what if you created him a each HashMap sorry for my grammar surrrrrrrrrrr
You'd be looking to map an identifier of a player to a respective villager. Which to start leaves us with: Map<UUID, Entity> However, if you wanted to have a list of entities you'd need a list instead of Entity or a separate class that holds all of your entities for you. Additionally, if you want to make sure that if one person tags a villager that is already tagged, you're going to have to separately track which players have tagged which villager.