Skip to content

Commit

Permalink
Add command to spoof a player into spectator
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrptonaught committed Jun 26, 2024
1 parent 70b61aa commit c7410f6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ yarn_mappings=1.21+build.2
loader_version=0.15.11

# Fabric API
fabric_version=0.100.3+1.21
fabric_version=0.100.4+1.21

# Mod Properties
mod_version=1.1.0-1.21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static void updateWorldBorderToAll(List<ServerPlayerEntity> players, Worl
}

private static boolean hasLCH(ServerPlayerEntity player) {
return ServerPlayNetworking.canSend(player, CustomWorldBorderNetworking.CUSTOM_BORDER_PACKET);
return ServerPlayNetworking.canSend(player, CustomWorldBorderPacket.PACKET_ID);
}

public static class SyncedBorder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.kyrptonaught.serverutils.ServerUtilsMod;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;

public class CustomWorldBorderNetworking {
public static final Identifier CUSTOM_BORDER_PACKET = Identifier.of(ServerUtilsMod.CustomWorldBorder.getMOD_ID(), "customborder");


public static void sendCustomWorldBorderPacket(ServerPlayerEntity player, double xCenter, double zCenter, double xSize, double zSize) {
ServerPlayNetworking.send(player, new CustomWorldBorderPacket(xCenter, zCenter, xSize, zSize));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static SyncKeybindsPacket read(RegistryByteBuf buf) {
}

public void write(RegistryByteBuf buf) {
buf.writeInt(keybinds.size());
keybinds.forEach((s, keybindConfigItem) -> keybindConfigItem.writeToPacket(s, buf));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.kyrptonaught.serverutils.utilityCommands;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import net.kyrptonaught.serverutils.Module;
import net.minecraft.command.argument.BlockPosArgumentType;
Expand All @@ -10,6 +11,7 @@
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.network.packet.s2c.play.EntityAttributesS2CPacket;
import net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.FunctionCommand;
Expand All @@ -18,6 +20,7 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.GameMode;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -96,6 +99,25 @@ public void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher)
}
}

return 1;
}))));

dispatcher.register(CommandManager.literal("spoofspectator")
.requires((source) -> source.hasPermissionLevel(2))
.then(CommandManager.argument("player", EntityArgumentType.players())
.then(CommandManager.argument("spoof", BoolArgumentType.bool())
.executes(context -> {
Collection<ServerPlayerEntity> players = EntityArgumentType.getPlayers(context, "player");
boolean spoof = BoolArgumentType.getBool(context, "spoof");

for (ServerPlayerEntity player : players) {
if (spoof) {
player.networkHandler.sendPacket(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.GAME_MODE_CHANGED, (float) GameMode.SPECTATOR.getId()));
} else {
player.networkHandler.sendPacket(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.GAME_MODE_CHANGED, (float) player.interactionManager.getGameMode().getId()));
}
}

return 1;
}))));
}
Expand Down

0 comments on commit c7410f6

Please sign in to comment.