Do not show effect particles by default, allow overriding this

This commit is contained in:
isokissa3 2020-01-31 01:00:50 +02:00
parent d68263ac3a
commit 2df13dcc81

View file

@ -23,39 +23,51 @@ public class PotionEffectFlag extends Flag<PotionEffect>
@Override @Override
public Object marshal(PotionEffect o) public Object marshal(PotionEffect o)
{ {
return o.getType().getName() + " " + o.getAmplifier(); return o.getType().getName() + " " + o.getAmplifier() + " " + o.hasParticles();
} }
@Override @Override
public PotionEffect parseInput(FlagContext context) throws InvalidFlagFormat public PotionEffect parseInput(FlagContext context) throws InvalidFlagFormat
{ {
String[] splitd = context.getUserInput().trim().split(" "); String[] split = context.getUserInput().trim().split(" ");
if (splitd.length == 2) if (split.length < 1 || split.length > 3)
{ {
PotionEffectType potionEffect = PotionEffectType.getByName(splitd[0]); throw new InvalidFlagFormat("Please use the following format: <effect name> [effect amplifier] [show particles]");
if (potionEffect != null)
{
return new PotionEffect(potionEffect, 319, new Integer(splitd[1]));
} }
else
PotionEffectType potionEffect = PotionEffectType.getByName(split[0]);
if (potionEffect == null)
{ {
throw new InvalidFlagFormat("Unable to find the potion effect type! Please refer to https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html"); throw new InvalidFlagFormat("Unable to find the potion effect type! Please refer to https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html");
} }
}
else return this.buildPotionEffect(split);
{
throw new InvalidFlagFormat("Please use the following format: <effect name> <effect amplifier>");
}
} }
@Override @Override
public PotionEffect unmarshal(Object o) public PotionEffect unmarshal(Object o)
{ {
String[] splitd = o.toString().split(" "); String[] split = o.toString().split(" ");
PotionEffectType type = PotionEffectType.getByName(splitd[0]); return this.buildPotionEffect(split);
int amplifier = Integer.parseInt(splitd[1]); }
return new PotionEffect(type, PotionEffectFlag.POTION_EFFECT_DURATION, amplifier); private PotionEffect buildPotionEffect(String[] split)
{
PotionEffectType potionEffect = PotionEffectType.getByName(split[0]);
int amplifier = 0;
if (split.length >= 2)
{
amplifier = Integer.parseInt(split[1]);
}
boolean showParticles = false;
if (split.length >= 3)
{
showParticles = Boolean.parseBoolean(split[2]);
}
return new PotionEffect(potionEffect, PotionEffectFlag.POTION_EFFECT_DURATION, amplifier, true, showParticles);
} }
} }