From c10bda92825b7037e7fcea9064808eb29acfeac5 Mon Sep 17 00:00:00 2001 From: aromaa Date: Fri, 24 May 2024 13:20:08 +0300 Subject: [PATCH] Update to 1.20.6 --- Spigot/pom.xml | 4 ++-- .../listeners/PlayerListener.java | 18 ++++++++++++++--- WG/pom.xml | 2 +- .../flags/helpers/PotionEffectFlag.java | 20 ++++++++++++++----- .../flags/helpers/PotionEffectTypeFlag.java | 19 +++++++++++------- pom.xml | 8 ++++---- 6 files changed, 49 insertions(+), 22 deletions(-) diff --git a/Spigot/pom.xml b/Spigot/pom.xml index 6a2f6a4..f0eee52 100644 --- a/Spigot/pom.xml +++ b/Spigot/pom.xml @@ -17,7 +17,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.3.0 + 3.5.3 package @@ -78,7 +78,7 @@ org.spigotmc spigot-api - 1.18.2-R0.1-SNAPSHOT + 1.20.6-R0.1-SNAPSHOT provided diff --git a/Spigot/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/PlayerListener.java b/Spigot/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/PlayerListener.java index 0984641..d301eb1 100644 --- a/Spigot/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/PlayerListener.java +++ b/Spigot/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/PlayerListener.java @@ -22,7 +22,8 @@ import org.bukkit.event.player.PlayerTeleportEvent; 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.scheduler.BukkitRunnable; import org.spigotmc.event.player.PlayerSpawnLocationEvent; @@ -37,6 +38,9 @@ import net.goldtreeservers.worldguardextraflags.wg.handlers.FlyFlagHandler; import net.goldtreeservers.worldguardextraflags.wg.handlers.GiveEffectsFlagHandler; +import java.util.ArrayList; +import java.util.List; + @RequiredArgsConstructor public class PlayerListener implements Listener { @@ -125,9 +129,17 @@ public void onPlayerItemConsumeEvent(PlayerItemConsumeEvent event) Player player = event.getPlayer(); ItemMeta itemMeta = event.getItem().getItemMeta(); - if (itemMeta instanceof PotionMeta) + if (itemMeta instanceof PotionMeta potionMeta) { - this.sessionManager.get(this.worldGuardPlugin.wrapPlayer(player)).getHandler(GiveEffectsFlagHandler.class).drinkPotion(player, Potion.fromItemStack(event.getItem()).getEffects()); + List effects = new ArrayList<>(); + if (potionMeta.getBasePotionType() != null) + { + effects.addAll(potionMeta.getBasePotionType().getPotionEffects()); + } + + effects.addAll(potionMeta.getCustomEffects()); + + this.sessionManager.get(this.worldGuardPlugin.wrapPlayer(player)).getHandler(GiveEffectsFlagHandler.class).drinkPotion(player, effects); } else { diff --git a/WG/pom.xml b/WG/pom.xml index 1a1b6f9..2b884ed 100644 --- a/WG/pom.xml +++ b/WG/pom.xml @@ -24,7 +24,7 @@ org.spigotmc spigot-api - 1.18.2-R0.1-SNAPSHOT + 1.20.6-R0.1-SNAPSHOT provided diff --git a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/PotionEffectFlag.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/PotionEffectFlag.java index 8f27702..2d097a1 100644 --- a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/PotionEffectFlag.java +++ b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/PotionEffectFlag.java @@ -1,5 +1,6 @@ package net.goldtreeservers.worldguardextraflags.flags.helpers; +import org.bukkit.Registry; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; @@ -23,7 +24,7 @@ public PotionEffectFlag(String name) @Override public Object marshal(PotionEffect o) { - return o.getType().getName() + " " + o.getAmplifier() + " " + o.hasParticles(); + return o.getType().getKey().toString() + " " + o.getAmplifier() + " " + o.hasParticles(); } @Override @@ -34,11 +35,16 @@ public PotionEffect parseInput(FlagContext context) throws InvalidFlagFormat { throw new InvalidFlagFormat("Please use the following format: [effect amplifier] [show particles]"); } - - PotionEffectType potionEffect = PotionEffectType.getByName(split[0]); + + PotionEffectType potionEffect = Registry.EFFECT.match(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"); + potionEffect = PotionEffectType.getByName(split[0]); + } + + if (potionEffect == null) + { + throw new InvalidFlagFormat("Unable to find the potion effect type! Input valid namespaced ids."); } return this.buildPotionEffect(split); @@ -54,7 +60,11 @@ public PotionEffect unmarshal(Object o) private PotionEffect buildPotionEffect(String[] split) { - PotionEffectType potionEffect = PotionEffectType.getByName(split[0]); + PotionEffectType potionEffect = Registry.EFFECT.match(split[0]); + if (potionEffect == null) + { + potionEffect = PotionEffectType.getByName(split[0]); + } int amplifier = 0; if (split.length >= 2) diff --git a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/PotionEffectTypeFlag.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/PotionEffectTypeFlag.java index 7f0ad0f..769be88 100644 --- a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/PotionEffectTypeFlag.java +++ b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/PotionEffectTypeFlag.java @@ -1,5 +1,7 @@ package net.goldtreeservers.worldguardextraflags.flags.helpers; +import org.bukkit.NamespacedKey; +import org.bukkit.Registry; import org.bukkit.potion.PotionEffectType; import com.sk89q.worldguard.protection.flags.Flag; @@ -16,26 +18,29 @@ public PotionEffectTypeFlag(String name) @Override public Object marshal(PotionEffectType o) { - return o.getName(); + return o.getKey().toString(); } @Override public PotionEffectType parseInput(FlagContext context) throws InvalidFlagFormat { - PotionEffectType potionEffect = PotionEffectType.getByName(context.getUserInput().trim()); - if (potionEffect != null) + PotionEffectType potionEffect = Registry.EFFECT.match(context.getUserInput().trim()); + if (potionEffect == null) { - return potionEffect; + potionEffect = PotionEffectType.getByName(context.getUserInput().trim()); } - else + + 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"); + return potionEffect; } + + throw new InvalidFlagFormat("Unable to find the potion effect type! Input valid namespaced ids."); } @Override public PotionEffectType unmarshal(Object o) { - return PotionEffectType.getByName(o.toString()); + return Registry.EFFECT.get(NamespacedKey.fromString(o.toString())); } } diff --git a/pom.xml b/pom.xml index 7afbf6f..2c718e6 100644 --- a/pom.xml +++ b/pom.xml @@ -13,10 +13,10 @@ org.apache.maven.plugins maven-compiler-plugin - 3.10.1 + 3.13.0 - 17 - 17 + 21 + 21 @@ -26,7 +26,7 @@ org.projectlombok lombok - 1.18.24 + 1.18.32 provided