Delay

Discussion in 'Plugin Development' started by klofno1, Jul 16, 2013.

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

    klofno1

    Hi, I am working on a plugin but I need to delay the chat command. I have been using some delay methods but they do not work so I've done something wrong. Could someone give me some clear direction on how to delay the command with 60 ticks?

    Main.java
    Code:java
    1. package me.Magic.JonathanNLD;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8.  
    9. public class Main extends JavaPlugin {
    10. private static final Logger log = Logger.getLogger("Minecraft");
    11. public static Main plugin;
    12.  
    13. @Override
    14. public void onEnable(){
    15. this.getServer().getPluginManager().registerEvents((Listener) new SpellsListener(), this);
    16. log.info("The Magic plugin has been enabled!");
    17. }
    18.  
    19.  
    20.  
    21. @Override
    22. public void onDisable(){
    23. log.info("The Magic plugin has been disabled!");
    24. }
    25.  
    26.  
    27.  
    28.  
    29. }


    SpellsListener.java
    Code:java
    1. package me.Magic.JonathanNLD;
    2.  
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.player.AsyncPlayerChatEvent;
    7.  
    8. public class SpellsListener implements Listener {
    9.  
    10. @EventHandler
    11. public void onInteract(AsyncPlayerChatEvent event){
    12. //AsyncPlayerChatEvent is used for chat commands
    13. Player player = event.getPlayer();
    14. //This 'gets'
    15. String message = event.getMessage();
    16. //This replaces event.getMessage with 'message'
    17. if (message.trim().equalsIgnoreCase("fulmen"))
    18. //The chat command + trims the command down to only 'fulmen'
    19. player.getWorld().strikeLightning(player.getTargetBlock(null, 100).getLocation());
    20. //This activates the lightning
    21.  
    22. }
    23. }
    24.  
    25.  

     
  2. Offline

    soulofw0lf

    final Player p = player;
    new BukkitRunnable(){
    @Override
    public void run(){
    p.getWorld().strikeLightning(player.getTargetBlock(null, 100).getLocation());
    }
    }.runTaskLater(plugin, 60);
     
  3. Offline

    klofno1

    soulofw0lf

    Error with 'plugin'. plugin cannot be resolved to a variable
    Shall I add this :

    Code:java
    1. Main plugin;
    2. public SpellsListener(Main plugin){
    3. this.plugin = plugin;
    4. }
     
  4. Offline

    soulofw0lf

    yes exactly
     
  5. Offline

    klofno1

    soulofw0lf

    This gives me an error in my main.java
    The constructor SpellsListener() is undefined
    Code:java
    1. package me.Magic.JonathanNLD;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8.  
    9. public class Main extends JavaPlugin {
    10. private static final Logger log = Logger.getLogger("Minecraft");
    11. public static Main plugin;
    12.  
    13. @Override
    14. public void onEnable(){
    15. this.getServer().getPluginManager().registerEvents((Listener) new SpellsListener(), this);
    16. log.info("The Magic plugin has been enabled!");
    17. }
    18.  
    19.  
    20.  
    21. @Override
    22. public void onDisable(){
    23. log.info("The Magic plugin has been disabled!");
    24. }
    25.  
    26.  
    27.  
    28.  
    29. }

     
  6. Offline

    soulofw0lf

    new SpellsListener()
    should be
    new SpellsListener(this)

    i believe?
     
Thread Status:
Not open for further replies.

Share This Page