Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sirapathy.repairdelay;
- import java.io.File;
- import java.io.IOException;
- import net.milkbowl.vault.economy.Economy;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.Repairable;
- import org.bukkit.plugin.RegisteredServiceProvider;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin
- {
- FileConfiguration config = this.getConfig();
- File data = new File(this.getDataFolder()+"/data.yml");
- FileConfiguration dataConfig = YamlConfiguration.loadConfiguration(data);
- public static Economy economy = null;
- @Override
- public void onEnable()
- {
- if (!setupEconomy())
- {
- getLogger().info("(!) VAULT DEPENDENCY NOT FOUND, SHUTTING DOWN! (!)");
- getServer().getPluginManager().disablePlugin(this);
- }
- if (!(new File("plugins/RepairDelay/config.yml")).exists())
- {
- this.getConfig().options().copyDefaults(true);
- this.saveConfig();
- }
- if (!(new File("plugins/RepairDelay/data.yml")).exists())
- {
- dataConfig.options().copyDefaults(true);
- saveCustomYml(dataConfig, data);
- }
- }
- public void saveCustomYml(FileConfiguration ymlConfig, File ymlFile)
- {
- try
- {
- ymlConfig.save(ymlFile);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- private boolean setupEconomy()
- {
- RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
- if (economyProvider != null)
- {
- economy = economyProvider.getProvider();
- }
- return (economy != null);
- }
- public void repairAll(Player p)
- {
- for(ItemStack items : p.getInventory().getContents())
- {
- if(items instanceof Repairable)
- {
- items.setDurability((short)0);
- }
- }
- for(ItemStack items : p.getEquipment().getArmorContents())
- {
- if(items instanceof Repairable)
- {
- items.setDurability((short)0);
- }
- }
- }
- @SuppressWarnings("deprecation")
- public void cooldown(final Player p)
- {
- if (dataConfig.contains("data." + p.getUniqueId()))
- {
- Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable()
- {
- @Override
- public void run()
- {
- if (dataConfig.getInt("data." + p.getUniqueId() + ".cooldown") > 0)
- {
- String amount = config.getString("data." + p.getUniqueId() + ".cooldown");
- int newAmount = config.getInt("data." + p.getUniqueId() + ".cooldown");
- dataConfig.set(amount, newAmount - 1);
- }
- else
- {
- return;
- }
- }
- },0L,20L);
- }
- else
- {
- dataConfig.set("data." + p.getUniqueId() + ".cooldown", config.getString("options.delay"));
- }
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
- {
- Player p = (Player) sender;
- ItemStack handItem = p.getInventory().getItemInMainHand();
- if (cmd.getName().equalsIgnoreCase("test"))
- {
- p.sendMessage("hi");
- }
- if (sender instanceof Player)
- {
- if (p.hasPermission("repairdelay.allow"))
- {
- if (cmd.getName().equalsIgnoreCase("fix"))
- {
- if (args.length == 0)
- {
- if (handItem instanceof Repairable)
- {
- if (economy.getBalance(p) >= config.getInt("options.price"))
- {
- handItem.setDurability((short)0);
- p.sendMessage(config.getString("messages.successfulrepair"));
- economy.withdrawPlayer(p, config.getDouble("options.price"));
- cooldown(p);
- }
- else
- {
- p.sendMessage(config.getString("messages.notenoughmoney"));
- }
- }
- else
- {
- p.sendMessage(config.getString("messages.itemfulldurability"));
- }
- }
- else if (args.length == 1)
- {
- if (p.hasPermission("repairdelay.fixall"))
- {
- if (args[0].equalsIgnoreCase("all"))
- {
- repairAll(p);
- p.sendMessage(config.getString("messages.successfulrepairall"));
- cooldown(p);
- }
- else if (args[0].equalsIgnoreCase("help"))
- {
- p.sendMessage(ChatColor.GRAY + "" + ChatColor.STRIKETHROUGH + "-----------" + ChatColor.GREEN + " RepairDelay Help " + ChatColor.GRAY + "" + ChatColor.STRIKETHROUGH + "-----------");
- p.sendMessage(ChatColor.AQUA + "Commands:");
- p.sendMessage(ChatColor.GREEN + " /fix " + ChatColor.GRAY + "(Repair the item you are holding.)");
- p.sendMessage(ChatColor.GREEN + " /fix all" + ChatColor.GRAY + "(Repair all the items in your inventory.)");
- p.sendMessage("");
- if (p.hasPermission("repairdelay.bypass"))
- {
- p.sendMessage(ChatColor.YELLOW + "Cost: " + ChatColor.WHITE + "$0");
- p.sendMessage(ChatColor.GRAY + "" + ChatColor.STRIKETHROUGH + "-----------" + ChatColor.GREEN + " RepairDelay Help " + ChatColor.GRAY + "" + ChatColor.STRIKETHROUGH + "-----------");
- }
- else
- {
- p.sendMessage(ChatColor.YELLOW + "Cost: " + ChatColor.WHITE + config.getString("options.price"));
- p.sendMessage(ChatColor.GRAY + "" + ChatColor.STRIKETHROUGH + "-----------" + ChatColor.GREEN + " RepairDelay Help " + ChatColor.GRAY + "" + ChatColor.STRIKETHROUGH + "-----------");
- }
- }
- else
- {
- p.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "(!) Incorrect usage, please do /fix help for more information.");
- }
- }
- else
- {
- p.sendMessage(config.getString("messages.nopermission"));
- }
- }
- else
- {
- p.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "(!) Incorrect usage, please do /fix help for more information.");
- }
- }
- }
- else
- {
- p.sendMessage(config.getString("messages.nopermission"));
- }
- }
- else
- {
- return false;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement