preciousstones api

Discussion in 'Spigot Plugin Development' started by JoKillerPT, Jun 11, 2018.

  1. im making a thing to tell when players leave a or entry i region and i do that
    Code (Java):
        public static boolean bo1 = true;
        public static boolean bo2 = true;
       
        @EventHandler
        public void onMove(PlayerMoveEvent e) {
            Player p1 = e.getPlayer();
            Block b1 = p1.getLocation().getBlock().getRelative(BlockFace.DOWN);
            Location loc = b1.getLocation();
            FieldFlag f1 = FieldFlag.ALL;
            FieldFlag f2 = FieldFlag.PREVENT_PVP;
           
            if (PreciousStones.API().isFieldProtectingArea(f1, loc) == true) {
                if(bo1 == true) {
                    bo1 = false;
                    if (PreciousStones.API().flagAppliesToPlayer(p1, f2, loc) == false) {
                        p1.sendMessage(ChatColor.GREEN + "Entering in a Region, PvP is " + ChatColor.RED + ChatColor.BOLD + "ON");
                    }
                    else {
                        p1.sendMessage(ChatColor.GREEN + "Entering in a Region, PvP is " + ChatColor.GREEN + ChatColor.BOLD + "OFF");
                    }
                    bo2 = true;
                }
            }else {
                if(bo2 == true) {
                    bo2 = false;
                    p1.sendMessage(ChatColor.GREEN + "Leaving a Region, PvP is " + ChatColor.RED + ChatColor.BOLD + "ON");
                }
                bo1 = true;
            }
        }
    but on localhost work fine i put on my server and doing that https://gyazo.com/6ca76ea2f293980f913208f9bd3c9bd8?token=8adcf83338d91ab0e9de4a76f8647be6
    and on localhost its only showing one message
     
  2. It's just a guess but I suppose it works on your localhost because you are alone on that server but you are no longer on your production server.
    You should save a boolean value for each player individually, else this will not work as you imagine it.
    This can be done by using a Map, most commonly a HashMap is used for these kinds of problems.
    As a key, you can use the player's UUID (better than the player object itself), and as value a Boolean Object.
     
  3. yes i do hashmap but how i send message for when that player entry on the region