Search in sources :

Example 31 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project pingspam by BasiqueEvangelist.

the class AliasCommand method listPlayerAliases.

private static int listPlayerAliases(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
    ServerCommandSource src = ctx.getSource();
    ServerPlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
    List<String> aliases = PlayerUtils.getAliasesOf(player);
    StringBuilder headerBuilder = new StringBuilder();
    StringBuilder contentBuilder = new StringBuilder();
    headerBuilder.append(" has ");
    headerBuilder.append(aliases.size());
    headerBuilder.append(" alias");
    if (aliases.size() != 1)
        headerBuilder.append("es");
    if (aliases.size() > 0) {
        headerBuilder.append(": ");
        boolean isFirst = true;
        for (String alias : aliases) {
            if (!isFirst)
                contentBuilder.append(", ");
            isFirst = false;
            contentBuilder.append(alias);
        }
    } else {
        headerBuilder.append('.');
    }
    src.sendFeedback(new LiteralText(player.getEntityName()).formatted(Formatting.AQUA).append(new LiteralText(headerBuilder.toString()).formatted(Formatting.GREEN)).append(new LiteralText(contentBuilder.toString()).formatted(Formatting.YELLOW)), false);
    return 0;
}
Also used : ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LiteralText(net.minecraft.text.LiteralText)

Example 32 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project ImmersivePortalsMod by qouteall.

the class MyCommandServer method processPortalTargetedCommand.

public static int processPortalTargetedCommand(CommandContext<ServerCommandSource> context, Consumer<Portal> processCommand) throws CommandSyntaxException {
    ServerCommandSource source = context.getSource();
    ServerPlayerEntity player = source.getPlayer();
    if (player == null) {
        source.sendFeedback(new LiteralText("Only player can use this command"), true);
        return 0;
    }
    Portal portal = getPlayerPointingPortal(player);
    if (portal == null) {
        source.sendFeedback(new LiteralText("You are not pointing to any portal"), true);
        return 0;
    } else {
        processCommand.accept(portal);
    }
    return 0;
}
Also used : VerticalConnectingPortal(com.qouteall.immersive_portals.portal.global_portals.VerticalConnectingPortal) Portal(com.qouteall.immersive_portals.portal.Portal) BorderPortal(com.qouteall.immersive_portals.portal.global_portals.BorderPortal) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LiteralText(net.minecraft.text.LiteralText)

Example 33 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project ImmersivePortalsMod by qouteall.

the class MyCommandClient method register.

public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
    // for composite command arguments, put into then() 's bracket
    // for parallel command arguments, put behind then()
    LiteralArgumentBuilder<ServerCommandSource> builder = CommandManager.literal("immersive_portals_debug").requires(commandSource -> true).then(CommandManager.literal("set_max_portal_layer").then(CommandManager.argument("argMaxPortalLayer", IntegerArgumentType.integer()).executes(context -> setMaxPortalLayer(IntegerArgumentType.getInteger(context, "argMaxPortalLayer")))));
    builder = builder.then(CommandManager.literal("list_nearby_portals").executes(context -> listNearbyPortals(context)));
    builder = builder.then(CommandManager.literal("is_client_chunk_loaded").then(CommandManager.argument("chunkX", IntegerArgumentType.integer()).then(CommandManager.argument("chunkZ", IntegerArgumentType.integer()).executes(MyCommandClient::isClientChunkLoaded))));
    builder = builder.then(CommandManager.literal("is_server_chunk_loaded").then(CommandManager.argument("chunkX", IntegerArgumentType.integer()).then(CommandManager.argument("chunkZ", IntegerArgumentType.integer()).executes(context -> {
        int chunkX = IntegerArgumentType.getInteger(context, "chunkX");
        int chunkZ = IntegerArgumentType.getInteger(context, "chunkZ");
        ServerPlayerEntity player = context.getSource().getPlayer();
        Chunk chunk = McHelper.getServer().getWorld(player.dimension).getChunk(chunkX, chunkZ, ChunkStatus.FULL, false);
        McHelper.serverLog(player, chunk != null && !(chunk instanceof EmptyChunk) ? "yes" : "no");
        return 0;
    }))));
    builder = builder.then(CommandManager.literal("add_portal").executes(context -> addPortal(context)));
    builder = builder.then(CommandManager.literal("report_player_status").executes(context -> reportPlayerStatus(context)));
    builder = builder.then(CommandManager.literal("client_remote_ticking_enable").executes(context -> {
        CGlobal.isClientRemoteTickingEnabled = true;
        return 0;
    }));
    builder = builder.then(CommandManager.literal("client_remote_ticking_disable").executes(context -> {
        CGlobal.isClientRemoteTickingEnabled = false;
        return 0;
    }));
    builder = builder.then(CommandManager.literal("advanced_frustum_culling_enable").executes(context -> {
        CGlobal.doUseAdvancedFrustumCulling = true;
        return 0;
    }));
    builder = builder.then(CommandManager.literal("advanced_frustum_culling_disable").executes(context -> {
        CGlobal.doUseAdvancedFrustumCulling = false;
        return 0;
    }));
    builder = builder.then(CommandManager.literal("multithreaded_chunk_loading_enable").executes(context -> {
        SGlobal.isChunkLoadingMultiThreaded = true;
        return 0;
    }));
    builder = builder.then(CommandManager.literal("multithreaded_chunk_loading_disable").executes(context -> {
        SGlobal.isChunkLoadingMultiThreaded = false;
        return 0;
    }));
    builder = builder.then(CommandManager.literal("hacked_chunk_render_dispatcher_enable").executes(context -> {
        CGlobal.useHackedChunkRenderDispatcher = true;
        return 0;
    }));
    builder = builder.then(CommandManager.literal("hacked_chunk_render_dispatcher_disable").executes(context -> {
        CGlobal.useHackedChunkRenderDispatcher = false;
        return 0;
    }));
    builder = builder.then(CommandManager.literal("front_culling_enable").executes(context -> {
        CGlobal.useFrontCulling = true;
        return 0;
    }));
    builder = builder.then(CommandManager.literal("front_culling_disable").executes(context -> {
        CGlobal.useFrontCulling = false;
        return 0;
    }));
    builder = builder.then(CommandManager.literal("switch_to_normal_renderer").executes(context -> {
        MinecraftClient.getInstance().execute(() -> {
            CGlobal.useCompatibilityRenderer = false;
        });
        return 0;
    }));
    builder = builder.then(CommandManager.literal("switch_to_compatibility_renderer").executes(context -> {
        MinecraftClient.getInstance().execute(() -> {
            CGlobal.useCompatibilityRenderer = true;
        });
        return 0;
    }));
    builder = builder.then(CommandManager.literal("report_server_entities").executes(context -> {
        ServerPlayerEntity player = context.getSource().getPlayer();
        List<Entity> entities = player.world.getEntities(Entity.class, new Box(player.getBlockPos()).expand(32));
        McHelper.serverLog(player, entities.toString());
        return 0;
    }));
    builder = builder.then(CommandManager.literal("report_resource_consumption").executes(MyCommandClient::reportResourceConsumption));
    builder = builder.then(CommandManager.literal("report_render_info_num").executes(context -> {
        String str = Helper.myToString(CGlobal.renderInfoNumMap.entrySet().stream());
        context.getSource().getPlayer().sendMessage(new LiteralText(str));
        return 0;
    }));
    builder = builder.then(CommandManager.literal("rebuild_all").executes(context -> {
        MinecraftClient.getInstance().execute(() -> {
            ((IEChunkRenderDispatcher) ((IEWorldRenderer) MinecraftClient.getInstance().worldRenderer).getChunkRenderDispatcher()).rebuildAll();
        });
        return 0;
    }));
    builder = builder.then(CommandManager.literal("shader_debug_enable").executes(context -> {
        CGlobal.isRenderDebugMode = true;
        return 0;
    }));
    builder = builder.then(CommandManager.literal("shader_debug_disable").executes(context -> {
        CGlobal.isRenderDebugMode = false;
        return 0;
    }));
    builder = builder.then(CommandManager.literal("get_player_colliding_portal_client").executes(context -> {
        Portal collidingPortal = ((IEEntity) MinecraftClient.getInstance().player).getCollidingPortal();
        McHelper.serverLog(context.getSource().getPlayer(), collidingPortal.toString());
        return 0;
    }));
    builder = builder.then(CommandManager.literal("report_rendering").executes(context -> {
        String str = MyRenderHelper.lastPortalRenderInfos.stream().map(list -> list.stream().map(Reference::get).collect(Collectors.toList())).collect(Collectors.toList()).toString();
        McHelper.serverLog(context.getSource().getPlayer(), str);
        return 0;
    }));
    builder = builder.then(CommandManager.literal("debug_mirror_mode_enable").executes(context -> {
        CGlobal.debugMirrorMode = true;
        return 0;
    }));
    builder = builder.then(CommandManager.literal("debug_mirror_mode_disable").executes(context -> {
        CGlobal.debugMirrorMode = false;
        return 0;
    }));
    builder = builder.then(CommandManager.literal("test_riding").executes(context -> {
        ServerPlayerEntity player = context.getSource().getPlayer();
        MinecartEntity minecart = EntityType.MINECART.create(player.world);
        minecart.setPosition(player.x + 1, player.y, player.z);
        player.world.spawnEntity(minecart);
        player.startRiding(minecart, true);
        return 0;
    }));
    builder = builder.then(CommandManager.literal("report_fog_color").executes(MyCommandClient::reportFogColor));
    builder = builder.then(CommandManager.literal("uniform_report_hand").executes(context -> {
        OFGlobal.debugFunc = program -> {
            String name = program.getName();
            if (name.equals("gbuffers_hand") || name.equals("gbuffers_hand_water")) {
                try {
                    ServerPlayerEntity player = context.getSource().getPlayer();
                    UniformReport.reportUniforms(program.getId(), s -> McHelper.serverLog(player, s));
                    OFGlobal.debugFunc = p -> {
                    };
                } catch (CommandSyntaxException e) {
                    e.printStackTrace();
                    return;
                }
            }
        };
        return 0;
    }));
    builder = builder.then(CommandManager.literal("teleport_on_rendering_enable").executes(context -> {
        CGlobal.teleportOnRendering = true;
        return 0;
    }));
    builder = builder.then(CommandManager.literal("teleport_on_rendering_disable").executes(context -> {
        CGlobal.teleportOnRendering = false;
        return 0;
    }));
    builder.then(CommandManager.literal("report_chunk_loaders").executes(context -> {
        ServerPlayerEntity player = context.getSource().getPlayer();
        ChunkVisibilityManager.getChunkLoaders(player).forEach(loader -> McHelper.serverLog(player, loader.toString()));
        return 0;
    }));
    dispatcher.register(builder);
    Helper.log("Successfully initialized command /immersive_portals_debug");
}
Also used : EntityType(net.minecraft.entity.EntityType) LiteralText(net.minecraft.text.LiteralText) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) BackgroundRenderer(net.minecraft.client.render.BackgroundRenderer) ServerWorld(net.minecraft.server.world.ServerWorld) Environment(net.fabricmc.api.Environment) CGlobal(com.qouteall.immersive_portals.CGlobal) Vec3d(net.minecraft.util.math.Vec3d) MinecartEntity(net.minecraft.entity.vehicle.MinecartEntity) EmptyChunk(net.minecraft.world.chunk.EmptyChunk) EnvType(net.fabricmc.api.EnvType) Chunk(net.minecraft.world.chunk.Chunk) SGlobal(com.qouteall.immersive_portals.SGlobal) MyRenderHelper(com.qouteall.immersive_portals.render.MyRenderHelper) Entity(net.minecraft.entity.Entity) MyClientChunkManager(com.qouteall.immersive_portals.chunk_loading.MyClientChunkManager) CommandContext(com.mojang.brigadier.context.CommandContext) OFGlobal(com.qouteall.immersive_portals.optifine_compatibility.OFGlobal) Box(net.minecraft.util.math.Box) UniformReport(com.qouteall.immersive_portals.optifine_compatibility.UniformReport) Helper(com.qouteall.immersive_portals.Helper) ChunkVisibilityManager(com.qouteall.immersive_portals.chunk_loading.ChunkVisibilityManager) Collectors(java.util.stream.Collectors) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) CommandManager(net.minecraft.server.command.CommandManager) Reference(java.lang.ref.Reference) Consumer(java.util.function.Consumer) McHelper(com.qouteall.immersive_portals.McHelper) List(java.util.List) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) com.qouteall.immersive_portals.ducks(com.qouteall.immersive_portals.ducks) DimensionType(net.minecraft.world.dimension.DimensionType) Portal(com.qouteall.immersive_portals.portal.Portal) ChunkStatus(net.minecraft.world.chunk.ChunkStatus) MinecraftClient(net.minecraft.client.MinecraftClient) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) IntegerArgumentType(com.mojang.brigadier.arguments.IntegerArgumentType) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) DimensionRenderHelper(com.qouteall.immersive_portals.render.DimensionRenderHelper) EmptyChunk(net.minecraft.world.chunk.EmptyChunk) MinecartEntity(net.minecraft.entity.vehicle.MinecartEntity) Entity(net.minecraft.entity.Entity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) MinecartEntity(net.minecraft.entity.vehicle.MinecartEntity) Reference(java.lang.ref.Reference) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Box(net.minecraft.util.math.Box) EmptyChunk(net.minecraft.world.chunk.EmptyChunk) Chunk(net.minecraft.world.chunk.Chunk) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) Portal(com.qouteall.immersive_portals.portal.Portal) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) LiteralText(net.minecraft.text.LiteralText)

Example 34 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project Geyser-Fabric by GeyserMC.

the class GeyserFabricCommandExecutor method run.

@Override
public int run(CommandContext context) {
    ServerCommandSource source = (ServerCommandSource) context.getSource();
    FabricCommandSender sender = new FabricCommandSender(source);
    GeyserSession session = getGeyserSession(sender);
    if (!canRun(source)) {
        sender.sendMessage(GeyserLocale.getLocaleStringLog("geyser.bootstrap.command.permission_fail"));
        return 0;
    }
    if (this.command.getName().equals("reload")) {
        GeyserFabricMod.getInstance().setReloading(true);
    }
    if (command.isBedrockOnly() && session == null) {
        sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", sender.getLocale()));
        return 0;
    }
    command.execute(session, sender, new String[0]);
    return 0;
}
Also used : GeyserSession(org.geysermc.geyser.session.GeyserSession) ServerCommandSource(net.minecraft.server.command.ServerCommandSource)

Example 35 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project KahzerxMod by otakucraft.

the class DiscordWhitelistSyncExtension method settingsCommand.

@Override
public void settingsCommand(LiteralArgumentBuilder<ServerCommandSource> builder) {
    builder.then(literal("notifyChatID").then(argument("chatID", LongArgumentType.longArg()).executes(context -> {
        extensionSettings().setNotifyChannelID(LongArgumentType.getLong(context, "chatID"));
        context.getSource().sendFeedback(new LiteralText("[notifyChatID] > " + extensionSettings().getNotifyChannelID() + "."), false);
        ExtensionManager.saveSettings();
        return 1;
    })).executes(context -> {
        String help = "Channel where you get notified when someone gets removed from the whitelist.";
        context.getSource().sendFeedback(new LiteralText(help), false);
        context.getSource().sendFeedback(new LiteralText("[notifyChatID] > " + extensionSettings().getNotifyChannelID() + "."), false);
        return 1;
    })).then(literal("groupID").then(argument("groupID", LongArgumentType.longArg()).executes(context -> {
        extensionSettings().setGroupID(LongArgumentType.getLong(context, "groupID"));
        context.getSource().sendFeedback(new LiteralText("[groupID] > " + extensionSettings().getGroupID() + "."), false);
        ExtensionManager.saveSettings();
        return 1;
    })).executes(context -> {
        String help = "ServerID, to know where to check members.";
        context.getSource().sendFeedback(new LiteralText(help), false);
        context.getSource().sendFeedback(new LiteralText("[groupID] > " + extensionSettings().getGroupID() + "."), false);
        return 1;
    })).then(literal("aggressive").then(argument("aggressive", BoolArgumentType.bool()).executes(context -> {
        extensionSettings().setAggressive(BoolArgumentType.getBool(context, "aggressive"));
        context.getSource().sendFeedback(new LiteralText("[aggressive] > " + extensionSettings().isAggressive() + "."), false);
        ExtensionManager.saveSettings();
        return 1;
    })).executes(context -> {
        String help = "Full whitelist/database sync.";
        context.getSource().sendFeedback(new LiteralText(help), false);
        context.getSource().sendFeedback(new LiteralText("[aggressive] > " + extensionSettings().isAggressive() + "."), false);
        return 1;
    })).then(literal("validRoles").then(literal("add").then(argument("roleID", LongArgumentType.longArg()).executes(context -> {
        if (extensionSettings().getValidRoles().contains(LongArgumentType.getLong(context, "roleID"))) {
            context.getSource().sendFeedback(new LiteralText("ID already added."), false);
        } else {
            extensionSettings().addValidRoleID(LongArgumentType.getLong(context, "roleID"));
            context.getSource().sendFeedback(new LiteralText("ID added."), false);
            ExtensionManager.saveSettings();
        }
        return 1;
    }))).then(literal("remove").then(argument("roleID", LongArgumentType.longArg()).executes(context -> {
        if (extensionSettings().getValidRoles().contains(LongArgumentType.getLong(context, "roleID"))) {
            extensionSettings().removeValidRoleID(LongArgumentType.getLong(context, "roleID"));
            context.getSource().sendFeedback(new LiteralText("ID removed."), false);
            ExtensionManager.saveSettings();
        } else {
            context.getSource().sendFeedback(new LiteralText("This ID doesn't exist."), false);
        }
        return 1;
    }))).then(literal("list").executes(context -> {
        context.getSource().sendFeedback(new LiteralText(extensionSettings().getValidRoles().toString()), false);
        return 1;
    })).executes(context -> {
        String help = "Role list that a member needs to have (at least one) so dont get kicked from the whitelist (ex: sub role).";
        context.getSource().sendFeedback(new LiteralText(help), false);
        return 1;
    }));
}
Also used : ExtensionSettings(com.kahzerx.kahzerxmod.extensions.ExtensionSettings) LiteralText(net.minecraft.text.LiteralText) GenericExtension(com.kahzerx.kahzerxmod.extensions.GenericExtension) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) DiscordExtension(com.kahzerx.kahzerxmod.extensions.discordExtension.discordExtension.DiscordExtension) LongArgumentType(com.mojang.brigadier.arguments.LongArgumentType) Extensions(com.kahzerx.kahzerxmod.Extensions) CommandManager.literal(net.minecraft.server.command.CommandManager.literal) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) CommandManager.argument(net.minecraft.server.command.CommandManager.argument) ExtensionManager(com.kahzerx.kahzerxmod.ExtensionManager) BoolArgumentType(com.mojang.brigadier.arguments.BoolArgumentType) MinecraftServer(net.minecraft.server.MinecraftServer) DiscordWhitelistExtension(com.kahzerx.kahzerxmod.extensions.discordExtension.discordWhitelistExtension.DiscordWhitelistExtension) LiteralText(net.minecraft.text.LiteralText)

Aggregations

ServerCommandSource (net.minecraft.server.command.ServerCommandSource)43 LiteralText (net.minecraft.text.LiteralText)35 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)33 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)14 CommandManager.literal (net.minecraft.server.command.CommandManager.literal)11 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)9 CommandManager.argument (net.minecraft.server.command.CommandManager.argument)9 Extensions (com.kahzerx.kahzerxmod.Extensions)7 GenericExtension (com.kahzerx.kahzerxmod.extensions.GenericExtension)7 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)6 UUID (java.util.UUID)6 CommandManager (net.minecraft.server.command.CommandManager)6 ExtensionSettings (com.kahzerx.kahzerxmod.extensions.ExtensionSettings)5 IntegerArgumentType (com.mojang.brigadier.arguments.IntegerArgumentType)5 StringArgumentType (com.mojang.brigadier.arguments.StringArgumentType)5 MinecraftServer (net.minecraft.server.MinecraftServer)5 ExtensionManager (com.kahzerx.kahzerxmod.ExtensionManager)4 GameProfile (com.mojang.authlib.GameProfile)4 ClickEvent (net.minecraft.text.ClickEvent)4 MutableText (net.minecraft.text.MutableText)4