mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
added a config updater
This commit is contained in:
@@ -21,10 +21,7 @@ import lol.hyper.githubreleaseapi.GitHubRelease;
|
||||
import lol.hyper.githubreleaseapi.GitHubReleaseAPI;
|
||||
import lol.hyper.toolstats.commands.CommandToolStats;
|
||||
import lol.hyper.toolstats.events.*;
|
||||
import lol.hyper.toolstats.tools.HashMaker;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import lol.hyper.toolstats.tools.ItemLore;
|
||||
import lol.hyper.toolstats.tools.NumberFormat;
|
||||
import lol.hyper.toolstats.tools.*;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.*;
|
||||
@@ -180,8 +177,11 @@ public final class ToolStats extends JavaPlugin {
|
||||
|
||||
public void loadConfig() {
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
logger.info(String.valueOf(config.getInt("config-version")));
|
||||
if (config.getInt("config-version") != CONFIG_VERSION) {
|
||||
logger.warning("Your config file is outdated! Please regenerate the config.");
|
||||
logger.warning("Your config file is outdated! We will try to update it, but you should regenerate it!");
|
||||
ConfigUpdater configUpdater = new ConfigUpdater(this);
|
||||
configUpdater.updateConfig();
|
||||
}
|
||||
|
||||
numberFormat = new NumberFormat(this);
|
||||
@@ -220,24 +220,21 @@ public final class ToolStats extends JavaPlugin {
|
||||
public boolean checkConfig(Material material, String configName) {
|
||||
String itemName = material.toString().toLowerCase();
|
||||
String itemType = null;
|
||||
if (itemName.contains("bow") || itemName.contains("shears") || itemName.contains("trident")) {
|
||||
if (itemName.contains("bow")) {
|
||||
// hardcode these
|
||||
if (material == Material.BOW || material == Material.SHEARS || material == Material.TRIDENT) {
|
||||
if (material == Material.BOW) {
|
||||
itemType = "bow";
|
||||
}
|
||||
if (itemName.contains("shears")) {
|
||||
if (material == Material.SHEARS) {
|
||||
itemType = "shears";
|
||||
}
|
||||
if (itemName.contains("trident")) {
|
||||
if (material == Material.TRIDENT) {
|
||||
itemType = "trident";
|
||||
}
|
||||
} else {
|
||||
itemType = itemName.substring(itemName.indexOf('_') + 1);
|
||||
}
|
||||
|
||||
if (itemType == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (itemType) {
|
||||
case "pickaxe": {
|
||||
return config.getBoolean("enabled." + configName + ".pickaxe");
|
||||
|
||||
@@ -75,7 +75,6 @@ public class PlayerJoin implements Listener {
|
||||
continue;
|
||||
}
|
||||
String hash = toolStats.hashMaker.makeHash(itemStack.getType(), owner, timestamp);
|
||||
toolStats.logger.info(hash);
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
}
|
||||
|
||||
|
||||
63
src/main/java/lol/hyper/toolstats/tools/ConfigUpdater.java
Normal file
63
src/main/java/lol/hyper/toolstats/tools/ConfigUpdater.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is part of ToolStats.
|
||||
*
|
||||
* ToolStats is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ToolStats is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package lol.hyper.toolstats.tools;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ConfigUpdater {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public ConfigUpdater(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
public void updateConfig() {
|
||||
// get a copy of the current config
|
||||
FileConfiguration newConfig = toolStats.config;
|
||||
int version = newConfig.getInt("config-version");
|
||||
|
||||
if (version == 5) {
|
||||
newConfig.set("config-version", 6);
|
||||
newConfig.set("enabled.spawned-in.pickaxe", true);
|
||||
newConfig.set("enabled.spawned-in.sword", true);
|
||||
newConfig.set("enabled.spawned-in.shovel", true);
|
||||
newConfig.set("enabled.spawned-in.axe", true);
|
||||
newConfig.set("enabled.spawned-in.hoe", true);
|
||||
newConfig.set("enabled.spawned-in.shears", true);
|
||||
newConfig.set("enabled.spawned-in.bow", true);
|
||||
newConfig.set("enabled.spawned-in.armor", true);
|
||||
newConfig.set("messages.spawned.spawned-by", "&7Spawned in by: &8{player}");
|
||||
newConfig.set("messages.spawned.spawned-on", "&7Spawned on: &8{date}");
|
||||
newConfig.set("generate-hash-for-items", "true");
|
||||
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-5.yml");
|
||||
newConfig.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config.yml");
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
toolStats.loadConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,10 +59,6 @@ public class ItemChecker {
|
||||
validItems.addAll(armorItems);
|
||||
validItems.addAll(meleeItems);
|
||||
validItems.addAll(mineItems);
|
||||
|
||||
for (Material material : validItems) {
|
||||
System.out.println(material);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user