AFK command

credit goes to isnortkoolaid
This commit is contained in:
Chipmunk 2024-01-12 20:58:20 -05:00
parent 9a73735f83
commit 0b8b79b02a
4 changed files with 66 additions and 0 deletions

View file

@ -22,6 +22,7 @@ public class Extras implements ModInitializer {
}
public static void registerCommands (CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess commandRegistryAccess, CommandManager.RegistrationEnvironment environment) {
AFKCommand.register(dispatcher);
ClearChatCommand.register(dispatcher);
PingCommand.register(dispatcher);
SpawnCoordinatesCommand.register(dispatcher);

View file

@ -0,0 +1,54 @@
package land.chipmunk.tgbextras.commands;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import static net.minecraft.server.command.CommandManager.literal;
import land.chipmunk.tgbextras.modules.PlayerExtensions;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
public class AFKCommand {
public static void register (CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(
literal("afk")
.executes(AFKCommand::AFKCommand)
);
}
public static int AFKCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
final ServerCommandSource source = context.getSource();
final ServerPlayerEntity player = source.getPlayerOrThrow();
PlayerExtensions playerEx = (PlayerExtensions) player;
playerEx.afk(!playerEx.afk());
if (playerEx.afk()) {
player.addStatusEffect(new StatusEffectInstance(StatusEffects.RESISTANCE, 2147483647, 4, true, false));
player.addStatusEffect(new StatusEffectInstance(StatusEffects.BLINDNESS, 2147483647, 99, true, false));
player.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, 2147483647, 99, true, false));
player.addStatusEffect(new StatusEffectInstance(StatusEffects.WEAKNESS, 2147483647, 99, true, false));
player.addStatusEffect(new StatusEffectInstance(StatusEffects.MINING_FATIGUE, 2147483647, 99, true, false));
source.getServer().getPlayerManager().broadcast(
Text.literal("* ")
.append(player.getDisplayName())
.append(Text.literal(" is now afk"))
, false);
} else {
player.clearStatusEffects();
source.getServer().getPlayerManager().broadcast(
Text.literal("* ")
.append(player.getDisplayName())
.append(Text.literal(" is no longer afk"))
, false);
}
return Command.SINGLE_SUCCESS;
}
}

View file

@ -12,6 +12,7 @@ import land.chipmunk.tgbextras.modules.PlayerExtensions;
@Mixin(ServerPlayerEntity.class)
public abstract class ServerPlayerEntityMixin implements PlayerExtensions {
private ServerPlayerEntity lastTeleportRequestor = null;
private boolean afk = false;
public ServerPlayerEntity lastTeleportRequestor () {
return lastTeleportRequestor;
@ -20,4 +21,12 @@ public abstract class ServerPlayerEntityMixin implements PlayerExtensions {
public ServerPlayerEntity lastTeleportRequestor (ServerPlayerEntity lastTeleportRequestor) {
return (this.lastTeleportRequestor = lastTeleportRequestor);
}
public boolean afk () {
return afk;
}
public boolean afk (boolean afk) {
return (this.afk = afk);
}
}

View file

@ -5,4 +5,6 @@ import net.minecraft.server.network.ServerPlayerEntity;
public interface PlayerExtensions {
ServerPlayerEntity lastTeleportRequestor ();
ServerPlayerEntity lastTeleportRequestor (ServerPlayerEntity lastTeleportRequestor);
boolean afk ();
boolean afk (boolean afk);
}