mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
Compare commits
13 Commits
c0d79fd740
...
1.9.10
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c28ee0fb8c | ||
|
|
8fe7292505 | ||
|
|
3da74fe656 | ||
|
|
ab0d2a1ca1 | ||
|
|
857ce5b631 | ||
|
|
b14fb30212 | ||
|
|
a9bb876b38 | ||
|
|
e819fadd50 | ||
|
|
c22c36f0a4 | ||
|
|
e38ffdef07 | ||
|
|
c7540244bc | ||
|
|
613957fadf | ||
|
|
e48be6ba20 |
@@ -7,6 +7,7 @@
|
|||||||
<a href="https://docs.hyper.lol/plugins/toolstats/about/"><img alt="ghpages" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/documentation/ghpages_vector.svg"></a>
|
<a href="https://docs.hyper.lol/plugins/toolstats/about/"><img alt="ghpages" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/documentation/ghpages_vector.svg"></a>
|
||||||
<a href="https://discord.gg/rJuQXVcJz8"><img alt="discord-singular" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/social/discord-singular_vector.svg"></a>
|
<a href="https://discord.gg/rJuQXVcJz8"><img alt="discord-singular" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/social/discord-singular_vector.svg"></a>
|
||||||
<a href="https://buymeacoffee.com/hyperdefined"><img alt="buymeacoffee-singular" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/donate/buymeacoffee-singular_vector.svg"></a>
|
<a href="https://buymeacoffee.com/hyperdefined"><img alt="buymeacoffee-singular" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/donate/buymeacoffee-singular_vector.svg"></a>
|
||||||
|
<a href="https://patreon.com/hyperdefined"><img alt="patreon-singular" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/donate/patreon-singular_vector.svg"></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
ToolStats is a Paper plugin that display various stats about tools. This plugin is inspired off of [GearStats](https://www.spigotmc.org/resources/gearstats.12960/). You can either track all statistics by default, or a use a token system to add statistics to tool/armor. You can configure how each statistic is shown on the item, or disable it!
|
ToolStats is a Paper plugin that display various stats about tools. This plugin is inspired off of [GearStats](https://www.spigotmc.org/resources/gearstats.12960/). You can either track all statistics by default, or a use a token system to add statistics to tool/armor. You can configure how each statistic is shown on the item, or disable it!
|
||||||
@@ -15,7 +16,7 @@ Here is everything it tracks:
|
|||||||
* Blocks mined (pickaxes, shovels, axes, hoes, shears).
|
* Blocks mined (pickaxes, shovels, axes, hoes, shears).
|
||||||
* Crops mined (hoes).
|
* Crops mined (hoes).
|
||||||
* Player/mob kills (swords, axes, tridents, bows/crossbows, mace).
|
* Player/mob kills (swords, axes, tridents, bows/crossbows, mace).
|
||||||
* Ownership of items when crafted, looted (from chests), traded, spawned via creative, and caught from fishing.
|
* Ownership of items when crafted, looted (from chests/vaults/barrels), traded, spawned via creative, and caught from fishing.
|
||||||
* Armor damage taken.
|
* Armor damage taken.
|
||||||
* Damage done with weapons.
|
* Damage done with weapons.
|
||||||
* Fish caught.
|
* Fish caught.
|
||||||
|
|||||||
32
pom.xml
32
pom.xml
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
<groupId>lol.hyper</groupId>
|
<groupId>lol.hyper</groupId>
|
||||||
<artifactId>toolstats</artifactId>
|
<artifactId>toolstats</artifactId>
|
||||||
<version>1.9.9</version>
|
<version>1.9.10</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>ToolStats</name>
|
<name>ToolStats</name>
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.14.0</version>
|
<version>3.14.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${java.version}</source>
|
<source>${java.version}</source>
|
||||||
<target>${java.version}</target>
|
<target>${java.version}</target>
|
||||||
@@ -60,16 +60,12 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.6.0</version>
|
<version>3.6.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<relocations>
|
<relocations>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>org.bstats</pattern>
|
<pattern>lol.hyper.hyperlib</pattern>
|
||||||
<shadedPattern>lol.hyper.toolstats.bstats</shadedPattern>
|
<shadedPattern>lol.hyper.toolstats.hyperlib</shadedPattern>
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>lol.hyper.githubreleaseapi</pattern>
|
|
||||||
<shadedPattern>lol.hyper.toolstats.updater</shadedPattern>
|
|
||||||
</relocation>
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -99,25 +95,23 @@
|
|||||||
<id>papermc</id>
|
<id>papermc</id>
|
||||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>jitpack.io</id>
|
||||||
|
<url>https://jitpack.io</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.papermc.paper</groupId>
|
<groupId>io.papermc.paper</groupId>
|
||||||
<artifactId>paper-api</artifactId>
|
<artifactId>paper-api</artifactId>
|
||||||
<version>1.21.7-R0.1-SNAPSHOT</version>
|
<version>1.21.10-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bstats</groupId>
|
<groupId>com.github.hyperdefined</groupId>
|
||||||
<artifactId>bstats-bukkit</artifactId>
|
<artifactId>hyperlib</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>1.0.9</version>
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>lol.hyper</groupId>
|
|
||||||
<artifactId>github-release-api</artifactId>
|
|
||||||
<version>1.0.5</version>
|
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -17,15 +17,16 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats;
|
package lol.hyper.toolstats;
|
||||||
|
|
||||||
import lol.hyper.githubreleaseapi.GitHubRelease;
|
import lol.hyper.hyperlib.HyperLib;
|
||||||
import lol.hyper.githubreleaseapi.GitHubReleaseAPI;
|
import lol.hyper.hyperlib.bstats.HyperStats;
|
||||||
import lol.hyper.githubreleaseapi.ReleaseNotFoundException;
|
import lol.hyper.hyperlib.releases.HyperUpdater;
|
||||||
|
import lol.hyper.hyperlib.utils.TextUtils;
|
||||||
import lol.hyper.toolstats.commands.CommandToolStats;
|
import lol.hyper.toolstats.commands.CommandToolStats;
|
||||||
import lol.hyper.toolstats.events.*;
|
import lol.hyper.toolstats.events.*;
|
||||||
import lol.hyper.toolstats.tools.*;
|
import lol.hyper.toolstats.tools.*;
|
||||||
import lol.hyper.toolstats.tools.config.ConfigTools;
|
import lol.hyper.toolstats.tools.config.ConfigTools;
|
||||||
import lol.hyper.toolstats.tools.config.ConfigUpdater;
|
import lol.hyper.toolstats.tools.config.ConfigUpdater;
|
||||||
import org.bstats.bukkit.Metrics;
|
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
@@ -33,10 +34,8 @@ import org.bukkit.inventory.ShapedRecipe;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
public final class ToolStats extends JavaPlugin {
|
public final class ToolStats extends JavaPlugin {
|
||||||
|
|
||||||
@@ -121,7 +120,7 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
public final NamespacedKey originType = new NamespacedKey(this, "origin");
|
public final NamespacedKey originType = new NamespacedKey(this, "origin");
|
||||||
|
|
||||||
public final int CONFIG_VERSION = 13;
|
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 final File configFile = new File(this.getDataFolder(), "config.yml");
|
||||||
public boolean tokens = false;
|
public boolean tokens = false;
|
||||||
public final Set<NamespacedKey> tokenKeys = new HashSet<>();
|
public final Set<NamespacedKey> tokenKeys = new HashSet<>();
|
||||||
@@ -152,9 +151,20 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
public TokenData tokenData;
|
public TokenData tokenData;
|
||||||
public AnvilEvent anvilEvent;
|
public AnvilEvent anvilEvent;
|
||||||
public PrepareCraft prepareCraft;
|
public PrepareCraft prepareCraft;
|
||||||
|
public BlockDispenseEvent blockDispenseEvent;
|
||||||
|
public HyperLib hyperLib;
|
||||||
|
public TextUtils textUtils;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
hyperLib = new HyperLib(this);
|
||||||
|
hyperLib.setup();
|
||||||
|
|
||||||
|
HyperStats stats = new HyperStats(hyperLib, 14110);
|
||||||
|
stats.setup();
|
||||||
|
|
||||||
|
textUtils = new TextUtils(hyperLib);
|
||||||
|
|
||||||
if (!configFile.exists()) {
|
if (!configFile.exists()) {
|
||||||
this.saveResource("config.yml", true);
|
this.saveResource("config.yml", true);
|
||||||
logger.info("Copying default config!");
|
logger.info("Copying default config!");
|
||||||
@@ -192,6 +202,7 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
shootBow = new ShootBow(this);
|
shootBow = new ShootBow(this);
|
||||||
anvilEvent = new AnvilEvent(this);
|
anvilEvent = new AnvilEvent(this);
|
||||||
prepareCraft = new PrepareCraft(this);
|
prepareCraft = new PrepareCraft(this);
|
||||||
|
blockDispenseEvent = new BlockDispenseEvent(this);
|
||||||
|
|
||||||
// save which stat can be used by a reset token
|
// save which stat can be used by a reset token
|
||||||
tokenKeys.add(blocksMined);
|
tokenKeys.add(blocksMined);
|
||||||
@@ -222,17 +233,21 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
Bukkit.getServer().getPluginManager().registerEvents(playerMove, this);
|
Bukkit.getServer().getPluginManager().registerEvents(playerMove, this);
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(anvilEvent, this);
|
Bukkit.getServer().getPluginManager().registerEvents(anvilEvent, this);
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(prepareCraft, this);
|
Bukkit.getServer().getPluginManager().registerEvents(prepareCraft, this);
|
||||||
|
Bukkit.getServer().getPluginManager().registerEvents(blockDispenseEvent, this);
|
||||||
|
|
||||||
this.getCommand("toolstats").setExecutor(commandToolStats);
|
this.getCommand("toolstats").setExecutor(commandToolStats);
|
||||||
|
|
||||||
new Metrics(this, 14110);
|
HyperUpdater updater = new HyperUpdater(hyperLib);
|
||||||
Bukkit.getAsyncScheduler().runNow(this, scheduledTask -> checkForUpdates());
|
updater.setGitHub("hyperdefined", "ToolStats");
|
||||||
|
updater.setModrinth("oBZj9E15");
|
||||||
|
updater.setHangar("ToolStats", "paper");
|
||||||
|
updater.check();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadConfig() {
|
public void loadConfig() {
|
||||||
config = YamlConfiguration.loadConfiguration(configFile);
|
config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
if (config.getInt("config-version") != CONFIG_VERSION) {
|
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 configUpdater = new ConfigUpdater(this);
|
||||||
configUpdater.updateConfig();
|
configUpdater.updateConfig();
|
||||||
}
|
}
|
||||||
@@ -247,29 +262,4 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
|
|
||||||
numberFormat = new NumberFormat(this);
|
numberFormat = new NumberFormat(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkForUpdates() {
|
|
||||||
GitHubReleaseAPI api;
|
|
||||||
try {
|
|
||||||
api = new GitHubReleaseAPI("ToolStats", "hyperdefined");
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.warning("Unable to check updates!");
|
|
||||||
e.printStackTrace();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
GitHubRelease current;
|
|
||||||
try {
|
|
||||||
current = api.getReleaseByTag(this.getPluginMeta().getVersion());
|
|
||||||
} catch (ReleaseNotFoundException e) {
|
|
||||||
logger.warning("You are running a version that does not exist on GitHub. If you are in a dev environment, you can ignore this. Otherwise, this is a bug!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
GitHubRelease latest = api.getLatestVersion();
|
|
||||||
int buildsBehind = api.getBuildsBehind(current);
|
|
||||||
if (buildsBehind == 0) {
|
|
||||||
logger.info("You are running the latest version.");
|
|
||||||
} else {
|
|
||||||
logger.warning("A new version is available (" + latest.getTagVersion() + ")! You are running version " + current.getTagVersion() + ". You are " + buildsBehind + " version(s) behind.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,12 +17,11 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats.commands;
|
package lol.hyper.toolstats.commands;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
package lol.hyper.toolstats.events;
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
|
|||||||
141
src/main/java/lol/hyper/toolstats/events/BlockDispenseEvent.java
Normal file
141
src/main/java/lol/hyper/toolstats/events/BlockDispenseEvent.java
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
/*
|
||||||
|
* 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.events;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockDispenseLootEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class BlockDispenseEvent implements Listener {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
public BlockDispenseEvent(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onDispense(BlockDispenseLootEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
if (player == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ItemStack> loot = event.getDispensedLoot();
|
||||||
|
// probably won't ever happen
|
||||||
|
if (loot.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ItemStack> newLoot = new ArrayList<>();
|
||||||
|
for (ItemStack lootItem : loot) {
|
||||||
|
ItemStack newLootItem = lootItem.clone();
|
||||||
|
Material lootItemMaterial = newLootItem.getType();
|
||||||
|
// if the item is one we want, do stuff
|
||||||
|
if (toolStats.itemChecker.isValidItem(lootItemMaterial)) {
|
||||||
|
newLootItem = addLootedOrigin(newLootItem, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the item returned null, add the original item
|
||||||
|
newLoot.add(Objects.requireNonNullElse(newLootItem, lootItem));
|
||||||
|
}
|
||||||
|
event.setDispensedLoot(newLoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds lore to newly generated items.
|
||||||
|
*
|
||||||
|
* @param itemStack The item to add lore to.
|
||||||
|
* @param owner The player that found the item.
|
||||||
|
* @return The item with the lore.
|
||||||
|
*/
|
||||||
|
private ItemStack addLootedOrigin(ItemStack itemStack, Player owner) {
|
||||||
|
ItemStack newItem = itemStack.clone();
|
||||||
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
|
if (meta == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
long timeCreated = System.currentTimeMillis();
|
||||||
|
Date finalDate;
|
||||||
|
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||||
|
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||||
|
timeCreated = finalDate.getTime();
|
||||||
|
}
|
||||||
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the current lore the item
|
||||||
|
List<Component> lore;
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
lore = meta.lore();
|
||||||
|
} else {
|
||||||
|
lore = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// if creation date is enabled, add it
|
||||||
|
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 2, newItem);
|
||||||
|
if (creationDate != null) {
|
||||||
|
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
||||||
|
lore.add(creationDate);
|
||||||
|
meta.lore(lore);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if ownership is enabled, add it
|
||||||
|
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 2, newItem);
|
||||||
|
if (itemOwner != null) {
|
||||||
|
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
||||||
|
lore.add(itemOwner);
|
||||||
|
meta.lore(lore);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if hash is enabled, add it
|
||||||
|
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||||
|
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||||
|
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
newItem.setItemMeta(meta);
|
||||||
|
return newItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats.events;
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -116,7 +116,7 @@ public class CraftItem implements Listener {
|
|||||||
ItemStack newItem = itemStack.clone();
|
ItemStack newItem = itemStack.clone();
|
||||||
ItemMeta meta = newItem.getItemMeta();
|
ItemMeta meta = newItem.getItemMeta();
|
||||||
if (meta == null) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
// get the current time
|
// get the current time
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats.events;
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -83,7 +83,7 @@ public class CreativeEvent implements Listener {
|
|||||||
ItemStack newSpawnedItem = itemStack.clone();
|
ItemStack newSpawnedItem = itemStack.clone();
|
||||||
ItemMeta meta = newSpawnedItem.getItemMeta();
|
ItemMeta meta = newSpawnedItem.getItemMeta();
|
||||||
if (meta == null) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
// get the current time
|
// get the current time
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
package lol.hyper.toolstats.events;
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats.events;
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats.events;
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats.events;
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats.events;
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ package lol.hyper.toolstats.events;
|
|||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -31,6 +31,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -62,7 +63,8 @@ public class PlayerInteract implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// store when a player opens a chest
|
// store when a player opens a chest
|
||||||
if (block.getType() != Material.AIR && block.getType() == Material.CHEST) {
|
BlockState state = block.getState();
|
||||||
|
if (state instanceof InventoryHolder) {
|
||||||
openedChests.put(block, player);
|
openedChests.put(block, player);
|
||||||
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> openedChests.remove(block), 20);
|
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> openedChests.remove(block), 20);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats.events;
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
package lol.hyper.toolstats.events;
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats.events;
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -123,7 +123,7 @@ public class VillagerTrade implements Listener {
|
|||||||
ItemStack newItem = oldItem.clone();
|
ItemStack newItem = oldItem.clone();
|
||||||
ItemMeta meta = newItem.getItemMeta();
|
ItemMeta meta = newItem.getItemMeta();
|
||||||
if (meta == null) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
long timeCreated = System.currentTimeMillis();
|
long timeCreated = System.currentTimeMillis();
|
||||||
|
|||||||
@@ -51,9 +51,9 @@ public class HashMaker {
|
|||||||
|
|
||||||
return hexString.toString();
|
return hexString.toString();
|
||||||
} catch (NoSuchAlgorithmException exception) {
|
} catch (NoSuchAlgorithmException exception) {
|
||||||
toolStats.logger.warning("Unable to generate hash for " + player + "!");
|
toolStats.logger.error("Unable to generate hash", exception);
|
||||||
toolStats.logger.warning("Generating a random UUID instead.");
|
toolStats.logger.warn("Unable to generate hash for {}!", player);
|
||||||
exception.printStackTrace();
|
toolStats.logger.warn("Generating a random UUID instead.");
|
||||||
return java.util.UUID.randomUUID().toString();
|
return java.util.UUID.randomUUID().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats.tools;
|
package lol.hyper.toolstats.tools;
|
||||||
|
|
||||||
import io.papermc.paper.datacomponent.DataComponentType;
|
|
||||||
import io.papermc.paper.datacomponent.DataComponentTypes;
|
import io.papermc.paper.datacomponent.DataComponentTypes;
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|||||||
@@ -17,13 +17,11 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats.tools;
|
package lol.hyper.toolstats.tools;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.event.ClickEvent;
|
|
||||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.inventory.PrepareAnvilEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
@@ -72,25 +70,6 @@ public class ItemLore {
|
|||||||
return 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.
|
* Remove a given lore from an item.
|
||||||
*
|
*
|
||||||
@@ -116,7 +95,7 @@ public class ItemLore {
|
|||||||
ItemStack clone = playerTool.clone();
|
ItemStack clone = playerTool.clone();
|
||||||
ItemMeta meta = clone.getItemMeta();
|
ItemMeta meta = clone.getItemMeta();
|
||||||
if (meta == null) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
// read the current stats from the item
|
// read the current stats from the item
|
||||||
@@ -190,7 +169,7 @@ public class ItemLore {
|
|||||||
|
|
||||||
if (cropsMined == null) {
|
if (cropsMined == null) {
|
||||||
cropsMined = 0;
|
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);
|
container.set(toolStats.cropsHarvested, PersistentDataType.INTEGER, cropsMined + add);
|
||||||
@@ -215,7 +194,7 @@ public class ItemLore {
|
|||||||
ItemStack clone = playerTool.clone();
|
ItemStack clone = playerTool.clone();
|
||||||
ItemMeta meta = clone.getItemMeta();
|
ItemMeta meta = clone.getItemMeta();
|
||||||
if (meta == null) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,7 +268,7 @@ public class ItemLore {
|
|||||||
|
|
||||||
if (blocksMined == null) {
|
if (blocksMined == null) {
|
||||||
blocksMined = 0;
|
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);
|
container.set(toolStats.blocksMined, PersistentDataType.INTEGER, blocksMined + add);
|
||||||
@@ -314,7 +293,7 @@ public class ItemLore {
|
|||||||
ItemStack clone = playerWeapon.clone();
|
ItemStack clone = playerWeapon.clone();
|
||||||
ItemMeta meta = clone.getItemMeta();
|
ItemMeta meta = clone.getItemMeta();
|
||||||
if (meta == null) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,7 +366,7 @@ public class ItemLore {
|
|||||||
|
|
||||||
if (playerKills == null) {
|
if (playerKills == null) {
|
||||||
playerKills = 0;
|
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);
|
container.set(toolStats.playerKills, PersistentDataType.INTEGER, playerKills + add);
|
||||||
@@ -412,7 +391,7 @@ public class ItemLore {
|
|||||||
ItemStack clone = playerWeapon.clone();
|
ItemStack clone = playerWeapon.clone();
|
||||||
ItemMeta meta = clone.getItemMeta();
|
ItemMeta meta = clone.getItemMeta();
|
||||||
if (meta == null) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -485,7 +464,7 @@ public class ItemLore {
|
|||||||
|
|
||||||
if (mobKills == null) {
|
if (mobKills == null) {
|
||||||
mobKills = 0;
|
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);
|
container.set(toolStats.mobKills, PersistentDataType.INTEGER, mobKills + add);
|
||||||
@@ -518,7 +497,7 @@ public class ItemLore {
|
|||||||
ItemStack clone = armorPiece.clone();
|
ItemStack clone = armorPiece.clone();
|
||||||
ItemMeta meta = clone.getItemMeta();
|
ItemMeta meta = clone.getItemMeta();
|
||||||
if (meta == null) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -591,7 +570,7 @@ public class ItemLore {
|
|||||||
|
|
||||||
if (damageTaken == null) {
|
if (damageTaken == null) {
|
||||||
damageTaken = 0.0;
|
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);
|
container.set(toolStats.armorDamage, PersistentDataType.DOUBLE, damageTaken + damage);
|
||||||
@@ -624,7 +603,7 @@ public class ItemLore {
|
|||||||
ItemStack clone = weapon.clone();
|
ItemStack clone = weapon.clone();
|
||||||
ItemMeta meta = clone.getItemMeta();
|
ItemMeta meta = clone.getItemMeta();
|
||||||
if (meta == null) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -697,7 +676,7 @@ public class ItemLore {
|
|||||||
|
|
||||||
if (damageDone == null) {
|
if (damageDone == null) {
|
||||||
damageDone = 0.0;
|
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);
|
container.set(toolStats.damageDone, PersistentDataType.DOUBLE, damageDone + damage);
|
||||||
@@ -722,7 +701,7 @@ public class ItemLore {
|
|||||||
ItemStack clone = elytra.clone();
|
ItemStack clone = elytra.clone();
|
||||||
ItemMeta meta = clone.getItemMeta();
|
ItemMeta meta = clone.getItemMeta();
|
||||||
if (meta == null) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -805,7 +784,7 @@ public class ItemLore {
|
|||||||
|
|
||||||
if (flightTime == null) {
|
if (flightTime == null) {
|
||||||
flightTime = 0L;
|
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);
|
container.set(toolStats.flightTime, PersistentDataType.LONG, flightTime + duration);
|
||||||
@@ -838,7 +817,7 @@ public class ItemLore {
|
|||||||
ItemStack clone = shears.clone();
|
ItemStack clone = shears.clone();
|
||||||
ItemMeta meta = clone.getItemMeta();
|
ItemMeta meta = clone.getItemMeta();
|
||||||
if (meta == null) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -911,7 +890,7 @@ public class ItemLore {
|
|||||||
|
|
||||||
if (sheepSheared == null) {
|
if (sheepSheared == null) {
|
||||||
sheepSheared = 0;
|
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);
|
container.set(toolStats.sheepSheared, PersistentDataType.INTEGER, sheepSheared + add);
|
||||||
@@ -936,7 +915,7 @@ public class ItemLore {
|
|||||||
ItemStack clone = bow.clone();
|
ItemStack clone = bow.clone();
|
||||||
ItemMeta meta = clone.getItemMeta();
|
ItemMeta meta = clone.getItemMeta();
|
||||||
if (meta == null) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1011,7 +990,7 @@ public class ItemLore {
|
|||||||
|
|
||||||
if (arrowsShot == null) {
|
if (arrowsShot == null) {
|
||||||
arrowsShot = 0;
|
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);
|
container.set(toolStats.arrowsShot, PersistentDataType.INTEGER, arrowsShot + add);
|
||||||
@@ -1036,7 +1015,7 @@ public class ItemLore {
|
|||||||
ItemStack clone = fishingRod.clone();
|
ItemStack clone = fishingRod.clone();
|
||||||
ItemMeta meta = clone.getItemMeta();
|
ItemMeta meta = clone.getItemMeta();
|
||||||
if (meta == null) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1109,7 +1088,7 @@ public class ItemLore {
|
|||||||
|
|
||||||
if (fishCaught == null) {
|
if (fishCaught == null) {
|
||||||
fishCaught = 0;
|
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);
|
container.set(toolStats.fishCaught, PersistentDataType.INTEGER, fishCaught + add);
|
||||||
|
|||||||
@@ -53,35 +53,35 @@ public class NumberFormat {
|
|||||||
// if these config values are missing, use the default ones
|
// if these config values are missing, use the default ones
|
||||||
if (dateFormat == null) {
|
if (dateFormat == null) {
|
||||||
dateFormat = "M/dd/yyyy";
|
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) {
|
if (decimalSeparator == null) {
|
||||||
decimalSeparator = ".";
|
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) {
|
if (commaSeparator == null) {
|
||||||
commaSeparator = ",";
|
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) {
|
if (commaFormat == null) {
|
||||||
commaFormat = "#,###";
|
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) {
|
if (decimalFormat == null) {
|
||||||
decimalFormat = "#,##0.00";
|
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
|
// test the date format
|
||||||
try {
|
try {
|
||||||
DATE_FORMAT = new SimpleDateFormat(dateFormat, Locale.getDefault());
|
DATE_FORMAT = new SimpleDateFormat(dateFormat, Locale.getDefault());
|
||||||
} catch (NullPointerException | IllegalArgumentException exception) {
|
} catch (NullPointerException | IllegalArgumentException exception) {
|
||||||
toolStats.logger.warning("date-format is NOT a valid format! Using default American English format.");
|
toolStats.logger.error("Invalid format or missing format", exception);
|
||||||
exception.printStackTrace();
|
toolStats.logger.warn("date-format is NOT a valid format! Using default American English format.");
|
||||||
DATE_FORMAT = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
|
DATE_FORMAT = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,8 +95,8 @@ public class NumberFormat {
|
|||||||
try {
|
try {
|
||||||
COMMA_FORMAT = new DecimalFormat(commaFormat, formatSymbols);
|
COMMA_FORMAT = new DecimalFormat(commaFormat, formatSymbols);
|
||||||
} catch (NullPointerException | IllegalArgumentException exception) {
|
} catch (NullPointerException | IllegalArgumentException exception) {
|
||||||
toolStats.logger.warning("number-formats.comma-format is NOT a valid format! Using default #,### instead.");
|
toolStats.logger.error("Invalid comma or missing format", exception);
|
||||||
exception.printStackTrace();
|
toolStats.logger.warn("number-formats.comma-format is NOT a valid format! Using default #,### instead.");
|
||||||
COMMA_FORMAT = new DecimalFormat("#,###", formatSymbols);
|
COMMA_FORMAT = new DecimalFormat("#,###", formatSymbols);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,8 +104,8 @@ public class NumberFormat {
|
|||||||
try {
|
try {
|
||||||
DECIMAL_FORMAT = new DecimalFormat(decimalFormat, formatSymbols);
|
DECIMAL_FORMAT = new DecimalFormat(decimalFormat, formatSymbols);
|
||||||
} catch (NullPointerException | IllegalArgumentException exception) {
|
} catch (NullPointerException | IllegalArgumentException exception) {
|
||||||
toolStats.logger.warning("number-formats.decimal-format is NOT a valid format! Using default #,###.00 instead.");
|
toolStats.logger.error("Invalid decimal or missing format", exception);
|
||||||
exception.printStackTrace();
|
toolStats.logger.warn("number-formats.decimal-format is NOT a valid format! Using default #,###.00 instead.");
|
||||||
DECIMAL_FORMAT = new DecimalFormat("#,###.00", formatSymbols);
|
DECIMAL_FORMAT = new DecimalFormat("#,###.00", formatSymbols);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,14 +154,14 @@ public class TokenData {
|
|||||||
|
|
||||||
String materialFromConfig = tokenConfig.getString("material");
|
String materialFromConfig = tokenConfig.getString("material");
|
||||||
if (materialFromConfig == null) {
|
if (materialFromConfig == null) {
|
||||||
toolStats.logger.warning("Could not find material config for token " + tokenType);
|
toolStats.logger.warn("Could not find material config for token {}", tokenType);
|
||||||
toolStats.logger.warning("Using PAPER as default.");
|
toolStats.logger.warn("Using PAPER as default.");
|
||||||
materialFromConfig = "PAPER";
|
materialFromConfig = "PAPER";
|
||||||
}
|
}
|
||||||
Material material = Material.getMaterial(materialFromConfig);
|
Material material = Material.getMaterial(materialFromConfig);
|
||||||
if (material == null) {
|
if (material == null) {
|
||||||
toolStats.logger.warning("Material " + materialFromConfig + " is not a valid Minecraft material.");
|
toolStats.logger.warn("Material {} is not a valid Minecraft material.", materialFromConfig);
|
||||||
toolStats.logger.warning("Using PAPER as default.");
|
toolStats.logger.warn("Using PAPER as default.");
|
||||||
material = Material.PAPER;
|
material = Material.PAPER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +170,8 @@ public class TokenData {
|
|||||||
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
||||||
|
|
||||||
// set the title and lore
|
// set the title and lore
|
||||||
Component title = toolStats.configTools.format("tokens.data." + tokenType + ".title");
|
String titleFromConfig = toolStats.config.getString("tokens.data." + tokenType + ".title");
|
||||||
|
Component title = toolStats.textUtils.format(titleFromConfig);
|
||||||
List<Component> lore = toolStats.configTools.getTokenLore(tokenType);
|
List<Component> lore = toolStats.configTools.getTokenLore(tokenType);
|
||||||
tokenMeta.displayName(title);
|
tokenMeta.displayName(title);
|
||||||
tokenMeta.lore(lore);
|
tokenMeta.lore(lore);
|
||||||
@@ -184,9 +185,9 @@ public class TokenData {
|
|||||||
String type = tokenConfig.getString("custom-model-data.type");
|
String type = tokenConfig.getString("custom-model-data.type");
|
||||||
Object value = tokenConfig.get("custom-model-data.value");
|
Object value = tokenConfig.get("custom-model-data.value");
|
||||||
if (type == null || value == null) {
|
if (type == null || value == null) {
|
||||||
toolStats.logger.info("Could not find custom model data for token " + tokenType);
|
toolStats.logger.info("Could not find custom model data for token {}", tokenType);
|
||||||
toolStats.logger.info("Type: " + type);
|
toolStats.logger.info("Type: {}", type);
|
||||||
toolStats.logger.info("Value: " + value);
|
toolStats.logger.info("Value: {}", value);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
CustomModelData data = setData(type, value);
|
CustomModelData data = setData(type, value);
|
||||||
@@ -207,7 +208,7 @@ public class TokenData {
|
|||||||
try {
|
try {
|
||||||
f = Float.parseFloat(data.toString());
|
f = Float.parseFloat(data.toString());
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
toolStats.logger.info(data + " is not a valid float!");
|
toolStats.logger.info("{} is not a valid float!", data);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return CustomModelData.customModelData().addFloat(f).build();
|
return CustomModelData.customModelData().addFloat(f).build();
|
||||||
@@ -216,7 +217,7 @@ public class TokenData {
|
|||||||
return CustomModelData.customModelData().addString(data.toString()).build();
|
return CustomModelData.customModelData().addString(data.toString()).build();
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
toolStats.logger.info(data + " is not a valid data type!");
|
toolStats.logger.info("{} is not a valid data type!", data);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.bukkit.persistence.PersistentDataAdapterContext;
|
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class UUIDDataType implements PersistentDataType<byte[], UUID> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Class<byte[]> getPrimitiveType() {
|
|
||||||
return byte[].class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Class<UUID> getComplexType() {
|
|
||||||
return UUID.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte @NotNull [] toPrimitive(UUID complex, @NotNull PersistentDataAdapterContext context) {
|
|
||||||
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
|
|
||||||
bb.putLong(complex.getMostSignificantBits());
|
|
||||||
bb.putLong(complex.getLeastSignificantBits());
|
|
||||||
return bb.array();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull UUID fromPrimitive(byte @NotNull [] primitive, @NotNull PersistentDataAdapterContext context) {
|
|
||||||
ByteBuffer bb = ByteBuffer.wrap(primitive);
|
|
||||||
long firstLong = bb.getLong();
|
|
||||||
long secondLong = bb.getLong();
|
|
||||||
return new UUID(firstLong, secondLong);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -20,8 +20,6 @@ package lol.hyper.toolstats.tools.config;
|
|||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.TextDecoration;
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -34,8 +32,6 @@ import java.util.regex.Pattern;
|
|||||||
public class ConfigTools {
|
public class ConfigTools {
|
||||||
|
|
||||||
private final ToolStats toolStats;
|
private final ToolStats toolStats;
|
||||||
public static final Pattern COLOR_CODES = Pattern.compile("[&§]([0-9a-fk-or])");
|
|
||||||
public static final Pattern CONFIG_HEX_PATTERN = Pattern.compile("[&§]#([A-Fa-f0-9]{6})");
|
|
||||||
|
|
||||||
public ConfigTools(ToolStats toolStats) {
|
public ConfigTools(ToolStats toolStats) {
|
||||||
this.toolStats = toolStats;
|
this.toolStats = toolStats;
|
||||||
@@ -50,7 +46,7 @@ public class ConfigTools {
|
|||||||
*/
|
*/
|
||||||
public boolean checkConfig(Material material, String configName) {
|
public boolean checkConfig(Material material, String configName) {
|
||||||
if (toolStats.config.getConfigurationSection("enabled." + configName) == null) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +104,7 @@ public class ConfigTools {
|
|||||||
public Component formatLore(String configName, String placeHolder, Object value) {
|
public Component formatLore(String configName, String placeHolder, Object value) {
|
||||||
String lore = toolStats.config.getString("messages." + configName);
|
String lore = toolStats.config.getString("messages." + configName);
|
||||||
if (lore == null) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,16 +121,7 @@ public class ConfigTools {
|
|||||||
lore = lore.replace(placeHolder, String.valueOf(value));
|
lore = lore.replace(placeHolder, String.valueOf(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we match the old color codes, then format them as so
|
component = toolStats.textUtils.format(lore);
|
||||||
Matcher hexMatcher = CONFIG_HEX_PATTERN.matcher(lore);
|
|
||||||
Matcher colorMatcher = COLOR_CODES.matcher(lore);
|
|
||||||
if (hexMatcher.find() || colorMatcher.find()) {
|
|
||||||
component = LegacyComponentSerializer.legacyAmpersand().deserialize(lore);
|
|
||||||
} else {
|
|
||||||
// otherwise format them normally
|
|
||||||
component = MiniMessage.miniMessage().deserialize(lore);
|
|
||||||
}
|
|
||||||
|
|
||||||
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
|
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +135,7 @@ public class ConfigTools {
|
|||||||
public Component formatLoreMultiplePlaceholders(String configName, Map<String, String> placeHoldersValues) {
|
public Component formatLoreMultiplePlaceholders(String configName, Map<String, String> placeHoldersValues) {
|
||||||
String lore = toolStats.config.getString("messages." + configName);
|
String lore = toolStats.config.getString("messages." + configName);
|
||||||
if (lore == null) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,49 +170,7 @@ public class ConfigTools {
|
|||||||
Component component;
|
Component component;
|
||||||
// Clean output text
|
// Clean output text
|
||||||
String outputText = result.toString().replaceAll("\\s+", " ").trim();
|
String outputText = result.toString().replaceAll("\\s+", " ").trim();
|
||||||
|
component = toolStats.textUtils.format(outputText);
|
||||||
// if we match the old color codes, then format them as so
|
|
||||||
Matcher hexMatcher = CONFIG_HEX_PATTERN.matcher(outputText);
|
|
||||||
Matcher colorMatcher = COLOR_CODES.matcher(outputText);
|
|
||||||
if (hexMatcher.find() || colorMatcher.find()) {
|
|
||||||
component = LegacyComponentSerializer.legacyAmpersand().deserialize(outputText);
|
|
||||||
} else {
|
|
||||||
// otherwise format them normally
|
|
||||||
component = MiniMessage.miniMessage().deserialize(outputText);
|
|
||||||
}
|
|
||||||
|
|
||||||
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Format a string from the config.
|
|
||||||
*
|
|
||||||
* @param configName The config to format.
|
|
||||||
* @return Formatted string, null if the configName doesn't exist.
|
|
||||||
*/
|
|
||||||
public Component format(String configName) {
|
|
||||||
String message = toolStats.config.getString(configName);
|
|
||||||
if (message == null) {
|
|
||||||
toolStats.logger.warning("Unable to find config message for: " + configName);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the config message is empty, don't send it
|
|
||||||
if (message.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// the final component for this lore
|
|
||||||
Component component;
|
|
||||||
// if we match the old color codes, then format them as so
|
|
||||||
Matcher hexMatcher = CONFIG_HEX_PATTERN.matcher(message);
|
|
||||||
Matcher colorMatcher = COLOR_CODES.matcher(message);
|
|
||||||
if (hexMatcher.find() || colorMatcher.find()) {
|
|
||||||
component = LegacyComponentSerializer.legacyAmpersand().deserialize(message);
|
|
||||||
} else {
|
|
||||||
// otherwise format them normally
|
|
||||||
component = MiniMessage.miniMessage().deserialize(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
|
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
|
||||||
}
|
}
|
||||||
@@ -251,16 +196,7 @@ public class ConfigTools {
|
|||||||
line = line.replace("{levels}", String.valueOf(levels));
|
line = line.replace("{levels}", String.valueOf(levels));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Component component;
|
Component component = toolStats.textUtils.format(line);
|
||||||
// if we match the old color codes, then format them as so
|
|
||||||
Matcher hexMatcher = CONFIG_HEX_PATTERN.matcher(line);
|
|
||||||
Matcher colorMatcher = COLOR_CODES.matcher(line);
|
|
||||||
if (hexMatcher.find() || colorMatcher.find()) {
|
|
||||||
component = LegacyComponentSerializer.legacyAmpersand().deserialize(line);
|
|
||||||
} else {
|
|
||||||
// otherwise format them normally
|
|
||||||
component = MiniMessage.miniMessage().deserialize(line);
|
|
||||||
}
|
|
||||||
component = component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
|
component = component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
|
||||||
finalLore.add(component);
|
finalLore.add(component);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ public class Version10 {
|
|||||||
try {
|
try {
|
||||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-9.yml");
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-9.yml");
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
toolStats.logger.severe("Unable to save config-9.yml!");
|
toolStats.logger.error("Unable to save config-9.yml!", exception);
|
||||||
throw new RuntimeException(exception);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// we make this super verbose so that admins can see what's being added
|
// we make this super verbose so that admins can see what's being added
|
||||||
@@ -72,8 +71,7 @@ public class Version10 {
|
|||||||
try {
|
try {
|
||||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
toolStats.logger.severe("Unable to save config.yml!");
|
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||||
throw new RuntimeException(exception);
|
|
||||||
}
|
}
|
||||||
toolStats.loadConfig();
|
toolStats.loadConfig();
|
||||||
toolStats.logger.info("Config has been updated to version 10. A copy of version 9 has been saved as config-9.yml");
|
toolStats.logger.info("Config has been updated to version 10. A copy of version 9 has been saved as config-9.yml");
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ public class Version11 {
|
|||||||
try {
|
try {
|
||||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-10.yml");
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-10.yml");
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
toolStats.logger.severe("Unable to save config-10.yml!");
|
toolStats.logger.error("Unable to save config-10.yml!", exception);
|
||||||
throw new RuntimeException(exception);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// we make this super verbose so that admins can see what's being added
|
// we make this super verbose so that admins can see what's being added
|
||||||
@@ -95,8 +94,7 @@ public class Version11 {
|
|||||||
try {
|
try {
|
||||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
toolStats.logger.severe("Unable to save config.yml!");
|
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||||
throw new RuntimeException(exception);
|
|
||||||
}
|
}
|
||||||
toolStats.loadConfig();
|
toolStats.loadConfig();
|
||||||
toolStats.logger.info("Config has been updated to version 11. A copy of version 10 has been saved as config-10.yml");
|
toolStats.logger.info("Config has been updated to version 11. A copy of version 10 has been saved as config-10.yml");
|
||||||
|
|||||||
@@ -44,8 +44,7 @@ public class Version12 {
|
|||||||
try {
|
try {
|
||||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-11.yml");
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-11.yml");
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
toolStats.logger.severe("Unable to save config-11.yml!");
|
toolStats.logger.error("Unable to save config-11.yml!", exception);
|
||||||
throw new RuntimeException(exception);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toolStats.logger.info("Updating config.yml to version 12.");
|
toolStats.logger.info("Updating config.yml to version 12.");
|
||||||
@@ -102,15 +101,14 @@ public class Version12 {
|
|||||||
try {
|
try {
|
||||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
toolStats.logger.severe("Unable to save config.yml!");
|
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||||
throw new RuntimeException(exception);
|
|
||||||
}
|
}
|
||||||
toolStats.loadConfig();
|
toolStats.loadConfig();
|
||||||
toolStats.logger.info("Config has been updated to version 12. A copy of version 11 has been saved as config-11.yml");
|
toolStats.logger.info("Config has been updated to version 12. A copy of version 11 has been saved as config-11.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transfer(String oldSection, String newSection) {
|
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);
|
ConfigurationSection old = toolStats.config.getConfigurationSection(oldSection);
|
||||||
toolStats.config.set(newSection, old);
|
toolStats.config.set(newSection, old);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,21 +43,20 @@ public class Version13 {
|
|||||||
try {
|
try {
|
||||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-12.yml");
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-12.yml");
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
toolStats.logger.severe("Unable to save config-12.yml!");
|
toolStats.logger.error("Unable to save config-12.yml!", exception);
|
||||||
throw new RuntimeException(exception);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toolStats.logger.info("Updating config.yml to version 13.");
|
toolStats.logger.info("Updating config.yml to version 13.");
|
||||||
toolStats.config.set("config-version", 13);
|
toolStats.config.set("config-version", 13);
|
||||||
|
|
||||||
for (String key : toolStats.config.getConfigurationSection("tokens.data").getKeys(false)) {
|
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.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.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.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);
|
toolStats.config.set("tokens.data." + key + ".custom-model-data.value", 1001);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,8 +64,7 @@ public class Version13 {
|
|||||||
try {
|
try {
|
||||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
toolStats.logger.severe("Unable to save config.yml!");
|
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||||
throw new RuntimeException(exception);
|
|
||||||
}
|
}
|
||||||
toolStats.loadConfig();
|
toolStats.loadConfig();
|
||||||
toolStats.logger.info("Config has been updated to version 13. A copy of version 12 has been saved as config-12.yml");
|
toolStats.logger.info("Config has been updated to version 13. A copy of version 12 has been saved as config-12.yml");
|
||||||
|
|||||||
@@ -46,8 +46,7 @@ public class Version6 {
|
|||||||
try {
|
try {
|
||||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-5.yml");
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-5.yml");
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
toolStats.logger.severe("Unable to save config-5.yml!");
|
toolStats.logger.error("Unable to save config-5.yml!", exception);
|
||||||
throw new RuntimeException(exception);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// we make this super verbose so that admins can see what's being added
|
// we make this super verbose so that admins can see what's being added
|
||||||
@@ -107,8 +106,7 @@ public class Version6 {
|
|||||||
try {
|
try {
|
||||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
toolStats.logger.severe("Unable to save config.yml!");
|
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||||
throw new RuntimeException(exception);
|
|
||||||
}
|
}
|
||||||
toolStats.loadConfig();
|
toolStats.loadConfig();
|
||||||
toolStats.logger.info("Config has been updated to version 6. A copy of version 5 has been saved as config-5.yml");
|
toolStats.logger.info("Config has been updated to version 6. A copy of version 5 has been saved as config-5.yml");
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ public class Version7 {
|
|||||||
try {
|
try {
|
||||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-6.yml");
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-6.yml");
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
toolStats.logger.severe("Unable to save config-6.yml!");
|
toolStats.logger.error("Unable to save config-6.yml!", exception);
|
||||||
throw new RuntimeException(exception);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// we make this super verbose so that admins can see what's being added
|
// we make this super verbose so that admins can see what's being added
|
||||||
@@ -61,8 +60,7 @@ public class Version7 {
|
|||||||
try {
|
try {
|
||||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
toolStats.logger.severe("Unable to save config.yml!");
|
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||||
throw new RuntimeException(exception);
|
|
||||||
}
|
}
|
||||||
toolStats.loadConfig();
|
toolStats.loadConfig();
|
||||||
toolStats.logger.info("Config has been updated to version 7. A copy of version 6 has been saved as config-6.yml");
|
toolStats.logger.info("Config has been updated to version 7. A copy of version 6 has been saved as config-6.yml");
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ public class Version8 {
|
|||||||
try {
|
try {
|
||||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-7.yml");
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-7.yml");
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
toolStats.logger.severe("Unable to save config-7.yml!");
|
toolStats.logger.error("Unable to save config-7.yml!", exception);
|
||||||
throw new RuntimeException(exception);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// we make this super verbose so that admins can see what's being added
|
// we make this super verbose so that admins can see what's being added
|
||||||
@@ -78,8 +77,7 @@ public class Version8 {
|
|||||||
try {
|
try {
|
||||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
toolStats.logger.severe("Unable to save config.yml!");
|
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||||
throw new RuntimeException(exception);
|
|
||||||
}
|
}
|
||||||
toolStats.loadConfig();
|
toolStats.loadConfig();
|
||||||
toolStats.logger.info("Config has been updated to version 8. A copy of version 7 has been saved as config-7.yml");
|
toolStats.logger.info("Config has been updated to version 8. A copy of version 7 has been saved as config-7.yml");
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ public class Version9 {
|
|||||||
try {
|
try {
|
||||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-8.yml");
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-8.yml");
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
toolStats.logger.severe("Unable to save config-8.yml!");
|
toolStats.logger.error("Unable to save config-8.yml!", exception);
|
||||||
throw new RuntimeException(exception);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toolStats.logger.info("Updating config.yml to version 9.");
|
toolStats.logger.info("Updating config.yml to version 9.");
|
||||||
@@ -78,8 +77,7 @@ public class Version9 {
|
|||||||
try {
|
try {
|
||||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
toolStats.logger.severe("Unable to save config.yml!");
|
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||||
throw new RuntimeException(exception);
|
|
||||||
}
|
}
|
||||||
toolStats.loadConfig();
|
toolStats.loadConfig();
|
||||||
toolStats.logger.info("Config has been updated to version 9. A copy of version 8 has been saved as config-8.yml");
|
toolStats.logger.info("Config has been updated to version 9. A copy of version 8 has been saved as config-8.yml");
|
||||||
@@ -93,7 +91,7 @@ public class Version9 {
|
|||||||
* @param lore The lore of the item.
|
* @param lore The lore of the item.
|
||||||
*/
|
*/
|
||||||
private void addToken(String tokenType, String title, String lore) {
|
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);
|
toolStats.config.set("tokens.data." + tokenType + ".title", title);
|
||||||
List<String> loreList = new ArrayList<>();
|
List<String> loreList = new ArrayList<>();
|
||||||
loreList.add(lore);
|
loreList.add(lore);
|
||||||
|
|||||||
Reference in New Issue
Block a user