Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CommandHandler implements CommandExecutor {
- public static HashMap<UUID, Integer> cooldownTime = new HashMap<UUID, Integer>();
- public static HashMap<UUID, BukkitRunnable> cooldownTask = new HashMap<UUID, BukkitRunnable>();
- public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) {
- if (!(sender instanceof Player)) {
- sender.sendMessage("You aint no player!");
- return false;
- }
- final Player p = (Player) sender;
- if (command.equalsIgnoreCase("smelt")) {
- if (cooldownTime.containsKey(p.getUniqueId())) {
- p.sendMessage(ChatColor.AQUA + "You must wait " + cooldownTime.get(p.getUniqueId()) + " seconds before using that command again!");
- return true;
- }
- cooldownTime.put(p.getUniqueId(), 5 * 60 * 20);
- cooldownTask.put(p.getUniqueId(), new BukkitRunnable() {
- public void run() {
- cooldownTime.put(p.getUniqueId(), cooldownTime.get(p.getUniqueId()) - 1);
- if (cooldownTime.get(p.getUniqueId()) == 0) {
- cooldownTime.remove(p.getUniqueId());
- cooldownTask.remove(p.getUniqueId());
- cancel();
- }
- }
- });
- cooldownTask.get(p.getUniqueId()).runTaskTimer(Bukkit.getPluginManager().getPlugin("Smelt"), 20, 20);
- for (ItemStack is : p.getInventory().getContents()) {
- if (is == null) continue;
- if (is.getType() == null) continue;
- int amount = is.getAmount();
- switch (is.getType()) {
- case DIAMOND_ORE:
- p.getInventory().remove(is);
- p.getInventory().addItem(new ItemStack(Material.DIAMOND, amount));
- break;
- case EMERALD_ORE:
- p.getInventory().remove(is);
- p.getInventory().addItem(new ItemStack(Material.EMERALD, amount));
- break;
- case GOLD_ORE:
- p.getInventory().remove(is);
- p.getInventory().addItem(new ItemStack(Material.GOLD_INGOT, amount));
- break;
- case IRON_ORE:
- p.getInventory().remove(is);
- p.getInventory().addItem(new ItemStack(Material.IRON_INGOT, amount));
- break;
- case COAL_ORE:
- p.getInventory().remove(is);
- p.getInventory().addItem(new ItemStack(Material.COAL, amount));
- break;
- }
- }
- p.sendMessage(ChatColor.AQUA + "You have smelted your inventory!");
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement