From 3727b745115259cd1ad7368e53e6bc4e10b6919a Mon Sep 17 00:00:00 2001 From: IzzelAliz Date: Wed, 23 Nov 2022 14:06:46 +0800 Subject: [PATCH] Update upstream --- .../core/network/NetworkManagerBridge.java | 4 +++ .../login/ServerLoginNetHandlerBridge.java | 8 ----- .../mixin/core/network/ConnectionMixin.java | 11 +++++++ .../ServerHandshakeNetHandlerMixin.java | 4 +-- .../network/ServerLoginNetHandlerMixin.java | 15 +-------- .../server/management/PlayerListMixin.java | 3 +- .../entity/player/ServerPlayerMixin.java | 26 ++++++++++++++++ .../entity/vehicle/MinecartTNTMixin.java | 31 +++++++++++++++++++ .../common/mod/util/ArclightPingEvent.java | 3 +- .../main/resources/mixins.arclight.core.json | 1 + 10 files changed, 78 insertions(+), 28 deletions(-) delete mode 100644 arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/network/login/ServerLoginNetHandlerBridge.java create mode 100644 arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/MinecartTNTMixin.java diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/network/NetworkManagerBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/network/NetworkManagerBridge.java index 09d18e46..76442a84 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/network/NetworkManagerBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/network/NetworkManagerBridge.java @@ -16,4 +16,8 @@ public interface NetworkManagerBridge { void bridge$setSpoofedProfile(Property[] spoofedProfile); SocketAddress bridge$getRawAddress(); + + String bridge$getHostname(); + + void bridge$setHostname(String hostname); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/network/login/ServerLoginNetHandlerBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/network/login/ServerLoginNetHandlerBridge.java deleted file mode 100644 index b3d3fc60..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/network/login/ServerLoginNetHandlerBridge.java +++ /dev/null @@ -1,8 +0,0 @@ -package io.izzel.arclight.common.bridge.core.network.login; - -public interface ServerLoginNetHandlerBridge { - - String bridge$getHostname(); - - void bridge$setHostname(String hostname); -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ConnectionMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ConnectionMixin.java index 1ae76a72..1a6d76bb 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ConnectionMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ConnectionMixin.java @@ -16,6 +16,7 @@ public class ConnectionMixin implements NetworkManagerBridge { @Shadow public Channel channel; public java.util.UUID spoofedUUID; public com.mojang.authlib.properties.Property[] spoofedProfile; + public String hostname; @Override public UUID bridge$getSpoofedUUID() { @@ -45,4 +46,14 @@ public class ConnectionMixin implements NetworkManagerBridge { public SocketAddress bridge$getRawAddress() { return getRawAddress(); } + + @Override + public String bridge$getHostname() { + return hostname; + } + + @Override + public void bridge$setHostname(String hostname) { + this.hostname = hostname; + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerHandshakeNetHandlerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerHandshakeNetHandlerMixin.java index 46c80b71..1f314962 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerHandshakeNetHandlerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerHandshakeNetHandlerMixin.java @@ -4,7 +4,6 @@ import com.google.gson.Gson; import com.mojang.authlib.properties.Property; import com.mojang.util.UUIDTypeAdapter; import io.izzel.arclight.common.bridge.core.network.NetworkManagerBridge; -import io.izzel.arclight.common.bridge.core.network.login.ServerLoginNetHandlerBridge; import net.minecraft.SharedConstants; import net.minecraft.network.Connection; import net.minecraft.network.ConnectionProtocol; @@ -49,6 +48,7 @@ public class ServerHandshakeNetHandlerMixin { @Overwrite public void handleIntention(ClientIntentionPacket packetIn) { if (!ServerLifecycleHooks.handleServerLogin(packetIn, this.connection)) return; + ((NetworkManagerBridge) this.connection).bridge$setHostname(packetIn.hostName + ":" + packetIn.port); switch (packetIn.getIntention()) { case LOGIN: { this.connection.setProtocol(ConnectionProtocol.LOGIN); @@ -108,8 +108,6 @@ public class ServerHandshakeNetHandlerMixin { ((NetworkManagerBridge) this.connection).bridge$setSpoofedProfile(gson.fromJson(split[3], Property[].class)); } } - ((ServerLoginNetHandlerBridge) this.connection.getPacketListener()).bridge$setHostname(packetIn.hostName + ":" + packetIn.port); - break; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerLoginNetHandlerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerLoginNetHandlerMixin.java index 08a861d5..c7518944 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerLoginNetHandlerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerLoginNetHandlerMixin.java @@ -3,7 +3,6 @@ package io.izzel.arclight.common.mixin.core.network; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import io.izzel.arclight.common.bridge.core.network.NetworkManagerBridge; -import io.izzel.arclight.common.bridge.core.network.login.ServerLoginNetHandlerBridge; import io.izzel.arclight.common.bridge.core.server.MinecraftServerBridge; import io.izzel.arclight.common.bridge.core.server.management.PlayerListBridge; import net.minecraft.DefaultUncaughtExceptionHandler; @@ -51,7 +50,7 @@ import java.util.concurrent.atomic.AtomicInteger; import static net.minecraft.server.network.ServerLoginPacketListenerImpl.isValidUsername; @Mixin(ServerLoginPacketListenerImpl.class) -public abstract class ServerLoginNetHandlerMixin implements ServerLoginNetHandlerBridge { +public abstract class ServerLoginNetHandlerMixin { // @formatter:off @Shadow private ServerLoginPacketListenerImpl.State state; @@ -69,18 +68,6 @@ public abstract class ServerLoginNetHandlerMixin implements ServerLoginNetHandle @Shadow @Nullable private static ProfilePublicKey validatePublicKey(@org.jetbrains.annotations.Nullable ProfilePublicKey.Data p_240244_, UUID p_240245_, SignatureValidator p_240246_, boolean p_240247_) throws ProfilePublicKey.ValidationException { return null; } // @formatter:on - public String hostname; - - @Override - public String bridge$getHostname() { - return hostname; - } - - @Override - public void bridge$setHostname(String hostname) { - this.hostname = hostname; - } - public void disconnect(final String s) { this.disconnect(Component.literal(s)); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerListMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerListMixin.java index bbe506af..64f9868d 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerListMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerListMixin.java @@ -7,7 +7,6 @@ import io.izzel.arclight.common.bridge.core.entity.EntityBridge; import io.izzel.arclight.common.bridge.core.entity.InternalEntityBridge; import io.izzel.arclight.common.bridge.core.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.core.network.NetworkManagerBridge; -import io.izzel.arclight.common.bridge.core.network.login.ServerLoginNetHandlerBridge; import io.izzel.arclight.common.bridge.core.network.play.ServerPlayNetHandlerBridge; import io.izzel.arclight.common.bridge.core.server.management.PlayerListBridge; import io.izzel.arclight.common.bridge.core.world.WorldBridge; @@ -225,7 +224,7 @@ public abstract class PlayerListMixin implements PlayerListBridge { ServerPlayer entity = new ServerPlayer(this.server, this.server.getLevel(Level.OVERWORLD), gameProfile, profilePublicKey); Player player = ((ServerPlayerEntityBridge) entity).bridge$getBukkitEntity(); - String hostname = handler == null ? "" : ((ServerLoginNetHandlerBridge) handler).bridge$getHostname(); + String hostname = handler == null ? "" : ((NetworkManagerBridge) handler.connection).bridge$getHostname(); InetAddress realAddress = handler == null ? ((InetSocketAddress) socketAddress).getAddress() : ((InetSocketAddress) ((NetworkManagerBridge) handler.connection).bridge$getRawAddress()).getAddress(); PlayerLoginEvent event = new PlayerLoginEvent(player, hostname, ((InetSocketAddress) socketAddress).getAddress(), realAddress); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/ServerPlayerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/ServerPlayerMixin.java index 78ff2442..b4d498e3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/ServerPlayerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/ServerPlayerMixin.java @@ -66,6 +66,7 @@ import net.minecraft.world.level.GameType; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.BiomeManager; import net.minecraft.world.level.block.NetherPortalBlock; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.border.WorldBorder; import net.minecraft.world.level.dimension.LevelStem; import net.minecraft.world.level.gameevent.GameEvent; @@ -93,6 +94,7 @@ import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.event.CraftPortalEvent; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; import org.bukkit.craftbukkit.v.scoreboard.CraftScoreboardManager; +import org.bukkit.craftbukkit.v.util.BlockStateListPopulator; import org.bukkit.craftbukkit.v.util.CraftChatMessage; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.bukkit.event.entity.PlayerDeathEvent; @@ -102,6 +104,7 @@ import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerLocaleChangeEvent; import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.world.PortalCreateEvent; import org.bukkit.inventory.MainHand; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -595,6 +598,29 @@ public abstract class ServerPlayerMixin extends PlayerMixin implements ServerPla return optional1; } + private transient BlockStateListPopulator arclight$populator; + + @Inject(method = "createEndPlatform", at = @At("HEAD")) + private void arclight$playerCreatePortalBegin(ServerLevel level, BlockPos pos, CallbackInfo ci) { + arclight$populator = new BlockStateListPopulator(level); + } + + @Redirect(method = "createEndPlatform", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + private boolean arclight$playerCreatePortal(ServerLevel instance, BlockPos pos, BlockState blockState) { + return arclight$populator.setBlock(pos, blockState, 3); + } + + @Inject(method = "createEndPlatform", at = @At("RETURN")) + private void arclight$playerCreatePortalEnd(ServerLevel level, BlockPos pos, CallbackInfo ci) { + var blockList = arclight$populator; + arclight$populator = null; + var portalEvent = new PortalCreateEvent((List) (List) blockList.getList(), ((WorldBridge) level).bridge$getWorld(), this.getBukkitEntity(), PortalCreateEvent.CreateReason.END_PLATFORM); + Bukkit.getPluginManager().callEvent(portalEvent); + if (!portalEvent.isCancelled()) { + blockList.updateList(); + } + } + private Either getBedResult(BlockPos blockposition, Direction enumdirection) { if (!this.isSleeping() && this.isAlive()) { if (!this.level.dimensionType().natural() || !this.level.dimensionType().bedWorks()) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/MinecartTNTMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/MinecartTNTMixin.java new file mode 100644 index 00000000..995a53e7 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/MinecartTNTMixin.java @@ -0,0 +1,31 @@ +package io.izzel.arclight.common.mixin.core.world.entity.vehicle; + +import io.izzel.arclight.mixin.Eject; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.vehicle.MinecartTNT; +import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.Level; +import org.bukkit.Bukkit; +import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(MinecartTNT.class) +public abstract class MinecartTNTMixin extends AbstractMinecartMixin { + + @Shadow private int fuse; + + @Eject(method = "explode", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;explode(Lnet/minecraft/world/entity/Entity;DDDFLnet/minecraft/world/level/Explosion$BlockInteraction;)Lnet/minecraft/world/level/Explosion;")) + private Explosion arclight$explode(Level level, Entity entity, double x, double y, double z, float radius, Explosion.BlockInteraction interaction, CallbackInfo ci) { + var event = new ExplosionPrimeEvent(this.getBukkitEntity(), radius, false); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + this.fuse = -1; + ci.cancel(); + return null; + } + return level.explode((MinecartTNT) (Object) this, x, y, z, event.getRadius(), event.getFire(), interaction); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightPingEvent.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightPingEvent.java index cdc193cc..a73ac151 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightPingEvent.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightPingEvent.java @@ -1,6 +1,7 @@ package io.izzel.arclight.common.mod.util; import io.izzel.arclight.common.bridge.core.entity.player.ServerPlayerEntityBridge; +import io.izzel.arclight.common.bridge.core.network.NetworkManagerBridge; import net.minecraft.network.Connection; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; @@ -22,7 +23,7 @@ public class ArclightPingEvent extends ServerListPingEvent { private final Object[] players; public ArclightPingEvent(Connection networkManager, MinecraftServer server) { - super(((InetSocketAddress) networkManager.getRemoteAddress()).getAddress(), server.getMotd(), server.previewsChat(), server.getPlayerList().getMaxPlayers()); + super(((NetworkManagerBridge) networkManager).bridge$getHostname(), ((InetSocketAddress) networkManager.getRemoteAddress()).getAddress(), server.getMotd(), server.previewsChat(), server.getPlayerList().getMaxPlayers()); this.icon = ((CraftServer) Bukkit.getServer()).getServerIcon(); this.players = server.getPlayerList().players.toArray(); } diff --git a/arclight-common/src/main/resources/mixins.arclight.core.json b/arclight-common/src/main/resources/mixins.arclight.core.json index ba984f8e..3de8a495 100644 --- a/arclight-common/src/main/resources/mixins.arclight.core.json +++ b/arclight-common/src/main/resources/mixins.arclight.core.json @@ -238,6 +238,7 @@ "world.entity.vehicle.BoatMixin", "world.entity.vehicle.ChestBoatMixin", "world.entity.vehicle.MinecartCommandBlock_MinecartCommandBaseMixin", + "world.entity.vehicle.MinecartTNTMixin", "world.food.FoodDataMixin", "world.gen.WorldGenRegionMixin", "world.gen.feature.structure.SwampHutPieceMixin",