diff options
Diffstat (limited to 'NET/worlds/scape/Event.java')
| -rw-r--r-- | NET/worlds/scape/Event.java | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/NET/worlds/scape/Event.java b/NET/worlds/scape/Event.java new file mode 100644 index 0000000..69c9c6a --- /dev/null +++ b/NET/worlds/scape/Event.java @@ -0,0 +1,74 @@ +package NET.worlds.scape; + +public class Event implements Cloneable { + public static final Class eventSuperclass = new Object().getClass(); + public int time; + public Object source; + public WObject target; + public WObject receiver; + + public Event(int time, Object source, WObject target) { + this.time = time; + this.source = source; + this.target = target; + } + + @Override + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException var2) { + System.out.println("Clone of Object not supported!"); + return null; + } + } + + public boolean isA(Class c) { + for (Class t = this.getClass(); t != eventSuperclass; t = t.getSuperclass()) { + if (t == c) { + return true; + } + } + + return false; + } + + public boolean deliver(Object o) { + return o instanceof Handler && ((Handler)o).handle(this); + } + + @Override + public String toString() { + String result = "Event at " + this.time; + String sname = null; + if (this.source instanceof SuperRoot) { + sname = ((SuperRoot)this.source).getName(); + } else if (this.source != null) { + sname = this.source.toString(); + } + + if (sname != null) { + result = result + " from " + sname; + } + + String tname = null; + if (this.target != null) { + this.target.getName(); + } + + if (tname != null) { + result = result + " to " + tname; + } + + String rname = null; + if (this.receiver != null) { + this.receiver.getName(); + } + + if (rname != null) { + result = result + " handled by " + rname; + } + + return result; + } +} |