update things

This commit is contained in:
hyperdefined
2025-08-06 19:34:59 -04:00
parent 613957fadf
commit c7540244bc
15 changed files with 59 additions and 80 deletions

View File

@@ -111,7 +111,7 @@
<dependency>
<groupId>com.github.hyperdefined</groupId>
<artifactId>hyperlib</artifactId>
<version>1.0.8</version>
<version>1.0.9</version>
<scope>compile</scope>
</dependency>
</dependencies>

View File

@@ -26,6 +26,7 @@ import lol.hyper.toolstats.events.*;
import lol.hyper.toolstats.tools.*;
import lol.hyper.toolstats.tools.config.ConfigTools;
import lol.hyper.toolstats.tools.config.ConfigUpdater;
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -35,7 +36,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Logger;
public final class ToolStats extends JavaPlugin {
@@ -120,7 +120,7 @@ public final class ToolStats extends JavaPlugin {
public final NamespacedKey originType = new NamespacedKey(this, "origin");
public final int CONFIG_VERSION = 13;
public final Logger logger = this.getLogger();
public final ComponentLogger logger = this.getComponentLogger();
public final File configFile = new File(this.getDataFolder(), "config.yml");
public boolean tokens = false;
public final Set<NamespacedKey> tokenKeys = new HashSet<>();
@@ -244,7 +244,7 @@ public final class ToolStats extends JavaPlugin {
public void loadConfig() {
config = YamlConfiguration.loadConfiguration(configFile);
if (config.getInt("config-version") != CONFIG_VERSION) {
logger.warning("Your config file is outdated! We will try to update it, but you should regenerate it!");
logger.warn("Your config file is outdated! We will try to update it, but you should regenerate it!");
ConfigUpdater configUpdater = new ConfigUpdater(this);
configUpdater.updateConfig();
}

View File

@@ -116,7 +116,7 @@ public class CraftItem implements Listener {
ItemStack newItem = itemStack.clone();
ItemMeta meta = newItem.getItemMeta();
if (meta == null) {
toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats.");
toolStats.logger.warn("{} does NOT have any meta! Unable to update stats.", itemStack);
return null;
}
// get the current time

View File

@@ -83,7 +83,7 @@ public class CreativeEvent implements Listener {
ItemStack newSpawnedItem = itemStack.clone();
ItemMeta meta = newSpawnedItem.getItemMeta();
if (meta == null) {
toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats.");
toolStats.logger.warn("{} does NOT have any meta! Unable to update stats.", itemStack);
return null;
}
// get the current time

View File

@@ -18,7 +18,6 @@
package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;

View File

@@ -123,7 +123,7 @@ public class VillagerTrade implements Listener {
ItemStack newItem = oldItem.clone();
ItemMeta meta = newItem.getItemMeta();
if (meta == null) {
toolStats.logger.warning(newItem + " does NOT have any meta! Unable to update stats.");
toolStats.logger.warn("{} does NOT have any meta! Unable to update stats.", newItem);
return null;
}
long timeCreated = System.currentTimeMillis();

View File

@@ -51,9 +51,9 @@ public class HashMaker {
return hexString.toString();
} catch (NoSuchAlgorithmException exception) {
toolStats.logger.warning("Unable to generate hash for " + player + "!");
toolStats.logger.warning("Generating a random UUID instead.");
exception.printStackTrace();
toolStats.logger.error("Unable to generate hash", exception);
toolStats.logger.warn("Unable to generate hash for {}!", player);
toolStats.logger.warn("Generating a random UUID instead.");
return java.util.UUID.randomUUID().toString();
}
}

View File

@@ -17,7 +17,6 @@
package lol.hyper.toolstats.tools;
import io.papermc.paper.datacomponent.DataComponentType;
import io.papermc.paper.datacomponent.DataComponentTypes;
import lol.hyper.toolstats.ToolStats;
import org.bukkit.Material;

View File

@@ -70,25 +70,6 @@ public class ItemLore {
return itemLore;
}
/**
* Add lore to a given item.
*
* @param itemMeta The item's meta.
* @param newLine The new line to add to the lore.
* @return The new item's lore.
*/
public List<Component> addItemLore(ItemMeta itemMeta, Component newLine) {
List<Component> itemLore;
if (itemMeta.hasLore()) {
itemLore = itemMeta.lore();
itemLore.add(newLine);
} else {
itemLore = new ArrayList<>();
itemLore.add(newLine);
}
return itemLore;
}
/**
* Remove a given lore from an item.
*
@@ -114,7 +95,7 @@ public class ItemLore {
ItemStack clone = playerTool.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
toolStats.logger.warn("{} does NOT have any meta! Unable to update stats.", clone);
return null;
}
// read the current stats from the item
@@ -188,7 +169,7 @@ public class ItemLore {
if (cropsMined == null) {
cropsMined = 0;
toolStats.logger.warning(clone + " does not have valid crops-mined set! Resting to zero. This should NEVER happen.");
toolStats.logger.warn("{} does not have valid crops-mined set! Resting to zero. This should NEVER happen.", clone);
}
container.set(toolStats.cropsHarvested, PersistentDataType.INTEGER, cropsMined + add);
@@ -213,7 +194,7 @@ public class ItemLore {
ItemStack clone = playerTool.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
toolStats.logger.warn("{} does NOT have any meta! Unable to update stats.", clone);
return null;
}
@@ -287,7 +268,7 @@ public class ItemLore {
if (blocksMined == null) {
blocksMined = 0;
toolStats.logger.warning(clone + " does not have valid generic-mined set! Resting to zero. This should NEVER happen.");
toolStats.logger.warn("{} does not have valid generic-mined set! Resting to zero. This should NEVER happen.", clone);
}
container.set(toolStats.blocksMined, PersistentDataType.INTEGER, blocksMined + add);
@@ -312,7 +293,7 @@ public class ItemLore {
ItemStack clone = playerWeapon.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
toolStats.logger.warn("{} does NOT have any meta! Unable to update stats.", clone);
return null;
}
@@ -385,7 +366,7 @@ public class ItemLore {
if (playerKills == null) {
playerKills = 0;
toolStats.logger.warning(clone + " does not have valid player-kills set! Resting to zero. This should NEVER happen.");
toolStats.logger.warn("{} does not have valid player-kills set! Resting to zero. This should NEVER happen.", clone);
}
container.set(toolStats.playerKills, PersistentDataType.INTEGER, playerKills + add);
@@ -410,7 +391,7 @@ public class ItemLore {
ItemStack clone = playerWeapon.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
toolStats.logger.warn("{} does NOT have any meta! Unable to update stats.", clone);
return null;
}
@@ -483,7 +464,7 @@ public class ItemLore {
if (mobKills == null) {
mobKills = 0;
toolStats.logger.warning(clone + " does not have valid mob-kills set! Resting to zero. This should NEVER happen.");
toolStats.logger.warn("{} does not have valid mob-kills set! Resting to zero. This should NEVER happen.", clone);
}
container.set(toolStats.mobKills, PersistentDataType.INTEGER, mobKills + add);
@@ -516,7 +497,7 @@ public class ItemLore {
ItemStack clone = armorPiece.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
toolStats.logger.warn("{} does NOT have any meta! Unable to update stats.", clone);
return null;
}
@@ -589,7 +570,7 @@ public class ItemLore {
if (damageTaken == null) {
damageTaken = 0.0;
toolStats.logger.warning(clone + " does not have valid damage-taken set! Resting to zero. This should NEVER happen.");
toolStats.logger.warn("{} does not have valid damage-taken set! Resting to zero. This should NEVER happen.", clone);
}
container.set(toolStats.armorDamage, PersistentDataType.DOUBLE, damageTaken + damage);
@@ -622,7 +603,7 @@ public class ItemLore {
ItemStack clone = weapon.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
toolStats.logger.warn("{} does NOT have any meta! Unable to update stats.", clone);
return null;
}
@@ -695,7 +676,7 @@ public class ItemLore {
if (damageDone == null) {
damageDone = 0.0;
toolStats.logger.warning(clone + " does not have valid damage-done set! Resting to zero. This should NEVER happen.");
toolStats.logger.warn("{} does not have valid damage-done set! Resting to zero. This should NEVER happen.", clone);
}
container.set(toolStats.damageDone, PersistentDataType.DOUBLE, damageDone + damage);
@@ -720,7 +701,7 @@ public class ItemLore {
ItemStack clone = elytra.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
toolStats.logger.warn("{} does NOT have any meta! Unable to update stats.", clone);
return null;
}
@@ -803,7 +784,7 @@ public class ItemLore {
if (flightTime == null) {
flightTime = 0L;
toolStats.logger.warning(flightTime + " does not have valid flight-time set! Resting to zero. This should NEVER happen.");
toolStats.logger.warn("{} does not have valid flight-time set! Resting to zero. This should NEVER happen.", flightTime);
}
container.set(toolStats.flightTime, PersistentDataType.LONG, flightTime + duration);
@@ -836,7 +817,7 @@ public class ItemLore {
ItemStack clone = shears.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
toolStats.logger.warn("{} does NOT have any meta! Unable to update stats.", clone);
return null;
}
@@ -909,7 +890,7 @@ public class ItemLore {
if (sheepSheared == null) {
sheepSheared = 0;
toolStats.logger.warning(clone + " does not have valid sheared set! Resting to zero. This should NEVER happen.");
toolStats.logger.warn("{} does not have valid sheared set! Resting to zero. This should NEVER happen.", clone);
}
container.set(toolStats.sheepSheared, PersistentDataType.INTEGER, sheepSheared + add);
@@ -934,7 +915,7 @@ public class ItemLore {
ItemStack clone = bow.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
toolStats.logger.warn("{} does NOT have any meta! Unable to update stats.", clone);
return null;
}
@@ -1009,7 +990,7 @@ public class ItemLore {
if (arrowsShot == null) {
arrowsShot = 0;
toolStats.logger.warning(arrowsShot + " does not have valid arrows-shot set! Resting to zero. This should NEVER happen.");
toolStats.logger.warn("{} does not have valid arrows-shot set! Resting to zero. This should NEVER happen.", arrowsShot);
}
container.set(toolStats.arrowsShot, PersistentDataType.INTEGER, arrowsShot + add);
@@ -1034,7 +1015,7 @@ public class ItemLore {
ItemStack clone = fishingRod.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
toolStats.logger.warn("{} does NOT have any meta! Unable to update stats.", clone);
return null;
}
@@ -1107,7 +1088,7 @@ public class ItemLore {
if (fishCaught == null) {
fishCaught = 0;
toolStats.logger.warning(clone + " does not have valid fish-caught set! Resting to zero. This should NEVER happen.");
toolStats.logger.warn("{} does not have valid fish-caught set! Resting to zero. This should NEVER happen.", clone);
}
container.set(toolStats.fishCaught, PersistentDataType.INTEGER, fishCaught + add);

View File

@@ -53,35 +53,35 @@ public class NumberFormat {
// if these config values are missing, use the default ones
if (dateFormat == null) {
dateFormat = "M/dd/yyyy";
toolStats.logger.warning("date-format is missing! Using default American English format.");
toolStats.logger.warn("date-format is missing! Using default American English format.");
}
if (decimalSeparator == null) {
decimalSeparator = ".";
toolStats.logger.warning("number-formats.decimal-separator is missing! Using default \".\" instead.");
toolStats.logger.warn("number-formats.decimal-separator is missing! Using default \".\" instead.");
}
if (commaSeparator == null) {
commaSeparator = ",";
toolStats.logger.warning("number-formats.comma-separator is missing! Using default \",\" instead.");
toolStats.logger.warn("number-formats.comma-separator is missing! Using default \",\" instead.");
}
if (commaFormat == null) {
commaFormat = "#,###";
toolStats.logger.warning("number-formats.comma-format is missing! Using default #,### instead.");
toolStats.logger.warn("number-formats.comma-format is missing! Using default #,### instead.");
}
if (decimalFormat == null) {
decimalFormat = "#,##0.00";
toolStats.logger.warning("number-formats.comma-separator is missing! Using default #,###.00 instead.");
toolStats.logger.warn("number-formats.comma-separator is missing! Using default #,###.00 instead.");
}
// test the date format
try {
DATE_FORMAT = new SimpleDateFormat(dateFormat, Locale.getDefault());
} catch (NullPointerException | IllegalArgumentException exception) {
toolStats.logger.warning("date-format is NOT a valid format! Using default American English format.");
exception.printStackTrace();
toolStats.logger.error("Invalid format or missing format", exception);
toolStats.logger.warn("date-format is NOT a valid format! Using default American English format.");
DATE_FORMAT = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
}
@@ -95,8 +95,8 @@ public class NumberFormat {
try {
COMMA_FORMAT = new DecimalFormat(commaFormat, formatSymbols);
} catch (NullPointerException | IllegalArgumentException exception) {
toolStats.logger.warning("number-formats.comma-format is NOT a valid format! Using default #,### instead.");
exception.printStackTrace();
toolStats.logger.error("Invalid comma or missing format", exception);
toolStats.logger.warn("number-formats.comma-format is NOT a valid format! Using default #,### instead.");
COMMA_FORMAT = new DecimalFormat("#,###", formatSymbols);
}
@@ -104,8 +104,8 @@ public class NumberFormat {
try {
DECIMAL_FORMAT = new DecimalFormat(decimalFormat, formatSymbols);
} catch (NullPointerException | IllegalArgumentException exception) {
toolStats.logger.warning("number-formats.decimal-format is NOT a valid format! Using default #,###.00 instead.");
exception.printStackTrace();
toolStats.logger.error("Invalid decimal or missing format", exception);
toolStats.logger.warn("number-formats.decimal-format is NOT a valid format! Using default #,###.00 instead.");
DECIMAL_FORMAT = new DecimalFormat("#,###.00", formatSymbols);
}
}

View File

@@ -154,14 +154,14 @@ public class TokenData {
String materialFromConfig = tokenConfig.getString("material");
if (materialFromConfig == null) {
toolStats.logger.warning("Could not find material config for token " + tokenType);
toolStats.logger.warning("Using PAPER as default.");
toolStats.logger.warn("Could not find material config for token {}", tokenType);
toolStats.logger.warn("Using PAPER as default.");
materialFromConfig = "PAPER";
}
Material material = Material.getMaterial(materialFromConfig);
if (material == null) {
toolStats.logger.warning("Material " + materialFromConfig + " is not a valid Minecraft material.");
toolStats.logger.warning("Using PAPER as default.");
toolStats.logger.warn("Material {} is not a valid Minecraft material.", materialFromConfig);
toolStats.logger.warn("Using PAPER as default.");
material = Material.PAPER;
}
@@ -185,9 +185,9 @@ public class TokenData {
String type = tokenConfig.getString("custom-model-data.type");
Object value = tokenConfig.get("custom-model-data.value");
if (type == null || value == null) {
toolStats.logger.info("Could not find custom model data for token " + tokenType);
toolStats.logger.info("Type: " + type);
toolStats.logger.info("Value: " + value);
toolStats.logger.info("Could not find custom model data for token {}", tokenType);
toolStats.logger.info("Type: {}", type);
toolStats.logger.info("Value: {}", value);
return null;
}
CustomModelData data = setData(type, value);
@@ -208,7 +208,7 @@ public class TokenData {
try {
f = Float.parseFloat(data.toString());
} catch (NumberFormatException e) {
toolStats.logger.info(data + " is not a valid float!");
toolStats.logger.info("{} is not a valid float!", data);
return null;
}
return CustomModelData.customModelData().addFloat(f).build();
@@ -217,7 +217,7 @@ public class TokenData {
return CustomModelData.customModelData().addString(data.toString()).build();
}
default: {
toolStats.logger.info(data + " is not a valid data type!");
toolStats.logger.info("{} is not a valid data type!", data);
return null;
}
}

View File

@@ -46,7 +46,7 @@ public class ConfigTools {
*/
public boolean checkConfig(Material material, String configName) {
if (toolStats.config.getConfigurationSection("enabled." + configName) == null) {
toolStats.logger.warning("Missing config section for enabled" + configName);
toolStats.logger.warn("Missing config section for enabled{}", configName);
return false;
}
@@ -104,7 +104,7 @@ public class ConfigTools {
public Component formatLore(String configName, String placeHolder, Object value) {
String lore = toolStats.config.getString("messages." + configName);
if (lore == null) {
toolStats.logger.warning("Unable to find config message for: messages." + configName);
toolStats.logger.warn("Unable to find config message for: messages.{}", configName);
return null;
}
@@ -135,7 +135,7 @@ public class ConfigTools {
public Component formatLoreMultiplePlaceholders(String configName, Map<String, String> placeHoldersValues) {
String lore = toolStats.config.getString("messages." + configName);
if (lore == null) {
toolStats.logger.warning("Unable to find config message for: messages." + configName);
toolStats.logger.warn("Unable to find config message for: messages.{}", configName);
return null;
}

View File

@@ -110,7 +110,7 @@ public class Version12 {
}
private void transfer(String oldSection, String newSection) {
toolStats.logger.info("Moving " + oldSection + " to " + newSection);
toolStats.logger.info("Moving {} to {}", oldSection, newSection);
ConfigurationSection old = toolStats.config.getConfigurationSection(oldSection);
toolStats.config.set(newSection, old);
}

View File

@@ -51,13 +51,13 @@ public class Version13 {
toolStats.config.set("config-version", 13);
for (String key : toolStats.config.getConfigurationSection("tokens.data").getKeys(false)) {
toolStats.logger.info("Adding tokens.data." + key + ".material");
toolStats.logger.info("Adding tokens.data.{}.material", key);
toolStats.config.set("tokens.data." + key + ".material", "PAPER");
toolStats.logger.info("Adding tokens.data." + key + ".custom-model-data.enabled");
toolStats.logger.info("Adding tokens.data.{}.custom-model-data.enabled", key);
toolStats.config.set("tokens.data." + key + ".custom-model-data.enabled", false);
toolStats.logger.info("Adding tokens.data." + key + ".custom-model-data.type");
toolStats.logger.info("Adding tokens.data.{}.custom-model-data.type", key);
toolStats.config.set("tokens.data." + key + ".custom-model-data.type", "float");
toolStats.logger.info("Adding tokens.data." + key + ".custom-model-data.value");
toolStats.logger.info("Adding tokens.data.{}.custom-model-data.value", key);
toolStats.config.set("tokens.data." + key + ".custom-model-data.value", 1001);
}

View File

@@ -93,7 +93,7 @@ public class Version9 {
* @param lore The lore of the item.
*/
private void addToken(String tokenType, String title, String lore) {
toolStats.logger.info("Adding token type configuration for " + tokenType);
toolStats.logger.info("Adding token type configuration for {}", tokenType);
toolStats.config.set("tokens.data." + tokenType + ".title", title);
List<String> loreList = new ArrayList<>();
loreList.add(lore);