Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0d79fd740 | ||
|
|
b056972d30 | ||
|
|
525df4bcf6 | ||
|
|
86cbdd58ff | ||
|
|
27a89fd67c | ||
|
|
70ed50ce9e | ||
|
|
84c1f8313a | ||
|
|
f7ec488396 | ||
|
|
df014fd888 | ||
|
|
1d617706a6 | ||
|
|
49e1acc66a | ||
|
|
eddaec1543 | ||
|
|
57ec36d5a7 | ||
|
|
a617875975 | ||
|
|
3ee53e0cf7 | ||
|
|
364859bc0a | ||
|
|
0efc07b12b | ||
|
|
e73ba5376c | ||
|
|
68318e3af2 | ||
|
|
c7cd25e866 |
32
README.md
@@ -4,7 +4,7 @@
|
||||
<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>
|
||||
</p>
|
||||
@@ -27,23 +27,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 |
6
pom.xml
@@ -23,7 +23,7 @@
|
||||
|
||||
<groupId>lol.hyper</groupId>
|
||||
<artifactId>toolstats</artifactId>
|
||||
<version>1.9.6</version>
|
||||
<version>1.9.9</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>
|
||||
@@ -105,7 +105,7 @@
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.21.5-R0.1-SNAPSHOT</version>
|
||||
<version>1.21.7-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -25,7 +25,6 @@ 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 lol.hyper.toolstats.tools.config.TokenItems;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
@@ -121,7 +120,7 @@ public final class ToolStats extends JavaPlugin {
|
||||
*/
|
||||
public final NamespacedKey originType = new NamespacedKey(this, "origin");
|
||||
|
||||
public final int CONFIG_VERSION = 12;
|
||||
public final int CONFIG_VERSION = 13;
|
||||
public final Logger logger = this.getLogger();
|
||||
public final File configFile = new File(this.getDataFolder(), "config.yml");
|
||||
public boolean tokens = false;
|
||||
@@ -150,8 +149,7 @@ public final class ToolStats extends JavaPlugin {
|
||||
public ItemChecker itemChecker;
|
||||
public ShootBow shootBow;
|
||||
public ConfigTools configTools;
|
||||
public TokenItems tokenItems;
|
||||
public TokenCrafting tokenCrafting;
|
||||
public TokenData tokenData;
|
||||
public AnvilEvent anvilEvent;
|
||||
public PrepareCraft prepareCraft;
|
||||
|
||||
@@ -164,10 +162,9 @@ public final class ToolStats extends JavaPlugin {
|
||||
|
||||
loadConfig();
|
||||
configTools = new ConfigTools(this);
|
||||
tokenItems = new TokenItems(this);
|
||||
tokenCrafting = new TokenCrafting(this);
|
||||
tokenCrafting.setup();
|
||||
for (ShapedRecipe recipe : tokenCrafting.getRecipes()) {
|
||||
tokenData = new TokenData(this);
|
||||
tokenData.setup();
|
||||
for (ShapedRecipe recipe : tokenData.getRecipes()) {
|
||||
if (tokens && config.getBoolean("tokens.craft-tokens")) {
|
||||
Bukkit.addRecipe(recipe);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
@@ -64,8 +63,8 @@ public class CommandToolStats implements TabExecutor {
|
||||
if (sender.hasPermission("toolstats.reload")) {
|
||||
boolean oldTokensStatus = toolStats.tokens;
|
||||
toolStats.loadConfig();
|
||||
toolStats.tokenCrafting.getRecipes().clear();
|
||||
toolStats.tokenCrafting.setup();
|
||||
toolStats.tokenData.getRecipes().clear();
|
||||
toolStats.tokenData.setup();
|
||||
// if the server went from tokens off -> on, add the recipes
|
||||
// if the server went from tokens on -> off, remove the recipes
|
||||
if (toolStats.tokens != oldTokensStatus) {
|
||||
@@ -73,14 +72,14 @@ public class CommandToolStats implements TabExecutor {
|
||||
if (toolStats.tokens) {
|
||||
sender.sendMessage(Component.text("It looks like you ENABLED the token system. While this is fine, it can break. Please restart your server instead.", NamedTextColor.YELLOW));
|
||||
if (toolStats.config.getBoolean("tokens.craft-token")) {
|
||||
for (ShapedRecipe recipe : toolStats.tokenCrafting.getRecipes()) {
|
||||
for (ShapedRecipe recipe : toolStats.tokenData.getRecipes()) {
|
||||
Bukkit.addRecipe(recipe);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// tokens are now disabled
|
||||
sender.sendMessage(Component.text("It looks like you DISABLED the token system. While this is fine, it can break. Please restart your server instead.", NamedTextColor.YELLOW));
|
||||
for (ShapedRecipe recipe : toolStats.tokenCrafting.getRecipes()) {
|
||||
for (ShapedRecipe recipe : toolStats.tokenData.getRecipes()) {
|
||||
Bukkit.removeRecipe(recipe.getKey());
|
||||
}
|
||||
}
|
||||
@@ -156,6 +155,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));
|
||||
@@ -172,7 +202,7 @@ public class CommandToolStats implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
String tokenType = args[2];
|
||||
if (!toolStats.tokenCrafting.getTokenTypes().contains(tokenType)) {
|
||||
if (!toolStats.tokenData.getTokenTypes().contains(tokenType)) {
|
||||
sender.sendMessage(Component.text("Invalid token type.", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
@@ -234,38 +264,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)) {
|
||||
@@ -294,82 +292,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -458,80 +404,9 @@ public class CommandToolStats implements TabExecutor {
|
||||
* @param tokenType The token type.
|
||||
*/
|
||||
private void giveToken(Player target, String tokenType, int amount) {
|
||||
switch (tokenType) {
|
||||
case "crops-mined": {
|
||||
ItemStack itemStack = toolStats.tokenItems.cropsMined();
|
||||
itemStack.setAmount(amount);
|
||||
target.getInventory().addItem(itemStack);
|
||||
break;
|
||||
}
|
||||
case "blocks-mined": {
|
||||
ItemStack itemStack = toolStats.tokenItems.blocksMined();
|
||||
itemStack.setAmount(amount);
|
||||
target.getInventory().addItem(itemStack);
|
||||
break;
|
||||
}
|
||||
case "damage-taken": {
|
||||
ItemStack itemStack = toolStats.tokenItems.damageTaken();
|
||||
itemStack.setAmount(amount);
|
||||
target.getInventory().addItem(itemStack);
|
||||
break;
|
||||
}
|
||||
case "damage-done": {
|
||||
ItemStack itemStack = toolStats.tokenItems.damageDone();
|
||||
itemStack.setAmount(amount);
|
||||
target.getInventory().addItem(itemStack);
|
||||
break;
|
||||
}
|
||||
case "mob-kills": {
|
||||
ItemStack itemStack = toolStats.tokenItems.mobKills();
|
||||
itemStack.setAmount(amount);
|
||||
target.getInventory().addItem(itemStack);
|
||||
break;
|
||||
}
|
||||
case "player-kills": {
|
||||
ItemStack itemStack = toolStats.tokenItems.playerKills();
|
||||
itemStack.setAmount(amount);
|
||||
target.getInventory().addItem(itemStack);
|
||||
break;
|
||||
}
|
||||
case "arrows-shot": {
|
||||
ItemStack itemStack = toolStats.tokenItems.arrowsShot();
|
||||
itemStack.setAmount(amount);
|
||||
target.getInventory().addItem(itemStack);
|
||||
break;
|
||||
}
|
||||
case "sheep-sheared": {
|
||||
ItemStack itemStack = toolStats.tokenItems.sheepSheared();
|
||||
itemStack.setAmount(amount);
|
||||
target.getInventory().addItem(itemStack);
|
||||
break;
|
||||
}
|
||||
case "flight-time": {
|
||||
ItemStack itemStack = toolStats.tokenItems.flightTime();
|
||||
itemStack.setAmount(amount);
|
||||
target.getInventory().addItem(itemStack);
|
||||
break;
|
||||
}
|
||||
case "fish-caught": {
|
||||
ItemStack itemStack = toolStats.tokenItems.fishCaught();
|
||||
itemStack.setAmount(amount);
|
||||
target.getInventory().addItem(itemStack);
|
||||
break;
|
||||
}
|
||||
case "reset": {
|
||||
ItemStack itemStack = toolStats.tokenItems.resetToken();
|
||||
itemStack.setAmount(amount);
|
||||
target.getInventory().addItem(itemStack);
|
||||
break;
|
||||
}
|
||||
case "remove": {
|
||||
ItemStack itemStack = toolStats.tokenItems.removeToken();
|
||||
itemStack.setAmount(amount);
|
||||
target.getInventory().addItem(itemStack);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ItemStack token = toolStats.tokenData.createToken(tokenType);
|
||||
token.setAmount(amount);
|
||||
target.getInventory().addItem(token);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -847,6 +722,7 @@ public class CommandToolStats implements TabExecutor {
|
||||
}
|
||||
editedItem.setItemMeta(editedItemMeta);
|
||||
player.getInventory().setItemInMainHand(editedItem);
|
||||
player.sendMessage(Component.text("Updated stat " + stat + " for held item!", NamedTextColor.GREEN));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1124,6 +1000,7 @@ public class CommandToolStats implements TabExecutor {
|
||||
}
|
||||
editedItem.setItemMeta(editedItemMeta);
|
||||
player.getInventory().setItemInMainHand(editedItem);
|
||||
player.sendMessage(Component.text("Removed stat " + stat + " for held item!", NamedTextColor.GREEN));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -1146,28 +1023,34 @@ 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.tokenCrafting.getTokenTypes().stream()
|
||||
return toolStats.tokenData.getTokenTypes().stream()
|
||||
.filter(s -> !s.equals("remove") && !s.equals("reset"))
|
||||
.map(s -> s.equals("crops-mined") ? "crops-harvested" : s)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
if (args.length == 2 && args[0].equalsIgnoreCase("remove") && sender.hasPermission("toolstats.remove")) {
|
||||
// yes I am lazy
|
||||
return toolStats.tokenCrafting.getTokenTypes().stream()
|
||||
return toolStats.tokenData.getTokenTypes().stream()
|
||||
.filter(s -> !s.equals("remove") && !s.equals("reset"))
|
||||
.map(s -> s.equals("crops-mined") ? "crops-harvested" : s)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
if (args.length == 3 && args[0].equalsIgnoreCase("givetokens") && sender.hasPermission("toolstats.givetokens")) {
|
||||
return toolStats.tokenCrafting.getTokenTypes();
|
||||
return toolStats.tokenData.getTokenTypes();
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -57,7 +57,6 @@ public class AnvilEvent implements Listener {
|
||||
}
|
||||
|
||||
Material firstSlotMaterial = firstSlot.getType();
|
||||
Material secondSlotMaterial = secondSlot.getType();
|
||||
|
||||
// make sure the first item is a valid item
|
||||
if (!toolStats.itemChecker.isValidItem(firstSlotMaterial)) {
|
||||
@@ -67,7 +66,7 @@ public class AnvilEvent implements Listener {
|
||||
PersistentDataContainer secondSlotContainer = secondSlot.getItemMeta().getPersistentDataContainer();
|
||||
|
||||
// make sure the 2nd item is one of ours
|
||||
if (secondSlotMaterial != Material.PAPER || !secondSlotContainer.has(toolStats.tokenType, PersistentDataType.STRING)) {
|
||||
if (!secondSlotContainer.has(toolStats.tokenType, PersistentDataType.STRING)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -91,7 +90,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;
|
||||
}
|
||||
|
||||
@@ -123,9 +124,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;
|
||||
@@ -164,10 +173,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);
|
||||
}
|
||||
@@ -391,155 +396,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"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,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.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -91,8 +92,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 +107,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")) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,15 +53,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -40,7 +39,7 @@ public class PrepareCraft implements Listener {
|
||||
// get the items in the crafting grid
|
||||
ItemStack[] grid = event.getInventory().getMatrix();
|
||||
for (ItemStack item : grid) {
|
||||
if (item == null || item.getType() != Material.PAPER) {
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
package lol.hyper.toolstats.tools;
|
||||
|
||||
import io.papermc.paper.datacomponent.DataComponentType;
|
||||
import io.papermc.paper.datacomponent.DataComponentTypes;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
@@ -116,6 +118,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.
|
||||
*
|
||||
|
||||
@@ -19,15 +19,17 @@ package lol.hyper.toolstats.tools;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.PrepareAnvilEvent;
|
||||
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 {
|
||||
|
||||
@@ -97,6 +99,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;
|
||||
@@ -196,7 +201,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;
|
||||
}
|
||||
@@ -295,7 +300,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;
|
||||
}
|
||||
@@ -393,7 +398,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;
|
||||
}
|
||||
@@ -491,7 +496,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;
|
||||
}
|
||||
@@ -597,7 +602,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;
|
||||
}
|
||||
@@ -703,7 +708,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;
|
||||
}
|
||||
@@ -819,7 +824,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;
|
||||
}
|
||||
@@ -917,7 +922,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;
|
||||
}
|
||||
@@ -1017,7 +1022,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;
|
||||
}
|
||||
@@ -1115,8 +1120,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,104 +17,110 @@
|
||||
|
||||
package lol.hyper.toolstats.tools;
|
||||
|
||||
import io.papermc.paper.datacomponent.DataComponentTypes;
|
||||
import io.papermc.paper.datacomponent.item.CustomModelData;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class TokenCrafting {
|
||||
public class TokenData {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
private final Set<ShapedRecipe> recipes = new HashSet<>();
|
||||
private final ArrayList<String> tokenTypes = new ArrayList<>();
|
||||
|
||||
public TokenCrafting(ToolStats toolStats) {
|
||||
public TokenData(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
NamespacedKey playerKillsKey = new NamespacedKey(toolStats, "player-kills-token");
|
||||
ShapedRecipe playerKillRecipe = new ShapedRecipe(playerKillsKey, toolStats.tokenItems.playerKills());
|
||||
ShapedRecipe playerKillRecipe = new ShapedRecipe(playerKillsKey, createToken("player-kills"));
|
||||
playerKillRecipe.shape(" P ", "PSP", " P ");
|
||||
playerKillRecipe.setIngredient('P', Material.PAPER);
|
||||
playerKillRecipe.setIngredient('S', Material.WOODEN_SWORD);
|
||||
recipes.add(playerKillRecipe);
|
||||
|
||||
NamespacedKey mobKillsKey = new NamespacedKey(toolStats, "mob-kills-token");
|
||||
ShapedRecipe mobKillsRecipe = new ShapedRecipe(mobKillsKey, toolStats.tokenItems.mobKills());
|
||||
ShapedRecipe mobKillsRecipe = new ShapedRecipe(mobKillsKey, createToken("mob-kills"));
|
||||
mobKillsRecipe.shape(" P ", "PRP", " P ");
|
||||
mobKillsRecipe.setIngredient('P', Material.PAPER);
|
||||
mobKillsRecipe.setIngredient('R', Material.ROTTEN_FLESH);
|
||||
recipes.add(mobKillsRecipe);
|
||||
|
||||
NamespacedKey blocksMinedKey = new NamespacedKey(toolStats, "blocks-mined-token");
|
||||
ShapedRecipe blocksMinedRecipe = new ShapedRecipe(blocksMinedKey, toolStats.tokenItems.blocksMined());
|
||||
ShapedRecipe blocksMinedRecipe = new ShapedRecipe(blocksMinedKey, createToken("blocks-mined"));
|
||||
blocksMinedRecipe.shape(" P ", "PSP", " P ");
|
||||
blocksMinedRecipe.setIngredient('P', Material.PAPER);
|
||||
blocksMinedRecipe.setIngredient('S', Material.WOODEN_PICKAXE);
|
||||
recipes.add(blocksMinedRecipe);
|
||||
|
||||
NamespacedKey cropsMinedKey = new NamespacedKey(toolStats, "crops-mined-token");
|
||||
ShapedRecipe cropsMinedRecipe = new ShapedRecipe(cropsMinedKey, toolStats.tokenItems.cropsMined());
|
||||
ShapedRecipe cropsMinedRecipe = new ShapedRecipe(cropsMinedKey, createToken("crops-mined"));
|
||||
cropsMinedRecipe.shape(" P ", "PHP", " P ");
|
||||
cropsMinedRecipe.setIngredient('P', Material.PAPER);
|
||||
cropsMinedRecipe.setIngredient('H', Material.WOODEN_HOE);
|
||||
recipes.add(cropsMinedRecipe);
|
||||
|
||||
NamespacedKey fishCaughtKey = new NamespacedKey(toolStats, "fish-caught-token");
|
||||
ShapedRecipe fishCaughtRecipe = new ShapedRecipe(fishCaughtKey, toolStats.tokenItems.fishCaught());
|
||||
ShapedRecipe fishCaughtRecipe = new ShapedRecipe(fishCaughtKey, createToken("fish-caught"));
|
||||
fishCaughtRecipe.shape(" P ", "PCP", " P ");
|
||||
fishCaughtRecipe.setIngredient('P', Material.PAPER);
|
||||
fishCaughtRecipe.setIngredient('C', Material.COD);
|
||||
recipes.add(fishCaughtRecipe);
|
||||
|
||||
NamespacedKey sheepShearedKey = new NamespacedKey(toolStats, "sheep-sheared-token");
|
||||
ShapedRecipe sheepShearedRecipe = new ShapedRecipe(sheepShearedKey, toolStats.tokenItems.sheepSheared());
|
||||
ShapedRecipe sheepShearedRecipe = new ShapedRecipe(sheepShearedKey, createToken("sheep-sheared"));
|
||||
sheepShearedRecipe.shape(" P ", "PWP", " P ");
|
||||
sheepShearedRecipe.setIngredient('P', Material.PAPER);
|
||||
sheepShearedRecipe.setIngredient('W', Material.WHITE_WOOL);
|
||||
recipes.add(sheepShearedRecipe);
|
||||
|
||||
NamespacedKey armorDamageKey = new NamespacedKey(toolStats, "damage-taken-token");
|
||||
ShapedRecipe armorDamageRecipe = new ShapedRecipe(armorDamageKey, toolStats.tokenItems.damageTaken());
|
||||
ShapedRecipe armorDamageRecipe = new ShapedRecipe(armorDamageKey, createToken("damage-taken"));
|
||||
armorDamageRecipe.shape(" P ", "PCP", " P ");
|
||||
armorDamageRecipe.setIngredient('P', Material.PAPER);
|
||||
armorDamageRecipe.setIngredient('C', Material.LEATHER_CHESTPLATE);
|
||||
recipes.add(armorDamageRecipe);
|
||||
|
||||
NamespacedKey damageDoneKey = new NamespacedKey(toolStats, "damage-done-token");
|
||||
ShapedRecipe damageDoneRecipe = new ShapedRecipe(damageDoneKey, toolStats.tokenItems.damageDone());
|
||||
ShapedRecipe damageDoneRecipe = new ShapedRecipe(damageDoneKey, createToken("damage-done"));
|
||||
damageDoneRecipe.shape(" P ", "PSP", " P ");
|
||||
damageDoneRecipe.setIngredient('P', Material.PAPER);
|
||||
damageDoneRecipe.setIngredient('S', Material.SHIELD);
|
||||
recipes.add(damageDoneRecipe);
|
||||
|
||||
NamespacedKey arrowsShotKey = new NamespacedKey(toolStats, "arrows-shot-token");
|
||||
ShapedRecipe arrowsShotRecipe = new ShapedRecipe(arrowsShotKey, toolStats.tokenItems.arrowsShot());
|
||||
ShapedRecipe arrowsShotRecipe = new ShapedRecipe(arrowsShotKey, createToken("arrows-shot"));
|
||||
arrowsShotRecipe.shape(" P ", "PAP", " P ");
|
||||
arrowsShotRecipe.setIngredient('P', Material.PAPER);
|
||||
arrowsShotRecipe.setIngredient('A', Material.ARROW);
|
||||
recipes.add(arrowsShotRecipe);
|
||||
|
||||
NamespacedKey flightTimeKey = new NamespacedKey(toolStats, "flight-time-token");
|
||||
ShapedRecipe flightTimeRecipe = new ShapedRecipe(flightTimeKey, toolStats.tokenItems.flightTime());
|
||||
ShapedRecipe flightTimeRecipe = new ShapedRecipe(flightTimeKey, createToken("flight-time"));
|
||||
flightTimeRecipe.shape(" P ", "PFP", " P ");
|
||||
flightTimeRecipe.setIngredient('P', Material.PAPER);
|
||||
flightTimeRecipe.setIngredient('F', Material.FEATHER);
|
||||
recipes.add(flightTimeRecipe);
|
||||
|
||||
NamespacedKey resetKey = new NamespacedKey(toolStats, "reset-token");
|
||||
ShapedRecipe resetRecipe = new ShapedRecipe(resetKey, toolStats.tokenItems.resetToken());
|
||||
ShapedRecipe resetRecipe = new ShapedRecipe(resetKey, createToken("reset"));
|
||||
resetRecipe.shape(" P ", "PPP", " P ");
|
||||
resetRecipe.setIngredient('P', Material.PAPER);
|
||||
recipes.add(resetRecipe);
|
||||
|
||||
NamespacedKey removeKey = new NamespacedKey(toolStats, "remove-token");
|
||||
ShapedRecipe removeRecipe = new ShapedRecipe(removeKey, toolStats.tokenItems.removeToken());
|
||||
ShapedRecipe removeRecipe = new ShapedRecipe(removeKey, createToken("remove"));
|
||||
removeRecipe.shape(" P ", "P P", " P ");
|
||||
removeRecipe.setIngredient('P', Material.PAPER);
|
||||
recipes.add(removeRecipe);
|
||||
@@ -140,4 +146,79 @@ public class TokenCrafting {
|
||||
public ArrayList<String> getTokenTypes() {
|
||||
return tokenTypes;
|
||||
}
|
||||
|
||||
public ItemStack createToken(String tokenType) {
|
||||
// we don't have to check if the token exists
|
||||
// we do that prior
|
||||
ConfigurationSection tokenConfig = toolStats.config.getConfigurationSection("tokens.data." + tokenType);
|
||||
|
||||
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.");
|
||||
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.");
|
||||
material = Material.PAPER;
|
||||
}
|
||||
|
||||
ItemStack token = new ItemStack(material);
|
||||
ItemMeta tokenMeta = token.getItemMeta();
|
||||
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
||||
|
||||
// set the title and lore
|
||||
Component title = toolStats.configTools.format("tokens.data." + tokenType + ".title");
|
||||
List<Component> lore = toolStats.configTools.getTokenLore(tokenType);
|
||||
tokenMeta.displayName(title);
|
||||
tokenMeta.lore(lore);
|
||||
|
||||
// set the PDC
|
||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, tokenType);
|
||||
token.setItemMeta(tokenMeta);
|
||||
|
||||
// set the custom model data
|
||||
if (tokenConfig.getBoolean("custom-model-data.enabled")) {
|
||||
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);
|
||||
return null;
|
||||
}
|
||||
CustomModelData data = setData(type, value);
|
||||
if (data != null) {
|
||||
token.setData(DataComponentTypes.CUSTOM_MODEL_DATA, data);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
private CustomModelData setData(String type, Object data) {
|
||||
switch (type.toLowerCase(Locale.ROOT)) {
|
||||
case "float": {
|
||||
float f;
|
||||
try {
|
||||
f = Float.parseFloat(data.toString());
|
||||
} catch (NumberFormatException e) {
|
||||
toolStats.logger.info(data + " is not a valid float!");
|
||||
return null;
|
||||
}
|
||||
return CustomModelData.customModelData().addFloat(f).build();
|
||||
}
|
||||
case "string": {
|
||||
return CustomModelData.customModelData().addString(data.toString()).build();
|
||||
}
|
||||
default: {
|
||||
toolStats.logger.info(data + " is not a valid data type!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -244,6 +244,13 @@ public class ConfigTools {
|
||||
|
||||
List<Component> finalLore = new ArrayList<>();
|
||||
for (String line : raw) {
|
||||
if (line.contains("{levels}")) {
|
||||
Integer levels = toolStats.config.getInt("tokens.data." + tokenType + ".levels");
|
||||
// will return 0 if it doesn't exist
|
||||
if (levels != 0) {
|
||||
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);
|
||||
|
||||
@@ -31,40 +31,15 @@ public class ConfigUpdater {
|
||||
public void updateConfig() {
|
||||
int version = toolStats.config.getInt("config-version");
|
||||
|
||||
// Version 5 to 6
|
||||
if (version == 5) {
|
||||
Version6 version6 = new Version6(toolStats);
|
||||
version6.update();
|
||||
}
|
||||
// Version 6 to 7
|
||||
if (version == 6) {
|
||||
Version7 version7 = new Version7(toolStats);
|
||||
version7.update();
|
||||
}
|
||||
// Version 7 to 8
|
||||
if (version == 7) {
|
||||
Version8 version8 = new Version8(toolStats);
|
||||
version8.update();
|
||||
}
|
||||
// Version 8 to 9
|
||||
if (version == 8) {
|
||||
Version9 version9 = new Version9(toolStats);
|
||||
version9.update();
|
||||
}
|
||||
// Version 9 to 10
|
||||
if (version == 9) {
|
||||
Version10 version10 = new Version10(toolStats);
|
||||
version10.update();
|
||||
}
|
||||
// Version 10 to 11
|
||||
if (version == 10) {
|
||||
Version11 version11 = new Version11(toolStats);
|
||||
version11.update();
|
||||
}
|
||||
// Version 11 to 12
|
||||
if (version == 11) {
|
||||
Version12 version12 = new Version12(toolStats);
|
||||
version12.update();
|
||||
switch (version) {
|
||||
case 5 -> new Version6(toolStats).update(); // 5 to 6
|
||||
case 6 -> new Version7(toolStats).update(); // 6 to 7
|
||||
case 7 -> new Version8(toolStats).update(); // 7 to 8
|
||||
case 8 -> new Version9(toolStats).update(); // 8 to 9
|
||||
case 9 -> new Version10(toolStats).update(); // 9 to 10
|
||||
case 10 -> new Version11(toolStats).update(); // 10 to 11
|
||||
case 11 -> new Version12(toolStats).update(); // 11 to 12
|
||||
case 12 -> new Version13(toolStats).update(); // 12 to 13
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,253 +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.config;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TokenItems {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public TokenItems(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
public ItemStack playerKills() {
|
||||
// set up the item
|
||||
ItemStack token = new ItemStack(Material.PAPER);
|
||||
ItemMeta tokenMeta = token.getItemMeta();
|
||||
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
||||
|
||||
// set the title and lore
|
||||
Component title = toolStats.configTools.format("tokens.data.player-kills.title");
|
||||
List<Component> lore = toolStats.configTools.getTokenLore("player-kills");
|
||||
tokenMeta.displayName(title);
|
||||
tokenMeta.lore(lore);
|
||||
|
||||
// set the PDC
|
||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "player-kills");
|
||||
token.setItemMeta(tokenMeta);
|
||||
return token;
|
||||
}
|
||||
|
||||
public ItemStack mobKills() {
|
||||
// set up the item
|
||||
ItemStack token = new ItemStack(Material.PAPER);
|
||||
ItemMeta tokenMeta = token.getItemMeta();
|
||||
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
||||
|
||||
// set the title and lore
|
||||
Component title = toolStats.configTools.format("tokens.data.mob-kills.title");
|
||||
List<Component> lore = toolStats.configTools.getTokenLore("mob-kills");
|
||||
tokenMeta.displayName(title);
|
||||
tokenMeta.lore(lore);
|
||||
|
||||
// set the PDC
|
||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "mob-kills");
|
||||
token.setItemMeta(tokenMeta);
|
||||
return token;
|
||||
}
|
||||
|
||||
public ItemStack blocksMined() {
|
||||
// set up the item
|
||||
ItemStack token = new ItemStack(Material.PAPER);
|
||||
ItemMeta tokenMeta = token.getItemMeta();
|
||||
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
||||
|
||||
// set the title and lore
|
||||
Component title = toolStats.configTools.format("tokens.data.blocks-mined.title");
|
||||
List<Component> lore = toolStats.configTools.getTokenLore("blocks-mined");
|
||||
tokenMeta.displayName(title);
|
||||
tokenMeta.lore(lore);
|
||||
|
||||
// set the PDC
|
||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "blocks-mined");
|
||||
token.setItemMeta(tokenMeta);
|
||||
return token;
|
||||
}
|
||||
|
||||
public ItemStack cropsMined() {
|
||||
// set up the item
|
||||
ItemStack token = new ItemStack(Material.PAPER);
|
||||
ItemMeta tokenMeta = token.getItemMeta();
|
||||
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
||||
|
||||
// set the title and lore
|
||||
Component title = toolStats.configTools.format("tokens.data.crops-mined.title");
|
||||
List<Component> lore = toolStats.configTools.getTokenLore("crops-mined");
|
||||
tokenMeta.displayName(title);
|
||||
tokenMeta.lore(lore);
|
||||
|
||||
// set the PDC
|
||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "crops-mined");
|
||||
token.setItemMeta(tokenMeta);
|
||||
return token;
|
||||
}
|
||||
|
||||
public ItemStack fishCaught() {
|
||||
// set up the item
|
||||
ItemStack token = new ItemStack(Material.PAPER);
|
||||
ItemMeta tokenMeta = token.getItemMeta();
|
||||
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
||||
|
||||
// set the title and lore
|
||||
Component title = toolStats.configTools.format("tokens.data.fish-caught.title");
|
||||
List<Component> lore = toolStats.configTools.getTokenLore("fight-caught");
|
||||
tokenMeta.displayName(title);
|
||||
tokenMeta.lore(lore);
|
||||
|
||||
// set the PDC
|
||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "fish-caught");
|
||||
token.setItemMeta(tokenMeta);
|
||||
return token;
|
||||
}
|
||||
|
||||
public ItemStack sheepSheared() {
|
||||
// set up the item
|
||||
ItemStack token = new ItemStack(Material.PAPER);
|
||||
ItemMeta tokenMeta = token.getItemMeta();
|
||||
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
||||
|
||||
// set the title and lore
|
||||
Component title = toolStats.configTools.format("tokens.data.sheep-sheared.title");
|
||||
List<Component> lore = toolStats.configTools.getTokenLore("sheep-sheared");
|
||||
tokenMeta.displayName(title);
|
||||
tokenMeta.lore(lore);
|
||||
|
||||
// set the PDC
|
||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "sheep-sheared");
|
||||
token.setItemMeta(tokenMeta);
|
||||
return token;
|
||||
}
|
||||
|
||||
public ItemStack damageTaken() {
|
||||
// set up the item
|
||||
ItemStack token = new ItemStack(Material.PAPER);
|
||||
ItemMeta tokenMeta = token.getItemMeta();
|
||||
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
||||
|
||||
// set the title and lore
|
||||
Component title = toolStats.configTools.format("tokens.data.damage-taken.title");
|
||||
List<Component> lore = toolStats.configTools.getTokenLore("damage-taken");
|
||||
tokenMeta.displayName(title);
|
||||
tokenMeta.lore(lore);
|
||||
|
||||
// set the PDC
|
||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "damage-taken");
|
||||
token.setItemMeta(tokenMeta);
|
||||
return token;
|
||||
}
|
||||
|
||||
public ItemStack damageDone() {
|
||||
// set up the item
|
||||
ItemStack token = new ItemStack(Material.PAPER);
|
||||
ItemMeta tokenMeta = token.getItemMeta();
|
||||
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
||||
|
||||
// set the title and lore
|
||||
Component title = toolStats.configTools.format("tokens.data.damage-done.title");
|
||||
List<Component> lore = toolStats.configTools.getTokenLore("damage-done");
|
||||
tokenMeta.displayName(title);
|
||||
tokenMeta.lore(lore);
|
||||
|
||||
// set the PDC
|
||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "damage-done");
|
||||
token.setItemMeta(tokenMeta);
|
||||
return token;
|
||||
}
|
||||
|
||||
public ItemStack arrowsShot() {
|
||||
// set up the item
|
||||
ItemStack token = new ItemStack(Material.PAPER);
|
||||
ItemMeta tokenMeta = token.getItemMeta();
|
||||
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
||||
|
||||
// set the title and lore
|
||||
Component title = toolStats.configTools.format("tokens.data.arrows-shot.title");
|
||||
List<Component> lore = toolStats.configTools.getTokenLore("arrows-shot");
|
||||
tokenMeta.displayName(title);
|
||||
tokenMeta.lore(lore);
|
||||
|
||||
// set the PDC
|
||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "arrows-shot");
|
||||
token.setItemMeta(tokenMeta);
|
||||
return token;
|
||||
}
|
||||
|
||||
public ItemStack flightTime() {
|
||||
// set up the item
|
||||
ItemStack token = new ItemStack(Material.PAPER);
|
||||
ItemMeta tokenMeta = token.getItemMeta();
|
||||
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
||||
|
||||
// set the title and lore
|
||||
Component title = toolStats.configTools.format("tokens.data.flight-time.title");
|
||||
List<Component> lore = toolStats.configTools.getTokenLore("flight-time");
|
||||
tokenMeta.displayName(title);
|
||||
tokenMeta.lore(lore);
|
||||
|
||||
// set the PDC
|
||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "flight-time");
|
||||
token.setItemMeta(tokenMeta);
|
||||
return token;
|
||||
}
|
||||
|
||||
public ItemStack resetToken() {
|
||||
// set up the item
|
||||
ItemStack token = new ItemStack(Material.PAPER);
|
||||
ItemMeta tokenMeta = token.getItemMeta();
|
||||
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
||||
|
||||
// set the title and lore
|
||||
Component title = toolStats.configTools.format("tokens.data.reset.title");
|
||||
List<Component> lore = toolStats.configTools.getTokenLore("reset");
|
||||
tokenMeta.displayName(title);
|
||||
tokenMeta.lore(lore);
|
||||
|
||||
// set the PDC
|
||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "reset");
|
||||
token.setItemMeta(tokenMeta);
|
||||
return token;
|
||||
}
|
||||
|
||||
public ItemStack removeToken() {
|
||||
// set up the item
|
||||
ItemStack token = new ItemStack(Material.PAPER);
|
||||
ItemMeta tokenMeta = token.getItemMeta();
|
||||
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
||||
|
||||
// set the title and lore
|
||||
Component title = toolStats.configTools.format("tokens.data.remove.title");
|
||||
List<Component> lore = toolStats.configTools.getTokenLore("remove");
|
||||
tokenMeta.displayName(title);
|
||||
tokenMeta.lore(lore);
|
||||
|
||||
// set the PDC
|
||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "remove");
|
||||
token.setItemMeta(tokenMeta);
|
||||
return token;
|
||||
}
|
||||
}
|
||||
@@ -17,16 +17,11 @@
|
||||
|
||||
package lol.hyper.toolstats.tools.config.versions;
|
||||
|
||||
import it.unimi.dsi.fastutil.Pair;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
|
||||
public class Version12 {
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.config.versions;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Version13 {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
/**
|
||||
* Used for updating from version 12 to 13.
|
||||
*
|
||||
* @param toolStats ToolStats instance.
|
||||
*/
|
||||
public Version13(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the config update.
|
||||
*/
|
||||
public void update() {
|
||||
// save the old config first
|
||||
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.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.config.set("tokens.data." + key + ".material", "PAPER");
|
||||
toolStats.logger.info("Adding tokens.data." + key + ".custom-model-data.enabled");
|
||||
toolStats.config.set("tokens.data." + key + ".custom-model-data.enabled", false);
|
||||
toolStats.logger.info("Adding tokens.data." + key + ".custom-model-data.type");
|
||||
toolStats.config.set("tokens.data." + key + ".custom-model-data.type", "float");
|
||||
toolStats.logger.info("Adding tokens.data." + key + ".custom-model-data.value");
|
||||
toolStats.config.set("tokens.data." + key + ".custom-model-data.value", 1001);
|
||||
}
|
||||
|
||||
// save the config and reload it
|
||||
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.loadConfig();
|
||||
toolStats.logger.info("Config has been updated to version 13. A copy of version 12 has been saved as config-12.yml");
|
||||
}
|
||||
}
|
||||
@@ -8,62 +8,134 @@ tokens:
|
||||
title: "&7ToolStats: &8Player Kills Token"
|
||||
lore:
|
||||
- "&8Combine with a melee or ranged weapon in an anvil to track player kills."
|
||||
- "&8Uses &7{levels} &8level."
|
||||
levels: 1
|
||||
material: PAPER
|
||||
custom-model-data:
|
||||
enabled: false
|
||||
type: float
|
||||
value: 1001
|
||||
mob-kills:
|
||||
title: "&7ToolStats: &8Mob Kills Token"
|
||||
lore:
|
||||
- "&8Combine with a melee or ranged weapon in an anvil to track mob kills."
|
||||
- "&8Uses &7{levels} &8level."
|
||||
levels: 1
|
||||
material: PAPER
|
||||
custom-model-data:
|
||||
enabled: false
|
||||
type: float
|
||||
value: 1001
|
||||
blocks-mined:
|
||||
title: "&7ToolStats: &8Blocks Mined Token"
|
||||
lore:
|
||||
- "&8Combine with a pickaxe, axe, shovel, or shears in an anvil to track blocks mined."
|
||||
- "&8Uses &7{levels} &8level."
|
||||
levels: 1
|
||||
material: PAPER
|
||||
custom-model-data:
|
||||
enabled: false
|
||||
type: float
|
||||
value: 1001
|
||||
crops-mined:
|
||||
title: "&7ToolStats: &8Crops Mined Token"
|
||||
lore:
|
||||
- "&8Combine with a hoe in an anvil to track crops broken."
|
||||
- "&8Uses &7{levels} &8level."
|
||||
levels: 1
|
||||
material: PAPER
|
||||
custom-model-data:
|
||||
enabled: false
|
||||
type: float
|
||||
value: 1001
|
||||
fish-caught:
|
||||
title: "&7ToolStats: &8Fish Caught Token"
|
||||
lore:
|
||||
- "&8Combine with a fishing rod in an anvil to track fish caught."
|
||||
- "&8Uses &7{levels} &8level."
|
||||
levels: 1
|
||||
material: PAPER
|
||||
custom-model-data:
|
||||
enabled: false
|
||||
type: float
|
||||
value: 1001
|
||||
sheep-sheared:
|
||||
title: "&7ToolStats: &8Sheep Sheared Token"
|
||||
lore:
|
||||
- "&8Combine with shears in an anvil to track sheep sheared."
|
||||
- "&8Uses &7{levels} &8level."
|
||||
levels: 1
|
||||
material: PAPER
|
||||
custom-model-data:
|
||||
enabled: false
|
||||
type: float
|
||||
value: 1001
|
||||
damage-taken:
|
||||
title: "&7ToolStats: &8Damage Taken Token"
|
||||
lore:
|
||||
- "&8Combine with an armor piece in an anvil to track damage taken."
|
||||
- "&8Uses &7{levels} &8level."
|
||||
levels: 1
|
||||
material: PAPER
|
||||
custom-model-data:
|
||||
enabled: false
|
||||
type: float
|
||||
value: 1001
|
||||
damage-done:
|
||||
title: "&7ToolStats: &8Damage Done Token"
|
||||
lore:
|
||||
- "&8Combine with a melee or ranged weapon in an anvil to track damage done."
|
||||
- "&8Uses &7{levels} &8level."
|
||||
levels: 1
|
||||
material: PAPER
|
||||
custom-model-data:
|
||||
enabled: false
|
||||
type: float
|
||||
value: 1001
|
||||
arrows-shot:
|
||||
title: "&7ToolStats: &8Arrows Shot Token"
|
||||
lore:
|
||||
- "&8Combine with a bow or crossbow in an anvil to track arrows shot."
|
||||
- "&8Uses &7{levels} &8level."
|
||||
levels: 1
|
||||
material: PAPER
|
||||
custom-model-data:
|
||||
enabled: false
|
||||
type: float
|
||||
value: 1001
|
||||
flight-time:
|
||||
title: "&7ToolStats: &8Flight Time Token"
|
||||
lore:
|
||||
- "&8Combine with an elytra in an anvil to track flight time."
|
||||
- "&8Uses &7{levels} &8level."
|
||||
levels: 1
|
||||
material: PAPER
|
||||
custom-model-data:
|
||||
enabled: false
|
||||
type: float
|
||||
value: 1001
|
||||
reset:
|
||||
title: "&7ToolStats: &8Reset Token"
|
||||
lore:
|
||||
- "&8Combine in an anvil with to reset ALL stats for this item. Tokens on this item stay."
|
||||
- "&8Uses &7{levels} &8level."
|
||||
levels: 1
|
||||
material: PAPER
|
||||
custom-model-data:
|
||||
enabled: false
|
||||
type: float
|
||||
value: 1001
|
||||
remove:
|
||||
title: "&7ToolStats: &8Remove Token"
|
||||
lore:
|
||||
- "&8Combine in an anvil with to REMOVE ALL stats and tokens for this item."
|
||||
- "&8Uses &7{levels} &8level."
|
||||
levels: 1
|
||||
material: PAPER
|
||||
custom-model-data:
|
||||
enabled: false
|
||||
type: float
|
||||
value: 1001
|
||||
|
||||
enabled:
|
||||
# Will show "Crafted by <player>"
|
||||
@@ -274,4 +346,4 @@ normalize-time-creation: false
|
||||
# Allows stats and origins to be tracked if the player is in creative mode.
|
||||
allow-creative: false
|
||||
|
||||
config-version: 12
|
||||
config-version: 13
|
||||
@@ -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
|
||||
|
||||