From 82d2ce9d6401ba436aa4e9d118b82eeb9be24a4a Mon Sep 17 00:00:00 2001 From: TonytheMacaroni Date: Sat, 20 Jan 2024 16:41:20 -0500 Subject: [PATCH 1/3] Use material tags to check if items are equippable --- .../magicspells/spells/instant/ConjureSpell.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/com/nisovin/magicspells/spells/instant/ConjureSpell.java b/core/src/main/java/com/nisovin/magicspells/spells/instant/ConjureSpell.java index 30b92666f..97fcf70cf 100644 --- a/core/src/main/java/com/nisovin/magicspells/spells/instant/ConjureSpell.java +++ b/core/src/main/java/com/nisovin/magicspells/spells/instant/ConjureSpell.java @@ -6,6 +6,7 @@ import net.kyori.adventure.text.Component; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.ChatColor; import org.bukkit.util.Vector; import org.bukkit.entity.Item; @@ -24,6 +25,8 @@ import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.inventory.InventoryOpenEvent; +import com.destroystokyo.paper.MaterialTags; + import com.nisovin.magicspells.Spell; import com.nisovin.magicspells.util.*; import com.nisovin.magicspells.MagicSpells; @@ -319,16 +322,18 @@ private void conjureItems(Player player, SpellData data) { boolean added = false; PlayerInventory inv = player.getInventory(); if (autoEquip && item.getAmount() == 1) { - if (item.getType().name().endsWith("HELMET") && isNothing(inv.getHelmet())) { + Material type = item.getType(); + + if (MaterialTags.HEAD_EQUIPPABLE.isTagged(type) && isNothing(inv.getHelmet())) { inv.setHelmet(item); added = true; - } else if (item.getType().name().endsWith("CHESTPLATE") && isNothing(inv.getChestplate())) { + } else if (MaterialTags.CHEST_EQUIPPABLE.isTagged(type) && isNothing(inv.getChestplate())) { inv.setChestplate(item); added = true; - } else if (item.getType().name().endsWith("LEGGINGS") && isNothing(inv.getLeggings())) { + } else if (MaterialTags.LEGGINGS.isTagged(type) && isNothing(inv.getLeggings())) { inv.setLeggings(item); added = true; - } else if (item.getType().name().endsWith("BOOTS") && isNothing(inv.getBoots())) { + } else if (MaterialTags.BOOTS.isTagged(type) && isNothing(inv.getBoots())) { inv.setBoots(item); added = true; } From 3c698a8e52011ed9c320367915625e17d081c87e Mon Sep 17 00:00:00 2001 From: TonytheMacaroni Date: Sat, 20 Jan 2024 16:52:03 -0500 Subject: [PATCH 2/3] Adjust gamemode targeting --- .../magicspells/util/ValidTargetList.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/com/nisovin/magicspells/util/ValidTargetList.java b/core/src/main/java/com/nisovin/magicspells/util/ValidTargetList.java index 28d3ce0b0..6b670513a 100644 --- a/core/src/main/java/com/nisovin/magicspells/util/ValidTargetList.java +++ b/core/src/main/java/com/nisovin/magicspells/util/ValidTargetList.java @@ -27,8 +27,6 @@ public enum TargetingElement { } - private static final Set DEFAULT_GAME_MODES = EnumSet.of(GameMode.SURVIVAL, GameMode.ADVENTURE); - private final Set gameModes = EnumSet.noneOf(GameMode.class); private final Set types = EnumSet.noneOf(EntityType.class); @@ -95,7 +93,6 @@ private void init(Spell spell, List list) { switch (s.toLowerCase()) { case "self", "caster" -> targetSelf = true; - case "player", "players" -> targetPlayers = true; case "invisible", "invisibles" -> targetInvisibles = true; case "nonplayer", "nonplayers" -> targetNonPlayers = true; case "monster", "monsters" -> targetMonsters = true; @@ -105,6 +102,11 @@ private void init(Spell spell, List list) { case "castermount", "selfmount" -> targetCasterMount = true; case "casterpassenger", "selfpassenger" -> targetCasterPassenger = true; case "entitytarget", "mobtarget" -> targetEntityTarget = true; + case "player", "players" -> { + gameModes.add(GameMode.SURVIVAL); + gameModes.add(GameMode.ADVENTURE); + targetPlayers = true; + } default -> { try { gameModes.add(GameMode.valueOf(s.toUpperCase())); @@ -116,6 +118,11 @@ private void init(Spell spell, List list) { else MagicSpells.error("Spell '" + spell.getInternalName() + "' has an invalid target type defined: " + s); } } + + if (gameModes.isEmpty()) { + gameModes.add(GameMode.SURVIVAL); + gameModes.add(GameMode.ADVENTURE); + } } } @@ -133,7 +140,7 @@ public boolean canTarget(LivingEntity caster, Entity target, boolean targetPlaye if (!(target instanceof LivingEntity) && !targetNonLivingEntities) return false; boolean targetIsPlayer = target instanceof Player; - if (targetIsPlayer && !canTargetGameMode(((Player) target).getGameMode())) return false; + if (targetIsPlayer && !gameModes.contains(((Player) target).getGameMode())) return false; if (targetSelf && target.equals(caster)) return true; if (!targetSelf && target.equals(caster)) return false; @@ -159,7 +166,7 @@ public boolean canTarget(Entity target) { if (!(target instanceof LivingEntity) && !targetNonLivingEntities) return false; boolean targetIsPlayer = target instanceof Player; - if (targetIsPlayer && !canTargetGameMode(((Player) target).getGameMode())) return false; + if (targetIsPlayer && !gameModes.contains(((Player) target).getGameMode())) return false; if (targetPlayers && targetIsPlayer) return true; if (targetNonPlayers && !targetIsPlayer) return true; @@ -174,16 +181,11 @@ public boolean canTarget(Entity target) { return false; } - private boolean canTargetGameMode(GameMode gameMode) { - if (gameModes.isEmpty()) return DEFAULT_GAME_MODES.contains(gameMode); - return gameModes.contains(gameMode); - } - public boolean canTarget(Entity target, boolean ignoreGameMode) { if (!(target instanceof LivingEntity) && !targetNonLivingEntities) return false; boolean targetIsPlayer = target instanceof Player; - if (!ignoreGameMode && targetIsPlayer && !canTargetGameMode(((Player) target).getGameMode())) return false; + if (!ignoreGameMode && targetIsPlayer && !gameModes.contains(((Player) target).getGameMode())) return false; if (targetPlayers && targetIsPlayer) return true; if (targetNonPlayers && !targetIsPlayer) return true; From b7218f35bd71087c4b4dfb14d36b22447b7994b3 Mon Sep 17 00:00:00 2001 From: TonytheMacaroni Date: Sat, 20 Jan 2024 17:21:14 -0500 Subject: [PATCH 3/3] Remove display hack --- .../com/nisovin/magicspells/util/EntityData.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/core/src/main/java/com/nisovin/magicspells/util/EntityData.java b/core/src/main/java/com/nisovin/magicspells/util/EntityData.java index c7677c3f0..ce125d659 100644 --- a/core/src/main/java/com/nisovin/magicspells/util/EntityData.java +++ b/core/src/main/java/com/nisovin/magicspells/util/EntityData.java @@ -339,7 +339,6 @@ public Entity spawn(@NotNull Location location, @Nullable SpellData data, @Nulla if (entityType == null || (!entityType.isSpawnable() && entityType != EntityType.FALLING_BLOCK && entityType != EntityType.DROPPED_ITEM)) return null; - boolean[] displayHack = new boolean[] {false, false}; Entity entity = switch (entityType) { case FALLING_BLOCK -> { BlockData blockData = fallingBlockData.get(data); @@ -371,25 +370,10 @@ public Entity spawn(@NotNull Location location, @Nullable SpellData data, @Nulla transformer.apply(e, data); if (consumer != null) consumer.accept(e); - - if (e instanceof Display) { - String version = org.bukkit.Bukkit.getMinecraftVersion(); - if ("1.19.4".equals(version) || "1.20".equals(version)) { - displayHack[0] = true; - displayHack[1] = e.isVisibleByDefault(); - - e.setVisibleByDefault(false); - } - } }); } }; - if (displayHack[0]) { - entity.teleport(startLoc); - entity.setVisibleByDefault(displayHack[1]); - } - return entity; }