Having trouble with player.spawnParticles

Discussion in 'Spigot Plugin Development' started by AmazingKoala1, Sep 12, 2019 at 3:08 AM.

  1. Hi,
    Im trying to use player.spawnParticles but it seems as if the function doesnt exist
    Code (Text):
    package net.therale.UltimateCosmetics;

    import net.minecraft.server.v1_8_R3.EnumParticle;
    import net.minecraft.server.v1_8_R3.PacketPlayOutWorldParticles;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitRunnable;

    public class Main extends JavaPlugin {
        public static Plugin plugin;
        public void onEnable(){
            plugin = this;
            for (Entity entity : Bukkit.getWorld("world").getEntities()) {
                if (entity instanceof Player) {
                    Player player = (Player) entity;

                    new BukkitRunnable() {

                        @Override
                        public void run() {


                            float red = 255;
                            float green =0;
                            float blue = 0;

                            player.spawnParticles();

                        }
                    }.runTaskTimerAsynchronously(this, 0, 0);
                }
            }
        }
        public void onDisable(){
            plugin = null;
        }
        public static void registerEvents(org.bukkit.plugin.Plugin plugin, Listener... listeners) {
            for (Listener listener : listeners) {
                Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
            }
        }
    }
     
     
  2. "player.spawnParticles();"
    its just spawnParticle - no "s"

    Screen Shot 2019-09-11 at 7.14.20 PM.png
     
  3. Its almost like the function doesnt exist
     
  4. which version of Spigot are you using?
     
  5. oh, yeah that method doesn't exist in 1.8.8
     
  6. Well what would i do to spawn particles
     
  7. I have no clue, I don't develop for dinosaur server versions. I recommend doing some googling, I'm sure you will find an answer.
     
    • Funny Funny x 1
  8. So I got the trails to work but I want everyone to see them is there a way i can do that
     
  9. Just send the packet to all players in viewing range.
     
  10. But then wont all of them actually have the particles and whats the code to do that my current code is


    Code (Text):
    package net.therale.UltimateCosmetics.Utils;

    import net.minecraft.server.v1_8_R3.EnumParticle;
    import net.minecraft.server.v1_8_R3.PacketPlayOutWorldParticles;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class UtilsCreateTrail extends JavaPlugin {
        public static void createTrail(Player player, EnumParticle particle) {
            Location loc = player.getLocation();
            PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particle,true, (float) (loc.getX()), (float) (loc.getY()), (float) (loc.getZ()), 0, 0, 0, 0, 10);
            ((CraftPlayer)player).getHandle().playerConnection.sendPacket(packet);
        }
    }
     
     
  11. dev_rauf

    dev_rauf Previously BestKvant

    Use World#spawnParticle method.
     
  12. I recommend if you are going to respond, read the rest of the thread.
    The method you are suggesting is not available in the version the OP stated they're using.
     
  13. https://hub.spigotmc.org/javadocs/s...ies-org.bukkit.Location-double-double-double-
    Code (Java):
    public static void createTrail(Player player, EnumParticle particle) {
        Location loc = player.getLocation();
        PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particle,true, (float) (loc.getX()), (float) (loc.getY()), (float) (loc.getZ()), 0, 0, 0, 0, 10);
        ((CraftPlayer)player).getHandle().playerConnection.sendPacket(packet);
        for(Entity e : loc.getWorld().getNearbyEntities(loc, 30, 30, 30)) { // For-loop sends the packet to all nearby players
            if(!(e instanceof Player)) continue;
            Player nearbyPlayer = (Player) e;
            ((CraftPlayer)nearbyPlayer).getHandle().playerConnection.sendPacket(packet);
        }
    }
     
  14. Code (Java):
    player.getWorld().playEffect()