如题,翻了一圈spigot api 没找到,想做一个简单的像apex那样的标记插件,获取玩家指向的方块/生物并say出来
找个人写一个吧,目前好像没有这类功能性插件
你可以自己尝试写一个准心对准的一个事件。
然后需要使用时就call一下
复制代码
然后需要使用时就call一下
- public class PlayerViewEvent extends PlayerEvent {
- private final Location playerEyeLocation;
- private static final HandlerList handlers = new HandlerList();
- public PlayerViewEvent(Player who, Location playerEyeLocation) {
- super(who);
- this.playerEyeLocation = playerEyeLocation;
- }
- /**
- * 返回你所看见的实体
- * @return
- */
- public Entity getPlayerViewEntity(){
- Location entityLoc;
- Location closeEntityLoc;
- Vector vector;
- Entity result = null;
- Collection<Entity> entities = this.player.getNearbyEntities(20.0 , 20.0 , 20.0);
- ArrayList<Entity> closeEntities = new ArrayList<>();
- for (Entity entity : entities){
- if (!this.canViewEntity(entity)){ // 省略了是否有方块阻挡的代码
- continue;
- }
- entityLoc = entity.getLocation();
- vector = entityLoc.subtract(this.player.getLocation()).toVector();
- if (Math.toDegrees(vector.angle(this.playerEyeLocation.getDirection())) <= 30){ // 夹角小于 30 度
- closeEntities.add(entity);
- }
- }
- if (closeEntities.isEmpty()){ // 无实体
- return null;
- }
- for (Entity entity : closeEntities){
- closeEntityLoc = entity.getLocation();
- if (result == null){
- result = entity;
- continue;
- }
- if (closeEntityLoc.distance(this.player.getLocation()) < result.getLocation().distance(this.player.getLocation()) && closeEntityLoc.distance(this.player.getLocation()) != 0){
- result = entity;
- }
- }
- return result;
- }
- @Override
- public HandlerList getHandlers() {
- return handlers;
- }
- public static HandlerList getHandlerList() {
- return handlers;
- }
- }
!!11111
PlayerInteractEntityEvent 这个事件可以用getRightClicked()方法来获取点击的实体