Hi, been awhile. How can I check if a player is inside of an area without using the MoveEvent? basically when i reload my server i have an array that stores playernames but if i DON'T MOVE the player doesnt get added back into the list.
You could always use the join event to check if they are in the area whenever they first join. I would assume anyway they would get into the area after that would trigger a move event.
@TerroDoor You would have to loop the players and check if they're in the area. Do this in the onEnable.
Why not just use the move event? Yes, it fires a lot but you can filter it so the code only gets ran if they actually moved a block rather than simply moved their head.
@KarimAKL thanks for the response, Ive come up with a function that checks if a player's coords are in/out of the region and i have this check running every second for every player online, inside my onEnable(). I mean, it's working and doing what it's supposed to do however i feel like it's using alot of memory.. and inbetween ticks and updating the player lists it sometimes doesn't register in time.. Code: public void onEnable() { Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { public void run() { for (Player pl : Bukkit.getOnlinePlayers()) { PlayerMove.checkLoc(pl); } } }, 0L, 20L); Code: public void checkLoc(Player p) { int px = p.getLocation().getBlockX(); int py = p.getLocation().getBlockY(); int pz = p.getLocation().getBlockZ(); if (px >= minx && px <= maxx && py >= miny && py <= maxy && pz >= minz && pz <= maxz) { if (!prot.contains(p.getName())) { prot.add(p.getName()); } } else { if (prot.contains(p.getName())) { prot.remove(p.getName()); } } @KarimAKL i'm also doing this because i need to manage AFK players inside of this region, that's why every second i need to update player locations. Could i also use the checkLoc method in a move event to prevent errors inbetween ticks? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
@TerroDoor Just check for the last time they moved using PlayerMoveEvent, instead of having a Runnable check every second.
@TerroDoor Have the Runnable check the last time they moved, then update that time in the PlayerMoveEvent if they're inside the area.