diff --git a/src/main/java/tk/shanebee/hg/listeners/McmmoListeners.java b/src/main/java/tk/shanebee/hg/listeners/McmmoListeners.java
index 853d542..b3008dd 100644
--- a/src/main/java/tk/shanebee/hg/listeners/McmmoListeners.java
+++ b/src/main/java/tk/shanebee/hg/listeners/McmmoListeners.java
@@ -9,7 +9,6 @@
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent;
import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillEvent;
import org.bukkit.Location;
-import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -97,29 +96,6 @@ protected void blockDamageEvent(FakeBlockDamageEvent event) {
}
}
- @EventHandler
- private void entityDamageByEntityEvent(FakeEntityDamageByEntityEvent event) {
- if (!Config.mcmmoUseSkills) {
- Entity damager = event.getDamager();
- Entity victim = event.getEntity();
- if (playerManager.hasPlayerData(damager.getUniqueId()) || playerManager.hasPlayerData(victim.getUniqueId())) {
- event.setCancelled(true);
- }
- }
- }
-
- @EventHandler
- private void entityDamageEvent(FakeEntityDamageEvent event) {
- if (!Config.mcmmoUseSkills) {
- if (event.getEntity() instanceof Player) {
- Player player = ((Player) event.getEntity());
- if (playerManager.hasPlayerData(player.getUniqueId())) {
- event.setCancelled(true);
- }
- }
- }
- }
-
@EventHandler
private void fishEvent(FakePlayerFishEvent event) {
if (!Config.mcmmoUseSkills) {
diff --git a/src/main/java/tk/shanebee/hg/managers/ItemStackManager.java b/src/main/java/tk/shanebee/hg/managers/ItemStackManager.java
index 86e07c0..cf4696f 100755
--- a/src/main/java/tk/shanebee/hg/managers/ItemStackManager.java
+++ b/src/main/java/tk/shanebee/hg/managers/ItemStackManager.java
@@ -4,6 +4,7 @@
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.Material;
+import org.bukkit.Registry;
import org.bukkit.configuration.Configuration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
@@ -12,9 +13,9 @@
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.SkullMeta;
-import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
+import org.bukkit.potion.PotionType;
import org.jetbrains.annotations.Nullable;
import tk.shanebee.hg.HG;
import tk.shanebee.hg.data.KitEntry;
@@ -164,9 +165,9 @@ public ItemStack getItem(String args, boolean isStackable) {
}
} else if (s.startsWith("potion-base:") && itemMeta instanceof PotionMeta) {
s = s.replace("potion-base:", "");
- PotionData potionData = PotionTypeUtils.getPotionData(s);
- if (potionData != null) {
- ((PotionMeta) itemMeta).setBasePotionData(potionData);
+ PotionType potionType = PotionTypeUtils.getPotionType(s);
+ if (potionType != null) {
+ ((PotionMeta) itemMeta).setBasePotionType(potionType);
}
} else if (s.startsWith("data:")) {
s = s.replace("data:", "").replace("~", " ");
@@ -181,7 +182,6 @@ public ItemStack getItem(String args, boolean isStackable) {
return item;
}
- @SuppressWarnings("deprecation") //Enchantment#getName
private void enchant(ItemMeta itemMeta, String line, String enchantString) {
enchantString = enchantString.replace("enchant:", "").toUpperCase();
String[] d = enchantString.split(":");
@@ -189,8 +189,8 @@ private void enchant(ItemMeta itemMeta, String line, String enchantString) {
if (d.length != 1 && Util.isInt(d[1])) {
level = Integer.parseInt(d[1]);
}
- for (Enchantment e : Enchantment.values()) {
- if (e.getKey().getKey().equalsIgnoreCase(d[0]) || e.getName().equalsIgnoreCase(d[0])) {
+ for (Enchantment e : Registry.ENCHANTMENT) {
+ if (e.getKey().getKey().equalsIgnoreCase(d[0]) || legacyNameMatches(e, d[0])) {
itemMeta.addEnchant(e, level, true);
return;
}
@@ -198,6 +198,11 @@ private void enchant(ItemMeta itemMeta, String line, String enchantString) {
Util.warning("Invalid enchantment: &c%s &eline: &b%s", enchantString, line);
}
+ @SuppressWarnings("deprecation") //Enchantment#getName has no non-deprecated replacement for legacy free-text name lookup
+ private boolean legacyNameMatches(Enchantment e, String name) {
+ return e.getName().equalsIgnoreCase(name);
+ }
+
private ItemStack itemStringToStack(String item, int amount) {
Material material;
try {
diff --git a/src/main/java/tk/shanebee/hg/util/PotionTypeUtils.java b/src/main/java/tk/shanebee/hg/util/PotionTypeUtils.java
index 0655a44..15b20d9 100644
--- a/src/main/java/tk/shanebee/hg/util/PotionTypeUtils.java
+++ b/src/main/java/tk/shanebee/hg/util/PotionTypeUtils.java
@@ -1,6 +1,5 @@
package tk.shanebee.hg.util;
-import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionType;
import org.jetbrains.annotations.Nullable;
@@ -9,7 +8,7 @@
import java.util.Map;
/**
- * Util for getting {@link PotionData}
+ * Util for getting {@link PotionType}
*/
public enum PotionTypeUtils {
@@ -82,26 +81,40 @@ public static PotionType getByKey(String key) {
}
/**
- * Get a PotionType based on a Bukkit key
+ * Get a PotionType based on a legacy Bukkit key
+ * Some legacy Bukkit key names (eg: 'SPEED', 'JUMP', 'REGEN') no longer exist as
+ * {@link PotionType} constants themselves, so this resolves via the enum's own
+ * MC-namespace name (eg: 'SWIFTNESS', 'LEAPING', 'REGENERATION') instead of assuming
+ * the legacy key is still a valid constant.
*
- * @param bukkit Key for PotionType
- * @return PotionType
+ * @param bukkit Legacy key for PotionType
+ * @return PotionType, or null if this legacy key has no modern equivalent
*/
+ @Nullable
public static PotionType getByBukkit(String bukkit) {
- return PotionType.valueOf(bukkit.toUpperCase());
+ for (PotionTypeUtils p : values()) {
+ if (p.bukkit.equalsIgnoreCase(bukkit)) {
+ try {
+ return PotionType.valueOf(p.name());
+ } catch (IllegalArgumentException ex) {
+ return null;
+ }
+ }
+ }
+ return null;
}
/**
- * Get PotionData from a String
+ * Get a PotionType from a String
* Formats:
*
POTION-TYPE (optional start with 'LONG_' or 'STRONG_')
*
POTION-TYPE:boolean(strong):boolean(extended)
*
* @param data data string of potion type
- * @return New PotionData if checks passed
+ * @return Resolved PotionType if checks passed
*/
@Nullable
- public static PotionData getPotionData(String data) {
+ public static PotionType getPotionType(String data) {
String[] potionData = data.split(":");
if (potionData.length == 1) {
String pData = potionData[0].toUpperCase(Locale.ROOT);
@@ -124,7 +137,7 @@ public static PotionData getPotionData(String data) {
Util.warning("Potion can not be upgraded: &b" + data);
return null;
}
- return new PotionData(potionType, extended, strong);
+ return resolveVariant(potionType, extended, strong);
} else if (potionData.length == 3) {
PotionType potionType = get(potionData[0]);
if (potionType == null) {
@@ -150,13 +163,29 @@ public static PotionData getPotionData(String data) {
return null;
}
- return new PotionData(potionType, extended, upgraded);
+ return resolveVariant(potionType, extended, upgraded);
} else {
potionTypeWarning("Improper setup of potion-data: &c");
return null;
}
}
+ /**
+ * Resolve the granular {@link PotionType} constant (eg: LONG_SWIFTNESS, STRONG_SWIFTNESS)
+ * for a base potion type plus extended/upgraded flags, since these are now folded directly
+ * into the enum rather than represented as separate metadata.
+ *
+ * @param base Base potion type (already validated as extendable/upgradeable if needed)
+ * @param extended Whether the extended (LONG_) variant is requested
+ * @param upgraded Whether the upgraded (STRONG_) variant is requested
+ * @return Resolved PotionType
+ */
+ private static PotionType resolveVariant(PotionType base, boolean extended, boolean upgraded) {
+ if (extended) return PotionType.valueOf("LONG_" + base.name());
+ if (upgraded) return PotionType.valueOf("STRONG_" + base.name());
+ return base;
+ }
+
private static void potionTypeWarning(@Nullable String warning) {
if (warning != null) Util.warning(warning);
Util.warning("&r - Check your configs");
diff --git a/src/main/java/tk/shanebee/hg/util/Util.java b/src/main/java/tk/shanebee/hg/util/Util.java
index 39170dd..96e69d7 100755
--- a/src/main/java/tk/shanebee/hg/util/Util.java
+++ b/src/main/java/tk/shanebee/hg/util/Util.java
@@ -10,12 +10,13 @@
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
+import org.bukkit.block.data.BlockData;
+import org.bukkit.block.data.Directional;
+import org.bukkit.block.data.FaceAttachable;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.FireworkMeta;
-import org.bukkit.material.Attachable;
-import org.bukkit.material.MaterialData;
import org.jetbrains.annotations.NotNull;
import tk.shanebee.hg.HG;
import tk.shanebee.hg.data.Config;
@@ -64,7 +65,7 @@ public static void log(String format, Object... objects) {
* @param warning Message to log to console
*/
public static void warning(String warning) {
- if (warning.length() > 0) { // only send messages if its actually a message
+ if (!warning.isEmpty()) { // only send messages if its actually a message
LOGGER.warning(getColString("&7[&e&lHungerGames&7] &eWARNING: " + warning));
}
}
@@ -114,7 +115,7 @@ public static void debug(@NotNull Exception exception) {
* @param s Message to send
*/
public static void scm(CommandSender sender, String s) {
- if (s.length() > 0) { // only send messages if its actually a message
+ if (!s.isEmpty()) { // only send messages if its actually a message
sender.sendMessage(getColString(s) + ChatColor.RESET);
}
}
@@ -137,7 +138,7 @@ public static void scm(CommandSender sender, String format, Object... objects) {
* @param message Message to send
*/
public static void sendPrefixedMessage(CommandSender sender, String message) {
- if (message.length() > 0) { // only send messages if its actually a message
+ if (!message.isEmpty()) { // only send messages if its actually a message
scm(sender, HG.getPlugin().getLang().prefix + message);
}
}
@@ -159,7 +160,7 @@ public static void sendPrefixedMessage(CommandSender sender, String format, Obje
* @param s Message to send
*/
public static void broadcast(String s) {
- if (s.length() > 0) { // only send messages if its actually a message
+ if (!s.isEmpty()) { // only send messages if its actually a message
Bukkit.broadcastMessage(getColString(HG.getPlugin().getLang().prefix + " " + s));
}
}
@@ -205,16 +206,12 @@ public static boolean isBool(String string) {
}
public static BlockFace getSignFace(BlockFace face) {
- switch (face) {
- case WEST:
- return BlockFace.SOUTH;
- case SOUTH:
- return BlockFace.EAST;
- case EAST:
- return BlockFace.NORTH;
- default:
- return BlockFace.WEST;
- }
+ return switch (face) {
+ case WEST -> BlockFace.SOUTH;
+ case SOUTH -> BlockFace.EAST;
+ case EAST -> BlockFace.NORTH;
+ default -> BlockFace.WEST;
+ };
}
/**
@@ -276,19 +273,32 @@ public static void shootFirework(Location l) {
fw.setFireworkMeta(fm);
}
- @SuppressWarnings("deprecation")
public static boolean isAttached(Block base, Block attached) {
if (attached.getType() == Material.AIR) return false;
- MaterialData bs = attached.getState().getData();
- //BlockData bs = attached.getBlockData();
-
- if (!(bs instanceof Attachable)) return false;
-
- Attachable at = (Attachable) bs;
- BlockFace face = at.getAttachedFace();
+ BlockData data = attached.getBlockData();
+ BlockFace face;
+
+ if (data instanceof FaceAttachable) {
+ FaceAttachable.AttachedFace attachedFace = ((FaceAttachable) data).getAttachedFace();
+ switch (attachedFace) {
+ case CEILING:
+ face = BlockFace.UP;
+ break;
+ case FLOOR:
+ face = BlockFace.DOWN;
+ break;
+ default:
+ if (!(data instanceof Directional)) return false;
+ face = ((Directional) data).getFacing().getOppositeFace();
+ break;
+ }
+ } else if (data instanceof Directional) {
+ face = ((Directional) data).getFacing().getOppositeFace();
+ } else {
+ return false;
+ }
- if (face == null) return false;
return attached.getRelative(face).equals(base);
}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 43972ca..058a924 100755
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -4,7 +4,7 @@ authors: [bob7l, Spoopy, ShaneBee, JT122406]
description: A Simple, fun, PvP arena plugin
version: '${project.version}'
website: https://bitbucket.org/ShaneBeeStudios/hungergames
-api-version: '1.14'
+api-version: '26.2'
softdepend: [Multiverse-Core, MultiWorld, Vault, My_Worlds, GoldenEnchants, mcMMO, MythicMobs, PlaceholderAPI, XConomy, PartyAndFriends, Spigot-Party-API-PAF, Parties, NBTAPI]
commands: