Search in sources :

Example 71 with Redirect

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();
}
Also used : Audience(net.kyori.adventure.audience.Audience) CauseStackManager(org.spongepowered.api.event.CauseStackManager) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) ServerSideConnectionEvent(org.spongepowered.api.event.network.ServerSideConnectionEvent) Component(net.kyori.adventure.text.Component) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 72 with Redirect

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;
}
Also used : DedicatedServerSettings(net.minecraft.server.dedicated.DedicatedServerSettings) DedicatedServerProperties(net.minecraft.server.dedicated.DedicatedServerProperties) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 73 with Redirect

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;
}
Also used : Path(java.nio.file.Path) Lifecycle(org.spongepowered.common.launch.Lifecycle) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 74 with Redirect

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);
}
Also used : AdvancementProgress(net.minecraft.advancements.AdvancementProgress) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) PlatformEntityBridge(org.spongepowered.common.bridge.world.entity.PlatformEntityBridge) Advancement(net.minecraft.advancements.Advancement) CriterionBridge(org.spongepowered.common.bridge.advancements.CriterionBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect) Nullable(javax.annotation.Nullable)

Example 75 with Redirect

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();
}
Also used : AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) CriterionProgressBridge(org.spongepowered.common.bridge.advancements.CriterionProgressBridge) CriterionProgress(net.minecraft.advancements.CriterionProgress) CriterionBridge(org.spongepowered.common.bridge.advancements.CriterionBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

Redirect (org.spongepowered.asm.mixin.injection.Redirect)165 CauseStackManager (org.spongepowered.api.event.CauseStackManager)25 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)15 ItemStack (net.minecraft.item.ItemStack)13 EffectTransactor (org.spongepowered.common.event.tracking.context.transaction.EffectTransactor)13 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)12 TransactionalCaptureSupplier (org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier)11 ArrayList (java.util.ArrayList)9 ItemStack (net.minecraft.world.item.ItemStack)9 Nullable (javax.annotation.Nullable)8 Vector3d (com.flowpowered.math.vector.Vector3d)7 World (net.minecraft.world.World)7 ServerLocation (org.spongepowered.api.world.server.ServerLocation)7 DamageSourceBridge (org.spongepowered.common.bridge.world.damagesource.DamageSourceBridge)7 IPhaseState (org.spongepowered.common.event.tracking.IPhaseState)7 IBlockState (net.minecraft.block.state.IBlockState)6 Entity (net.minecraft.entity.Entity)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 ServerLevel (net.minecraft.server.level.ServerLevel)6 EntityItem (net.minecraft.entity.item.EntityItem)5