|
| 1 | +package io.github.optijava.opt_carpet_addition.mixins.showDetailWhenFakePlayerJoin; |
| 2 | + |
| 3 | +import carpet.CarpetServer; |
| 4 | +import carpet.commands.PlayerCommand; |
| 5 | +import com.mojang.brigadier.arguments.StringArgumentType; |
| 6 | +import com.mojang.brigadier.context.CommandContext; |
| 7 | +import io.github.optijava.opt_carpet_addition.OptCarpetAddition; |
| 8 | +import net.minecraft.server.command.ServerCommandSource; |
| 9 | +import org.spongepowered.asm.mixin.Mixin; |
| 10 | +import org.spongepowered.asm.mixin.injection.At; |
| 11 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 12 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 13 | + |
| 14 | +@Mixin(PlayerCommand.class) |
| 15 | +public class PlayerCommand_Mixin { |
| 16 | + @Inject(at = @At("TAIL"), method = "spawn(Lcom/mojang/brigadier/context/CommandContext;)I", cancellable = true) |
| 17 | + public void injectSpawn(CommandContext<ServerCommandSource> context, CallbackInfo info) { |
| 18 | + if (context.getSource().getEntity() == null) { |
| 19 | + CarpetServer.minecraft_server.getCommandManager().execute(CarpetServer.minecraft_server.getCommandSource(), "tell @a Unexpected exception occurred when show fake player details: Can't show details because 'context.getSource().getEntity()' is null."); |
| 20 | + OptCarpetAddition.LOGGER.warn("Unexpected exception occurred when show fake player details: Can't show details because 'context.getSource().getEntity()' is null."); |
| 21 | + info.cancel(); |
| 22 | + } |
| 23 | + CarpetServer.minecraft_server.getCommandManager().execute(CarpetServer.minecraft_server.getCommandSource(), "tell @a Fake player " + StringArgumentType.getString(context, "player") + " was summoned by " + context.getSource().getName() + " in " + context.getSource().getWorld().toString() + "@" + context.getSource().getEntity().getX() + "/" + context.getSource().getEntity().getY() + "/" + context.getSource().getEntity().getZ()); |
| 24 | + OptCarpetAddition.LOGGER.info("Fake player " + StringArgumentType.getString(context, "player") + " was summoned by " + context.getSource().getName() + " in " + context.getSource().getWorld().toString() + "@" + context.getSource().getEntity().getX() + "/" + context.getSource().getEntity().getY() + "/" + context.getSource().getEntity().getZ()); |
| 25 | + } |
| 26 | +} |
0 commit comments