我一直在寻找,但我找不到我想要的.我想得到一个球员的位置,如果它符合一个明确的位置,传送到另一个位置的球员。这就是我要得到的。控制台中没有显示错误,但当player在X= 300中时不会发生任何错误。
public void onPlayerInteract(PlayerInteractEvent e)
{
if(e.getPlayer().getLocation().getX()==300)
{
e.getPlayer().teleport(new Location(Bukkit.getServer().getWorld("world"), 310, 75, 300));
}
}发布于 2014-08-12 19:00:02
这里有三个错误,为了使它们正常工作,我修复了我的代码:
public void onPlayerMove(PlayerMoveEvent e)
{ // On player movement!
if((int) e.getPlayer().getLocation().getX() == 300)
// If you cast as int 3.9 or 3.01 it will return 3
{
e.getPlayer().teleport(new Location(Bukkit.getWorld("world"), 310, 75, 300));
/* There is a bug in bukkit plugins since 1.6.4.
* You need to get the world just by getWorld(); not
* getServer().getWorld();
*/
}
}这是在10/10 :)
发布于 2014-08-12 03:43:12
X是一个浮点数,它从来就不是300。试一试
if(Math.abs(e.getPlayer().getLocation().getX()-300) < 1){发布于 2014-08-12 18:44:26
您正在检查玩家的x坐标是否正好等于300,这可能从来不是这样。它最像一个十进制数,类似于所以300.05456。
你可能想做的是,检查球员是否站在一个街区与x = 300。如果是这样的话,这就是你应该做的。
if (e.getPlayer().getLocation().getBlockX() == 300) {
// Do stuff
}https://stackoverflow.com/questions/25255774
复制相似问题