Search in sources :

Example 96 with ServerPlayerEntity

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;
}
Also used : SoundEvent(net.minecraft.sound.SoundEvent) Identifier(net.minecraft.util.Identifier) SoundEventAccessor(me.basiqueevangelist.pingspam.mixin.SoundEventAccessor) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LiteralText(net.minecraft.text.LiteralText)

Example 97 with ServerPlayerEntity

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;
}
Also used : SoundEventAccessor(me.basiqueevangelist.pingspam.mixin.SoundEventAccessor) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LiteralText(net.minecraft.text.LiteralText)

Example 98 with ServerPlayerEntity

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;
}
Also used : ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LiteralText(net.minecraft.text.LiteralText)

Example 99 with ServerPlayerEntity

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;
}
Also used : ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LiteralText(net.minecraft.text.LiteralText)

Example 100 with ServerPlayerEntity

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;
}
Also used : ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LiteralText(net.minecraft.text.LiteralText)

Aggregations

ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)169 LiteralText (net.minecraft.text.LiteralText)51 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)32 ItemStack (net.minecraft.item.ItemStack)23 PlayerEntity (net.minecraft.entity.player.PlayerEntity)19 Entity (net.minecraft.entity.Entity)15 UUID (java.util.UUID)14 LivingEntity (net.minecraft.entity.LivingEntity)14 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)12 TranslatableText (net.minecraft.text.TranslatableText)12 Inject (org.spongepowered.asm.mixin.injection.Inject)12 ServerWorld (net.minecraft.server.world.ServerWorld)11 PacketByteBuf (net.minecraft.network.PacketByteBuf)10 GameProfile (com.mojang.authlib.GameProfile)9 Formatting (net.minecraft.util.Formatting)9 BlockPos (net.minecraft.util.math.BlockPos)9 ArrayList (java.util.ArrayList)8 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)6 Collectors (java.util.stream.Collectors)6 ArmorStandEntity (net.minecraft.entity.decoration.ArmorStandEntity)6