mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
further polish
This commit is contained in:
parent
471838a77f
commit
4348ce50cf
@ -36,12 +36,10 @@ public class GamemodeCommand extends Command {
|
|||||||
.append(Component.text("!")), MessageType.SYSTEM);
|
.append(Component.text("!")), MessageType.SYSTEM);
|
||||||
});
|
});
|
||||||
|
|
||||||
//Targets parameter, can accept multiple players
|
|
||||||
ArgumentEntity player = ArgumentType.Entity("targets").onlyPlayers(true);
|
ArgumentEntity player = ArgumentType.Entity("targets").onlyPlayers(true);
|
||||||
|
|
||||||
//Upon invalid usage, print the correct usage of the command to the sender
|
//Upon invalid usage, print the correct usage of the command to the sender
|
||||||
setDefaultExecutor((sender, context) -> {
|
setDefaultExecutor((sender, context) -> {
|
||||||
//The used alias
|
|
||||||
String commandName = context.getCommandName();
|
String commandName = context.getCommandName();
|
||||||
|
|
||||||
sender.sendMessage(Component.text("Usage: /" + commandName + " <gamemode> [targets]", NamedTextColor.RED), MessageType.SYSTEM);
|
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));
|
sender.sendMessage(Component.text("Please run this command in-game.", NamedTextColor.RED));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check permission, this could be replaced with hasPermission
|
//Check permission, this could be replaced with hasPermission
|
||||||
if (sender.asPlayer().getPermissionLevel() < 2) {
|
if (sender.asPlayer().getPermissionLevel() < 2) {
|
||||||
sender.sendMessage(Component.text("You don't have permission to use this command.", NamedTextColor.RED));
|
sender.sendMessage(Component.text("You don't have permission to use this command.", NamedTextColor.RED));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Arguments
|
|
||||||
GameMode mode = context.get(gamemode);
|
GameMode mode = context.get(gamemode);
|
||||||
|
|
||||||
//Set the gamemode for the sender
|
//Set the gamemode for the sender
|
||||||
@ -76,7 +74,6 @@ public class GamemodeCommand extends Command {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Arguments
|
|
||||||
EntityFinder finder = context.get(player);
|
EntityFinder finder = context.get(player);
|
||||||
GameMode mode = context.get(gamemode);
|
GameMode mode = context.get(gamemode);
|
||||||
|
|
||||||
@ -104,15 +101,12 @@ public class GamemodeCommand extends Command {
|
|||||||
} else {
|
} else {
|
||||||
p.setGameMode(mode);
|
p.setGameMode(mode);
|
||||||
|
|
||||||
//Create necessary components
|
|
||||||
String gamemodeString = "gameMode." + mode.name().toLowerCase(Locale.ROOT);
|
String gamemodeString = "gameMode." + mode.name().toLowerCase(Locale.ROOT);
|
||||||
Component gamemodeComponent = Component.translatable(gamemodeString);
|
Component gamemodeComponent = Component.translatable(gamemodeString);
|
||||||
Component playerName = p.getDisplayName() == null ? p.getName() : p.getDisplayName();
|
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);
|
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);
|
sender.sendMessage(Component.translatable("commands.gamemode.success.other", playerName, gamemodeComponent), MessageType.SYSTEM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user