32 lines
1.3 KiB
Java
32 lines
1.3 KiB
Java
|
package net.minecraft.server.commands;
|
||
|
|
||
|
import com.mojang.brigadier.CommandDispatcher;
|
||
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||
|
import com.mojang.brigadier.context.CommandContext;
|
||
|
import net.minecraft.commands.CommandSourceStack;
|
||
|
import net.minecraft.commands.Commands;
|
||
|
import net.minecraft.network.chat.Component;
|
||
|
|
||
|
public class SetPlayerIdleTimeoutCommand {
|
||
|
public static void register(CommandDispatcher<CommandSourceStack> p_138635_) {
|
||
|
p_138635_.register(
|
||
|
Commands.literal("setidletimeout")
|
||
|
.requires(p_138639_ -> p_138639_.hasPermission(3))
|
||
|
.then(
|
||
|
Commands.argument("minutes", IntegerArgumentType.integer(0))
|
||
|
.executes(p_138637_ -> setIdleTimeout(p_138637_.getSource(), IntegerArgumentType.getInteger(p_138637_, "minutes")))
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
private static int setIdleTimeout(CommandSourceStack p_138641_, int p_138642_) {
|
||
|
p_138641_.getServer().setPlayerIdleTimeout(p_138642_);
|
||
|
if (p_138642_ > 0) {
|
||
|
p_138641_.sendSuccess(() -> Component.translatable("commands.setidletimeout.success", p_138642_), true);
|
||
|
} else {
|
||
|
p_138641_.sendSuccess(() -> Component.translatable("commands.setidletimeout.success.disabled"), true);
|
||
|
}
|
||
|
|
||
|
return p_138642_;
|
||
|
}
|
||
|
}
|