西瓜太郎
如题,翻了一圈spigot api 没找到,想做一个简单的像apex那样的标记插件,获取玩家指向的方块/生物并say出来

good14
找个人写一个吧,目前好像没有这类功能性插件

⠀蛋⠀
你可以自己尝试写一个准心对准的一个事件。
然后需要使用时就call一下

  1. public class PlayerViewEvent extends PlayerEvent {

  2.     private final Location playerEyeLocation;
  3.     private static final HandlerList handlers = new HandlerList();

  4.     public PlayerViewEvent(Player who, Location playerEyeLocation) {
  5.         super(who);
  6.         this.playerEyeLocation = playerEyeLocation;
  7.     }

  8.     /**
  9.      * 返回你所看见的实体
  10.      * @return
  11.      */
  12.     public Entity getPlayerViewEntity(){
  13.         Location entityLoc;
  14.         Location closeEntityLoc;
  15.         Vector vector;
  16.         Entity result = null;
  17.         Collection<Entity> entities = this.player.getNearbyEntities(20.0 , 20.0 , 20.0);
  18.         ArrayList<Entity> closeEntities = new ArrayList<>();
  19.         for (Entity entity : entities){
  20.             if (!this.canViewEntity(entity)){ // 省略了是否有方块阻挡的代码
  21.                 continue;
  22.             }
  23.             entityLoc = entity.getLocation();
  24.             vector = entityLoc.subtract(this.player.getLocation()).toVector();
  25.             if (Math.toDegrees(vector.angle(this.playerEyeLocation.getDirection())) <= 30){ // 夹角小于 30 度
  26.                 closeEntities.add(entity);
  27.             }
  28.         }
  29.         if (closeEntities.isEmpty()){ // 无实体
  30.             return null;
  31.         }
  32.         for (Entity entity : closeEntities){
  33.             closeEntityLoc = entity.getLocation();
  34.             if (result == null){
  35.                 result = entity;
  36.                 continue;
  37.             }
  38.             if (closeEntityLoc.distance(this.player.getLocation()) < result.getLocation().distance(this.player.getLocation()) && closeEntityLoc.distance(this.player.getLocation()) != 0){
  39.                 result = entity;
  40.             }
  41.         }
  42.         return result;
  43.     }

  44.     @Override
  45.     public HandlerList getHandlers() {
  46.         return handlers;
  47.     }

  48.     public static HandlerList getHandlerList() {
  49.         return handlers;
  50.     }
  51. }
复制代码

jjwjj
!!11111

米迦勒c
PlayerInteractEntityEvent 这个事件可以用getRightClicked()方法来获取点击的实体

第一页 上一页 下一页 最后一页