Hello, i would like know how to create a score for one player when: "As soon as the player has find a chest, a message appears with: You have find 1 chest on 10. " For the sesond chet : "You have find 2 chests on 10. " ... Thanks for you replies. (Sorry for my spelling, I'm french).
@Spadax Create a HashMap. The keys will be player UUIDs and the values will be an Integer. This represents the amount of chests a player has found. Create a second hashmap, the keys will also be UUIDs but the values will be an Arraylist of Locations. This represents the chests that have been already clicked by the player. On player interact If the block is a chest. Check if the location is in the second hashmap's arraylist. If it is, return. If it is not, get the int from the first hashmap, add +1 to the score, and then add the chest's location to the arraylist.
@Spadax Do you have the Location object? If you do, all you need to do is pass it to the list.add() method. Again, it's very hard to help you if you don't post your code.
@Spadax Why? Why would you need that? Unless you plan on storing all three integers and name of the world as one value, the XYZ and world name will all be separated without any way to tell which value goes with the others. Just add the location to the hashmap. If you are still having problems, post your code.
Code: package fr.chest; import java.util.ArrayList; import java.util.HashMap; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.plugin.java.JavaPlugin; public class Global extends JavaPlugin implements Listener{ HashMap<String, Integer> hmp = new HashMap<String, Integer>(); @SuppressWarnings("rawtypes") HashMap<String, ArrayList> hmc = new HashMap<String, ArrayList>(); ArrayList<String> ahm = new ArrayList<>(); public void onEnable() { } public void onInteractChest(PlayerInteractEvent e) { Player p = e.getPlayer(); String uuid = p.getUniqueId().toString(); double c1X = e.getClickedBlock().getLocation().getBlockX(); double c1Y = e.getClickedBlock().getLocation().getBlockY(); double c1Z = e.getClickedBlock().getLocation().getBlockZ(); if(e.getMaterial() == Material.CHEST) { hmp.put(uuid, 0); hmc.put(uuid, ahm); } } }
don't convert uuid to a string. Your HashMap should look like this: HashMap<UUID, Integer> playerScore = new HashMap<UUID, Integer>();
First make sure you got a hashMap that has a UUID and a Location HashMap<UUID, Location> playerChestLocations = new HashMap<UUID,Location>(); get the clickedBlock from the interact event get the Type and if it isn't chest or double chest or trapped chest return save location of the clicked block in a variable for ex: clickedBlock; to store: playerChestLocations.put(player.getUniqueID, clickedBlockLocation);