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,13 +31,23 @@ public abstract class DSign {
// Check Trigger // Check Trigger
if (gworld != null) { if (gworld != null) {
String[] typeSplit = sign.getLine(3).split(","); String line3 = sign.getLine(3).replaceAll("\\s", "");
for (String typeSplitPart : typeSplit) { String[] triggerTypes = line3.split(",");
String[] splitted = typeSplitPart.split(" ");
Trigger trigger = Trigger.getOrCreate(splitted, this); for (String triggerString : triggerTypes) {
if (trigger != null) { if (!triggerString.equals("")) {
trigger.addListener(this);
this.triggers.add(trigger); 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);
}
} }
} }
} }

View File

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