Search in sources :

Example 1 with StringReader

use of com.mojang.brigadier.StringReader in project MyPet by xXKeyleXx.

the class PlatformHelper method playParticleEffect.

/**
 * @param location   the {@link Location} around which players must be to see the effect
 * @param effectName list of effects: https://gist.github.com/riking/5759002
 * @param offsetX    the amount to be randomly offset by in the X axis
 * @param offsetY    the amount to be randomly offset by in the Y axis
 * @param offsetZ    the amount to be randomly offset by in the Z axis
 * @param speed      the speed of the particles
 * @param count      the number of particles
 * @param radius     the radius around the location
 */
@Override
public void playParticleEffect(Location location, String effectName, float offsetX, float offsetY, float offsetZ, float speed, int count, int radius, de.Keyle.MyPet.api.compat.Compat<Object> data) {
    Particle effect = IRegistry.PARTICLE_TYPE.get(new MinecraftKey(effectName));
    Validate.notNull(location, "Location cannot be null");
    Validate.notNull(effect, "Effect cannot be null");
    Validate.notNull(location.getWorld(), "World cannot be null");
    ParticleParam particle = null;
    if (effect.d() != null && data != null) {
        try {
            particle = effect.d().b(effect, new StringReader(" " + data.get().toString()));
        } catch (CommandSyntaxException e) {
            e.printStackTrace();
        }
    } else if (effect instanceof ParticleType) {
        particle = (ParticleType) effect;
    }
    if (particle == null) {
        return;
    }
    PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particle, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count);
    radius = radius * radius;
    for (Player player : location.getWorld().getPlayers()) {
        if ((int) MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), location) <= radius) {
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) StringReader(com.mojang.brigadier.StringReader) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException)

Example 2 with StringReader

use of com.mojang.brigadier.StringReader in project MyPet by xXKeyleXx.

the class PlatformHelper method playParticleEffect.

/**
 * @param location   the {@link Location} around which players must be to see the effect
 * @param effectName list of effects: https://gist.github.com/riking/5759002
 * @param offsetX    the amount to be randomly offset by in the X axis
 * @param offsetY    the amount to be randomly offset by in the Y axis
 * @param offsetZ    the amount to be randomly offset by in the Z axis
 * @param speed      the speed of the particles
 * @param count      the number of particles
 * @param radius     the radius around the location
 */
@Override
public void playParticleEffect(Location location, String effectName, float offsetX, float offsetY, float offsetZ, float speed, int count, int radius, de.Keyle.MyPet.api.compat.Compat<Object> data) {
    ParticleType effect = Registry.PARTICLE_TYPE.get(new ResourceLocation(effectName));
    Validate.notNull(location, "Location cannot be null");
    Validate.notNull(effect, "Effect cannot be null");
    Validate.notNull(location.getWorld(), "World cannot be null");
    ParticleOptions particle = null;
    if (effect.getDeserializer() != null && data != null) {
        try {
            particle = effect.getDeserializer().fromCommand(effect, new StringReader(" " + data.get().toString()));
        } catch (CommandSyntaxException e) {
            e.printStackTrace();
        }
    } else if (effect instanceof SimpleParticleType) {
        particle = (SimpleParticleType) effect;
    }
    if (particle == null) {
        return;
    }
    ClientboundLevelParticlesPacket packet = new ClientboundLevelParticlesPacket(particle, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count);
    radius = radius * radius;
    for (Player player : location.getWorld().getPlayers()) {
        if ((int) MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), location) <= radius) {
            ((CraftPlayer) player).getHandle().connection.send(packet);
        }
    }
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) ParticleOptions(net.minecraft.core.particles.ParticleOptions) ResourceLocation(net.minecraft.resources.ResourceLocation) StringReader(com.mojang.brigadier.StringReader) ParticleType(net.minecraft.core.particles.ParticleType) SimpleParticleType(net.minecraft.core.particles.SimpleParticleType) ClientboundLevelParticlesPacket(net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) SimpleParticleType(net.minecraft.core.particles.SimpleParticleType) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException)

Example 3 with StringReader

use of com.mojang.brigadier.StringReader in project MyPet by xXKeyleXx.

the class PlatformHelper method playParticleEffect.

/**
 * @param location   the {@link Location} around which players must be to see the effect
 * @param effectName list of effects: https://gist.github.com/riking/5759002
 * @param offsetX    the amount to be randomly offset by in the X axis
 * @param offsetY    the amount to be randomly offset by in the Y axis
 * @param offsetZ    the amount to be randomly offset by in the Z axis
 * @param speed      the speed of the particles
 * @param count      the number of particles
 * @param radius     the radius around the location
 */
@Override
public void playParticleEffect(Player player, Location location, String effectName, float offsetX, float offsetY, float offsetZ, float speed, int count, int radius, de.Keyle.MyPet.api.compat.Compat<Object> data) {
    ParticleType effect = Registry.PARTICLE_TYPE.get(new ResourceLocation(effectName));
    Validate.notNull(location, "Location cannot be null");
    Validate.notNull(effect, "Effect cannot be null");
    Validate.notNull(location.getWorld(), "World cannot be null");
    ParticleOptions particle = null;
    if (effect.getDeserializer() != null && data != null) {
        try {
            particle = effect.getDeserializer().fromCommand(effect, new StringReader(" " + data.get().toString()));
        } catch (CommandSyntaxException e) {
            e.printStackTrace();
        }
    } else if (effect instanceof SimpleParticleType) {
        particle = (SimpleParticleType) effect;
    }
    if (particle == null) {
        return;
    }
    ClientboundLevelParticlesPacket packet = new ClientboundLevelParticlesPacket(particle, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count);
    if (MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), location) <= radius) {
        ((CraftPlayer) player).getHandle().connection.send(packet);
    }
}
Also used : ParticleOptions(net.minecraft.core.particles.ParticleOptions) ResourceLocation(net.minecraft.resources.ResourceLocation) StringReader(com.mojang.brigadier.StringReader) ParticleType(net.minecraft.core.particles.ParticleType) SimpleParticleType(net.minecraft.core.particles.SimpleParticleType) ClientboundLevelParticlesPacket(net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) SimpleParticleType(net.minecraft.core.particles.SimpleParticleType) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException)

Example 4 with StringReader

use of com.mojang.brigadier.StringReader in project MinecraftForge by MinecraftForge.

the class ConsoleCommandCompleter method complete.

@Override
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
    String buffer = line.line();
    boolean prefix;
    if (buffer.isEmpty() || buffer.charAt(0) != '/') {
        buffer = '/' + buffer;
        prefix = false;
    } else {
        prefix = true;
    }
    final String input = buffer;
    // See NetHandlerPlayServer#processTabComplete
    StringReader stringReader = new StringReader(input);
    if (stringReader.canRead() && stringReader.peek() == '/')
        stringReader.skip();
    try {
        ParseResults<CommandSourceStack> results = this.server.getCommands().getDispatcher().parse(stringReader, this.server.createCommandSourceStack());
        Suggestions tabComplete = this.server.getCommands().getDispatcher().getCompletionSuggestions(results).get();
        for (Suggestion suggestion : tabComplete.getList()) {
            String completion = suggestion.getText();
            if (!completion.isEmpty()) {
                boolean hasPrefix = prefix || completion.charAt(0) != '/';
                Candidate candidate = new Candidate(hasPrefix ? completion : completion.substring(1));
                candidates.add(candidate);
            }
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (ExecutionException e) {
        logger.error("Failed to tab complete", e);
    }
}
Also used : Suggestions(com.mojang.brigadier.suggestion.Suggestions) Candidate(org.jline.reader.Candidate) Suggestion(com.mojang.brigadier.suggestion.Suggestion) StringReader(com.mojang.brigadier.StringReader) ExecutionException(java.util.concurrent.ExecutionException) CommandSourceStack(net.minecraft.commands.CommandSourceStack)

Example 5 with StringReader

use of com.mojang.brigadier.StringReader in project MyPet by xXKeyleXx.

the class PlatformHelper method playParticleEffect.

/**
 * @param location   the {@link Location} around which players must be to see the effect
 * @param effectName list of effects: https://gist.github.com/riking/5759002
 * @param offsetX    the amount to be randomly offset by in the X axis
 * @param offsetY    the amount to be randomly offset by in the Y axis
 * @param offsetZ    the amount to be randomly offset by in the Z axis
 * @param speed      the speed of the particles
 * @param count      the number of particles
 * @param radius     the radius around the location
 */
@Override
public void playParticleEffect(Location location, String effectName, float offsetX, float offsetY, float offsetZ, float speed, int count, int radius, de.Keyle.MyPet.api.compat.Compat<Object> data) {
    Particle effect = IRegistry.PARTICLE_TYPE.get(new MinecraftKey(effectName));
    Validate.notNull(location, "Location cannot be null");
    Validate.notNull(effect, "Effect cannot be null");
    Validate.notNull(location.getWorld(), "World cannot be null");
    ParticleParam particle = null;
    if (effect.d() != null && data != null) {
        try {
            // noinspection unchecked
            particle = effect.d().b(effect, new StringReader(" " + data.get().toString()));
        } catch (CommandSyntaxException e) {
            e.printStackTrace();
        }
    } else if (effect instanceof ParticleType) {
        particle = (ParticleType) effect;
    }
    if (particle == null) {
        return;
    }
    PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particle, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count);
    radius = radius * radius;
    for (Player player : location.getWorld().getPlayers()) {
        if ((int) MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), location) <= radius) {
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer) StringReader(com.mojang.brigadier.StringReader) CraftPlayer(org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException)

Aggregations

StringReader (com.mojang.brigadier.StringReader)7 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)6 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)4 ParticleOptions (net.minecraft.core.particles.ParticleOptions)4 ParticleType (net.minecraft.core.particles.ParticleType)4 SimpleParticleType (net.minecraft.core.particles.SimpleParticleType)4 ClientboundLevelParticlesPacket (net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket)4 ResourceLocation (net.minecraft.resources.ResourceLocation)4 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)2 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)2 Suggestion (com.mojang.brigadier.suggestion.Suggestion)1 Suggestions (com.mojang.brigadier.suggestion.Suggestions)1 ExecutionException (java.util.concurrent.ExecutionException)1 CommandSourceStack (net.minecraft.commands.CommandSourceStack)1 CraftPlayer (org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer)1 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)1 Candidate (org.jline.reader.Candidate)1