Example #1
0
    public static boolean handleCommand(CommandSender sender, String[] words) {
      if (words.length == 0) return false;

      List<CommandInfo> commands = instance.commandMap.get(words[0]);
      if (commands == null) return false;
      commandLoop:
      for (CommandInfo cmd : commands) {
        if (!(cmd.catchAll
            ? words.length - 1 >= cmd.args.length
            : words.length - 1 == cmd.args.length)) continue;

        List<Object> dataArgs = new ArrayList<Object>(cmd.args.length + 1); // estimate
        dataArgs.add(sender instanceof Player ? (Player) sender : null);
        dataArgs.add(sender instanceof Player ? ((Player) sender).getWorld() : null);

        for (int i = 1; i < words.length; i++) {
          if (i - 1 >= cmd.args.length) break;

          if (!cmd.args[i - 1].addToEventDataList(dataArgs, words[i])) continue commandLoop;
        }

        if (cmd.catchAll && cmd.catchAllName != null) {
          dataArgs.add(
              Utils.joinBy(" ", Arrays.copyOfRange(words, cmd.args.length + 1, words.length)));
        }

        EventData data = cmd.eventInfo.makeData(dataArgs.toArray(), false);
        try {
          if (cmd.routines != null) cmd.routines.run(data);
        } catch (BailException e) {
          ModDamage.reportBailException(e);
        }

        return true;
      }

      return false;
    }
Example #2
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onEntityDamage(EntityDamageEvent event) {
    if (!ModDamage.isEnabled || event.isCancelled()) return;

    if (!event.isCancelled() && (event.getEntity() instanceof LivingEntity)) {
      EventData data = getEventData(event);
      if (data != null) {
        runRoutines(data);
        double newDamage = data.get(Double.class, data.start + 5);

        event.setCancelled(data.get(Boolean.class, data.start + data.objects.length - 1));

        if (event.getDamage() != newDamage && newDamage <= 0) event.setCancelled(true);

        event.setDamage(newDamage);
      } else
        ModDamage.printToLog(
            Level.SEVERE,
            "["
                + Bukkit.getPluginManager().getPlugin("ModDamage").getDescription().getName()
                + "] Error! Unhandled damage event. Is Bukkit and ModDamage up-to-date?");
    }
  }
Example #3
0
 @Override
 public Plugin getPlugin() {
   return ModDamage.getPluginConfiguration().plugin;
 }