예제 #1
0
 private void sendSpecificHelp(CommandSender sender, String rootCommand, String modifier)
     throws CommandException {
   CommandInfo info = getCommand(rootCommand, modifier);
   if (info == null)
     throw new CommandException(CommandMessages.COMMAND_MISSING, rootCommand + " " + modifier);
   Messaging.send(sender, format(info.getCommandAnnotation(), rootCommand));
   String help = Messaging.tryTranslate(info.getCommandAnnotation().help());
   if (help.isEmpty()) return;
   Messaging.send(sender, ChatColor.AQUA + help);
 }
예제 #2
0
파일: NMS.java 프로젝트: Jeebiss/Citizens2
  static {
    // true field above false and three synchronised lists
    THREAD_STOPPER = getField(NetworkManager.class, "n");

    // constants taken from source code
    MOVEMENT_SPEEDS.put(EntityType.CHICKEN, 0.25F);
    MOVEMENT_SPEEDS.put(EntityType.COW, 0.2F);
    MOVEMENT_SPEEDS.put(EntityType.CREEPER, 0.3F);
    MOVEMENT_SPEEDS.put(EntityType.IRON_GOLEM, 0.15F);
    MOVEMENT_SPEEDS.put(EntityType.MUSHROOM_COW, 0.2F);
    MOVEMENT_SPEEDS.put(EntityType.OCELOT, 0.23F);
    MOVEMENT_SPEEDS.put(EntityType.SHEEP, 0.25F);
    MOVEMENT_SPEEDS.put(EntityType.SNOWMAN, 0.25F);
    MOVEMENT_SPEEDS.put(EntityType.PIG, 0.27F);
    MOVEMENT_SPEEDS.put(EntityType.PLAYER, 1F);
    MOVEMENT_SPEEDS.put(EntityType.VILLAGER, 0.3F);

    LAND_SPEED_MODIFIER_FIELD = getField(EntityLiving.class, "bQ");
    SPEED_FIELD = getField(EntityLiving.class, "bI");
    NAVIGATION_WORLD_FIELD = getField(Navigation.class, "b");
    PATHFINDING_RANGE = getField(Navigation.class, "e");
    GOAL_FIELD = getField(PathfinderGoalSelector.class, "a");

    try {
      Field field = getField(EntityTypes.class, "d");
      ENTITY_INT_TO_CLASS = (Map<Integer, Class<?>>) field.get(null);
      field = getField(EntityTypes.class, "e");
      ENTITY_CLASS_TO_INT = (Map<Class<?>, Integer>) field.get(null);
    } catch (Exception e) {
      Messaging.logTr(Messages.ERROR_GETTING_ID_MAPPING, e.getMessage());
    }
  }
예제 #3
0
 private static String format(Command command, String alias) {
   return String.format(
       COMMAND_FORMAT,
       alias,
       (command.usage().isEmpty() ? "" : " " + command.usage()),
       Messaging.tryTranslate(command.desc()));
 }
 @Override
 public String getPromptText(ConversationContext context) {
   String text = Messaging.tr(Messages.SELECTION_PROMPT);
   for (NPC npc : choices) {
     text += "\n    - " + npc.getId();
   }
   return text;
 }
예제 #5
0
파일: NMS.java 프로젝트: Jeebiss/Citizens2
 public static void stopNetworkThreads(NetworkManager manager) {
   if (THREAD_STOPPER == null) return;
   try {
     THREAD_STOPPER.set(manager, false);
   } catch (Exception e) {
     Messaging.logTr(Messages.ERROR_STOPPING_NETWORK_THREADS, e.getMessage());
   }
 }
예제 #6
0
파일: NMS.java 프로젝트: Jeebiss/Citizens2
 public static void setLandSpeedModifier(EntityLiving handle, float speed) {
   if (LAND_SPEED_MODIFIER_FIELD == null) return;
   try {
     LAND_SPEED_MODIFIER_FIELD.setFloat(handle, speed);
   } catch (Exception e) {
     Messaging.logTr(Messages.ERROR_UPDATING_SPEED, e.getMessage());
   }
 }
예제 #7
0
 /**
  * A safe version of <code>execute</code> which catches and logs all errors that occur. Returns
  * whether the command handler should print usage or not.
  *
  * @see #execute(Command, String[], CommandSender, Object...)
  * @return Whether further usage should be printed
  */
 public boolean executeSafe(
     org.bukkit.command.Command command,
     String[] args,
     CommandSender sender,
     Object... methodArgs) {
   try {
     try {
       execute(command, args, sender, methodArgs);
     } catch (ServerCommandException ex) {
       Messaging.sendTr(sender, CommandMessages.MUST_BE_INGAME);
     } catch (CommandUsageException ex) {
       Messaging.sendError(sender, ex.getMessage());
       Messaging.sendError(sender, ex.getUsage());
     } catch (UnhandledCommandException ex) {
       return false;
     } catch (WrappedCommandException ex) {
       throw ex.getCause();
     } catch (CommandException ex) {
       Messaging.sendError(sender, ex.getMessage());
     } catch (NumberFormatException ex) {
       Messaging.sendErrorTr(sender, CommandMessages.INVALID_NUMBER);
     }
   } catch (Throwable ex) {
     ex.printStackTrace();
     if (sender instanceof Player) {
       Messaging.sendErrorTr(sender, CommandMessages.REPORT_ERROR);
       Messaging.sendError(sender, ex.getClass().getName() + ": " + ex.getMessage());
     }
   }
   return true;
 }
예제 #8
0
 private void sendHelp(CommandSender sender, String name, int page) throws CommandException {
   if (name.equalsIgnoreCase("npc")) name = "NPC";
   Paginator paginator =
       new Paginator()
           .header(capitalize(name) + " " + Messaging.tr(CommandMessages.COMMAND_HELP_HEADER));
   for (String line : getLines(sender, name.toLowerCase())) paginator.addLine(line);
   if (!paginator.sendPage(sender, page))
     throw new CommandException(CommandMessages.COMMAND_PAGE_MISSING, page);
 }
예제 #9
0
파일: NMS.java 프로젝트: Jeebiss/Citizens2
 public static void updatePathfindingRange(NPC npc, float pathfindingRange) {
   if (PATHFINDING_RANGE == null) return;
   Navigation navigation = ((CraftLivingEntity) npc.getBukkitEntity()).getHandle().getNavigation();
   try {
     PATHFINDING_RANGE.set(navigation, pathfindingRange);
   } catch (Exception e) {
     Messaging.logTr(Messages.ERROR_UPDATING_PATHFINDING_RANGE, e.getMessage());
   }
 }
예제 #10
0
 static {
   try {
     Field field = getField(EntityTypes.class, "f");
     ENTITY_CLASS_TO_INT = (Map<Class<?>, Integer>) field.get(null);
     field = getField(EntityTypes.class, "d");
     ENTITY_CLASS_TO_NAME = (Map<Class<?>, String>) field.get(null);
   } catch (Exception e) {
     Messaging.logTr(Messages.ERROR_GETTING_ID_MAPPING, e.getMessage());
   }
 }
예제 #11
0
파일: NMS.java 프로젝트: Jeebiss/Citizens2
 public static void updateNavigationWorld(LivingEntity entity, org.bukkit.World world) {
   if (NAVIGATION_WORLD_FIELD == null) return;
   EntityLiving handle = ((CraftLivingEntity) entity).getHandle();
   World worldHandle = ((CraftWorld) world).getHandle();
   try {
     NAVIGATION_WORLD_FIELD.set(handle.getNavigation(), worldHandle);
   } catch (Exception e) {
     Messaging.logTr(Messages.ERROR_UPDATING_NAVIGATION_WORLD, e.getMessage());
   }
 }
예제 #12
0
파일: NMS.java 프로젝트: Jeebiss/Citizens2
 public static Field getField(Class<?> clazz, String field) {
   Field f = null;
   try {
     f = clazz.getDeclaredField(field);
     f.setAccessible(true);
   } catch (Exception e) {
     Messaging.logTr(Messages.ERROR_GETTING_FIELD, field, e.getMessage());
   }
   return f;
 }
예제 #13
0
 public static void clearGoals(PathfinderGoalSelector... goalSelectors) {
   if (GOAL_FIELD == null || goalSelectors == null) return;
   for (PathfinderGoalSelector selector : goalSelectors) {
     try {
       List<?> list = (List<?>) NMS.GOAL_FIELD.get(selector);
       list.clear();
     } catch (Exception e) {
       Messaging.logTr(Messages.ERROR_CLEARING_GOALS, e.getLocalizedMessage());
     }
   }
 }
 @Override
 protected Prompt acceptValidatedInput(ConversationContext context, Number input) {
   boolean found = false;
   for (NPC npc : choices) {
     if (input.intValue() == npc.getId()) {
       found = true;
       break;
     }
   }
   CommandSender sender = (CommandSender) context.getForWhom();
   if (!found) {
     Messaging.sendErrorTr(sender, Messages.SELECTION_PROMPT_INVALID_CHOICE, input);
     return this;
   }
   NPC toSelect = CitizensAPI.getNPCRegistry().getById(input.intValue());
   try {
     callback.run(toSelect);
   } catch (ServerCommandException ex) {
     Messaging.sendTr(sender, CommandMessages.MUST_BE_INGAME);
   } catch (CommandUsageException ex) {
     Messaging.sendError(sender, ex.getMessage());
     Messaging.sendError(sender, ex.getUsage());
   } catch (UnhandledCommandException ex) {
     ex.printStackTrace();
   } catch (WrappedCommandException ex) {
     ex.getCause().printStackTrace();
   } catch (CommandException ex) {
     Messaging.sendError(sender, ex.getMessage());
   } catch (NumberFormatException ex) {
     Messaging.sendErrorTr(sender, CommandMessages.INVALID_NUMBER);
   }
   return null;
 }
예제 #15
0
 public static void updateNavigationWorld(
     org.bukkit.entity.Entity entity, org.bukkit.World world) {
   if (NAVIGATION_WORLD_FIELD == null) return;
   Entity en = NMS.getHandle(entity);
   if (en == null || !(en instanceof EntityInsentient)) return;
   EntityInsentient handle = (EntityInsentient) en;
   World worldHandle = ((CraftWorld) world).getHandle();
   try {
     NAVIGATION_WORLD_FIELD.set(handle.getNavigation(), worldHandle);
   } catch (Exception e) {
     Messaging.logTr(Messages.ERROR_UPDATING_NAVIGATION_WORLD, e.getMessage());
   }
 }
예제 #16
0
파일: NMS.java 프로젝트: Jeebiss/Citizens2
 public static org.bukkit.entity.Entity spawnCustomEntity(
     org.bukkit.World world, Location at, Class<? extends Entity> clazz, EntityType type) {
   World handle = ((CraftWorld) world).getHandle();
   Entity entity = null;
   try {
     Constructor<?> constructor = getCustomEntityConstructor(clazz, type);
     entity = (Entity) constructor.newInstance(handle);
   } catch (Exception e) {
     Messaging.logTr(Messages.ERROR_SPAWNING_CUSTOM_ENTITY, e.getMessage());
     return null;
   }
   handle.addEntity(entity);
   entity.setLocation(at.getX(), at.getY(), at.getZ(), at.getYaw(), at.getPitch());
   return entity.getBukkitEntity();
 }
예제 #17
0
파일: NMS.java 프로젝트: Jun3541/Citizens2
 static {
   try {
     Field field = getField(EntityTypes.class, "e");
     ENTITY_INT_TO_CLASS = (Map<Integer, Class<?>>) field.get(null);
     field = getField(EntityTypes.class, "f");
     ENTITY_CLASS_TO_INT = (Map<Class<?>, Integer>) field.get(null);
   } catch (Exception e) {
     Messaging.logTr(Messages.ERROR_GETTING_ID_MAPPING, e.getMessage());
     try {
       Field field = getField(Class.forName("ns"), "d");
       MC_ENTITY_INT_TO_CLASS = (Map<Integer, Class<?>>) field.get(null);
       field = getField(Class.forName("ns"), "e");
       MC_ENTITY_CLASS_TO_INT = (Map<Class<?>, Integer>) field.get(null);
     } catch (Exception e2) {
     }
   }
 }
예제 #18
0
 @Override
 public void load(DataKey key) throws NPCLoadException {
   for (DataKey sub : key.getRelative("list").getIntegerSubKeys()) {
     String[] parts = sub.getString("").split(";");
     Location location;
     try {
       location =
           new Location(
               Bukkit.getServer().getWorld(parts[1]),
               Double.valueOf(parts[2]),
               Double.valueOf(parts[3]),
               Double.valueOf(parts[4]));
       anchors.add(new Anchor(parts[0], location));
     } catch (NumberFormatException e) {
       Messaging.logTr(Messages.SKIPPING_INVALID_ANCHOR, sub.name(), e.getMessage());
     } catch (NullPointerException e) {
       // Invalid world/location/etc. Still enough data to build an
       // unloaded anchor
       anchors.add(new Anchor(parts[0], sub.getString("").split(";", 2)[1]));
     }
   }
 }
 @Override
 public void begin() {
   Messaging.sendTr(player, Messages.EQUIPMENT_EDITOR_BEGIN);
 }
예제 #20
0
 public void describe(CommandSender sender) {
   Messaging.sendTr(sender, Messages.AGE_TRAIT_DESCRIPTION, npc.getName(), age, locked);
 }
예제 #21
0
 public String getPromptText(final ConversationContext context) {
   return Messaging.tr("citizens.editors.waypoints.triggers.delay.prompt", new Object[0]);
 }
 @Override
 public void end() {
   Messaging.sendTr(player, Messages.EQUIPMENT_EDITOR_END);
 }
예제 #23
0
 public void describe(CommandSender sender) {
   Messaging.sendTr(sender, Messages.SIZE_DESCRIPTION, npc.getName(), size);
 }