From 1addc326db0be709131a75fd8455002171018ef8 Mon Sep 17 00:00:00 2001 From: isokissa3 Date: Tue, 11 Dec 2018 02:04:02 +0200 Subject: [PATCH] PotionEffect hasParticles not supported on 1.7 --- .../utils/SupportedFeatures.java | 11 +++++++++++ .../wg/handlers/BlockedEffectsFlagHandler.java | 12 ++++++++++-- .../wg/handlers/GiveEffectsFlagHandler.java | 14 +++++++++++--- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/utils/SupportedFeatures.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/utils/SupportedFeatures.java index e5fe541..2a4f1f5 100644 --- a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/utils/SupportedFeatures.java +++ b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/utils/SupportedFeatures.java @@ -5,6 +5,7 @@ import java.awt.Color; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityPotionEffectEvent; +import org.bukkit.potion.PotionEffect; import lombok.Getter; @@ -16,6 +17,7 @@ public class SupportedFeatures @Getter private static boolean frostwalkerSupported; @Getter private static boolean stopSoundSupported; @Getter private static boolean potionEffectEventSupported; + @Getter private static boolean potionEffectParticles; static { @@ -42,5 +44,14 @@ public class SupportedFeatures catch (Throwable ignored) { } + + try + { + SupportedFeatures.potionEffectParticles = PotionEffect.class.getDeclaredMethod("hasParticles") != null; + } + catch(Throwable ignored) + { + + } } } diff --git a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/BlockedEffectsFlagHandler.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/BlockedEffectsFlagHandler.java index 73c911f..b48e922 100644 --- a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/BlockedEffectsFlagHandler.java +++ b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/BlockedEffectsFlagHandler.java @@ -19,6 +19,7 @@ import com.sk89q.worldguard.session.Session; import net.goldtreeservers.worldguardextraflags.flags.Flags; import net.goldtreeservers.worldguardextraflags.flags.data.PotionEffectDetails; +import net.goldtreeservers.worldguardextraflags.utils.SupportedFeatures; import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils; import net.goldtreeservers.worldguardextraflags.wg.wrappers.HandlerWrapper; @@ -91,7 +92,7 @@ public class BlockedEffectsFlagHandler extends HandlerWrapper if (effect != null) { - this.removedEffects.put(effect.getType(), new PotionEffectDetails(System.nanoTime() + (long)(effect.getDuration() / 20D * TimeUnit.SECONDS.toNanos(1L)), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles())); + this.removedEffects.put(effect.getType(), new PotionEffectDetails(System.nanoTime() + (long)(effect.getDuration() / 20D * TimeUnit.SECONDS.toNanos(1L)), effect.getAmplifier(), effect.isAmbient(), SupportedFeatures.isPotionEffectParticles() ? effect.hasParticles() : true)); player.removePotionEffect(effectType); } @@ -111,7 +112,14 @@ public class BlockedEffectsFlagHandler extends HandlerWrapper int timeLeft = removedEffect.getTimeLeftInTicks(); if (timeLeft > 0) { - player.addPotionEffect(new PotionEffect(potionEffect.getKey(), timeLeft, removedEffect.getAmplifier(), removedEffect.isAmbient(), removedEffect.isParticles()), true); + if (SupportedFeatures.isPotionEffectParticles()) + { + player.addPotionEffect(new PotionEffect(potionEffect.getKey(), timeLeft, removedEffect.getAmplifier(), removedEffect.isAmbient(), removedEffect.isParticles()), true); + } + else + { + player.addPotionEffect(new PotionEffect(potionEffect.getKey(), timeLeft, removedEffect.getAmplifier(), removedEffect.isAmbient()), true); + } } } diff --git a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/GiveEffectsFlagHandler.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/GiveEffectsFlagHandler.java index 4763a2c..028221e 100644 --- a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/GiveEffectsFlagHandler.java +++ b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/GiveEffectsFlagHandler.java @@ -23,6 +23,7 @@ import com.sk89q.worldguard.session.Session; import lombok.Getter; import net.goldtreeservers.worldguardextraflags.flags.Flags; import net.goldtreeservers.worldguardextraflags.flags.data.PotionEffectDetails; +import net.goldtreeservers.worldguardextraflags.utils.SupportedFeatures; import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils; import net.goldtreeservers.worldguardextraflags.wg.wrappers.HandlerWrapper; @@ -105,7 +106,7 @@ public class GiveEffectsFlagHandler extends HandlerWrapper if (this.givenEffects.add(effect.getType()) && effect_ != null) { - this.removedEffects.put(effect_.getType(), new PotionEffectDetails(System.nanoTime() + (long)(effect_.getDuration() / 20D * TimeUnit.SECONDS.toNanos(1L)), effect_.getAmplifier(), effect_.isAmbient(), effect_.hasParticles())); + this.removedEffects.put(effect_.getType(), new PotionEffectDetails(System.nanoTime() + (long)(effect_.getDuration() / 20D * TimeUnit.SECONDS.toNanos(1L)), effect_.getAmplifier(), effect_.isAmbient(), SupportedFeatures.isPotionEffectParticles() ? effect_.hasParticles() : true)); player.removePotionEffect(effect_.getType()); } @@ -160,7 +161,14 @@ public class GiveEffectsFlagHandler extends HandlerWrapper if (timeLeft > 0) { - player.addPotionEffect(new PotionEffect(effect.getKey(), timeLeft, removedEffect.getAmplifier(), removedEffect.isAmbient(), removedEffect.isParticles()), true); + if (SupportedFeatures.isPotionEffectParticles()) + { + player.addPotionEffect(new PotionEffect(effect.getKey(), timeLeft, removedEffect.getAmplifier(), removedEffect.isAmbient(), removedEffect.isParticles()), true); + } + else + { + player.addPotionEffect(new PotionEffect(effect.getKey(), timeLeft, removedEffect.getAmplifier(), removedEffect.isAmbient()), true); + } } } @@ -180,7 +188,7 @@ public class GiveEffectsFlagHandler extends HandlerWrapper { for(PotionEffect effect : effects) { - this.removedEffects.put(effect.getType(), new PotionEffectDetails(System.nanoTime() + (long)(effect.getDuration() / 20D * TimeUnit.SECONDS.toNanos(1L)), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles())); + this.removedEffects.put(effect.getType(), new PotionEffectDetails(System.nanoTime() + (long)(effect.getDuration() / 20D * TimeUnit.SECONDS.toNanos(1L)), effect.getAmplifier(), effect.isAmbient(), SupportedFeatures.isPotionEffectParticles() ? effect.hasParticles() : true)); } this.check(player, WorldGuardUtils.getCommunicator().getRegionContainer().createQuery().getApplicableRegions(player.getLocation()));