further polish

This commit is contained in:
MrGazdag 2021-07-20 17:01:30 +02:00 committed by GitHub
parent 471838a77f
commit 4348ce50cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 8 deletions

View File

@ -36,12 +36,10 @@ public class GamemodeCommand extends Command {
.append(Component.text("!")), MessageType.SYSTEM);
});
//Targets parameter, can accept multiple players
ArgumentEntity player = ArgumentType.Entity("targets").onlyPlayers(true);
//Upon invalid usage, print the correct usage of the command to the sender
setDefaultExecutor((sender, context) -> {
//The used alias
String commandName = context.getCommandName();
sender.sendMessage(Component.text("Usage: /" + commandName + " <gamemode> [targets]", NamedTextColor.RED), MessageType.SYSTEM);
@ -54,13 +52,13 @@ public class GamemodeCommand extends Command {
sender.sendMessage(Component.text("Please run this command in-game.", NamedTextColor.RED));
return;
}
//Check permission, this could be replaced with hasPermission
if (sender.asPlayer().getPermissionLevel() < 2) {
sender.sendMessage(Component.text("You don't have permission to use this command.", NamedTextColor.RED));
return;
}
//Arguments
GameMode mode = context.get(gamemode);
//Set the gamemode for the sender
@ -76,7 +74,6 @@ public class GamemodeCommand extends Command {
return;
}
//Arguments
EntityFinder finder = context.get(player);
GameMode mode = context.get(gamemode);
@ -104,15 +101,12 @@ public class GamemodeCommand extends Command {
} else {
p.setGameMode(mode);
//Create necessary components
String gamemodeString = "gameMode." + mode.name().toLowerCase(Locale.ROOT);
Component gamemodeComponent = Component.translatable(gamemodeString);
Component playerName = p.getDisplayName() == null ? p.getName() : p.getDisplayName();
//Send a message to the changed player
//Send a message to the changed player and the sender
p.sendMessage(Component.translatable("gameMode.changed", gamemodeComponent), MessageType.SYSTEM);
//Send a message to the sender
sender.sendMessage(Component.translatable("commands.gamemode.success.other", playerName, gamemodeComponent), MessageType.SYSTEM);
}
}