Replace redundant code with shorter version
This commit is contained in:
parent
c2047ccd2c
commit
1aa225f700
18 changed files with 31 additions and 110 deletions
|
@ -18,11 +18,7 @@ public class FlyCommand {
|
|||
var rootCommand = literal("fly")
|
||||
.requires(Permissions.require("rcc.command.fly", 3))
|
||||
.executes(context -> {
|
||||
if (!context.getSource().isExecutedByPlayer()) {
|
||||
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return 1;
|
||||
}
|
||||
var player = context.getSource().getPlayer();
|
||||
var player = context.getSource().getPlayerOrThrow();
|
||||
context.getSource().sendFeedback(() -> toggleFlight(player), true);
|
||||
|
||||
return 1;
|
||||
|
|
|
@ -18,11 +18,7 @@ public class GodCommand {
|
|||
var rootCommand = literal("god")
|
||||
.requires(Permissions.require("rcc.command.god", 3))
|
||||
.executes(context -> {
|
||||
if (!context.getSource().isExecutedByPlayer()) {
|
||||
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return 1;
|
||||
}
|
||||
var player = context.getSource().getPlayer();
|
||||
var player = context.getSource().getPlayerOrThrow();
|
||||
context.getSource().sendFeedback(() -> toggleGod(player), true);
|
||||
|
||||
return 1;
|
||||
|
|
|
@ -5,6 +5,7 @@ import cc.reconnected.server.util.Components;
|
|||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import eu.pb4.placeholders.api.PlaceholderContext;
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.minecraft.command.CommandSource;
|
||||
|
@ -34,12 +35,8 @@ public class DeleteHomeCommand {
|
|||
dispatcher.register(rootCommand);
|
||||
}
|
||||
|
||||
private static int execute(CommandContext<ServerCommandSource> context, String name) {
|
||||
if (!context.getSource().isExecutedByPlayer()) {
|
||||
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return 1;
|
||||
}
|
||||
var player = context.getSource().getPlayer();
|
||||
private static int execute(CommandContext<ServerCommandSource> context, String name) throws CommandSyntaxException {
|
||||
var player = context.getSource().getPlayerOrThrow();
|
||||
var playerState = RccServer.state.getPlayerState(player.getUuid());
|
||||
var homes = playerState.homes;
|
||||
var playerContext = PlaceholderContext.of(context.getSource().getPlayer());
|
||||
|
|
|
@ -5,6 +5,7 @@ import cc.reconnected.server.util.Components;
|
|||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import eu.pb4.placeholders.api.PlaceholderContext;
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.minecraft.command.CommandSource;
|
||||
|
@ -34,12 +35,8 @@ public class HomeCommand {
|
|||
dispatcher.register(rootCommand);
|
||||
}
|
||||
|
||||
private static int execute(CommandContext<ServerCommandSource> context, String name) {
|
||||
if (!context.getSource().isExecutedByPlayer()) {
|
||||
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return 1;
|
||||
}
|
||||
var player = context.getSource().getPlayer();
|
||||
private static int execute(CommandContext<ServerCommandSource> context, String name) throws CommandSyntaxException {
|
||||
var player = context.getSource().getPlayerOrThrow();
|
||||
var playerState = RccServer.state.getPlayerState(player.getUuid());
|
||||
var homes = playerState.homes;
|
||||
var playerContext = PlaceholderContext.of(context.getSource().getPlayer());
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.mojang.brigadier.CommandDispatcher;
|
|||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import eu.pb4.placeholders.api.PlaceholderContext;
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
|
@ -36,12 +37,8 @@ public class SetHomeCommand {
|
|||
dispatcher.register(rootCommand);
|
||||
}
|
||||
|
||||
private static int execute(CommandContext<ServerCommandSource> context, String name, boolean forced) {
|
||||
if (!context.getSource().isExecutedByPlayer()) {
|
||||
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return 1;
|
||||
}
|
||||
var player = context.getSource().getPlayer();
|
||||
private static int execute(CommandContext<ServerCommandSource> context, String name, boolean forced) throws CommandSyntaxException {
|
||||
var player = context.getSource().getPlayerOrThrow();
|
||||
var playerState = RccServer.state.getPlayerState(player.getUuid());
|
||||
var homes = playerState.homes;
|
||||
var playerContext = PlaceholderContext.of(player);
|
||||
|
|
|
@ -13,13 +13,7 @@ public class AfkCommand {
|
|||
var rootCommand = literal("afk")
|
||||
.requires(Permissions.require("rcc.command.afk", true))
|
||||
.executes(context -> {
|
||||
|
||||
if (!context.getSource().isExecutedByPlayer()) {
|
||||
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
var player = context.getSource().getPlayer();
|
||||
var player = context.getSource().getPlayerOrThrow();
|
||||
AfkTracker.getInstance().setPlayerAfk(player, true);
|
||||
|
||||
return 1;
|
||||
|
|
|
@ -22,21 +22,9 @@ public class NearCommand {
|
|||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||
var rootCommand = literal("near")
|
||||
.requires(Permissions.require("rcc.command.near", 2))
|
||||
.executes(context -> {
|
||||
if (!context.getSource().isExecutedByPlayer()) {
|
||||
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return 1;
|
||||
}
|
||||
return execute(context, RccServer.CONFIG.nearCommand.nearCommandDefaultRange, context.getSource().getPlayer());
|
||||
})
|
||||
.executes(context -> execute(context, RccServer.CONFIG.nearCommand.nearCommandDefaultRange, context.getSource().getPlayerOrThrow()))
|
||||
.then(argument("radius", IntegerArgumentType.integer(0, RccServer.CONFIG.nearCommand.nearCommandMaxRange))
|
||||
.executes(context -> {
|
||||
if (!context.getSource().isExecutedByPlayer()) {
|
||||
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return 1;
|
||||
}
|
||||
return execute(context, IntegerArgumentType.getInteger(context, "radius"), context.getSource().getPlayer());
|
||||
}));
|
||||
.executes(context -> execute(context, IntegerArgumentType.getInteger(context, "radius"), context.getSource().getPlayerOrThrow())));
|
||||
|
||||
dispatcher.register(rootCommand);
|
||||
}
|
||||
|
|
|
@ -15,12 +15,7 @@ public class SetSpawnCommand {
|
|||
var rootCommand = literal("setspawn")
|
||||
.requires(Permissions.require("rcc.command.setspawn", 3))
|
||||
.executes(context -> {
|
||||
if (!context.getSource().isExecutedByPlayer()) {
|
||||
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
var player = context.getSource().getPlayer();
|
||||
var player = context.getSource().getPlayerOrThrow();
|
||||
var spawnPosition = new ServerPosition(player);
|
||||
|
||||
var serverState = RccServer.state.getServerState();
|
||||
|
|
|
@ -16,12 +16,7 @@ public class SpawnCommand {
|
|||
var rootCommand = literal("spawn")
|
||||
.requires(Permissions.require("rcc.command.spawn", true))
|
||||
.executes(context -> {
|
||||
if (!context.getSource().isExecutedByPlayer()) {
|
||||
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
var player = context.getSource().getPlayer();
|
||||
var player = context.getSource().getPlayerOrThrow();
|
||||
var serverState = RccServer.state.getServerState();
|
||||
var playerContext = PlaceholderContext.of(player);
|
||||
var spawnPosition = serverState.spawn;
|
||||
|
|
|
@ -16,12 +16,7 @@ public class BackCommand {
|
|||
var rootCommand = literal("back")
|
||||
.requires(Permissions.require("rcc.command.back", true))
|
||||
.executes(context -> {
|
||||
if (!context.getSource().isExecutedByPlayer()) {
|
||||
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
var player = context.getSource().getPlayer();
|
||||
var player = context.getSource().getPlayerOrThrow();
|
||||
var playerContext = PlaceholderContext.of(player);
|
||||
|
||||
var lastPosition = BackTracker.lastPlayerPositions.get(player.getUuid());
|
||||
|
|
|
@ -20,12 +20,7 @@ public class TeleportAcceptCommand {
|
|||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||
var node = dispatcher.register(literal("tpaccept")
|
||||
.executes(context -> {
|
||||
if (!context.getSource().isExecutedByPlayer()) {
|
||||
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
var player = context.getSource().getPlayer();
|
||||
var player = context.getSource().getPlayerOrThrow();
|
||||
var playerUuid = player.getUuid();
|
||||
var playerRequests = TeleportTracker.teleportRequests.get(playerUuid);
|
||||
var playerContext = PlaceholderContext.of(player);
|
||||
|
|
|
@ -6,6 +6,7 @@ import cc.reconnected.server.util.Components;
|
|||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import eu.pb4.placeholders.api.PlaceholderContext;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
|
@ -34,15 +35,11 @@ public class TeleportAskCommand {
|
|||
dispatcher.register(literal("tpask").redirect(node));
|
||||
}
|
||||
|
||||
private static void execute(CommandContext<ServerCommandSource> context) {
|
||||
private static void execute(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
var source = context.getSource();
|
||||
if (!source.isExecutedByPlayer()) {
|
||||
source.sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return;
|
||||
}
|
||||
var player = context.getSource().getPlayerOrThrow();
|
||||
|
||||
var server = source.getServer();
|
||||
var player = source.getPlayer();
|
||||
var targetName = StringArgumentType.getString(context, "player");
|
||||
var playerManager = server.getPlayerManager();
|
||||
var target = playerManager.getPlayer(targetName);
|
||||
|
|
|
@ -6,6 +6,7 @@ import cc.reconnected.server.util.Components;
|
|||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import eu.pb4.placeholders.api.PlaceholderContext;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
|
@ -34,15 +35,10 @@ public class TeleportAskHereCommand {
|
|||
dispatcher.register(literal("tpaskhere").redirect(node));
|
||||
}
|
||||
|
||||
private static void execute(CommandContext<ServerCommandSource> context) {
|
||||
private static void execute(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
var source = context.getSource();
|
||||
if (!source.isExecutedByPlayer()) {
|
||||
source.sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return;
|
||||
}
|
||||
|
||||
var player = context.getSource().getPlayerOrThrow();
|
||||
var server = source.getServer();
|
||||
var player = source.getPlayer();
|
||||
var targetName = StringArgumentType.getString(context, "player");
|
||||
var playerManager = server.getPlayerManager();
|
||||
var target = playerManager.getPlayer(targetName);
|
||||
|
|
|
@ -46,12 +46,7 @@ public class TeleportDenyCommand {
|
|||
})
|
||||
.then(argument("uuid", UuidArgumentType.uuid())
|
||||
.executes(context -> {
|
||||
if (!context.getSource().isExecutedByPlayer()) {
|
||||
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
var player = context.getSource().getPlayer();
|
||||
var player = context.getSource().getPlayerOrThrow();
|
||||
var uuid = UuidArgumentType.getUuid(context, "uuid");
|
||||
var playerUuid = player.getUuid();
|
||||
var playerRequests = TeleportTracker.teleportRequests.get(playerUuid);
|
||||
|
|
|
@ -31,11 +31,6 @@ public class DeleteWarpCommand {
|
|||
}
|
||||
|
||||
private static int execute(CommandContext<ServerCommandSource> context, String name) {
|
||||
if (!context.getSource().isExecutedByPlayer()) {
|
||||
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return 1;
|
||||
}
|
||||
var player = context.getSource().getPlayer();
|
||||
var serverState = RccServer.state.getServerState();
|
||||
var warps = serverState.warps;
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import cc.reconnected.server.struct.ServerPosition;
|
|||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.Text;
|
||||
|
@ -24,12 +25,8 @@ public class SetWarpCommand {
|
|||
dispatcher.register(rootCommand);
|
||||
}
|
||||
|
||||
private static int execute(CommandContext<ServerCommandSource> context, String name) {
|
||||
if (!context.getSource().isExecutedByPlayer()) {
|
||||
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return 1;
|
||||
}
|
||||
var player = context.getSource().getPlayer();
|
||||
private static int execute(CommandContext<ServerCommandSource> context, String name) throws CommandSyntaxException {
|
||||
var player = context.getSource().getPlayerOrThrow();
|
||||
var serverState = RccServer.state.getServerState();
|
||||
|
||||
var warps = serverState.warps;
|
||||
|
|
|
@ -5,6 +5,7 @@ import cc.reconnected.server.util.Components;
|
|||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import eu.pb4.placeholders.api.PlaceholderContext;
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.minecraft.command.CommandSource;
|
||||
|
@ -33,12 +34,8 @@ public class WarpCommand {
|
|||
dispatcher.register(rootCommand);
|
||||
}
|
||||
|
||||
private static int execute(CommandContext<ServerCommandSource> context, String name) {
|
||||
if (!context.getSource().isExecutedByPlayer()) {
|
||||
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return 1;
|
||||
}
|
||||
var player = context.getSource().getPlayer();
|
||||
private static int execute(CommandContext<ServerCommandSource> context, String name) throws CommandSyntaxException {
|
||||
var player = context.getSource().getPlayerOrThrow();
|
||||
var serverState = RccServer.state.getServerState();
|
||||
var warps = serverState.warps;
|
||||
var playerContext = PlaceholderContext.of(player);
|
||||
|
|
|
@ -9,7 +9,6 @@ import eu.pb4.placeholders.api.Placeholders;
|
|||
import eu.pb4.placeholders.api.parsers.NodeParser;
|
||||
import eu.pb4.placeholders.api.parsers.TextParserV1;
|
||||
import net.minecraft.entity.damage.DamageTracker;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.network.packet.s2c.play.PositionFlag;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
|
|
Loading…
Reference in a new issue