mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
migration to Paper API
This commit is contained in:
44
pom.xml
44
pom.xml
@@ -29,7 +29,7 @@
|
||||
<name>ToolStats</name>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<java.version>21</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
@@ -67,18 +67,10 @@
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>lol.hyper.toolstats.bstats</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>net.kyori.adventure</pattern>
|
||||
<shadedPattern>lol.hyper.toolstats.adventure</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>lol.hyper.githubreleaseapi</pattern>
|
||||
<shadedPattern>lol.hyper.toolstats.updater</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>space.arim.morepaperlib</pattern>
|
||||
<shadedPattern>lol.hyper.toolstats.morepaperlib</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
<executions>
|
||||
@@ -104,8 +96,8 @@
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
<id>papermc</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>arim-mvn-lgpl3</id>
|
||||
@@ -115,9 +107,9 @@
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.20.2-R0.1-SNAPSHOT</version>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.21.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -132,29 +124,5 @@
|
||||
<version>1.0.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>4.17.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
<version>4.3.4</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>space.arim.morepaperlib</groupId>
|
||||
<artifactId>morepaperlib</artifactId>
|
||||
<version>0.4.4</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
<version>1.20-R0.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -27,17 +27,13 @@ import lol.hyper.toolstats.tools.ItemLore;
|
||||
import lol.hyper.toolstats.tools.NumberFormat;
|
||||
import lol.hyper.toolstats.tools.config.ConfigTools;
|
||||
import lol.hyper.toolstats.tools.config.ConfigUpdater;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import space.arim.morepaperlib.MorePaperLib;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -81,10 +77,6 @@ public final class ToolStats extends JavaPlugin {
|
||||
* Stores how much damage an armor piece has taken.
|
||||
*/
|
||||
public final NamespacedKey armorDamage = new NamespacedKey(this, "damage-taken");
|
||||
/**
|
||||
* Stores how much damage an armor piece has taken (as an int).
|
||||
*/
|
||||
public final NamespacedKey armorDamageInt = new NamespacedKey(this, "damage-taken-int");
|
||||
/**
|
||||
* Key for tracking new elytras that spawn.
|
||||
*/
|
||||
@@ -134,8 +126,6 @@ public final class ToolStats extends JavaPlugin {
|
||||
public PlayerJoin playerJoin;
|
||||
public NumberFormat numberFormat;
|
||||
public YamlConfiguration config;
|
||||
private BukkitAudiences adventure;
|
||||
public MorePaperLib morePaperLib;
|
||||
public HashMaker hashMaker;
|
||||
public CreativeEvent creativeEvent;
|
||||
public PlayerMove playerMove;
|
||||
@@ -145,8 +135,6 @@ public final class ToolStats extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.adventure = BukkitAudiences.create(this);
|
||||
morePaperLib = new MorePaperLib(this);
|
||||
if (!configFile.exists()) {
|
||||
this.saveResource("config.yml", true);
|
||||
logger.info("Copying default config!");
|
||||
@@ -194,8 +182,7 @@ public final class ToolStats extends JavaPlugin {
|
||||
this.getCommand("toolstats").setExecutor(commandToolStats);
|
||||
|
||||
new Metrics(this, 14110);
|
||||
|
||||
morePaperLib.scheduling().asyncScheduler().run(this::checkForUpdates);
|
||||
Bukkit.getAsyncScheduler().runNow(this, scheduledTask -> checkForUpdates());
|
||||
}
|
||||
|
||||
public void loadConfig() {
|
||||
@@ -231,23 +218,4 @@ public final class ToolStats extends JavaPlugin {
|
||||
logger.warning("A new version is available (" + latest.getTagVersion() + ")! You are running version " + current.getTagVersion() + ". You are " + buildsBehind + " version(s) behind.");
|
||||
}
|
||||
}
|
||||
|
||||
public BukkitAudiences getAdventure() {
|
||||
if (this.adventure == null) {
|
||||
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
|
||||
}
|
||||
return this.adventure;
|
||||
}
|
||||
|
||||
public void scheduleEntity(BukkitRunnable runnable, Entity entity, int delay) {
|
||||
morePaperLib.scheduling().entitySpecificScheduler(entity).runDelayed(runnable, null, delay);
|
||||
}
|
||||
|
||||
public void scheduleGlobal(BukkitRunnable runnable, int delay) {
|
||||
morePaperLib.scheduling().globalRegionalScheduler().runDelayed(runnable, delay);
|
||||
}
|
||||
|
||||
public void scheduleRegion(BukkitRunnable runnable, World world, Chunk chunk, int delay) {
|
||||
morePaperLib.scheduling().regionSpecificScheduler(world, chunk.getX(), chunk.getZ()).runDelayed(runnable, delay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package lol.hyper.toolstats.commands;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -42,65 +41,63 @@ import java.util.*;
|
||||
public class CommandToolStats implements TabExecutor {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
private final BukkitAudiences audiences;
|
||||
|
||||
public CommandToolStats(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
this.audiences = toolStats.getAdventure();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (!sender.hasPermission("toolstats.command")) {
|
||||
audiences.sender(sender).sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
|
||||
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
audiences.sender(sender).sendMessage(Component.text("ToolStats version " + toolStats.getDescription().getVersion() + ". Created by hyperdefined.", NamedTextColor.GREEN));
|
||||
sender.sendMessage(Component.text("ToolStats version " + toolStats.getPluginMeta().getVersion() + ". Created by hyperdefined.", NamedTextColor.GREEN));
|
||||
return true;
|
||||
}
|
||||
switch (args[0]) {
|
||||
case "reload": {
|
||||
if (sender.hasPermission("toolstats.reload")) {
|
||||
toolStats.loadConfig();
|
||||
audiences.sender(sender).sendMessage(Component.text("Configuration reloaded!", NamedTextColor.GREEN));
|
||||
sender.sendMessage(Component.text("Configuration reloaded!", NamedTextColor.GREEN));
|
||||
} else {
|
||||
audiences.sender(sender).sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
|
||||
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "reset": {
|
||||
if (!sender.hasPermission("toolstats.reset")) {
|
||||
audiences.sender(sender).sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
|
||||
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
audiences.sender(sender).sendMessage(Component.text("You must be a player for this command.", NamedTextColor.RED));
|
||||
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.reset.confirm")) {
|
||||
audiences.sender(sender).sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
|
||||
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())) {
|
||||
audiences.sender(sender).sendMessage(Component.text("You must hold a valid item.", NamedTextColor.RED));
|
||||
sender.sendMessage(Component.text("You must hold a valid item.", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
fixItemLore(heldItem, player);
|
||||
audiences.sender(sender).sendMessage(Component.text("The lore was reset!", NamedTextColor.GREEN));
|
||||
sender.sendMessage(Component.text("The lore was reset!", NamedTextColor.GREEN));
|
||||
return true;
|
||||
}
|
||||
audiences.sender(sender).sendMessage(Component.text("This will remove ALL current lore from the held item and replace it with the correct lore.", NamedTextColor.GREEN));
|
||||
audiences.sender(sender).sendMessage(Component.text("If the owner of the item is broken, it will reset to the person holding it.", NamedTextColor.GREEN));
|
||||
audiences.sender(sender).sendMessage(Component.text("Only use this if the tags on the tool are incorrect.", NamedTextColor.GREEN));
|
||||
audiences.sender(sender).sendMessage(Component.text("Type /toolstats reset confirm to confirm this.", NamedTextColor.GREEN));
|
||||
sender.sendMessage(Component.text("This will remove ALL current lore from the held item and replace it with the correct lore.", NamedTextColor.GREEN));
|
||||
sender.sendMessage(Component.text("If the owner of the item is broken, it will reset to the person holding it.", NamedTextColor.GREEN));
|
||||
sender.sendMessage(Component.text("Only use this if the tags on the tool are incorrect.", NamedTextColor.GREEN));
|
||||
sender.sendMessage(Component.text("Type /toolstats reset confirm to confirm this.", NamedTextColor.GREEN));
|
||||
return true;
|
||||
}
|
||||
default: {
|
||||
audiences.sender(sender).sendMessage(Component.text("Invalid sub-command.", NamedTextColor.RED));
|
||||
sender.sendMessage(Component.text("Invalid sub-command.", NamedTextColor.RED));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -119,7 +116,7 @@ public class CommandToolStats implements TabExecutor {
|
||||
return;
|
||||
}
|
||||
PersistentDataContainer container = finalMeta.getPersistentDataContainer();
|
||||
List<String> lore = new ArrayList<>();
|
||||
List<Component> lore = new ArrayList<>();
|
||||
|
||||
// set how the item was obtained
|
||||
Integer origin = -1;
|
||||
@@ -145,19 +142,19 @@ public class CommandToolStats implements TabExecutor {
|
||||
|
||||
if (flightTime != null) {
|
||||
if (toolStats.config.getBoolean("enabled.flight-time")) {
|
||||
String line = toolStats.configTools.formatLore("flight-time", "{time}", toolStats.numberFormat.formatDouble((double) flightTime / 1000));
|
||||
Component line = toolStats.configTools.formatLore("flight-time", "{time}", toolStats.numberFormat.formatDouble((double) flightTime / 1000));
|
||||
lore.add(line);
|
||||
}
|
||||
}
|
||||
|
||||
if (timeCreated != null) {
|
||||
String timeCreatedLine = toolStats.configTools.formatLore("looted.found-by", "{player}", player.getName());
|
||||
String playerOwnerLine = toolStats.configTools.formatLore("looted.found-on", "{date}", toolStats.numberFormat.formatDate(new Date(timeCreated)));
|
||||
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.setLore(lore);
|
||||
finalMeta.lore(lore);
|
||||
finalItem.setItemMeta(finalMeta);
|
||||
int slot = player.getInventory().getHeldItemSlot();
|
||||
player.getInventory().setItem(slot, finalItem);
|
||||
@@ -176,7 +173,7 @@ public class CommandToolStats implements TabExecutor {
|
||||
// if the owner's name is null for whatever reason, set the new owner
|
||||
// to the current player running the command
|
||||
if (ownerName == null) {
|
||||
audiences.player(player).sendMessage(Component.text("The owner of this item is null. Setting to " + player.getName() + ".", NamedTextColor.RED));
|
||||
player.sendMessage(Component.text("The owner of this item is null. Setting to " + player.getName() + ".", NamedTextColor.RED));
|
||||
ownerName = player.getName();
|
||||
container.set(toolStats.genericOwner, new UUIDDataType(), player.getUniqueId());
|
||||
}
|
||||
@@ -309,7 +306,7 @@ public class CommandToolStats implements TabExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
finalMeta.setLore(lore);
|
||||
finalMeta.lore(lore);
|
||||
finalItem.setItemMeta(finalMeta);
|
||||
int slot = player.getInventory().getHeldItemSlot();
|
||||
player.getInventory().setItem(slot, finalItem);
|
||||
|
||||
@@ -17,7 +17,10 @@
|
||||
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -36,6 +39,7 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class BlocksMined implements Listener {
|
||||
|
||||
@@ -60,13 +64,7 @@ public class BlocksMined implements Listener {
|
||||
|
||||
if (block.getType() == Material.CHEST) {
|
||||
toolStats.playerInteract.openedChests.put(block, player);
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
toolStats.playerInteract.openedChests.remove(block);
|
||||
}
|
||||
};
|
||||
toolStats.scheduleGlobal(runnable, 20);
|
||||
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> toolStats.playerInteract.openedChests.remove(block), 20);
|
||||
}
|
||||
|
||||
// only check certain items
|
||||
@@ -110,13 +108,13 @@ public class BlocksMined implements Listener {
|
||||
if (toolStats.configTools.checkConfig(playerTool.getType(), "blocks-mined")) {
|
||||
String oldBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
|
||||
String newBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined + 1);
|
||||
String oldLine = toolStats.configTools.formatLore("blocks-mined", "{blocks}", oldBlocksMinedFormatted);
|
||||
String newLine = toolStats.configTools.formatLore("blocks-mined", "{blocks}", newBlocksMinedFormatted);
|
||||
Component oldLine = toolStats.configTools.formatLore("blocks-mined", "{blocks}", oldBlocksMinedFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("blocks-mined", "{blocks}", newBlocksMinedFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return;
|
||||
}
|
||||
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.setLore(newLore);
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
playerTool.setItemMeta(meta);
|
||||
}
|
||||
@@ -151,13 +149,13 @@ public class BlocksMined implements Listener {
|
||||
if (toolStats.configTools.checkConfig(playerTool.getType(), "blocks-mined")) {
|
||||
String oldCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined);
|
||||
String newCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined + 1);
|
||||
String oldLine = toolStats.configTools.formatLore("crops-harvested", "{crops}", oldCropsMinedFormatted);
|
||||
String newLine = toolStats.configTools.formatLore("crops-harvested", "{crops}", newCropsMinedFormatted);
|
||||
Component oldLine = toolStats.configTools.formatLore("crops-harvested", "{crops}", oldCropsMinedFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("crops-harvested", "{crops}", newCropsMinedFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return;
|
||||
}
|
||||
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.setLore(newLore);
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
playerTool.setItemMeta(meta);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@@ -31,7 +32,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class ChunkPopulate implements Listener {
|
||||
|
||||
@@ -49,34 +49,30 @@ public class ChunkPopulate implements Listener {
|
||||
if (event.getChunk().getWorld().getEnvironment() != World.Environment.THE_END) {
|
||||
return;
|
||||
}
|
||||
World world = event.getChunk().getWorld();
|
||||
// this is delayed because entities are not loaded instantly
|
||||
// we just check 1 second later
|
||||
Chunk chunk = event.getChunk();
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
// if there is a new item frame
|
||||
if (!(entity instanceof ItemFrame)) {
|
||||
Bukkit.getRegionScheduler().runDelayed(toolStats, world, chunk.getX(), chunk.getZ(), scheduledTask -> {
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
// if there is a new item frame
|
||||
if (!(entity instanceof ItemFrame itemFrame)) {
|
||||
continue;
|
||||
}
|
||||
// if the item frame has an elytra
|
||||
if (itemFrame.getItem().getType() == Material.ELYTRA) {
|
||||
ItemStack elytraCopy = itemFrame.getItem();
|
||||
ItemMeta meta = elytraCopy.getItemMeta();
|
||||
if (meta == null) {
|
||||
continue;
|
||||
}
|
||||
ItemFrame itemFrame = (ItemFrame) entity;
|
||||
// if the item frame has an elytra
|
||||
if (itemFrame.getItem().getType() == Material.ELYTRA) {
|
||||
ItemStack elytraCopy = itemFrame.getItem();
|
||||
ItemMeta meta = elytraCopy.getItemMeta();
|
||||
if (meta == null) {
|
||||
continue;
|
||||
}
|
||||
// add the new tag so we know it's new
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.set(toolStats.newElytra, PersistentDataType.INTEGER, 1);
|
||||
elytraCopy.setItemMeta(meta);
|
||||
itemFrame.setItem(elytraCopy);
|
||||
}
|
||||
// add the new tag so we know it's new
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.set(toolStats.newElytra, PersistentDataType.INTEGER, 1);
|
||||
elytraCopy.setItemMeta(meta);
|
||||
itemFrame.setItem(elytraCopy);
|
||||
}
|
||||
}
|
||||
};
|
||||
toolStats.scheduleRegion(runnable, chunk.getWorld(), chunk, 20);
|
||||
}, 20);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import org.bukkit.ChatColor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -32,7 +32,9 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class CraftItem implements Listener {
|
||||
|
||||
@@ -62,13 +64,10 @@ public class CraftItem implements Listener {
|
||||
|
||||
// if the player shift clicks, send them this warning
|
||||
if (event.isShiftClick()) {
|
||||
String configMessage = toolStats.config.getString("messages.shift-click-warning.crafting");
|
||||
if (configMessage != null) {
|
||||
if (!configMessage.isEmpty()) {
|
||||
event.getWhoClicked().sendMessage(ChatColor.translateAlternateColorCodes('&', configMessage));
|
||||
}
|
||||
}
|
||||
Component component = toolStats.configTools.formatLore("shift-click-warning", null, null);
|
||||
event.getWhoClicked().sendMessage(component);
|
||||
}
|
||||
|
||||
// test the item before setting it
|
||||
ItemStack newItem = addLore(itemStack, player);
|
||||
if (newItem != null) {
|
||||
@@ -113,30 +112,30 @@ public class CraftItem implements Listener {
|
||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 0);
|
||||
|
||||
List<String> lore;
|
||||
List<Component> lore;
|
||||
// get the current lore the item
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
lore = meta.lore();
|
||||
} else {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
// do we add the lore based on the config?
|
||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "created-date")) {
|
||||
String date = toolStats.numberFormat.formatDate(finalDate);
|
||||
String newLine = toolStats.configTools.formatLore("created.created-on", "{date}", date);
|
||||
Component newLine = toolStats.configTools.formatLore("created.created-on", "{date}", date);
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
meta.setLore(lore);
|
||||
meta.lore(lore);
|
||||
}
|
||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "created-by")) {
|
||||
String newLine = toolStats.configTools.formatLore("created.created-by", "{player}", owner.getName());
|
||||
Component newLine = toolStats.configTools.formatLore("created.created-by", "{player}", owner.getName());
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
meta.setLore(lore);
|
||||
meta.lore(lore);
|
||||
}
|
||||
newItem.setItemMeta(meta);
|
||||
return newItem;
|
||||
|
||||
@@ -19,6 +19,7 @@ package lol.hyper.toolstats.events;
|
||||
|
||||
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;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -104,8 +105,8 @@ public class CreativeEvent implements Listener {
|
||||
|
||||
if (toolStats.configTools.checkConfig(newSpawnedItem.getType(), "spawned-in")) {
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.setLore(newLore);
|
||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
|
||||
newSpawnedItem.setItemMeta(meta);
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.*;
|
||||
@@ -51,10 +52,9 @@ public class EntityDamage implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
||||
if (!(event.getEntity() instanceof LivingEntity mobBeingAttacked)) {
|
||||
return;
|
||||
}
|
||||
LivingEntity mobBeingAttacked = (LivingEntity) event.getEntity();
|
||||
|
||||
// ignore void and /kill damage
|
||||
String cause = event.getCause().toString().toUpperCase();
|
||||
@@ -65,8 +65,7 @@ public class EntityDamage implements Listener {
|
||||
// mob is going to die
|
||||
if (mobBeingAttacked.getHealth() - event.getFinalDamage() <= 0) {
|
||||
// a player is killing something
|
||||
if (event.getDamager() instanceof Player) {
|
||||
Player attackingPlayer = (Player) event.getDamager();
|
||||
if (event.getDamager() instanceof Player attackingPlayer) {
|
||||
if (attackingPlayer.getGameMode() == GameMode.CREATIVE || attackingPlayer.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
@@ -86,27 +85,24 @@ public class EntityDamage implements Listener {
|
||||
trackedMobs.add(mobBeingAttacked.getUniqueId());
|
||||
}
|
||||
// trident is being thrown at something
|
||||
if (event.getDamager() instanceof Trident) {
|
||||
Trident trident = (Trident) event.getDamager();
|
||||
if (event.getDamager() instanceof Trident trident) {
|
||||
ItemStack newTrident;
|
||||
// trident is killing player
|
||||
if (mobBeingAttacked instanceof Player) {
|
||||
newTrident = tridentPlayerKills(trident.getItem());
|
||||
newTrident = tridentPlayerKills(trident.getItemStack());
|
||||
} else {
|
||||
// trident is killing a mob
|
||||
newTrident = tridentMobKills(trident.getItem());
|
||||
newTrident = tridentMobKills(trident.getItemStack());
|
||||
trackedMobs.add(mobBeingAttacked.getUniqueId());
|
||||
}
|
||||
if (newTrident != null) {
|
||||
trident.setItem(newTrident);
|
||||
trident.setItemStack(newTrident);
|
||||
}
|
||||
}
|
||||
// arrow is being shot
|
||||
if (event.getDamager() instanceof Arrow) {
|
||||
Arrow arrow = (Arrow) event.getDamager();
|
||||
if (event.getDamager() instanceof Arrow arrow) {
|
||||
// if the shooter is a player
|
||||
if (arrow.getShooter() instanceof Player) {
|
||||
Player shootingPlayer = (Player) arrow.getShooter();
|
||||
if (arrow.getShooter() instanceof Player shootingPlayer) {
|
||||
if (shootingPlayer.getGameMode() == GameMode.CREATIVE || shootingPlayer.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
@@ -143,8 +139,7 @@ public class EntityDamage implements Listener {
|
||||
}
|
||||
}
|
||||
// player is taken damage but not being killed
|
||||
if (mobBeingAttacked instanceof Player) {
|
||||
Player playerTakingDamage = (Player) mobBeingAttacked;
|
||||
if (mobBeingAttacked instanceof Player playerTakingDamage) {
|
||||
if (playerTakingDamage.getGameMode() == GameMode.CREATIVE || playerTakingDamage.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
@@ -161,7 +156,7 @@ public class EntityDamage implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onDamage(EntityDamageEvent event) {
|
||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
||||
if (!(event.getEntity() instanceof LivingEntity mobBeingAttacked)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -171,10 +166,8 @@ public class EntityDamage implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity mobBeingAttacked = (LivingEntity) event.getEntity();
|
||||
// player is taken damage but not being killed
|
||||
if (mobBeingAttacked instanceof Player) {
|
||||
Player playerTakingDamage = (Player) mobBeingAttacked;
|
||||
if (mobBeingAttacked instanceof Player playerTakingDamage) {
|
||||
if (playerTakingDamage.getGameMode() == GameMode.CREATIVE || playerTakingDamage.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
@@ -191,7 +184,7 @@ public class EntityDamage implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onDamage(EntityDamageByBlockEvent event) {
|
||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
||||
if (!(event.getEntity() instanceof LivingEntity mobBeingAttacked)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -201,10 +194,8 @@ public class EntityDamage implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity mobBeingAttacked = (LivingEntity) event.getEntity();
|
||||
// player is taken damage but not being killed
|
||||
if (mobBeingAttacked instanceof Player) {
|
||||
Player playerTakingDamage = (Player) mobBeingAttacked;
|
||||
if (mobBeingAttacked instanceof Player playerTakingDamage) {
|
||||
if (playerTakingDamage.getGameMode() == GameMode.CREATIVE || playerTakingDamage.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
@@ -247,13 +238,13 @@ public class EntityDamage implements Listener {
|
||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "player-kills")) {
|
||||
String oldPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
||||
String newPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills + 1);
|
||||
String oldLine = toolStats.configTools.formatLore("kills.player", "{kills}", oldPlayerKillsFormatted);
|
||||
String newLine = toolStats.configTools.formatLore("kills.player", "{kills}", newPlayerKillsFormatted);
|
||||
Component oldLine = toolStats.configTools.formatLore("kills.player", "{kills}", oldPlayerKillsFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("kills.player", "{kills}", newPlayerKillsFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return;
|
||||
}
|
||||
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.setLore(newLore);
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
@@ -286,13 +277,13 @@ public class EntityDamage implements Listener {
|
||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "mob-kills")) {
|
||||
String oldMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
||||
String newMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills + 1);
|
||||
String oldLine = toolStats.configTools.formatLore("kills.mob", "{kills}", oldMobKillsFormatted);
|
||||
String newLine = toolStats.configTools.formatLore("kills.mob", "{kills}", newMobKillsFormatted);
|
||||
Component oldLine = toolStats.configTools.formatLore("kills.mob", "{kills}", oldMobKillsFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("kills.mob", "{kills}", newMobKillsFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return;
|
||||
}
|
||||
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.setLore(newLore);
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
@@ -329,13 +320,13 @@ public class EntityDamage implements Listener {
|
||||
if (toolStats.config.getBoolean("enabled.armor-damage")) {
|
||||
String oldDamageFormatted = toolStats.numberFormat.formatDouble(damageTaken);
|
||||
String newDamageFormatted = toolStats.numberFormat.formatDouble(damageTaken + damage);
|
||||
String oldLine = toolStats.configTools.formatLore("damage-taken", "{damage}", oldDamageFormatted);
|
||||
String newLine = toolStats.configTools.formatLore("damage-taken", "{damage}", newDamageFormatted);
|
||||
Component oldLine = toolStats.configTools.formatLore("damage-taken", "{damage}", oldDamageFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("damage-taken", "{damage}", newDamageFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return;
|
||||
}
|
||||
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.setLore(newLore);
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
@@ -369,13 +360,13 @@ public class EntityDamage implements Listener {
|
||||
if (toolStats.configTools.checkConfig(newTrident.getType(), "mob-kills")) {
|
||||
String oldMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
||||
String newMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills + 1);
|
||||
String oldLine = toolStats.configTools.formatLore("kills.mob", "{kills}", oldMobKillsFormatted);
|
||||
String newLine = toolStats.configTools.formatLore("kills.mob", "{kills}", newMobKillsFormatted);
|
||||
Component oldLine = toolStats.configTools.formatLore("kills.mob", "{kills}", oldMobKillsFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("kills.mob", "{kills}", newMobKillsFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return null;
|
||||
}
|
||||
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.setLore(newLore);
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
newTrident.setItemMeta(meta);
|
||||
return newTrident;
|
||||
@@ -410,13 +401,13 @@ public class EntityDamage implements Listener {
|
||||
if (toolStats.configTools.checkConfig(newTrident.getType(), "player-kills")) {
|
||||
String oldPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
||||
String newPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills + 1);
|
||||
String oldLine = toolStats.configTools.formatLore("kills.player", "{kills}", oldPlayerKillsFormatted);
|
||||
String newLine = toolStats.configTools.formatLore("kills.player", "{kills}", newPlayerKillsFormatted);
|
||||
Component oldLine = toolStats.configTools.formatLore("kills.player", "{kills}", oldPlayerKillsFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("kills.player", "{kills}", newPlayerKillsFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return null;
|
||||
}
|
||||
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.setLore(newLore);
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
newTrident.setItemMeta(meta);
|
||||
return newTrident;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -91,9 +92,9 @@ public class EntityDeath implements Listener {
|
||||
if (mobName == null) {
|
||||
mobName = entity.getName();
|
||||
}
|
||||
String newLine = toolStats.configTools.formatLore("dropped-by", "{name}", mobName);
|
||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, newLine);
|
||||
meta.setLore(newLore);
|
||||
Component newLine = toolStats.configTools.formatLore("dropped-by", "{name}", mobName);
|
||||
List<Component> newLore = toolStats.itemLore.addItemLore(meta, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
newItem.setItemMeta(meta);
|
||||
return newItem;
|
||||
|
||||
@@ -19,6 +19,7 @@ package lol.hyper.toolstats.events;
|
||||
|
||||
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;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -76,8 +77,7 @@ public class GenerateLoot implements Listener {
|
||||
Player player = toolStats.playerInteract.openedChests.get(openedChest);
|
||||
setLoot(event.getLoot(), player);
|
||||
}
|
||||
if (inventoryHolder instanceof StorageMinecart) {
|
||||
StorageMinecart mineCart = (StorageMinecart) inventoryHolder;
|
||||
if (inventoryHolder instanceof StorageMinecart mineCart) {
|
||||
if (toolStats.playerInteract.openedMineCarts.containsKey(mineCart)) {
|
||||
Player player = toolStats.playerInteract.openedMineCarts.get(mineCart);
|
||||
setLoot(event.getLoot(), player);
|
||||
@@ -118,8 +118,8 @@ public class GenerateLoot implements Listener {
|
||||
|
||||
if (toolStats.configTools.checkConfig(newItem.getType(), "looted-tag")) {
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.setLore(newLore);
|
||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
newItem.setItemMeta(meta);
|
||||
return newItem;
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -31,6 +33,7 @@ import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class InventoryOpen implements Listener {
|
||||
|
||||
@@ -83,14 +86,8 @@ public class InventoryOpen implements Listener {
|
||||
}
|
||||
}
|
||||
ItemMeta clone = itemMeta.clone();
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
itemStack.setItemMeta(clone);
|
||||
}
|
||||
};
|
||||
if (location != null) {
|
||||
toolStats.scheduleRegion(runnable, location.getWorld(), location.getChunk(), 1);
|
||||
Bukkit.getRegionScheduler().runDelayed(toolStats, location, scheduledTask -> itemStack.setItemMeta(clone), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package lol.hyper.toolstats.events;
|
||||
|
||||
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;
|
||||
import org.bukkit.entity.*;
|
||||
@@ -48,13 +49,12 @@ public class PickupItem implements Listener {
|
||||
return;
|
||||
}
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
if (entity instanceof Player player) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
Item item = event.getItem();
|
||||
if (item.getType() == EntityType.DROPPED_ITEM) {
|
||||
if (item.getType() == EntityType.ITEM) {
|
||||
ItemStack itemStack = event.getItem().getItemStack();
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta == null) {
|
||||
@@ -103,8 +103,8 @@ public class PickupItem implements Listener {
|
||||
|
||||
if (toolStats.config.getBoolean("enabled.elytra-tag")) {
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.setLore(newLore);
|
||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
finalItem.setItemMeta(meta);
|
||||
return finalItem;
|
||||
|
||||
@@ -19,6 +19,7 @@ package lol.hyper.toolstats.events;
|
||||
|
||||
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;
|
||||
import org.bukkit.entity.Item;
|
||||
@@ -130,13 +131,13 @@ public class PlayerFish implements Listener {
|
||||
if (toolStats.config.getBoolean("enabled.fish-caught")) {
|
||||
String oldFishFormatted = toolStats.numberFormat.formatInt(fishCaught);
|
||||
String newFishFormatted = toolStats.numberFormat.formatInt(fishCaught + 1);
|
||||
String oldLine = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", oldFishFormatted);
|
||||
String newLine = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", newFishFormatted);
|
||||
Component oldLine = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", oldFishFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", newFishFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return;
|
||||
}
|
||||
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.setLore(newLore);
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
fishingRod.setItemMeta(meta);
|
||||
}
|
||||
@@ -171,8 +172,8 @@ public class PlayerFish implements Listener {
|
||||
|
||||
if (toolStats.configTools.checkConfig(newItem.getType(), "fished-tag")) {
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.setLore(newLore);
|
||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
newItem.setItemMeta(meta);
|
||||
return newItem;
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -34,6 +36,7 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class PlayerInteract implements Listener {
|
||||
|
||||
@@ -64,13 +67,7 @@ public class PlayerInteract implements Listener {
|
||||
// store when a player opens a chest
|
||||
if (block.getType() != Material.AIR && block.getType() == Material.CHEST) {
|
||||
openedChests.put(block, player);
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
openedChests.remove(block);
|
||||
}
|
||||
};
|
||||
toolStats.scheduleGlobal(runnable, 20);
|
||||
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> openedChests.remove(block), 20);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,16 +79,10 @@ public class PlayerInteract implements Listener {
|
||||
return;
|
||||
}
|
||||
// store when a player opens a minecart
|
||||
if (clicked.getType() == EntityType.MINECART_CHEST) {
|
||||
if (clicked.getType() == EntityType.CHEST_MINECART) {
|
||||
StorageMinecart storageMinecart = (StorageMinecart) clicked;
|
||||
openedMineCarts.put(storageMinecart, player);
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
openedMineCarts.remove(storageMinecart);
|
||||
}
|
||||
};
|
||||
toolStats.scheduleGlobal(runnable, 20);
|
||||
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> openedMineCarts.remove(storageMinecart), 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -31,6 +32,7 @@ import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class PlayerJoin implements Listener {
|
||||
|
||||
@@ -77,13 +79,7 @@ public class PlayerJoin implements Listener {
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
}
|
||||
ItemMeta clone = itemMeta.clone();
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
itemStack.setItemMeta(clone);
|
||||
}
|
||||
};
|
||||
toolStats.scheduleEntity(runnable, player, 1);
|
||||
player.getScheduler().runDelayed(toolStats, scheduledTask -> itemStack.setItemMeta(clone), null, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -94,13 +95,13 @@ public class PlayerMove implements Listener {
|
||||
if (toolStats.config.getBoolean("enabled.flight-time")) {
|
||||
String oldFlightFormatted = toolStats.numberFormat.formatDouble((double) flightTime / 1000);
|
||||
String newFlightFormatted = toolStats.numberFormat.formatDouble(newDuration / 1000);
|
||||
String oldLine = toolStats.configTools.formatLore("flight-time", "{time}", oldFlightFormatted);
|
||||
String newLine = toolStats.configTools.formatLore("flight-time", "{time}", newFlightFormatted);
|
||||
Component oldLine = toolStats.configTools.formatLore("flight-time", "{time}", oldFlightFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("flight-time", "{time}", newFlightFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return;
|
||||
}
|
||||
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.setLore(newLore);
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
chest.setItemMeta(meta);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -54,7 +55,7 @@ public class SheepShear implements Listener {
|
||||
return;
|
||||
}
|
||||
Entity entity = event.getRightClicked();
|
||||
if (!(entity instanceof Sheep)) {
|
||||
if (!(entity instanceof Sheep sheep)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -65,7 +66,6 @@ public class SheepShear implements Listener {
|
||||
}
|
||||
|
||||
// make sure the sheep is not sheared
|
||||
Sheep sheep = (Sheep) entity;
|
||||
if (sheep.isSheared()) {
|
||||
return;
|
||||
}
|
||||
@@ -121,13 +121,13 @@ public class SheepShear implements Listener {
|
||||
if (toolStats.config.getBoolean("enabled.sheep-sheared")) {
|
||||
String oldSheepFormatted = toolStats.numberFormat.formatInt(sheepSheared);
|
||||
String newSheepFormatted = toolStats.numberFormat.formatInt(sheepSheared + 1);
|
||||
String oldLine = toolStats.configTools.formatLore("sheep-sheared", "{sheep}", oldSheepFormatted);
|
||||
String newLine = toolStats.configTools.formatLore("sheep-sheared", "{sheep}", newSheepFormatted);
|
||||
Component oldLine = toolStats.configTools.formatLore("sheep-sheared", "{sheep}", oldSheepFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("sheep-sheared", "{sheep}", newSheepFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return;
|
||||
}
|
||||
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.setLore(newLore);
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
newShears.setItemMeta(meta);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -47,11 +48,10 @@ public class ShootBow implements Listener {
|
||||
public void onShoot(EntityShootBowEvent event) {
|
||||
Entity shooter = event.getEntity();
|
||||
// only listen for players
|
||||
if (!(shooter instanceof Player)) {
|
||||
if (!(shooter instanceof Player player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) shooter;
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.ADVENTURE) {
|
||||
return;
|
||||
}
|
||||
@@ -111,13 +111,13 @@ public class ShootBow implements Listener {
|
||||
if (toolStats.config.getBoolean("enabled.arrows-shot")) {
|
||||
String oldArrowsFormatted = toolStats.numberFormat.formatInt(arrowsShot);
|
||||
String newArrowsFormatted = toolStats.numberFormat.formatInt(arrowsShot + 1);
|
||||
String oldLine = toolStats.configTools.formatLore("arrows-shot", "{arrows}", oldArrowsFormatted);
|
||||
String newLine = toolStats.configTools.formatLore("arrows-shot", "{arrows}", newArrowsFormatted);
|
||||
Component oldLine = toolStats.configTools.formatLore("arrows-shot", "{arrows}", oldArrowsFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("arrows-shot", "{arrows}", newArrowsFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return;
|
||||
}
|
||||
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.setLore(newLore);
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
bow.setItemMeta(meta);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -51,10 +52,9 @@ public class VillagerTrade implements Listener {
|
||||
return;
|
||||
}
|
||||
Inventory inventory = event.getClickedInventory();
|
||||
if (!(event.getWhoClicked() instanceof Player)) {
|
||||
if (!(event.getWhoClicked() instanceof Player player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
@@ -117,8 +117,8 @@ public class VillagerTrade implements Listener {
|
||||
|
||||
if (toolStats.configTools.checkConfig(newItem.getType(), "traded-tag")) {
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.setLore(newLore);
|
||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
newItem.setItemMeta(meta);
|
||||
return newItem;
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
package lol.hyper.toolstats.tools;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
@@ -41,17 +43,16 @@ public class ItemLore {
|
||||
* @param newLine The new line to replace oldLine.
|
||||
* @return The item's new lore.
|
||||
*/
|
||||
public List<String> updateItemLore(ItemMeta itemMeta, String oldLine, String newLine) {
|
||||
List<String> itemLore;
|
||||
oldLine = toolStats.configTools.removeColor(oldLine);
|
||||
public List<Component> updateItemLore(ItemMeta itemMeta, Component oldLine, Component newLine) {
|
||||
List<Component> itemLore;
|
||||
if (itemMeta.hasLore()) {
|
||||
itemLore = itemMeta.getLore();
|
||||
itemLore = itemMeta.lore();
|
||||
// keep track of line index
|
||||
// this doesn't mess the lore of existing items
|
||||
for (int x = 0; x < itemLore.size(); x++) {
|
||||
// check to see if the line matches the config value
|
||||
Component line = itemLore.get(x);
|
||||
// find the old line to update, keeping index
|
||||
// this means we update this line only!
|
||||
String line = toolStats.configTools.removeColor(itemLore.get(x));
|
||||
if (line.equals(oldLine)) {
|
||||
itemLore.set(x, newLine);
|
||||
return itemLore;
|
||||
@@ -67,10 +68,10 @@ public class ItemLore {
|
||||
return itemLore;
|
||||
}
|
||||
|
||||
public List<String> addItemLore(ItemMeta itemMeta, String newLine) {
|
||||
List<String> itemLore;
|
||||
public List<Component> addItemLore(ItemMeta itemMeta, Component newLine) {
|
||||
List<Component> itemLore;
|
||||
if (itemMeta.hasLore()) {
|
||||
itemLore = itemMeta.getLore();
|
||||
itemLore = itemMeta.lore();
|
||||
itemLore.add(newLine);
|
||||
} else {
|
||||
itemLore = new ArrayList<>();
|
||||
@@ -87,9 +88,9 @@ public class ItemLore {
|
||||
* @param formattedDate The date of the ownership.
|
||||
* @return The item's new lore.
|
||||
*/
|
||||
public List<String> addNewOwner(ItemMeta itemMeta, String playerName, String formattedDate) {
|
||||
String dateCreatedLore;
|
||||
String itemOwnerLore;
|
||||
public List<Component> addNewOwner(ItemMeta itemMeta, String playerName, String formattedDate) {
|
||||
Component dateCreatedLore;
|
||||
Component itemOwnerLore;
|
||||
Integer origin = null;
|
||||
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
||||
@@ -100,7 +101,7 @@ public class ItemLore {
|
||||
if (origin == null) {
|
||||
toolStats.logger.info("Unable to determine origin for item " + itemMeta.getAsString());
|
||||
toolStats.logger.info("This IS a bug, please report this to the GitHub.");
|
||||
return itemMeta.getLore();
|
||||
return itemMeta.lore();
|
||||
}
|
||||
|
||||
// set the lore based on the origin
|
||||
@@ -112,12 +113,12 @@ public class ItemLore {
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.looted.looted-on is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.getLore();
|
||||
return itemMeta.lore();
|
||||
}
|
||||
if (itemOwnerLore == null) {
|
||||
toolStats.logger.warning("messages.looted.looted-by is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.getLore();
|
||||
return itemMeta.lore();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -128,12 +129,12 @@ public class ItemLore {
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.traded.traded-on is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.getLore();
|
||||
return itemMeta.lore();
|
||||
}
|
||||
if (itemOwnerLore == null) {
|
||||
toolStats.logger.warning("messages.traded.traded-by is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.getLore();
|
||||
return itemMeta.lore();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -144,12 +145,12 @@ public class ItemLore {
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.looted.found-on is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.getLore();
|
||||
return itemMeta.lore();
|
||||
}
|
||||
if (itemOwnerLore == null) {
|
||||
toolStats.logger.warning("messages.looted.found-by is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.getLore();
|
||||
return itemMeta.lore();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -160,12 +161,12 @@ public class ItemLore {
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.fished.caught-on is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.getLore();
|
||||
return itemMeta.lore();
|
||||
}
|
||||
if (itemOwnerLore == null) {
|
||||
toolStats.logger.warning("messages.fished.caught-by is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.getLore();
|
||||
return itemMeta.lore();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -176,31 +177,31 @@ public class ItemLore {
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.spawned-in.spawned-on is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.getLore();
|
||||
return itemMeta.lore();
|
||||
}
|
||||
if (itemOwnerLore == null) {
|
||||
toolStats.logger.warning("messages.spawned-in.spawned-by is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.getLore();
|
||||
return itemMeta.lore();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
toolStats.logger.warning("Origin " + origin + " was found. Data was modified OR something REALLY broke.");
|
||||
toolStats.logger.warning(itemMeta.getAsString());
|
||||
return itemMeta.getLore();
|
||||
return itemMeta.lore();
|
||||
}
|
||||
}
|
||||
|
||||
List<String> newLore;
|
||||
List<Component> newLore;
|
||||
if (itemMeta.hasLore()) {
|
||||
newLore = itemMeta.getLore();
|
||||
newLore = itemMeta.lore();
|
||||
} else {
|
||||
newLore = new ArrayList<>();
|
||||
}
|
||||
|
||||
newLore.add(dateCreatedLore.replace("{date}", formattedDate));
|
||||
newLore.add(itemOwnerLore.replace("{player}", playerName));
|
||||
newLore.add(dateCreatedLore);
|
||||
newLore.add(itemOwnerLore);
|
||||
return newLore;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
package lol.hyper.toolstats.tools.config;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.ChatColor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
@@ -70,46 +72,21 @@ public class ConfigTools {
|
||||
itemType = itemName.substring(itemName.indexOf('_') + 1);
|
||||
}
|
||||
|
||||
switch (itemType) {
|
||||
case "pickaxe": {
|
||||
return toolStats.config.getBoolean("enabled." + configName + ".pickaxe");
|
||||
}
|
||||
case "sword": {
|
||||
return toolStats.config.getBoolean("enabled." + configName + ".sword");
|
||||
}
|
||||
case "shovel": {
|
||||
return toolStats.config.getBoolean("enabled." + configName + ".shovel");
|
||||
}
|
||||
case "axe": {
|
||||
return toolStats.config.getBoolean("enabled." + configName + ".axe");
|
||||
}
|
||||
case "hoe": {
|
||||
return toolStats.config.getBoolean("enabled." + configName + ".hoe");
|
||||
}
|
||||
case "shears": {
|
||||
return toolStats.config.getBoolean("enabled." + configName + ".shears");
|
||||
}
|
||||
case "crossbow":
|
||||
case "bow": {
|
||||
return toolStats.config.getBoolean("enabled." + configName + ".bow");
|
||||
}
|
||||
case "trident": {
|
||||
return toolStats.config.getBoolean("enabled." + configName + ".trident");
|
||||
}
|
||||
case "fishing-rod": {
|
||||
return toolStats.config.getBoolean("enabled." + configName + ".fishing-rod");
|
||||
}
|
||||
case "mace": {
|
||||
return toolStats.config.getBoolean("enabled." + configName + ".mace");
|
||||
}
|
||||
case "helmet":
|
||||
case "chestplate":
|
||||
case "leggings":
|
||||
case "boots": {
|
||||
return toolStats.config.getBoolean("enabled." + configName + ".armor");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return switch (itemType) {
|
||||
case "pickaxe" -> toolStats.config.getBoolean("enabled." + configName + ".pickaxe");
|
||||
case "sword" -> toolStats.config.getBoolean("enabled." + configName + ".sword");
|
||||
case "shovel" -> toolStats.config.getBoolean("enabled." + configName + ".shovel");
|
||||
case "axe" -> toolStats.config.getBoolean("enabled." + configName + ".axe");
|
||||
case "hoe" -> toolStats.config.getBoolean("enabled." + configName + ".hoe");
|
||||
case "shears" -> toolStats.config.getBoolean("enabled." + configName + ".shears");
|
||||
case "crossbow", "bow" -> toolStats.config.getBoolean("enabled." + configName + ".bow");
|
||||
case "trident" -> toolStats.config.getBoolean("enabled." + configName + ".trident");
|
||||
case "fishing-rod" -> toolStats.config.getBoolean("enabled." + configName + ".fishing-rod");
|
||||
case "mace" -> toolStats.config.getBoolean("enabled." + configName + ".mace");
|
||||
case "helmet", "chestplate", "leggings", "boots" ->
|
||||
toolStats.config.getBoolean("enabled." + configName + ".armor");
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,28 +97,29 @@ public class ConfigTools {
|
||||
* @param value The value to set the placeholder.
|
||||
* @return Formatted string, null if the configName doesn't exist.
|
||||
*/
|
||||
public String formatLore(String configName, String placeHolder, Object value) {
|
||||
public Component formatLore(String configName, String placeHolder, Object value) {
|
||||
String lore = toolStats.config.getString("messages." + configName);
|
||||
if (lore == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// the final component for this lore
|
||||
Component component;
|
||||
|
||||
// set the placeholder to the value
|
||||
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);
|
||||
while (hexMatcher.find()) {
|
||||
String hexCode = hexMatcher.group(1);
|
||||
lore = lore.replaceAll(hexMatcher.group(), net.md_5.bungee.api.ChatColor.of("#" + hexCode).toString());
|
||||
}
|
||||
|
||||
Matcher colorMatcher = COLOR_CODES.matcher(lore);
|
||||
while (colorMatcher.find()) {
|
||||
String colorCode = colorMatcher.group(1);
|
||||
lore = lore.replaceAll("&" + colorCode, ChatColor.getByChar(colorCode).toString());
|
||||
if (hexMatcher.find() || colorMatcher.find()) {
|
||||
component = LegacyComponentSerializer.legacyAmpersand().deserialize(lore);
|
||||
} else {
|
||||
// otherwise format them normally
|
||||
component = Component.text(lore);
|
||||
}
|
||||
|
||||
return ChatColor.translateAlternateColorCodes('§', lore);
|
||||
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package lol.hyper.toolstats.tools.config.versions;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
Reference in New Issue
Block a user