mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a55cea4b5d | ||
|
|
d0fcd4fc61 | ||
|
|
f14b9bc474 | ||
|
|
366a54052a | ||
|
|
fe96235ed1 | ||
|
|
fe8052f9d6 | ||
|
|
884bdef444 | ||
|
|
be31202f65 | ||
|
|
39d8a42110 | ||
|
|
91090dd6cc | ||
|
|
29a2a5150c | ||
|
|
b38d2825cb | ||
|
|
fd6c120a58 | ||
|
|
459569a1dc | ||
|
|
9ba6200415 | ||
|
|
b94e0e8c36 | ||
|
|
a42c526198 | ||
|
|
851a494935 | ||
|
|
72e869d5e2 | ||
|
|
300fe56c5a |
22
pom.xml
22
pom.xml
@@ -23,7 +23,7 @@
|
||||
|
||||
<groupId>lol.hyper</groupId>
|
||||
<artifactId>toolstats</artifactId>
|
||||
<version>1.6.2</version>
|
||||
<version>1.7</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>ToolStats</name>
|
||||
@@ -37,7 +37,7 @@
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.3.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>auto-clean</id>
|
||||
@@ -60,7 +60,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<version>3.5.0</version>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
@@ -75,6 +75,10 @@
|
||||
<pattern>lol.hyper.githubreleaseapi</pattern>
|
||||
<shadedPattern>lol.hyper.toolstats.updater</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>space.arim.morepaperlib</pattern>
|
||||
<shadedPattern>lol.hyper.toolstats.morepaperlib</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
<executions>
|
||||
@@ -103,6 +107,10 @@
|
||||
<id>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>arim-mvn-lgpl3</id>
|
||||
<url>https://mvn-repo.arim.space/lesser-gpl3/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@@ -127,7 +135,7 @@
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<version>4.14.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -136,5 +144,11 @@
|
||||
<version>4.3.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>space.arim.morepaperlib</groupId>
|
||||
<artifactId>morepaperlib</artifactId>
|
||||
<version>0.4.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -25,13 +25,14 @@ import lol.hyper.toolstats.tools.ItemLore;
|
||||
import lol.hyper.toolstats.tools.NumberFormat;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import space.arim.morepaperlib.MorePaperLib;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -39,26 +40,56 @@ import java.util.logging.Logger;
|
||||
|
||||
public final class ToolStats extends JavaPlugin {
|
||||
|
||||
// stores who created an item
|
||||
/**
|
||||
* Stores who created an item.
|
||||
*/
|
||||
public final NamespacedKey genericOwner = new NamespacedKey(this, "owner");
|
||||
// stores when an item was created
|
||||
/**
|
||||
* Stores when the item was created.
|
||||
*/
|
||||
public final NamespacedKey timeCreated = new NamespacedKey(this, "time-created");
|
||||
// stores how many player kills by sword
|
||||
/**
|
||||
* Stores how many player kills.
|
||||
*/
|
||||
public final NamespacedKey swordPlayerKills = new NamespacedKey(this, "player-kills");
|
||||
// stores how many mob kills by sword
|
||||
/**
|
||||
* Stores how many mob kills.
|
||||
*/
|
||||
public final NamespacedKey swordMobKills = new NamespacedKey(this, "mob-kills");
|
||||
// stores how blocks mined (used for all tools)
|
||||
/**
|
||||
* Stores how many blocks were mined.
|
||||
*/
|
||||
public final NamespacedKey genericMined = new NamespacedKey(this, "generic-mined");
|
||||
// stores how many fish were caught
|
||||
/**
|
||||
* Stores how many fish were caught.
|
||||
*/
|
||||
public final NamespacedKey fishingRodCaught = new NamespacedKey(this, "fish-caught");
|
||||
// stores how many times sheep were sheared
|
||||
/**
|
||||
* Stores how many sheep were sheared.
|
||||
*/
|
||||
public final NamespacedKey shearsSheared = new NamespacedKey(this, "sheared");
|
||||
// stores how much damage armor has taken
|
||||
/**
|
||||
* Stores how much damage an armor piece has taken.
|
||||
*/
|
||||
public final NamespacedKey armorDamage = new NamespacedKey(this, "damage-taken");
|
||||
// stores how much damage armor has taken (as int)
|
||||
/**
|
||||
* Stores how much damage an armor piece has taken (as an int).
|
||||
*/
|
||||
public final NamespacedKey armorDamageInt = new NamespacedKey(this, "damage-taken-int");
|
||||
// used for tracking new elytras
|
||||
/**
|
||||
* Key for tracking new elytras that spawn.
|
||||
*/
|
||||
public final NamespacedKey newElytra = new NamespacedKey(this, "new");
|
||||
/**
|
||||
* Stores how an item was created.
|
||||
* 0 = crafted.
|
||||
* 1 = dropped.
|
||||
* 2 = looted.
|
||||
* 3 = traded.
|
||||
* 4 = founded (for elytras).
|
||||
* 5 = fished.
|
||||
*/
|
||||
public final NamespacedKey originType = new NamespacedKey(this, "origin");
|
||||
|
||||
public BlocksMined blocksMined;
|
||||
public ChunkPopulate chunkPopulate;
|
||||
@@ -73,19 +104,23 @@ public final class ToolStats extends JavaPlugin {
|
||||
public VillagerTrade villagerTrade;
|
||||
public CommandToolStats commandToolStats;
|
||||
public ItemLore itemLore;
|
||||
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 = 4;
|
||||
public final int CONFIG_VERSION = 5;
|
||||
|
||||
private BukkitAudiences adventure;
|
||||
public MorePaperLib morePaperLib;
|
||||
|
||||
public NumberFormat numberFormat;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.adventure = BukkitAudiences.create(this);
|
||||
morePaperLib = new MorePaperLib(this);
|
||||
if (!configFile.exists()) {
|
||||
this.saveResource("config.yml", true);
|
||||
logger.info("Copying default config!");
|
||||
@@ -104,6 +139,8 @@ public final class ToolStats extends JavaPlugin {
|
||||
villagerTrade = new VillagerTrade(this);
|
||||
commandToolStats = new CommandToolStats(this);
|
||||
itemLore = new ItemLore(this);
|
||||
inventoryOpen = new InventoryOpen(this);
|
||||
playerJoin = new PlayerJoin(this);
|
||||
|
||||
Bukkit.getServer().getPluginManager().registerEvents(blocksMined, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(chunkPopulate, this);
|
||||
@@ -116,12 +153,14 @@ public final class ToolStats extends JavaPlugin {
|
||||
Bukkit.getServer().getPluginManager().registerEvents(playerInteract, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(sheepShear, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(villagerTrade, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(inventoryOpen, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(playerJoin, this);
|
||||
|
||||
this.getCommand("toolstats").setExecutor(commandToolStats);
|
||||
|
||||
new Metrics(this, 14110);
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, this::checkForUpdates);
|
||||
morePaperLib.scheduling().asyncScheduler().run(this::checkForUpdates);
|
||||
}
|
||||
|
||||
public void loadConfig() {
|
||||
@@ -272,4 +311,16 @@ public final class ToolStats extends JavaPlugin {
|
||||
}
|
||||
return this.adventure;
|
||||
}
|
||||
|
||||
public void scheduleEntity(BukkitRunnable runnable, Entity entity, int delay) {
|
||||
morePaperLib.scheduling().entitySpecificScheduler(entity).runDelayed(runnable, null, delay);
|
||||
}
|
||||
|
||||
public void scheduleGlobal(BukkitRunnable runnable, int delay) {
|
||||
morePaperLib.scheduling().globalRegionalScheduler().runDelayed(runnable, delay);
|
||||
}
|
||||
|
||||
public void scheduleRegion(BukkitRunnable runnable, World world, Chunk chunk, int delay) {
|
||||
morePaperLib.scheduling().regionSpecificScheduler(world, chunk.getX(), chunk.getZ()).runDelayed(runnable, delay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class CommandToolStats implements TabExecutor {
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
||||
if (ItemChecker.isValidItem(heldItem.getType())) {
|
||||
if (!ItemChecker.isValidItem(heldItem.getType())) {
|
||||
audiences.sender(sender).sendMessage(Component.text("You must hold a valid item.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
@@ -129,24 +129,15 @@ public class CommandToolStats implements TabExecutor {
|
||||
return;
|
||||
}
|
||||
|
||||
// determine how the item was originally created
|
||||
// this doesn't get saved, so we just rely on the lore
|
||||
// if there isn't a tag, default to crafted
|
||||
String type = "DEFAULT";
|
||||
if (finalMeta.hasLore()) {
|
||||
if (finalMeta.getLore() != null) {
|
||||
for (String line : finalMeta.getLore()) {
|
||||
if (line.contains(caughtByLore)) {
|
||||
type = "CAUGHT";
|
||||
}
|
||||
if (line.contains(lootedByLore)) {
|
||||
type = "LOOTED";
|
||||
}
|
||||
if (line.contains(tradedByLore)) {
|
||||
type = "TRADED";
|
||||
}
|
||||
}
|
||||
}
|
||||
// set how the item was obtained
|
||||
Integer origin = -1;
|
||||
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
||||
origin = container.get(toolStats.originType, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
// set to -1 if it's invalid
|
||||
if (origin == null) {
|
||||
origin = -1;
|
||||
}
|
||||
|
||||
// hard code elytras
|
||||
@@ -171,21 +162,25 @@ public class CommandToolStats implements TabExecutor {
|
||||
if (container.has(toolStats.genericOwner, new UUIDDataType())) {
|
||||
container.set(toolStats.genericOwner, new UUIDDataType(), player.getUniqueId());
|
||||
// show how the item was created based on the previous lore
|
||||
switch (type) {
|
||||
case "DEFAULT": {
|
||||
switch (origin) {
|
||||
case 0: {
|
||||
lore.add(toolStats.getLoreFromConfig("created.created-by", true).replace("{player}", player.getName()));
|
||||
break;
|
||||
}
|
||||
case "CAUGHT": {
|
||||
lore.add(toolStats.getLoreFromConfig("fished.caught-by", true).replace("{player}", player.getName()));
|
||||
case 2: {
|
||||
lore.add(toolStats.getLoreFromConfig("looted.looted-by", true).replace("{player}", player.getName()));
|
||||
break;
|
||||
}
|
||||
case "LOOTED": {
|
||||
case 3: {
|
||||
lore.add(toolStats.getLoreFromConfig("traded.traded-by", true).replace("{player}", player.getName()));
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
lore.add(toolStats.getLoreFromConfig("looted.found-by", true).replace("{player}", player.getName()));
|
||||
break;
|
||||
}
|
||||
case "TRADED": {
|
||||
lore.add(toolStats.getLoreFromConfig("traded.traded-by", true).replace("{player}", player.getName()));
|
||||
case 5: {
|
||||
lore.add(toolStats.getLoreFromConfig("fished.caught-by", true).replace("{player}", player.getName()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -196,21 +191,25 @@ public class CommandToolStats implements TabExecutor {
|
||||
Long time = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||
if (time != null) {
|
||||
// show how when the item was created based on the previous lore
|
||||
switch (type) {
|
||||
case "DEFAULT": {
|
||||
switch (origin) {
|
||||
case 0: {
|
||||
lore.add(toolStats.getLoreFromConfig("created.created-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
||||
break;
|
||||
}
|
||||
case "CAUGHT": {
|
||||
lore.add(toolStats.getLoreFromConfig("fished.caught-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
||||
case 2: {
|
||||
lore.add(toolStats.getLoreFromConfig("looted.looted-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
||||
break;
|
||||
}
|
||||
case "LOOTED": {
|
||||
case 3: {
|
||||
lore.add(toolStats.getLoreFromConfig("traded.traded-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
lore.add(toolStats.getLoreFromConfig("looted.found-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
||||
break;
|
||||
}
|
||||
case "TRADED": {
|
||||
lore.add(toolStats.getLoreFromConfig("traded.traded-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
||||
case 5: {
|
||||
lore.add(toolStats.getLoreFromConfig("fished.caught-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@@ -32,6 +31,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class ChunkPopulate implements Listener {
|
||||
|
||||
@@ -51,28 +51,32 @@ public class ChunkPopulate implements Listener {
|
||||
}
|
||||
// this is delayed because entities are not loaded instantly
|
||||
// we just check 1 second later
|
||||
Bukkit.getScheduler().runTaskLater(toolStats, () -> {
|
||||
Chunk chunk = event.getChunk();
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
// if there is a new item frame
|
||||
if (!(entity instanceof ItemFrame)) {
|
||||
return;
|
||||
}
|
||||
ItemFrame itemFrame = (ItemFrame) entity;
|
||||
// if the item frame has an elytra
|
||||
if (itemFrame.getItem().getType() == Material.ELYTRA) {
|
||||
ItemStack elytraCopy = itemFrame.getItem();
|
||||
ItemMeta meta = elytraCopy.getItemMeta();
|
||||
if (meta == null) {
|
||||
return;
|
||||
Chunk chunk = event.getChunk();
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
// if there is a new item frame
|
||||
if (!(entity instanceof ItemFrame)) {
|
||||
continue;
|
||||
}
|
||||
ItemFrame itemFrame = (ItemFrame) entity;
|
||||
// if the item frame has an elytra
|
||||
if (itemFrame.getItem().getType() == Material.ELYTRA) {
|
||||
ItemStack elytraCopy = itemFrame.getItem();
|
||||
ItemMeta meta = elytraCopy.getItemMeta();
|
||||
if (meta == null) {
|
||||
continue;
|
||||
}
|
||||
// add the new tag so we know it's new
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.set(toolStats.newElytra, PersistentDataType.INTEGER, 1);
|
||||
elytraCopy.setItemMeta(meta);
|
||||
itemFrame.setItem(elytraCopy);
|
||||
}
|
||||
// add the new tag so we know it's new
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.set(toolStats.newElytra, PersistentDataType.INTEGER, 1);
|
||||
elytraCopy.setItemMeta(meta);
|
||||
itemFrame.setItem(elytraCopy);
|
||||
}
|
||||
}
|
||||
}, 20);
|
||||
};
|
||||
toolStats.scheduleRegion(runnable, chunk.getWorld(), chunk, 20);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +106,7 @@ public class CraftItem implements Listener {
|
||||
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 0);
|
||||
|
||||
String createdByRaw = toolStats.getLoreFromConfig("created.created-by", true);
|
||||
String createdOnRaw = toolStats.getLoreFromConfig("created.created-on", true);
|
||||
|
||||
@@ -19,7 +19,6 @@ package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.*;
|
||||
|
||||
@@ -83,6 +83,9 @@ public class EntityDeath implements Listener {
|
||||
return null;
|
||||
}
|
||||
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
|
||||
|
||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{name}", mob, "dropped-by");
|
||||
|
||||
if (toolStats.config.getBoolean("enabled.dropped-by")) {
|
||||
|
||||
@@ -20,7 +20,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.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -37,6 +36,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -77,26 +77,29 @@ public class GenerateLoot implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
// run task later since if it runs on the same tick it breaks idk
|
||||
// run task later since if it runs on the same tick it breaks
|
||||
Block finalOpenedChest = openedChest;
|
||||
Bukkit.getScheduler().runTaskLater(toolStats, () -> {
|
||||
Player player = toolStats.playerInteract.openedChests.get(finalOpenedChest);
|
||||
// do a classic for loop, so we keep track of chest index of item
|
||||
for (int i = 0; i < chestInv.getContents().length; i++) {
|
||||
ItemStack itemStack = chestInv.getItem(i);
|
||||
// ignore air
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
if (ItemChecker.isValidItem(itemStack.getType())) {
|
||||
ItemStack newItem = addLore(itemStack, player);
|
||||
if (newItem != null) {
|
||||
chestInv.setItem(i, newItem);
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Player player = toolStats.playerInteract.openedChests.get(finalOpenedChest);
|
||||
// keep track of chest index of item
|
||||
for (int i = 0; i < chestInv.getContents().length; i++) {
|
||||
ItemStack itemStack = chestInv.getItem(i);
|
||||
// ignore air
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
if (ItemChecker.isValidItem(itemStack.getType())) {
|
||||
ItemStack newItem = addLore(itemStack, player);
|
||||
if (newItem != null) {
|
||||
chestInv.setItem(i, newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}, 1);
|
||||
};
|
||||
toolStats.scheduleRegion(runnable, lootLocation.getWorld(), lootLocation.getChunk(), 1);
|
||||
}
|
||||
if (inventoryHolder instanceof StorageMinecart) {
|
||||
StorageMinecart mineCart = (StorageMinecart) inventoryHolder;
|
||||
@@ -143,9 +146,10 @@ public class GenerateLoot implements Listener {
|
||||
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
||||
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate, "LOOTED");
|
||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
|
||||
if (toolStats.checkConfig(newItem, "looted-tag")) {
|
||||
meta.setLore(newLore);
|
||||
|
||||
87
src/main/java/lol/hyper/toolstats/events/InventoryOpen.java
Normal file
87
src/main/java/lol/hyper/toolstats/events/InventoryOpen.java
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class InventoryOpen implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public InventoryOpen(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onOpen(InventoryOpenEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory inventory = event.getInventory();
|
||||
for (ItemStack itemStack : inventory) {
|
||||
if (itemStack == null) {
|
||||
continue;
|
||||
}
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
if (itemMeta == null) {
|
||||
continue;
|
||||
}
|
||||
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||
// ignore any items that already have the origin tag
|
||||
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
||||
continue;
|
||||
}
|
||||
// ignore items that are not the right type
|
||||
if (!ItemChecker.isValidItem(itemStack.getType())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemMeta newMeta = toolStats.itemLore.getOrigin(itemMeta, itemStack.getType() == Material.ELYTRA);
|
||||
if (newMeta == null) {
|
||||
continue;
|
||||
}
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
itemStack.setItemMeta(newMeta);
|
||||
}
|
||||
};
|
||||
Location location = inventory.getLocation();
|
||||
// only run for actual inventories
|
||||
if (location != null) {
|
||||
toolStats.scheduleRegion(runnable, location.getWorld(), location.getChunk(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,10 +91,11 @@ public class PickupItem implements Listener {
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 4);
|
||||
container.remove(toolStats.newElytra);
|
||||
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate, "LOOTED");
|
||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
|
||||
if (toolStats.config.getBoolean("enabled.elytra-tag")) {
|
||||
meta.setLore(newLore);
|
||||
|
||||
@@ -157,9 +157,10 @@ public class PlayerFish implements Listener {
|
||||
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
|
||||
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate, "FISHED");
|
||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
|
||||
if (toolStats.checkConfig(newItem, "fished-tag")) {
|
||||
meta.setLore(newLore);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
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;
|
||||
@@ -31,6 +30,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.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -63,7 +63,13 @@ public class PlayerInteract implements Listener {
|
||||
// store when a player opens a chest
|
||||
if (block.getType() != Material.AIR && block.getType() == Material.CHEST) {
|
||||
openedChests.put(block, player);
|
||||
Bukkit.getScheduler().runTaskLater(toolStats, () -> openedChests.remove(block), 20);
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
openedChests.remove(block);
|
||||
}
|
||||
};
|
||||
toolStats.scheduleGlobal(runnable, 20);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +84,13 @@ public class PlayerInteract implements Listener {
|
||||
if (clicked.getType() == EntityType.MINECART_CHEST) {
|
||||
StorageMinecart storageMinecart = (StorageMinecart) clicked;
|
||||
openedMineCarts.put(storageMinecart, player);
|
||||
Bukkit.getScheduler().runTaskLater(toolStats, () -> openedMineCarts.remove(storageMinecart), 20);
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
openedMineCarts.remove(storageMinecart);
|
||||
}
|
||||
};
|
||||
toolStats.scheduleGlobal(runnable, 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
83
src/main/java/lol/hyper/toolstats/events/PlayerJoin.java
Normal file
83
src/main/java/lol/hyper/toolstats/events/PlayerJoin.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class PlayerJoin implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public PlayerJoin(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
Inventory inventory = player.getInventory();
|
||||
for (ItemStack itemStack : inventory) {
|
||||
if (itemStack == null) {
|
||||
continue;
|
||||
}
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
if (itemMeta == null) {
|
||||
continue;
|
||||
}
|
||||
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||
// ignore any items that already have the origin tag
|
||||
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
||||
continue;
|
||||
}
|
||||
// ignore items that are not the right type
|
||||
if (!ItemChecker.isValidItem(itemStack.getType())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemMeta newMeta = toolStats.itemLore.getOrigin(itemMeta, itemStack.getType() == Material.ELYTRA);
|
||||
if (newMeta == null) {
|
||||
continue;
|
||||
}
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
itemStack.setItemMeta(newMeta);
|
||||
}
|
||||
};
|
||||
Location location = inventory.getLocation();
|
||||
// only run for actual inventories
|
||||
if (location != null) {
|
||||
toolStats.scheduleRegion(runnable, location.getWorld(), location.getChunk(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,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.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -109,9 +108,10 @@ public class VillagerTrade implements Listener {
|
||||
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
|
||||
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate, "TRADED");
|
||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
|
||||
if (toolStats.checkConfig(newItem, "traded-tag")) {
|
||||
meta.setLore(newLore);
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.Locale;
|
||||
|
||||
public class ItemChecker {
|
||||
|
||||
private static final String[] validItems = { "pickaxe", "sword", "shovel", "axe", "hoe", "bow", "helmet", "chestplate", "leggings", "boots", "fishing" };
|
||||
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" };
|
||||
|
||||
@@ -19,11 +19,11 @@ package lol.hyper.toolstats.tools;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ItemLore {
|
||||
|
||||
@@ -58,22 +58,18 @@ public class ItemLore {
|
||||
|
||||
if (itemMeta.hasLore()) {
|
||||
newLore = itemMeta.getLore();
|
||||
boolean hasLore = false;
|
||||
// keep track of line index
|
||||
// this doesn't mess the lore of existing items
|
||||
for (int x = 0; x < newLore.size(); x++) {
|
||||
// check to see if the line matches the config value
|
||||
// this means we update this line only!
|
||||
if (newLore.get(x).contains(configLore)) {
|
||||
hasLore = true;
|
||||
newLore.set(x, newLine);
|
||||
break;
|
||||
return newLore;
|
||||
}
|
||||
}
|
||||
// if the item has lore but doesn't have our line, add it
|
||||
if (!hasLore) {
|
||||
newLore.add(newLine);
|
||||
}
|
||||
// if the item has lore, but we didn't find the line
|
||||
newLore.add(newLine);
|
||||
} else {
|
||||
// if the item has no lore, create a new list and add the line
|
||||
newLore = new ArrayList<>();
|
||||
@@ -88,38 +84,46 @@ public class ItemLore {
|
||||
* @param itemMeta The item meta.
|
||||
* @param playerName The new owner of item.
|
||||
* @param formattedDate The date of the ownership.
|
||||
* @param type The type of new ownership.
|
||||
* @return The item's new lore.
|
||||
*/
|
||||
public List<String> addNewOwner(ItemMeta itemMeta, String playerName, String formattedDate, String type) {
|
||||
public List<String> addNewOwner(ItemMeta itemMeta, String playerName, String formattedDate) {
|
||||
String dateCreated = null;
|
||||
String itemOwner = null;
|
||||
switch (type) {
|
||||
case "LOOTED": {
|
||||
Integer origin = null;
|
||||
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
||||
origin = container.get(toolStats.originType, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
if (origin == null) {
|
||||
origin = -1;
|
||||
}
|
||||
|
||||
switch (origin) {
|
||||
case 2: {
|
||||
dateCreated = toolStats.getLoreFromConfig("looted.looted-on", true);
|
||||
itemOwner = toolStats.getLoreFromConfig("looted.looted-by", true);
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
dateCreated = toolStats.getLoreFromConfig("traded.traded-on", true);
|
||||
itemOwner = toolStats.getLoreFromConfig("traded.traded-by", true);
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
dateCreated = toolStats.getLoreFromConfig("looted.found-on", true);
|
||||
itemOwner = toolStats.getLoreFromConfig("looted.found-by", true);
|
||||
break;
|
||||
}
|
||||
case "CREATED": {
|
||||
dateCreated = toolStats.getLoreFromConfig("created.created-on", true);
|
||||
itemOwner = toolStats.getLoreFromConfig("created.created-by", true);
|
||||
break;
|
||||
}
|
||||
case "FISHED": {
|
||||
case 5: {
|
||||
dateCreated = toolStats.getLoreFromConfig("fished.caught-on", true);
|
||||
itemOwner = toolStats.getLoreFromConfig("fished.caught-by", true);
|
||||
break;
|
||||
}
|
||||
case "TRADED": {
|
||||
dateCreated = toolStats.getLoreFromConfig("traded.traded-on", true);
|
||||
itemOwner = toolStats.getLoreFromConfig("traded.traded-by", true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (dateCreated == null || itemOwner == null) {
|
||||
toolStats.logger.warning("There is no lore message for messages." + type.toLowerCase(Locale.ENGLISH) + "!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
toolStats.logger.info("Unable to determine origin of item for " + itemMeta);
|
||||
return itemMeta.getLore();
|
||||
}
|
||||
|
||||
@@ -134,4 +138,63 @@ public class ItemLore {
|
||||
newLore.add(itemOwner.replace("{player}", playerName));
|
||||
return newLore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine an item's origin based on lore.
|
||||
*
|
||||
* @param itemMeta The item's meta.
|
||||
* @param elytra If they item is an elytra.
|
||||
* @return The new item meta with the new origin tag. Returns null if origin cannot be determined.
|
||||
*/
|
||||
public ItemMeta getOrigin(ItemMeta itemMeta, boolean elytra) {
|
||||
List<String> lore;
|
||||
if (!itemMeta.hasLore()) {
|
||||
return null;
|
||||
}
|
||||
lore = itemMeta.getLore();
|
||||
Integer origin = null;
|
||||
|
||||
for (String line : lore) {
|
||||
// this is the worst code I have ever written
|
||||
String createdBy = toolStats.getLoreFromConfig("created.created-by", false);
|
||||
String createdOn = toolStats.getLoreFromConfig("created.created-on", false);
|
||||
String caughtBy = toolStats.getLoreFromConfig("fished.caught-by", false);
|
||||
String lootedBy = toolStats.getLoreFromConfig("looted.looted-by", false);
|
||||
String foundBy = toolStats.getLoreFromConfig("looted.found-by", false);
|
||||
String tradedBy = toolStats.getLoreFromConfig("traded.traded-by", false);
|
||||
|
||||
if (createdBy != null && line.contains(createdBy)) {
|
||||
origin = 0;
|
||||
}
|
||||
if (createdOn != null && line.contains(createdOn)) {
|
||||
origin = 0;
|
||||
}
|
||||
if (caughtBy != null && line.contains(caughtBy)) {
|
||||
origin = 5;
|
||||
}
|
||||
if (lootedBy != null && line.contains(lootedBy)) {
|
||||
origin = 2;
|
||||
}
|
||||
// because the config changed, "found-by" was being used for ALL looted items
|
||||
// this includes elytras, so we have to check for this mistake
|
||||
if (foundBy != null && line.contains(foundBy)) {
|
||||
if (elytra) {
|
||||
origin = 4;
|
||||
} else {
|
||||
origin = 5;
|
||||
}
|
||||
}
|
||||
if (tradedBy != null && line.contains(tradedBy)) {
|
||||
origin = 3;
|
||||
}
|
||||
}
|
||||
|
||||
if (origin == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, origin);
|
||||
return itemMeta;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,8 @@ messages:
|
||||
caught-on: "&7Caught on: &8{date}"
|
||||
fish-caught: "&7Fish caught: &8{fish}"
|
||||
looted:
|
||||
looted-by: "&7Looted by: &8{player}"
|
||||
looted-on: "&7Looted on: &8{date}"
|
||||
found-by: "&7Found by: &8{player}"
|
||||
found-on: "&7Found on: &8{date}"
|
||||
traded:
|
||||
@@ -111,4 +113,4 @@ number-formats:
|
||||
comma-format: "#,###"
|
||||
decimal-format: "#,###.00"
|
||||
|
||||
config-version: 4
|
||||
config-version: 5
|
||||
@@ -4,6 +4,7 @@ main: lol.hyper.toolstats.ToolStats
|
||||
api-version: 1.15
|
||||
author: hyperdefined
|
||||
description: Track various tool stats!
|
||||
folia-supported: true
|
||||
commands:
|
||||
toolstats:
|
||||
usage: /toolstats
|
||||
|
||||
Reference in New Issue
Block a user