use of net.minecraft.text.LiteralText in project pingspam by BasiqueEvangelist.
the class AliasCommand method removeAlias.
private static int removeAlias(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
ServerCommandSource src = ctx.getSource();
String alias = StringArgumentType.getString(ctx, "alias");
ServerPlayerEntity player = src.getPlayer();
List<String> aliases = PlayerUtils.getAliasesOf(player);
if (!ALIAS_PATTERN.asPredicate().test(alias))
throw INVALID_ALIAS.create();
if (aliases.stream().noneMatch(x -> x.equalsIgnoreCase(alias)))
throw NO_SUCH_ALIAS.create();
aliases.removeIf(x -> x.equalsIgnoreCase(alias));
if (!NameLogic.isValidName(src.getMinecraftServer().getPlayerManager(), alias, false))
ServerNetworkLogic.removePossibleName(src.getMinecraftServer().getPlayerManager(), alias);
src.sendFeedback(new LiteralText("Removed alias ").formatted(Formatting.RED).append(new LiteralText('"' + alias + '"').formatted(Formatting.YELLOW)).append(new LiteralText(".")), false);
return 0;
}
use of net.minecraft.text.LiteralText in project pingspam by BasiqueEvangelist.
the class AliasCommand method removePlayerAlias.
private static int removePlayerAlias(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
ServerCommandSource src = ctx.getSource();
String alias = StringArgumentType.getString(ctx, "alias");
ServerPlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
List<String> aliases = PlayerUtils.getAliasesOf(player);
if (!ALIAS_PATTERN.asPredicate().test(alias))
throw INVALID_ALIAS.create();
if (aliases.stream().noneMatch(x -> x.equalsIgnoreCase(alias)))
throw NO_SUCH_ALIAS_OTHER.create(player);
aliases.removeIf(x -> x.equalsIgnoreCase(alias));
if (!NameLogic.isValidName(src.getMinecraftServer().getPlayerManager(), alias, false))
ServerNetworkLogic.removePossibleName(src.getMinecraftServer().getPlayerManager(), alias);
src.sendFeedback(new LiteralText("Removed alias ").formatted(Formatting.RED).append(new LiteralText('"' + alias + '"').formatted(Formatting.YELLOW)).append(new LiteralText(" from ")).append(new LiteralText(player.getEntityName()).formatted(Formatting.AQUA)).append(new LiteralText(".")), true);
return 0;
}
use of net.minecraft.text.LiteralText in project pingspam by BasiqueEvangelist.
the class AliasCommand method addAliases.
private static int addAliases(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
ServerCommandSource src = ctx.getSource();
String newAlias = StringArgumentType.getString(ctx, "alias");
ServerPlayerEntity player = src.getPlayer();
List<String> aliases = PlayerUtils.getAliasesOf(player);
if (!ALIAS_PATTERN.asPredicate().test(newAlias))
throw INVALID_ALIAS.create();
if (aliases.stream().anyMatch(x -> x.equalsIgnoreCase(newAlias)))
throw ALIAS_EXISTS.create();
if (NameLogic.isValidName(src.getMinecraftServer().getPlayerManager(), newAlias, false))
throw ALIAS_COLLISION.create();
if (aliases.size() >= ALIAS_LIMIT && !Permissions.check(src, "pingspam.bypass.aliaslimit", 2))
throw TOO_MANY_ALIASES.create();
aliases.add(newAlias);
ServerNetworkLogic.addPossibleName(src.getMinecraftServer().getPlayerManager(), newAlias);
src.sendFeedback(new LiteralText("Added alias ").formatted(Formatting.GREEN).append(new LiteralText('"' + newAlias + '"').formatted(Formatting.YELLOW)).append(new LiteralText(".")), false);
return 0;
}
use of net.minecraft.text.LiteralText in project pingspam by BasiqueEvangelist.
the class AliasCommand method addPlayerAlias.
private static int addPlayerAlias(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
ServerCommandSource src = ctx.getSource();
String newAlias = StringArgumentType.getString(ctx, "alias");
ServerPlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
List<String> aliases = PlayerUtils.getAliasesOf(player);
if (!ALIAS_PATTERN.asPredicate().test(newAlias))
throw INVALID_ALIAS.create();
if (aliases.stream().anyMatch(x -> x.equalsIgnoreCase(newAlias)))
throw ALIAS_EXISTS_OTHER.create(player);
if (NameLogic.isValidName(src.getMinecraftServer().getPlayerManager(), newAlias, false))
throw ALIAS_COLLISION.create();
if (aliases.size() >= ALIAS_LIMIT && !Permissions.check(src, "pingspam.bypass.aliaslimit", 2))
throw TOO_MANY_ALIASES.create();
aliases.add(newAlias);
ServerNetworkLogic.addPossibleName(src.getMinecraftServer().getPlayerManager(), newAlias);
src.sendFeedback(new LiteralText("Added alias ").formatted(Formatting.GREEN).append(new LiteralText('"' + newAlias + '"').formatted(Formatting.YELLOW)).append(new LiteralText(" to ")).append(new LiteralText(player.getEntityName()).formatted(Formatting.AQUA)).append(new LiteralText(".")), true);
return 0;
}
use of net.minecraft.text.LiteralText in project pingspam by BasiqueEvangelist.
the class AliasCommand method listAliases.
private static int listAliases(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
ServerCommandSource src = ctx.getSource();
ServerPlayerEntity player = src.getPlayer();
List<String> aliases = PlayerUtils.getAliasesOf(player);
StringBuilder headerBuilder = new StringBuilder();
StringBuilder contentBuilder = new StringBuilder();
headerBuilder.append("You have ");
headerBuilder.append(aliases.size());
headerBuilder.append(" alias");
if (aliases.size() != 1)
headerBuilder.append("es");
if (aliases.size() > 0) {
headerBuilder.append(": ");
boolean isFirst = true;
for (String alias : aliases) {
if (!isFirst)
contentBuilder.append(", ");
isFirst = false;
contentBuilder.append(alias);
}
} else {
headerBuilder.append('.');
}
src.sendFeedback(new LiteralText(headerBuilder.toString()).formatted(Formatting.GREEN).append(new LiteralText(contentBuilder.toString()).formatted(Formatting.YELLOW)), false);
return 0;
}
Aggregations