All Downloads are FREE. Search and download functionalities are using the official Maven repository.

skadistats.clarity.model.GameEvent Maven / Gradle / Ivy

Go to download

Clarity is an open source replay parser for Dota 2, CSGO, CS2 and Deadlock written in Java.

There is a newer version: 3.1.1
Show newest version
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());
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy