Skip to content

Commit

Permalink
Improve importer of config.yml and challenges.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
rlf committed Jul 24, 2018
1 parent bc2e7bc commit 5d17929
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 49 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<properties>
<api.version>2.7.4</api.version>
<bukkit-utils.version>1.21</bukkit-utils.version>
<bukkit-utils.version>1.22-bukkit-1.12</bukkit-utils.version>
<po-utils.version>1.2</po-utils.version>
<deluxechat.version>1.6</deluxechat.version>
<vault.version>1.6</vault.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public static boolean loadPluginConfig(FileConfiguration config) {
}
general_spawnSize = config.getInt("options.general.spawnSize", 50);
island_chestItems = ItemStackUtil.createItemArray(ItemStackUtil.createItemList(
config.getString("options.island.chestItems", null),
config.getStringList("options.island.chestItems")
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import dk.lockfuglsang.minecraft.util.TimeUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import us.talabrek.ultimateskyblock.imports.challenges.ConfigPre13Importer;
import us.talabrek.ultimateskyblock.imports.challenges.ConfigPre113Importer;
import us.talabrek.ultimateskyblock.imports.fixuuidleader.UUIDLeaderImporter;
import us.talabrek.ultimateskyblock.imports.levelconfig.LevelConfigImporter;
import us.talabrek.ultimateskyblock.imports.name2uuid.Name2UUIDImporter;
Expand Down Expand Up @@ -58,7 +58,7 @@ private List<USBImporter> getImporters() {
importers.add(new USBUpdateImporter());
importers.add(new Name2UUIDImporter());
importers.add(new LevelConfigImporter());
importers.add(new ConfigPre13Importer());
importers.add(new ConfigPre113Importer());
ServiceLoader serviceLoader = ServiceLoader.load(USBImporter.class, getClass().getClassLoader());
for (Iterator<USBImporter> it = serviceLoader.iterator(); it.hasNext(); ) {
importers.add(it.next());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@

import dk.lockfuglsang.minecraft.util.ItemStackUtil;
import dk.lockfuglsang.minecraft.yml.YmlConfiguration;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
import us.talabrek.ultimateskyblock.imports.USBImporter;
import us.talabrek.ultimateskyblock.uSkyBlock;
import us.talabrek.ultimateskyblock.util.LogUtil;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static dk.lockfuglsang.minecraft.file.FileUtil.readConfig;

public class ConfigPre13Importer implements USBImporter {
public class ConfigPre113Importer implements USBImporter {
public static final Pattern REQ_PATTERN = Pattern.compile("(?<itemstack>(?<type>[0-9A-Z_]+)(:(?<subtype>[0-9]+))?)(?<meta>\\{.*\\})?:(?<amount>[0-9]+)(;(?<op>[+\\-*\\^])(?<inc>[0-9]+))?");
private static final Pattern ITEM_AMOUNT_PATTERN = Pattern.compile("(\\{p=(?<prob>0\\.[0-9]+)\\})?(?<itemstack>(?<id>[0-9A-Z_]+)(:(?<sub>[0-9]+))?):(?<amount>[0-9]+)\\s*(?<meta>\\{.*\\})?");
private static final Pattern ITEM_PATTERN = Pattern.compile("(?<itemstack>(?<id>[0-9A-Z_]+)(:(?<sub>[0-9]+))?)\\s*(?<meta>\\{.*\\})?");
Expand All @@ -30,7 +32,7 @@ public class ConfigPre13Importer implements USBImporter {

@Override
public String getName() {
return "configpre13";
return "config-pre-1-13";
}

@Override
Expand Down Expand Up @@ -67,26 +69,30 @@ private void convertConfig(FileConfiguration config) {
Set<String> keys = config.getKeys(true);
// displayItems (and lockedDisplayItem)
for (String key : keys.stream().filter(f -> f.toLowerCase().endsWith("displayitem")).collect(Collectors.toList())) {
config.set(key, convertItem(config.getString(key)));
try {
config.set(key, convertItem(config.getString(key)));
} catch (Exception e) {
LogUtil.log(Level.WARNING, "Unable to convert config.yml:" + key + ":" + e.getMessage());
}
}
// chestItems
for (String key : keys.stream().filter(f -> f.endsWith(".chestItems")).collect(Collectors.toList())) {
List<String> value = new ArrayList<>();
if (config.isList(key)) {
for (String key : keys.stream().filter(f -> f.endsWith(".chestItems") || f.endsWith(".extraItems")).collect(Collectors.toList())) {
try {
List<String> value = new ArrayList<>();
value.addAll(convertItemAmountList(config.getStringList(key)));
} else if (config.isString(key)) {
value.addAll(convertItemAmountList(Arrays.asList(config.getString(key, "").split(" "))));
config.set(key, value);
} catch (Exception e) {
LogUtil.log(Level.WARNING, "Unable to convert config.yml:" + key + ":" + e.getMessage());
}
config.set(key, value);
}
// extraPermissions
ConfigurationSection extraPerms = config.getConfigurationSection("options.island.extraPermissions");
if (extraPerms != null) {
for (String key : extraPerms.getKeys(true)) {
if (config.isList(key)) {
for (String key : extraPerms.getKeys(false)) {
try {
extraPerms.set(key, convertItemAmountList(extraPerms.getStringList(key)));
} else {
extraPerms.set(key, convertItemAmountList(Arrays.asList(extraPerms.getString(key, "").split(" "))));
} catch (Exception e) {
LogUtil.log(Level.WARNING, "Unable to convert config.yml:" + key + ":" + e.getMessage());
}
}
}
Expand All @@ -96,27 +102,31 @@ private void convertChallenges(FileConfiguration config) {
// Convert all requiredItems
Set<String> keys = config.getKeys(true);
for (String key : keys.stream().filter(f -> f.endsWith(".requiredItems")).collect(Collectors.toList())) {
List<String> value = new ArrayList<>();
if (config.isList(key)) {
try {
List<String> value = new ArrayList<>();
value.addAll(convertRequiredItemsList(config.getStringList(key)));
} else if (config.isString(key)) {
value.addAll(convertRequiredItemsList(Arrays.asList(config.getString(key, "").split(" "))));
config.set(key, value);
} catch (Exception e) {
LogUtil.log(Level.WARNING, "Unable to convert challenges.yml:" + key + ":" + e.getMessage());
}
config.set(key, value);
}
// Rewards (.items)
for (String key : keys.stream().filter(f -> f.endsWith(".items")).collect(Collectors.toList())) {
List<String> value = new ArrayList<>();
if (config.isList(key)) {
try {
List<String> value = new ArrayList<>();
value.addAll(convertItemAmountList(config.getStringList(key)));
} else if (config.isString(key)) {
value.addAll(convertItemAmountList(Arrays.asList(config.getString(key, "").split(" "))));
config.set(key, value);
} catch (Exception e) {
LogUtil.log(Level.WARNING, "Unable to convert challenges.yml:" + key + ":" + e.getMessage());
}
config.set(key, value);
}
// displayItems (and lockedDisplayItem)
for (String key : keys.stream().filter(f -> f.toLowerCase().endsWith("displayitem")).collect(Collectors.toList())) {
config.set(key, convertItem(config.getString(key)));
try {
config.set(key, convertItem(config.getString(key)));
} catch (Exception e) {
LogUtil.log(Level.WARNING, "Unable to convert challenges.yml:" + key + ":" + e.getMessage());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ public Inventory createEditMenu(String configName, String path, int page) {
if (!config.isString(path)) {
return null;
}
String items = config.getString(path);
List<String> stringList = config.getStringList(path);
List<ItemStack> itemList = null;
try {
itemList = ItemStackUtil.createItemList(items);
itemList = ItemStackUtil.createItemList(stringList);
} catch (IllegalArgumentException ignored) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class PerkLogic {

public PerkLogic(uSkyBlock plugin, IslandGenerator islandGenerator) {
this.plugin = plugin;
defaultPerk = new Perk(ItemStackUtil.createItemList(""), Settings.general_maxPartySize,
defaultPerk = new Perk(Collections.emptyList(), Settings.general_maxPartySize,
plugin.getConfig().getInt("options.island.spawn-limits.animals", 30),
plugin.getConfig().getInt("options.island.spawn-limits.monsters", 50),
plugin.getConfig().getInt("options.island.spawn-limits.villagers", 16),
Expand Down Expand Up @@ -60,7 +60,7 @@ public PerkLogic(uSkyBlock plugin, IslandGenerator islandGenerator) {
.golems(config.getInt("golems", 0))
.rewBonus(config.getInt("rewardBonus", 0))
.hungerReduction(config.getInt("hungerReduction", 0))
.extraItems(ItemStackUtil.createItemList(config.getString("extraItems", null), config.getStringList("extraItems")))
.extraItems(ItemStackUtil.createItemList(config.getStringList("extraItems")))
.build();
ItemStack itemStack = ItemStackUtil.createItemStack(
config.getString("displayItem", "SAPLING"),
Expand Down Expand Up @@ -127,7 +127,7 @@ private void addDonorPerks(String perm, ConfigurationSection config) {
} else {
// Read leaf
donorPerks.put(perm, new Perk(
ItemStackUtil.createItemList(config.getString("extraItems", null), config.getStringList("extraItems")),
ItemStackUtil.createItemList(config.getStringList("extraItems")),
config.getInt("maxPartySize", defaultPerk.getMaxPartySize()),
config.getInt("animals", defaultPerk.getAnimals()),
config.getInt("monsters", defaultPerk.getMonsters()),
Expand All @@ -145,7 +145,7 @@ private void addExtraPermissionPerks(ConfigurationSection config) {
return;
}
for (String key : config.getKeys(false)) {
List<ItemStack> items = ItemStackUtil.createItemList(config.getString(key, null), config.getStringList(key));
List<ItemStack> items = ItemStackUtil.createItemList(config.getStringList(key));
if (items != null && !items.isEmpty()) {
String perm = "usb." + key;
donorPerks.put(perm, new PerkBuilder(donorPerks.get(perm))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import dk.lockfuglsang.minecraft.command.CommandManager;
import dk.lockfuglsang.minecraft.file.FileUtil;
import dk.lockfuglsang.minecraft.po.I18nUtil;
import dk.lockfuglsang.minecraft.util.TimeUtil;
import dk.lockfuglsang.minecraft.util.VersionUtil;
import dk.lockfuglsang.minecraft.yml.YmlConfiguration;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -35,33 +37,33 @@
import org.bukkit.scheduler.BukkitTask;
import us.talabrek.ultimateskyblock.api.IslandLevel;
import us.talabrek.ultimateskyblock.api.IslandRank;
import us.talabrek.ultimateskyblock.api.async.Callback;
import us.talabrek.ultimateskyblock.api.event.MemberJoinedEvent;
import us.talabrek.ultimateskyblock.api.event.MemberLeftEvent;
import us.talabrek.ultimateskyblock.api.event.uSkyBlockEvent;
import us.talabrek.ultimateskyblock.api.event.uSkyBlockScoreChangedEvent;
import us.talabrek.ultimateskyblock.api.uSkyBlockAPI;
import us.talabrek.ultimateskyblock.api.async.Callback;
import us.talabrek.ultimateskyblock.challenge.ChallengeLogic;
import us.talabrek.ultimateskyblock.chat.ChatEvents;
import us.talabrek.ultimateskyblock.chat.ChatLogic;
import us.talabrek.ultimateskyblock.chat.IslandTalkCommand;
import us.talabrek.ultimateskyblock.chat.PartyTalkCommand;
import us.talabrek.ultimateskyblock.command.AdminCommand;
import us.talabrek.ultimateskyblock.command.ChallengeCommand;
import us.talabrek.ultimateskyblock.command.IslandCommand;
import us.talabrek.ultimateskyblock.chat.IslandTalkCommand;
import us.talabrek.ultimateskyblock.chat.PartyTalkCommand;
import us.talabrek.ultimateskyblock.command.admin.DebugCommand;
import us.talabrek.ultimateskyblock.command.admin.SetMaintenanceCommand;
import us.talabrek.ultimateskyblock.command.island.BiomeCommand;
import us.talabrek.ultimateskyblock.event.ExploitEvents;
import us.talabrek.ultimateskyblock.event.GriefEvents;
import us.talabrek.ultimateskyblock.event.InternalEvents;
import us.talabrek.ultimateskyblock.event.ItemDropEvents;
import us.talabrek.ultimateskyblock.event.MenuEvents;
import us.talabrek.ultimateskyblock.event.NetherTerraFormEvents;
import us.talabrek.ultimateskyblock.event.PlayerEvents;
import us.talabrek.ultimateskyblock.event.SpawnEvents;
import us.talabrek.ultimateskyblock.event.ToolMenuEvents;
import us.talabrek.ultimateskyblock.event.WorldGuardEvents;
import us.talabrek.ultimateskyblock.event.InternalEvents;
import us.talabrek.ultimateskyblock.handler.AsyncWorldEditHandler;
import us.talabrek.ultimateskyblock.handler.ConfirmHandler;
import us.talabrek.ultimateskyblock.handler.CooldownHandler;
Expand All @@ -72,16 +74,16 @@
import us.talabrek.ultimateskyblock.handler.placeholder.PlaceholderHandler;
import us.talabrek.ultimateskyblock.imports.USBImporterExecutor;
import us.talabrek.ultimateskyblock.island.BlockLimitLogic;
import us.talabrek.ultimateskyblock.island.level.AweLevelLogic;
import us.talabrek.ultimateskyblock.island.IslandGenerator;
import us.talabrek.ultimateskyblock.island.IslandInfo;
import us.talabrek.ultimateskyblock.island.IslandLocatorLogic;
import us.talabrek.ultimateskyblock.island.IslandLogic;
import us.talabrek.ultimateskyblock.island.level.IslandScore;
import us.talabrek.ultimateskyblock.island.level.ChunkSnapshotLevelLogic;
import us.talabrek.ultimateskyblock.island.level.LevelLogic;
import us.talabrek.ultimateskyblock.island.LimitLogic;
import us.talabrek.ultimateskyblock.island.OrphanLogic;
import us.talabrek.ultimateskyblock.island.level.AweLevelLogic;
import us.talabrek.ultimateskyblock.island.level.ChunkSnapshotLevelLogic;
import us.talabrek.ultimateskyblock.island.level.IslandScore;
import us.talabrek.ultimateskyblock.island.level.LevelLogic;
import us.talabrek.ultimateskyblock.island.task.CreateIslandTask;
import us.talabrek.ultimateskyblock.island.task.RecalculateRunnable;
import us.talabrek.ultimateskyblock.island.task.SetBiomeTask;
Expand All @@ -100,8 +102,6 @@
import us.talabrek.ultimateskyblock.util.LocationUtil;
import us.talabrek.ultimateskyblock.util.PlayerUtil;
import us.talabrek.ultimateskyblock.util.ServerUtil;
import dk.lockfuglsang.minecraft.util.TimeUtil;
import dk.lockfuglsang.minecraft.util.VersionUtil;
import us.talabrek.ultimateskyblock.uuid.BukkitPlayerDB;
import us.talabrek.ultimateskyblock.uuid.FilePlayerDB;
import us.talabrek.ultimateskyblock.uuid.MemoryPlayerDB;
Expand Down Expand Up @@ -178,6 +178,7 @@ public class uSkyBlock extends JavaPlugin implements uSkyBlockAPI, CommandManage

private volatile boolean maintenanceMode = false;
private BlockLimitLogic blockLimitLogic;
private Metrics metrics;

public uSkyBlock() {
}
Expand Down Expand Up @@ -248,7 +249,9 @@ public void run() {
}
}, getConfig().getLong("init.initDelay", 50L));
try {
Metrics metrics = new Metrics(this);
metrics = new Metrics(this);
metrics.addCustomChart(new Metrics.SimplePie("language", () -> getConfig().getString("language", "en")));
metrics.addCustomChart(new Metrics.SimplePie("radius_and_distance", () -> String.format("(%d,%d)", Settings.island_radius, Settings.island_distance)));
} catch (Exception e) {
log(Level.WARNING, "Failed to submit metrics data", e);
}
Expand Down
6 changes: 3 additions & 3 deletions uSkyBlock-Core/src/main/resources/challenges.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ ranks:
description: Mine from a cobblestone generator.
type: onPlayer
requiredItems:
- COBBLESTONE:6COBBLESTONE;+2
- COBBLESTONE:64;+2
displayItem: COBBLESTONE
lockedDisplayItem: STAINED_GLASS_PANE:7
resetInHours: 12
Expand Down Expand Up @@ -1589,7 +1589,7 @@ ranks:

#===============================================
#
# Here follows the format and explanation for the challenge group and challenges setup. The single commented (#) are the most used settings
# Here follows the format and explanation for the challenge group and challenges setup. The single commented (#) are the most used settings
# while the double commented (##) are optionnal if you like to use those settings.
#
#ranks:
Expand Down Expand Up @@ -1687,4 +1687,4 @@ ranks:
# All commented settings (#) in the above challenges (not the explanation) can be removed to clean up the challenges.yml.
#
# DO NOT CHANGE!
version: 100
version: 26

0 comments on commit 5d17929

Please sign in to comment.