mirror of
https://github.com/YouHaveTrouble/Enchantio.git
synced 2026-08-27 23:46:41 +00:00
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:
@@ -15,7 +15,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<java.version>21</java.version>
|
<java.version>21</java.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<revision>1.15.1</revision>
|
<revision>1.15.2</revision>
|
||||||
</properties>
|
</properties>
|
||||||
<url>https://youhavetrouble.me</url>
|
<url>https://youhavetrouble.me</url>
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class CloakingListener implements Listener {
|
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 CloakingEnchant cloakingEnchant = (CloakingEnchant) EnchantioConfig.ENCHANTS.get(CloakingEnchant.KEY);
|
||||||
private final PotionEffect cloakingEffect = new PotionEffect(PotionEffectType.INVISIBILITY, 3, 0, false, false, false);
|
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) -> {
|
Bukkit.getGlobalRegionScheduler().runAtFixedRate(enchantio, (task) -> {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if (!player.isSneaking()) {
|
if (!player.isSneaking()) {
|
||||||
ticksSinceLastMovement.put(player.getUniqueId(), 0L);
|
ticksSinceLastMovement.put(player.getUniqueId(), 0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int cloakingLevel = Enchantio.getSumOfEnchantLevels(player.getEquipment(), cloaking);
|
int cloakingLevel = Enchantio.getSumOfEnchantLevels(player.getEquipment(), cloaking);
|
||||||
if (cloakingLevel == 0) continue;
|
if (cloakingLevel == 0) continue;
|
||||||
ticksSinceLastMovement.computeIfPresent(player.getUniqueId(), (uuid, ticks) -> ticks + 1);
|
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);
|
player.getScheduler().execute(enchantio, () -> player.addPotionEffect(cloakingEffect), () -> {}, 1);
|
||||||
}
|
}
|
||||||
}, 1, 1);
|
}, 1, 1);
|
||||||
@@ -54,7 +54,7 @@ public class CloakingListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
ticksSinceLastMovement.put(event.getPlayer().getUniqueId(), 0L);
|
ticksSinceLastMovement.put(event.getPlayer().getUniqueId(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
@@ -65,17 +65,17 @@ public class CloakingListener implements Listener {
|
|||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
if (!event.hasChangedPosition()) return;
|
if (!event.hasChangedPosition()) return;
|
||||||
ticksSinceLastMovement.put(event.getPlayer().getUniqueId(), 0L);
|
ticksSinceLastMovement.put(event.getPlayer().getUniqueId(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
public void onPlayerJump(PlayerJumpEvent event) {
|
public void onPlayerJump(PlayerJumpEvent event) {
|
||||||
ticksSinceLastMovement.put(event.getPlayer().getUniqueId(), 0L);
|
ticksSinceLastMovement.put(event.getPlayer().getUniqueId(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
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);
|
smeltingCache.put(singleItem, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
smeltingCache.put(singleItem, null);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import io.papermc.paper.registry.RegistryKey;
|
|||||||
import me.youhavetrouble.enchantio.Enchantio;
|
import me.youhavetrouble.enchantio.Enchantio;
|
||||||
import me.youhavetrouble.enchantio.EnchantioConfig;
|
import me.youhavetrouble.enchantio.EnchantioConfig;
|
||||||
import me.youhavetrouble.enchantio.enchants.TelepathyEnchant;
|
import me.youhavetrouble.enchantio.enchants.TelepathyEnchant;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Registry;
|
import org.bukkit.Registry;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Item;
|
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
|
// If there's ever a performance problem here, it's the following
|
||||||
Bukkit.getScheduler().runTask(Enchantio.getPlugin(Enchantio.class), () -> event.getItems().forEach((item) -> {
|
Enchantio enchantio = Enchantio.getPlugin(Enchantio.class);
|
||||||
if (item == null || item.isDead()) return;
|
event.getItems().forEach((item) -> {
|
||||||
item.teleport(event.getPlayer(), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
if (item == null) return;
|
||||||
}));
|
item.getScheduler().run(enchantio, (task) -> {
|
||||||
|
if (item.isDead()) return;
|
||||||
|
item.teleport(event.getPlayer(), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||||
|
}, null);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,22 +19,25 @@ public class VampirismListener implements Listener {
|
|||||||
|
|
||||||
public VampirismListener() {
|
public VampirismListener() {
|
||||||
if (vampirism == null) return;
|
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()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
boolean hasVampirism = Enchantio.getSumOfEnchantLevels(player.getEquipment(), vampirism) != 0;
|
boolean hasVampirism = Enchantio.getSumOfEnchantLevels(player.getEquipment(), vampirism) != 0;
|
||||||
if (!hasVampirism) return;
|
if (!hasVampirism) continue;
|
||||||
Location abovePlayer = player.getLocation().add(0, player.getEyeHeight() + 0.5, 0);
|
player.getScheduler().execute(enchantio, () -> {
|
||||||
Block block = player.getWorld().getBlockAt(abovePlayer);
|
Location abovePlayer = player.getLocation().add(0, player.getEyeHeight() + 0.5, 0);
|
||||||
byte light = block.getLightFromSky();
|
Block block = player.getWorld().getBlockAt(abovePlayer);
|
||||||
if (light < 15) return;
|
byte light = block.getLightFromSky();
|
||||||
int fireTicks = player.getFireTicks();
|
if (light < 15) return;
|
||||||
|
int fireTicks = player.getFireTicks();
|
||||||
|
|
||||||
// Prefent fire animation from disappearing on the client
|
// Prefent fire animation from disappearing on the client
|
||||||
if (player.getFireTicks() < 20) {
|
if (player.getFireTicks() < 20) {
|
||||||
fireTicks = 25;
|
fireTicks = 25;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.setFireTicks(Math.max(fireTicks, player.getMaxFireTicks()));
|
player.setFireTicks(Math.max(fireTicks, player.getMaxFireTicks()));
|
||||||
|
}, () -> {}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}, 1, 20);
|
}, 1, 20);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ version: '${project.version}'
|
|||||||
main: me.youhavetrouble.enchantio.Enchantio
|
main: me.youhavetrouble.enchantio.Enchantio
|
||||||
bootstrapper: me.youhavetrouble.enchantio.EnchantioBootstrap
|
bootstrapper: me.youhavetrouble.enchantio.EnchantioBootstrap
|
||||||
api-version: '1.21.9'
|
api-version: '1.21.9'
|
||||||
|
folia-supported: true
|
||||||
authors: [YouHaveTrouble]
|
authors: [YouHaveTrouble]
|
||||||
description: Custom enchants for paper servers
|
description: Custom enchants for paper servers
|
||||||
website: https://youhavetrouble.me
|
website: https://youhavetrouble.me
|
||||||
|
|||||||
Reference in New Issue
Block a user