I'm making my custom plugin and I want to make one thing:
when a player is in a specified region/coords like from 0, 60, 0 to 50, 80, 50 set players inventory clear
CodePudding user response:
Globally, you have to check if it was not in before move, and if it will be in just after.
You can do like that:
@EventHandler
public void onMove(PlayerMoveEvent e) { // when move
if(e.isCancelled())
return;
if(!isLocIn(e.getFrom()) && isLocIn(e.getTo())) { // if was not in but will be in
e.getPlayer().getInventory().clear(); // clear inventory
}
}
private boolean isLocIn(Location loc) {
// enter min & max values
int minX = 0, minY = 60, minZ = 0;
int maxX = 50, maxY = 80, maxZ = 50;
// get content from given loc
double x = loc.getX();
double y = loc.getY();
double z = loc.getZ();
return x > minX && x < maxX && y > minY && y < maxY && z > minZ && z < maxZ; // check in x/y/z are more than min and lower than max
}