mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
unify item arrays & date formats
This commit is contained in:
@@ -32,6 +32,8 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public final class ToolStats extends JavaPlugin {
|
||||
@@ -55,6 +57,13 @@ public final class ToolStats extends JavaPlugin {
|
||||
// used for tracking new elytras
|
||||
public final NamespacedKey newElytra = new NamespacedKey(this, "new");
|
||||
|
||||
public final String[] allValidItems = {
|
||||
"pickaxe", "sword", "shovel", "axe", "hoe", "bow", "helmet", "chestplate", "leggings", "boots", "fishing"
|
||||
};
|
||||
public final String[] meleeItems = {"sword", "trident", "axe"};
|
||||
public final String[] mineItems = {"pickaxe", "axe", "hoe", "shovel", "shear"};
|
||||
public final SimpleDateFormat dateFormat = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
|
||||
|
||||
public BlocksMined blocksMined;
|
||||
public ChunkPopulate chunkPopulate;
|
||||
public CraftItem craftItem;
|
||||
@@ -144,7 +153,8 @@ public final class ToolStats extends JavaPlugin {
|
||||
|
||||
/**
|
||||
* Checks the config to see if we want to show lore on certain items.
|
||||
* @param itemStack The item to check.
|
||||
*
|
||||
* @param itemStack The item to check.
|
||||
* @param configName The config we are checking under.
|
||||
* @return If we want to allow lore or not.
|
||||
*/
|
||||
@@ -200,8 +210,9 @@ public final class ToolStats extends JavaPlugin {
|
||||
|
||||
/**
|
||||
* Gets the lore message from the config.
|
||||
*
|
||||
* @param configName The config name, "messages." is already in front.
|
||||
* @param raw If you want the raw message with the formatting codes and placeholders.
|
||||
* @param raw If you want the raw message with the formatting codes and placeholders.
|
||||
* @return The lore message.
|
||||
*/
|
||||
public String getLoreFromConfig(String configName, boolean raw) {
|
||||
|
||||
@@ -36,7 +36,6 @@ import java.util.List;
|
||||
public class BlocksMined implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
private final String[] validTools = {"pickaxe", "axe", "hoe", "shovel", "shear"};
|
||||
|
||||
public BlocksMined(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
@@ -59,7 +58,7 @@ public class BlocksMined implements Listener {
|
||||
}
|
||||
// only check certain items
|
||||
String itemName = heldItem.getType().toString().toLowerCase();
|
||||
if (Arrays.stream(validTools).noneMatch(itemName::contains)) {
|
||||
if (Arrays.stream(toolStats.mineItems).noneMatch(itemName::contains)) {
|
||||
return;
|
||||
}
|
||||
// if it's an item we want, update the stats
|
||||
|
||||
@@ -30,16 +30,11 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class CraftItem implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
public final String[] validItems = {
|
||||
"pickaxe", "sword", "shovel", "axe", "hoe", "bow", "helmet", "chestplate", "leggings", "boots", "fishing"
|
||||
};
|
||||
private final SimpleDateFormat format = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
|
||||
|
||||
public CraftItem(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
@@ -57,7 +52,7 @@ public class CraftItem implements Listener {
|
||||
}
|
||||
String name = itemStack.getType().toString().toLowerCase(Locale.ROOT);
|
||||
// only check for items we want
|
||||
for (String x : validItems) {
|
||||
for (String x : toolStats.allValidItems) {
|
||||
if (name.contains(x)) {
|
||||
// if the player shift clicks, send them this warning
|
||||
if (event.isShiftClick()) {
|
||||
@@ -80,8 +75,9 @@ public class CraftItem implements Listener {
|
||||
|
||||
/**
|
||||
* Adds crafted tags to item.
|
||||
*
|
||||
* @param itemStack The item add item to.
|
||||
* @param owner The player crafting.
|
||||
* @param owner The player crafting.
|
||||
* @return A copy of the item with the tags + lore.
|
||||
*/
|
||||
private ItemStack addLore(ItemStack itemStack, Player owner) {
|
||||
@@ -127,7 +123,7 @@ public class CraftItem implements Listener {
|
||||
}
|
||||
// do we add the lore based on the config?
|
||||
if (toolStats.checkConfig(itemStack, "created-date")) {
|
||||
lore.add(createdOnRaw.replace("{date}", format.format(finalDate)));
|
||||
lore.add(createdOnRaw.replace("{date}", toolStats.dateFormat.format(finalDate)));
|
||||
}
|
||||
if (toolStats.checkConfig(itemStack, "created-by")) {
|
||||
lore.add(createdByRaw.replace("{player}", owner.getName()));
|
||||
|
||||
@@ -39,7 +39,6 @@ import java.util.*;
|
||||
public class EntityDamage implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
private final String[] validTools = {"sword", "trident", "axe"};
|
||||
private final DecimalFormat decimalFormat = new DecimalFormat("0.00");
|
||||
public final Set<UUID> trackedMobs = new HashSet<>();
|
||||
|
||||
@@ -71,7 +70,7 @@ public class EntityDamage implements Listener {
|
||||
}
|
||||
// check items we want
|
||||
String itemName = heldItem.getType().toString().toLowerCase();
|
||||
if (Arrays.stream(validTools).noneMatch(itemName::contains)) {
|
||||
if (Arrays.stream(toolStats.meleeItems).noneMatch(itemName::contains)) {
|
||||
return;
|
||||
}
|
||||
// a player is killing another player
|
||||
@@ -176,6 +175,7 @@ public class EntityDamage implements Listener {
|
||||
|
||||
/**
|
||||
* Updates a weapon's player kills.
|
||||
*
|
||||
* @param itemStack The item to update.
|
||||
* @return A copy of the item.
|
||||
*/
|
||||
@@ -238,6 +238,7 @@ public class EntityDamage implements Listener {
|
||||
|
||||
/**
|
||||
* Updates a weapon's mob kills.
|
||||
*
|
||||
* @param itemStack The item to update.
|
||||
* @return A copy of the item.
|
||||
*/
|
||||
@@ -300,8 +301,9 @@ public class EntityDamage implements Listener {
|
||||
|
||||
/**
|
||||
* Updates a player's armor damage stats.
|
||||
*
|
||||
* @param itemStack The armor piece.
|
||||
* @param damage How much damage is being added.
|
||||
* @param damage How much damage is being added.
|
||||
*/
|
||||
private void updateArmorDamage(ItemStack itemStack, double damage) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
@@ -360,6 +362,7 @@ public class EntityDamage implements Listener {
|
||||
|
||||
/**
|
||||
* Check if item is an armor piece.
|
||||
*
|
||||
* @param itemType The item type, not name.
|
||||
* @return If the item is an armor piece.
|
||||
*/
|
||||
|
||||
@@ -47,7 +47,7 @@ public class EntityDeath implements Listener {
|
||||
if (toolStats.mobKill.trackedMobs.contains(livingEntityUUID)) {
|
||||
for (ItemStack current : event.getDrops()) {
|
||||
String name = current.getType().toString().toLowerCase(Locale.ROOT);
|
||||
for (String item : toolStats.craftItem.validItems) {
|
||||
for (String item : toolStats.allValidItems) {
|
||||
if (name.contains(item)) {
|
||||
addLore(current, livingEntity.getName());
|
||||
}
|
||||
@@ -59,8 +59,9 @@ public class EntityDeath implements Listener {
|
||||
|
||||
/**
|
||||
* Adds "drop by" tag to item.
|
||||
*
|
||||
* @param itemStack The item to add lore to.
|
||||
* @param mob The mob or player name.
|
||||
* @param mob The mob or player name.
|
||||
*/
|
||||
private void addLore(ItemStack itemStack, String mob) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
@@ -43,10 +43,6 @@ import java.util.Locale;
|
||||
public class GenerateLoot implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
public final String[] validItems = {
|
||||
"pickaxe", "sword", "shovel", "axe", "hoe", "bow", "helmet", "chestplate", "leggings", "boots", "fishing"
|
||||
};
|
||||
private final SimpleDateFormat format = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
|
||||
|
||||
public GenerateLoot(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
@@ -88,20 +84,21 @@ public class GenerateLoot implements Listener {
|
||||
continue;
|
||||
}
|
||||
String name = itemStack.getType().toString().toLowerCase(Locale.ROOT);
|
||||
for (String x : validItems) {
|
||||
for (String x : toolStats.allValidItems) {
|
||||
if (name.contains(x)) {
|
||||
chestInv.setItem(i, addLore(itemStack, player));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},1);
|
||||
}, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds lore to newly generated items.
|
||||
*
|
||||
* @param itemStack The item to add lore to.
|
||||
* @param owner The player that found the item.
|
||||
* @param owner The player that found the item.
|
||||
* @return The item with the lore.
|
||||
*/
|
||||
private ItemStack addLore(ItemStack itemStack, Player owner) {
|
||||
@@ -137,7 +134,7 @@ public class GenerateLoot implements Listener {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
if (toolStats.checkConfig(newItem, "looted-tag")) {
|
||||
lore.add(foundOnLoreRaw.replace("{date}", format.format(finalDate)));
|
||||
lore.add(foundOnLoreRaw.replace("{date}", toolStats.dateFormat.format(finalDate)));
|
||||
lore.add(foundByLoreRaw.replace("{player}", owner.getName()));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
|
||||
@@ -30,16 +30,13 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class PickupItem implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
private final SimpleDateFormat format = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
|
||||
|
||||
public PickupItem(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
@@ -69,8 +66,9 @@ public class PickupItem implements Listener {
|
||||
|
||||
/**
|
||||
* Adds "looted by" tags for elytras.
|
||||
*
|
||||
* @param itemStack The elytra to add lore to.
|
||||
* @param owner The player who found it.
|
||||
* @param owner The player who found it.
|
||||
*/
|
||||
private void addLore(ItemStack itemStack, Player owner) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
@@ -100,7 +98,7 @@ public class PickupItem implements Listener {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
if (toolStats.config.getBoolean("enabled.elytra-tag")) {
|
||||
lore.add(foundOnLoreRaw.replace("{date}", format.format(finalDate)));
|
||||
lore.add(foundOnLoreRaw.replace("{date}", toolStats.dateFormat.format(finalDate)));
|
||||
lore.add(foundByLoreRaw.replace("{player}", owner.getName()));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
|
||||
@@ -39,10 +39,6 @@ import java.util.Locale;
|
||||
public class PlayerFish implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
public final String[] validItems = {
|
||||
"pickaxe", "sword", "shovel", "axe", "hoe", "bow", "helmet", "chestplate", "leggings", "boots", "fishing"
|
||||
};
|
||||
private final SimpleDateFormat format = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
|
||||
|
||||
public PlayerFish(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
@@ -68,7 +64,7 @@ public class PlayerFish implements Listener {
|
||||
return;
|
||||
}
|
||||
ItemStack caughtItem = ((Item) event.getCaught()).getItemStack();
|
||||
for (String x : validItems) {
|
||||
for (String x : toolStats.allValidItems) {
|
||||
if (caughtItem.getType().toString().toLowerCase(Locale.ROOT).contains(x)) {
|
||||
addNewLore(caughtItem, player);
|
||||
}
|
||||
@@ -77,6 +73,7 @@ public class PlayerFish implements Listener {
|
||||
|
||||
/**
|
||||
* Updates a fishing rod's count.
|
||||
*
|
||||
* @param itemStack The fishing rod to update.
|
||||
*/
|
||||
private void updateFishCount(ItemStack itemStack) {
|
||||
@@ -135,8 +132,9 @@ public class PlayerFish implements Listener {
|
||||
|
||||
/**
|
||||
* Adds "caught by" tags to newly fished items.
|
||||
*
|
||||
* @param itemStack The item to add lore to.
|
||||
* @param owner The player who caught the item.
|
||||
* @param owner The player who caught the item.
|
||||
*/
|
||||
private void addNewLore(ItemStack itemStack, Player owner) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
@@ -170,7 +168,7 @@ public class PlayerFish implements Listener {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
if (toolStats.checkConfig(itemStack, "fished-tag")) {
|
||||
lore.add(caughtOnLoreRaw.replace("{date}", format.format(finalDate)));
|
||||
lore.add(caughtOnLoreRaw.replace("{date}", toolStats.dateFormat.format(finalDate)));
|
||||
lore.add(caughtByLoreRaw.replace("{player}", owner.getName()));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
|
||||
@@ -66,6 +66,7 @@ public class SheepShear implements Listener {
|
||||
|
||||
/**
|
||||
* Adds tags to shears.
|
||||
*
|
||||
* @param itemStack The shears.
|
||||
*/
|
||||
private void addLore(ItemStack itemStack) {
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -42,10 +41,6 @@ import java.util.Locale;
|
||||
public class VillagerTrade implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
public final String[] validItems = {
|
||||
"pickaxe", "sword", "shovel", "axe", "hoe", "bow", "helmet", "chestplate", "leggings", "boots", "fishing"
|
||||
};
|
||||
private final SimpleDateFormat format = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
|
||||
|
||||
public VillagerTrade(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
@@ -63,7 +58,7 @@ public class VillagerTrade implements Listener {
|
||||
if (event.getSlotType() == InventoryType.SlotType.RESULT) {
|
||||
ItemStack item = event.getCurrentItem();
|
||||
// only check items we want
|
||||
for (String x : validItems) {
|
||||
for (String x : toolStats.allValidItems) {
|
||||
if (item.getType().toString().toLowerCase(Locale.ROOT).contains(x)) {
|
||||
// if the player shift clicks show the warning
|
||||
if (event.isShiftClick()) {
|
||||
@@ -78,7 +73,7 @@ public class VillagerTrade implements Listener {
|
||||
}
|
||||
// this gets delayed since villager inventories suck for no reason
|
||||
// if you don't delay this it doesn't work idk
|
||||
Bukkit.getScheduler().runTaskLater(toolStats, ()-> event.setCurrentItem(newItem), 5);
|
||||
Bukkit.getScheduler().runTaskLater(toolStats, () -> event.setCurrentItem(newItem), 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,8 +82,9 @@ public class VillagerTrade implements Listener {
|
||||
|
||||
/**
|
||||
* Adds "traded by" tags to item.
|
||||
*
|
||||
* @param itemStack The item to add lore.
|
||||
* @param owner The player who traded.
|
||||
* @param owner The player who traded.
|
||||
* @return The item with lore.
|
||||
*/
|
||||
private ItemStack addLore(ItemStack itemStack, Player owner) {
|
||||
@@ -123,7 +119,7 @@ public class VillagerTrade implements Listener {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
if (toolStats.checkConfig(itemStack, "traded-tag")) {
|
||||
lore.add(tradedOnLoreRaw.replace("{date}", format.format(finalDate)));
|
||||
lore.add(tradedOnLoreRaw.replace("{date}", toolStats.dateFormat.format(finalDate)));
|
||||
lore.add(tradedByLoreRaw.replace("{player}", owner.getName()));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
|
||||
Reference in New Issue
Block a user