mirror of
https://github.com/songoda/EpicBosses.git
synced 2025-01-06 23:37:33 +01:00
fix message store overwrite on spawn, other NPE errors
This commit is contained in:
parent
e9d0dbeb62
commit
9d30164308
@ -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<String> commands = this.bossEntityManager.getOnSpawnCommands(bossEntity);
|
||||
List<String> messages = this.bossEntityManager.getOnSpawnMessage(bossEntity);
|
||||
List<String> commands = new ArrayList(this.bossEntityManager.getOnSpawnCommands(bossEntity));
|
||||
List<String> 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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -97,7 +97,7 @@ public class OnDeathCommandEditor extends VariablePanelHandler<BossEntity> {
|
||||
|
||||
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);
|
||||
|
@ -97,7 +97,7 @@ public class OnSpawnCommandEditor extends VariablePanelHandler<BossEntity> {
|
||||
|
||||
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);
|
||||
|
@ -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<String> lore, Map<String, String> 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()) {
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user