Esempio n. 1
0
  @Override
  public void onEnable() {
    plugin = this;
    commands.register(TargetCommands.class);
    commands.register(MovementCommands.class);
    commands.register(ManagementCommands.class);

    PluginManager pm = getServer().getPluginManager();
    pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Priority.Normal, this);
    pm.registerEvent(Event.Type.ENTITY_TARGET, entityListener, Priority.Normal, this);
    pm.registerEvent(Event.Type.PLAYER_ANIMATION, playerListener, Priority.Normal, this);
    pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
    pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Normal, this);
    pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, playerListener, Priority.Normal, this);
    pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Priority.Normal, this);
    pm.registerEvent(Event.Type.PLAYER_INTERACT_ENTITY, playerListener, Priority.Normal, this);
    pm.registerEvent(Event.Type.CHUNK_UNLOAD, worldListener, Priority.Normal, this);
    pm.registerEvent(Event.Type.CHUNK_LOAD, worldListener, Priority.Normal, this);
    PluginDescriptionFile pdfFile = this.getDescription();
    DataHandler.loadSettings();
    DataHandler.loadUsers();

    getServer().getScheduler().scheduleSyncRepeatingTask(this, new TickTask(), 5, 1);
    Messaging.log("version [" + pdfFile.getVersion() + "] (" + codename + ") loaded");
  }
Esempio n. 2
0
  @Override
  public boolean onCommand(
      CommandSender sender, Command command, String commandLabel, String[] args) {
    if (!(sender instanceof Player)) {
      sender.sendMessage("Must be ingame to perform this command.");
      return true;
    }
    Player player = (Player) sender;
    try {
      // must put command into split.
      String[] split = new String[args.length + 1];
      System.arraycopy(args, 0, split, 1, args.length);
      split[0] = command.getName().toLowerCase();

      String modifier = "";
      if (args.length > 0) modifier = args[0];

      // No command found!
      if (!commands.hasCommand(split[0], modifier)) {
        return false;
      }

      try {
        commands.execute(split, player, MonsterManager.getTamer(player), player);
      } catch (CommandPermissionsException e) {
        Messaging.sendError(player, Constants.noPermissionsMessage);
      } catch (MissingNestedCommandException e) {
        Messaging.sendError(player, e.getUsage());
      } catch (CommandUsageException e) {
        Messaging.sendError(player, e.getMessage());
        Messaging.sendError(player, e.getUsage());
      } catch (RequirementMissingException e) {
        Messaging.sendError(player, e.getMessage());
      } catch (WrappedCommandException e) {
        throw e.getCause();
      } catch (UnhandledCommandException e) {
        return false;
      }
    } catch (NumberFormatException e) {
      Messaging.sendError(player, "That is not a valid number.");
    } catch (Throwable excp) {
      excp.printStackTrace();
      Messaging.sendError(player, "Please report this error: [See console]");
      Messaging.sendError(player, excp.getClass().getName() + ": " + excp.getMessage());
    }
    return true;
  }