mirror of
https://github.com/YouHaveTrouble/Enchantio.git
synced 2026-05-11 21:56:55 +00:00
fix cloaking activating without the enchant present
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.10.1</revision>
|
<revision>1.10.2</revision>
|
||||||
</properties>
|
</properties>
|
||||||
<url>https://youhavetrouble.me</url>
|
<url>https://youhavetrouble.me</url>
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
package me.youhavetrouble.enchantio.listeners;
|
package me.youhavetrouble.enchantio.listeners;
|
||||||
|
|
||||||
import com.destroystokyo.paper.event.player.PlayerJumpEvent;
|
import com.destroystokyo.paper.event.player.PlayerJumpEvent;
|
||||||
|
import io.papermc.paper.registry.RegistryAccess;
|
||||||
|
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.CloakingEnchant;
|
import me.youhavetrouble.enchantio.enchants.CloakingEnchant;
|
||||||
|
import me.youhavetrouble.enchantio.enchants.ExecutionerEnchant;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Registry;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@@ -26,7 +31,11 @@ public class CloakingListener implements Listener {
|
|||||||
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);
|
||||||
|
|
||||||
|
private final Registry<Enchantment> registry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT);
|
||||||
|
private final Enchantment cloaking = registry.get(CloakingEnchant.KEY);
|
||||||
|
|
||||||
public CloakingListener() {
|
public CloakingListener() {
|
||||||
|
if (cloaking == null) return;
|
||||||
Enchantio enchantio = Enchantio.getPlugin(Enchantio.class);
|
Enchantio enchantio = Enchantio.getPlugin(Enchantio.class);
|
||||||
Bukkit.getGlobalRegionScheduler().runAtFixedRate(enchantio, (task) -> {
|
Bukkit.getGlobalRegionScheduler().runAtFixedRate(enchantio, (task) -> {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
@@ -34,6 +43,8 @@ public class CloakingListener implements Listener {
|
|||||||
ticksSinceLastMovement.put(player.getUniqueId(), 0L);
|
ticksSinceLastMovement.put(player.getUniqueId(), 0L);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
int cloakingLevel = Enchantio.getSumOfEnchantLevels(player.getEquipment(), cloaking);
|
||||||
|
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(), 0L) < cloakingEnchant.getTicksToActivate()) continue;
|
||||||
player.getScheduler().execute(enchantio, () -> player.addPotionEffect(cloakingEffect), () -> {}, 1);
|
player.getScheduler().execute(enchantio, () -> player.addPotionEffect(cloakingEffect), () -> {}, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user