diff --git a/src/main/java/de/erethon/dungeonsxl/sign/BedSign.java b/src/main/java/de/erethon/dungeonsxl/sign/BedSign.java index 47ed2b1f..68ab3a5f 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/BedSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/BedSign.java @@ -61,7 +61,7 @@ public class BedSign extends DSign { } getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); } else { - markAsErroneous(); + markAsErroneous("No bed attached"); } } diff --git a/src/main/java/de/erethon/dungeonsxl/sign/BlockSign.java b/src/main/java/de/erethon/dungeonsxl/sign/BlockSign.java index 0543f8ee..f665f16a 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/BlockSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/BlockSign.java @@ -48,20 +48,30 @@ public class BlockSign extends DSign { @Override public void onInit() { - if (!lines[1].isEmpty()) { - String line1[] = lines[1].split(","); - offBlock = plugin.getCaliburn().getExItem(line1[0]); - if (line1.length > 1) { - offBlockData = (byte) NumberUtil.parseInt(line1[1]); - } + if (lines[1].isEmpty()) { + offBlock = VanillaItem.AIR; + } else if (lines[2].isEmpty()) { + onBlock = VanillaItem.AIR; } - if (!lines[2].isEmpty()) { - String line2[] = lines[2].split(","); - onBlock = plugin.getCaliburn().getExItem(line2[0]); - if (line2.length > 1) { - onBlockData = (byte) NumberUtil.parseInt(line2[1]); - } + String[] line1 = lines[1].split(","); + offBlock = plugin.getCaliburn().getExItem(line1[0]); + if (offBlock == null) { + markAsErroneous("Could not recognize offBlock, input: " + lines[1]); + return; + } + if (line1.length > 1) { + offBlockData = (byte) NumberUtil.parseInt(line1[1]); + } + + String[] line2 = lines[2].split(","); + onBlock = plugin.getCaliburn().getExItem(line2[0]); + if (onBlock == null) { + markAsErroneous("Could not recognize onBlock, input: " + lines[2]); + return; + } + if (line2.length > 1) { + onBlockData = (byte) NumberUtil.parseInt(line2[1]); } getSign().getBlock().setType(offBlock.getMaterial()); diff --git a/src/main/java/de/erethon/dungeonsxl/sign/BossShopSign.java b/src/main/java/de/erethon/dungeonsxl/sign/BossShopSign.java index 038c78c3..404a02c6 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/BossShopSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/BossShopSign.java @@ -67,8 +67,11 @@ public class BossShopSign extends DSign { @Override public void onInit() { - if (bossShop == null || bossShop.getAPI().getShop(lines[1]) == null) { - markAsErroneous(); + if (bossShop == null) { + markAsErroneous("BossShop not enabled"); + return; + } else if (bossShop.getAPI().getShop(lines[1]) == null) { + markAsErroneous("No such BossShop"); return; } diff --git a/src/main/java/de/erethon/dungeonsxl/sign/ChestSign.java b/src/main/java/de/erethon/dungeonsxl/sign/ChestSign.java index 8c81cb99..c98f4db5 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/ChestSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/ChestSign.java @@ -186,7 +186,7 @@ public class ChestSign extends DSign { getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); } else { - markAsErroneous(); + markAsErroneous("No chest attached"); } } diff --git a/src/main/java/de/erethon/dungeonsxl/sign/DSign.java b/src/main/java/de/erethon/dungeonsxl/sign/DSign.java index 376c343c..1aa67341 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/DSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/DSign.java @@ -53,6 +53,8 @@ public abstract class DSign { // List of Triggers private Set triggers = new HashSet<>(); + private boolean erroneous; + public DSign(Sign sign, String[] lines, DGameWorld gameWorld) { this.sign = sign; this.lines = lines; @@ -168,6 +170,10 @@ public abstract class DSign { } public void onUpdate() { + if (erroneous) { + return; + } + for (Trigger trigger : triggers) { if (!trigger.isTriggered()) { onDisable(); @@ -197,17 +203,26 @@ public abstract class DSign { return !triggers.isEmpty(); } + public boolean isErroneous() { + return erroneous; + } + /** * Set a placeholder to show that the sign is setup incorrectly. + * + * @param reason + * the reason why the sign is marked as erroneous */ - public void markAsErroneous() { + public void markAsErroneous(String reason) { + erroneous = true; sign.setLine(0, ERROR_0); sign.setLine(1, ERROR_1); sign.setLine(2, ERROR_2); sign.setLine(3, ERROR_3); sign.update(); - DMessage.LOG_ERROR_SIGN_SETUP.getMessage(sign.getX() + ", " + sign.getY() + ", " + sign.getZ()); + MessageUtil.log(plugin, DMessage.LOG_ERROR_SIGN_SETUP.getMessage(sign.getX() + ", " + sign.getY() + ", " + sign.getZ())); + MessageUtil.log(plugin, getType().getName() + ": " + reason); } /* Statics */ diff --git a/src/main/java/de/erethon/dungeonsxl/sign/OpenDoorSign.java b/src/main/java/de/erethon/dungeonsxl/sign/OpenDoorSign.java index f090316a..c1263cba 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/OpenDoorSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/OpenDoorSign.java @@ -95,7 +95,7 @@ public class OpenDoorSign extends DSign { getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); } else { - markAsErroneous(); + markAsErroneous("No door attached"); } } diff --git a/src/main/java/de/erethon/dungeonsxl/sign/ResourcePackSign.java b/src/main/java/de/erethon/dungeonsxl/sign/ResourcePackSign.java index d88c6c2f..bdbb576c 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/ResourcePackSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/ResourcePackSign.java @@ -78,7 +78,7 @@ public class ResourcePackSign extends DSign { resourcePack = (String) url; } else { - markAsErroneous(); + markAsErroneous("Unknown resourcepack format"); return; } diff --git a/src/main/java/de/erethon/dungeonsxl/sign/ScriptSign.java b/src/main/java/de/erethon/dungeonsxl/sign/ScriptSign.java index 52ba0ff4..65efdcf5 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/ScriptSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/ScriptSign.java @@ -51,6 +51,9 @@ public class ScriptSign extends DSign { SignScript script = plugin.getSignScripts().getByName(name); for (String[] lines : script.getSigns()) { DSign dSign = DSign.create(getSign(), lines, getGameWorld()); + if (dSign.isErroneous()) { + continue; + } getGameWorld().getDSigns().add(dSign); dSign.onInit(); diff --git a/src/main/java/de/erethon/dungeonsxl/sign/lobby/ClassesSign.java b/src/main/java/de/erethon/dungeonsxl/sign/lobby/ClassesSign.java index bd5917b9..2ca64680 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/lobby/ClassesSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/lobby/ClassesSign.java @@ -71,7 +71,7 @@ public class ClassesSign extends DSign { getGameWorld().getClassesSigns().add(getSign()); } else { - markAsErroneous(); + markAsErroneous("No such class"); } } diff --git a/src/main/java/de/erethon/dungeonsxl/sign/message/HologramSign.java b/src/main/java/de/erethon/dungeonsxl/sign/message/HologramSign.java index aef18e99..6daec383 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/message/HologramSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/message/HologramSign.java @@ -52,7 +52,7 @@ public class HologramSign extends DSign { @Override public void onInit() { if (Bukkit.getPluginManager().getPlugin("HolographicDisplays") == null) { - markAsErroneous(); + markAsErroneous("HolographicDisplays not enabled"); return; } getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); diff --git a/src/main/java/de/erethon/dungeonsxl/sign/message/SoundMessageSign.java b/src/main/java/de/erethon/dungeonsxl/sign/message/SoundMessageSign.java index 7ad87713..fb6f6ef9 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/message/SoundMessageSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/message/SoundMessageSign.java @@ -81,7 +81,7 @@ public class SoundMessageSign extends DSign { getSign().getBlock().setType(VanillaItem.AIR.getMaterial()); initialized = true; } else { - markAsErroneous(); + markAsErroneous("1. Line is empty; expected input: sound name"); } } diff --git a/src/main/java/de/erethon/dungeonsxl/sign/mob/ExternalMobSign.java b/src/main/java/de/erethon/dungeonsxl/sign/mob/ExternalMobSign.java index b34f4bf7..bab91af0 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/mob/ExternalMobSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/mob/ExternalMobSign.java @@ -233,7 +233,7 @@ public class ExternalMobSign extends DSign implements MobSign { } if (provider == null) { - markAsErroneous(); + markAsErroneous("Could not fetch a known external mob provider from " + lines[2]); return; } } diff --git a/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java b/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java index 9f576c28..ff6d455c 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java +++ b/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java @@ -31,7 +31,6 @@ import de.erethon.dungeonsxl.mob.DMob; import de.erethon.dungeonsxl.player.DGroup; import de.erethon.dungeonsxl.sign.DSign; import de.erethon.dungeonsxl.sign.DSignType; -import de.erethon.dungeonsxl.sign.DSignTypeDefault; import de.erethon.dungeonsxl.sign.LocationSign; import de.erethon.dungeonsxl.sign.lobby.StartSign; import de.erethon.dungeonsxl.sign.mob.MobSign; @@ -174,7 +173,7 @@ public class DGameWorld extends DInstanceWorld { // Try the matching location for (DSign dSign : dSigns) { - if (dSign.getType() == DSignTypeDefault.START) { + if (dSign instanceof StartSign) { if (((StartSign) dSign).getId() == index) { return ((LocationSign) dSign).getLocation(); } @@ -183,7 +182,7 @@ public class DGameWorld extends DInstanceWorld { // Try any location for (DSign dSign : dSigns) { - if (dSign.getType() == DSignTypeDefault.START) { + if (dSign instanceof StartSign) { return ((LocationSign) dSign).getLocation(); } } @@ -479,10 +478,8 @@ public class DGameWorld extends DInstanceWorld { } for (DSign dSign : dSigns) { - if (dSign != null) { - if (!dSign.hasTriggers()) { - dSign.onTrigger(); - } + if (dSign != null && !dSign.isErroneous() && !dSign.hasTriggers()) { + dSign.onTrigger(); } } }