!Added config update for newest crafting station API and config rework

This commit is contained in:
Indyuce 2020-02-15 14:21:19 +01:00
parent 2aa75c4c3e
commit e9bc67de3c
2 changed files with 66 additions and 5 deletions

View File

@ -149,7 +149,7 @@ public class MMOItemsCommand implements CommandExecutor {
}
sender.sendMessage("");
sender.sendMessage(ChatColor.YELLOW + "Use " + ChatColor.GOLD + "/mi update " + update.getId() + ChatColor.YELLOW + " to apply this config update.");
sender.sendMessage(ChatColor.YELLOW + "Use " + ChatColor.GOLD + "/mi update apply " + update.getId() + ChatColor.YELLOW + " to apply this config update.");
}
if (args[1].equalsIgnoreCase("list")) {
@ -176,7 +176,7 @@ public class MMOItemsCommand implements CommandExecutor {
if (id != Integer.parseInt(args[3]))
throw new NumberFormatException();
} catch (NumberFormatException exception) {
sender.sendMessage(ChatColor.RED + "Specified IDs do not match.");
sender.sendMessage(ChatColor.RED + "Update IDs do not match. Make sure you enter twice the same ID to confirm you want to apply this update.");
return true;
}
@ -188,7 +188,7 @@ public class MMOItemsCommand implements CommandExecutor {
PluginUpdate update = MMOItems.plugin.getUpdates().get(id);
sender.sendMessage(ChatColor.YELLOW + "Applying config update " + id + "...");
update.apply(sender);
sender.sendMessage(ChatColor.YELLOW + "Config update " + id + " was successfully applied.");
sender.sendMessage(ChatColor.YELLOW + "Config update " + id + " was successfully applied. Check the console for potential update error logs.");
}
}
// ==================================================================================================================================

View File

@ -1,11 +1,18 @@
package net.Indyuce.mmoitems.manager;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ConfigFile;
@ -21,7 +28,7 @@ public class PluginUpdateManager {
private Map<Integer, PluginUpdate> updates = new HashMap<>();
public PluginUpdateManager() {
register(new PluginUpdate(1, new String[] { "Applies a fix for skull textures values in 4.7.1.", "Texture values data storage changed in 4.7.1 due to the UUID change." }, (sender) -> {
register(new PluginUpdate(1, new String[] { "Applies a fix for skull textures values in 4.7.1.", "Texture values data storage changed in 4.7.1 due to the UUID change." }, sender -> {
for (Type type : MMOItems.plugin.getTypes().getAll()) {
ConfigFile config = type.getConfigFile();
@ -37,7 +44,61 @@ public class PluginUpdateManager {
}
}));
register(new PluginUpdate(2, new String[] { "Enables the item updater for every item.", "&cNot recommended unless you know what you are doing." }, (sender) -> {
register(new PluginUpdate(3, new String[] { "5.3.2: converts all your crafting station recipes to the newest config format.", "&cWarning, running this update will get rid of your # config file comments." }, sender -> {
for (File file : new File(MMOItems.plugin.getDataFolder() + "\\crafting-stations").listFiles()) {
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
if (config.contains("recipes"))
for (String key : config.getConfigurationSection("recipes").getKeys(false))
try {
List<String> ingredients = config.getStringList("recipes." + key + ".ingredients");
List<String> newest = new ArrayList<String>();
for (String ingredient : ingredients) {
String[] split = ingredient.split("\\ ");
if (split[0].equals("mmoitem")) {
String format = "mmoitem{material=\"" + split[1] + "\",id=\"" + split[2] + "\"";
if (split.length > 3)
format += ",amount=" + split[3];
if (split.length > 4)
format += ",display=\"" + split[4] + "\"";
newest.add(format + "}");
}
else if (split[0].equals("vanilla")) {
String format = "vanilla{type=\"" + split[1] + "\"";
if (split.length > 2 && !split[2].equals("."))
format += ",display=\"" + split[2] + "\"";
if (split.length > 3)
format += "amount=" + split[3];
if (split.length > 4)
format += "display=\"" + split[4] + "\"";
newest.add(format + "}");
}
else {
MMOItems.plugin.getLogger().log(Level.INFO, "Config Update 3: Could not match ingredient from '" + ingredient + "' from recipe '" + key + "', added it anyway.");
newest.add(ingredient);
}
}
config.set("recipes." + key + ".ingredients", newest);
} catch (Exception exception) {
MMOItems.plugin.getLogger().log(Level.INFO, "Config Update 3: Could not convert recipe with key '" + key + "': " + exception.getMessage());
}
try {
config.save(file);
} catch (IOException exception) {
MMOItems.plugin.getLogger().log(Level.INFO, "Config Update 3: Could not save config '" + file.getName() + "': " + exception.getMessage());
}
}
}));
register(new PluginUpdate(2, new String[] { "Enables the item updater for every item.", "&cNot recommended unless you know what you are doing." }, sender -> {
for (Type type : MMOItems.plugin.getTypes().getAll())
for (String id : type.getConfigFile().getConfig().getKeys(false)) {
String itemPath = type.getId() + "." + id;