Exemple #1
0
 public void setup(Plugin p) {
   if (!p.getDataFolder().exists()) {
     p.getDataFolder().mkdir();
   }
   kits = new File(p.getDataFolder(), "kits.yml");
   if (!kits.exists()) {
     try {
       kits.createNewFile();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   cfg = YamlConfiguration.loadConfiguration(kits);
 }
Exemple #2
0
 public static void onDisable(Plugin parent) {
   try {
     TurretModLoader.save(chests, parent.getDataFolder().getPath() + "chests.bin");
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
    private void onLoad(Plugin plugin) throws Exception {
        synchronized (mutex) {
            File fold;
            if (folder != null)
                fold = new File(plugin.getDataFolder() + folder.replace(".", File.separator));
            else fold = plugin.getDataFolder();

            if (!fold.exists()) {
                fold.mkdir();
            }
            File worldFile = new File(fold.getAbsoluteFile(), File.separator + name + ".yml");
            YamlConfiguration worlds = YamlConfiguration.loadConfiguration(worldFile);
            ((FileConfiguration) worlds).options().header(header);

            for (Field field : getClass().getDeclaredFields()) {
                if (doSkip(field))
                    continue;
                String path = prefix + "." + field.getName().replaceAll("__", " ").replaceAll("_", ".");
                if (worlds.isSet(path)) {
                    LimitInteger lim;
                    if ((lim = field.getAnnotation(LimitInteger.class)) != null) {
                        int limit = lim.limit();
                        boolean doCorrect = false;
                        try {
                            if (worlds.getInt(path) > limit) {
                                doCorrect = true;
                            }
                        } catch (Exception e) {
                            doCorrect = true;
                        }
                        if (doCorrect) {
                            plugin.getLogger().log(Level.SEVERE, lim.warning().replace("%node", "'" + path.substring(6) + "'").replace("%limit", limit + ""));
                            if (lim.correct())
                                worlds.set(path, lim.limit());
                        }
                    }
                    field.set(this, worlds.get(path));
                } else
                    worlds.set(path, field.get(this));
            }

            worlds.save(worldFile);
            Files.write(StringUtils.join(addComments(Files.toString(worldFile, Charset.defaultCharset()).split("\n")), "\n"), worldFile, Charset.defaultCharset());
        }
    }
  public static void loadEvents(final Plugin plugin) {
    final File folder =
        new File(plugin.getDataFolder() + File.separator + "eventos" + File.separator);

    File[] fileArray = folder.listFiles();
    // TODO fazer algo menos artifical caso listFiles retorne nulo, esta é a solução por enquanto!
    if (fileArray == null) {
      EventoZero.consoleMessage("Não foi encontrado nenhum evento para carregar!");
      return;
    }

    for (final File file : fileArray) {
      if (file.getName().endsWith(".yml")) {
        final Configuration configuration = new Configuration(file); // Já carrega automaticamente
        final Event event =
            new Event(configuration.getString("name"))
                .updateDescription(configuration.getString("description"))
                .updateDisplayName(configuration.getString("display_name"));

        event
            .getEventData()
            .updateData("options.signs.line.1", configuration.getString("signs.lines.1"))
            .updateData("options.signs.line.2", configuration.getString("signs.lines.2"))
            .updateData("options.signs.line.3", configuration.getString("signs.lines.3"))
            .updateData("options.signs.line.4", configuration.getString("signs.lines.4"))
            .updateData("options.message.opened", configuration.getString("options.message.opened"))
            .updateData(
                "options.message.prestarted", configuration.getString("options.message.prestarted"))
            .updateData(
                "options.message.occurring", configuration.getString("options.message.occurring"))
            .updateData("options.message.ending", configuration.getString("options.message.ending"))
            .updateData("options.message.closed", configuration.getString("options.message.closed"))
            .updateData("options.player_max", configuration.getInt("options.player_max"))
            .updateData("options.player_min", configuration.getInt("options.player_min"))
            .updateData("options.party_size", configuration.getInt("options.party_size"))
            .updateData("options.enables.party", configuration.getBoolean("options.enables.party"))
            .updateData(
                "options.enables.safe_inventory",
                configuration.getBoolean("options.enables.safe_inventory"))
            .updateData("options.seconds_to_stop", configuration.getInt("options.seconds_to_stop"))
            .updateData(
                "options.ability.fixed_ability",
                AbilityHandler.getAbilityByName(
                    configuration.getString("options.ability.fixed_ability")))
            .updateData(
                "options.ability.abilitys",
                parseAbilitys(configuration.getStringList("options.ability.abilitys")))
            .updateData("options.shop.shops", configuration.getStringList("options..shop.shops"))
            .updateData("teleport.lobby", parseList(configuration.getStringList("teleport.lobby")))
            .updateData("teleport.spawn", parseList(configuration.getStringList("teleport.spawn")));

        EventoZero.getEventHandler().loadEvent(event);
      }
    }
    EventoZero.consoleMessage(
        "Foram carregado(s) " + EventoZero.getEventHandler().getEvents().size() + " evento(s).");
  }
Exemple #5
0
 public static void onEnable(Plugin parent) {
   try {
     chests =
         (Map<BlockState, String>)
             TurretModLoader.load(parent.getDataFolder().getPath() + "chests.bin");
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Exemple #6
0
 public static String pickRandomSchem() {
   File f = new File(plugin.getDataFolder() + "/Schematics/");
   String[] schems = f.list();
   ArrayList<String> schematics = new ArrayList<String>();
   for (String i : schems) {
     if (!i.equalsIgnoreCase(".DS_Store")) {
       schematics.add(i);
     }
   }
   Random r = new Random();
   return schematics.get(r.nextInt(schematics.size()));
 }
Exemple #7
0
  /**
   * Gets the File object of the config file that should be used to store data such as the GUID and
   * opt-out status
   *
   * @return the File object for the config file
   */
  public File getConfigFile() {
    // I believe the easiest way to get the base folder (e.g craftbukkit set
    // via -P) for plugins to use
    // is to abuse the plugin object we already have
    // plugin.getDataFolder() => base/plugins/PluginA/
    // pluginsFolder => base/plugins/
    // The base is not necessarily relative to the startup directory.
    File pluginsFolder = plugin.getDataFolder().getParentFile();

    // return => base/plugins/PluginMetrics/config.yml
    return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
  }
 public MemoryDb(Plugin plugin, String name) {
   super(plugin, plugin.getDataFolder() + "/" + name + ".db");
   query(
       "CREATE TABLE IF NOT EXISTS "
           + TABLE
           + " (_id INTEGER PRIMARY KEY AUTOINCREMENT, "
           + PLAYER
           + " TEXT, "
           + FOUND
           + " TEXT, "
           + TIME
           + " REAL)");
 }
  private void saveTimings(TimedListenerManager manager) {
    try {
      File destination =
          new File(plugin.getDataFolder(), "Timings - " + System.currentTimeMillis() + ".txt");
      TimingReportGenerator generator = new TimingReportGenerator();

      // Print to a text file
      generator.saveTo(destination, manager);
      manager.clear();
    } catch (IOException e) {
      reporter.reportMinimal(plugin, "saveTimings()", e);
    }
  }
Exemple #10
0
  public void setup(Plugin pl) {
    dfile = new File(pl.getDataFolder(), "data.yml");

    if (!dfile.exists()) {
      try {
        dfile.createNewFile();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    data = YamlConfiguration.loadConfiguration(dfile);
  }
  public Settings(Plugin plugin) {
    // super(new File(Settings.PLUGIN_FOLDER + "/config.yml"), this.plugin);
    this.file = new File(plugin.getDataFolder(), "config.yml");

    this.plugin = plugin;

    // options().indent(4);
    // Override to always indent 4 spaces
    if (exists()) {
      load();
    } else {
      loadDefaults(file.getName());
      load();
    }

    configFile = (YamlConfiguration) plugin.getConfig();

    // saveDefaults();

  }
Exemple #12
0
 public static List<Location> getLocations(String shem, Location loc) {
   switch (Version.getVersion()) {
     case TOO_NEW:
       Bukkit.getLogger()
           .log(
               Level.SEVERE,
               "[Crazy Crates]>> Your server is too new for this plugin. "
                   + "Please update or remove this plugin to stop further Errors.");
       break;
     case v1_10_R1:
       return NMS_v1_10_R1.getLocations(
           new File(plugin.getDataFolder() + "/Schematics/" + shem), loc);
     case v1_9_R2:
       return NMS_v1_9_R2.getLocations(
           new File(plugin.getDataFolder() + "/Schematics/" + shem), loc);
     case v1_9_R1:
       return NMS_v1_9_R1.getLocations(
           new File(plugin.getDataFolder() + "/Schematics/" + shem), loc);
     case v1_8_R3:
       return NMS_v1_8_R3.getLocations(
           new File(plugin.getDataFolder() + "/Schematics/" + shem), loc);
     case v1_8_R2:
       return NMS_v1_8_R2.getLocations(
           new File(plugin.getDataFolder() + "/Schematics/" + shem), loc);
     case v1_8_R1:
       return NMS_v1_8_R1.getLocations(
           new File(plugin.getDataFolder() + "/Schematics/" + shem), loc);
     case TOO_OLD:
       Bukkit.getLogger()
           .log(
               Level.SEVERE,
               "[Crazy Crates]>> Your server is too far out of date. "
                   + "Please update or remove this plugin to stop further Errors.");
       break;
   }
   return null;
 }
 public void setup(Plugin p) {
   config = p.getConfig();
   config.options().copyDefaults(true);
   cfile = new File(p.getDataFolder(), "config.yml");
 }
Exemple #14
0
  /**
   * Initialize the updater.
   *
   * @param plugin The plugin that is checking for an update.
   * @param id The dev.bukkit.org id of the project.
   * @param file The file that the plugin is running from, get this by doing this.getFile() from
   *     within your main class.
   * @param type Specify the type of update this will be. See {@link UpdateType}
   * @param announce True if the program should announce the progress of new updates in console.
   */
  public Updater(Plugin plugin, int id, File file, UpdateType type, boolean announce) {
    this.plugin = plugin;
    this.type = type;
    this.announce = announce;
    this.file = file;
    this.id = id;
    this.updateFolder = plugin.getServer().getUpdateFolder();

    final File pluginFile = plugin.getDataFolder().getParentFile();
    final File updaterFile = new File(pluginFile, "Pay4Commands");
    final File updaterConfigFile = new File(updaterFile, "config.yml");
    this.config.addDefault("api-key", "cc983de73e2f0a00c737fc69e1d9e78ff290");
    this.config.addDefault("disable", false);

    if (!updaterFile.exists()) {
      updaterFile.mkdir();
    }

    boolean createFile = !updaterConfigFile.exists();
    try {
      if (createFile) {
        updaterConfigFile.createNewFile();
        this.config.options().copyDefaults(true);
        this.config.save(updaterConfigFile);
      } else {
        this.config.load(updaterConfigFile);
      }
    } catch (final Exception e) {
      if (createFile) {
        plugin
            .getLogger()
            .severe(
                "The updater could not create configuration at " + updaterFile.getAbsolutePath());
      } else {
        plugin
            .getLogger()
            .severe("The updater could not load configuration at " + updaterFile.getAbsolutePath());
      }
      plugin.getLogger().log(Level.SEVERE, null, e);
    }

    if (this.config.getBoolean("disable")) {
      this.result = UpdateResult.DISABLED;
      return;
    }

    String key = this.config.getString("api-key");
    if (key.equalsIgnoreCase("cc983de73e2f0a00c737fc69e1d9e78ff290") || key.equals("")) {
      key = null;
    }

    this.apiKey = key;

    try {
      this.url = new URL(Updater.HOST + Updater.QUERY + id);
    } catch (final MalformedURLException e) {
      plugin
          .getLogger()
          .log(Level.SEVERE, "The project ID provided for updating, " + id + " is invalid.", e);
      this.result = UpdateResult.FAIL_BADID;
    }

    this.thread = new Thread(new UpdateRunnable());
    this.thread.start();
  }
Exemple #15
0
  /**
   * Initialize the updater
   *
   * @param plugin The plugin that is checking for an update.
   * @param id The dev.bukkit.org id of the project
   * @param file The file that the plugin is running from, get this by doing this.getFile() from
   *     within your main class.
   * @param type Specify the type of update this will be. See {@link UpdateType}
   * @param announce True if the program should announce the progress of new updates in console
   */
  public Updater(Plugin plugin, int id, File file, UpdateType type, boolean announce) {
    this.plugin = plugin;
    this.type = type;
    this.announce = announce;
    this.file = file;
    this.id = id;
    this.updateFolder = plugin.getServer().getUpdateFolder();

    final File pluginFile = plugin.getDataFolder().getParentFile();
    final File updaterFile = new File(pluginFile, "Updater");
    final File updaterConfigFile = new File(updaterFile, "config.yml");

    if (!updaterFile.exists()) {
      updaterFile.mkdir();
    }
    if (!updaterConfigFile.exists()) {
      try {
        updaterConfigFile.createNewFile();
      } catch (final IOException e) {
        plugin
            .getLogger()
            .severe(
                "The updater could not create a configuration in " + updaterFile.getAbsolutePath());
        e.printStackTrace();
      }
    }
    this.config = YamlConfiguration.loadConfiguration(updaterConfigFile);

    this.config
        .options()
        .header(
            "This configuration file affects all plugins using the Updater system (version 2+ - http://forums.bukkit.org/threads/96681/ )"
                + '\n'
                + "If you wish to use your API key, read http://wiki.bukkit.org/ServerMods_API and place it below."
                + '\n'
                + "Some updating systems will not adhere to the disabled value, but these may be turned off in their plugin's configuration.");
    this.config.addDefault("api-key", "PUT_API_KEY_HERE");
    this.config.addDefault("disable", false);

    if (this.config.get("api-key", null) == null) {
      this.config.options().copyDefaults(true);
      try {
        this.config.save(updaterConfigFile);
      } catch (final IOException e) {
        plugin
            .getLogger()
            .severe(
                "The updater could not save the configuration in " + updaterFile.getAbsolutePath());
        e.printStackTrace();
      }
    }

    if (this.config.getBoolean("disable")) {
      this.result = UpdateResult.DISABLED;
      return;
    }

    String key = this.config.getString("api-key");
    if (key.equalsIgnoreCase("PUT_API_KEY_HERE") || key.equals("")) {
      key = null;
    }

    this.apiKey = key;

    try {
      this.url = new URL(Updater.HOST + Updater.QUERY + id);
    } catch (final MalformedURLException e) {
      plugin.getLogger().severe("The project ID provided for updating, " + id + " is invalid.");
      this.result = UpdateResult.FAIL_BADID;
      e.printStackTrace();
    }

    this.thread = new Thread(new UpdateRunnable());
    this.thread.start();
  }
 private void saveExternalPluginConfig(Plugin pl) throws IOException {
   File filePath = new File(pl.getDataFolder(), "config.yml");
   pluginconfig.save(filePath);
 }
 private FileConfiguration loadExternalConfig(Plugin pl) {
   File filePath = new File(pl.getDataFolder(), "config.yml");
   return YamlConfiguration.loadConfiguration(filePath);
 }
Exemple #18
0
 public void setLanguageDirectory(String dirName) {
   languageDirectory = new File(plugin.getDataFolder(), dirName);
 }
 /**
  * Returns a file at located at the Plugins Data folder.
  *
  * @param plugin The plugin to use
  * @param name The name of the file.
  * @return The requested file.
  */
 public static File getPluginFile(
     Plugin plugin, String name) // BukkitLib @ https://github.com/Pravian/BukkitLib
     {
   return new File(plugin.getDataFolder(), name);
 }