/**
   * Register an event. python-facing. this version converts from string info.
   *
   * @param handler function handler
   * @param type Event type string
   * @param priority Event priority string
   */
  public void registerEvent(PyObject handler, PyString type, PyString priority) {
    try {
      String clazz = type.asString();
      Class<?> event = null;

      if (clazz.contains(".")) {
        try {
          // try if we can find the class
          event = Class.forName(clazz);
        } catch (ClassNotFoundException e) {
          // assume the subpackage and class name was given and append org.bukkit.event
          event = Class.forName("org.bukkit.event." + clazz);
        }
      } else if (customEvents.containsKey(clazz)) {
        // check if the name of a custom event was given
        event = customEvents.get(clazz);
      } else {
        throw new IllegalArgumentException("Could not find Event " + clazz);
      }

      if (!event.getClass().isInstance(event)) {
        throw new IllegalArgumentException(type.asString().toUpperCase() + " is not of type Event");
      }
      Class<? extends Event> realtype = (Class<? extends Event>) event;
      EventPriority realpriority = EventPriority.valueOf(priority.upper());
      registerEvent(handler, realtype, realpriority);

    } catch (ClassNotFoundException e) {
      Bukkit.getLogger()
          .log(
              Level.SEVERE,
              "Could not register event " + type + " because the event could not be found",
              e);
    }
  }
Пример #2
0
  public void configurePlugin() {

    if (getConfig().getBoolean("logfile")) {
      setupLogfile();
    } else { // Needed during configuration reload to turn off logging if the option changes
      if (logfileHandler != null) {
        logfileHandler.close();
        logger.removeHandler(logfileHandler);
        logfileHandler = null;
      }
    }

    try {
      ruleLogLevel = Level.parse(getConfig().getString("loglevel", "info").toUpperCase());
    } catch (IllegalArgumentException e) {
      ruleLogLevel = Level.INFO;
    }

    decolor = getConfig().getBoolean("decolor");

    try {
      debugMode = DebugModes.valueOf(getConfig().getString("debug"));
    } catch (IllegalArgumentException e) {
      debugMode = DebugModes.off;
    }

    cmdlist = getConfig().getStringList("cmdlist");
    cmdblist = getConfig().getStringList("cmdblist");

    enabledEvents.clear(); // Reset the enabled event types.
    for (EventType e : EventType.values()) {
      switch (e) {
        case CHAT:
          chatPriority =
              EventPriority.valueOf(getConfig().getString("chatpriority", "LOWEST").toUpperCase());
          enabledEvents.add(EventType.CHAT);
          break;

        case COMMAND:
          if (getConfig().getBoolean("commandfilter", false)) {
            cmdPriority =
                EventPriority.valueOf(getConfig().getString("cmdpriority", "LOWEST").toUpperCase());
            enabledEvents.add(EventType.COMMAND);
          }
          break;

        case SIGN:
          if (getConfig().getBoolean("signfilter", false)) {
            signPriority =
                EventPriority.valueOf(
                    getConfig().getString("signpriority", "LOWEST").toUpperCase());
            enabledEvents.add(EventType.SIGN);
          }
          break;

        case ITEM:
          if (getConfig().getBoolean("itemfilter", false)) {
            invPriority =
                EventPriority.valueOf(getConfig().getString("invpriority", "LOWEST").toUpperCase());
            enabledEvents.add(EventType.ITEM);
          }
          break;
      }
    }
  }