Skip to content

Commit

Permalink
Fixed Witch Potion Switcher not working on 1.21+ (NoClassDefFoundErro…
Browse files Browse the repository at this point in the history
…r org/bukkit/potion/Potion error) (#269)
  • Loading branch information
cervinakuy committed Sep 22, 2024
1 parent 768a7a9 commit eefd176
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/main/java/com/planetgallium/kitpvp/listener/ItemListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;

import java.util.Objects;
import java.util.Random;

public class ItemListener implements Listener {
Expand Down Expand Up @@ -502,16 +502,31 @@ private int getItemByMeta(Material type, String displayName, Player p) {
}

private ItemStack createWitchPotion() {
Potion potion = new Potion(pickPotion(), 1);
potion.setSplash(true);
PotionType randomPotionType = randomPotionType();

ItemStack potionStack = potion.toItemStack(1);
Toolkit.appendToLore(potionStack, "X");
if (Toolkit.versionToNumber() >= 121) { // 1.21+
ItemStack potionStack = new ItemStack(Material.SPLASH_POTION);
Toolkit.appendToLore(potionStack, "X");
PotionMeta potionMeta = (PotionMeta) potionStack.getItemMeta();

return potionStack;
if (potionMeta != null) {
potionMeta.setBasePotionType(randomPotionType);
potionStack.setItemMeta(potionMeta);
}

return potionStack;
} else { // pre 1.21
Potion potion = new Potion(randomPotionType, 1);
potion.setSplash(true);

ItemStack potionStack = potion.toItemStack(1);
Toolkit.appendToLore(potionStack, "X");

return potionStack;
}
}

private PotionType pickPotion() {
private PotionType randomPotionType() {
PotionType potion = null;

Random ran = new Random();
Expand Down

0 comments on commit eefd176

Please sign in to comment.