Solved Particle Effcts

Discussion in 'Spigot Plugin Development' started by ula492, May 23, 2016.

  1. Edit:
    One more question :) is adding this to a UUID List a good idea? Im using it activate and deactivate the effect
    or is their a much nicer and neater way to do it?
    Code (Text):
       public static ArrayList<UUID> WaterHelix = new ArrayList<UUID>();


        public static void WH(final Player p) {

            if (WaterHelix.contains(p.getPlayer().getUniqueId())) {
                new BukkitRunnable() {

                    public void run() {
                        double phi = 0;

                        phi += Math.PI / 8;
                        double x;
                        double y;
                        double z;

                        Location loc = p.getLocation();
                        for (double t = 0; t <= 2 * Math.PI; t += Math.PI / 16) {
                            for (double i = 0; i <= 1; i += 1) {
                                x = 0.3 * (2 * Math.PI - t) * 0.5 * Math.cos(t + phi + i * Math.PI);
                                y = 0.5 * t;
                                z = 0.3 * (2 * Math.PI - t) * 0.5 * Math.sin(t + phi + i * Math.PI);
                                loc.add(x, y, z);
                                ParticleEffect.WATER_DROP.display(0, 0, 0, 0, 10, loc, 30);
                                loc.subtract(x, y, z);
                            }
                        }
                    }
                }.runTaskTimer(Main.getInstance(), 0, 2);
            }
        }
     
    This is how I call it and activate it
    Code (Text):
    f (event.getCurrentItem().getItemMeta().getDisplayName().contains("§a§lHelix")) {
                event.setCancelled(true);
                WaterHelix.add(event.getWhoClicked().getUniqueId());
                if(WaterHelix.contains(p.getUniqueId())){
                    WH(p);
                }
                p.closeInventory();
            }
    This is how I Unactivate it
    Code (Text):

            if (event.getItem().getItemMeta().getDisplayName().contains("§aParticle Menu")) {
                if(!p.hasPermission("Rank.Particle.use")){
                    event.setCancelled(true);
                    p.getPlayer().playSound(p.getPlayer().getLocation(), Sound.ANVIL_LAND, 4F, 4F);
                    p.sendMessage("§4You Do not have the require rank to open this, Visit §awww.thevoidmc.net to purchase a rank!");
                }else{
                    event.setCancelled(true);
                    p.playSound(p.getLocation(), Sound.CLICK, 4F, 4F);
                    ParticleMenu.ParticleGUI(p);
                    Water.WaterHelix.remove(p.getUniqueId());
                }

            }


    --------------------------------Old question Below--------------------------------

    So, for the past week ive been looking around for something to help me
    I found this (http://dev.bukkit.org/bukkit-plugins/effectlib/ , https://bukkit.org/threads/creating-a-helix-3d-spiral-out-of-particles.314312/) Does were the biggest "help" but I still cant figure it out.

    I have this current code

    It no work :(

    Code (Text):
        public static void WH(final Player p){
            new BukkitRunnable(){
                double phi = 0;
                public void run(){

                    phi += Math.PI/8;
                    double x; double y; double z;

                    Location loc = p.getLocation();
                    for (double t = 0; t <=2*Math.PI; t += Math.PI/16){
                        for (double i = 0;  i <= 1; i += 1){
                            x =  0.3 * (2 * Math.PI - t ) * 0.5 * Math.cos(t + phi + i * Math.PI);
                            y =  0.5 * t;
                            z =  0.3 * (2 * Math.PI - t ) * 0.5 * Math.sin(t + phi + i * Math.PI);
                            loc.add(x,y,z);
                            ParticleEffect.WATER_DROP.display(0, 0, 0, 1, 1, loc, 1);
                            loc.subtract(x,y,z);
                        }
                    }
                    if(phi > 10*Math.PI){
                        this.cancel();
                    }
                }
            }.runTaskTimer(this.plugin, 0, 3);
        }
    Im not asking for a code fix or spoon feed(which would be nice) Im asking for a link to forum post or something to lead me the right way to help me:).
     
    #1 ula492, May 23, 2016
    Last edited: May 25, 2016
  2. What no work?
     
  3. The code. Cus of the "this.plugin" Which I dont want to fix (Because Ive read its not the "best way"), So Im looking for a better way to do this particle Effect.
     
  4. replace this.plugin with an instance of your main
     
  5. I was trying that earlier but it was null. But i got it to work now.
     
  6. I don't understand, where have you heard that? What's bad about it? All it's doing is using the instance of your plugin from the constructor. I see no harm.
     
  7. a particle coder told me that, He has more experience so i just went a long with it. :/
     
  8. More experience with what exactly? Just because they know a little bit more math doesn't mean they understand everything about Java. If you are just passing an instance from your plugin in a constructor, there is nothing wrong with it
     
    #9 GamerzKing, May 23, 2016
    Last edited: May 23, 2016
    • Like Like x 1
    • Agree Agree x 1
  9. Try
    Code (Java):

                            x =  0.5 * (2 * Math.PI - t ) * Math.cos(t + phi + (i * Math.PI));
                            y =  t / (Math.PI / 16);
                            z =  0.5 * (2 * Math.PI - t ) * Math.sin(t + phi + (i * Math.PI));
     
    If that works I'll provide an good explanation. :)
     
  10. Did not work, it didnt even run :( / No errors
     
    #11 ula492, May 23, 2016
    Last edited: May 23, 2016
  11. Ive got it too work, the only issue is that people cant see it
     
  12. Change that to:

    ParticleEffect.WATER_DROP.display(0, 0, 0, 1, 1, loc, 30);

    that last number says how close you need to be to see it
     
  13. what does 30 mean? Blocks? Or
     
  14. Blocks i think :p
     
  15. One more question :) is adding this to a UUID List a good idea? Im using it activate and deactivate the effect
    or is their a much nicer and neater way to do it?
    Code (Text):
       public static ArrayList<UUID> WaterHelix = new ArrayList<UUID>();


        public static void WH(final Player p) {

            if (WaterHelix.contains(p.getPlayer().getUniqueId())) {
                new BukkitRunnable() {

                    public void run() {
                        double phi = 0;

                        phi += Math.PI / 8;
                        double x;
                        double y;
                        double z;

                        Location loc = p.getLocation();
                        for (double t = 0; t <= 2 * Math.PI; t += Math.PI / 16) {
                            for (double i = 0; i <= 1; i += 1) {
                                x = 0.3 * (2 * Math.PI - t) * 0.5 * Math.cos(t + phi + i * Math.PI);
                                y = 0.5 * t;
                                z = 0.3 * (2 * Math.PI - t) * 0.5 * Math.sin(t + phi + i * Math.PI);
                                loc.add(x, y, z);
                                ParticleEffect.WATER_DROP.display(0, 0, 0, 0, 10, loc, 30);
                                loc.subtract(x, y, z);
                            }
                        }
                    }
                }.runTaskTimer(Main.getInstance(), 0, 2);
            }
        }
     
    This is how I call it and activate it
    Code (Text):
    f (event.getCurrentItem().getItemMeta().getDisplayName().contains("§a§lHelix")) {
                event.setCancelled(true);
                WaterHelix.add(event.getWhoClicked().getUniqueId());
                if(WaterHelix.contains(p.getUniqueId())){
                    WH(p);
                }
                p.closeInventory();
            }
    This is how I Unactivate it
    Code (Text):

            if (event.getItem().getItemMeta().getDisplayName().contains("§aParticle Menu")) {
                if(!p.hasPermission("Rank.Particle.use")){
                    event.setCancelled(true);
                    p.getPlayer().playSound(p.getPlayer().getLocation(), Sound.ANVIL_LAND, 4F, 4F);
                    p.sendMessage("§4You Do not have the require rank to open this, Visit §awww.thevoidmc.net to purchase a rank!");
                }else{
                    event.setCancelled(true);
                    p.playSound(p.getLocation(), Sound.CLICK, 4F, 4F);
                    ParticleMenu.ParticleGUI(p);
                    Water.WaterHelix.remove(p.getUniqueId());
                }

            }
     
    #16 ula492, May 24, 2016
    Last edited: May 24, 2016
  16. yes UUID is the good Idea but if you know how HashMap works would be more neat I think.
     
  17. ive never really used any of does too, or learnt about them a lot. But for some reason with that code I can not remove a player from the List..
     
  18. eh ?

    Code (Java):
    package com.seeula;

    import java.util.*;

    publicclassHashMapDemo{
       public static void main(String args[]){
       // create hash map
       HashMap<Integer, String> newmap =new HashMap<Integer, String>();  
     
       // populate hash map
       newmap.put(1,"me");
       newmap.put(2,"madmax");
       newmap.put(3,"cookie");
     
       System.out.println("Values before remove: "+ newmap);
     
       // remove value for key 2
       newmap.remove(2);

       System.out.println("Values after remove: "+ newmap);
       }
    }
     
  19. im using UUID not hash