mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
@@ -22,6 +22,7 @@ import lol.hyper.githubreleaseapi.GitHubReleaseAPI;
|
||||
import lol.hyper.toolstats.commands.CommandToolStats;
|
||||
import lol.hyper.toolstats.events.*;
|
||||
import lol.hyper.toolstats.tools.HashMaker;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import lol.hyper.toolstats.tools.ItemLore;
|
||||
import lol.hyper.toolstats.tools.NumberFormat;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
@@ -100,6 +101,10 @@ public final class ToolStats extends JavaPlugin {
|
||||
*/
|
||||
public final NamespacedKey originType = new NamespacedKey(this, "origin");
|
||||
|
||||
public final int CONFIG_VERSION = 6;
|
||||
public final Logger logger = this.getLogger();
|
||||
public final File configFile = new File(this.getDataFolder(), "config.yml");
|
||||
|
||||
public BlocksMined blocksMined;
|
||||
public ChunkPopulate chunkPopulate;
|
||||
public CraftItem craftItem;
|
||||
@@ -116,16 +121,12 @@ public final class ToolStats extends JavaPlugin {
|
||||
public InventoryOpen inventoryOpen;
|
||||
public PlayerJoin playerJoin;
|
||||
public NumberFormat numberFormat;
|
||||
|
||||
public final Logger logger = this.getLogger();
|
||||
public final File configFile = new File(this.getDataFolder(), "config.yml");
|
||||
public FileConfiguration config;
|
||||
public final int CONFIG_VERSION = 6;
|
||||
|
||||
private BukkitAudiences adventure;
|
||||
public MorePaperLib morePaperLib;
|
||||
public HashMaker hashMaker;
|
||||
public CreativeEvent creativeEvent;
|
||||
public ItemChecker itemChecker;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -153,6 +154,7 @@ public final class ToolStats extends JavaPlugin {
|
||||
inventoryOpen = new InventoryOpen(this);
|
||||
playerJoin = new PlayerJoin(this);
|
||||
creativeEvent = new CreativeEvent(this);
|
||||
itemChecker = new ItemChecker();
|
||||
|
||||
Bukkit.getServer().getPluginManager().registerEvents(blocksMined, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(chunkPopulate, this);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package lol.hyper.toolstats.commands;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -86,7 +85,7 @@ public class CommandToolStats implements TabExecutor {
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
||||
if (!ItemChecker.isValidItem(heldItem.getType())) {
|
||||
if (!toolStats.itemChecker.isValidItem(heldItem.getType())) {
|
||||
audiences.sender(sender).sendMessage(Component.text("You must hold a valid item.", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -71,7 +70,7 @@ public class BlocksMined implements Listener {
|
||||
}
|
||||
|
||||
// only check certain items
|
||||
if (!ItemChecker.isMineTool(heldItem.getType())) {
|
||||
if (!toolStats.itemChecker.isMineTool(heldItem.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
@@ -57,7 +56,7 @@ public class CraftItem implements Listener {
|
||||
return;
|
||||
}
|
||||
// only check certain items
|
||||
if (!ItemChecker.isValidItem(itemStack.getType())) {
|
||||
if (!toolStats.itemChecker.isValidItem(itemStack.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -49,7 +48,7 @@ public class CreativeEvent implements Listener {
|
||||
return;
|
||||
}
|
||||
ItemStack spawnedItem = event.getCursor();
|
||||
if (!ItemChecker.isValidItem(spawnedItem.getType())) {
|
||||
if (!toolStats.itemChecker.isValidItem(spawnedItem.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.*;
|
||||
@@ -74,7 +73,7 @@ public class EntityDamage implements Listener {
|
||||
PlayerInventory attackingPlayerInventory = attackingPlayer.getInventory();
|
||||
ItemStack heldItem = attackingPlayerInventory.getItemInMainHand();
|
||||
// only check certain items
|
||||
if (!ItemChecker.isMeleeWeapon(heldItem.getType())) {
|
||||
if (!toolStats.itemChecker.isMeleeWeapon(heldItem.getType())) {
|
||||
return;
|
||||
}
|
||||
// a player is killing another player
|
||||
@@ -152,7 +151,7 @@ public class EntityDamage implements Listener {
|
||||
PlayerInventory playerInventory = playerTakingDamage.getInventory();
|
||||
for (ItemStack armorPiece : playerInventory.getArmorContents()) {
|
||||
if (armorPiece != null) {
|
||||
if (ItemChecker.isArmor(armorPiece.getType())) {
|
||||
if (toolStats.itemChecker.isArmor(armorPiece.getType())) {
|
||||
updateDamage(armorPiece, event.getFinalDamage());
|
||||
}
|
||||
}
|
||||
@@ -182,7 +181,7 @@ public class EntityDamage implements Listener {
|
||||
PlayerInventory playerInventory = playerTakingDamage.getInventory();
|
||||
for (ItemStack armorPiece : playerInventory.getArmorContents()) {
|
||||
if (armorPiece != null) {
|
||||
if (ItemChecker.isArmor(armorPiece.getType())) {
|
||||
if (toolStats.itemChecker.isArmor(armorPiece.getType())) {
|
||||
updateDamage(armorPiece, event.getFinalDamage());
|
||||
}
|
||||
}
|
||||
@@ -212,7 +211,7 @@ public class EntityDamage implements Listener {
|
||||
PlayerInventory playerInventory = playerTakingDamage.getInventory();
|
||||
for (ItemStack armorPiece : playerInventory.getArmorContents()) {
|
||||
if (armorPiece != null) {
|
||||
if (ItemChecker.isArmor(armorPiece.getType())) {
|
||||
if (toolStats.itemChecker.isArmor(armorPiece.getType())) {
|
||||
updateDamage(armorPiece, event.getFinalDamage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -59,7 +58,7 @@ public class EntityDeath implements Listener {
|
||||
}
|
||||
|
||||
}
|
||||
if (ItemChecker.isValidItem(droppedItem.getType())) {
|
||||
if (toolStats.itemChecker.isValidItem(droppedItem.getType())) {
|
||||
ItemStack newItem = addLore(droppedItem, livingEntity.getName());
|
||||
if (newItem != null) {
|
||||
event.getDrops().set(i, newItem);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -140,7 +139,7 @@ public class GenerateLoot implements Listener {
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
if (ItemChecker.isValidItem(itemStack.getType())) {
|
||||
if (toolStats.itemChecker.isValidItem(itemStack.getType())) {
|
||||
ItemStack newItem = addLore(itemStack, player);
|
||||
if (newItem != null) {
|
||||
loot.set(i, newItem);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -55,7 +54,7 @@ public class InventoryOpen implements Listener {
|
||||
continue;
|
||||
}
|
||||
// ignore items that are not the right type
|
||||
if (!ItemChecker.isValidItem(itemStack.getType())) {
|
||||
if (!toolStats.itemChecker.isValidItem(itemStack.getType())) {
|
||||
continue;
|
||||
}
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
@@ -92,7 +91,7 @@ public class PlayerFish implements Listener {
|
||||
}
|
||||
ItemStack caughtItem = ((Item) event.getCaught()).getItemStack();
|
||||
Item caughtItemEntity = (Item) event.getCaught();
|
||||
if (ItemChecker.isValidItem(caughtItem.getType())) {
|
||||
if (toolStats.itemChecker.isValidItem(caughtItem.getType())) {
|
||||
ItemStack newItem = addNewLore(caughtItem, player);
|
||||
if (newItem != null) {
|
||||
caughtItemEntity.setItemStack(newItem);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -52,7 +51,7 @@ public class PlayerJoin implements Listener {
|
||||
continue;
|
||||
}
|
||||
// ignore items that are not the right type
|
||||
if (!ItemChecker.isValidItem(itemStack.getType())) {
|
||||
if (!toolStats.itemChecker.isValidItem(itemStack.getType())) {
|
||||
continue;
|
||||
}
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
@@ -65,7 +64,7 @@ public class VillagerTrade implements Listener {
|
||||
if (event.getSlotType() == InventoryType.SlotType.RESULT) {
|
||||
ItemStack item = event.getCurrentItem();
|
||||
// only check items we want
|
||||
if (!ItemChecker.isValidItem(item.getType())) {
|
||||
if (!toolStats.itemChecker.isValidItem(item.getType())) {
|
||||
return;
|
||||
}
|
||||
// if the player shift clicks, show the warning
|
||||
|
||||
@@ -19,15 +19,51 @@ package lol.hyper.toolstats.tools;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ItemChecker {
|
||||
|
||||
private static final String[] validItems = {"pickaxe", "sword", "shovel", "axe", "hoe", "bow", "helmet", "chestplate", "leggings", "boots", "fishing", "elytra"};
|
||||
private static final String[] validArmor = {"helmet", "chestplate", "leggings", "boots"};
|
||||
private static final String[] validMelee = {"sword", "trident", "axe"};
|
||||
private static final String[] validMine = {"pickaxe", "axe", "hoe", "shovel", "shear", "hoe"};
|
||||
private final List<Material> validItems = new ArrayList<>();
|
||||
private final List<Material> armorItems = new ArrayList<>();
|
||||
private final List<Material> meleeItems = new ArrayList<>();
|
||||
private final List<Material> mineItems = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Creates an item checker and saves all valid items we want.
|
||||
*/
|
||||
public ItemChecker() {
|
||||
for (Material material : Material.values()) {
|
||||
String lowerCase = material.toString().toLowerCase(Locale.ROOT);
|
||||
if (lowerCase.contains("_pickaxe") || lowerCase.contains("_axe") || lowerCase.contains("_hoe") || lowerCase.contains("_shovel")) {
|
||||
mineItems.add(material);
|
||||
}
|
||||
|
||||
if (lowerCase.contains("_sword") || lowerCase.contains("_axe")) {
|
||||
meleeItems.add(material);
|
||||
}
|
||||
|
||||
if (lowerCase.contains("_helmet") || lowerCase.contains("_chestplate") || lowerCase.contains("_leggings") || lowerCase.contains("_boots")) {
|
||||
armorItems.add(material);
|
||||
}
|
||||
}
|
||||
|
||||
// hardcode these
|
||||
mineItems.add(Material.SHEARS);
|
||||
meleeItems.add(Material.TRIDENT);
|
||||
validItems.add(Material.BOW);
|
||||
validItems.add(Material.FISHING_ROD);
|
||||
|
||||
// combine the lists
|
||||
validItems.addAll(armorItems);
|
||||
validItems.addAll(meleeItems);
|
||||
validItems.addAll(mineItems);
|
||||
|
||||
for (Material material : validItems) {
|
||||
System.out.println(material);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if item is an armor piece.
|
||||
@@ -35,8 +71,8 @@ public class ItemChecker {
|
||||
* @param itemType The item type, not name.
|
||||
* @return If the item is an armor piece.
|
||||
*/
|
||||
public static boolean isArmor(Material itemType) {
|
||||
return Arrays.stream(validArmor).anyMatch(type -> itemType.toString().toLowerCase(Locale.ROOT).contains(type));
|
||||
public boolean isArmor(Material itemType) {
|
||||
return armorItems.contains(itemType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,8 +81,8 @@ public class ItemChecker {
|
||||
* @param itemType The item type, not name.
|
||||
* @return If the item something we want to track.
|
||||
*/
|
||||
public static boolean isValidItem(Material itemType) {
|
||||
return Arrays.stream(validItems).anyMatch(type -> itemType.toString().toLowerCase(Locale.ROOT).contains(type));
|
||||
public boolean isValidItem(Material itemType) {
|
||||
return validItems.contains(itemType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,8 +91,8 @@ public class ItemChecker {
|
||||
* @param itemType The item type, not name.
|
||||
* @return If the item is a melee weapon.
|
||||
*/
|
||||
public static boolean isMeleeWeapon(Material itemType) {
|
||||
return Arrays.stream(validMelee).anyMatch(type -> itemType.toString().toLowerCase(Locale.ROOT).contains(type));
|
||||
public boolean isMeleeWeapon(Material itemType) {
|
||||
return meleeItems.contains(itemType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +101,7 @@ public class ItemChecker {
|
||||
* @param itemType The item type, not name.
|
||||
* @return If the item is a mining tool.
|
||||
*/
|
||||
public static boolean isMineTool(Material itemType) {
|
||||
return Arrays.stream(validMine).anyMatch(type -> itemType.toString().toLowerCase(Locale.ROOT).contains(type));
|
||||
public boolean isMineTool(Material itemType) {
|
||||
return mineItems.contains(itemType);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user