Java Code Examples for org.bukkit.configuration.file.FileConfiguration#set()

The following examples show how to use org.bukkit.configuration.file.FileConfiguration#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegionsTests.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
public static void loadRegionTypeCobble3() {
    FileConfiguration config = new YamlConfiguration();
    config.set("max", 1);
    ArrayList<String> reqs = new ArrayList<>();
    reqs.add("cobblestone*2");
    reqs.add("g:glass*1");
    config.set("build-reqs", reqs);
    ArrayList<String> effects = new ArrayList<>();
    effects.add("block_place");
    effects.add("block_break");
    config.set("effects", effects);
    config.set("effect-radius", 7);
    config.set("period", 100);
    ArrayList<String> reagents = new ArrayList<>();
    reagents.add("IRON_PICKAXE");
    reagents.add("GOLD_BLOCK");
    reagents.add("IRON_BLOCK");
    config.set("upkeep.0.input", reagents);
    ArrayList<String> outputs = new ArrayList<>();
    outputs.add("COBBLESTONE");
    config.set("upkeep.0.output", outputs);
    ItemManager.getInstance().loadRegionType(config, "cobble");
}
 
Example 2
Source File: TauntOption.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
private static void updateFile(File file, FileConfiguration storage) {
       ArrayList<Integer> placement = new ArrayList<>(Arrays.asList(0, 2, 4, 6, 8, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26, 27, 29, 31, 33, 35,
       		36, 38, 40, 42, 44, 45, 47, 49, 51, 53));
       storage.set("menuSize", 45);
	for (int i = 0; i < playerOptions.size(); i++) {
		playerOptions.get(i).setPosition(placement.get(i) % 45);
		playerOptions.get(i).setPage((Math.floorDiv(placement.get(i), 45))+1);
		playerOptions.get(i).setMenuSize(45);
		storage.set("taunts." + playerOptions.get(i).getKey() + ".position", playerOptions.get(i).getPosition());
		storage.set("taunts." + playerOptions.get(i).getKey() + ".page", playerOptions.get(i).getPage());
	}
	try {
		storage.save(file);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 3
Source File: PlotMe_Core.java    From PlotMe-Core with GNU General Public License v3.0 6 votes vote down vote up
private void setupConfigFiles() {
    createConfigs();
    // Get the config we will be working with
    FileConfiguration config = getConfig();
    // Do any config validation
    if (config.getInt("NbClearSpools") > 20) {
        getLogger().warning("Having more than 20 clear spools seems drastic, changing to 20");
        config.set("NbClearSpools", 20);
    }
    //Check if the config doesn't have the worlds section. This should happen only if there is no config file for the plugin already.
    if (!config.contains("worlds")) {
        getServerBridge().loadDefaultConfig(configFile, "worlds.plotworld");
    }
    getConfig().set("Version", "0.17.3");
    // Copy new values over
    getConfig().options().copyDefaults(true);
    configFile.saveConfig();
}
 
Example 4
Source File: CrazyCrates.java    From Crazy-Crates with MIT License 6 votes vote down vote up
/**
 * Take keys from an offline player.
 * @param player The player which you are taking keys from.
 * @param crate The Crate of which key you are taking from the player.
 * @param keys The amount of keys you wish to take.
 * @return Returns true if it took the keys and false if an error occurred.
 */
public boolean takeOfflineKeys(String player, Crate crate, int keys) {
    try {
        FileConfiguration data = Files.DATA.getFile();
        player = player.toLowerCase();
        int playerKeys = 0;
        if (data.contains("Offline-Players." + player + "." + crate.getName())) {
            playerKeys = data.getInt("Offline-Players." + player + "." + crate.getName());
        }
        data.set("Offline-Players." + player + "." + crate.getName(), playerKeys - keys);
        Files.DATA.saveFile();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
Example 5
Source File: HealthDecayEvent.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void saveEventData() {
	File dataDirectory = SkyWarsReloaded.get().getDataFolder();
       File mapDataDirectory = new File(dataDirectory, "mapsData");

       if (!mapDataDirectory.exists() && !mapDataDirectory.mkdirs()) {
       	return;
       }
       
       File mapFile = new File(mapDataDirectory, gMap.getName() + ".yml");
    if (mapFile.exists()) {
        FileConfiguration fc = YamlConfiguration.loadConfiguration(mapFile);
        fc.set("events." + eventName + ".enabled", this.enabled);
        fc.set("events." + eventName + ".minStart", this.min);
        fc.set("events." + eventName + ".maxStart", this.max);
        fc.set("events." + eventName + ".length", this.length);
        fc.set("events." + eventName + ".chance", this.chance);
        fc.set("events." + eventName + ".title", this.title);
        fc.set("events." + eventName + ".subtitle", this.subtitle);
        fc.set("events." + eventName + ".startMessage",  this.startMessage);
        fc.set("events." + eventName + ".endMessage", this.endMessage);
        fc.set("events." + eventName + ".announceTimer", this.announceEvent);
        fc.set("events." + eventName + ".repeatable", this.repeatable);
        try {
			fc.save(mapFile);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
}
 
Example 6
Source File: DisableRegenEvent.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void saveEventData() {
	File dataDirectory = SkyWarsReloaded.get().getDataFolder();
       File mapDataDirectory = new File(dataDirectory, "mapsData");

       if (!mapDataDirectory.exists() && !mapDataDirectory.mkdirs()) {
       	return;
       }
       
       File mapFile = new File(mapDataDirectory, gMap.getName() + ".yml");
    if (mapFile.exists()) {
        FileConfiguration fc = YamlConfiguration.loadConfiguration(mapFile);
        fc.set("events." + eventName + ".enabled", this.enabled);
        fc.set("events." + eventName + ".minStart", this.min);
        fc.set("events." + eventName + ".maxStart", this.max);
        fc.set("events." + eventName + ".length", this.length);
        fc.set("events." + eventName + ".chance", this.chance);
        fc.set("events." + eventName + ".title", this.title);
        fc.set("events." + eventName + ".subtitle", this.subtitle);
        fc.set("events." + eventName + ".startMessage",  this.startMessage);
        fc.set("events." + eventName + ".endMessage", this.endMessage);
        fc.set("events." + eventName + ".announceTimer", this.announceEvent);
        fc.set("events." + eventName + ".repeatable", this.repeatable);
        try {
			fc.save(mapFile);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
}
 
Example 7
Source File: GlobalProtectionCache.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param config the config to save all protections to
 */
public void saveAll(FileConfiguration config) {
    config.set("protections", null);
    for (GlobalProtection protection : protections) {
        protection.save(config);
    }

    plugin.getGlobalData().save();
}
 
Example 8
Source File: GroupManager.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Loads the groups defined in a 'worlds.yml' file into memory.
 *
 * @param config The contents of the configuration file.
 */
public void loadGroupsToMemory(FileConfiguration config) {
    groups.clear();

    for (String key : config.getConfigurationSection("groups.").getKeys(false)) {
        List<String> worlds;
        if (config.contains("groups." + key + ".worlds")) {
            worlds = config.getStringList("groups." + key + ".worlds");
        } else {
            worlds = config.getStringList("groups." + key);
            config.set("groups." + key, null);
            config.set("groups." + key + ".worlds", worlds);
            if (settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES)) {
                config.set("groups." + key + ".default-gamemode", "SURVIVAL");
            }
        }

        if (settings.getProperty(PwiProperties.MANAGE_GAMEMODES)) {
            GameMode gameMode = GameMode.SURVIVAL;
            if (config.getString("groups." + key + ".default-gamemode") != null) {
                gameMode = GameMode.valueOf(config.getString("groups." + key + ".default-gamemode").toUpperCase());
            }

            addGroup(key, worlds, gameMode);
        } else {
            addGroup(key, worlds);
        }

        setDefaultsFile(key);
    }
}
 
Example 9
Source File: ItemsTests.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
private void loadRegionTypeCityHall2() {
    ItemManager itemManager = ItemManager.getInstance();
    FileConfiguration config = new YamlConfiguration();
    config.set("icon", "GOLD_BLOCK");
    ArrayList<String> preReqs = new ArrayList<>();
    preReqs.add("shack2:built=1");
    config.set("pre-reqs", preReqs);
    config.set("build-radius", 7);
    itemManager.loadRegionType(config, "cityhall2");
}
 
Example 10
Source File: RegionsTests.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
public static void loadRegionTypeUtility() {
    FileConfiguration config = new YamlConfiguration();
    ArrayList<String> reqs = new ArrayList<>();
    config.set("build-reqs", reqs);
    ArrayList<String> effects = new ArrayList<>();
    config.set("effects", effects);
    config.set("build-radius", 5);
    config.set("upkeep.0.power-output", 96);
    ItemManager.getInstance().loadRegionType(config, "utility");
}
 
Example 11
Source File: RegionsTests.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
public static void loadRegionTypeDirt() {
    FileConfiguration config = new YamlConfiguration();
    ArrayList<String> reqs = new ArrayList<>();
    reqs.add("dirt*1");
    config.set("build-reqs", reqs);
    ArrayList<String> effects = new ArrayList<>();
    config.set("effects", effects);
    ItemManager.getInstance().loadRegionType(config, "dirt");
}
 
Example 12
Source File: ConfigHelper.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
public static double getOrSetDefault(double defaultValue, FileConfiguration config, String path) {
    double result;
    if (config.isSet(path)) {
        result = config.getDouble(path);
    } else {
        result = defaultValue;
        config.set(path, defaultValue);
    }
    return result;
}
 
Example 13
Source File: DoubleDamageEvent.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void saveEventData() {
	File dataDirectory = SkyWarsReloaded.get().getDataFolder();
       File mapDataDirectory = new File(dataDirectory, "mapsData");

       if (!mapDataDirectory.exists() && !mapDataDirectory.mkdirs()) {
       	return;
       }
       
       File mapFile = new File(mapDataDirectory, gMap.getName() + ".yml");
    if (mapFile.exists()) {
        FileConfiguration fc = YamlConfiguration.loadConfiguration(mapFile);
        fc.set("events." + eventName + ".enabled", this.enabled);
        fc.set("events." + eventName + ".minStart", this.min);
        fc.set("events." + eventName + ".maxStart", this.max);
        fc.set("events." + eventName + ".length", this.length);
        fc.set("events." + eventName + ".chance", this.chance);
        fc.set("events." + eventName + ".title", this.title);
        fc.set("events." + eventName + ".subtitle", this.subtitle);
        fc.set("events." + eventName + ".startMessage",  this.startMessage);
        fc.set("events." + eventName + ".endMessage", this.endMessage);
        fc.set("events." + eventName + ".announceTimer", this.announceEvent);
        fc.set("events." + eventName + ".repeatable", this.repeatable);
        try {
			fc.save(mapFile);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
}
 
Example 14
Source File: ConfigHelper.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
public static int getOrSetDefault(int defaultValue, FileConfiguration config, String path) {
    int result;
    if (config.isSet(path)) {
        result = config.getInt(path);
    } else {
        result = defaultValue;
        config.set(path, defaultValue);
    }
    return result;
}
 
Example 15
Source File: DelArena.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
public boolean onCommand(CommandSender sender, String[] args) {	
    if (!sender.hasPermission(permission()) && !sender.isOp()){
        MessageManager.getInstance().sendFMessage(PrefixType.ERROR, "error.nopermission", sender);
        return true;
    }
    
    if(args.length != 1){
        MessageManager.getInstance().sendFMessage(PrefixType.ERROR, "error.notspecified", sender, "input-Arena");
        return true;
    }
    
    FileConfiguration s = SettingsManager.getInstance().getSystemConfig();
    //FileConfiguration spawn = SettingsManager.getInstance().getSpawns();
    int arena = Integer.parseInt(args[0]);
    Game g = GameManager.getInstance().getGame(arena);
    
    if(g == null){
        MessageManager.getInstance().sendFMessage(PrefixType.ERROR, "error.gamedoesntexist", sender, "arena-" + arena);
        return true;
    }
    
    g.disable();
    s.set("sg-system.arenas."+arena+".enabled", false);
    s.set("sg-system.arenano", s.getInt("sg-system.arenano") - 1);
    //spawn.set("spawns."+arena, null);
    MessageManager.getInstance().sendFMessage(PrefixType.INFO, "info.deleted", sender, "input-Arena");
    SettingsManager.getInstance().saveSystemConfig();
    GameManager.getInstance().hotRemoveArena(arena);
    //LobbyManager.getInstance().clearAllSigns();
    LobbyManager.getInstance().removeSignsForArena(arena);
    return true;
}
 
Example 16
Source File: ConfigHelper.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Will return object from a config with specified path. If the object does not exist in
 * the config, it will add it into the config and return the default object.
 *
 * @param defaultValue default object
 * @param config       FileConfiguration instance
 * @param path         path to object
 */

//this method is probably the only necessary method in this util
public static Object getOrSetDefault(Object defaultValue, FileConfiguration config, String path) {
    Object result;
    if (config.isSet(path)) {
        result = config.get(path);
    } else {
        result = defaultValue;
        config.set(path, defaultValue);
    }
    return result;
}
 
Example 17
Source File: GroupSign.java    From DungeonsXL with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void save(FileConfiguration config) {
    super.save(config);
    String preString = getDataPath() + "." + getWorld().getName() + "." + getId();
    config.set(preString + ".groupName", groupName);
}
 
Example 18
Source File: WarehouseEffect.java    From Civs with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onChestPlace(BlockPlaceEvent event) {
    if (event.getBlock().getType() != Material.CHEST) {
        return;
    }

    Location l = Region.idToLocation(Region.blockLocationToString(event.getBlock().getLocation()));
    Region r = RegionManager.getInstance().getRegionAt(l);
    if (r == null) {
        return;
    }

    if (!r.getEffects().containsKey(KEY)) {
        return;
    }


    File dataFolder = new File(Civs.dataLocation, Constants.REGIONS);
    if (!dataFolder.exists()) {
        return;
    }
    File dataFile = new File(dataFolder, r.getId() + ".yml");
    if (!dataFile.exists()) {
        return;
    }
    FileConfiguration config = new YamlConfiguration();
    try {
        config.load(dataFile);
        List<String> locationList = config.getStringList(Constants.CHESTS);
        locationList.add(Region.locationToString(l));
        config.set(Constants.CHESTS, locationList);
        config.save(dataFile);
    } catch (Exception e) {
        Civs.logger.log(Level.WARNING, UNABLE_TO_SAVE_CHEST, r.getId());
        return;
    }

    if (!invs.containsKey(r)) {
        invs.put(r, new ArrayList<>());
    }
    CVInventory cvInventory = UnloadedInventoryHandler.getInstance().getChestInventory(event.getBlockPlaced().getLocation());
    invs.get(r).add(cvInventory);
}
 
Example 19
Source File: GameKit.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
public static void newKit(Player player, String kitName) {
File dataDirectory = SkyWarsReloaded.get().getDataFolder();
      File kitsDirectory = new File(dataDirectory, "kits");
  	if (!kitsDirectory.exists()) {
          if (!kitsDirectory.mkdirs())  {
              return;
          }
      }
      
  	File kitFile = new File(kitsDirectory, kitName + ".yml");
      FileConfiguration storage = YamlConfiguration.loadConfiguration(kitFile);

      ItemStack[] inventory = player.getInventory().getContents();
      storage.set("inventory", inventory);
      
      ItemStack[] armor = player.getInventory().getArmorContents();
      storage.set("armor",  armor);
      
      storage.set("requirePermission", false);
      
      storage.set("icon", new ItemStack(Material.SNOW_BLOCK, 1));
      
      storage.set("lockedIcon", new ItemStack(Material.BARRIER, 1));
      
      storage.set("position", 0);
      
      storage.set("page", 1);
      
      storage.set("name", kitName);
      
      storage.set("enabled", false);
      
      for (int x = 1; x < 17; x++) {
      	storage.set("lores.line" + x, " ");
      }
      storage.set("lores.locked", "&CPermission required to unlock this kit!");
      
      storage.set("gameSettings.noRegen", false);
      storage.set("gameSettings.noPvp", false);
      storage.set("gameSettings.soupPvp", false);
      storage.set("gameSettings.noFallDamage", false);
      
      storage.set("filename", kitFile.getName().substring(0, kitFile.getName().lastIndexOf('.')));
      
      try {
      	storage.save(kitFile);
} catch (IOException e) {
          SkyWarsReloaded.get().getLogger().info("Failed to save new kit file!");
}
      GameKit.getKits().add(new GameKit(kitFile));
  }
 
Example 20
Source File: DataStorage.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
public void saveStats(final PlayerStat pData) {
boolean sqlEnabled = SkyWarsReloaded.get().getConfig().getBoolean("sqldatabase.enabled");
if (!sqlEnabled) {
	try {
           File dataDirectory = SkyWarsReloaded.get().getDataFolder();
           File playerDataDirectory = new File(dataDirectory, "player_data");

           if (!playerDataDirectory.exists() && !playerDataDirectory.mkdirs()) {
           	return;
           }

           File playerFile = new File(playerDataDirectory, pData.getId() + ".yml");
           if (!playerFile.exists()) {
           	SkyWarsReloaded.get().getLogger().info("File doesn't exist!");
           	return;
           }

           copyDefaults(playerFile);
           FileConfiguration fc = YamlConfiguration.loadConfiguration(playerFile);
           fc.set("uuid", pData.getId());
           fc.set("wins", pData.getWins());
           fc.set("losses", pData.getLosses());
           fc.set("kills", pData.getKills());
           fc.set("deaths", pData.getDeaths());
           fc.set("elo", pData.getElo());
           fc.set("xp", pData.getXp());
           fc.set("pareffect", pData.getParticleEffect());
           fc.set("proeffect", pData.getProjectileEffect());
           fc.set("glasscolor", pData.getGlassColor());
           fc.set("killsound", pData.getKillSound());
           fc.set("winsound", pData.getWinSound());
           fc.set("taunt", pData.getTaunt());
           fc.save(playerFile);
           
       } catch (IOException ioException) {
           System.out.println("Failed to load faction " + pData.getId() + ": " + ioException.getMessage());
       }
} else {
          Database database = SkyWarsReloaded.getDb();

          if (database.checkConnection()) {
              return;
          }

          Connection connection = database.getConnection();
          PreparedStatement preparedStatement = null;

          try {
          	 String query = "UPDATE `sw_player` SET `player_name` = ?, `wins` = ?, `losses` = ?, `kills` = ?, `deaths` = ?, `elo` = ?, `xp` = ?, `pareffect` = ?, " +
				 "`proeffect` = ?, `glasscolor` = ?,`killsound` = ?, `winsound` = ?, `taunt` = ? WHERE `uuid` = ?;";
               
               preparedStatement = connection.prepareStatement(query);
               preparedStatement.setString(1, pData.getPlayerName());
               preparedStatement.setInt(2, pData.getWins());
               preparedStatement.setInt(3, pData.getLosses());
               preparedStatement.setInt(4, pData.getKills());
               preparedStatement.setInt(5, pData.getDeaths());
               preparedStatement.setInt(6, pData.getElo());
               preparedStatement.setInt(7, pData.getXp());
               preparedStatement.setString(8, pData.getParticleEffect());
               preparedStatement.setString(9, pData.getProjectileEffect());
               preparedStatement.setString(10, pData.getGlassColor());
               preparedStatement.setString(11, pData.getKillSound());
               preparedStatement.setString(12, pData.getWinSound());
               preparedStatement.setString(13, pData.getTaunt());
               preparedStatement.setString(14, pData.getId());
               preparedStatement.executeUpdate();

          } catch (final SQLException sqlException) {
              sqlException.printStackTrace();

          } finally {
              if (preparedStatement != null) {
                  try {
                      preparedStatement.close();
                  } catch (final SQLException ignored) {
                  }
              }
          }
}
  }