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

The following examples show how to use org.bukkit.configuration.file.YamlConfiguration#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: WorldBorder.java    From Carbon with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void save() {
	for (Entry<World, WorldBorder> entry : worldsWorldBorder.entrySet()) {
		WorldBorder worldborder = entry.getValue();
		YamlConfiguration config = new YamlConfiguration();
		config.set("x", worldborder.x);
		config.set("z", worldborder.z);
		config.set("damageAmount", worldborder.damageAmount);
		config.set("damageBuffer", worldborder.damageBuffer);
		config.set("warningBlocks", worldborder.warningBlocks);
		config.set("warningTime", worldborder.warningTime);
		if (worldborder.getStatus() != EnumWorldBorderStatus.STATIONARY) {
			config.set("lerpTime", worldborder.lerpEndTime - worldborder.lerpStartTime);
			config.set("currentRadius", worldborder.currentRadius);
		}
		config.set("oldRadius", worldborder.oldRadius);
		try {
			config.save(new File(entry.getKey().getWorldFolder(), "worldborder.yml"));
		} catch (IOException e) {
                         e.printStackTrace(System.out);
		}
	}
}
 
Example 2
Source File: NPCManager.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
public void saveHealth(NPC npc) {
    if(isInvalid(npc)) return;
    TraitCombatLogX traitCombatLogX = npc.getTrait(TraitCombatLogX.class);
    OfflinePlayer owner = traitCombatLogX.getOwner();
    
    YamlConfiguration config = getData(owner);
    if(npc.isSpawned()) {
        Entity entity = npc.getEntity();
        if(entity instanceof LivingEntity) {
            LivingEntity livingEntity = (LivingEntity) entity;
            double health = livingEntity.getHealth();

            config.set("citizens-compatibility.last-health", health);
            setData(owner, config);
            return;
        }
    }

    config.set("citizens-compatibility.last-health", 0.0D);
    setData(owner, config);
}
 
Example 3
Source File: HologramAPIInteraction.java    From BedwarsRel with GNU General Public License v3.0 6 votes vote down vote up
private void updateHologramDatabase() {
  try {
    // update hologram-database file
    File file = new File(BedwarsRel.getInstance().getDataFolder(), "holodb.yml");
    YamlConfiguration config = new YamlConfiguration();
    List<Map<String, Object>> serializedLocations = new ArrayList<Map<String, Object>>();

    for (Location holoLocation : this.hologramLocations) {
      serializedLocations.add(Utils.locationSerialize(holoLocation));
    }

    if (!file.exists()) {
      file.createNewFile();
    }

    config.set("locations", serializedLocations);
    config.save(file);
  } catch (Exception ex) {
    BedwarsRel.getInstance().getBugsnag().notify(ex);
    ex.printStackTrace();
  }
}
 
Example 4
Source File: CustomGunItem.java    From QualityArmory with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void initIronsights(File dataFolder) {
	File ironsights = new File(dataFolder, "default_ironsightstoggleitem.yml");
	YamlConfiguration ironconfig = YamlConfiguration.loadConfiguration(ironsights);
	if (!ironconfig.contains("displayname")) {
		ironconfig.set("material", Material.CROSSBOW.name());
		ironconfig.set("id", 68);
		ironconfig.set("displayname", IronsightsHandler.ironsightsDisplay);
		try {
			ironconfig.save(ironsights);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	IronsightsHandler.ironsightsMaterial = Material.matchMaterial(ironconfig.getString("material"));
	IronsightsHandler.ironsightsData = ironconfig.getInt("id");
	IronsightsHandler.ironsightsDisplay = ironconfig.getString("displayname");

}
 
Example 5
Source File: TopTen.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
public void topTenSave() {
    if (topTenList == null) {
        return;
    }
    //plugin.getLogger().info("Saving top ten list");
    // Make file
    File topTenFile = new File(plugin.getDataFolder(), "topten.yml");
    // Make configuration
    YamlConfiguration config = new YamlConfiguration();
    // Save config
    int rank = 0;
    for (Map.Entry<UUID, Long> m : topTenList.entrySet()) {
        if (rank++ == 10) {
            break;
        }
        config.set("topten." + m.getKey().toString(), m.getValue());
    }
    try {
        config.save(topTenFile);
    } catch (Exception e) {
        plugin.getLogger().severe("Could not save top ten list!");
        e.printStackTrace();
    }
}
 
Example 6
Source File: HolographicDisplaysInteraction.java    From BedwarsRel with GNU General Public License v3.0 6 votes vote down vote up
private void updateHologramDatabase() {
  try {
    // update hologram-database file
    File file = new File(BedwarsRel.getInstance().getDataFolder(), "holodb.yml");
    YamlConfiguration config = new YamlConfiguration();
    List<Map<String, Object>> serializedLocations = new ArrayList<Map<String, Object>>();

    for (Location holoLocation : this.hologramLocations) {
      serializedLocations.add(Utils.locationSerialize(holoLocation));
    }

    if (!file.exists()) {
      file.createNewFile();
    }

    config.set("locations", serializedLocations);
    config.save(file);
  } catch (Exception ex) {
    BedwarsRel.getInstance().getBugsnag().notify(ex);
    ex.printStackTrace();
  }
}
 
Example 7
Source File: Game.java    From BedwarsRel with GNU General Public License v3.0 6 votes vote down vote up
private void updateSignConfig() {
  try {
    File config = new File(
        BedwarsRel.getInstance().getDataFolder() + "/" + GameManager.gamesPath + "/"
            + this.name + "/sign.yml");

    YamlConfiguration cfg = new YamlConfiguration();
    if (config.exists()) {
      cfg = YamlConfiguration.loadConfiguration(config);
    }

    List<Map<String, Object>> locList = new ArrayList<Map<String, Object>>();
    for (Location loc : this.joinSigns.keySet()) {
      locList.add(Utils.locationSerialize(loc));
    }

    cfg.set("signs", locList);
    cfg.save(config);
  } catch (Exception ex) {
    BedwarsRel.getInstance().getBugsnag().notify(ex);
    BedwarsRel.getInstance().getServer().getConsoleSender()
        .sendMessage(ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
            ._l(BedwarsRel.getInstance().getServer().getConsoleSender(), "errors.savesign")));
  }
}
 
Example 8
Source File: ListenerPVP.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
public void disablePVP(Player player) {
    if(player == null) return;

    YamlConfiguration playerData = this.plugin.getDataFile(player);
    playerData.set("pvp", false);
    this.plugin.saveDataFile(player, playerData);
}
 
Example 9
Source File: CoopPlay.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when disabling the plugin
 */
public void saveCoops() {
    YamlConfiguration coopConfig = new YamlConfiguration();
    for (UUID playerUUID : coopPlayers.keySet()) {
        coopConfig.set(playerUUID.toString(), getMyCoops(playerUUID));
    }
    Util.saveYamlFile(coopConfig, "coops.yml", false);
}
 
Example 10
Source File: ListenerDamageDeath.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onDespawn(NPCDespawnEvent e) {
    DespawnReason despawnReason = e.getReason();
    if(despawnReason == DespawnReason.PENDING_RESPAWN) return;
    
    Logger logger = this.expansion.getLogger();
    logger.info("[Debug] Removing NPC for reason '" + despawnReason + "'.");
    
    NPC npc = e.getNPC();
    NPCManager npcManager = this.expansion.getNPCManager();
    if(npcManager.isInvalid(npc)) return;

    TraitCombatLogX traitCombatLogX = npc.getTrait(TraitCombatLogX.class);
    OfflinePlayer owner = traitCombatLogX.getOwner();
    if(owner == null) return;
    
    if(despawnReason == DespawnReason.DEATH) npcManager.dropInventory(npc);
    npcManager.saveHealth(npc);
    npcManager.saveLocation(npc);
    
    YamlConfiguration data = npcManager.getData(owner);
    data.set("citizens-compatibility.punish-next-join", true);
    npcManager.setData(owner, data);

    JavaPlugin plugin = this.expansion.getPlugin().getPlugin();
    BukkitScheduler scheduler = Bukkit.getScheduler();
    scheduler.runTaskLater(plugin, npc::destroy, 1L);
}
 
Example 11
Source File: RedProtectUtil.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public void addProps(YamlConfiguration fileDB, Region r) {
    String rname = r.getName();
    fileDB.createSection(rname);
    fileDB.set(rname + ".name", rname);
    fileDB.set(rname + ".lastvisit", r.getDate());
    fileDB.set(rname + ".admins", r.getAdmins().stream().map(t -> t.getUUID() + "@" + t.getPlayerName()).collect(Collectors.toList()));
    fileDB.set(rname + ".members", r.getMembers().stream().map(t -> t.getUUID() + "@" + t.getPlayerName()).collect(Collectors.toList()));
    fileDB.set(rname + ".leaders", r.getLeaders().stream().map(t -> t.getUUID() + "@" + t.getPlayerName()).collect(Collectors.toList()));
    fileDB.set(rname + ".priority", r.getPrior());
    fileDB.set(rname + ".welcome", r.getWelcome());
    fileDB.set(rname + ".world", r.getWorld());
    fileDB.set(rname + ".maxX", r.getMaxMbrX());
    fileDB.set(rname + ".maxZ", r.getMaxMbrZ());
    fileDB.set(rname + ".minX", r.getMinMbrX());
    fileDB.set(rname + ".minZ", r.getMinMbrZ());
    fileDB.set(rname + ".maxY", r.getMaxY());
    fileDB.set(rname + ".minY", r.getMinY());
    fileDB.set(rname + ".value", r.getValue());
    fileDB.set(rname + ".flags", r.getFlags());
    fileDB.set(rname + ".candelete", r.canDelete());
    fileDB.set(rname + ".canpurge", r.canPurge());

    Location loc = r.getTPPoint();
    if (loc != null) {
        int x = loc.getBlockX();
        int y = loc.getBlockY();
        int z = loc.getBlockZ();
        float yaw = loc.getYaw();
        float pitch = loc.getPitch();
        fileDB.set(rname + ".tppoint", x + "," + y + "," + z + "," + yaw + "," + pitch);
    } else {
        fileDB.set(rname + ".tppoint", "");
    }
}
 
Example 12
Source File: ItemUtils.java    From ProRecipes with GNU General Public License v2.0 5 votes vote down vote up
protected static String nbtString(ItemStack itemStack) {

      YamlConfiguration config = new YamlConfiguration();
      //itemStack.setDurability((short)0);
      if(itemStack.getType() == Material.AIR){
      	itemStack.setDurability((short)-1);
      }
      config.set("i", itemStack);
      String ssa = config.saveToString();
      Map<String, Object> map = itemStack.serialize();
     
      if(map.containsKey("meta")){
      	 String s = map.get("meta").toString();
           if(s.contains("internal")){
           	String internal = "";
           	List<String> arr = Arrays.asList(s.split(", "));
           	for(String t : arr){
           		if(t.contains("internal")){
           			internal = t.replace("internal=", "").replace("}", "");
           			return internal;
           		}
           	}
           	
           	
           	
           }
           
      }
     
      return "";
  }
 
Example 13
Source File: Util.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Covert ItemStack to YAML string.
 *
 * @param iStack target ItemStack
 * @return String serialized itemStack
 */
@NotNull
public static String serialize(@NotNull ItemStack iStack) {
    YamlConfiguration cfg = new YamlConfiguration();
    cfg.set("item", iStack);
    return cfg.saveToString();
}
 
Example 14
Source File: Util.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Parse colors for the YamlConfiguration.
 *
 * @param config yaml config
 */
public static void parseColours(@NotNull YamlConfiguration config) {
    Set<String> keys = config.getKeys(true);
    for (String key : keys) {
        String filtered = config.getString(key);
        if (filtered == null) {
            continue;
        }
        if (filtered.startsWith("MemorySection")) {
            continue;
        }
        filtered = parseColours(filtered);
        config.set(key, filtered);
    }
}
 
Example 15
Source File: ListenerPVP.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
public void enablePVP(Player player) {
    if(player == null) return;

    YamlConfiguration playerData = this.plugin.getDataFile(player);
    playerData.set("pvp", true);
    this.plugin.saveDataFile(player, playerData);
}
 
Example 16
Source File: Game.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
private void createGameConfig(File config) {
  YamlConfiguration yml = new YamlConfiguration();

  yml.set("name", this.name);
  yml.set("world", this.getRegion().getWorld().getName());
  yml.set("loc1", Utils.locationSerialize(this.loc1));
  yml.set("loc2", Utils.locationSerialize(this.loc2));
  yml.set("lobby", Utils.locationSerialize(this.lobby));
  yml.set("minplayers", this.getMinPlayers());

  if (BedwarsRel.getInstance().getBooleanConfig("store-game-records", true)) {
    yml.set("record", this.record);

    if (BedwarsRel.getInstance().getBooleanConfig("store-game-records-holder", true)) {
      yml.set("record-holders", this.recordHolders);
    }
  }

  if (this.regionName == null) {
    this.regionName = this.region.getName();
  }

  yml.set("regionname", this.regionName);
  yml.set("time", this.time);

  yml.set("targetmaterial", this.getTargetMaterial().name());
  yml.set("builder", this.builder);

  if (this.hologramLocation != null) {
    yml.set("hololoc", Utils.locationSerialize(this.hologramLocation));
  }

  if (this.mainLobby != null) {
    yml.set("mainlobby", Utils.locationSerialize(this.mainLobby));
  }

  yml.set("autobalance", this.autobalance);

  yml.set("spawner", this.resourceSpawners);
  yml.createSection("teams", this.teams);

  try {
    yml.save(config);
    this.config = yml;
  } catch (IOException e) {
    BedwarsRel.getInstance().getBugsnag().notify(e);
    BedwarsRel.getInstance().getLogger().info(ChatWriter.pluginMessage(e.getMessage()));
  }
}
 
Example 17
Source File: TSerializer.java    From TabooLib with MIT License 4 votes vote down vote up
public static String serializeCS(ConfigurationSerializable o) {
    YamlConfiguration y = new YamlConfiguration();
    y.set("value", o);
    return y.saveToString();
}
 
Example 18
Source File: UsersFile.java    From WildernessTp with MIT License 4 votes vote down vote up
public void addUse(UUID uuid){
    int uses = getUsers().getInt("Users."+uuid,0);
    YamlConfiguration users = getUsers();
    users.set("Users."+uuid,uses+1);
    save(users);
}
 
Example 19
Source File: UCConfig.java    From UltimateChat with GNU General Public License v3.0 4 votes vote down vote up
private void loadChannels() throws IOException {
    File chfolder = new File(UChat.get().getDataFolder(), "channels");

    if (!chfolder.exists()) {
        chfolder.mkdir();
        UChat.get().getUCLogger().info("Created folder: " + chfolder.getPath());
    }

    if (UChat.get().getChannels() == null) {
        UChat.get().setChannels(new HashMap<>());
    }

    File[] listOfFiles = chfolder.listFiles();

    YamlConfiguration channel;

    if (Objects.requireNonNull(listOfFiles).length == 0) {
        //create default channels
        File g = new File(chfolder, "global.yml");
        channel = YamlConfiguration.loadConfiguration(g);
        channel.set("name", "Global");
        channel.set("alias", "g");
        channel.set("color", "&2");
        channel.set("jedis", false);
        channel.set("dynmap.enable", true);
        channel.save(g);

        File l = new File(chfolder, "local.yml");
        channel = YamlConfiguration.loadConfiguration(l);
        channel.set("name", "Local");
        channel.set("alias", "l");
        channel.set("color", "&e");
        channel.set("jedis", false);
        channel.set("across-worlds", false);
        channel.set("distance", 40);
        channel.save(l);

        File ad = new File(chfolder, "admin.yml");
        channel = YamlConfiguration.loadConfiguration(ad);
        channel.set("name", "Admin");
        channel.set("alias", "ad");
        channel.set("color", "&b");
        channel.set("jedis", false);
        channel.save(ad);

        listOfFiles = chfolder.listFiles();
    }

    for (File file : Objects.requireNonNull(listOfFiles)) {
        if (file.getName().endsWith(".yml")) {
            channel = YamlConfiguration.loadConfiguration(file);
            UCChannel ch = new UCChannel(channel.getValues(true));

            try {
                addChannel(ch);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example 20
Source File: ConverterChestCommands.java    From TrMenu with MIT License 4 votes vote down vote up
private static int convert(File file, int count) {
    if (file.isDirectory()) {
        for (File f : file.listFiles()) {
            count += convert(f, count);
        }
        return count;
    } else if (!file.getName().endsWith(".yml")) {
        return count;
    }
    try {
        ListIterator<Character> buttons = Arrays.asList('#', '-', '+', '=', '<', '>', '~', '_', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z').listIterator();
        YamlConfiguration trmenu = new YamlConfiguration();
        YamlConfiguration conf = YamlConfiguration.loadConfiguration(file);
        List<String> cmds = conf.contains("menu-settings.command") ? Arrays.asList(conf.getString("menu-settings.command").split(";( )?")) : new ArrayList<>();
        for (int i = 0; i < cmds.size(); i++) {
            cmds.set(i, cmds.get(i) + "-fromCC");
        }
        int rows = conf.getInt("menu-settings.rows", 6);
        int update = conf.getInt("menu-settings.auto-refresh", -1) * 20;
        trmenu.set("Title", conf.getString("menu-settings.name"));
        trmenu.set("Open-Commands", cmds);
        trmenu.set("Open-Actions", conf.contains("menu-settings.open-action") ? conf.getString("menu-settings.open-action").split(";( )?") : "");

        List<String> shape = Lists.newArrayList();
        while (rows > 0) {
            shape.add("         ");
            rows--;
        }
        trmenu.set("Shape", shape);

        conf.getValues(false).forEach((icon, value) -> {
            if (!"menu-settings".equalsIgnoreCase(icon)) {
                MemorySection section = (MemorySection) value;
                int x = section.getInt("POSITION-X") - 1;
                int y = section.getInt("POSITION-Y") - 1;
                char[] chars = shape.get(y).toCharArray();
                char symbol = buttons.next();
                chars[x] = symbol;
                shape.set(y, new String(chars));

                if (update > 0) {
                    trmenu.set("Buttons." + symbol + ".update", update);
                }
                trmenu.set("Buttons." + symbol + ".display.mats", section.get("ID"));
                trmenu.set("Buttons." + symbol + ".display.name", section.get("NAME"));
                trmenu.set("Buttons." + symbol + ".display.lore", section.get("LORE"));
                if (section.contains("COMMAND")) {
                    trmenu.set("Buttons." + symbol + ".actions.all", section.getString("COMMAND").split(";( )?"));
                }
                if (section.contains("ENCHANTMENT")) {
                    trmenu.set("Buttons." + symbol + ".display.shiny", true);
                }
            }
        });
        trmenu.set("Shape", fixShape(shape));
        file.renameTo(new File(file.getParent(), file.getName().replace(".yml", "") + ".CONVERTED.TRMENU"));
        trmenu.save(new File(TrMenu.getPlugin().getDataFolder(), "menus/" + file.getName().replace(".yml", "") + "-fromcc.yml"));
        return count + 1;
    } catch (Throwable e) {
        e.printStackTrace();
    }
    return count;
}