use of org.spongepowered.api.entity.living.player.server.ServerPlayer in project SpongeCommon by SpongePowered.
the class ServerPlayerMixin method impl$handleClientSettings.
@SuppressWarnings({ "ConstantConditions", "UnstableApiUsage" })
@Inject(method = "updateOptions", at = @At("HEAD"))
private void impl$handleClientSettings(final ServerboundClientInformationPacket packet, final CallbackInfo ci) {
if (!ShouldFire.PLAYER_CHANGE_CLIENT_SETTINGS_EVENT) {
return;
}
final ServerboundClientInformationPacketAccessor $packet = (ServerboundClientInformationPacketAccessor) packet;
final Locale newLocale = LocaleCache.getLocale($packet.accessor$language());
final ImmutableSet<SkinPart> skinParts = Sponge.game().registry(RegistryTypes.SKIN_PART).stream().map(part -> (SpongeSkinPart) part).filter(part -> part.test(packet.getModelCustomisation())).collect(ImmutableSet.toImmutableSet());
final int viewDistance = $packet.accessor$viewDistance();
// Post before the player values are updated
try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
final ChatVisibility visibility = (ChatVisibility) (Object) packet.getChatVisibility();
final PlayerChangeClientSettingsEvent event = SpongeEventFactory.createPlayerChangeClientSettingsEvent(frame.currentCause(), visibility, skinParts, newLocale, (ServerPlayer) this, packet.getChatColors(), viewDistance);
SpongeCommon.post(event);
}
}
use of org.spongepowered.api.entity.living.player.server.ServerPlayer in project SpongeCommon by SpongePowered.
the class ServerPlayerMixin method impl$copyDataOnRespawn.
@Inject(method = "restoreFrom(Lnet/minecraft/server/level/ServerPlayer;Z)V", at = @At("HEAD"))
private void impl$copyDataOnRespawn(final net.minecraft.server.level.ServerPlayer oldPlayer, final boolean respawnFromEnd, final CallbackInfo ci) {
// Copy Sponge data
if (oldPlayer instanceof DataCompoundHolder) {
final DataCompoundHolder oldEntity = (DataCompoundHolder) oldPlayer;
DataUtil.syncDataToTag(oldEntity);
final CompoundTag compound = oldEntity.data$getCompound();
((DataCompoundHolder) this).data$setCompound(compound);
DataUtil.syncTagToData(this);
}
// Update boss bars
SpongeAdventure.forEachBossBar(bar -> ((BossEventBridge) bar).bridge$replacePlayer(oldPlayer, (net.minecraft.server.level.ServerPlayer) (Object) this));
}
use of org.spongepowered.api.entity.living.player.server.ServerPlayer in project SpongeCommon by SpongePowered.
the class ServerGamePacketListenerImplMixin method impl$handlePlayerDisconnect.
@Redirect(method = "onDisconnect", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V"))
public void impl$handlePlayerDisconnect(final PlayerList playerList, final net.minecraft.network.chat.Component component, final ChatType chatType, UUID uuid) {
// be fired either.
if (this.player.connection == null) {
return;
}
final ServerPlayer spongePlayer = (ServerPlayer) this.player;
try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
frame.pushCause(this.player);
final Component message = SpongeAdventure.asAdventure(component);
Audience audience = Sponge.server().broadcastAudience();
final ServerSideConnectionEvent.Disconnect event = SpongeEventFactory.createServerSideConnectionEventDisconnect(PhaseTracker.getCauseStackManager().currentCause(), audience, Optional.of(audience), message, message, spongePlayer.connection(), spongePlayer);
SpongeCommon.post(event);
event.audience().ifPresent(a -> a.sendMessage(spongePlayer, event.message()));
}
((ServerPlayerBridge) this.player).bridge$getWorldBorderListener().onPlayerDisconnect();
}
use of org.spongepowered.api.entity.living.player.server.ServerPlayer in project SpongeCommon by SpongePowered.
the class SpongeInventoryMenu method setCurrentInventory.
@Override
public void setCurrentInventory(ViewableInventory inventory) {
if (inventory.getClass().equals(this.inventory.getClass()) && inventory instanceof ViewableCustomInventory && inventory.capacity() == this.inventory.capacity()) {
this.inventory = inventory;
for (Map.Entry<Container, ServerPlayer> entry : this.tracked.entrySet()) {
final net.minecraft.world.inventory.AbstractContainerMenu container = (net.minecraft.world.inventory.AbstractContainerMenu) entry.getKey();
final ServerPlayer player = entry.getValue();
// create a new container for the viewable inventory
final net.minecraft.world.inventory.AbstractContainerMenu newContainer = ((ViewableCustomInventory) inventory).createMenu(-1, ((Player) player).inventory, (Player) player);
for (int i = 0; i < inventory.capacity(); i++) {
// And put its slots into the old container
final Slot slot = newContainer.slots.get(i);
container.slots.set(i, slot);
// Update Container items
((AbstractContainerMenuAccessor) container).accessor$lastSlots().set(i, slot.getItem());
}
// send update to Client
for (ContainerListener listener : ((AbstractContainerMenuAccessor) container).accessor$containerListeners()) {
listener.refreshContainer(container, ((AbstractContainerMenuAccessor) container).accessor$lastSlots());
}
}
} else {
// Get all distinct players and reopen inventory for them
this.inventory = inventory;
this.reopen();
}
}
use of org.spongepowered.api.entity.living.player.server.ServerPlayer in project SpongeCommon by SpongePowered.
the class AdvancementProgressMixin method impl$revokeCriterion.
private boolean impl$revokeCriterion(String rawCriterion) {
final net.minecraft.advancements.CriterionProgress criterionProgress = this.criteria.get(rawCriterion);
if (criterionProgress == null || !criterionProgress.isDone()) {
return false;
}
if (SpongeScoreCriterion.BYPASS_EVENT) {
criterionProgress.revoke();
return true;
}
final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
final ServerPlayer player = ((PlayerAdvancementsBridge) this.impl$playerAdvancements).bridge$getPlayer();
final CriterionProgress progress = (CriterionProgress) criterionProgress;
final AdvancementCriterion criterion = progress.criterion();
final CriterionBridge criterionBridge = (CriterionBridge) criterion;
// The score criterion needs special care
final SpongeScoreCriterion scoreCriterion = criterionBridge.bridge$getScoreCriterion();
final CriterionEvent event;
final Advancement advancement = ((org.spongepowered.api.advancement.AdvancementProgress) this).advancement();
if (scoreCriterion != null) {
final SpongeScoreCriterionProgress scoreProgress = (SpongeScoreCriterionProgress) this.impl$progressMap.get(scoreCriterion.name());
final int lastScore = scoreProgress.score();
final int score = lastScore + 1;
if (lastScore == scoreCriterion.goal()) {
event = SpongeEventFactory.createCriterionEventScoreRevoke(cause, advancement, scoreCriterion, player, lastScore, score);
} else if (score == scoreCriterion.goal()) {
event = SpongeEventFactory.createCriterionEventScoreGrant(cause, advancement, scoreCriterion, player, Instant.now(), lastScore, score);
} else {
event = SpongeEventFactory.createCriterionEventScoreChange(cause, advancement, scoreCriterion, player, lastScore, score);
}
} else {
event = SpongeEventFactory.createCriterionEventRevoke(cause, advancement, criterion, player);
}
if (SpongeCommon.post(event)) {
return false;
}
criterionProgress.revoke();
return true;
}
Aggregations