Solved Plugin with money support and cooldown

Discussion in 'Plugin Development' started by Alayathekid, Jun 5, 2015.

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

    Alayathekid

    Hello I am new to making plugins, but am working on a project for a friend of mine. I was wondering how I could make it so that the plugin would subtract money from iConomy or something every time the command was used. While I'm talking about this is there a way to make it so that the player cannot use the command for a certain amount of time after he runs it once. This is the code btw

    Code:
    package me.alayathekid.tobedandspawn;
    
    import java.util.logging.Logger;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class tobedandspawnmain extends JavaPlugin{
        public final Logger logger = Logger.getLogger("Minecraft");
        public static tobedandspawnmain plugin;
      
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version: " + pdfFile.getVersion() + " has been Disabled!");
        }
      
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version: " + pdfFile.getVersion() + " has been Disabled!");
        }
      
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            if(commandLabel.equalsIgnoreCase("bed")){
                //working on a cost here
                //working on a cooldown timer here
                Location bedSpot = player.getBedSpawnLocation();
                player.teleport(bedSpot);
                player.sendMessage(ChatColor.GOLD + "You wake up in your bed!");
            }else if(commandLabel.equalsIgnoreCase("spawn")){
                Location worldSpawn = player.getWorld().getSpawnLocation();
                player.teleport(worldSpawn);
                player.sendMessage(ChatColor.GOLD + "You have been teleported to spawn!");
        }
        return false;
    }
    
    }

    It is based off of essentials btw, but I wanted to get the experience. I got to a stump trying to figure out the money and cooldowns...
     
  2. Offline

    ForsakenRealmz

  3. Offline

    Alayathekid

    Thank you, I do like tutorial videos, but I can never find them on google. :D not gonna put solved until finished though.

    Just found out that the same guy made a tutorial for vault! I'm going to mark as solved now!

    Problem again... I had the unreachable code error. Can you tell me some way to fix that in this code?

    Code:
    package me.alayathekid.tobedandspawn;
    
    import java.util.ArrayList;
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class tobedandspawnmain extends JavaPlugin{
        public final Logger logger = Logger.getLogger("Minecraft");
        public static tobedandspawnmain plugin;
       
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version: " + pdfFile.getVersion() + " has been Disabled!");
        }
       
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version: " + pdfFile.getVersion() + " has been Disabled!");
        }
       
        ArrayList<Player> cooldown = new ArrayList<Player>();
        ArrayList<Player> scd = new ArrayList<Player>();
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            final Player player = (Player) sender;
            if(commandLabel.equalsIgnoreCase("bed")){
                if (cooldown.contains(player)){
                    player.sendMessage(ChatColor.RED + "Please wait some more before running this command again!");
                    return true;
               
                //LINE UNDER unreachable code error
                Location bedSpot = player.getBedSpawnLocation();
                player.teleport(bedSpot);
                player.sendMessage(ChatColor.GOLD + "You wake up in your bed!");
                }
                cooldown.add(player);
                Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                    public void run() {
                        cooldown.remove(player);
                    }
                }, 1200);
                       
            }else if(commandLabel.equalsIgnoreCase("spawn")){
                if (scd.contains(player)){
                    player.sendMessage(ChatColor.RED + "Please wait some more before running this command again!");
                    scd.add(player);
                    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                        public void run() {
                            scd.remove(player);
                        }
                    }, 1200);
                    return true;
                }
                Location worldSpawn = player.getWorld().getSpawnLocation();
                player.teleport(worldSpawn);
                player.sendMessage(ChatColor.GOLD + "You have been teleported to spawn!");
        }
        return false;
    }
    
    }
    <Edit by mrCookieSlime: Merged posts. Please don't double post. There is an Edit Button right next to the Date.>
     
    Last edited by a moderator: Jun 5, 2015
  4. Offline

    Lilret123

    @Alayathekid
    You return, then tell it to do more stuff...(move that more stuff to before the return)
     
  5. Offline

    Alayathekid

    Yes. I found out about this last night, but I wasn't able to mark as solved because my internet crashed.
     
Thread Status:
Not open for further replies.

Share This Page