Hey! Basically I'm doing a /ores plugin where it shows you a players mined ores, however I'm having trouble with the hashmaps. Basically when you're getting a said player's value I would have to check if they have mined any ores if and if they havent, add them to the hashmaps and displayed all the values as 0. But if a player hasnt mined a diamond lets say and a player does /ores <name> then it would show as null. Is there an easier way to check if a player mined the ore instead of making 8 else if statements
How about creating an extra class for this. Maybe something like OreData, where you put your information about a players mining stuff. It could hold all ore counters, and methods for checking if the player allready has mined something. Than you can put it into your hasmap like .put(Player UUID, oreData). If the player has no data yet, put it in with an empty oreData object.
Code: public class OreData implements Listener { HashMap<UUID, Integer> diamonds = new HashMap<UUID, Integer>(); HashMap<UUID, Integer> redstone = new HashMap<UUID, Integer>(); HashMap<UUID, Integer> emerald = new HashMap<UUID, Integer>(); HashMap<UUID, Integer> gold = new HashMap<UUID, Integer>(); HashMap<UUID, Integer> iron = new HashMap<UUID, Integer>(); HashMap<UUID, Integer> coal = new HashMap<UUID, Integer>(); HashMap<UUID, Integer> lapis = new HashMap<UUID, Integer>(); @Lordloss @bwfcwalshy Sorry for the late response, so I have started storing the data and these are what the hashmaps look like. Edit: would it be possible to loop through all these hashmaps and check if a player is in it?
Well, i think you got something wrong about how i meant that... The idea was this: Every player gets an OreData object. in This object the ores are stored as Integer. Then you have one single HashMap<UUID, OreData> which stores all players with their data. If you want to see the mined diamonds by a player, it could look in example like "hashmap.get(uuid).diamonds"