Esempio n. 1
0
  private void load() {
    for (String key : keys) {
      if (config.getProperty(key) == null) config.setProperty(key, defaults.get(key));
      strings.put(key, config.getString(key).replace("&", "\u00a7"));
    }

    // clear defaults to free memory
    defaults.clear();
  }
  private boolean migratePortals(String name, File oldFolder, File newFolder) {
    Configuration newConfig = new Configuration(new File(newFolder, "portals.yml"));
    MultiversePortals.staticLog(Level.INFO, "Trying to migrate Portals.yml...");
    Configuration oldConfig = new Configuration(new File(oldFolder, "Portals.yml"));
    oldConfig.load();
    List<String> keys = oldConfig.getKeys("portals");
    if (keys == null) {
      MultiversePortals.staticLog(Level.SEVERE, "Migration FAILURE!");
      MultiversePortals.staticLog(Level.SEVERE, "Old Folder Location: " + oldFolder);
      MultiversePortals.staticLog(Level.SEVERE, "New Folder Location: " + newFolder);
      MultiversePortals.staticLog(Level.SEVERE, "Old Config Dump: " + oldConfig.getAll());
      return false;
    }
    for (String key : keys) {
      // Since portal names are lowercase, no reason not to do that here.
      String lowerkey = key.toLowerCase();
      if (newConfig.getProperty(lowerkey) != null) {
        MultiversePortals.staticLog(Level.SEVERE, "Portals are now case-insensitive!");
        MultiversePortals.staticLog(Level.SEVERE, "Found at least 2 portals named: " + lowerkey);
        continue;
      }

      newConfig.setProperty(
          "portals." + lowerkey + ".entryfee.amount",
          oldConfig.getDouble("portals." + key + ".price", 0.0));
      newConfig.setProperty("portals." + lowerkey + ".entryfee.amount", -1);
      newConfig.setProperty(
          "portals." + lowerkey + ".destination",
          transformDestination(
              oldConfig.getString("portals." + key + ".destlocation", "i:Invalid")));
      newConfig.setProperty(
          "portals." + lowerkey + ".world", oldConfig.getProperty("portals." + key + ".world"));
      newConfig.setProperty(
          "portals." + lowerkey + ".location",
          oldConfig.getProperty("portals." + key + ".location"));
      newConfig.setProperty(
          "portals." + lowerkey + ".owner", oldConfig.getProperty("portals." + key + ".owner"));
    }
    newConfig.save();
    MultiversePortals.staticLog(Level.INFO, "Migration SUCCESS!");
    return true;
  }
Esempio n. 3
0
 private void updateKeys() {
   String fromKey, toKey, holder;
   for (String[] update : keyUpdates) {
     fromKey = update[0];
     if (config.getProperty(fromKey) != null) {
       toKey = update[1];
       holder = config.getString(fromKey);
       config.removeProperty(fromKey);
       if (!toKey.equals("")) config.setProperty(toKey, holder);
     }
   }
 }
Esempio n. 4
0
  @Override
  public void onEnable() {
    pdf = this.getDescription();
    // Begin config code
    if (!new File(getDataFolder(), "config.yml").exists()) {
      try {
        getDataFolder().mkdir();
        new File(getDataFolder(), "config.yml").createNewFile();
      } catch (Exception e) {
        e.printStackTrace();
        System.out.println(pref + "Error making config.yml?!");
        getServer().getPluginManager().disablePlugin(this); // Cleanup
        return;
      }
    }
    cfg = this.getConfiguration(); // Get config

    if (cfg.getKeys().isEmpty()) { // Config hasn't been made
      System.out.println(pref + "config.yml not found, making with default values");
      cfg.setProperty("RealDrops.enabled", false);
      cfg.setProperty("Permissions.enabled", true);
      cfg.setProperty("MobTarget.enabled", true);
      cfg.setProperty("DisableItemPickup", true);
      for (String mobtype : MobType.types) {
        cfg.setHeader(
            "#Setting a mobtype to false will not allow a player to disguise as that type");
        cfg.setProperty("Blacklist." + mobtype, true); // Just making
      }
      cfg.save();
    }
    if (cfg.getProperty("MobTarget.enabled") == null
        || cfg.getProperty("DisableItemPickup.enabled") == null) {
      cfg.setProperty("MobTarget.enabled", true);
      cfg.setProperty("DisableItemPickup.enabled", true);
      cfg.save();
    }
    if (cfg.getProperty("Blacklist.enderman") == null) {
      cfg.setProperty("Blacklist.enderman", true);
      cfg.setProperty("Blacklist.silverfish", true);
      cfg.setProperty("Blacklist.cavespider", true);
    }

    cfg.save();
    perm = cfg.getBoolean("Permissions.enabled", true);

    PluginManager pm = getServer().getPluginManager();
    this.getCommand("md").setExecutor(new MDCommand(this));

    pm.registerEvents(playerlistener, this);
    pm.registerEvents(entitylistener, this);

    getServer().getScheduler().scheduleSyncRepeatingTask(this, new DisguiseTask(this), 1200, 1200);

    System.out.println(
        "["
            + pdf.getName()
            + "]"
            + " by "
            + pdf.getAuthors().get(0)
            + " version "
            + pdf.getVersion()
            + " enabled.");
  }
Esempio n. 5
0
  @Override
  public void onEnable() {
    pdf = this.getDescription();
    // Begin config code
    if (!new File(getDataFolder(), "config.yml").exists()) {
      try {
        getDataFolder().mkdir();
        new File(getDataFolder(), "config.yml").createNewFile();
      } catch (Exception e) {
        e.printStackTrace();
        System.out.println(pref + "Error making config.yml?!");
        getServer().getPluginManager().disablePlugin(this); // Cleanup
        return;
      }
    }
    cfg = this.getConfiguration(); // Get config

    if (cfg.getKeys().isEmpty()) { // Config hasn't been made
      System.out.println(pref + "config.yml not found, making with default values");
      cfg.setProperty("RealDrops.enabled", false);
      cfg.setProperty("Permissions.enabled", true);
      cfg.setProperty("MobTarget.enabled", true);
      cfg.setProperty("DisableItemPickup", true);
      for (String mobtype : MobIdEnum.map.keySet()) {
        cfg.setHeader(
            "#Setting a mobtype to false will not allow a player to disguise as that type");
        cfg.setProperty("Blacklist." + mobtype, true); // Just making
      }
      cfg.save();
    }
    if (cfg.getProperty("MobTarget.enabled") == null
        || cfg.getProperty("DisableItemPickup.enabled") == null) {
      cfg.setProperty("MobTarget.enabled", true);
      cfg.setProperty("DisableItemPickup.enabled", true);
      cfg.save();
    }
    if (cfg.getProperty("Blacklist.enderman") == null) {
      cfg.setProperty("Blacklist.enderman", true);
      cfg.setProperty("Blacklist.silverfish", true);
      cfg.setProperty("Blacklist.cavespider", true);
    }

    cfg.save();
    perm = cfg.getBoolean("Permissions.enabled", true);

    PluginManager pm = getServer().getPluginManager();
    this.getCommand("md").setExecutor(new MDCommand(this));
    pm.registerEvent(Event.Type.PLAYER_JOIN, playerlistener, Priority.Lowest, this);
    pm.registerEvent(Event.Type.PLAYER_QUIT, playerlistener, Priority.Normal, this);
    pm.registerEvent(Event.Type.PLAYER_RESPAWN, playerlistener, Priority.Normal, this);
    pm.registerEvent(Event.Type.PLAYER_TELEPORT, playerlistener, Priority.Monitor, this);
    pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM, playerlistener, Priority.Monitor, this);
    pm.registerEvent(Event.Type.ENTITY_DEATH, entitylistener, Priority.Normal, this);
    pm.registerEvent(Event.Type.ENTITY_TARGET, entitylistener, Priority.Normal, this);
    pm.registerEvent(Event.Type.PLAYER_ANIMATION, playerlistener, Priority.Normal, this);

    // new MDPlayerListener(this), Priority.Normal, this);
    getServer().getScheduler().scheduleSyncRepeatingTask(this, new DisguiseTask(this), 1200, 1200);
    // Register packet listeners
    // org.getspout.spoutapi.packet.listener.Listeners.addListener(17, packetlistener);
    // org.getspout.spoutapi.packet.listener.Listeners.addListener(18, packetlistener);
    System.out.println(
        "["
            + pdf.getName()
            + "]"
            + " by "
            + pdf.getAuthors().get(0)
            + " version "
            + pdf.getVersion()
            + " enabled.");
  }
Esempio n. 6
0
 @SuppressWarnings("unchecked")
 public List<String> readStringList(String root) {
   Configuration config = load();
   return ((List<String>) config.getProperty(root));
 }
Esempio n. 7
0
 private void removeKeys() {
   for (String key : keyRemovals) {
     if (config.getProperty(key) != null) config.removeProperty(key);
   }
 }