Search in sources :

Example 1 with PlayerChangeClientSettingsEvent

use of org.spongepowered.api.event.entity.living.humanoid.player.PlayerChangeClientSettingsEvent in project LanternServer by LanternPowered.

the class HandlerPlayInClientSettings method handle.

@Override
public void handle(NetworkContext context, MessagePlayInClientSettings message) {
    final LanternPlayer player = context.getSession().getPlayer();
    final Cause cause = Cause.of(EventContext.empty(), player);
    final PlayerChangeClientSettingsEvent event = SpongeEventFactory.createPlayerChangeClientSettingsEvent(cause, message.getChatVisibility(), LanternSkinPart.fromBitPattern(message.getSkinPartsBitPattern()), message.getLocale(), player, message.getEnableColors(), message.getViewDistance());
    Sponge.getEventManager().post(event);
    player.setLocale(event.getLocale());
    player.setViewDistance(event.getViewDistance());
    player.setChatVisibility(event.getChatVisibility());
    player.setChatColorsEnabled(message.getEnableColors());
    player.offer(LanternKeys.DISPLAYED_SKIN_PARTS, event.getDisplayedSkinParts());
    player.offer(Keys.DOMINANT_HAND, message.getDominantHand());
}
Also used : PlayerChangeClientSettingsEvent(org.spongepowered.api.event.entity.living.humanoid.player.PlayerChangeClientSettingsEvent) Cause(org.spongepowered.api.event.cause.Cause) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Example 2 with PlayerChangeClientSettingsEvent

use of org.spongepowered.api.event.entity.living.humanoid.player.PlayerChangeClientSettingsEvent in project SpongeCommon by SpongePowered.

the class MixinEntityPlayerMP method postClientSettingsEvent.

// Post before the player values are updated
@Inject(method = "handleClientSettings", at = @At("HEAD"))
public void postClientSettingsEvent(CPacketClientSettings packet, CallbackInfo ci) {
    // TODO: add HandPreference to PlayerChangeClientSettingsEvent once DominantHandData is implemented
    Sponge.getCauseStackManager().pushCause(this);
    final PlayerChangeClientSettingsEvent event = SpongeEventFactory.createPlayerChangeClientSettingsEvent(Sponge.getCauseStackManager().getCurrentCause(), (ChatVisibility) (Object) packet.getChatVisibility(), SkinUtil.fromFlags(packet.getModelPartFlags()), LocaleCache.getLocale(packet.getLang()), this, packet.isColorsEnabled(), packet.view);
    SpongeImpl.postEvent(event);
    Sponge.getCauseStackManager().popCause();
}
Also used : PlayerChangeClientSettingsEvent(org.spongepowered.api.event.entity.living.humanoid.player.PlayerChangeClientSettingsEvent) IInteractionObject(net.minecraft.world.IInteractionObject) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

PlayerChangeClientSettingsEvent (org.spongepowered.api.event.entity.living.humanoid.player.PlayerChangeClientSettingsEvent)2 IInteractionObject (net.minecraft.world.IInteractionObject)1 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)1 Cause (org.spongepowered.api.event.cause.Cause)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1