有什么办法让玩家给特定的物品时,在坐标?

  • 本文关键字:坐标 玩家 java minecraft
  • 更新时间 :
  • 英文 :


我正在制作我的自定义插件,我想做一件事:

当玩家处于指定区域/坐标时,如从0,60,0到50,80,50设置玩家库存清除

全局来说,你必须检查它是否在移动之前没有出现,以及它是否会在移动之后出现。

你可以这样做:

@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
}

最新更新