Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f2d37587d |
@@ -5,7 +5,7 @@ org.gradle.configuration-cache=false
|
|||||||
|
|
||||||
# Mod
|
# Mod
|
||||||
mod_id=video_player
|
mod_id=video_player
|
||||||
mod_version=0.4.30
|
mod_version=0.4.31
|
||||||
maven_group=com.ejclaw.videoplayer
|
maven_group=com.ejclaw.videoplayer
|
||||||
archives_base_name=video_player
|
archives_base_name=video_player
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.ejclaw.videoplayer.command;
|
||||||
|
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import net.minecraft.server.permissions.Permissions;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shared {@code .requires(...)} predicate for all {@code /video*} commands.
|
||||||
|
*
|
||||||
|
* <p>Semantics:
|
||||||
|
* <ul>
|
||||||
|
* <li><b>Player source</b> — must be OP (permission level ≥ 2, via
|
||||||
|
* {@link Permissions#COMMANDS_GAMEMASTER}). Non-OP players don't even see the command
|
||||||
|
* in tab-completion.</li>
|
||||||
|
* <li><b>Non-player source</b> — server console, command block, and datapack
|
||||||
|
* {@code /function} are always allowed regardless of any permission level
|
||||||
|
* or gamerule. This means admins don't need to bump {@code functionPermissionLevel}
|
||||||
|
* just to drive {@code /videoPlace} etc. from a datapack function.</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* <p>The bypass for non-player sources is safe because reaching one of those execution
|
||||||
|
* contexts already requires server-operator trust:
|
||||||
|
* <ul>
|
||||||
|
* <li>Console — physical/admin access to the server.</li>
|
||||||
|
* <li>Command block — placing one requires OP + {@code /gamerule sendCommandFeedback}
|
||||||
|
* privileges, and {@code /execute as} preserves the underlying source's permissions
|
||||||
|
* (so a non-OP player can't smuggle commands through one).</li>
|
||||||
|
* <li>Datapack function — installed by the server admin.</li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
public final class CommandPermissions {
|
||||||
|
private CommandPermissions() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} when the source is allowed to run a {@code /video*} command.
|
||||||
|
*
|
||||||
|
* <p>Player → OP only. Anything else → always allowed.
|
||||||
|
*/
|
||||||
|
public static boolean opOrServer(CommandSourceStack s) {
|
||||||
|
if (s.getEntity() instanceof Player) {
|
||||||
|
return s.permissions().hasPermission(Permissions.COMMANDS_GAMEMASTER);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,7 +20,6 @@ import net.minecraft.network.chat.MutableComponent;
|
|||||||
import net.minecraft.network.chat.Style;
|
import net.minecraft.network.chat.Style;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.server.permissions.Permissions;
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -32,8 +31,9 @@ import java.util.Map;
|
|||||||
* <br>{@code /videocache remove <name>} — drop the entry from server config and tell every client
|
* <br>{@code /videocache remove <name>} — drop the entry from server config and tell every client
|
||||||
* to delete the matching cache file.
|
* to delete the matching cache file.
|
||||||
*
|
*
|
||||||
* <p>Replaces the old {@code /videopreload}. Same permission gate
|
* <p>Replaces the old {@code /videopreload}. Permission gate via
|
||||||
* ({@link Permissions#COMMANDS_GAMEMASTER}) so command blocks can drive it.
|
* {@link CommandPermissions#opOrServer(CommandSourceStack)} so command blocks and datapack
|
||||||
|
* functions can drive it without touching {@code functionPermissionLevel}.
|
||||||
*/
|
*/
|
||||||
public final class VideoCacheCommand {
|
public final class VideoCacheCommand {
|
||||||
private VideoCacheCommand() {}
|
private VideoCacheCommand() {}
|
||||||
@@ -44,7 +44,7 @@ public final class VideoCacheCommand {
|
|||||||
|
|
||||||
private static LiteralArgumentBuilder<CommandSourceStack> build(String root) {
|
private static LiteralArgumentBuilder<CommandSourceStack> build(String root) {
|
||||||
return Commands.literal(root)
|
return Commands.literal(root)
|
||||||
.requires(s -> s.permissions().hasPermission(Permissions.COMMANDS_GAMEMASTER))
|
.requires(CommandPermissions::opOrServer)
|
||||||
.then(Commands.literal("add")
|
.then(Commands.literal("add")
|
||||||
.then(Commands.argument("name", StringArgumentType.word())
|
.then(Commands.argument("name", StringArgumentType.word())
|
||||||
.then(Commands.argument("url", StringArgumentType.greedyString())
|
.then(Commands.argument("url", StringArgumentType.greedyString())
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
|||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.permissions.Permissions;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
|
|
||||||
@@ -24,7 +23,7 @@ public final class VideoDeleteCommand {
|
|||||||
private static com.mojang.brigadier.builder.LiteralArgumentBuilder<CommandSourceStack>
|
private static com.mojang.brigadier.builder.LiteralArgumentBuilder<CommandSourceStack>
|
||||||
build(String name) {
|
build(String name) {
|
||||||
return Commands.literal(name)
|
return Commands.literal(name)
|
||||||
.requires(s -> s.permissions().hasPermission(Permissions.COMMANDS_GAMEMASTER))
|
.requires(CommandPermissions::opOrServer)
|
||||||
.then(Commands.argument("pos", BlockPosArgument.blockPos())
|
.then(Commands.argument("pos", BlockPosArgument.blockPos())
|
||||||
.executes(VideoDeleteCommand::run));
|
.executes(VideoDeleteCommand::run));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import net.minecraft.core.BlockPos;
|
|||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.server.permissions.Permissions;
|
|
||||||
|
|
||||||
/** SPEC §4.5.1 — {@code /videoMute <pos> <on|off>} */
|
/** SPEC §4.5.1 — {@code /videoMute <pos> <on|off>} */
|
||||||
public final class VideoMuteCommand {
|
public final class VideoMuteCommand {
|
||||||
@@ -27,7 +26,7 @@ public final class VideoMuteCommand {
|
|||||||
private static com.mojang.brigadier.builder.LiteralArgumentBuilder<CommandSourceStack>
|
private static com.mojang.brigadier.builder.LiteralArgumentBuilder<CommandSourceStack>
|
||||||
build(String name) {
|
build(String name) {
|
||||||
return Commands.literal(name)
|
return Commands.literal(name)
|
||||||
.requires(s -> s.permissions().hasPermission(Permissions.COMMANDS_GAMEMASTER))
|
.requires(CommandPermissions::opOrServer)
|
||||||
.then(Commands.argument("pos", BlockPosArgument.blockPos())
|
.then(Commands.argument("pos", BlockPosArgument.blockPos())
|
||||||
.then(Commands.argument("state", StringArgumentType.word())
|
.then(Commands.argument("state", StringArgumentType.word())
|
||||||
.executes(VideoMuteCommand::run)));
|
.executes(VideoMuteCommand::run)));
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import net.minecraft.nbt.CompoundTag;
|
|||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.server.permissions.Permissions;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,7 +52,7 @@ public final class VideoPlaceCommand {
|
|||||||
private static com.mojang.brigadier.builder.LiteralArgumentBuilder<CommandSourceStack>
|
private static com.mojang.brigadier.builder.LiteralArgumentBuilder<CommandSourceStack>
|
||||||
build(String name) {
|
build(String name) {
|
||||||
return Commands.literal(name)
|
return Commands.literal(name)
|
||||||
.requires(s -> s.permissions().hasPermission(Permissions.COMMANDS_GAMEMASTER))
|
.requires(CommandPermissions::opOrServer)
|
||||||
.then(Commands.argument("pos", BlockPosArgument.blockPos())
|
.then(Commands.argument("pos", BlockPosArgument.blockPos())
|
||||||
.then(Commands.argument("facing", StringArgumentType.word())
|
.then(Commands.argument("facing", StringArgumentType.word())
|
||||||
.then(Commands.argument("width", IntegerArgumentType.integer(1, 32))
|
.then(Commands.argument("width", IntegerArgumentType.integer(1, 32))
|
||||||
|
|||||||
@@ -6,18 +6,17 @@ import net.minecraft.commands.CommandSourceStack;
|
|||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.server.permissions.Permissions;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
public final class VideoStickCommand {
|
public final class VideoStickCommand {
|
||||||
private VideoStickCommand() {}
|
private VideoStickCommand() {}
|
||||||
|
|
||||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||||
// OP/console/command-block 만 사용 가능. Permissions.COMMANDS_GAMEMASTER = level 2,
|
// 플레이어는 OP(level 2+) 만, 콘솔/커맨드블럭/함수(/function) 는 무조건 통과.
|
||||||
// 즉 /op 받은 플레이어(level 4) 와 콘솔(level 4), command block(default level 2) 통과.
|
// 따라서 functionPermissionLevel 같은 gamerule 을 만질 필요가 없다.
|
||||||
// 일반 플레이어(level 0) 는 탭 자동완성에도 안 떠야 정상.
|
// 일반 플레이어(level 0) 는 탭 자동완성에도 안 떠야 정상.
|
||||||
dispatcher.register(Commands.literal("videoStick")
|
dispatcher.register(Commands.literal("videoStick")
|
||||||
.requires(s -> s.permissions().hasPermission(Permissions.COMMANDS_GAMEMASTER))
|
.requires(CommandPermissions::opOrServer)
|
||||||
.executes(ctx -> run(ctx.getSource())));
|
.executes(ctx -> run(ctx.getSource())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user