private Plugin mockPlugin(Server server, String name, PluginLoadOrder order, String... depend) {
    Plugin plugin = mock(Plugin.class);
    PluginDescriptionFile file = mock(PluginDescriptionFile.class);

    when(plugin.getServer()).thenReturn(server);
    when(plugin.getName()).thenReturn(name);
    when(plugin.toString()).thenReturn(name);
    when(plugin.getDescription()).thenReturn(file);

    // This is the difficult part
    when(file.getLoad()).thenReturn(order);
    when(file.getDepend()).thenReturn(Arrays.asList(depend));
    when(file.getSoftDepend()).thenReturn(null);
    return plugin;
  }
Beispiel #2
0
  public void initializeMasterFilter() {
    String pname = "";
    try {
      for (Plugin p : this.getServer().getPluginManager().getPlugins()) {
        pname = p.toString();
        p.getLogger().setFilter(this.masterFilter);
        // i++;
      }
      this.getServer().getLogger().setFilter(masterFilter);
      Bukkit.getLogger().setFilter(masterFilter);
      Logger.getLogger("Minecraft").setFilter(masterFilter);
    } catch (Exception e) {
      log(Level.INFO, "Cannot load filter in '" + pname + "'. Retrying later..");
    }
    this.getServer()
        .getScheduler()
        .scheduleSyncDelayedTask(
            this,
            new Runnable() {

              @Override
              public void run() {
                String pname = "";
                try {
                  for (Plugin p : getServer().getPluginManager().getPlugins()) {
                    pname = p.toString();
                    p.getLogger().setFilter(masterFilter);
                  }
                  getServer().getLogger().setFilter(masterFilter);
                  Bukkit.getLogger().setFilter(masterFilter);
                  Logger.getLogger("Minecraft").setFilter(masterFilter);
                } catch (Exception e) {
                  log(
                      Level.WARNING,
                      "Cannot load filter in '"
                          + pname
                          + "'. The logs of this plugin will not be filtered");
                }
              }
            },
            1);
  }