PotionEffect hasParticles not supported on 1.7

This commit is contained in:
isokissa3 2018-12-11 02:04:02 +02:00
parent 7d12cdb0e1
commit 1addc326db
3 changed files with 32 additions and 5 deletions

View file

@ -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)
{
}
}
}

View file

@ -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);
}
}
}

View file

@ -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()));