[URGENT For My Plugin!] Schedulers/Intervals?

Discussion in 'Plugin Development' started by LandonTheGeek, Mar 30, 2013.

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

    LandonTheGeek

    Hey guys,
    Beast here. I need to get an update out there for my Broadcaster, "EasyBroadcast". What I am wanting to know is "what" the coding script is to add an interval to messages. I have looked EVERYWHERE! I looked on Youtube. I look EVEN on TheBCBroz. (That one is outdated.) This is urgent, as it will help accelerate my plugin greatly. I can give you a piece of my code if you need it to "insert" some stuff in. :D

    Thanks!
    -xXTh3B3astXxify
     
  2. Offline

    kreashenz

    Use the Bukkit Schedulers, and set the config time to broadcast in that time.. I don't find it hard, but I just can't do schedulers.. Something like,
    Code:
    //Scheduler line, try using a taskTimer
    public void run() {
    // do the broadcast here
    }, this.getConfig().getInt("interval"), 0)
    }
    It should look like that, I'm not sure, really.
     
  3. Offline

    LandonTheGeek

    Since you sound like a relevant guy, what would it look like if you inserted that code into this?

    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]) {
            if(commandLabel.equalsIgnoreCase("broadcast")) {
                Player player = (Player) sender;
                StringBuilder sb = new StringBuilder();
                for(int i = 0; i < args.length; i++){
                  sb.append(args[i]).append(" ");
                }
                if(sender.hasPermission(new Permissions().Broadcast)){
                Bukkit.broadcastMessage(ChatColor.LIGHT_PURPLE + "[" + (getConfig().getString("BroadcastPrefix")) + "] " + ChatColor.GREEN + sb.toString());
                } else{
                    player.sendMessage(ChatColor.LIGHT_PURPLE + "You don't have permission!");
                }
            }
            }
    P.S. I tried it, and failed, as I don't have TO much Java EXP. xD

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  4. Offline

    kreashenz

    Uhhm, honestly, I have no clue :) I haven't really used Schedulers, so I'm not sure..
     
  5. Offline

    LandonTheGeek

    kreashenz

    Okay. Thank you for trying. :) Can anyone else sort this out please? This is urgent!

    Can someone please help me on this? This is still UnSolved, and it is urgent!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  6. Offline

    Cybermaxke

    It should be something like this:
    Code:
    new BukkitRunnable() {
     
        @Override
        public void run() {
            //Do stuff
        }
     
    }.runTaskLater(plugin, delay);
     
  7. Offline

    LandonTheGeek

    How would you insert it in this line of code? Sorry, I'm not pro at Java yet. :D

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]) {
            if(commandLabel.equalsIgnoreCase("broadcast")) {
                Player player = (Player) sender;
                StringBuilder sb = new StringBuilder();
                for(int i = 0; i < args.length; i++){
                  sb.append(args[i]).append(" ");
                }
                if(sender.hasPermission(new Permissions().Broadcast)){
                Bukkit.broadcastMessage(ChatColor.LIGHT_PURPLE + "[" + (getConfig().getString("BroadcastPrefix")) + "] " + ChatColor.GREEN + sb.toString());
                } else{
                    player.sendMessage(ChatColor.LIGHT_PURPLE + "You don't have permission!");
                }
            }
            }
     
  8. Offline

    LandonTheGeek

    Does anyone know? It has been over 24HRS so *BUMP* :D

    I need to update this soon or I will get yelled at. :D Can I please have helped on the Schedule Repeating Task with that line of code above my post just recently?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  9. Offline

    Cybermaxke

    It should be something like this:
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]) {
        if(commandLabel.equalsIgnoreCase("broadcast")) {
            Player player = (Player) sender;
            final StringBuilder sb = new StringBuilder();
            for (int i = 0; i < args.length; i++){
                sb.append(args[i]).append(" ");
            }
            if(sender.hasPermission(new Permissions().Broadcast)){
                new BukkitRunnable() {
                   
                    @Override
                    public void run() {
                        Bukkit.broadcastMessage(ChatColor.LIGHT_PURPLE + "[" + (getConfig().getString("BroadcastPrefix")) + "] " + ChatColor.GREEN + sb.toString());
                    }
                   
                }.runTaskLater(plugin, delay);
            } else{
                player.sendMessage(ChatColor.LIGHT_PURPLE + "You don't have permission!");
            }
        }
    }
     
  10. Offline

    LandonTheGeek

    By the way... Thank you for the response. Greatly appreciated.

    Number One: what do I put in "plugin"?

    Code:
    }.runTaskLater(plugin, delay);
    Number Two: How do I insert a messages.txt into public void run() so that I can run a line of messages on the interval?

    Thanks my man!
    Beast
     
Thread Status:
Not open for further replies.

Share This Page