先说说这个思路吧,就是获取玩家坐标,当玩家移动,坐标发生变化,之后就清空玩家身上的状态。。
这段代码应该怎么写? 我不知道getLocation()咋用。。。
这段代码应该怎么写? 我不知道getLocation()咋用。。。
PlayerMoveEvent事件:
@EventHandler
public void move(PlayerMoveEvent e)
{
boolean move=false;
Location to=e.getTo();
Location from=e.getFrom();
if(to.getX()!=from.getX())
move=true;
else if(to.getY()!=from.getY())
move=true;
else if(to.getZ()!=from.getZ())
move=true;
if(move)
{
e.getPlayer().sendMessage("§a你进行了真正的移动而不是移动了视角");
}
}
@EventHandler
public void move(PlayerMoveEvent e)
{
boolean move=false;
Location to=e.getTo();
Location from=e.getFrom();
if(to.getX()!=from.getX())
move=true;
else if(to.getY()!=from.getY())
move=true;
else if(to.getZ()!=from.getZ())
move=true;
if(move)
{
e.getPlayer().sendMessage("§a你进行了真正的移动而不是移动了视角");
}
}
PlayerMoveEvent事件在玩家移动视角时也会触发,因此获取原来的地点以及即将移动到的地点,判断即将移动到的地点的xyz其中一个不等于原来的地点的xyz才代表移动
如果是不想那么精确,让他在他所在的方块能移动也没事的话可以把getX()换成getBlockX(),yz同理
如果是不想那么精确,让他在他所在的方块能移动也没事的话可以把getX()换成getBlockX(),yz同理
810587921 发表于 2016-4-10 19:09
PlayerMoveEvent事件:
@EventHandler
public void move(PlayerMoveEvent e)

大触我把你的代码放进eclipse里,但是出现了几个报错,是这个服务端不支持吗?还是eclipse的问题?
602723113 发表于 2016-4-11 06:54
大触我把你的代码放进eclipse里,但是出现了几个报错,是这个服务端不支持吗?还是eclipse的问题? ...
导包啊,
602723113 发表于 2016-4-11 10:07
我就导入了这些,还有什么遗漏的么?我的端是spigot的
Location
