Add Folia support (#3)

* Add Folia support

* Minor perf tweaks: cache negative smelting lookups, avoid boxed Long in cloaking tracker

* Bump version to 1.15.2

* Simplify smelting cache lookup back to containsKey-first

* maintainer

Co-authored-by: YouHaveTrouble <garrenpolska@gmail.com>

---------

Co-authored-by: YouHaveTrouble <youhavetrouble@youhavetrouble.me>
This commit is contained in:
Josiah Royal
2026-07-26 17:28:08 -04:00
committed by GitHub
parent 08ea6355fa
commit 85585b14d6
6 changed files with 33 additions and 25 deletions
+1 -1
View File
@@ -15,7 +15,7 @@
<properties>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<revision>1.15.1</revision>
<revision>1.15.2</revision>
</properties>
<url>https://youhavetrouble.me</url>
@@ -26,7 +26,7 @@ import java.util.UUID;
public class CloakingListener implements Listener {
private final HashMap<UUID, Long> ticksSinceLastMovement = new HashMap<>();
private final HashMap<UUID, Integer> ticksSinceLastMovement = new HashMap<>();
private final CloakingEnchant cloakingEnchant = (CloakingEnchant) EnchantioConfig.ENCHANTS.get(CloakingEnchant.KEY);
private final PotionEffect cloakingEffect = new PotionEffect(PotionEffectType.INVISIBILITY, 3, 0, false, false, false);
@@ -40,13 +40,13 @@ public class CloakingListener implements Listener {
Bukkit.getGlobalRegionScheduler().runAtFixedRate(enchantio, (task) -> {
for (Player player : Bukkit.getOnlinePlayers()) {
if (!player.isSneaking()) {
ticksSinceLastMovement.put(player.getUniqueId(), 0L);
ticksSinceLastMovement.put(player.getUniqueId(), 0);
continue;
}
int cloakingLevel = Enchantio.getSumOfEnchantLevels(player.getEquipment(), cloaking);
if (cloakingLevel == 0) continue;
ticksSinceLastMovement.computeIfPresent(player.getUniqueId(), (uuid, ticks) -> ticks + 1);
if (ticksSinceLastMovement.getOrDefault(player.getUniqueId(), 0L) < cloakingEnchant.getTicksToActivate()) continue;
if (ticksSinceLastMovement.getOrDefault(player.getUniqueId(), 0) < cloakingEnchant.getTicksToActivate()) continue;
player.getScheduler().execute(enchantio, () -> player.addPotionEffect(cloakingEffect), () -> {}, 1);
}
}, 1, 1);
@@ -54,7 +54,7 @@ public class CloakingListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
ticksSinceLastMovement.put(event.getPlayer().getUniqueId(), 0L);
ticksSinceLastMovement.put(event.getPlayer().getUniqueId(), 0);
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
@@ -65,17 +65,17 @@ public class CloakingListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerMove(PlayerMoveEvent event) {
if (!event.hasChangedPosition()) return;
ticksSinceLastMovement.put(event.getPlayer().getUniqueId(), 0L);
ticksSinceLastMovement.put(event.getPlayer().getUniqueId(), 0);
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerJump(PlayerJumpEvent event) {
ticksSinceLastMovement.put(event.getPlayer().getUniqueId(), 0L);
ticksSinceLastMovement.put(event.getPlayer().getUniqueId(), 0);
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerInteract(PlayerInteractEvent event) {
ticksSinceLastMovement.put(event.getPlayer().getUniqueId(), 0L);
ticksSinceLastMovement.put(event.getPlayer().getUniqueId(), 0);
}
@@ -60,6 +60,7 @@ public class SmeltingListener implements Listener {
smeltingCache.put(singleItem, result);
return result;
}
smeltingCache.put(singleItem, null);
return null;
}
@@ -6,7 +6,6 @@ import io.papermc.paper.registry.RegistryKey;
import me.youhavetrouble.enchantio.Enchantio;
import me.youhavetrouble.enchantio.EnchantioConfig;
import me.youhavetrouble.enchantio.enchants.TelepathyEnchant;
import org.bukkit.Bukkit;
import org.bukkit.Registry;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Item;
@@ -36,10 +35,14 @@ public class TelepathyListener implements Listener {
}
// If there's ever a performance problem here, it's the following
Bukkit.getScheduler().runTask(Enchantio.getPlugin(Enchantio.class), () -> event.getItems().forEach((item) -> {
if (item == null || item.isDead()) return;
Enchantio enchantio = Enchantio.getPlugin(Enchantio.class);
event.getItems().forEach((item) -> {
if (item == null) return;
item.getScheduler().run(enchantio, (task) -> {
if (item.isDead()) return;
item.teleport(event.getPlayer(), PlayerTeleportEvent.TeleportCause.PLUGIN);
}));
}, null);
});
}
}
@@ -19,10 +19,12 @@ public class VampirismListener implements Listener {
public VampirismListener() {
if (vampirism == null) return;
Bukkit.getGlobalRegionScheduler().runAtFixedRate(Enchantio.getPlugin(Enchantio.class), (task) -> {
Enchantio enchantio = Enchantio.getPlugin(Enchantio.class);
Bukkit.getGlobalRegionScheduler().runAtFixedRate(enchantio, (task) -> {
for (Player player : Bukkit.getOnlinePlayers()) {
boolean hasVampirism = Enchantio.getSumOfEnchantLevels(player.getEquipment(), vampirism) != 0;
if (!hasVampirism) return;
if (!hasVampirism) continue;
player.getScheduler().execute(enchantio, () -> {
Location abovePlayer = player.getLocation().add(0, player.getEyeHeight() + 0.5, 0);
Block block = player.getWorld().getBlockAt(abovePlayer);
byte light = block.getLightFromSky();
@@ -35,6 +37,7 @@ public class VampirismListener implements Listener {
}
player.setFireTicks(Math.max(fireTicks, player.getMaxFireTicks()));
}, () -> {}, 0);
}
}, 1, 20);
+1
View File
@@ -3,6 +3,7 @@ version: '${project.version}'
main: me.youhavetrouble.enchantio.Enchantio
bootstrapper: me.youhavetrouble.enchantio.EnchantioBootstrap
api-version: '1.21.9'
folia-supported: true
authors: [YouHaveTrouble]
description: Custom enchants for paper servers
website: https://youhavetrouble.me