/src/me/never2nv/SimpleMedic/SimpleMedic.java

https://github.com/bmx-atvman14/Simple-Medic · Java · 144 lines · 120 code · 19 blank · 5 comment · 35 complexity · 58b2e69a30c950b12efcbd2737a99c37 MD5 · raw file

  1. package me.never2nv.SimpleMedic;
  2. import java.util.logging.Logger;
  3. import org.bukkit.ChatColor;
  4. import org.bukkit.command.Command;
  5. import org.bukkit.command.CommandSender;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.plugin.PluginDescriptionFile;
  8. import org.bukkit.plugin.RegisteredServiceProvider;
  9. import org.bukkit.plugin.java.JavaPlugin;
  10. import net.milkbowl.vault.economy.Economy;
  11. import net.milkbowl.vault.economy.EconomyResponse;
  12. public class SimpleMedic extends JavaPlugin{
  13. public static Economy econ = null;
  14. public final Logger logger = Logger.getLogger("Minecraft)");
  15. public static SimpleMedic plugin;
  16. @Override
  17. public void onDisable() {
  18. PluginDescriptionFile pdffile = this.getDescription();
  19. this.logger.info("Congrats! U iz ubber smart! " + pdffile.getName() + " has been disabled!");
  20. }
  21. @Override
  22. public void onEnable() {
  23. if (!setupEconomy() ) {
  24. System.out.println("[Medic] has been disabled because vault is not found");
  25. getServer().getPluginManager().disablePlugin(this);
  26. return;
  27. } else {
  28. PluginDescriptionFile pdffile = this.getDescription();
  29. this.logger.info("Well would ya look at that? " + pdffile.getName() + " Version " + pdffile.getVersion() + " has been enabled!");
  30. getConfig().options().copyDefaults(true);
  31. saveConfig();
  32. }
  33. }
  34. private boolean setupEconomy() {
  35. //The actual code to search for an economy to use
  36. if (getServer().getPluginManager().getPlugin("Vault") == null) {
  37. return false;
  38. }
  39. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
  40. if (rsp == null) {
  41. return false;
  42. }
  43. econ = rsp.getProvider();
  44. return econ != null;
  45. }
  46. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
  47. boolean econenabled = plugin.getConfig().getBoolean("econ-enabled");
  48. int cost = plugin.getConfig().getInt("econ-cost");
  49. Player player = (Player) sender;
  50. if(commandLabel.equalsIgnoreCase("extme") || commandLabel.equalsIgnoreCase("extinguishme")){
  51. if(args.length == 0){
  52. if(player.hasPermission("simplemedic.ext")|| player.hasPermission("simplemedic.*") {
  53. player.sendMessage(ChatColor.DARK_RED + "[MEDIC] You have been extinguished!");
  54. player.setFireTicks(0);
  55. }else if(args.length == 1){
  56. if(player.hasPermission("simplemedic.ext.others")|| player.hasPermission("simplemedic.*") {
  57. Player target = player.getServer().getPlayer(args[0]);
  58. target.setFireTicks(0);
  59. player.sendMessage(ChatColor.DARK_RED + "[MEDIC] " + target.getName() + " has been extinguished!");
  60. target.sendMessage(ChatColor.DARK_RED + "[MEDIC] You have been extinguished!");
  61. }else {
  62. player.sendMessage(ChatColor.DARK_RED + "[MEDIC] Error: Incorrect usage.");
  63. }
  64. }
  65. if(commandLabel.equalsIgnoreCase("medic") || commandLabel.equalsIgnoreCase("med")){
  66. if(args.length == 0){
  67. if(player.hasPermission("simplemedic.heal")|| player.hasPermission("simplemedic.*") {
  68. if(econenabled) {
  69. EconomyResponse r = econ.withdrawPlayer(player.getName(), cost);
  70. if(r.transactionSuccess()) {
  71. //If the transaction succeeds it heals them else it tells them the error
  72. //healing player
  73. player.setHealth(20);
  74. player.setFireTicks(0);
  75. player.chat("/me " + ChatColor.DARK_RED + "just got healed by a " + ChatColor.GREEN + "Medic!");
  76. player.sendMessage(ChatColor.GREEN + "[MEDIC] " + ChatColor.WHITE + "You've Been Healed!");
  77. }
  78. else {
  79. player.sendMessage(String.format("An error occured: %s", r.errorMessage));
  80. }
  81. } else {
  82. player.setHealth(20);
  83. player.setFireTicks(0);
  84. player.chat("/me " + ChatColor.DARK_RED + "just got healed by a " + ChatColor.GREEN + "Medic!");
  85. player.sendMessage(ChatColor.GREEN + "[MEDIC] " + ChatColor.WHITE + "You've Been Healed!");
  86. }
  87. }
  88. }
  89. else if(args.length == 1){
  90. if(player.hasPermission("simplemedic.heal.others") || player.hasPermission("simplemedic.*") ) {
  91. if(econenabled) {
  92. EconomyResponse r = econ.withdrawPlayer(player.getName(), cost);
  93. if(r.transactionSuccess()) {
  94. //See above :D
  95. if(player.getServer().getPlayer(args[0]) !=null){
  96. Player targetPlayer = player.getServer().getPlayer(args[0]);
  97. targetPlayer.setHealth(20);
  98. targetPlayer.setFireTicks(0);
  99. targetPlayer.getBedSpawnLocation();
  100. player.chat("/me " + ChatColor.DARK_RED + "just got healed by a " + ChatColor.GREEN + "Medic!");
  101. player.sendMessage(ChatColor.GREEN + "[MEDIC] " + ChatColor.WHITE + "You've Been Healed!");
  102. }
  103. else {
  104. // checks to see if player is online, else displays this message!
  105. player.sendMessage(ChatColor.RED + "PLAYER IS NOT ONLINE!");
  106. }
  107. }
  108. else {
  109. player.sendMessage(String.format("An error occured: %s", r.errorMessage));
  110. } else {
  111. targetPlayer.setHealth(20);
  112. targetPlayer.setFireTicks(0);
  113. targetPlayer.getBedSpawnLocation();
  114. player.chat("/me " + ChatColor.DARK_RED + "just got healed by a " + ChatColor.GREEN + "Medic!");
  115. player.sendMessage(ChatColor.GREEN + "[MEDIC] " + ChatColor.WHITE + "You've Been Healed!");
  116. }
  117. }
  118. }
  119. return false;
  120. }
  121. return false;
  122. }
  123. return false;
  124. }
  125. }