skadistats.clarity.model.GameEvent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clarity Show documentation
Show all versions of clarity Show documentation
Clarity is an open source replay parser for Dota 2, CSGO, CS2 and Deadlock written in Java.
package skadistats.clarity.model;
public class GameEvent {
private final GameEventDescriptor descriptor;
private final Object[] state;
public GameEvent(GameEventDescriptor descriptor) {
this.descriptor = descriptor;
this.state = new Object[descriptor.getKeys().length];
}
public void set(int index, Object value) {
this.state[index] = value;
}
public T getProperty(int index) {
return (T) state[index];
}
public T getProperty(String property) {
var index = descriptor.getIndexForKey(property);
if (index == null) {
throw new IllegalArgumentException(String.format("property %s not found on game event of class %s", property, descriptor.getName()));
}
return (T) state[index.intValue()];
}
public String getName() {
return this.descriptor.getName();
}
public int getEventId() {
return this.descriptor.getEventId();
}
@Override
public String toString() {
var buf = new StringBuilder();
for (var i = 0; i < state.length; i++) {
if (i > 0) {
buf.append(", ");
}
buf.append(descriptor.getKeys()[i]);
buf.append("=");
buf.append(state[i]);
}
return String.format("GameEvent [name=%s, id=%s%s%s]", descriptor.getName(), descriptor.getEventId(), buf.length() > 0 ? ", " : "", buf.toString());
}
}