mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2026-01-21 13:55:59 +00:00
Compare commits
9 Commits
c22c36f0a4
...
1.9.11
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5040a4636 | ||
|
|
c28ee0fb8c | ||
|
|
8fe7292505 | ||
|
|
3da74fe656 | ||
|
|
ab0d2a1ca1 | ||
|
|
857ce5b631 | ||
|
|
b14fb30212 | ||
|
|
a9bb876b38 | ||
|
|
e819fadd50 |
@@ -16,7 +16,7 @@ Here is everything it tracks:
|
||||
* Blocks mined (pickaxes, shovels, axes, hoes, shears).
|
||||
* Crops mined (hoes).
|
||||
* Player/mob kills (swords, axes, tridents, bows/crossbows, mace).
|
||||
* Ownership of items when crafted, looted (from chests), traded, spawned via creative, and caught from fishing.
|
||||
* Ownership of items when crafted, looted (from chests/vaults/barrels), traded, spawned via creative, and caught from fishing.
|
||||
* Armor damage taken.
|
||||
* Damage done with weapons.
|
||||
* Fish caught.
|
||||
|
||||
8
pom.xml
8
pom.xml
@@ -23,7 +23,7 @@
|
||||
|
||||
<groupId>lol.hyper</groupId>
|
||||
<artifactId>toolstats</artifactId>
|
||||
<version>1.9.9</version>
|
||||
<version>1.9.11</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>ToolStats</name>
|
||||
@@ -51,7 +51,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.14.0</version>
|
||||
<version>3.14.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
@@ -60,7 +60,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.6.1</version>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
@@ -105,7 +105,7 @@
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.21.8-R0.1-SNAPSHOT</version>
|
||||
<version>1.21.11-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -119,7 +119,7 @@ public final class ToolStats extends JavaPlugin {
|
||||
*/
|
||||
public final NamespacedKey originType = new NamespacedKey(this, "origin");
|
||||
|
||||
public final int CONFIG_VERSION = 13;
|
||||
public final int CONFIG_VERSION = 14;
|
||||
public final ComponentLogger logger = this.getComponentLogger();
|
||||
public final File configFile = new File(this.getDataFolder(), "config.yml");
|
||||
public boolean tokens = false;
|
||||
@@ -151,6 +151,7 @@ public final class ToolStats extends JavaPlugin {
|
||||
public TokenData tokenData;
|
||||
public AnvilEvent anvilEvent;
|
||||
public PrepareCraft prepareCraft;
|
||||
public BlockDispenseEvent blockDispenseEvent;
|
||||
public HyperLib hyperLib;
|
||||
public TextUtils textUtils;
|
||||
|
||||
@@ -201,6 +202,7 @@ public final class ToolStats extends JavaPlugin {
|
||||
shootBow = new ShootBow(this);
|
||||
anvilEvent = new AnvilEvent(this);
|
||||
prepareCraft = new PrepareCraft(this);
|
||||
blockDispenseEvent = new BlockDispenseEvent(this);
|
||||
|
||||
// save which stat can be used by a reset token
|
||||
tokenKeys.add(blocksMined);
|
||||
@@ -231,6 +233,7 @@ public final class ToolStats extends JavaPlugin {
|
||||
Bukkit.getServer().getPluginManager().registerEvents(playerMove, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(anvilEvent, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(prepareCraft, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(blockDispenseEvent, this);
|
||||
|
||||
this.getCommand("toolstats").setExecutor(commandToolStats);
|
||||
|
||||
|
||||
141
src/main/java/lol/hyper/toolstats/events/BlockDispenseEvent.java
Normal file
141
src/main/java/lol/hyper/toolstats/events/BlockDispenseEvent.java
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* This file is part of ToolStats.
|
||||
*
|
||||
* ToolStats is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ToolStats is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockDispenseLootEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class BlockDispenseEvent implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public BlockDispenseEvent(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onDispense(BlockDispenseLootEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ItemStack> loot = event.getDispensedLoot();
|
||||
// probably won't ever happen
|
||||
if (loot.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ItemStack> newLoot = new ArrayList<>();
|
||||
for (ItemStack lootItem : loot) {
|
||||
ItemStack newLootItem = lootItem.clone();
|
||||
Material lootItemMaterial = newLootItem.getType();
|
||||
// if the item is one we want, do stuff
|
||||
if (toolStats.itemChecker.isValidItem(lootItemMaterial)) {
|
||||
newLootItem = addLootedOrigin(newLootItem, player);
|
||||
}
|
||||
|
||||
// if the item returned null, add the original item
|
||||
newLoot.add(Objects.requireNonNullElse(newLootItem, lootItem));
|
||||
}
|
||||
event.setDispensedLoot(newLoot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds lore to newly generated items.
|
||||
*
|
||||
* @param itemStack The item to add lore to.
|
||||
* @param owner The player that found the item.
|
||||
* @return The item with the lore.
|
||||
*/
|
||||
private ItemStack addLootedOrigin(ItemStack itemStack, Player owner) {
|
||||
ItemStack newItem = itemStack.clone();
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta == null) {
|
||||
return null;
|
||||
}
|
||||
long timeCreated = System.currentTimeMillis();
|
||||
Date finalDate;
|
||||
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||
timeCreated = finalDate.getTime();
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// get the current lore the item
|
||||
List<Component> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.lore();
|
||||
} else {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
|
||||
// if creation date is enabled, add it
|
||||
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 2, newItem);
|
||||
if (creationDate != null) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
||||
lore.add(creationDate);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
// if ownership is enabled, add it
|
||||
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 2, newItem);
|
||||
if (itemOwner != null) {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
||||
lore.add(itemOwner);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
// if hash is enabled, add it
|
||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
}
|
||||
|
||||
newItem.setItemMeta(meta);
|
||||
return newItem;
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,8 @@ package lol.hyper.toolstats.events;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -31,6 +31,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -62,7 +63,8 @@ public class PlayerInteract implements Listener {
|
||||
return;
|
||||
}
|
||||
// store when a player opens a chest
|
||||
if (block.getType() != Material.AIR && block.getType() == Material.CHEST) {
|
||||
BlockState state = block.getState();
|
||||
if (state instanceof InventoryHolder) {
|
||||
openedChests.put(block, player);
|
||||
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> openedChests.remove(block), 20);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ItemChecker {
|
||||
mineItems.add(material);
|
||||
}
|
||||
|
||||
if (lowerCase.contains("_sword") || lowerCase.contains("_axe")) {
|
||||
if (lowerCase.contains("_sword") || lowerCase.contains("_axe") || lowerCase.contains("_spear")) {
|
||||
meleeItems.add(material);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ public class ConfigTools {
|
||||
case "trident" -> toolStats.config.getBoolean("enabled." + configName + ".trident");
|
||||
case "fishing-rod" -> toolStats.config.getBoolean("enabled." + configName + ".fishing-rod");
|
||||
case "mace" -> toolStats.config.getBoolean("enabled." + configName + ".mace");
|
||||
case "spear" -> toolStats.config.getBoolean("enabled." + configName + ".spear");
|
||||
case "helmet", "chestplate", "leggings", "boots" ->
|
||||
toolStats.config.getBoolean("enabled." + configName + ".armor");
|
||||
default -> false;
|
||||
|
||||
@@ -40,6 +40,7 @@ public class ConfigUpdater {
|
||||
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
|
||||
case 13 -> new Version14(toolStats).update(); // 13 to 14
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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 Version14 {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
/**
|
||||
* Used for updating from version 13 to 14.
|
||||
*
|
||||
* @param toolStats ToolStats instance.
|
||||
*/
|
||||
public Version14(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-13.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.error("Unable to save config-13.yml!", exception);
|
||||
}
|
||||
|
||||
toolStats.logger.info("Updating config.yml to version 14.");
|
||||
toolStats.config.set("config-version", 14);
|
||||
|
||||
// add spear to sections to be a toggle
|
||||
toolStats.config.set("enabled.crafted-by.spear", true);
|
||||
toolStats.logger.info("Adding enabled.crafted-by.spear");
|
||||
|
||||
toolStats.config.set("enabled.crafted-on.spear", true);
|
||||
toolStats.logger.info("Adding enabled.crafted-on.spear");
|
||||
|
||||
toolStats.config.set("enabled.looted-by.spear", true);
|
||||
toolStats.logger.info("Adding enabled.looted-by.spear");
|
||||
|
||||
toolStats.config.set("enabled.looted-on.spear", true);
|
||||
toolStats.logger.info("Adding enabled.looted-on.spear");
|
||||
|
||||
toolStats.config.set("enabled.damage-done.spear", true);
|
||||
toolStats.logger.info("Adding enabled.damage-done.spear");
|
||||
|
||||
toolStats.config.set("enabled.player-kills.spear", true);
|
||||
toolStats.logger.info("Adding enabled.player-kills.spear");
|
||||
|
||||
toolStats.config.set("enabled.mob-kills.spear", true);
|
||||
toolStats.logger.info("Adding enabled.mob-kills.spear");
|
||||
|
||||
toolStats.config.set("enabled.spawned-in-by.spear", true);
|
||||
toolStats.logger.info("Adding enabled.spawned-in-by.spear");
|
||||
|
||||
toolStats.config.set("enabled.spawned-in-on.spear", true);
|
||||
toolStats.logger.info("Adding enabled.spawned-in-on.spear");
|
||||
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||
}
|
||||
toolStats.loadConfig();
|
||||
toolStats.logger.info("Config has been updated to version 14. A copy of version 13 has been saved as config-13.yml");
|
||||
}
|
||||
}
|
||||
@@ -150,6 +150,7 @@ enabled:
|
||||
armor: true
|
||||
mace: true
|
||||
fishing-rod: true
|
||||
spear: true
|
||||
# Will show "Crafted on <date>"
|
||||
crafted-on:
|
||||
pickaxe: true
|
||||
@@ -162,6 +163,7 @@ enabled:
|
||||
armor: true
|
||||
mace: true
|
||||
fishing-rod: true
|
||||
spear: true
|
||||
# Will show "Fished by <player>"
|
||||
fished-by:
|
||||
pickaxe: true
|
||||
@@ -195,6 +197,7 @@ enabled:
|
||||
bow: true
|
||||
armor: true
|
||||
fishing-rod: true
|
||||
spear: true
|
||||
# Will show "Found on <date>"
|
||||
looted-on:
|
||||
pickaxe: true
|
||||
@@ -206,6 +209,7 @@ enabled:
|
||||
bow: true
|
||||
armor: true
|
||||
fishing-rod: true
|
||||
spear: true
|
||||
# Will show "Traded by <player>"
|
||||
traded-by:
|
||||
pickaxe: true
|
||||
@@ -234,18 +238,21 @@ enabled:
|
||||
trident: true
|
||||
bow: true
|
||||
mace: true
|
||||
spear: true
|
||||
player-kills:
|
||||
sword: true
|
||||
axe: true
|
||||
trident: true
|
||||
bow: true
|
||||
mace: true
|
||||
spear: true
|
||||
mob-kills:
|
||||
sword: true
|
||||
axe: true
|
||||
trident: true
|
||||
bow: true
|
||||
mace: true
|
||||
spear: true
|
||||
blocks-mined:
|
||||
pickaxe: true
|
||||
shovel: true
|
||||
@@ -264,6 +271,7 @@ enabled:
|
||||
armor: true
|
||||
mace: true
|
||||
fishing-rod: true
|
||||
spear: true
|
||||
# Will show "Spawned in on <date>"
|
||||
spawned-in-on:
|
||||
pickaxe: true
|
||||
@@ -276,6 +284,7 @@ enabled:
|
||||
armor: true
|
||||
mace: true
|
||||
fishing-rod: true
|
||||
spear: true
|
||||
fish-caught: true
|
||||
sheep-sheared: true
|
||||
armor-damage: true
|
||||
@@ -346,4 +355,4 @@ normalize-time-creation: false
|
||||
# Allows stats and origins to be tracked if the player is in creative mode.
|
||||
allow-creative: false
|
||||
|
||||
config-version: 13
|
||||
config-version: 14
|
||||
Reference in New Issue
Block a user