Little countdown problem

Discussion in 'Plugin Development' started by CheifKeef, Feb 26, 2015.

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

    CheifKeef

    Im struggling on making a plugin that basically destroys your base in the case of a raid or you're in distress, when the player types /void they will be prompted with a message that states if they want to proceed, if they do they type /proceed and it counts down from 10 to 1 and it disperses tnt around the player killing him/her along with their base. I don't know how to do the TNT part, but I'm really having trouble with the count down i don't know whats wrong, I'm pretty new to coding.


    Code:
    package me.PokeMasterBrobee.Void;
    
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Void extends JavaPlugin{
        public final Logger logger = Logger.getLogger("Minecraft");
       
        public static int SecondsToCountDown=10;
        public static Plugin plugin;
        int taskID1;
        int taskID2;
       
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " has been disabled!");
        }
       
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " has been enabled!");
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = (Player) sender;
            if(cmd.getName().equalsIgnoreCase("Void")) {
                player.sendMessage(ChatColor.DARK_RED + "[" + ChatColor.YELLOW + "Warning" + ChatColor.DARK_RED + "]" + ChatColor.AQUA + " Are you sure you want to perform this command, If yes type /Proceed");
            }
            if(cmd.getName().equalsIgnoreCase("Proceed")) {
                if(player instanceof Player){
                    player.sendMessage(SecondsToCountDown + " seconds left untill total destruction");
                    startSecondsCountdown();
                }
            }
            return true;
        }
       
        public Runnable startSecondsCountdown() {
            taskID2 = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                public void run() {
                    SecondsToCountDown--;
                    if (SecondsToCountDown !=0) {
                        Bukkit.broadcastMessage(SecondsToCountDown + " seconds left untill destruction!");
                    }
                    if (SecondsToCountDown==0) {
                        plugin.getServer().getScheduler().cancelTask(taskID2);
                        SecondsToCountDown=5;
                        Bukkit.broadcastMessage("Boom!");
                    }
                }
            }, 20L, 20L);
            return null;
        }
       
    
    }
     
  2. Offline

    teej107

    I can see that. Stop watching BCBroz. His tutorials are one of the lowest of quality tutorials you can use.

    For the TnT part, it would require you knowing the location of the player's base.
     
  3. Offline

    Unica

    @CheifKeef

    • BukkitRunnable method
      Code:
      private final int TIME_TO_EXPLODE = 10;
      private void startCountdown(Player p){
          new BukkitRunnable(){
                int time = TIME_TO_EXPLODE;
                public void run(){
                }
          }.runTaskTimer(instance, delay, Ticks);
      }
    • Decrease the time with 1 for every 20 ticks. (Leave delay at 0)
    • If Time is equal to 0, proceed to your action, and cancel the Runnable
    • Add a Location object in the parameter for the explosions

    Why it currently doesn't work
    • You create a getter for a Runnable, and you return Null. Why a getter? Why null if you make a getter? (Why not a value)
    • You send the message one single time if the player does the command, a.k.a. It will send the message one single time, it's not a loop, or a runnable, or a thread. It's one single action, so it won't magically send you a message every second.
    • You cast the CommandSender to a Player object, and THEN you check if the sender is actually a Player object. Doesn't make sense.
    • BCBroz crap.
     
  4. Offline

    CheifKeef

    Ok, how would i get the persons location and then disperse tnt in that location killing the player along with destroying his/her base.
     
Thread Status:
Not open for further replies.

Share This Page