use of org.spongepowered.asm.mixin.injection.Redirect 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.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MainMixin method impl$cacheBootstrapProperties.
@Redirect(method = "main", at = @At(value = "NEW", target = "net/minecraft/server/dedicated/DedicatedServerSettings"))
private static DedicatedServerSettings impl$cacheBootstrapProperties(final RegistryAccess p_i242100_1_, final Path p_i242100_2_) {
final DedicatedServerSettings provider = new DedicatedServerSettings(p_i242100_1_, p_i242100_2_);
final DedicatedServerProperties properties = provider.getProperties();
BootstrapProperties.init(properties.worldGenSettings, properties.gamemode, properties.difficulty, properties.pvp, properties.hardcore, true, properties.viewDistance, p_i242100_1_);
return provider;
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MainMixin method impl$configurePackRepository.
@Redirect(method = "main", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;getLevelPath(Lnet/minecraft/world/level/storage/LevelResource;)Ljava/nio/file/Path;"))
private static Path impl$configurePackRepository(final LevelStorageSource.LevelStorageAccess levelSave, final LevelResource folderName) {
final Path datapackDir = levelSave.getLevelPath(folderName);
final Lifecycle lifecycle = Launch.instance().lifecycle();
lifecycle.establishGlobalRegistries();
lifecycle.establishDataProviders();
lifecycle.callRegisterDataEvent();
lifecycle.callRegisterDataPackValueEvent(datapackDir);
return datapackDir;
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class PlayerAdvancementsMixin method impl$updateProgressOnUnregister.
@Nullable
@Redirect(method = "unregisterListeners", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/advancements/AdvancementProgress;getCriterion(Ljava/lang/String;)Lnet/minecraft/advancements/CriterionProgress;"))
private CriterionProgress impl$updateProgressOnUnregister(final AdvancementProgress advancementProgress, final String criterion) {
if (((PlatformEntityBridge) this.player).bridge$isFakePlayer()) {
return advancementProgress.getCriterion(criterion);
}
final org.spongepowered.api.advancement.Advancement advancement = ((org.spongepowered.api.advancement.AdvancementProgress) advancementProgress).advancement();
final AdvancementCriterion advancementCriterion = (AdvancementCriterion) ((Advancement) advancement).getCriteria().get(criterion);
final CriterionBridge criterionBridge = (CriterionBridge) advancementCriterion;
// Only remove the trigger once the goal is reached
if (criterionBridge.bridge$getScoreCriterion() != null && !((org.spongepowered.api.advancement.AdvancementProgress) advancementProgress).get(criterionBridge.bridge$getScoreCriterion()).get().achieved()) {
return null;
}
return advancementProgress.getCriterion(criterion);
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class PlayerAdvancementsMixin method impl$onUnregisterListenersGetProgress.
@Redirect(method = "registerListeners(Lnet/minecraft/advancements/Advancement;)V", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/advancements/CriterionProgress;isDone()Z"))
private boolean impl$onUnregisterListenersGetProgress(final CriterionProgress progress) {
final CriterionProgressBridge mixinCriterionProgress = (CriterionProgressBridge) progress;
if (((PlatformEntityBridge) this.player).bridge$isFakePlayer() || !mixinCriterionProgress.bridge$isCriterionAvailable()) {
return progress.isDone();
}
final AdvancementCriterion criterion = ((org.spongepowered.api.advancement.criteria.CriterionProgress) progress).criterion();
final CriterionBridge mixinCriterion = (CriterionBridge) criterion;
// Only remove the trigger once the goal is reached
if (mixinCriterion.bridge$getScoreCriterion() != null) {
return ((CriterionProgressBridge) progress).bridge$getAdvancementProgress().get(mixinCriterion.bridge$getScoreCriterion()).get().achieved();
}
return progress.isDone();
}
Aggregations