Exemple #1
0
 @SuppressWarnings("deprecation")
 public ConfigFile(JavaPlugin plugin, String fileName) {
   if (plugin == null) throw new IllegalArgumentException("plugin cannot be null");
   if (!plugin.isInitialized()) throw new IllegalArgumentException("plugin must be initialized");
   this.plugin = plugin;
   this.fileName = fileName;
   File dataFolder = plugin.getDataFolder();
   if (dataFolder == null) throw new IllegalStateException();
   this.configFile = new File(plugin.getDataFolder(), fileName);
 }
 public FlatDatabase(
     final Class<S> clazz,
     final String[] defaultColumnNames,
     final JavaPlugin plugin,
     final String path) {
   super(DatabaseType.FLAT, clazz, defaultColumnNames);
   this.plugin = plugin;
   this.filePath = path;
   this.file = new File(plugin.getDataFolder(), filePath);
   this.backupFile = new File(plugin.getDataFolder().getPath(), filePath + "_old");
 }
 public FlatDatabase(
     final Class<S> clazz,
     final String[] defaultColumnNames,
     final String defaultPath,
     final JavaPlugin plugin,
     final ConfigurationSection config) {
   super(DatabaseType.FLAT, clazz, defaultColumnNames);
   this.plugin = plugin;
   this.filePath = config == null ? defaultPath : config.getString("FLAT.filePath", defaultPath);
   this.file = new File(plugin.getDataFolder().getPath(), filePath);
   this.backupFile = new File(plugin.getDataFolder().getPath(), filePath + "_old");
 }
Exemple #4
0
  @SuppressWarnings("ConstantConditions")
  public static ConfigImpl loadConfig(
      final ConfigFile config,
      final JavaPlugin plugin,
      final ClassLoader classLoader,
      final File dataFolder) {
    // Plugin or classloader must be specified
    Validate.isTrue(plugin != null || classLoader != null, "Plugin or classloader can't be null");

    final ConfigImpl cached;
    if ((cached = ConfigImpl.cache.get(config)) != null) {
      cached.reload(); // Make sure the config is up-to-date
      return cached;
    }

    final File file =
        new File(
            dataFolder != null ? dataFolder : (plugin != null ? plugin.getDataFolder() : null),
            config.getFileName());

    if (!file.exists()) // Copy the config from jar file
    {
      final InputStream inJarFile =
          classLoader != null
              ? classLoader.getResourceAsStream(config.getFileName())
              : plugin.getResource(config.getFileName());

      IOUtils.saveToFile(inJarFile, file);
    }

    final ConfigImpl configuration =
        new ConfigImpl(YamlConfiguration.loadConfiguration(file), file, config);
    ConfigImpl.cache.put(config, configuration);
    return configuration;
  }
  public void reloadLocalizedStrings() {
    File localizedStringsFile =
        new File(plugin.getDataFolder().getPath() + "/localization/" + languageFile);
    if (this.isDefault()) {
      if (defaultLocalizedStrings == null) {
        localizedStrings = defaultLocalizedStrings;
      }
      return;
    } else if (!localizedStringsFile.exists()) {

      CivLog.warning(
          "Configuration file:"
              + languageFile
              + " was missing. You must create this file in plugins/Civcraft/localization/");
      CivLog.warning("Using default_lang.yml");
      this.setLanguageFile("");
      return;
    }
    localizedStrings = YamlConfiguration.loadConfiguration(localizedStringsFile);

    CivLog.info("Loading Configuration file:" + languageFile);
    // read the config.yml into memory
    YamlConfiguration cfg = new YamlConfiguration();
    try {
      cfg.load(localizedStringsFile);
    } catch (FileNotFoundException e1) {
      e1.printStackTrace();
    } catch (IOException e1) {
      e1.printStackTrace();
    } catch (InvalidConfigurationException e1) {
      e1.printStackTrace();
    }
    localizedStrings.setDefaults(cfg);
  }
  public void reloadDefaultLocalizedStrings() {
    String defaultLanguageFile = "default_lang.yml";
    File defaultLocalizedStringsFile =
        new File(plugin.getDataFolder().getPath() + "/localization/" + defaultLanguageFile);
    CivLog.warning(
        "Configuration file:" + defaultLanguageFile + " in use. Updating to disk from Jar.");
    try {
      CivSettings.streamResourceToDisk("/localization/" + defaultLanguageFile);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    defaultLocalizedStrings = YamlConfiguration.loadConfiguration(defaultLocalizedStringsFile);

    CivLog.info("Loading Configuration file:" + defaultLanguageFile);
    // read the config.yml into memory
    YamlConfiguration cfg = new YamlConfiguration();
    try {
      cfg.load(defaultLocalizedStringsFile);
    } catch (FileNotFoundException e1) {
      e1.printStackTrace();
    } catch (IOException e1) {
      e1.printStackTrace();
    } catch (InvalidConfigurationException e1) {
      e1.printStackTrace();
    }
    defaultLocalizedStrings.setDefaults(cfg);
  }
  public void setupConfig() throws IOException {
    configFile = new File(plugin.getDataFolder(), fileName);

    if (!configFile.exists()) {
      configFile.createNewFile();
      copy(plugin.getResource(fileName), configFile);
    }
  }
Exemple #8
0
 private void addPlayer(Player player, boolean serverLoad) {
   OnlinePlayer op = new OnlinePlayer(player, serverLoad);
   this.getServer().getPluginManager().registerEvents(op, this);
   players.add(op);
   if (!serverLoad) {
     UUID uuid = lastKnownAlias(player.getName());
     if (uuid == null) {
       addAlias(player.getName(), player.getUniqueId());
     } else if (!player.getUniqueId().equals(uuid)) {
       File f = new File(instance.getDataFolder(), "player" + File.separator + uuid + ".yml");
       f.renameTo(
           new File(
               instance.getDataFolder(),
               "player" + File.separator + player.getUniqueId() + ".yml"));
       addAlias(player.getName(), player.getUniqueId());
     }
   }
 }
Exemple #9
0
  private String replaceDatabaseString(String input) {
    input =
        input.replaceAll(
            "\\{DIR\\}", javaPlugin.getDataFolder().getPath().replaceAll("\\\\", "/") + "/");
    input =
        input.replaceAll(
            "\\{NAME\\}", javaPlugin.getDescription().getName().replaceAll("[^\\w_-]", ""));

    return input;
  }
 /*
  * Сохранение сообщений в файл
  */
 public void SaveMSG() {
   String[] keys = this.msglist.split(",");
   try {
     File f = new File(plg.getDataFolder() + File.separator + this.language + ".lng");
     if (!f.exists()) f.createNewFile();
     YamlConfiguration cfg = new YamlConfiguration();
     for (int i = 0; i < keys.length; i++) cfg.set(keys[i], msg.get(keys[i]));
     cfg.save(f);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  /** {@inheritDoc} */
  @Override
  public void loadLocale(Locale l) throws NoSuchLocalizationException {
    messages.remove(l);

    InputStream resstream = null;
    InputStream filestream = null;

    try {
      filestream = new FileInputStream(new File(plugin.getDataFolder(), l.getLanguage() + ".yml"));
    } catch (FileNotFoundException e) {
    }

    try {
      resstream =
          plugin.getResource(
              new StringBuilder(LOCALIZATION_FOLDER_NAME)
                  .append("/")
                  .append(l.getLanguage())
                  .append(".yml")
                  .toString());
    } catch (Exception e) {
    }

    if ((resstream == null) && (filestream == null)) throw new NoSuchLocalizationException(l);

    messages.put(l, new HashMap<Message, List<String>>(Message.values().length));

    FileConfiguration resconfig =
        (resstream == null) ? null : YamlConfiguration.loadConfiguration(resstream);
    FileConfiguration fileconfig =
        (filestream == null) ? null : YamlConfiguration.loadConfiguration(filestream);
    for (Message m : Message.values()) {
      List<String> values = m.getDefault();

      if (resconfig != null) {
        if (resconfig.isList(m.toString())) {
          values = resconfig.getStringList(m.toString());
        } else {
          values.add(resconfig.getString(m.toString(), values.get(0)));
        }
      }
      if (fileconfig != null) {
        if (fileconfig.isList(m.toString())) {
          values = fileconfig.getStringList(m.toString());
        } else {
          values.add(fileconfig.getString(m.toString(), values.get(0)));
        }
      }

      messages.get(l).put(m, values);
    }
  }
  // Load the conf file and search for configs in the jar memory
  public void ReloadConfig() {
    if (file == null) {
      file = new File(plugin.getDataFolder(), fname);
    }
    conf = YamlConfiguration.loadConfiguration(file);

    // Look for defaults in the jar
    InputStream isDefaults = plugin.getResource(fname);
    if (isDefaults != null) {
      YamlConfiguration confDefault = YamlConfiguration.loadConfiguration(isDefaults);
      conf.setDefaults(confDefault);
    }
  }
 /*
  *  Инициализация файла с сообщениями
  */
 public void InitMsgFile() {
   try {
     lng = new YamlConfiguration();
     File f = new File(plg.getDataFolder() + File.separator + this.language + ".lng");
     if (f.exists()) lng.load(f);
     else {
       InputStream is = plg.getClass().getResourceAsStream("/language/" + this.language + ".lng");
       if (is != null) lng.load(is);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemple #14
0
  public void reloadConfig() {
    if (configFile == null) {
      File dataFolder = plugin.getDataFolder();
      if (dataFolder == null) throw new IllegalStateException();
      configFile = new File(dataFolder, fileName);
    }
    fileConfiguration = YamlConfiguration.loadConfiguration(configFile);

    // Look for defaults in the jar
    InputStream defConfigStream = plugin.getResource(fileName);
    if (defConfigStream != null) {
      YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
      fileConfiguration.setDefaults(defConfig);
    }
  }
 public VersionUpdater(JavaPlugin instance) {
   FileConfiguration fconf = instance.getConfig();
   List<String> messages = fconf.getStringList("Messages");
   int interval = fconf.getInt("Interval");
   boolean inSec = fconf.getBoolean("InSeconds");
   boolean debug = fconf.getBoolean("Debug");
   File configFile = new File(instance.getDataFolder(), "config.yml");
   configFile.delete();
   instance.saveDefaultConfig();
   instance.reloadConfig();
   fconf = instance.getConfig();
   fconf.set("Interval", interval);
   fconf.set("InSeconds", inSec);
   fconf.set("Debug", debug);
   fconf.set("Messages", messages);
   instance.saveConfig();
 }
  public SimpleYamlConfiguration(
      final JavaPlugin plugin,
      final String fileName,
      final LinkedHashMap<String, Object> configDefaults,
      final String name) {
    /*
     * accepts null as configDefaults -> check for resource and copies it if
     * found, makes an empty config if nothing is found
     */
    final String folderPath = plugin.getDataFolder().getAbsolutePath() + File.separator;
    file = new File(folderPath + fileName);

    if (file.exists() == false) {
      if (configDefaults == null) {
        if (plugin.getResource(fileName) != null) {
          plugin.saveResource(fileName, false);
          plugin.getLogger().info("New " + name + " file copied from jar");
          try {
            this.load(file);
          } catch (final Exception e) {
            e.printStackTrace();
          }
        }
      } else {
        for (final String key : configDefaults.keySet()) {
          this.set(key, configDefaults.get(key));
        }

        try {
          this.save(file);
          plugin.getLogger().info("New " + name + " file created");
        } catch (final IOException e) {
          e.printStackTrace();
        }
      }
    } else {
      try {
        this.load(file);
        plugin.getLogger().info(name + " file loaded");
      } catch (final Exception e) {
        e.printStackTrace();
      }
    }
  }
Exemple #17
0
 /**
  * Initialize the debugger.
  *
  * @param plugin the plugin, used for grabbing the data folder to store the debug message in.
  */
 private void initialize(JavaPlugin plugin) {
   this.file = new File(plugin.getDataFolder(), "debug.txt");
   this.plugin = plugin;
 }
 public boolean MakeOld() {
   File file = new File(plugin.getDataFolder(), fileName + "_old");
   file.delete();
   return configFile.renameTo(new File(plugin.getDataFolder(), fileName + "_old"));
 }
Exemple #19
0
 public String getLangFolder() {
   return parent.getDataFolder() + File.separator + "lang";
 }
  /**
   * Creates a new configuration together with its own file.
   *
   * @param plugin the plugin the configuration belongs to
   * @param fileName the name of the file, should end with .yml
   */
  public Configuration(final JavaPlugin plugin, final String fileName) {
    this.plugin = plugin;
    file = new File(plugin.getDataFolder(), fileName);

    reload();
  }
Exemple #21
0
  // Event
  @EventHandler
  public void pInteract(PlayerInteractEvent event) {
    // Store player, action, block, world, location
    Player player = event.getPlayer();
    Action action = event.getAction();
    Block block = event.getClickedBlock();
    World world;
    try {
      world = block.getWorld();
    } catch (NullPointerException npe) {
      return;
    }
    Location loc = block.getLocation();

    // Keep players from clicking the points
    if (action.equals(Action.RIGHT_CLICK_BLOCK) || action.equals(Action.LEFT_CLICK_BLOCK)) {
      // Check if its a gold or iron plate
      if (block.getType().equals(Material.GOLD_PLATE)
          || block.getType().equals(Material.IRON_PLATE)) {
        // Check if this blocks coords match coords in the file
        File file = new File(plugin.getDataFolder() + "/worldData/" + world.getName() + ".yml");
        FileConfiguration config = YamlConfiguration.loadConfiguration(file);
        for (String key : config.getConfigurationSection("").getKeys(false)) {
          Point pointInfo = new Point(plugin, world, key);
          Location keyLoc = pointInfo.getLocation();
          if (keyLoc.equals(loc)) {
            // Make sure it exists
            if (pointInfo.getExists()) {
              event.setCancelled(true);
              return;
            }
          }
        }
      }
      // Else player stepped on it
    } else if (action.equals(Action.PHYSICAL)) {
      PlayerInfo pInfo = new PlayerInfo(player, plugin);
      // Check if iron or gold
      // Gold
      if (block.getType().equals(Material.GOLD_PLATE)) {
        // See if the coords match the Start or Finish for this world
        // ***** Start *****
        Point pointInfo = new Point(plugin, world, "Start");
        if (pointInfo.getLocation().equals(loc)) {
          if (pointInfo.getExists()) {
            // Check if the player has a cooldown
            if (!pInfo.getHasStartCD()) {
              // Check for finish point
              Point point = new Point(plugin, world, "Finish");
              if (point.getExists()) {
                pInfo.setStartTime(System.currentTimeMillis());
                pInfo.setLastCP("null");
                pInfo.setHasStartCD(true);
                pInfo.setHasFinishCD(false);
                // Check if started
                if (pInfo.getHasStarted()) {
                  player.sendMessage(
                      ChatColor.GREEN
                          + ""
                          + ChatColor.BOLD
                          + "[iParkour]"
                          + ChatColor.GOLD
                          + " Your time has been reset! Good luck!");
                } else {
                  pInfo.setHasStarted(true);
                  player.sendMessage(
                      ChatColor.GREEN
                          + ""
                          + ChatColor.BOLD
                          + "[iParkour]"
                          + ChatColor.GOLD
                          + " The timer has started! Good luck!");
                }
                // Finish doesn't exist
              } else {
                player.sendMessage(
                    ChatColor.GREEN
                        + ""
                        + ChatColor.BOLD
                        + "[iParkour]"
                        + ChatColor.RED
                        + " There has to be a Finish point before you can start!");
                pInfo.setHasStartCD(true);
              }
            }
          } // Else do nothing

          // ***** Finish *****
        } else {
          pointInfo = new Point(plugin, world, "Finish");
          if (pointInfo.getLocation().equals(loc)) {
            // Check if exists
            if (pointInfo.getExists()) {
              // Check for Start
              Point point = new Point(plugin, world, "Start");
              if (point.getExists()) {
                // Check if the player has started
                if (pInfo.getHasStarted()) {
                  // Check for finish cooldown
                  if (!pInfo.getHasFinishCD()) {
                    Long endTime = System.currentTimeMillis();
                    pInfo.checkForRecord(endTime);
                    pInfo.setHasStarted(false);
                    pInfo.setHasStartCD(false);
                    pInfo.setHasFinishCD(true);
                    pInfo.setLastCP("null");
                  }
                } else {
                  if (!pInfo.getHasFinishCD()) {
                    pInfo.setHasFinishCD(true);
                    player.sendMessage(
                        ChatColor.GREEN
                            + ""
                            + ChatColor.BOLD
                            + "[iParkour] "
                            + ChatColor.GOLD
                            + "You have to start at the beginning!");
                  }
                }

                // Start doesn't exist
              } else {
                player.sendMessage(
                    ChatColor.GREEN
                        + ""
                        + ChatColor.BOLD
                        + "[iParkour]"
                        + ChatColor.RED
                        + " There has to be a Start point before you can finish!");
                pInfo.setHasStartCD(true);
              }
            } // Else do nothing
          }
        }

        // Iron
      } else if (block.getType().equals(Material.IRON_PLATE)) {
        File file = new File(plugin.getDataFolder() + "/worldData/" + world.getName() + ".yml");
        FileConfiguration config = YamlConfiguration.loadConfiguration(file);
        for (String key : config.getConfigurationSection("").getKeys(false)) {
          // If start or finish ignore it
          if (!key.equals("Start") && !key.equals("Finish")) {
            Point pointInfo = new Point(plugin, world, key);
            if (loc.equals(pointInfo.getLocation()) && pointInfo.getExists()) {
              // Check if player has started
              if (pInfo.getHasStarted()) {
                // Check for new checkpoint
                String lastCP = pInfo.getLastCP();
                if (lastCP.equals("null") || !lastCP.equals(key)) {
                  pInfo.setLastCP(key);
                  player.sendMessage(
                      ChatColor.GREEN
                          + ""
                          + ChatColor.BOLD
                          + "[iParkour] "
                          + ChatColor.GOLD
                          + "You have reached a Checkpoint! Use the command "
                          + ChatColor.GREEN
                          + ""
                          + ChatColor.BOLD
                          + "/iparkour checkpoint"
                          + ChatColor.GOLD
                          + " to return here!");
                  return;
                }
              }
              return;
            }
          }
        }
      }
    }
  }
 public void setGlobalMeta(Database data) {
   this.global = new FileMetaData(new File(plugin.getDataFolder(), "global_meta.yml"), data);
 }
 public void setWorldMeta(Database data, String world) {
   MetaData meta = new FileMetaData(new File(plugin.getDataFolder(), world + "_meta.yml"), data);
   worlds.put(world, meta);
 }
 public boolean exists(JavaPlugin plugin) {
   File fileObject = new File(plugin.getDataFolder() + "\\data.yml");
   return fileObject.exists();
 }
Exemple #25
0
 public KConfig(JavaPlugin plugin) {
   this.plugin = plugin;
   this.fileName = "KingdomData.yml";
   this.configFile = new File(plugin.getDataFolder(), fileName);
 }