Solved How can I add a bukkit scheduler to this?

Discussion in 'Plugin Development' started by SympatheticSky, Feb 17, 2017.

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

    SympatheticSky

    I have been looking all over the web for 2 hours and putting in

    Main:
    Code:
    package com.sky.sympathy;
    
    import java.util.logging.Logger;
    
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.sky.sympathy.BotMAR.MaR;
    
    public class MainBot extends JavaPlugin {
       
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = getDescription();
            Logger logger = Logger.getLogger("Minecraft");
           
            registerEvents();
           
            logger.info(pdfFile.getName() + " has been enabled (V." + pdfFile.getVersion() + ")");
        }
       
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = getDescription();
            Logger logger = Logger.getLogger("Minecraft");
           
            logger.info(pdfFile.getName() + " has been enabled (V." + pdfFile.getVersion() + ")");
        }
    
        public void registerEvents() {
            PluginManager pm = getServer().getPluginManager();
           
            pm.registerEvents(new MaR(), this);
    }
       
    }
    code myself trying to find a solution and I can not do it... How can I add a scheduler to this?

    Other Class:
    Code:
    package com.sky.sympathy.BotMAR;
    
    import org.bukkit.Bukkit;
    
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    
    
    public class MaR implements Listener {
        @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent event) {
            Player player = event.getPlayer();
            String message = event.getMessage().toLowerCase();
            if (message.contains("hey symbot")) {
                event.setCancelled(false);
    Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + "[Symbot] " + ChatColor.DARK_PURPLE + "Hello " + player.getName() + "!");
                }
        }
       
    }
    I am basically trying to make the message delay in front of the players chat
    Example:
    <Player> hey symbot
    <SymBot> Hello Player

    What I am getting is:
    <SymBot> Hello Player
    <Player> hey symbot

    Btw I am new to bukkit coding and have little knowledge of Java
     
  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    PQE

    The code in your eventhandler is always run before what the event would normally happen would run (this way you can still cancel it). You want to use a Bukkit scheduler, eg:

    getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    @Override
    public void run() {
    //CODE
    }
    }, SECONDS * 20);
     
  4. @SympatheticSky Please do not learn off the BcBroz he is a very bad source for tutorials, I am not in the mood to find links and go through what's wrong right now so I'll tag someone instead.
    @mine-care
     
  5. Offline

    mine-care

    @bwfcwalshy Got it!


    Right, BcBroz is a really bad way to start with bukkit, i think that most experienced members of these forums are watching videos from this channel to have a laugh. Bellow im quoting parts of your code which need improvement and why that is. Most of these practices source from TheBcBroz channel.

    Package names in java, must be all lower case. Although this doesnt affect code performance, it violates the Naming Conventions making the code harder to read and maintain in the long run.

    Ah... Clasical BcBroz, Well let the Minecraft logger alone and use getLogger() to get your plugin's logger if you need to print a message on console.

    You don't need enable messages all togeather because bukkit already displays them by default.

    Likewise, you don't need disable messages as bukkit already takes care of them. Furthermore after removing the message lines there is no need to overwrite the onDisable method because it is not used for anything ;)

    Typically classes should be assigned sensible names related to their purpose, Again a convention but trust me it is usefull future-wise :p

    Remember, the method contains() is case sensitive! "ABC".contains("a") is false.

    Keep those in mind next time you make a plugin and try some other way of learning Java. Not BcBroz!
     
  6. Offline

    SympatheticSky


    Thanks for the assistance! Do you recommend Pogo?
     
  7. mine-care likes this.
  8. Offline

    mine-care

Thread Status:
Not open for further replies.

Share This Page