use of com.voxelgameslib.voxelgameslib.api.game.GameMode in project VoxelGamesLibv2 by VoxelGamesLib.
the class VoxelGamesLib method registerCommandReplacements.
private void registerCommandReplacements() {
CommandReplacements rep = commandManager.getCommandReplacements();
rep.addReplacement("@gamemodes", gameHandler.getGameModes().stream().map(GameMode::getName).collect(Collectors.joining("|")));
rep.addReplacement("@locales", Arrays.stream(Locale.values()).map(locale -> locale.getName() + "|" + locale.getTag()).collect(Collectors.joining("|")));
rep.addReplacement("@roles", Arrays.stream(Role.values()).map(Role::getName).collect(Collectors.joining("|")));
rep.addReplacement("@stats", statsHandler.getStatTypes().stream().map(stat -> stat.getPrefix() + ":" + stat.name()).collect(Collectors.joining("|")));
rep.addReplacement("%user", "voxelgameslib.role.user");
rep.addReplacement("%premium", "voxelgameslib.role.premium");
rep.addReplacement("%moderator", "voxelgameslib.role.moderator");
rep.addReplacement("%admin", "voxelgameslib.role.admin");
}
use of com.voxelgameslib.voxelgameslib.api.game.GameMode in project VoxelGamesLibv2 by VoxelGamesLib.
the class VoxelGamesLib method registerCommandContexts.
private void registerCommandContexts() {
CommandContexts<BukkitCommandExecutionContext> con = commandManager.getCommandContexts();
con.registerIssuerAwareContext(User.class, c -> {
boolean isOptional = c.hasAnnotation(Optional.class);
CommandSender sender = c.getSender();
boolean isPlayerSender = sender instanceof Player;
if (!c.hasFlag("other")) {
Player player = isPlayerSender ? (Player) sender : null;
if (player == null) {
if (!isOptional) {
throw new InvalidCommandArgument(MessageKeys.NOT_ALLOWED_ON_CONSOLE, false);
} else {
return null;
}
}
return userHandler.getUser(player.getUniqueId()).orElseThrow(() -> new InvalidCommandArgument("Unknown user " + player.getDisplayName()));
} else {
String arg = c.popFirstArg();
if (arg == null) {
if (isOptional) {
if (c.hasFlag("defaultself")) {
if (isPlayerSender) {
return userHandler.getUser(((Player) sender).getUniqueId()).orElseThrow(() -> new InvalidCommandArgument("Unknown user " + ((Player) sender).getDisplayName()));
} else {
throw new InvalidCommandArgument(MessageKeys.NOT_ALLOWED_ON_CONSOLE, false);
}
}
}
return null;
} else {
return userHandler.getUser(arg).orElseThrow(() -> new InvalidCommandArgument("Unknown user " + arg));
}
}
});
con.registerContext(int.class, c -> Integer.parseInt(c.popFirstArg()));
con.registerContext(GameMode.class, c -> {
GameMode mode = gameHandler.getGameModes().stream().filter(gameMode -> gameMode.getName().equalsIgnoreCase(c.getFirstArg())).findAny().orElseThrow(() -> new InvalidCommandArgument("Unknown gamemode " + c.getFirstArg()));
// pop later so that we can get a nice error message
c.popLastArg();
return mode;
});
con.registerContext(Locale.class, c -> {
Locale locale = Locale.fromName(c.getFirstArg()).orElse(Locale.fromTag(c.getFirstArg()).orElseThrow(() -> new InvalidCommandArgument("Unknown locale " + c.getFirstArg())));
// pop later so that we can get a nice error message
c.popFirstArg();
return locale;
});
con.registerContext(Role.class, c -> Role.fromName(c.popFirstArg()));
con.registerContext(UUID.class, c -> UUID.fromString(c.popFirstArg()));
con.registerContext(Trackable.class, c -> {
Trackable s = StatsHandler.fromName(c.getFirstArg()).orElseThrow(() -> new InvalidCommandArgument("Unknown stats type " + c.getFirstArg()));
// pop later so that we can get a nice error message
c.popFirstArg();
return s;
});
}
use of com.voxelgameslib.voxelgameslib.api.game.GameMode in project VoxelGamesLibv2 by VoxelGamesLib.
the class WorldCreator method author.
@Subcommand("author")
@CommandPermission("%admin")
public void author(@Nonnull User sender, @Nonnull String author) {
if (step != 5) {
Lang.msg(sender, LangKey.WORLD_CREATOR_WRONG_STEP, step, 5);
return;
}
this.author = author;
Lang.msg(sender, LangKey.WORLD_CREATOR_AUTHOR_SET, author);
for (GameMode mode : gameHandler.getGameModes()) {
sender.sendMessage(TextComponent.of(mode.getName() + " ").color(TextColor.YELLOW).clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/worldcreator gamemode " + mode.getName())));
}
Lang.msg(sender, LangKey.WORLD_CREATOR_DONE_QUERY, "/worldcreator gamemode done");
step = 6;
}
Aggregations