use of net.minecraft.server.network.ServerPlayerEntity in project pingspam by BasiqueEvangelist.
the class PingSoundCommand method setPingSound.
private static int setPingSound(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
ServerCommandSource src = ctx.getSource();
ServerPlayerEntity player = src.getPlayer();
Identifier soundId = IdentifierArgumentType.getIdentifier(ctx, "sound");
SoundEvent event = Registry.SOUND_EVENT.getOrEmpty(soundId).orElseThrow(INVALID_SOUND::create);
PlayerUtils.setPingSound(player, event);
src.sendFeedback(new LiteralText("Set ping sound to ").formatted(Formatting.GREEN).append(new LiteralText(((SoundEventAccessor) PlayerUtils.getPingSound(player)).pingspam$getId().toString()).formatted(Formatting.YELLOW)).append(new LiteralText(".")), false);
return 0;
}
use of net.minecraft.server.network.ServerPlayerEntity in project pingspam by BasiqueEvangelist.
the class PingSoundCommand method getPingSound.
private static int getPingSound(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
ServerCommandSource src = ctx.getSource();
ServerPlayerEntity player = src.getPlayer();
if (PlayerUtils.getPingSound(player) != null) {
src.sendFeedback(new LiteralText("Your current ping sound is ").formatted(Formatting.GREEN).append(new LiteralText(((SoundEventAccessor) PlayerUtils.getPingSound(player)).pingspam$getId().toString()).formatted(Formatting.YELLOW)).append(new LiteralText(".")), false);
} else {
src.sendFeedback(new LiteralText("You have disabled ping sounds.").formatted(Formatting.GREEN), false);
}
return 0;
}
use of net.minecraft.server.network.ServerPlayerEntity 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.network.ServerPlayerEntity 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.network.ServerPlayerEntity 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;
}
Aggregations