This runnable won't work in a constructor...

Discussion in 'Plugin Development' started by JTGaming2012, Aug 19, 2014.

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

    JTGaming2012

    No idea why this won't work... Can I have some help please?
    Code:java
    1. public ArrowTurret(Location l) {
    2. this.setLocation(l);
    3. this.setTurret(l.getWorld().spawn(l, Villager.class));
    4. turret.setCustomName(name);
    5. turret.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 1000000, 49));
    6.  
    7. Main.plugin.getServer().getScheduler().scheduleSyncRepeatingTask(Main.plugin, new BukkitRunnable() {
    8. public void run() {
    9.  
    10. Bukkit.broadcastMessage("YEa");
    11.  
    12. }
    13. }, 20, 20);
    14. }


    Everything works until the runable!
     
  2. Offline

    br456

    Try this:
    Code:java
    1. Main.plugin.getServer().getScheduler().scheduleSyncRepeatingTask(Main.plugin, new Runnable() {
    2. @Override
    3. public void run() {
    4.  
    5. Bukkit.broadcastMessage("YEa");
    6.  
    7. }
    8. }, 20, 20);
    9. }

    Change the BukkitRunnable to Runnable, that is the object you need to use. Also, you need to override the run method, so use @Override annotation above your run method.
     
  3. Offline

    ZachBora

    This is the second time I see people use "Main", is that something that works for plugin?
     
  4. Offline

    br456

    ZachBora
    JT has a static Plugin variable in his main class
     
  5. Offline

    ZachBora

    br456 each plugin can have a main class?
     
  6. Offline

    br456

    ZachBora
    Just call you main class Main
     
  7. Offline

    Necrodoom

    ZachBora they basically named their base javaplugin class Main and are using it staticly.
    Should use instance instead.
     
Thread Status:
Not open for further replies.

Share This Page