Particle Trail

Discussion in 'Plugin Development' started by XxZHALO13Xx, Dec 17, 2014.

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

    XxZHALO13Xx

    How would i make it so when a Player fires a bow it shows particles following the arrow? Without runnables would be the best since this isnt in my main class. Any help on where i need to start for this
     
  2. Offline

    Speaw

  3. Offline

    XxZHALO13Xx

    @Speaw Yes. I've seen that thread but it uses a run which i can't use. not in main class
     
  4. Offline

    Webbeh

    You can use a scheduler/runnable outside the main class without problem, you just have to point it to the main plugin...
     
  5. Offline

    XxZHALO13Xx

    @Webbeh Yes.. Everytime i have tried it doesnt work
     
  6. Offline

    nverdier

    Is there an error? What does it say?
     
  7. Offline

    XxZHALO13Xx

    @nverdier no like i dont know how to do the run thing... i dont know where to stick it in my other class. thats what i meant
     
  8. Offline

    AdamQpzm

    @XxZHALO13Xx Pass an instance of you main class to the other class, store it in a private field, and then you can use the field instead of 'this'
     
  9. Offline

    XxZHALO13Xx

    @AdamQpzm could i create a method that will call the run? like a public startSpell1 thing?
     
  10. Offline

    nverdier

    Ah. So you would have in the runnable class that extends BukkitRunnable
    Code:
    Bukkit.getServer().getScheduler().runTaskTimer(main, new Runnable() blah blah blah)
    Where main is:
    Code:
    private Main main;
    public <runnableClass>(Main pl) {
    this.main = pl;
    }
    This is in the runnable task. Then you call it in your main class.
     
    Last edited by a moderator: Dec 17, 2014
  11. Offline

    AdamQpzm

    @XxZHALO13Xx If you want to, sure. :)

    @nverdier No no no! Public static instances of the main class are bad! It's much better to pass an instance of the main class.
     
  12. Offline

    Monkey_Swag

    @XxZHALO13Xx use a regular runnable. Instead of using 'this' use whatever variable you decided to use for the instance of your main class.
     
  13. Offline

    nverdier

    Fixed :D *I knew that*..
     
    AdamQpzm likes this.
  14. Offline

    AdamQpzm

  15. Offline

    nverdier

    Damn fixed.
     
    AdamQpzm likes this.
  16. Offline

    XxZHALO13Xx

  17. Offline

    AdamQpzm

    @XxZHALO13Xx What version are you using and have you added both bukkit and craftbukkit to the build path?
     
  18. Offline

    XxZHALO13Xx

  19. Offline

    AdamQpzm

    @XxZHALO13Xx You need CraftBukkit too, the NMS classes are only found in CraftBukkit.
     
  20. Offline

    XxZHALO13Xx

    @AdamQpzm ah ok thx...

    Code:
     @Override
         public void run() {
             for(Projectile arrows : arrow){
                 for(Player online : Bukkit.getOnlinePlayers()){
                     Location loc = arrows.getLocation();
                     ((CraftPlayer) online).getHandle().playerConnection
                             .sendPacket(new PacketPlayOutWorldParticles(
                                     "witchMagic", (float) loc.getX(),
                                     (float) loc.getY(), (float) loc.getZ(), 1,
                                     1, 1,(float) 0, 6));
                 }
                 }
             }
    
    }, 0, 1);
    }
    
    @EventHandler
    public void onfirebow(EntityShootBowEvent e){
    arrow.add((Projectile) e.getProjectile());
    
    
    }
    @EventHandler
    public void onland(ProjectileHitEvent e){
    arrow.remove(e.getEntity());
    
    
    }
    
    
    }
    }, 0, 1); says
    Syntax error on tokens, ConstructorHeaderName expected instead
    fixed event thing

    @AdamQpzm heres my full class
    Code:
    public class FireSpell extends BukkitRunnable implements Listener{
       
        public List<String> toggledFireTrail = new ArrayList<String>();
        private static SpellGUI spellGuiClass;
        private static FireSpell fireSpell;
        public static ItemStack fireTrail;
        private Core core;
       
       
        private String FireTrailEN = ChatColor.RED + "" + ChatColor.BOLD + "Inferno Trail ENABLED";
        private String FireTrailDS = ChatColor.RED + "" + ChatColor.BOLD + "Inferno Trail DISABLED";
       
        public ArrayList<Projectile> arrow = new ArrayList<Projectile>();
       
        public FireSpell(Core pl) {
            this.core = pl;
            }
       
        public static ItemStack item1(String name){
            ItemStack i = new ItemStack(new ItemStack(Material.LAVA_BUCKET, 1));
            ItemMeta im = i.getItemMeta();
            im.setDisplayName(name);
            im.setLore(Arrays.asList("┬žaMakes Projectile's Trail Fire!"));
            i.setItemMeta(im);
            return i;
        }
       
        @SuppressWarnings("static-access")
        @EventHandler
        public void onInventoryClick(InventoryClickEvent e) {
            Player p = (Player) e.getWhoClicked();
            if (!e.getInventory().getName().equalsIgnoreCase(spellGuiClass.spellGui.getName())) return;
            if (e.getCurrentItem().getItemMeta() == null) return;
            if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Inferno Trail")){
                e.setCancelled(true);
                if(toggledFireTrail.contains(p.getName())){
                    toggledFireTrail.remove(p.getName());
                    p.sendMessage(Core.MAIN + FireTrailDS);
                }
                else{
                    toggledFireTrail.add(p.getName());
                    p.sendMessage(Core.MAIN + FireTrailEN);
                   
                }
                p.closeInventory();
            }
        }
       
         @Override
         public void run() {
             for(Projectile arrows : arrow){
                 for(Player online : Bukkit.getOnlinePlayers()){
                     Location loc = arrows.getLocation();
                     ((CraftPlayer) online).getHandle().playerConnection
                             .sendPacket(new PacketPlayOutWorldParticles(
                                     "witchMagic", (float) loc.getX(),
                                     (float) loc.getY(), (float) loc.getZ(), 1,
                                     1, 1,(float) 0, 6));
                 }
                 }
             }
    
    
    
    @EventHandler
    public void onfirebow(EntityShootBowEvent e){
    
    arrow.add((Projectile) e.getProjectile());
    
    
    }
    @EventHandler
    public void onland(ProjectileHitEvent e){
    arrow.remove(e.getEntity());
    
    
    }
    
    
    }
       
         
    @nverdier so nothing happened when i shot the bow

    @nverdier org.bukkit.Bukkit.getScheduler().scheduleSyncRepeatingTask(new FireSpell(), new Runnable(){ (Main Class) why doesnt this work? What do i need to do to fix cause i think itll make the plugin work

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  21. Offline

    SuperOriginal

    @XxZHALO13Xx FireSpell is not JavaPlugin so don't try and start a runnable with it.. Use your MAIN as everyone has told you already... Read up on the construction of runnables. It'll help you.
     
  22. Offline

    gamemster2468

    As SuperOriginal said, you need to use your main class.

    I would highly recommend using a constructor.

    Here's an example:

    Code:
    public ClassName{
    
    private MainClass plugin;
    
    public ClassName(MainClass plugin) {
    this.plugin = plugin;
    }
    
    plugin.WhatEver();
    
    }
     
Thread Status:
Not open for further replies.

Share This Page