Beispiel #1
0
  @Override
  public void enable() {

    plugin.registerCommands(CircuitCommands.class);

    plugin.createDefaultConfiguration(
        new File(plugin.getDataFolder(), "ic-config.yml"), "ic-config.yml", false);
    icConfiguration =
        new YAMLICConfiguration(
            new YAMLProcessor(
                new File(plugin.getDataFolder(), "ic-config.yml"), true, YAMLFormat.EXTENDED),
            plugin.getLogger());

    manager = new MechanicManager();
    plugin.registerManager(manager, true, true, true, false);

    midiFolder = new File(plugin.getDataFolder(), "midi/");
    new File(getMidiFolder(), "playlists").mkdirs();

    romFolder = new File(plugin.getDataFolder(), "rom/");

    fireworkFolder = new File(plugin.getDataFolder(), "fireworks/");
    getFireworkFolder();

    registerMechanics();

    try {
      icConfiguration.load();
    } catch (Throwable e) {
      e.printStackTrace();
    }
  }
Beispiel #2
0
  /**
   * Used for the /ic list command.
   *
   * @param p
   * @return
   */
  public String[] generateICText(Player p, String search, char[] parameters) {

    ArrayList<String> icNameList = new ArrayList<String>();
    icNameList.addAll(ICManager.registered.keySet());

    Collections.sort(icNameList);

    ArrayList<String> strings = new ArrayList<String>();
    boolean col = true;
    for (String ic : icNameList) {
      try {
        thisIC:
        {
          RegisteredICFactory ric = ICManager.registered.get(ic);
          IC tic = ric.getFactory().create(null);
          if (search != null
              && !tic.getTitle().toLowerCase().contains(search.toLowerCase())
              && !ric.getId().toLowerCase().contains(search.toLowerCase())) continue;
          if (parameters != null) {
            for (char c : parameters) {
              if (c == 'r' && !(ric.getFactory() instanceof RestrictedIC)) break thisIC;
              else if (c == 's' && ric.getFactory() instanceof RestrictedIC) break thisIC;
              else if (c == 'b'
                  && !ric.getFactory().getClass().getPackage().getName().endsWith("blocks"))
                break thisIC;
              else if (c == 'i'
                  && !ric.getFactory().getClass().getPackage().getName().endsWith("items"))
                break thisIC;
              else if (c == 'e'
                  && !ric.getFactory().getClass().getPackage().getName().endsWith("entity"))
                break thisIC;
              else if (c == 'w'
                  && !ric.getFactory().getClass().getPackage().getName().endsWith("weather"))
                break thisIC;
              else if (c == 'l'
                  && !ric.getFactory().getClass().getPackage().getName().endsWith("logic"))
                break thisIC;
              else if (c == 'm'
                  && !ric.getFactory().getClass().getPackage().getName().endsWith("miscellaneous"))
                break thisIC;
              else if (c == 'c'
                  && !ric.getFactory().getClass().getPackage().getName().endsWith("sensors"))
                break thisIC;
            }
          }
          col = !col;
          ChatColor colour = col ? ChatColor.YELLOW : ChatColor.GOLD;

          if (!ICMechanicFactory.checkPermissionsBoolean(
              CraftBookPlugin.inst().wrapPlayer(p), ric.getFactory(), ic.toLowerCase())) {
            colour = col ? ChatColor.RED : ChatColor.DARK_RED;
          }
          strings.add(
              colour
                  + tic.getTitle()
                  + " ("
                  + ric.getId()
                  + ")"
                  + ": "
                  + (tic instanceof SelfTriggeredIC ? "ST " : "T ")
                  + (ric.getFactory() instanceof RestrictedIC ? ChatColor.DARK_RED + "R " : ""));
        }
      } catch (Throwable e) {
        plugin.getLogger().warning("An error occurred generating the docs for IC: " + ic + ".");
        plugin.getLogger().warning("Please report this error on: http://youtrack.sk89q.com/.");
      }
    }

    return strings.toArray(new String[strings.size()]);
  }