Advertisement
Guest User

Untitled

a guest
Jan 25th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.01 KB | None | 0 0
  1. package com.sirapathy.repairdelay;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. import net.milkbowl.vault.economy.Economy;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.ChatColor;
  10. import org.bukkit.command.Command;
  11. import org.bukkit.command.CommandSender;
  12. import org.bukkit.configuration.file.FileConfiguration;
  13. import org.bukkit.configuration.file.YamlConfiguration;
  14. import org.bukkit.entity.Player;
  15. import org.bukkit.inventory.ItemStack;
  16. import org.bukkit.inventory.meta.Repairable;
  17. import org.bukkit.plugin.RegisteredServiceProvider;
  18. import org.bukkit.plugin.java.JavaPlugin;
  19.  
  20. public class Main extends JavaPlugin
  21. {
  22.  
  23. FileConfiguration config = this.getConfig();
  24.  
  25. File data = new File(this.getDataFolder()+"/data.yml");
  26. FileConfiguration dataConfig = YamlConfiguration.loadConfiguration(data);
  27.  
  28. public static Economy economy = null;
  29.  
  30. @Override
  31. public void onEnable()
  32. {
  33.  
  34. if (!setupEconomy())
  35. {
  36.  
  37. getLogger().info("(!) VAULT DEPENDENCY NOT FOUND, SHUTTING DOWN! (!)");
  38. getServer().getPluginManager().disablePlugin(this);
  39.  
  40. }
  41.  
  42. if (!(new File("plugins/RepairDelay/config.yml")).exists())
  43. {
  44.  
  45. this.getConfig().options().copyDefaults(true);
  46. this.saveConfig();
  47.  
  48. }
  49.  
  50. if (!(new File("plugins/RepairDelay/data.yml")).exists())
  51. {
  52.  
  53. dataConfig.options().copyDefaults(true);
  54. saveCustomYml(dataConfig, data);
  55.  
  56. }
  57.  
  58. }
  59.  
  60. public void saveCustomYml(FileConfiguration ymlConfig, File ymlFile)
  61. {
  62.  
  63. try
  64. {
  65.  
  66. ymlConfig.save(ymlFile);
  67.  
  68. }
  69.  
  70. catch (IOException e)
  71. {
  72.  
  73. e.printStackTrace();
  74.  
  75. }
  76.  
  77. }
  78.  
  79. private boolean setupEconomy()
  80. {
  81.  
  82. RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
  83.  
  84. if (economyProvider != null)
  85. {
  86.  
  87. economy = economyProvider.getProvider();
  88.  
  89. }
  90. return (economy != null);
  91. }
  92.  
  93. public void repairAll(Player p)
  94. {
  95.  
  96. for(ItemStack items : p.getInventory().getContents())
  97. {
  98.  
  99. if(items instanceof Repairable)
  100. {
  101.  
  102. items.setDurability((short)0);
  103.  
  104. }
  105.  
  106. }
  107.  
  108. for(ItemStack items : p.getEquipment().getArmorContents())
  109. {
  110.  
  111. if(items instanceof Repairable)
  112. {
  113.  
  114. items.setDurability((short)0);
  115.  
  116. }
  117.  
  118. }
  119.  
  120. }
  121.  
  122. @SuppressWarnings("deprecation")
  123. public void cooldown(final Player p)
  124. {
  125.  
  126. if (dataConfig.contains("data." + p.getUniqueId()))
  127. {
  128.  
  129. Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable()
  130. {
  131.  
  132. @Override
  133. public void run()
  134. {
  135.  
  136. if (dataConfig.getInt("data." + p.getUniqueId() + ".cooldown") > 0)
  137. {
  138.  
  139. String amount = config.getString("data." + p.getUniqueId() + ".cooldown");
  140. int newAmount = config.getInt("data." + p.getUniqueId() + ".cooldown");
  141.  
  142. dataConfig.set(amount, newAmount - 1);
  143.  
  144. }
  145.  
  146. else
  147. {
  148.  
  149. return;
  150.  
  151. }
  152.  
  153. }
  154.  
  155. },0L,20L);
  156.  
  157. }
  158.  
  159. else
  160. {
  161.  
  162. dataConfig.set("data." + p.getUniqueId() + ".cooldown", config.getString("options.delay"));
  163.  
  164. }
  165.  
  166. }
  167.  
  168. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
  169. {
  170.  
  171. Player p = (Player) sender;
  172.  
  173. ItemStack handItem = p.getInventory().getItemInMainHand();
  174.  
  175. if (cmd.getName().equalsIgnoreCase("test"))
  176. {
  177.  
  178. p.sendMessage("hi");
  179.  
  180. }
  181.  
  182. if (sender instanceof Player)
  183. {
  184.  
  185. if (p.hasPermission("repairdelay.allow"))
  186. {
  187.  
  188. if (cmd.getName().equalsIgnoreCase("fix"))
  189. {
  190.  
  191. if (args.length == 0)
  192. {
  193.  
  194. if (handItem instanceof Repairable)
  195. {
  196.  
  197. if (economy.getBalance(p) >= config.getInt("options.price"))
  198. {
  199.  
  200. handItem.setDurability((short)0);
  201. p.sendMessage(config.getString("messages.successfulrepair"));
  202.  
  203. economy.withdrawPlayer(p, config.getDouble("options.price"));
  204.  
  205. cooldown(p);
  206.  
  207. }
  208.  
  209. else
  210. {
  211.  
  212. p.sendMessage(config.getString("messages.notenoughmoney"));
  213.  
  214. }
  215.  
  216. }
  217.  
  218. else
  219. {
  220.  
  221. p.sendMessage(config.getString("messages.itemfulldurability"));
  222.  
  223. }
  224.  
  225. }
  226.  
  227. else if (args.length == 1)
  228. {
  229.  
  230. if (p.hasPermission("repairdelay.fixall"))
  231. {
  232.  
  233. if (args[0].equalsIgnoreCase("all"))
  234. {
  235.  
  236. repairAll(p);
  237. p.sendMessage(config.getString("messages.successfulrepairall"));
  238.  
  239. cooldown(p);
  240.  
  241. }
  242.  
  243. else if (args[0].equalsIgnoreCase("help"))
  244. {
  245.  
  246. p.sendMessage(ChatColor.GRAY + "" + ChatColor.STRIKETHROUGH + "-----------" + ChatColor.GREEN + " RepairDelay Help " + ChatColor.GRAY + "" + ChatColor.STRIKETHROUGH + "-----------");
  247. p.sendMessage(ChatColor.AQUA + "Commands:");
  248. p.sendMessage(ChatColor.GREEN + " /fix " + ChatColor.GRAY + "(Repair the item you are holding.)");
  249. p.sendMessage(ChatColor.GREEN + " /fix all" + ChatColor.GRAY + "(Repair all the items in your inventory.)");
  250. p.sendMessage("");
  251.  
  252. if (p.hasPermission("repairdelay.bypass"))
  253. {
  254.  
  255. p.sendMessage(ChatColor.YELLOW + "Cost: " + ChatColor.WHITE + "$0");
  256. p.sendMessage(ChatColor.GRAY + "" + ChatColor.STRIKETHROUGH + "-----------" + ChatColor.GREEN + " RepairDelay Help " + ChatColor.GRAY + "" + ChatColor.STRIKETHROUGH + "-----------");
  257.  
  258. }
  259.  
  260. else
  261. {
  262.  
  263. p.sendMessage(ChatColor.YELLOW + "Cost: " + ChatColor.WHITE + config.getString("options.price"));
  264. p.sendMessage(ChatColor.GRAY + "" + ChatColor.STRIKETHROUGH + "-----------" + ChatColor.GREEN + " RepairDelay Help " + ChatColor.GRAY + "" + ChatColor.STRIKETHROUGH + "-----------");
  265.  
  266. }
  267.  
  268. }
  269.  
  270. else
  271. {
  272.  
  273. p.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "(!) Incorrect usage, please do /fix help for more information.");
  274.  
  275. }
  276.  
  277. }
  278.  
  279. else
  280. {
  281.  
  282. p.sendMessage(config.getString("messages.nopermission"));
  283.  
  284. }
  285.  
  286. }
  287.  
  288. else
  289. {
  290.  
  291. p.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "(!) Incorrect usage, please do /fix help for more information.");
  292.  
  293. }
  294.  
  295. }
  296.  
  297. }
  298.  
  299. else
  300. {
  301.  
  302. p.sendMessage(config.getString("messages.nopermission"));
  303.  
  304. }
  305.  
  306. }
  307.  
  308. else
  309. {
  310.  
  311. return false;
  312.  
  313. }
  314.  
  315. return true;
  316.  
  317. }
  318.  
  319. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement