Solved Turn off particles for only ONE person

Discussion in 'Plugin Development' started by plisov, Jun 3, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    plisov

    :)
     
    Last edited: Jun 8, 2016
  2. Please add this library:
    https://bukkit.org/threads/1-8-particleeffect-v1-7.154406
    • ParticleEffect.NAME.display(Vector direction, float speed, Location center, List<Player> players);
    This is the line you should use.
    When you want all players to see the particles, as argument players put
    Code:
    Bukkit.getServer().getOnlinePlayers();
    When you want that everyone but you see the particles, you would have to make a list and remove yourself.
    Code:
            List<Player> players = new ArrayList<Player>();
            for(Player p : Bukkit.getOnlinePlayers()) {
            if(p.getName() != me.getName())    { // Replace "me" with your player variable.
            players.add(p);  
            }
            }
    
    And just pass players variable as the players argument.
     
  3. Offline

    plisov

    I already have the particles withing. Alli need to know is how to turn them off for only one player. Not how to show to one person or to everyone. :)
     
  4. Offline

    Xerox262

    @plisov The Bukkit method by default shows the particles to everyone, the only way to control whom receives particles is to actually send the packets yourself
     
  5. Offline

    plisov

    Ok. Thanks for the help. Would I put the code in the first post here?
    Code:
            List<Player> players = new ArrayList<Player>();
            for(Player p : Bukkit.getOnlinePlayers()) {
            if(p.getName() != me.getName())    { // Replace "me" with your player variable.
            (CODE FROM FIRST POST GOES HERE?)
            players.add(p);
            }
            }
     
  6. Offline

    teej107

    @plisov You can use ProtocolLib to easily intercept outgoing packets to the clients.
     
  7. Offline

    plisov

    I probably did this completely wrong. I have never used Lists so I do not know how to use them. What I did was take the BukkitRunnable from its old location and put it into the for loop in the list. Have a look.
    Code:
        @EventHandler
        public void onInventoryClick(InventoryClickEvent e) {
            Player player = (Player) e.getWhoClicked();
            List<Player> players = new ArrayList<Player>();
            for(Player p : Bukkit.getOnlinePlayers()) {
            if(p.getName() != player.getName())    {
                new BukkitRunnable() {
                    double t = 0;
                    @Override
                    public void run() {
                        Location location1 = player.getEyeLocation();
                        Location location2 = player.getEyeLocation();
                        Location location3 = player.getEyeLocation();
                        int particles = 15;
                        t = t + Math.PI/6;
                        float radius = 0.6f;
                        for (int i = 0; i < particles; i++) {
                            double angle, x, z;
                            angle = t*4 * Math.PI * i / particles;
                            x = Math.cos(t) * radius;
                            z = Math.sin(t) * radius;
                            //angle = 4 * Math.PI * i / particles;
                            //x = Math.cos(angle) * radius;
                            //z = Math.sin(angle) * radius;
                            location1.add(x, 0.5, z);
                            //location2.add(x, -0.66, z);
                            //location3.add(x, -1.33, z);
                            ParticleEffect.SNOW_SHOVEL.display(location1, 0, 0, 0, 0, 1);
                            //ParticleEffect.REDSTONE.display(location2, 0, 0, 0, 0, 1);
                            //ParticleEffect.REDSTONE.display(location3, 0, 0, 0, 0, 1);
                            location1.subtract(x, 0.5, z);
                            //location2.subtract(x, -0.66, z);
                            //location3.subtract(x, -1.33, z);
                        }
                    }
                       
                    }.runTaskTimer(plugin, 20, 1);// Replace "me" with your player variable.
    
            }
            }
            if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Angel")) {
                if(player.hasPermission("particles.angel")) {
                if (!e.getInventory().getName().equalsIgnoreCase(GUI.getName())) return;
                if (e.getCurrentItem().getItemMeta() == null) return;
                    e.setCancelled(true);
                    Location loc = player.getLocation();
                    players.add(player); 
                    e.getWhoClicked().closeInventory();
            } else {
                player.sendMessage(ChatColor.RED + "No access.");
                e.setCancelled(true);
                return;
            }
            }
            if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Stop Angel")) {
                if (!e.getInventory().getName().equalsIgnoreCase(GUI.getName())) return;
                if (e.getCurrentItem().getItemMeta() == null) return;
                    e.setCancelled(true);
                    Location loc = player.getLocation();
                    players.remove(player);
                    e.getWhoClicked().closeInventory();
            }
    Please explain how to set this up correctly. :)

    Bump.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page