mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
basic folia support
This commit is contained in:
14
pom.xml
14
pom.xml
@@ -75,6 +75,10 @@
|
|||||||
<pattern>lol.hyper.githubreleaseapi</pattern>
|
<pattern>lol.hyper.githubreleaseapi</pattern>
|
||||||
<shadedPattern>lol.hyper.toolstats.updater</shadedPattern>
|
<shadedPattern>lol.hyper.toolstats.updater</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>space.arim.morepaperlib</pattern>
|
||||||
|
<shadedPattern>lol.hyper.toolstats.morepaperlib</shadedPattern>
|
||||||
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
@@ -103,6 +107,10 @@
|
|||||||
<id>spigotmc-repo</id>
|
<id>spigotmc-repo</id>
|
||||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>arim-mvn-lgpl3</id>
|
||||||
|
<url>https://mvn-repo.arim.space/lesser-gpl3/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -136,5 +144,11 @@
|
|||||||
<version>4.3.0</version>
|
<version>4.3.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>space.arim.morepaperlib</groupId>
|
||||||
|
<artifactId>morepaperlib</artifactId>
|
||||||
|
<version>0.4.3</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -25,13 +25,14 @@ import lol.hyper.toolstats.tools.ItemLore;
|
|||||||
import lol.hyper.toolstats.tools.NumberFormat;
|
import lol.hyper.toolstats.tools.NumberFormat;
|
||||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.*;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import space.arim.morepaperlib.MorePaperLib;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -112,11 +113,13 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
public final int CONFIG_VERSION = 5;
|
public final int CONFIG_VERSION = 5;
|
||||||
|
|
||||||
private BukkitAudiences adventure;
|
private BukkitAudiences adventure;
|
||||||
|
public MorePaperLib morePaperLib;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
this.adventure = BukkitAudiences.create(this);
|
this.adventure = BukkitAudiences.create(this);
|
||||||
|
morePaperLib = new MorePaperLib(this);
|
||||||
if (!configFile.exists()) {
|
if (!configFile.exists()) {
|
||||||
this.saveResource("config.yml", true);
|
this.saveResource("config.yml", true);
|
||||||
logger.info("Copying default config!");
|
logger.info("Copying default config!");
|
||||||
@@ -154,7 +157,7 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
|
|
||||||
new Metrics(this, 14110);
|
new Metrics(this, 14110);
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(this, this::checkForUpdates);
|
morePaperLib.scheduling().asyncScheduler().run(this::checkForUpdates);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadConfig() {
|
public void loadConfig() {
|
||||||
@@ -305,4 +308,27 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
return this.adventure;
|
return this.adventure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void scheduleEntity(BukkitRunnable runnable, Entity entity, int delay) {
|
||||||
|
if (Bukkit.getServer().getVersion().contains("Folia")) {
|
||||||
|
morePaperLib.scheduling().entitySpecificScheduler(entity).runDelayed(runnable, null, delay);
|
||||||
|
} else {
|
||||||
|
runnable.runTaskLater(this, delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void scheduleGlobal(BukkitRunnable runnable, int delay) {
|
||||||
|
if (Bukkit.getServer().getVersion().contains("Folia")) {
|
||||||
|
morePaperLib.scheduling().globalRegionalScheduler().runDelayed(runnable, delay);
|
||||||
|
} else {
|
||||||
|
runnable.runTaskLater(this, delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void scheduleRegion(BukkitRunnable runnable, World world, Chunk chunk, int delay) {
|
||||||
|
if (Bukkit.getServer().getVersion().contains("Folia")) {
|
||||||
|
morePaperLib.scheduling().regionSpecificScheduler(world, chunk.getX(), chunk.getZ()).runDelayed(runnable, delay);
|
||||||
|
} else {
|
||||||
|
runnable.runTaskLater(this, delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
public class ChunkPopulate implements Listener {
|
public class ChunkPopulate implements Listener {
|
||||||
|
|
||||||
@@ -51,28 +52,32 @@ public class ChunkPopulate implements Listener {
|
|||||||
}
|
}
|
||||||
// this is delayed because entities are not loaded instantly
|
// this is delayed because entities are not loaded instantly
|
||||||
// we just check 1 second later
|
// we just check 1 second later
|
||||||
Bukkit.getScheduler().runTaskLater(toolStats, () -> {
|
Chunk chunk = event.getChunk();
|
||||||
Chunk chunk = event.getChunk();
|
BukkitRunnable runnable = new BukkitRunnable() {
|
||||||
for (Entity entity : chunk.getEntities()) {
|
@Override
|
||||||
// if there is a new item frame
|
public void run() {
|
||||||
if (!(entity instanceof ItemFrame)) {
|
for (Entity entity : chunk.getEntities()) {
|
||||||
continue;
|
// if there is a new item frame
|
||||||
}
|
if (!(entity instanceof ItemFrame)) {
|
||||||
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;
|
continue;
|
||||||
}
|
}
|
||||||
// add the new tag so we know it's new
|
ItemFrame itemFrame = (ItemFrame) entity;
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
// if the item frame has an elytra
|
||||||
container.set(toolStats.newElytra, PersistentDataType.INTEGER, 1);
|
if (itemFrame.getItem().getType() == Material.ELYTRA) {
|
||||||
elytraCopy.setItemMeta(meta);
|
ItemStack elytraCopy = itemFrame.getItem();
|
||||||
itemFrame.setItem(elytraCopy);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 20);
|
};
|
||||||
|
toolStats.scheduleRegion(runnable, chunk.getWorld(), chunk, 20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -77,26 +78,29 @@ public class GenerateLoot implements Listener {
|
|||||||
return;
|
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;
|
Block finalOpenedChest = openedChest;
|
||||||
Bukkit.getScheduler().runTaskLater(toolStats, () -> {
|
BukkitRunnable runnable = new BukkitRunnable() {
|
||||||
Player player = toolStats.playerInteract.openedChests.get(finalOpenedChest);
|
@Override
|
||||||
// do a classic for loop, so we keep track of chest index of item
|
public void run() {
|
||||||
for (int i = 0; i < chestInv.getContents().length; i++) {
|
Player player = toolStats.playerInteract.openedChests.get(finalOpenedChest);
|
||||||
ItemStack itemStack = chestInv.getItem(i);
|
// keep track of chest index of item
|
||||||
// ignore air
|
for (int i = 0; i < chestInv.getContents().length; i++) {
|
||||||
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
ItemStack itemStack = chestInv.getItem(i);
|
||||||
continue;
|
// ignore air
|
||||||
}
|
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
||||||
if (ItemChecker.isValidItem(itemStack.getType())) {
|
continue;
|
||||||
ItemStack newItem = addLore(itemStack, player);
|
}
|
||||||
if (newItem != null) {
|
if (ItemChecker.isValidItem(itemStack.getType())) {
|
||||||
chestInv.setItem(i, newItem);
|
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) {
|
if (inventoryHolder instanceof StorageMinecart) {
|
||||||
StorageMinecart mineCart = (StorageMinecart) inventoryHolder;
|
StorageMinecart mineCart = (StorageMinecart) inventoryHolder;
|
||||||
|
|||||||
@@ -21,14 +21,17 @@ import lol.hyper.toolstats.ToolStats;
|
|||||||
import lol.hyper.toolstats.tools.ItemChecker;
|
import lol.hyper.toolstats.tools.ItemChecker;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -46,33 +49,39 @@ public class InventoryOpen implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(toolStats, ()-> {
|
Player player = (Player) event.getPlayer();
|
||||||
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 = getOrigin(itemMeta, itemStack.getType() == Material.ELYTRA);
|
Inventory inventory = event.getInventory();
|
||||||
if (newMeta == null) {
|
for (ItemStack itemStack : inventory) {
|
||||||
continue;
|
if (itemStack == null) {
|
||||||
}
|
continue;
|
||||||
itemStack.setItemMeta(newMeta);
|
|
||||||
}
|
}
|
||||||
},1);
|
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 = getOrigin(itemMeta, itemStack.getType() == Material.ELYTRA);
|
||||||
|
if (newMeta == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BukkitRunnable runnable = new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
itemStack.setItemMeta(newMeta);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
toolStats.scheduleEntity(runnable, player, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,11 +102,11 @@ public class InventoryOpen implements Listener {
|
|||||||
for (String line : lore) {
|
for (String line : lore) {
|
||||||
// this is the worst code I have ever written
|
// this is the worst code I have ever written
|
||||||
String createdBy = toolStats.getLoreFromConfig("created.created-by", false);
|
String createdBy = toolStats.getLoreFromConfig("created.created-by", false);
|
||||||
String createdOn = toolStats.getLoreFromConfig("created.created-by", false);
|
String createdOn = toolStats.getLoreFromConfig("created.created-on", false);
|
||||||
String caughtBy = toolStats.getLoreFromConfig("created.created-by", false);
|
String caughtBy = toolStats.getLoreFromConfig("fished.caught-by", false);
|
||||||
String lootedBy = toolStats.getLoreFromConfig("created.created-by", false);
|
String lootedBy = toolStats.getLoreFromConfig("looted.looted-by", false);
|
||||||
String foundBy = toolStats.getLoreFromConfig("created.created-by", false);
|
String foundBy = toolStats.getLoreFromConfig("looted.found-by", false);
|
||||||
String tradedBy = toolStats.getLoreFromConfig("created.created-by", false);
|
String tradedBy = toolStats.getLoreFromConfig("traded.traded-by", false);
|
||||||
|
|
||||||
if (createdBy != null && line.contains(createdBy)) {
|
if (createdBy != null && line.contains(createdBy)) {
|
||||||
origin = 0;
|
origin = 0;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@@ -63,7 +64,13 @@ public class PlayerInteract implements Listener {
|
|||||||
// store when a player opens a chest
|
// store when a player opens a chest
|
||||||
if (block.getType() != Material.AIR && block.getType() == Material.CHEST) {
|
if (block.getType() != Material.AIR && block.getType() == Material.CHEST) {
|
||||||
openedChests.put(block, player);
|
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 +85,13 @@ public class PlayerInteract implements Listener {
|
|||||||
if (clicked.getType() == EntityType.MINECART_CHEST) {
|
if (clicked.getType() == EntityType.MINECART_CHEST) {
|
||||||
StorageMinecart storageMinecart = (StorageMinecart) clicked;
|
StorageMinecart storageMinecart = (StorageMinecart) clicked;
|
||||||
openedMineCarts.put(storageMinecart, player);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ main: lol.hyper.toolstats.ToolStats
|
|||||||
api-version: 1.15
|
api-version: 1.15
|
||||||
author: hyperdefined
|
author: hyperdefined
|
||||||
description: Track various tool stats!
|
description: Track various tool stats!
|
||||||
|
folia-supported: true
|
||||||
commands:
|
commands:
|
||||||
toolstats:
|
toolstats:
|
||||||
usage: /toolstats
|
usage: /toolstats
|
||||||
|
|||||||
Reference in New Issue
Block a user