Source Code

package com.gmail.mattglas.superpickaxe;
 
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;

import net.milkbowl.vault.Vault;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.plugins.Economy_3co;
import net.milkbowl.vault.economy.plugins.Economy_AEco;

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.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
 
public final class main extends JavaPlugin {
	public HashMap<String, Long> cooldowns = new HashMap<String, Long>();
	private Economy economy;
	public void loadConfiguration(){
		this.getConfig().set("hastelevel", 127);
		this.getConfig().set("cost", 500);
		this.getConfig().set("cooldown", 90);
		this.getConfig().set("allowparticle", true);
		this.getConfig().set("allowtimeset", true);
		this.getConfig().set("defaulttime", false);
	    this.getConfig().options().copyDefaults(true); 
	    String[] list = {"#allowtimeset: Allows players to set their own mining time", "#defaulttime Sets the time to a default of 30 Minutes", "#allowparticle Allows an alert to the player that SPA is enabled", "#hastelevel #The level of haste when mining. This is controllable so you can allow them to mine fast, but not enough to demolish an area,", "#cooldown The cooldown the player has to wait until they can use it again", "#cost How much it costs to use /spa"};
		this.getConfig().set("instructions", Arrays.asList(list));
	     this.saveConfig();
	     
	}
    public void onEnable() {
    	loadConfiguration();
		if(!new File(this.getDataFolder(),"config.yml").exists()) {
			this.saveDefaultConfig();
		}
		if(Bukkit.getPluginManager().getPlugin("Vault") instanceof Vault)
		{
			RegisteredServiceProvider<Economy> service = Bukkit.getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);

			if(service != null)
				economy = service.getProvider();
		}
		}
    
 
    @Override
    public void onDisable() {
        // TODO Insert logic to be performed when the plugin is disabled
    }
    @SuppressWarnings("deprecation")
	@Override
    public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String[] args) {
    	final Player player  = (Player) sender;
    	
    	if (commandlabel.equalsIgnoreCase("spas")) { // If the player typed /basic then do the following...
    		if (player.hasPermission("superpickaxe.use")) {
       		 int cooldownTime = getConfig().getInt("cooldown");; // Get number of seconds from wherever you want
 	        if(cooldowns.containsKey(sender.getName())) {
 	            long secondsLeft = ((cooldowns.get(sender.getName())/1000)+cooldownTime) - (System.currentTimeMillis()/1000);
 	            if(secondsLeft>0) {
 	                // Still cooling down
 	                sender.sendMessage("You cant use that commands for another "+ secondsLeft +" seconds!");
 	                return true;
 	            }
 	        }
 	        // No cooldown found or cooldown has expired, save new cooldown
 	        cooldowns.put(sender.getName(), System.currentTimeMillis());
 	        

    		int cost = getConfig().getInt("cost");
    		economy.withdrawPlayer(player.getName(), cost);
    		if(this.getConfig().getBoolean("allowparticle")) {
    		Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                public void run() {
                                ParticleEffect.ENCHANTMENT_TABLE.display(player.getLocation().add(0, 2, 0), 15, 0, 0, 0, 10, 10);
                        
                }
        }, 0, 12000);
    		}
    		if(this.getConfig().getBoolean("allowtimeset")) {
    		if(args.length == 1) {
                int time = Integer.parseInt(args[0]);
                int amount = getConfig().getInt("hastelevel");
        		player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, time*1200, amount));
    		}
    		}
    		if(this.getConfig().getBoolean("defaulttime")) {
    			int amount = getConfig().getInt("hastelevel");
    		player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 36000, amount));
    		} else {
    			}
    		}
    	}else if (commandlabel.equalsIgnoreCase("spao")) {
    		if (player.hasPermission("superpickaxe.use")) {
    	    for (PotionEffect effect : player.getActivePotionEffects())
    	        player.removePotionEffect(effect.getType());
    		} else {
    			}
    }else if (commandlabel.equalsIgnoreCase("spa")) {
    	if (player.hasPermission("superpickaxe.use")) {
    	sender.sendMessage(ChatColor.AQUA + "" + "Welcome "+sender.getName()+" to the Mineguild Super Pickaxe Menu!");
    	sender.sendMessage(ChatColor.AQUA + "" + "Listed here are the plugins commands.");
    	sender.sendMessage(ChatColor.GREEN + "" + "To enable and set time: /spas (Minute)");
    	sender.sendMessage(ChatColor.RED + "" + "To disable: /spao");
    	} else {
			}
}
		return false;
}
}

Comments

Posts Quoted:
Reply
Clear All Quotes