Improve sign error handling; resolves #404 and resolves #411

This commit is contained in:
Daniel Saukel 2018-06-05 00:37:04 +02:00
parent e6055dd4f0
commit b236431456
13 changed files with 59 additions and 31 deletions

View File

@ -61,7 +61,7 @@ public class BedSign extends DSign {
}
getSign().getBlock().setType(VanillaItem.AIR.getMaterial());
} else {
markAsErroneous();
markAsErroneous("No bed attached");
}
}

View File

@ -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());

View File

@ -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;
}

View File

@ -186,7 +186,7 @@ public class ChestSign extends DSign {
getSign().getBlock().setType(VanillaItem.AIR.getMaterial());
} else {
markAsErroneous();
markAsErroneous("No chest attached");
}
}

View File

@ -53,6 +53,8 @@ public abstract class DSign {
// List of Triggers
private Set<Trigger> 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 */

View File

@ -95,7 +95,7 @@ public class OpenDoorSign extends DSign {
getSign().getBlock().setType(VanillaItem.AIR.getMaterial());
} else {
markAsErroneous();
markAsErroneous("No door attached");
}
}

View File

@ -78,7 +78,7 @@ public class ResourcePackSign extends DSign {
resourcePack = (String) url;
} else {
markAsErroneous();
markAsErroneous("Unknown resourcepack format");
return;
}

View File

@ -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();

View File

@ -71,7 +71,7 @@ public class ClassesSign extends DSign {
getGameWorld().getClassesSigns().add(getSign());
} else {
markAsErroneous();
markAsErroneous("No such class");
}
}

View File

@ -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());

View File

@ -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");
}
}

View File

@ -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;
}
}

View File

@ -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();
}
}
}