use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class ServerPingSystem method onPingFromClient.
@ReceiveEvent(components = ClientComponent.class)
public void onPingFromClient(PingFromClientEvent event, EntityRef entity) {
Instant end = Instant.now();
endMap.put(entity, end);
updatePing(entity);
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class AudioSystem method onPlaySound.
/**
* Receives the sound played event and calls on the AudioManager to play it.
*
* @param playSoundEvent The sound event.
* @param entity The entity that instigated the event.
*/
@ReceiveEvent
public void onPlaySound(PlaySoundEvent playSoundEvent, EntityRef entity) {
LocationComponent location = entity.getComponent(LocationComponent.class);
if (location != null) {
Vector3f pos = location.getWorldPosition(new Vector3f());
if (pos.isFinite()) {
audioManager.playSound(playSoundEvent.getSound(), pos, playSoundEvent.getVolume(), AudioManager.PRIORITY_NORMAL);
return;
} else {
logger.warn("Can't play sound with non-finite position/rotation?! Entity: {}", entity);
}
}
audioManager.playSound(playSoundEvent.getSound(), playSoundEvent.getVolume());
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class AfkClientSystem method onDetectAfk.
@ReceiveEvent
public void onDetectAfk(AfkDetectEvent event, EntityRef entityRef) {
EntityRef entity = localPlayer.getClientEntity();
long afkTime = time.getGameTimeInMs() - lastActive;
if (afkTime >= AFK_TIMEOUT) {
AfkComponent component = entity.getComponent(AfkComponent.class);
if (!component.afk) {
component.afk = true;
AfkRequest request = new AfkRequest(entity, true);
entity.send(request);
}
}
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class AfkClientSystem method onAfk.
@ReceiveEvent
public void onAfk(AfkEvent event, EntityRef entityRef) {
if (requireConnection()) {
return;
}
EntityRef entity = event.getTarget();
AfkComponent component = entity.getComponent(AfkComponent.class);
if (component != null) {
component.afk = event.isAfk();
entity.addOrSaveComponent(component);
}
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class PlaySoundAction method onActivate.
/**
* This method plays sound if it wasn't played by prediction system
*
* @param event contains the details for the active event, used here for location purposes
* @param entity is source of the playsound
*/
@ReceiveEvent(components = PlaySoundActionComponent.class)
public void onActivate(ActivateEvent event, EntityRef entity) {
if (event.getInstigator().equals(localPlayer.getCharacterEntity())) {
// owner has heard sound from prediction
return;
}
PlaySoundActionComponent playSound = entity.getComponent(PlaySoundActionComponent.class);
StaticSound sound = random.nextItem(playSound.sounds);
if (sound != null) {
Vector3f pos;
switch(playSound.relativeTo) {
case Target:
pos = event.getTargetLocation();
break;
default:
pos = event.getInstigatorLocation();
break;
}
if (pos == null) {
pos = event.getOrigin();
}
audioManager.playSound(sound, pos, playSound.volume, AudioManager.PRIORITY_NORMAL);
}
}
Aggregations