Particle off

Discussion in 'Plugin Development' started by Vipevsiki1337, May 29, 2019.

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

    Vipevsiki1337

    Hello, i want to my particles off with player quits but particles stay in place on player quit
    Code:
    package pl.vipevski.pm;
    
    import java.util.ArrayList;
    import java.util.logging.Level;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity;
    import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.inventory.InventoryInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitRunnable;
    
    import net.md_5.bungee.api.ChatColor;
    import net.minecraft.server.v1_8_R3.EnumParticle;
    import net.minecraft.server.v1_8_R3.PacketPlayOutWorldParticles;
    
    public class Main extends JavaPlugin implements Listener{
        public void onEnable(){
            getLogger().log(Level.INFO, "LOADED");
            getServer().getPluginManager().registerEvents(this, this);
            runParticles();
            }
        public ItemStack createItem(Material mat, int amount, String string){
            ItemStack item = new ItemStack(mat, amount);
            ItemMeta meta = item.getItemMeta();
            meta.setDisplayName(string);
            item.setItemMeta(meta);
            return item;
        }
        public void display(EnumParticle type, float x, float y, float z, float count){
            PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(type, true, x, y, z, 0, 0, 0, 0, (int) count, null);
            for(Player p : Bukkit.getServer().getOnlinePlayers()){
                CraftPlayer cp = (CraftPlayer) p;
                cp.getHandle().playerConnection.sendPacket(packet);
            }
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){   
            if(cmd.getName().equalsIgnoreCase("menu")){
                if (!(sender.hasPermission("particle.core"))) {
                    sender.sendMessage("§c» Nie posiadasz permisji do tej komendy! (particle.core)");
                    return false;
                }else{
                    Player p = (Player) sender;
                    openMenu(p);
                    return true;
                }
            }
            return false;
        }
        Inventory inv = Bukkit.createInventory(null, 27, ChatColor.GOLD + "Menu particlesow");
        public void openMenu(Player p){
            inv.setItem(1, createItem(Material.BLAZE_POWDER, 1, ChatColor.RED + "Ogien"));
            inv.setItem(3, createItem(Material.WOOL, 1, ChatColor.GREEN + "Slime"));
            inv.setItem(11, createItem(Material.EMERALD, 1, ChatColor.RED + "Szczescie"));
            inv.setItem(5, createItem(Material.FIREWORK, 1, ChatColor.YELLOW + "Fajerwerki"));
            inv.setItem(7, createItem(Material.REDSTONE, 1, ChatColor.RED + "Redstone"));
            inv.setItem(15, createItem(Material.WATER_BUCKET, 1, ChatColor.BLUE + "deszcz"));
           
            inv.setItem(13, createItem(Material.BARRIER, 1, ChatColor.RED + "Usun particlesy"));
           
            p.openInventory(inv);
        }
        ArrayList<Player> flame = new ArrayList<Player>();
        ArrayList<Player> slime = new ArrayList<Player>();
        ArrayList<Player> firework = new ArrayList<Player>();
        ArrayList<Player> redstone = new ArrayList<Player>();
        ArrayList<Player> szczescie = new ArrayList<Player>();
        ArrayList<Player> deszcz = new ArrayList<Player>();
        @EventHandler
        public void click(InventoryClickEvent e){
            if(e.getInventory() == e.getWhoClicked().getInventory()) return;
            if(e.getInventory().getName().equals(inv.getName())){
                ItemStack clicked = e.getCurrentItem();
                if(clicked.getType() == Material.BLAZE_POWDER){
                    flame.add((Player) e.getWhoClicked());
                    slime.remove(e.getWhoClicked());
                    szczescie.remove(e.getWhoClicked());
                    firework.remove(e.getWhoClicked());
                    redstone.remove(e.getWhoClicked());
                }
                if(clicked.getType() == Material.WATER_BUCKET){
                    flame.remove(e.getWhoClicked());
                    slime.remove(e.getWhoClicked());
                    szczescie.remove(e.getWhoClicked());
                    deszcz.add((Player) e.getWhoClicked());
                    redstone.remove(e.getWhoClicked());
                   
                }
                if(clicked.getType() == Material.WOOL){
                    flame.remove(e.getWhoClicked());
                    slime.add((Player) e.getWhoClicked());
                    szczescie.remove(e.getWhoClicked());
                    firework.remove(e.getWhoClicked());
                    redstone.remove(e.getWhoClicked());
                    deszcz.remove(e.getWhoClicked());
                }
                if(clicked.getType() == Material.EMERALD){
                    flame.remove(e.getWhoClicked());
                    szczescie.add((Player) e.getWhoClicked());
                    slime.remove(e.getWhoClicked());
                    firework.remove(e.getWhoClicked());
                    redstone.remove(e.getWhoClicked());
                    deszcz.remove(e.getWhoClicked());
                }
                if(clicked.getType() == Material.FIREWORK){
                    flame.remove(e.getWhoClicked());
                    slime.remove(e.getWhoClicked());
                    szczescie.remove(e.getWhoClicked());
                    firework.add((Player) e.getWhoClicked());
                    deszcz.remove(e.getWhoClicked());
                    redstone.remove(e.getWhoClicked());
                }
                if(clicked.getType() == Material.REDSTONE){
                    flame.remove(e.getWhoClicked());
                    slime.remove(e.getWhoClicked());
                    szczescie.remove(e.getWhoClicked());
                    firework.remove(e.getWhoClicked());
                    redstone.add((Player) e.getWhoClicked());
                    deszcz.remove(e.getWhoClicked());
                }
                if(clicked.getType() == Material.BARRIER){
                    flame.remove(e.getWhoClicked());
                    slime.remove(e.getWhoClicked());
                    szczescie.remove(e.getWhoClicked());
                    firework.remove((Player) e.getWhoClicked());
                    deszcz.remove(e.getWhoClicked());
                    redstone.remove(e.getWhoClicked());
                    deszcz.remove(e.getWhoClicked());
                }
                e.setCancelled(true);}
            }
        public void runParticles(){
            new BukkitRunnable(){
                public void run(){
                    for(Player p : flame){
                        display(EnumParticle.FLAME, (float)p.getLocation().getX(), (float)p.getLocation().getY(), (float)p.getLocation().getZ(), 10);
                    }
                    for(Player p : deszcz){
                        display(EnumParticle.WATER_DROP, (float)p.getLocation().getX(), (float)p.getLocation().getY(), (float)p.getLocation().getZ(), 10);
                    }
                    for(Player p : slime){
                        display(EnumParticle.SLIME, (float)p.getLocation().getX(), (float)p.getLocation().getY(), (float)p.getLocation().getZ(), 10);
                    }
                    for(Player p : szczescie){
                    display(EnumParticle.VILLAGER_HAPPY, (float)p.getLocation().getX(), (float)p.getLocation().getY(), (float)p.getLocation().getZ(), 10);
                }
                    for(Player p : firework){
                        display(EnumParticle.FIREWORKS_SPARK, (float)p.getLocation().getX(), (float)p.getLocation().getY(), (float)p.getLocation().getZ(), 10);
                    }
                    for(Player p : redstone){
                        display(EnumParticle.REDSTONE, (float)p.getLocation().getX(), (float)p.getLocation().getY(), (float)p.getLocation().getZ(), 10);
                    }
                }
            }.runTaskTimer(this, 0, 2);
        }
    }
     
    Last edited by a moderator: May 29, 2019
  2. Offline

    KarimAKL

    @Vipevsiki1337
    1. Use UUID instead of Player. (For the lists)
    2. Simply check if the player is offline, if they are offline, remove them from the list.
     
  3. Offline

    Vipevsiki1337

    Can you show me all code?
     
  4. Offline

    KarimAKL

    @Vipevsiki1337 To check if a player is offline from a UUID, you can do something like this:
    Code:Java
    1. OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
    2. if (!player.isOnline()) {
    3. // Player is offline
    4. }
    5. // Player is online
     
  5. Offline

    Vipevsiki1337

    Ok, anyone can show me all code?
    I do not understand :/
     
  6. Offline

    bwfcwalshy Retired Staff

    Remove all the lists, instead use a HashMap<UUID, ParticleEffect> after that make a PlayerQuitEvent function and remove from the map (this silently fails if player isn't in it). Then, during the runnable just do 1 for loop of entrySet and spawn the Entry#getValue at the Player of Entry#getKey's location.

    To add the GUI code for this, simply put into the map with the right material.

    If you need help try and look at the JavaDocs or StackOverflow first before asking here. Being able to self-solve is a skill you'll need to learn.
     
Thread Status:
Not open for further replies.

Share This Page