Fix splash potion support for /potion. Resolves #1166

This commit is contained in:
Ali Moghnieh 2018-01-07 02:18:59 +00:00
parent 50e2d27d5b
commit b6aea0a5f8
No known key found for this signature in database
GPG Key ID: F09D3A1BAF2E6D70
2 changed files with 21 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.NumberUtil;
import com.google.common.base.Joiner;
import net.ess3.api.IEssentials;
import net.ess3.nms.refl.ReflUtil;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.Color;
@ -392,9 +393,17 @@ public class MetaItemStack {
}
pmeta.addCustomEffect(pEffect, true);
stack.setItemMeta(pmeta);
Potion potion = Potion.fromItemStack(stack);
potion.setSplash(isSplashPotion);
potion.apply(stack);
if (ReflUtil.getNmsVersionObject().isHigherThanOrEqualTo(ReflUtil.V1_9_R1)) {
if (isSplashPotion && stack.getType() != Material.SPLASH_POTION) {
stack.setType(Material.SPLASH_POTION);
} else if (!isSplashPotion && stack.getType() != Material.POTION) {
stack.setType(Material.POTION);
}
} else {
Potion potion = Potion.fromItemStack(stack);
potion.setSplash(isSplashPotion);
potion.apply(stack);
}
resetPotionMeta();
}
}

View File

@ -11,6 +11,7 @@ import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@ -23,6 +24,8 @@ import java.util.TreeSet;
import static com.earth2me.essentials.I18n.tl;
import net.ess3.nms.refl.ReflUtil;
public class Commandpotion extends EssentialsCommand {
public Commandpotion() {
@ -43,8 +46,12 @@ public class Commandpotion extends EssentialsCommand {
}
throw new NotEnoughArgumentsException(tl("potions", StringUtil.joinList(potionslist.toArray())));
}
if (stack.getType() == Material.POTION) {
boolean holdingPotion = stack.getType() == Material.POTION;
if (!holdingPotion && ReflUtil.getNmsVersionObject().isHigherThanOrEqualTo(ReflUtil.V1_9_R1)) {
holdingPotion = stack.getType() == Material.SPLASH_POTION || stack.getType() == Material.LINGERING_POTION;
}
if (holdingPotion) {
PotionMeta pmeta = (PotionMeta) stack.getItemMeta();
if (args.length > 0) {
if (args[0].equalsIgnoreCase("clear")) {