Solved BukkitRunnable Class Help

Discussion in 'Plugin Development' started by Harry5573, Aug 5, 2013.

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

    Harry5573

    Hello everyone, im trying to find out out how to cancel a bukkit runnable class and im having no luck, i have tried Bukkit.getScheduler().cancelTask but i cant find a way to get the id and then it gives me a error saying its not running when it is D:. Heres the classes

    CTC Class:
    Code:
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package com.mctnt.plugin.gamemodes;
     
    import com.mctnt.countdown.Cycle;
    import com.mctnt.countdown.Game;
    import com.mctnt.plugin.core.TheMcTnTPlugin;
    import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
    import com.sk89q.worldguard.protection.ApplicableRegionSet;
    import com.sk89q.worldguard.protection.flags.StateFlag;
    import com.sk89q.worldguard.protection.managers.RegionManager;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockFromToEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.scheduler.BukkitRunnable;
     
    /**
    *
    * @author Harry5573
    */
    public class CaptureTheCore implements Listener {
     
        public static TheMcTnTPlugin plugin;
        public static final StateFlag RED_CORE = new StateFlag("redcore", false);
        public static final StateFlag BLUE_CORE = new StateFlag("bluecore", false);
     
        public CaptureTheCore(TheMcTnTPlugin instance) {
            this.plugin = instance;
        }
       
        @EventHandler
        public void onBreak(BlockBreakEvent e) {
            Player player = e.getPlayer();
            WorldGuardPlugin wgp = this.plugin.getWGP();
     
            Location playerloc = e.getBlock().getLocation();
            RegionManager rm = wgp.getRegionManager(playerloc.getWorld());
            ApplicableRegionSet applicableRegions = rm.getApplicableRegions(playerloc);
     
            if ((applicableRegions.allows(RED_CORE)) && (plugin.isRed.contains(player))) {
                e.setCancelled(true);
                player.sendMessage(ChatColor.RED + "You may not break your own core");
                return;
            }
            if ((applicableRegions.allows(BLUE_CORE)) && (plugin.isBlue.contains(player))) {
                e.setCancelled(true);
                player.sendMessage(ChatColor.RED + "You may not break your own core");
                return;
            }
     
        }
     
        @EventHandler
        public void onPlace(BlockPlaceEvent e) {
            Player player = e.getPlayer();
            WorldGuardPlugin wgp = this.plugin.getWGP();
     
            Location playerloc = e.getBlock().getLocation();
            RegionManager rm = wgp.getRegionManager(playerloc.getWorld());
            ApplicableRegionSet applicableRegions = rm.getApplicableRegions(playerloc);
     
            if ((applicableRegions.allows(RED_CORE)) || (applicableRegions.allows(BLUE_CORE) && (!plugin.isAdminMode.contains(player.getName())))) {
                e.setCancelled(true);
                player.sendMessage(ChatColor.RED + "You may not place blocks in the cores");
                return;
            }
        }
       
        @EventHandler
        public void onLavaFlow(BlockFromToEvent e) {
           
            if (!plugin.cfManager.getMapsFile().get("Maps." + plugin.getCurrentMap() + ".gamemode").equals("ctc")) {
                return;
            }
     
            int coreredx = plugin.cfManager.getMapsFile().getInt("Maps." + plugin.getCurrentMap() + ".Core-Red-Lava-X");
            int coreredz = plugin.cfManager.getMapsFile().getInt("Maps." + plugin.getCurrentMap() + ".Core-Red-Lava-Z");
            int corebluex = plugin.cfManager.getMapsFile().getInt("Maps." + plugin.getCurrentMap() + ".Core-Blue-Lava-X");
            int corebluez = plugin.cfManager.getMapsFile().getInt("Maps." + plugin.getCurrentMap() + ".Core-Blue-Lava-Z");
     
            //Just to be sure
            if (!e.getBlock().getWorld().getName().equals(plugin.getCurrentMap())) {
                return;
            }
     
            if (!(e.getBlock().getType() == Material.STATIONARY_LAVA || e.getBlock().getType() == Material.LAVA)) {
                return;
            }
           
            if (!(plugin.getConfig().getString("incycle").equals("false") && (plugin.getConfig().getString("inpregame").equals("false")))) {
                System.out.println("Wasnt in a game wtf");
                return;
            }
     
            if ((e.getBlock().getLocation().getBlockX() == coreredx) && (e.getBlock().getLocation().getBlockZ() == coreredz)) {
                System.out.println("[TheMcTnTPlugin] Blue team won the game!");
                Bukkit.broadcastMessage(ChatColor.GREEN + "################################");
                Bukkit.broadcastMessage(ChatColor.BLUE + "Blue Team Has Destroyed The Red Teams Core!");
                Bukkit.broadcastMessage(ChatColor.GREEN + "################################");
               
                //Cancel the game task
               
               
                //Cycle the maps!
                new Cycle(plugin).runTaskTimer(plugin, 0L, 20L);
                return;
            }
            if ((e.getBlock().getLocation().getBlockX() == corebluex) && (e.getBlock().getLocation().getBlockZ() == corebluez)) {
                Bukkit.broadcastMessage(ChatColor.GREEN + "################################");
                Bukkit.broadcastMessage(ChatColor.RED + "Red Team Has Destroyed The Blue Teams Core!");
                Bukkit.broadcastMessage(ChatColor.GREEN + "################################");
                //Cancel the game task
               
               
                //Cycle the maps!
                new Cycle(plugin).runTaskTimer(plugin, 0L, 20L);
                return;
            }
        }
    }
    
    Bukkit Runnable Class:
    Code:
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package com.mctnt.countdown;
     
    import com.mctnt.plugin.core.TheMcTnTPlugin;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.scheduler.BukkitRunnable;
     
    /**
    *
    * @author Harry5573
    */
    public class Game extends BukkitRunnable {
     
        public static TheMcTnTPlugin plugin;
        private int time;
     
        public Game(TheMcTnTPlugin instance, int time) {
            this.time = time;
            this.plugin = instance;
        }
       
        public void cancelTask() {
            this.cancel();
        }
       
        public void run()
        {
           
            if (time > 0) {
                if (time == plugin.cfManager.getMapsFile().getInt("Maps." + plugin.getCurrentMap() + ".timemax") - 1) {
                    Bukkit.broadcastMessage(ChatColor.DARK_PURPLE + "###########################################");
                    Bukkit.broadcastMessage(ChatColor.DARK_PURPLE + "#############" + ChatColor.GREEN + "The Match has started" + ChatColor.DARK_PURPLE + "#########");
                    Bukkit.broadcastMessage(ChatColor.DARK_PURPLE + "###########################################");
                   
                    //Force teleport everyone
                    for (Player pls : Bukkit.getOnlinePlayers()) {
                        plugin.rb.forceTpTeams(pls);
                    }
                }
               
                time--;
            }
            if (time == 0) {
                Bukkit.broadcastMessage(ChatColor.DARK_PURPLE + "###########################################");
                Bukkit.broadcastMessage(ChatColor.DARK_PURPLE + "##############" + ChatColor.DARK_RED + "The Match is over!" + ChatColor.DARK_PURPLE + "##############");
                Bukkit.broadcastMessage(ChatColor.DARK_PURPLE + "######" + ChatColor.AQUA + "" + ChatColor.BOLD + "The Match Expired With No Winner" + ChatColor.DARK_PURPLE + "######");
                Bukkit.broadcastMessage(ChatColor.DARK_PURPLE + "###########################################");
                new Cycle(plugin).runTaskTimer(plugin, 0L, 20L);
                System.out.println("[TheMcTnTPlugin] Cycling maps..");
               
                this.cancel();
            }
        }
    }
    
    Nevermind guys, just used this as its the only one running

    Code:
                Bukkit.getScheduler().cancelAllTasks();
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  2. Offline

    UltraFireFX

Thread Status:
Not open for further replies.

Share This Page