Solidify Trigger Recognition on Signs

This commit is contained in:
Sn0wStorm 2013-08-05 19:25:37 +02:00
parent c82d45ced4
commit b4bfb39b3d
2 changed files with 50 additions and 42 deletions

View File

@ -31,10 +31,19 @@ public abstract class DSign {
// Check Trigger
if (gworld != null) {
String[] typeSplit = sign.getLine(3).split(",");
for (String typeSplitPart : typeSplit) {
String[] splitted = typeSplitPart.split(" ");
Trigger trigger = Trigger.getOrCreate(splitted, this);
String line3 = sign.getLine(3).replaceAll("\\s", "");
String[] triggerTypes = line3.split(",");
for (String triggerString : triggerTypes) {
if (!triggerString.equals("")) {
String type = triggerString.substring(0, 1);
String value = null;
if (triggerString.length() > 1) {
value = triggerString.substring(1);
}
Trigger trigger = Trigger.getOrCreate(type, value, this);
if (trigger != null) {
trigger.addListener(this);
this.triggers.add(trigger);
@ -42,6 +51,7 @@ public abstract class DSign {
}
}
}
}
public void onInit() {

View File

@ -23,48 +23,46 @@ public abstract class Trigger {
public abstract void unregister(GameWorld gworld);
public static Trigger getOrCreate(String[] splitted, DSign dsign) {
public static Trigger getOrCreate(String type, String value, DSign dsign) {
Trigger trigger = null;
if (splitted.length > 0) {
if (splitted[0].equalsIgnoreCase("R")) {
if (type.equalsIgnoreCase("R")) {
trigger = RedstoneTrigger.getOrCreate(dsign.getSign(), dsign.getGameWorld());
} else if (splitted[0].equalsIgnoreCase("D")) {
} else if (type.equalsIgnoreCase("D")) {
if (splitted.length > 1) {
trigger = new DistanceTrigger(P.p.parseInt(splitted[1]), dsign.getSign().getLocation());
if (value != null) {
trigger = new DistanceTrigger(P.p.parseInt(value), dsign.getSign().getLocation());
} else {
trigger = new DistanceTrigger(dsign.getSign().getLocation());
}
} else if (splitted[0].equalsIgnoreCase("T")) {
} else if (type.equalsIgnoreCase("T")) {
if (splitted.length > 1) {
trigger = SignTrigger.getOrCreate(P.p.parseInt(splitted[1]), dsign.getGameWorld());
if (value != null) {
trigger = SignTrigger.getOrCreate(P.p.parseInt(value), dsign.getGameWorld());
}
} else if (splitted[0].equalsIgnoreCase("I")) {
} else if (type.equalsIgnoreCase("I")) {
if (splitted.length > 1) {
trigger = InteractTrigger.getOrCreate(P.p.parseInt(splitted[1]), dsign.getGameWorld());
if (value != null) {
trigger = InteractTrigger.getOrCreate(P.p.parseInt(value), dsign.getGameWorld());
}
} else if (splitted[0].equalsIgnoreCase("M")) {
} else if (type.equalsIgnoreCase("M")) {
if (splitted.length > 1) {
trigger = MobTrigger.getOrCreate(splitted[1], dsign.getGameWorld());
if (value != null) {
trigger = MobTrigger.getOrCreate(value, dsign.getGameWorld());
}
} else if (splitted[0].equalsIgnoreCase("U")) {
} else if (type.equalsIgnoreCase("U")) {
if (splitted.length > 1) {
trigger = UseItemTrigger.getOrCreate(splitted[1], dsign.getGameWorld());
if (value != null) {
trigger = UseItemTrigger.getOrCreate(value, dsign.getGameWorld());
}
}
}
return trigger;
}