Skip to content

Commit

Permalink
#411 More block sign error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Sataniel98 committed Jun 5, 2018
1 parent 186dd11 commit d165467
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions src/main/java/de/erethon/dungeonsxl/sign/BlockSign.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,54 @@ public boolean check() {
public void onInit() {
if (lines[1].isEmpty()) {
offBlock = VanillaItem.AIR;
} else if (lines[2].isEmpty()) {
onBlock = VanillaItem.AIR;
}

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]);
} else {
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]);
if (lines[2].isEmpty()) {
onBlock = VanillaItem.AIR;

} else {
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());
getSign().getBlock().setData(offBlockData);
try {
getSign().getBlock().setData(offBlockData);
} catch (IllegalArgumentException exception) {
markAsErroneous("offBlock data value " + offBlockData + " cannot be applied to given type " + offBlock.getId());
return;
}
initialized = true;
}

@Override
public void onTrigger() {
if (initialized && !active) {
getSign().getBlock().setType(onBlock.getMaterial());
getSign().getBlock().setData(onBlockData);
try {
getSign().getBlock().setData(onBlockData);
} catch (IllegalArgumentException exception) {
markAsErroneous("onBlock data value " + onBlockData + " cannot be applied to given type " + onBlock.getId());
return;
}
active = true;
}
}
Expand Down

0 comments on commit d165467

Please sign in to comment.