HashMap checking and rewriting coordinates

Discussion in 'Plugin Development' started by ReiL_RL, Jun 18, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    ReiL_RL

    Hi, I need help with HashMap. When I click the left mouse button, the coordinates are taken, and then I have to check if these coordinates have already been taken, then overwrite, if not, they are added to the configuration, but I don’t understand how to check and overwrite the existing ones and save them. I apologize for the spelling. I am just Russian and do not know much English. And yes, I'm still a beginner)

    code/

    Code:
    package PrizeParkour;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    public class RigthClick implements Listener  {
      
        @EventHandler
        public void arrowstick(PlayerInteractEvent event) {
            Player p = event.getPlayer();
            if(event.getAction() == Action.LEFT_CLICK_BLOCK){
                if(p.getInventory().getItemInMainHand().getType().equals(Material.BLAZE_ROD) && p.getInventory().getItemInMainHand().getItemMeta().hasDisplayName()) {
                    if(p.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals(ChatColor.translateAlternateColorCodes('&',"&6Wand"))) {
                        for(String line : PrizeParkour.Language.getStringList("messages.point")) {
                            p.sendMessage(ChatColor.translateAlternateColorCodes('&',line));
                        }
                        event.setCancelled(true);
                        Location location = event.getClickedBlock().getLocation();
                        String loc = location.getWorld().getName() + "," + location.getX() + "," + location.getY() + "," + location.getZ() + "," + location.getPitch() + "," + location.getYaw();
                        String[] array = {p.getDisplayName(),loc};
                        if(playerSearch(p.getDisplayName()))
                            PrizeParkour.selections.add(array);
                        else
                            PrizeParkour.selections.add(array);
                    }
                }
            }
        }
        public static Location getDeserializedLocation(String s) {
            String [] split = s.split(";");
            return new Location(Bukkit.getWorld(split[0]), Double.parseDouble(split[1]), Double.parseDouble(split[2]), Double.parseDouble(split[3]), Float.parseFloat(split[4]), Float.parseFloat(split[5]));
        }
      
        public Boolean playerSearch(String player) {
            for(int i = 0; i < PrizeParkour.selections.length; i++) {
                if(PrizeParkour.selections[I][0].equals(player)) {
                    return i;
                }
            }
            return 0;
        }
    }[code][/I]
     
    Last edited by a moderator: Jun 18, 2020
Thread Status:
Not open for further replies.

Share This Page