From 9d3016430844ad4041d52eba38fd2a29328f5ae7 Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Tue, 13 Aug 2019 12:23:24 -0500 Subject: [PATCH 1/4] fix message store overwrite on spawn, other NPE errors --- .../listeners/pre/BossSpawnListener.java | 18 ++++++++++-------- .../epicbosses/managers/BossEntityManager.java | 6 +++--- .../epicbosses/panel/MainMenuPanel.java | 1 - .../bosses/commands/OnDeathCommandEditor.java | 2 +- .../bosses/commands/OnSpawnCommandEditor.java | 2 +- .../utils/itemstack/ItemStackUtils.java | 15 +++++++++++---- .../utils/panel/base/IPanelHandler.java | 1 - 7 files changed, 26 insertions(+), 19 deletions(-) diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/listeners/pre/BossSpawnListener.java b/plugin-modules/Core/src/com/songoda/epicbosses/listeners/pre/BossSpawnListener.java index 2243f5e..6471278 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/listeners/pre/BossSpawnListener.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/listeners/pre/BossSpawnListener.java @@ -17,6 +17,7 @@ import com.songoda.epicbosses.utils.ServerUtils; import com.songoda.epicbosses.utils.StringUtils; import com.songoda.epicbosses.utils.itemstack.ItemStackUtils; import com.songoda.epicbosses.utils.version.VersionHandler; +import java.util.ArrayList; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; @@ -117,8 +118,8 @@ public class BossSpawnListener implements Listener { BossEntity bossEntity = activeBossHolder.getBossEntity(); Location location = activeBossHolder.getLocation(); - List commands = this.bossEntityManager.getOnSpawnCommands(bossEntity); - List messages = this.bossEntityManager.getOnSpawnMessage(bossEntity); + List commands = new ArrayList(this.bossEntityManager.getOnSpawnCommands(bossEntity)); + List messages = new ArrayList(this.bossEntityManager.getOnSpawnMessage(bossEntity)); int messageRadius = this.bossEntityManager.getOnSpawnMessageRadius(bossEntity); ServerUtils serverUtils = ServerUtils.get(); @@ -133,22 +134,23 @@ public class BossSpawnListener implements Listener { player.updateInventory(); } - if (commands != null) + if (!commands.isEmpty()) commands.replaceAll(s -> s.replaceAll("%player%", player.getName())); - if (messages != null && !activeBossHolder.isCustomSpawnMessage()) + if (!messages.isEmpty() && !activeBossHolder.isCustomSpawnMessage()) messages.replaceAll(s -> s.replace("{name}", player.getName())); } else { - if (messages != null && !activeBossHolder.isCustomSpawnMessage()) + if (!messages.isEmpty() && !activeBossHolder.isCustomSpawnMessage()) messages.replaceAll(s -> s.replace("{name}", "Console")); } - if (commands != null) + if (!commands.isEmpty()) commands.forEach(serverUtils::sendConsoleCommand); - if(messages != null && !activeBossHolder.isCustomSpawnMessage()) { + if(!messages.isEmpty() && !activeBossHolder.isCustomSpawnMessage()) { if(activeBossHolder.getName() != null) messages.replaceAll(s -> s.replace("{boss}", activeBossHolder.getName())); - messages.replaceAll(s -> s.replace("{location}", StringUtils.get().translateLocation(location))); + final String locationString = StringUtils.get().translateLocation(location); + messages.replaceAll(s -> s.replace("{location}", locationString)); MessageUtils.get().sendMessage(location, NumberUtils.get().getSquared(messageRadius), messages); } diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossEntityManager.java b/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossEntityManager.java index a653794..e4adeed 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossEntityManager.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossEntityManager.java @@ -183,7 +183,7 @@ public class BossEntityManager { if(messages == null) { Debug.FAILED_TO_LOAD_MESSAGES.debug(id); - return null; + return Collections.EMPTY_LIST; } return messages; @@ -203,7 +203,7 @@ public class BossEntityManager { if(commands == null) { Debug.FAILED_TO_LOAD_COMMANDS.debug(id); - return null; + return Collections.EMPTY_LIST; } return commands; @@ -215,7 +215,7 @@ public class BossEntityManager { if(messages == null) { Debug.FAILED_TO_LOAD_MESSAGES.debug(id); - return null; + return Collections.EMPTY_LIST; } return messages; diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/MainMenuPanel.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/MainMenuPanel.java index 77e374d..3c4420d 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/panel/MainMenuPanel.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/MainMenuPanel.java @@ -7,7 +7,6 @@ import com.songoda.epicbosses.utils.panel.base.ClickAction; import com.songoda.epicbosses.utils.panel.base.PanelHandler; import com.songoda.epicbosses.utils.panel.builder.PanelBuilder; import com.songoda.epicbosses.utils.panel.builder.PanelBuilderCounter; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/commands/OnDeathCommandEditor.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/commands/OnDeathCommandEditor.java index 113168e..e0327c3 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/commands/OnDeathCommandEditor.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/commands/OnDeathCommandEditor.java @@ -97,7 +97,7 @@ public class OnDeathCommandEditor extends VariablePanelHandler { replaceMap.put("{name}", name); - if(bossEntity.getCommands().getOnDeath().equalsIgnoreCase(name)) { + if(bossEntity.getCommands().getOnDeath() != null && bossEntity.getCommands().getOnDeath().equalsIgnoreCase(name)) { ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.Boss.Commands.selectedName"), replaceMap); } else { ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.Boss.Commands.name"), replaceMap); diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/commands/OnSpawnCommandEditor.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/commands/OnSpawnCommandEditor.java index f877e9f..35addcd 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/commands/OnSpawnCommandEditor.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/commands/OnSpawnCommandEditor.java @@ -97,7 +97,7 @@ public class OnSpawnCommandEditor extends VariablePanelHandler { replaceMap.put("{name}", name); - if(bossEntity.getCommands().getOnSpawn().equalsIgnoreCase(name)) { + if(bossEntity.getCommands().getOnSpawn() != null && bossEntity.getCommands().getOnSpawn().equalsIgnoreCase(name)) { ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.Boss.Commands.selectedName"), replaceMap); } else { ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.Boss.Commands.name"), replaceMap); diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/utils/itemstack/ItemStackUtils.java b/plugin-modules/Core/src/com/songoda/epicbosses/utils/itemstack/ItemStackUtils.java index fb113cf..6ccbacb 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/utils/itemstack/ItemStackUtils.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/utils/itemstack/ItemStackUtils.java @@ -153,15 +153,15 @@ public class ItemStackUtils { } } - if(lore != null) { + if(lore != null && !lore.isEmpty()) { for(String z : lore) { String y = z; if(replacedMap != null) { for(String x : replacedMap.keySet()) { - if(!y.contains(x)) continue; + if(x == null || !y.contains(x)) continue; - if (!replacedMap.containsKey(x)) { + if (replacedMap.get(x) == null) { ServerUtils.get().logDebug("Failed to apply replaced lore: [y=" + y + "x=" + x + "]"); continue; } @@ -258,7 +258,14 @@ public class ItemStackUtils { } public static void applyDisplayLore(ItemStack itemStack, List lore, Map replaceMap) { - ItemMeta itemMeta = itemStack.getItemMeta(); + ItemMeta itemMeta; + if (itemStack == null || (itemMeta = itemStack.getItemMeta()) == null) + return; + if (lore == null || lore.isEmpty()) { + itemMeta.setLore(Collections.EMPTY_LIST); + itemStack.setItemMeta(itemMeta); + return; + } if(replaceMap != null) { for(String s : replaceMap.keySet()) { diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/utils/panel/base/IPanelHandler.java b/plugin-modules/Core/src/com/songoda/epicbosses/utils/panel/base/IPanelHandler.java index 1d95bc5..1dc660c 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/utils/panel/base/IPanelHandler.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/utils/panel/base/IPanelHandler.java @@ -1,7 +1,6 @@ package com.songoda.epicbosses.utils.panel.base; import com.songoda.epicbosses.utils.panel.Panel; -import com.songoda.epicbosses.utils.panel.builder.PanelBuilder; import org.bukkit.entity.Player; /** From 5944301722c7e79414df54163fbcf2b91a2ca8d4 Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Tue, 13 Aug 2019 13:32:58 -0500 Subject: [PATCH 2/4] fix WG 5 compatibility --- .../epicbosses/utils/dependencies/WorldGuardLegacyHelper.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api-modules/WorldGuard-Legacy/src/com/songoda/epicbosses/utils/dependencies/WorldGuardLegacyHelper.java b/api-modules/WorldGuard-Legacy/src/com/songoda/epicbosses/utils/dependencies/WorldGuardLegacyHelper.java index 25f029d..b38ed4d 100644 --- a/api-modules/WorldGuard-Legacy/src/com/songoda/epicbosses/utils/dependencies/WorldGuardLegacyHelper.java +++ b/api-modules/WorldGuard-Legacy/src/com/songoda/epicbosses/utils/dependencies/WorldGuardLegacyHelper.java @@ -78,7 +78,8 @@ public class WorldGuardLegacyHelper implements IWorldGuardHelper { List regions = new ArrayList<>(); List parentNames = new ArrayList<>(); - ApplicableRegionSet set = this.worldGuard.getRegionManager(loc.getWorld()).getApplicableRegions(loc); + // this prototype is different from v5 to v6, but they're both Iterable + Iterable set = (Iterable) this.worldGuard.getRegionManager(loc.getWorld()).getApplicableRegions(loc); for (ProtectedRegion region : set) { String id = region.getId(); From cfa18f7c3f05ff9545536ddb0ddf2b310804930e Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Fri, 16 Aug 2019 07:27:03 -0500 Subject: [PATCH 3/4] typo fix in messages --- plugin-modules/Core/resources-json/current/messages.json | 2 +- plugin-modules/Core/resources-json/legacy/messages.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-modules/Core/resources-json/current/messages.json b/plugin-modules/Core/resources-json/current/messages.json index 54c4966..84d8b34 100644 --- a/plugin-modules/Core/resources-json/current/messages.json +++ b/plugin-modules/Core/resources-json/current/messages.json @@ -26,7 +26,7 @@ "&6&l#{pos} &e{name}&f - &e{percent}% &f(&e{dmg} dmg&f)" ], "SKTaunt1": [ - "&6&lSkeleton King &f» &7My pocket knife is sharper then that sword! &o*cackle*" + "&6&lSkeleton King &f» &7My pocket knife is sharper than that sword! &o*cackle*" ], "SKTaunt2": [ "&6&lSkeleton King &f» &7You think you humans can defeat me?! I am the notorious Skeleton King!" diff --git a/plugin-modules/Core/resources-json/legacy/messages.json b/plugin-modules/Core/resources-json/legacy/messages.json index 54c4966..84d8b34 100644 --- a/plugin-modules/Core/resources-json/legacy/messages.json +++ b/plugin-modules/Core/resources-json/legacy/messages.json @@ -26,7 +26,7 @@ "&6&l#{pos} &e{name}&f - &e{percent}% &f(&e{dmg} dmg&f)" ], "SKTaunt1": [ - "&6&lSkeleton King &f» &7My pocket knife is sharper then that sword! &o*cackle*" + "&6&lSkeleton King &f» &7My pocket knife is sharper than that sword! &o*cackle*" ], "SKTaunt2": [ "&6&lSkeleton King &f» &7You think you humans can defeat me?! I am the notorious Skeleton King!" From 7d4fb871bcba7c9e3a3ad8c0b9308e4edcabc263 Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Fri, 16 Aug 2019 12:22:53 -0500 Subject: [PATCH 4/4] remove durability check, prefer material and item meta for spawn eggs --- .../listeners/pre/BossSpawnListener.java | 2 +- .../utils/itemstack/ItemStackUtils.java | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/listeners/pre/BossSpawnListener.java b/plugin-modules/Core/src/com/songoda/epicbosses/listeners/pre/BossSpawnListener.java index 6471278..2d8f66b 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/listeners/pre/BossSpawnListener.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/listeners/pre/BossSpawnListener.java @@ -64,7 +64,7 @@ public class BossSpawnListener implements Listener { if(block.getType() == Material.AIR) return; Map entitiesAndSpawnItems = this.bossEntityManager.getMapOfEntitiesAndSpawnItems(); - ItemStack itemStack = this.versionHandler.getItemInHand(player).clone(); + ItemStack itemStack = this.versionHandler.getItemInHand(player); BossEntity bossEntity = null; for(Map.Entry entry : entitiesAndSpawnItems.entrySet()) { diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/utils/itemstack/ItemStackUtils.java b/plugin-modules/Core/src/com/songoda/epicbosses/utils/itemstack/ItemStackUtils.java index 6ccbacb..57d83ef 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/utils/itemstack/ItemStackUtils.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/utils/itemstack/ItemStackUtils.java @@ -60,7 +60,7 @@ public class ItemStackUtils { return new ItemStack(Material.AIR); if (versionHandler.getVersion().isLessThanOrEqualTo(Versions.v1_12_R1)) { - return new ItemStack(Material.valueOf("MONSTER_EGG"), spawnableEntityIds.get(entityType)); + return new ItemStack(Material.valueOf("MONSTER_EGG"), 1, spawnableEntityIds.get(entityType)); } else { return new ItemStack(spawnableEntityMaterials.get(entityType)); } @@ -399,7 +399,8 @@ public class ItemStackUtils { public static boolean isItemStackSame(ItemStack itemStack1, ItemStack itemStack2) { if(itemStack1 == null || itemStack2 == null) return false; if(itemStack1.getType() != itemStack2.getType()) return false; - if(itemStack1.getDurability() != itemStack2.getDurability()) return false; + // Durability checks are too tempermental to be reliable for all versions + //if(itemStack1.getDurability() != itemStack2.getDurability()) return false; ItemMeta itemMeta1 = itemStack1.getItemMeta(); ItemMeta itemMeta2 = itemStack2.getItemMeta(); @@ -407,17 +408,15 @@ public class ItemStackUtils { if(itemMeta1 == null || itemMeta2 == null) return false; if(itemMeta1.hasDisplayName() == itemMeta2.hasDisplayName()) { - if(itemMeta1.hasDisplayName()) { - if(!itemMeta1.getDisplayName().equals(itemMeta2.getDisplayName())) return false; - } + if(itemMeta1.hasDisplayName() && !itemMeta1.getDisplayName().equals(itemMeta2.getDisplayName())) + return false; } else { return false; } if(itemMeta1.hasLore() == itemMeta2.hasLore()) { - if(itemMeta1.hasLore()) { - if(!itemMeta1.getLore().equals(itemMeta2.getLore())) return false; - } + if(itemMeta1.hasLore() && !itemMeta1.getLore().equals(itemMeta2.getLore())) + return false; } else { return false; }