Пример #1
0
  /** @author CraftCraft */
  public void loadPlugins() {
    pluginManager.registerInterface(JavaPluginLoader.class);

    File pluginFolder = theServer.getFile("plugins");

    if (pluginFolder.exists()) {
      this.theLogger.info("Plugins are being loaded...");
      Plugin[] plugins = pluginManager.loadPlugins(pluginFolder);
      for (Plugin plugin : plugins) {
        try {
          String message = String.format("Loading %s", plugin.getDescription().getFullName());
          plugin.getLogger().info(message);
          plugin.onLoad();
        } catch (Throwable ex) {
          Logger.getLogger(CraftServer.class.getName())
              .log(
                  Level.SEVERE,
                  ex.getMessage()
                      + " initializing "
                      + plugin.getDescription().getFullName()
                      + " (Is it up to date?)",
                  ex);
        }
      }
    } else {
      theLogger.info("Plugin folder doesn't exist: " + pluginFolder.getAbsolutePath());
      pluginFolder.mkdir();
    }
  }
Пример #2
0
  /*
   * @author CraftCraft
   */
  private void loadPlugin(Plugin plugin) {
    try {
      pluginManager.enablePlugin(plugin);

      List<Permission> perms = plugin.getDescription().getPermissions();

      for (Permission perm : perms) {
        try {
          pluginManager.addPermission(perm);
        } catch (IllegalArgumentException ex) {
          getLogger()
              .log(
                  Level.WARNING,
                  "Plugin "
                      + plugin.getDescription().getFullName()
                      + " tried to register permission '"
                      + perm.getName()
                      + "' but it's already registered",
                  ex);
        }
      }
    } catch (Throwable ex) {
      Logger.getLogger(CraftServer.class.getName())
          .log(
              Level.SEVERE,
              ex.getMessage()
                  + " loading "
                  + plugin.getDescription().getFullName()
                  + " (Is it up to date?)",
              ex);
    }
  }
Пример #3
0
 Object createGuiElement(Class cls, EntityPlayer player, World world, int x, int y, int z) {
   try {
     try {
       if (debugGui)
         System.out.printf(
             "BaseMod.createGuiElement: Invoking create method of %s for %s in %s\n",
             cls, player, world);
       return cls.getMethod(
               "create", EntityPlayer.class, World.class, int.class, int.class, int.class)
           .invoke(null, player, world, x, y, z);
     } catch (NoSuchMethodException e) {
       if (debugGui)
         System.out.printf("BaseMod.createGuiElement: Invoking constructor of %s\n", cls);
       return cls.getConstructor(EntityPlayer.class, World.class, int.class, int.class, int.class)
           .newInstance(player, world, x, y, z);
     }
   } catch (Exception e) {
     Throwable cause = e.getCause();
     System.out.printf("BaseMod.createGuiElement: %s: %s\n", e, cause);
     if (cause != null) cause.printStackTrace();
     else e.printStackTrace();
     // throw new RuntimeException(e);
     return null;
   }
 }