use of net.minecraft.server.command.ServerCommandSource in project pingspam by BasiqueEvangelist.
the class GroupCommand method listPlayerGroups.
private static int listPlayerGroups(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
ServerCommandSource src = ctx.getSource();
ServerPlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
List<String> groups = PlayerUtils.getPingGroupsOf(player);
StringBuilder headerBuilder = new StringBuilder();
StringBuilder contentBuilder = new StringBuilder();
headerBuilder.append(" is in ");
headerBuilder.append(groups.size());
headerBuilder.append(" ping group");
if (groups.size() != 1)
headerBuilder.append("s");
if (groups.size() > 0) {
headerBuilder.append(": ");
boolean isFirst = true;
for (String group : groups) {
if (!isFirst)
contentBuilder.append(", ");
isFirst = false;
contentBuilder.append(group);
}
} else {
headerBuilder.append('.');
}
src.sendFeedback(new LiteralText(player.getEntityName()).formatted(Formatting.AQUA).append(new LiteralText(headerBuilder.toString()).formatted(Formatting.GREEN)).append(new LiteralText(contentBuilder.toString()).formatted(Formatting.YELLOW)), false);
return 0;
}
use of net.minecraft.server.command.ServerCommandSource in project pingspam by BasiqueEvangelist.
the class GroupCommand method addPlayerGroup.
private static int addPlayerGroup(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
ServerCommandSource src = ctx.getSource();
String newGroup = StringArgumentType.getString(ctx, "groupname");
ServerPlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
List<String> groups = PlayerUtils.getPingGroupsOf(player);
if (!GROUPNAME_PATTERN.asPredicate().test(newGroup))
throw INVALID_GROUPNAME.create();
if (groups.stream().anyMatch(x -> x.equalsIgnoreCase(newGroup)))
throw IN_GROUP_OTHER.create(player);
if (NameLogic.isValidName(src.getMinecraftServer().getPlayerManager(), newGroup, true))
throw NAME_COLLISION.create();
groups.add(newGroup);
ServerNetworkLogic.addPossibleName(src.getMinecraftServer().getPlayerManager(), newGroup);
src.sendFeedback(new LiteralText("Added player ").formatted(Formatting.GREEN).append(new LiteralText(player.getEntityName()).formatted(Formatting.AQUA)).append(" to group ").append(new LiteralText(newGroup).formatted(Formatting.YELLOW).append(".")), true);
return 0;
}
use of net.minecraft.server.command.ServerCommandSource in project pingspam by BasiqueEvangelist.
the class GroupCommand method listOwnGroups.
private static int listOwnGroups(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
ServerCommandSource src = ctx.getSource();
ServerPlayerEntity player = src.getPlayer();
List<String> pingGroups = PlayerUtils.getPingGroupsOf(player);
StringBuilder headerBuilder = new StringBuilder();
StringBuilder contentBuilder = new StringBuilder();
headerBuilder.append("You are in ");
headerBuilder.append(pingGroups.size());
headerBuilder.append(" ping group");
if (pingGroups.size() != 1)
headerBuilder.append("s");
if (pingGroups.size() > 0) {
headerBuilder.append(": ");
boolean isFirst = true;
for (String pingGroup : pingGroups) {
if (!isFirst)
contentBuilder.append(", ");
isFirst = false;
contentBuilder.append(pingGroup);
}
} else {
headerBuilder.append('.');
}
src.sendFeedback(new LiteralText(headerBuilder.toString()).formatted(Formatting.GREEN).append(new LiteralText(contentBuilder.toString()).formatted(Formatting.YELLOW)), false);
return 0;
}
use of net.minecraft.server.command.ServerCommandSource in project pingspam by BasiqueEvangelist.
the class PingIgnoreCommand method removeIgnoredPlayer.
private static int removeIgnoredPlayer(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
ServerCommandSource src = ctx.getSource();
Collection<GameProfile> removedPlayers = GameProfileArgumentType.getProfileArgument(ctx, "player");
ServerPlayerEntity player = src.getPlayer();
List<UUID> ignoredPlayers = PlayerUtils.getIgnoredPlayersOf(player);
StringBuilder playersBuilder = new StringBuilder();
boolean isFirst = true;
for (GameProfile removedPlayer : removedPlayers) {
if (!isFirst)
playersBuilder.append(", ");
isFirst = false;
playersBuilder.append(removedPlayer.getName());
if (!ignoredPlayers.contains(removedPlayer.getId())) {
throw PLAYER_NOT_IGNORED.create();
}
ignoredPlayers.remove(removedPlayer.getId());
}
src.sendFeedback(new LiteralText("You are no longer ignoring ").formatted(Formatting.GREEN).append(new LiteralText(playersBuilder.toString()).formatted(Formatting.AQUA)).append("."), false);
return 0;
}
use of net.minecraft.server.command.ServerCommandSource in project pingspam by BasiqueEvangelist.
the class PingIgnoreCommand method addIgnoredPlayer.
private static int addIgnoredPlayer(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
ServerCommandSource src = ctx.getSource();
Collection<GameProfile> playersToIgnore = GameProfileArgumentType.getProfileArgument(ctx, "player");
ServerPlayerEntity player = src.getPlayer();
List<UUID> ignoredPlayers = PlayerUtils.getIgnoredPlayersOf(player);
StringBuilder playersBuilder = new StringBuilder();
boolean isFirst = true;
for (GameProfile playerToIgnore : playersToIgnore) {
if (!isFirst)
playersBuilder.append(", ");
isFirst = false;
playersBuilder.append(playerToIgnore.getName());
if (ignoredPlayers.contains(playerToIgnore.getId())) {
throw PLAYER_ALREADY_IGNORED.create();
}
ignoredPlayers.add(playerToIgnore.getId());
}
src.sendFeedback(new LiteralText("You are now ignoring ").formatted(Formatting.RED).append(new LiteralText(playersBuilder.toString()).formatted(Formatting.AQUA)).append(new LiteralText(".")), false);
return 0;
}
Aggregations