Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c28ee0fb8c | ||
|
|
8fe7292505 | ||
|
|
3da74fe656 | ||
|
|
ab0d2a1ca1 | ||
|
|
857ce5b631 | ||
|
|
b14fb30212 | ||
|
|
a9bb876b38 | ||
|
|
e819fadd50 | ||
|
|
c22c36f0a4 | ||
|
|
e38ffdef07 | ||
|
|
c7540244bc | ||
|
|
613957fadf | ||
|
|
e48be6ba20 | ||
|
|
c0d79fd740 | ||
|
|
b056972d30 | ||
|
|
525df4bcf6 | ||
|
|
86cbdd58ff | ||
|
|
27a89fd67c | ||
|
|
70ed50ce9e | ||
|
|
84c1f8313a | ||
|
|
f7ec488396 | ||
|
|
df014fd888 |
35
README.md
@@ -4,9 +4,10 @@
|
||||
<a href="https://modrinth.com/plugin/ToolStats"><img alt="modrinth" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/available/modrinth_vector.svg"></a>
|
||||
<a href="https://hangar.papermc.io/hyperdefined/ToolStats"><img alt="hangar" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/available/hangar_vector.svg"></a>
|
||||
<a href="https://papermc.io"><img alt="paper" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/supported/paper_vector.svg"></a>
|
||||
<a href="https://github.com/hyperdefined/ToolStats/wiki"><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://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>
|
||||
|
||||
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).
|
||||
* Crops mined (hoes).
|
||||
* 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.
|
||||
* Damage done with weapons.
|
||||
* Fish caught.
|
||||
@@ -27,23 +28,23 @@ The best part is, this data is stored on the item itself.
|
||||
|
||||
If item lore is ever incorrect/missing, you can run `/toolstats reset`. This command fixes the lore on whatever item you are holding.
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
## Documentation
|
||||
Visit the [wiki](https://github.com/hyperdefined/ToolStats/wiki) for help.
|
||||
Visit the [wiki](https://docs.hyper.lol/plugins/toolstats/about/) for help.
|
||||
|
||||
## License
|
||||
This plugin is released under GNU General Public License v3. See [LICENSE](https://github.com/hyperdefined/ToolStats/blob/master/LICENSE).
|
||||
|
Before Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 7.6 KiB |
|
Before Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 9.4 KiB |
BIN
images/image.png
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 8.8 KiB |
|
Before Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 94 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 47 KiB |
|
Before Width: | Height: | Size: 15 KiB |
34
pom.xml
@@ -23,7 +23,7 @@
|
||||
|
||||
<groupId>lol.hyper</groupId>
|
||||
<artifactId>toolstats</artifactId>
|
||||
<version>1.9.7</version>
|
||||
<version>1.9.10</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>ToolStats</name>
|
||||
@@ -37,7 +37,7 @@
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<version>3.5.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>auto-clean</id>
|
||||
@@ -51,7 +51,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.14.0</version>
|
||||
<version>3.14.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
@@ -60,16 +60,12 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.6.1</version>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>lol.hyper.toolstats.bstats</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>lol.hyper.githubreleaseapi</pattern>
|
||||
<shadedPattern>lol.hyper.toolstats.updater</shadedPattern>
|
||||
<pattern>lol.hyper.hyperlib</pattern>
|
||||
<shadedPattern>lol.hyper.toolstats.hyperlib</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
@@ -99,25 +95,23 @@
|
||||
<id>papermc</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.21.5-R0.1-SNAPSHOT</version>
|
||||
<version>1.21.10-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>lol.hyper</groupId>
|
||||
<artifactId>github-release-api</artifactId>
|
||||
<version>1.0.5</version>
|
||||
<groupId>com.github.hyperdefined</groupId>
|
||||
<artifactId>hyperlib</artifactId>
|
||||
<version>1.0.9</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -17,15 +17,16 @@
|
||||
|
||||
package lol.hyper.toolstats;
|
||||
|
||||
import lol.hyper.githubreleaseapi.GitHubRelease;
|
||||
import lol.hyper.githubreleaseapi.GitHubReleaseAPI;
|
||||
import lol.hyper.githubreleaseapi.ReleaseNotFoundException;
|
||||
import lol.hyper.hyperlib.HyperLib;
|
||||
import lol.hyper.hyperlib.bstats.HyperStats;
|
||||
import lol.hyper.hyperlib.releases.HyperUpdater;
|
||||
import lol.hyper.hyperlib.utils.TextUtils;
|
||||
import lol.hyper.toolstats.commands.CommandToolStats;
|
||||
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 org.bstats.bukkit.Metrics;
|
||||
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@@ -33,10 +34,8 @@ import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
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 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<>();
|
||||
@@ -152,9 +151,20 @@ public final class ToolStats extends JavaPlugin {
|
||||
public TokenData tokenData;
|
||||
public AnvilEvent anvilEvent;
|
||||
public PrepareCraft prepareCraft;
|
||||
public BlockDispenseEvent blockDispenseEvent;
|
||||
public HyperLib hyperLib;
|
||||
public TextUtils textUtils;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
hyperLib = new HyperLib(this);
|
||||
hyperLib.setup();
|
||||
|
||||
HyperStats stats = new HyperStats(hyperLib, 14110);
|
||||
stats.setup();
|
||||
|
||||
textUtils = new TextUtils(hyperLib);
|
||||
|
||||
if (!configFile.exists()) {
|
||||
this.saveResource("config.yml", true);
|
||||
logger.info("Copying default config!");
|
||||
@@ -192,6 +202,7 @@ public final class ToolStats extends JavaPlugin {
|
||||
shootBow = new ShootBow(this);
|
||||
anvilEvent = new AnvilEvent(this);
|
||||
prepareCraft = new PrepareCraft(this);
|
||||
blockDispenseEvent = new BlockDispenseEvent(this);
|
||||
|
||||
// save which stat can be used by a reset token
|
||||
tokenKeys.add(blocksMined);
|
||||
@@ -222,17 +233,21 @@ public final class ToolStats extends JavaPlugin {
|
||||
Bukkit.getServer().getPluginManager().registerEvents(playerMove, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(anvilEvent, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(prepareCraft, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(blockDispenseEvent, this);
|
||||
|
||||
this.getCommand("toolstats").setExecutor(commandToolStats);
|
||||
|
||||
new Metrics(this, 14110);
|
||||
Bukkit.getAsyncScheduler().runNow(this, scheduledTask -> checkForUpdates());
|
||||
HyperUpdater updater = new HyperUpdater(hyperLib);
|
||||
updater.setGitHub("hyperdefined", "ToolStats");
|
||||
updater.setModrinth("oBZj9E15");
|
||||
updater.setHangar("ToolStats", "paper");
|
||||
updater.check();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -247,29 +262,4 @@ public final class ToolStats extends JavaPlugin {
|
||||
|
||||
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;
|
||||
|
||||
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -155,6 +154,37 @@ public class CommandToolStats implements TabExecutor {
|
||||
sender.sendMessage(Component.text("Type /toolstats reset confirm to confirm this.", NamedTextColor.GREEN));
|
||||
return true;
|
||||
}
|
||||
case "purge": {
|
||||
if (!sender.hasPermission("toolstats.purge")) {
|
||||
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
sender.sendMessage(Component.text("You must be a player for this command.", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 2 && args[1].equalsIgnoreCase("confirm")) {
|
||||
if (!sender.hasPermission("toolstats.purge.confirm")) {
|
||||
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
||||
if (!toolStats.itemChecker.isValidItem(heldItem.getType())) {
|
||||
sender.sendMessage(Component.text("You must hold a valid item.", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
ItemStack purgedItem = toolStats.itemLore.removeAll(heldItem, true);
|
||||
player.getInventory().setItemInMainHand(purgedItem);
|
||||
sender.sendMessage(Component.text("The item was purged!", NamedTextColor.GREEN));
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(Component.text("This will purge ALL ToolStats data from this item.", NamedTextColor.GREEN));
|
||||
sender.sendMessage(Component.text("This includes all stats, ownership, and creation time.", NamedTextColor.GREEN));
|
||||
sender.sendMessage(Component.text("THIS CANNOT BE UNDONE!", NamedTextColor.GREEN));
|
||||
sender.sendMessage(Component.text("Type /toolstats purge confirm to confirm this.", NamedTextColor.GREEN));
|
||||
return true;
|
||||
}
|
||||
case "givetokens": {
|
||||
if (!sender.hasPermission("toolstats.givetokens")) {
|
||||
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
|
||||
@@ -233,38 +263,6 @@ public class CommandToolStats implements TabExecutor {
|
||||
origin = -1;
|
||||
}
|
||||
|
||||
// hard code elytras
|
||||
if (finalItem.getType() == Material.ELYTRA) {
|
||||
Long flightTime = null;
|
||||
Long timeCreated = null;
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) {
|
||||
timeCreated = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||
}
|
||||
if (container.has(toolStats.flightTime, PersistentDataType.LONG)) {
|
||||
flightTime = container.get(toolStats.flightTime, PersistentDataType.LONG);
|
||||
}
|
||||
|
||||
if (flightTime != null) {
|
||||
if (toolStats.config.getBoolean("enabled.flight-time")) {
|
||||
Map<String, String> flightTimeFormatted = toolStats.numberFormat.formatTime(flightTime);
|
||||
Component line = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", flightTimeFormatted);
|
||||
lore.add(line);
|
||||
}
|
||||
}
|
||||
|
||||
if (timeCreated != null) {
|
||||
Component timeCreatedLine = toolStats.configTools.formatLore("looted.found-by", "{player}", player.getName());
|
||||
Component playerOwnerLine = toolStats.configTools.formatLore("looted.found-on", "{date}", toolStats.numberFormat.formatDate(new Date(timeCreated)));
|
||||
lore.add(timeCreatedLine);
|
||||
lore.add(playerOwnerLine);
|
||||
}
|
||||
|
||||
finalMeta.lore(lore);
|
||||
finalItem.setItemMeta(finalMeta);
|
||||
int slot = player.getInventory().getHeldItemSlot();
|
||||
player.getInventory().setItem(slot, finalItem);
|
||||
}
|
||||
|
||||
if (container.has(toolStats.droppedBy, PersistentDataType.STRING)) {
|
||||
if (toolStats.config.getBoolean("enabled.dropped-by")) {
|
||||
if (container.has(toolStats.droppedBy)) {
|
||||
@@ -293,82 +291,30 @@ public class CommandToolStats implements TabExecutor {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), player.getUniqueId());
|
||||
}
|
||||
|
||||
// show how the item was created based on the previous lore
|
||||
switch (origin) {
|
||||
case 0: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "crafted-by")) {
|
||||
lore.add(toolStats.configTools.formatLore("crafted.crafted-by", "{player}", ownerName));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "looted-by")) {
|
||||
lore.add(toolStats.configTools.formatLore("looted.looted-by", "{player}", ownerName));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "traded-by")) {
|
||||
lore.add(toolStats.configTools.formatLore("traded.traded-by", "{player}", ownerName));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "fished-by")) {
|
||||
lore.add(toolStats.configTools.formatLore("fished.caught-by", "{player}", ownerName));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "spawned-in-by")) {
|
||||
lore.add(toolStats.configTools.formatLore("spawned-in.spawned-by", "{player}", ownerName));
|
||||
}
|
||||
break;
|
||||
}
|
||||
// add the ownership lore
|
||||
Component ownerLore = toolStats.itemLore.formatOwner(ownerName, origin, original);
|
||||
if (ownerLore != null) {
|
||||
lore.add(ownerLore);
|
||||
}
|
||||
|
||||
}
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) {
|
||||
Long time = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||
if (time != null) {
|
||||
String date = toolStats.numberFormat.formatDate(new Date(time));
|
||||
// show how when the item was created based on the previous lore
|
||||
switch (origin) {
|
||||
case 0: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "crafted-on")) {
|
||||
lore.add(toolStats.configTools.formatLore("crafted.crafted-on", "{date}", date));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
if (toolStats.config.getBoolean("enabled.dropped-on")) {
|
||||
lore.add(toolStats.configTools.formatLore("dropped-on", "{date}", date));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "looted-on")) {
|
||||
lore.add(toolStats.configTools.formatLore("looted.looted-on", "{date}", date));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "traded-on")) {
|
||||
lore.add(toolStats.configTools.formatLore("traded.traded-on", "{date}", date));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "fished-on")) {
|
||||
lore.add(toolStats.configTools.formatLore("fished.caught-on", "{date}", date));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "spawned-in-on")) {
|
||||
lore.add(toolStats.configTools.formatLore("spawned-in.spawned-on", "{date}", date));
|
||||
}
|
||||
break;
|
||||
}
|
||||
// add the creation time lore
|
||||
Component creationTimeLore = toolStats.itemLore.formatCreationTime(time, origin, original);
|
||||
if (creationTimeLore != null) {
|
||||
lore.add(creationTimeLore);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toolStats.config.getBoolean("enabled.flight-time")) {
|
||||
if (container.has(toolStats.flightTime, PersistentDataType.LONG)) {
|
||||
Long flightTime = container.get(toolStats.flightTime, PersistentDataType.LONG);
|
||||
if (flightTime != null) {
|
||||
Map<String, String> flightTimeFormatted = toolStats.numberFormat.formatTime(flightTime);
|
||||
Component line = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", flightTimeFormatted);
|
||||
lore.add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1076,12 +1022,18 @@ public class CommandToolStats implements TabExecutor {
|
||||
if (sender.hasPermission("toolstats.remove")) {
|
||||
suggestions.add("remove");
|
||||
}
|
||||
if (sender.hasPermission("toolstats.purge")) {
|
||||
suggestions.add("purge");
|
||||
}
|
||||
return suggestions.isEmpty() ? null : suggestions;
|
||||
}
|
||||
|
||||
if (args.length == 2 && args[0].equalsIgnoreCase("reset") && sender.hasPermission("toolstats.reset.confirm")) {
|
||||
return Collections.singletonList("confirm");
|
||||
}
|
||||
if (args.length == 2 && args[0].equalsIgnoreCase("purge") && sender.hasPermission("toolstats.purge.confirm")) {
|
||||
return Collections.singletonList("confirm");
|
||||
}
|
||||
if (args.length == 2 && args[0].equalsIgnoreCase("edit") && sender.hasPermission("toolstats.edit")) {
|
||||
// yes I am lazy
|
||||
return toolStats.tokenData.getTokenTypes().stream()
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -90,7 +89,9 @@ public class AnvilEvent implements Listener {
|
||||
}
|
||||
|
||||
if (tokenType.equalsIgnoreCase("remove")) {
|
||||
remove(event, clone);
|
||||
ItemStack removedStats = toolStats.itemLore.removeAll(clone, false);
|
||||
event.setResult(removedStats);
|
||||
event.getView().setRepairCost(toolStats.itemChecker.getCost("remove"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -122,9 +123,17 @@ public class AnvilEvent implements Listener {
|
||||
addToken(event, tokenType, "mob-kills", clone);
|
||||
return;
|
||||
}
|
||||
if (tokenType.equalsIgnoreCase("damage-done")) {
|
||||
addToken(event, tokenType, "damage-done", clone);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (toolStats.itemChecker.canGlide(clone)) {
|
||||
addToken(event, tokenType, "flight-time", clone);
|
||||
return;
|
||||
}
|
||||
if (toolStats.itemChecker.isArmor(firstSlotMaterial)) {
|
||||
addToken(event, tokenType, "damage-taken", clone);
|
||||
return;
|
||||
@@ -163,10 +172,6 @@ public class AnvilEvent implements Listener {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (firstSlotMaterial == Material.ELYTRA) {
|
||||
addToken(event, tokenType, "flight-time", clone);
|
||||
return;
|
||||
}
|
||||
if (firstSlotMaterial == Material.FISHING_ROD) {
|
||||
addToken(event, tokenType, "fish-caught", clone);
|
||||
}
|
||||
@@ -390,155 +395,4 @@ public class AnvilEvent implements Listener {
|
||||
event.setResult(finalItem);
|
||||
event.getView().setRepairCost(toolStats.itemChecker.getCost("reset"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all stats from an item.
|
||||
*
|
||||
* @param event The PrepareAnvilEvent event.
|
||||
* @param inputItem The input item to remove stats from.
|
||||
*/
|
||||
private void remove(PrepareAnvilEvent event, ItemStack inputItem) {
|
||||
ItemStack finalItem = inputItem.clone();
|
||||
ItemMeta meta = finalItem.getItemMeta();
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
// remove the applied tokens
|
||||
if (container.has(toolStats.tokenApplied)) {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
}
|
||||
|
||||
if (container.has(toolStats.playerKills)) {
|
||||
Integer playerKills = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
|
||||
if (playerKills == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.playerKills);
|
||||
|
||||
String playerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("kills.player", "{kills}", playerKillsFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.mobKills)) {
|
||||
Integer mobKills = container.get(toolStats.mobKills, PersistentDataType.INTEGER);
|
||||
if (mobKills == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.mobKills);
|
||||
|
||||
String mobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("kills.mob", "{kills}", mobKillsFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.blocksMined)) {
|
||||
Integer blocksMined = container.get(toolStats.blocksMined, PersistentDataType.INTEGER);
|
||||
if (blocksMined == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.blocksMined);
|
||||
|
||||
String blocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("blocks-mined", "{blocks}", blocksMinedFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.cropsHarvested)) {
|
||||
Integer cropsHarvested = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
|
||||
if (cropsHarvested == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.cropsHarvested);
|
||||
|
||||
String cropsHarvestedFormatted = toolStats.numberFormat.formatInt(cropsHarvested);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("crops-harvested", "{crops}", cropsHarvestedFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.fishCaught)) {
|
||||
Integer fishCaught = container.get(toolStats.fishCaught, PersistentDataType.INTEGER);
|
||||
if (fishCaught == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.fishCaught);
|
||||
|
||||
String fishCaughtFormatted = toolStats.numberFormat.formatInt(fishCaught);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", fishCaughtFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.sheepSheared)) {
|
||||
Integer sheepSheared = container.get(toolStats.sheepSheared, PersistentDataType.INTEGER);
|
||||
if (sheepSheared == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.sheepSheared);
|
||||
|
||||
String sheepShearedFormatted = toolStats.numberFormat.formatInt(sheepSheared);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("sheep.sheared", "{sheep}", sheepShearedFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.armorDamage)) {
|
||||
Double armorDamage = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
|
||||
if (armorDamage == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.armorDamage);
|
||||
|
||||
String armorDamageFormatted = toolStats.numberFormat.formatDouble(armorDamage);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("damage-taken", "{damage}", armorDamageFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.damageDone)) {
|
||||
Double damageDone = container.get(toolStats.damageDone, PersistentDataType.DOUBLE);
|
||||
if (damageDone == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.damageDone);
|
||||
|
||||
String damageDoneFormatted = toolStats.numberFormat.formatDouble(damageDone);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("damage-done", "{damage}", damageDoneFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.arrowsShot)) {
|
||||
Integer arrowsShot = container.get(toolStats.arrowsShot, PersistentDataType.INTEGER);
|
||||
if (arrowsShot == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.arrowsShot);
|
||||
|
||||
String arrowsShotFormatted = toolStats.numberFormat.formatInt(arrowsShot);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("arrows-shot", "{arrows}", arrowsShotFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.flightTime)) {
|
||||
Long flightTime = container.get(toolStats.flightTime, PersistentDataType.LONG);
|
||||
if (flightTime == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.flightTime);
|
||||
|
||||
String flightTimeFormatted = toolStats.numberFormat.formatDouble(flightTime);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("flight-time", "{time}", flightTimeFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
|
||||
event.setResult(finalItem);
|
||||
event.getView().setRepairCost(toolStats.itemChecker.getCost("remove"));
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
@@ -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
|
||||
@@ -125,8 +125,6 @@ public class CraftItem implements Listener {
|
||||
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||
timeCreated = finalDate.getTime();
|
||||
} else {
|
||||
finalDate = new Date(timeCreated);
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
@@ -145,29 +143,20 @@ public class CraftItem implements Listener {
|
||||
}
|
||||
|
||||
// if creation date is enabled, add it
|
||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "crafted-on")) {
|
||||
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 0, newItem);
|
||||
if (creationDate != null) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 0);
|
||||
|
||||
String date = toolStats.numberFormat.formatDate(finalDate);
|
||||
Component newLine = toolStats.configTools.formatLore("crafted.crafted-on", "{date}", date);
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
lore.add(creationDate);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
// if creation owner is enabled, add it
|
||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "crafted-by")) {
|
||||
// if ownership is enabled, add it
|
||||
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 0, newItem);
|
||||
if (itemOwner != null) {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 0);
|
||||
|
||||
Component newLine = toolStats.configTools.formatLore("crafted.crafted-by", "{player}", owner.getName());
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
lore.add(itemOwner);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -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
|
||||
@@ -92,8 +92,6 @@ public class CreativeEvent implements Listener {
|
||||
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||
timeCreated = finalDate.getTime();
|
||||
} else {
|
||||
finalDate = new Date(timeCreated);
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
@@ -111,28 +109,21 @@ public class CreativeEvent implements Listener {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "spawned-in-on")) {
|
||||
// if creation date is enabled, add it
|
||||
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 6, newSpawnedItem);
|
||||
if (creationDate != null) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 6);
|
||||
|
||||
String date = toolStats.numberFormat.formatDate(finalDate);
|
||||
Component newLine = toolStats.configTools.formatLore("spawned-in.spawned-on", "{date}", date);
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
lore.add(creationDate);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "spawned-in-by")) {
|
||||
// if ownership is enabled, add it
|
||||
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 6, newSpawnedItem);
|
||||
if (itemOwner != null) {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 6);
|
||||
|
||||
Component newLine = toolStats.configTools.formatLore("spawned-in.spawned-by", "{player}", owner.getName());
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
lore.add(itemOwner);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
|
||||
@@ -91,8 +91,6 @@ public class EntityDeath implements Listener {
|
||||
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||
timeCreated = finalDate.getTime();
|
||||
} else {
|
||||
finalDate = new Date(timeCreated);
|
||||
}
|
||||
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
@@ -108,12 +106,13 @@ public class EntityDeath implements Listener {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (toolStats.config.getBoolean("enabled.dropped-on")) {
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
|
||||
// if creation date is enabled, add it
|
||||
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 1, newItem);
|
||||
if (creationDate != null) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
String date = toolStats.numberFormat.formatDate(finalDate);
|
||||
Component droppedOn = toolStats.configTools.formatLore("dropped-on", "{date}", date);
|
||||
lore.add(droppedOn);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
|
||||
lore.add(creationDate);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
if (toolStats.config.getBoolean("enabled.dropped-by")) {
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -104,8 +104,6 @@ public class GenerateLoot implements Listener {
|
||||
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||
timeCreated = finalDate.getTime();
|
||||
} else {
|
||||
finalDate = new Date(timeCreated);
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
@@ -121,28 +119,21 @@ public class GenerateLoot implements Listener {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (toolStats.configTools.checkConfig(newItem.getType(), "looted-on")) {
|
||||
// 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);
|
||||
|
||||
String date = toolStats.numberFormat.formatDate(finalDate);
|
||||
Component newLine = toolStats.configTools.formatLore("looted.looted-on", "{date}", date);
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
lore.add(creationDate);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
if (toolStats.configTools.checkConfig(newItem.getType(), "looted-by")) {
|
||||
// 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);
|
||||
|
||||
Component newLine = toolStats.configTools.formatLore("looted.looted-by", "{player}", owner.getName());
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
lore.add(itemOwner);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
@@ -95,8 +95,6 @@ public class PickupItem implements Listener {
|
||||
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||
timeCreated = finalDate.getTime();
|
||||
} else {
|
||||
finalDate = new Date(timeCreated);
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
@@ -123,12 +121,22 @@ public class PickupItem implements Listener {
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 4);
|
||||
container.remove(toolStats.newElytra);
|
||||
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
Component dateCreatedLore = toolStats.configTools.formatLore("looted.found-on", "{date}", formattedDate);
|
||||
Component itemOwnerLore = toolStats.configTools.formatLore("looted.found-by", "{player}", owner.getName());
|
||||
lore.add(dateCreatedLore);
|
||||
lore.add(itemOwnerLore);
|
||||
meta.lore(lore);
|
||||
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 4, finalItem);
|
||||
if (creationDate != null) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 4);
|
||||
lore.add(creationDate);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 4, finalItem);
|
||||
if (itemOwner != null) {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 4);
|
||||
lore.add(itemOwner);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
finalItem.setItemMeta(meta);
|
||||
return finalItem;
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
@@ -114,8 +114,6 @@ public class PlayerFish implements Listener {
|
||||
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||
timeCreated = finalDate.getTime();
|
||||
} else {
|
||||
finalDate = new Date(timeCreated);
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
@@ -131,28 +129,21 @@ public class PlayerFish implements Listener {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (toolStats.configTools.checkConfig(newItem.getType(), "fished-on")) {
|
||||
// if creation date is enabled, add it
|
||||
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 5, newItem);
|
||||
if (creationDate != null) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
|
||||
|
||||
String date = toolStats.numberFormat.formatDate(finalDate);
|
||||
Component newLine = toolStats.configTools.formatLore("fished.caught-on", "{date}", date);
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
lore.add(creationDate);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
if (toolStats.configTools.checkConfig(newItem.getType(), "fished-by")) {
|
||||
// if ownership is enabled, add it
|
||||
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 5, newItem);
|
||||
if (itemOwner != null) {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
|
||||
|
||||
Component newLine = toolStats.configTools.formatLore("fished.caught-by", "{player}", owner.getName());
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
lore.add(itemOwner);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ package lol.hyper.toolstats.events;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -31,6 +31,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -62,7 +63,8 @@ public class PlayerInteract implements Listener {
|
||||
return;
|
||||
}
|
||||
// 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);
|
||||
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> openedChests.remove(block), 20);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@@ -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;
|
||||
@@ -53,15 +52,23 @@ public class PlayerMove implements Listener {
|
||||
// player is not flying
|
||||
if (playerStartFlight.containsKey(player)) {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
ItemStack chest = inventory.getChestplate();
|
||||
// make sure the player is wearing an elytra
|
||||
if (chest != null && chest.getType() == Material.ELYTRA) {
|
||||
long duration = (System.currentTimeMillis() - playerStartFlight.get(player));
|
||||
ItemMeta newItem = toolStats.itemLore.updateFlightTime(chest, duration);
|
||||
if (newItem != null) {
|
||||
inventory.getChestplate().setItemMeta(newItem);
|
||||
// copy their current armor
|
||||
ItemStack[] armor = inventory.getArmorContents().clone();
|
||||
for (ItemStack armorPiece : armor) {
|
||||
// skip missing slots
|
||||
if (armorPiece == null) {
|
||||
continue;
|
||||
}
|
||||
// if the armor piece can glide, track the flight time
|
||||
if (toolStats.itemChecker.canGlide(armorPiece)) {
|
||||
long duration = (System.currentTimeMillis() - playerStartFlight.get(player));
|
||||
ItemMeta newMeta = toolStats.itemLore.updateFlightTime(armorPiece, duration);
|
||||
if (newMeta != null) {
|
||||
armorPiece.setItemMeta(newMeta);
|
||||
}
|
||||
}
|
||||
}
|
||||
inventory.setArmorContents(armor);
|
||||
playerStartFlight.remove(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
@@ -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();
|
||||
@@ -131,8 +131,6 @@ public class VillagerTrade implements Listener {
|
||||
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||
timeCreated = finalDate.getTime();
|
||||
} else {
|
||||
finalDate = new Date(timeCreated);
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
@@ -148,28 +146,22 @@ public class VillagerTrade implements Listener {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (toolStats.configTools.checkConfig(newItem.getType(), "traded-on")) {
|
||||
|
||||
// if creation date is enabled, add it
|
||||
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 3, newItem);
|
||||
if (creationDate != null) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
|
||||
|
||||
String date = toolStats.numberFormat.formatDate(finalDate);
|
||||
Component newLine = toolStats.configTools.formatLore("traded.traded-on", "{date}", date);
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
lore.add(creationDate);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
if (toolStats.configTools.checkConfig(newItem.getType(), "traded-by")) {
|
||||
// if ownership is enabled, add it
|
||||
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 3, newItem);
|
||||
if (itemOwner != null) {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
|
||||
|
||||
Component newLine = toolStats.configTools.formatLore("traded.traded-by", "{player}", owner.getName());
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
lore.add(itemOwner);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package lol.hyper.toolstats.tools;
|
||||
|
||||
import io.papermc.paper.datacomponent.DataComponentTypes;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
@@ -116,6 +117,22 @@ public class ItemChecker {
|
||||
return mineItems.contains(itemType);
|
||||
}
|
||||
|
||||
/**
|
||||
* In newer versions of Minecraft, you can make items glide, which works
|
||||
* like an Elytra.
|
||||
*
|
||||
* @param itemStack The item to check.
|
||||
* @return True/false if the item can glide like an Elytra.
|
||||
*/
|
||||
public boolean canGlide(ItemStack itemStack) {
|
||||
// if it's an elytra, we are good
|
||||
if (itemStack.getType() == Material.ELYTRA) {
|
||||
return true;
|
||||
}
|
||||
// otherwise if it has the GLIDER data
|
||||
return itemStack.hasData(DataComponentTypes.GLIDER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a given item for a target token.
|
||||
*
|
||||
|
||||
@@ -17,17 +17,17 @@
|
||||
|
||||
package lol.hyper.toolstats.tools;
|
||||
|
||||
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
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.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class ItemLore {
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
@@ -97,6 +78,9 @@ public class ItemLore {
|
||||
* @return The lore with the line removed.
|
||||
*/
|
||||
public List<Component> removeLore(List<Component> inputLore, Component toRemove) {
|
||||
if (inputLore == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<Component> newLore = new ArrayList<>(inputLore);
|
||||
newLore.removeIf(line -> PlainTextComponentSerializer.plainText().serialize(line).equals(PlainTextComponentSerializer.plainText().serialize(toRemove)));
|
||||
return newLore;
|
||||
@@ -111,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
|
||||
@@ -185,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);
|
||||
@@ -196,7 +180,7 @@ public class ItemLore {
|
||||
if (oldLine == null || newLine == null) {
|
||||
return null;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
List<Component> newLore = updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
return meta;
|
||||
}
|
||||
@@ -210,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;
|
||||
}
|
||||
|
||||
@@ -284,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);
|
||||
@@ -295,7 +279,7 @@ public class ItemLore {
|
||||
if (oldLine == null || newLine == null) {
|
||||
return null;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
List<Component> newLore = updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
return meta;
|
||||
}
|
||||
@@ -309,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;
|
||||
}
|
||||
|
||||
@@ -382,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);
|
||||
@@ -393,7 +377,7 @@ public class ItemLore {
|
||||
if (oldLine == null || newLine == null) {
|
||||
return null;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
List<Component> newLore = updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
return meta;
|
||||
}
|
||||
@@ -407,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;
|
||||
}
|
||||
|
||||
@@ -480,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);
|
||||
@@ -491,7 +475,7 @@ public class ItemLore {
|
||||
if (oldLine == null || newLine == null) {
|
||||
return null;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
List<Component> newLore = updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
return meta;
|
||||
}
|
||||
@@ -513,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;
|
||||
}
|
||||
|
||||
@@ -586,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);
|
||||
@@ -597,7 +581,7 @@ public class ItemLore {
|
||||
if (oldLine == null || newLine == null) {
|
||||
return null;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
List<Component> newLore = updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
return meta;
|
||||
}
|
||||
@@ -619,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;
|
||||
}
|
||||
|
||||
@@ -692,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);
|
||||
@@ -703,7 +687,7 @@ public class ItemLore {
|
||||
if (oldLine == null || newLine == null) {
|
||||
return null;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
List<Component> newLore = updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
return meta;
|
||||
}
|
||||
@@ -717,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;
|
||||
}
|
||||
|
||||
@@ -800,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);
|
||||
@@ -819,7 +803,7 @@ public class ItemLore {
|
||||
if (oldLine == null || newLine == null) {
|
||||
return null;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
List<Component> newLore = updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
return meta;
|
||||
}
|
||||
@@ -833,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;
|
||||
}
|
||||
|
||||
@@ -906,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);
|
||||
@@ -917,7 +901,7 @@ public class ItemLore {
|
||||
if (oldLine == null || newLine == null) {
|
||||
return null;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
List<Component> newLore = updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
return meta;
|
||||
}
|
||||
@@ -931,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;
|
||||
}
|
||||
|
||||
@@ -1006,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);
|
||||
@@ -1017,7 +1001,7 @@ public class ItemLore {
|
||||
if (oldLine == null || newLine == null) {
|
||||
return null;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
List<Component> newLore = updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
return meta;
|
||||
}
|
||||
@@ -1031,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;
|
||||
}
|
||||
|
||||
@@ -1104,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);
|
||||
@@ -1115,8 +1099,269 @@ public class ItemLore {
|
||||
if (oldLine == null || newLine == null) {
|
||||
return null;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
List<Component> newLore = updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
return meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the item owner lore.
|
||||
*
|
||||
* @param playerName The player's name who owns the items.
|
||||
* @param origin The origin type.
|
||||
* @param item The item.
|
||||
* @return A component with the lore.
|
||||
*/
|
||||
public Component formatOwner(String playerName, int origin, ItemStack item) {
|
||||
switch (origin) {
|
||||
case 0: {
|
||||
if (toolStats.configTools.checkConfig(item.getType(), "crafted-by")) {
|
||||
return toolStats.configTools.formatLore("crafted.crafted-by", "{player}", playerName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
if (toolStats.configTools.checkConfig(item.getType(), "looted-by")) {
|
||||
return toolStats.configTools.formatLore("looted.looted-by", "{player}", playerName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
if (toolStats.configTools.checkConfig(item.getType(), "traded-by")) {
|
||||
return toolStats.configTools.formatLore("traded.traded-by", "{player}", playerName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
if (toolStats.config.getBoolean("enabled.elytra-tag")) {
|
||||
return toolStats.configTools.formatLore("looted.found-by", "{player}", playerName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
if (toolStats.configTools.checkConfig(item.getType(), "fished-by")) {
|
||||
return toolStats.configTools.formatLore("fished.caught-by", "{player}", playerName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
if (toolStats.configTools.checkConfig(item.getType(), "spawned-in-by")) {
|
||||
return toolStats.configTools.formatLore("spawned-in.spawned-by", "{player}", playerName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the item creation time.
|
||||
*
|
||||
* @param creationDate When the item was created.
|
||||
* @param origin The origin type.
|
||||
* @param item The item.
|
||||
* @return A component with the lore.
|
||||
*/
|
||||
public Component formatCreationTime(long creationDate, int origin, ItemStack item) {
|
||||
String date = toolStats.numberFormat.formatDate(new Date(creationDate));
|
||||
switch (origin) {
|
||||
case 0: {
|
||||
if (toolStats.configTools.checkConfig(item.getType(), "crafted-on")) {
|
||||
return toolStats.configTools.formatLore("crafted.crafted-on", "{date}", date);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
if (toolStats.config.getBoolean("enabled.dropped-on")) {
|
||||
return toolStats.configTools.formatLore("dropped-on", "{date}", date);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
if (toolStats.configTools.checkConfig(item.getType(), "looted-on")) {
|
||||
return toolStats.configTools.formatLore("looted.looted-on", "{date}", date);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
if (toolStats.configTools.checkConfig(item.getType(), "traded-on")) {
|
||||
return toolStats.configTools.formatLore("traded.traded-on", "{date}", date);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
if (toolStats.config.getBoolean("enabled.elytra-tag")) {
|
||||
return toolStats.configTools.formatLore("looted.found-on", "{date}", date);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
if (toolStats.configTools.checkConfig(item.getType(), "fished-on")) {
|
||||
return toolStats.configTools.formatLore("fished.caught-on", "{date}", date);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
if (toolStats.configTools.checkConfig(item.getType(), "spawned-in-on")) {
|
||||
return toolStats.configTools.formatLore("spawned-in.spawned-on", "{date}", date);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all stats, ownership, and creation time from an item.
|
||||
*
|
||||
* @param inputItem The input item to remove stats from.
|
||||
* @param removeMeta Remove ownership and creation time?
|
||||
*/
|
||||
public ItemStack removeAll(ItemStack inputItem, boolean removeMeta) {
|
||||
ItemStack finalItem = inputItem.clone();
|
||||
ItemMeta meta = finalItem.getItemMeta();
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
// remove the applied tokens
|
||||
if (container.has(toolStats.tokenApplied)) {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
}
|
||||
|
||||
if (container.has(toolStats.playerKills)) {
|
||||
Integer playerKills = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
|
||||
if (playerKills != null) {
|
||||
container.remove(toolStats.playerKills);
|
||||
|
||||
String playerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("kills.player", "{kills}", playerKillsFormatted);
|
||||
meta.lore(removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
if (container.has(toolStats.mobKills)) {
|
||||
Integer mobKills = container.get(toolStats.mobKills, PersistentDataType.INTEGER);
|
||||
if (mobKills != null) {
|
||||
container.remove(toolStats.mobKills);
|
||||
String mobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("kills.mob", "{kills}", mobKillsFormatted);
|
||||
meta.lore(removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
if (container.has(toolStats.blocksMined)) {
|
||||
Integer blocksMined = container.get(toolStats.blocksMined, PersistentDataType.INTEGER);
|
||||
if (blocksMined != null) {
|
||||
container.remove(toolStats.blocksMined);
|
||||
String blocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("blocks-mined", "{blocks}", blocksMinedFormatted);
|
||||
meta.lore(removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
if (container.has(toolStats.cropsHarvested)) {
|
||||
Integer cropsHarvested = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
|
||||
if (cropsHarvested != null) {
|
||||
container.remove(toolStats.cropsHarvested);
|
||||
String cropsHarvestedFormatted = toolStats.numberFormat.formatInt(cropsHarvested);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("crops-harvested", "{crops}", cropsHarvestedFormatted);
|
||||
meta.lore(removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
if (container.has(toolStats.fishCaught)) {
|
||||
Integer fishCaught = container.get(toolStats.fishCaught, PersistentDataType.INTEGER);
|
||||
if (fishCaught != null) {
|
||||
container.remove(toolStats.fishCaught);
|
||||
String fishCaughtFormatted = toolStats.numberFormat.formatInt(fishCaught);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", fishCaughtFormatted);
|
||||
meta.lore(removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
if (container.has(toolStats.sheepSheared)) {
|
||||
Integer sheepSheared = container.get(toolStats.sheepSheared, PersistentDataType.INTEGER);
|
||||
if (sheepSheared != null) {
|
||||
container.remove(toolStats.sheepSheared);
|
||||
String sheepShearedFormatted = toolStats.numberFormat.formatInt(sheepSheared);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("sheep.sheared", "{sheep}", sheepShearedFormatted);
|
||||
meta.lore(removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
if (container.has(toolStats.armorDamage)) {
|
||||
Double armorDamage = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
|
||||
if (armorDamage != null) {
|
||||
container.remove(toolStats.armorDamage);
|
||||
String armorDamageFormatted = toolStats.numberFormat.formatDouble(armorDamage);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("damage-taken", "{damage}", armorDamageFormatted);
|
||||
meta.lore(removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
if (container.has(toolStats.damageDone)) {
|
||||
Double damageDone = container.get(toolStats.damageDone, PersistentDataType.DOUBLE);
|
||||
if (damageDone != null) {
|
||||
container.remove(toolStats.damageDone);
|
||||
String damageDoneFormatted = toolStats.numberFormat.formatDouble(damageDone);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("damage-done", "{damage}", damageDoneFormatted);
|
||||
meta.lore(removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
if (container.has(toolStats.arrowsShot)) {
|
||||
Integer arrowsShot = container.get(toolStats.arrowsShot, PersistentDataType.INTEGER);
|
||||
if (arrowsShot != null) {
|
||||
container.remove(toolStats.arrowsShot);
|
||||
|
||||
String arrowsShotFormatted = toolStats.numberFormat.formatInt(arrowsShot);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("arrows-shot", "{arrows}", arrowsShotFormatted);
|
||||
meta.lore(removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
if (container.has(toolStats.flightTime)) {
|
||||
Long flightTime = container.get(toolStats.flightTime, PersistentDataType.LONG);
|
||||
if (flightTime != null) {
|
||||
container.remove(toolStats.flightTime);
|
||||
Map<String, String> flightTimeFormatted = toolStats.numberFormat.formatTime(flightTime);
|
||||
Component lineToRemove = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", flightTimeFormatted);
|
||||
meta.lore(removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
if (removeMeta) {
|
||||
Integer origin = null;
|
||||
if (container.has(toolStats.originType)) {
|
||||
origin = container.get(toolStats.originType, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
if (container.has(toolStats.timeCreated)) {
|
||||
Long timeCreated = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||
if (timeCreated != null && origin != null) {
|
||||
container.remove(toolStats.timeCreated);
|
||||
Component timeCreatedLore = formatCreationTime(timeCreated, origin, finalItem);
|
||||
meta.lore(removeLore(meta.lore(), timeCreatedLore));
|
||||
}
|
||||
}
|
||||
if (container.has(toolStats.itemOwner)) {
|
||||
UUID owner = container.get(toolStats.itemOwner, new UUIDDataType());
|
||||
if (owner != null && origin != null) {
|
||||
container.remove(toolStats.itemOwner);
|
||||
String ownerName = Bukkit.getOfflinePlayer(owner).getName();
|
||||
if (ownerName != null) {
|
||||
Component ownerLore = formatOwner(ownerName, origin, finalItem);
|
||||
meta.lore(removeLore(meta.lore(), ownerLore));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (origin != null) {
|
||||
container.remove(toolStats.originType);
|
||||
}
|
||||
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
|
||||
return finalItem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -170,7 +170,8 @@ public class TokenData {
|
||||
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
||||
|
||||
// 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);
|
||||
tokenMeta.displayName(title);
|
||||
tokenMeta.lore(lore);
|
||||
@@ -184,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);
|
||||
@@ -207,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();
|
||||
@@ -216,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 net.kyori.adventure.text.Component;
|
||||
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 java.util.ArrayList;
|
||||
@@ -34,8 +32,6 @@ import java.util.regex.Pattern;
|
||||
public class ConfigTools {
|
||||
|
||||
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) {
|
||||
this.toolStats = toolStats;
|
||||
@@ -50,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;
|
||||
}
|
||||
|
||||
@@ -108,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;
|
||||
}
|
||||
|
||||
@@ -125,16 +121,7 @@ public class ConfigTools {
|
||||
lore = lore.replace(placeHolder, String.valueOf(value));
|
||||
}
|
||||
|
||||
// if we match the old color codes, then format them as so
|
||||
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);
|
||||
}
|
||||
|
||||
component = toolStats.textUtils.format(lore);
|
||||
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
|
||||
}
|
||||
|
||||
@@ -148,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;
|
||||
}
|
||||
|
||||
@@ -183,49 +170,7 @@ public class ConfigTools {
|
||||
Component component;
|
||||
// Clean output text
|
||||
String outputText = result.toString().replaceAll("\\s+", " ").trim();
|
||||
|
||||
// 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);
|
||||
}
|
||||
component = toolStats.textUtils.format(outputText);
|
||||
|
||||
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
|
||||
}
|
||||
@@ -251,16 +196,7 @@ public class ConfigTools {
|
||||
line = line.replace("{levels}", String.valueOf(levels));
|
||||
}
|
||||
}
|
||||
Component component;
|
||||
// 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 = toolStats.textUtils.format(line);
|
||||
component = component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
|
||||
finalLore.add(component);
|
||||
}
|
||||
|
||||
@@ -43,8 +43,7 @@ public class Version10 {
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-9.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config-9.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
toolStats.logger.error("Unable to save config-9.yml!", exception);
|
||||
}
|
||||
|
||||
// we make this super verbose so that admins can see what's being added
|
||||
@@ -72,8 +71,7 @@ public class Version10 {
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||
}
|
||||
toolStats.loadConfig();
|
||||
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 {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-10.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config-10.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
toolStats.logger.error("Unable to save config-10.yml!", exception);
|
||||
}
|
||||
|
||||
// we make this super verbose so that admins can see what's being added
|
||||
@@ -95,8 +94,7 @@ public class Version11 {
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||
}
|
||||
toolStats.loadConfig();
|
||||
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 {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-11.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config-11.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
toolStats.logger.error("Unable to save config-11.yml!", exception);
|
||||
}
|
||||
|
||||
toolStats.logger.info("Updating config.yml to version 12.");
|
||||
@@ -102,15 +101,14 @@ public class Version12 {
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||
}
|
||||
toolStats.loadConfig();
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -43,21 +43,20 @@ public class Version13 {
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-12.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config-12.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
toolStats.logger.error("Unable to save config-12.yml!", exception);
|
||||
}
|
||||
|
||||
toolStats.logger.info("Updating config.yml to version 13.");
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -65,8 +64,7 @@ public class Version13 {
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||
}
|
||||
toolStats.loadConfig();
|
||||
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 {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-5.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config-5.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
toolStats.logger.error("Unable to save config-5.yml!", exception);
|
||||
}
|
||||
|
||||
// we make this super verbose so that admins can see what's being added
|
||||
@@ -107,8 +106,7 @@ public class Version6 {
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||
}
|
||||
toolStats.loadConfig();
|
||||
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 {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-6.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config-6.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
toolStats.logger.error("Unable to save config-6.yml!", exception);
|
||||
}
|
||||
|
||||
// we make this super verbose so that admins can see what's being added
|
||||
@@ -61,8 +60,7 @@ public class Version7 {
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||
}
|
||||
toolStats.loadConfig();
|
||||
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 {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-7.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config-7.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
toolStats.logger.error("Unable to save config-7.yml!", exception);
|
||||
}
|
||||
|
||||
// we make this super verbose so that admins can see what's being added
|
||||
@@ -78,8 +77,7 @@ public class Version8 {
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||
}
|
||||
toolStats.loadConfig();
|
||||
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 {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-8.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config-8.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
toolStats.logger.error("Unable to save config-8.yml!", exception);
|
||||
}
|
||||
|
||||
toolStats.logger.info("Updating config.yml to version 9.");
|
||||
@@ -78,8 +77,7 @@ public class Version9 {
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||
}
|
||||
toolStats.loadConfig();
|
||||
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.
|
||||
*/
|
||||
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);
|
||||
|
||||
@@ -23,6 +23,12 @@ permissions:
|
||||
toolstats.reset.confirm:
|
||||
description: Allows the usage of /toolstats reset confirm.
|
||||
default: true
|
||||
toolstats.purge:
|
||||
description: Allows the usage of /toolstats purge.
|
||||
default: true
|
||||
toolstats.purge.confirm:
|
||||
description: Allows the usage of /toolstats purge confirm.
|
||||
default: true
|
||||
toolstats.givetokens:
|
||||
description: Allows the usage of /toolstats givetoken.
|
||||
default: op
|
||||
|
||||