PageRenderTime 66ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/src/net/milkbowl/vault/economy/plugins/Economy_CommandsEX.java

https://gitlab.com/MineYourMind/Vault
Java | 234 lines | 190 code | 44 blank | 0 comment | 18 complexity | 1ab00354c0df5b6dbf85ed01496ec0ec MD5 | raw file
  1. package net.milkbowl.vault.economy.plugins;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.logging.Logger;
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.event.EventHandler;
  7. import org.bukkit.event.EventPriority;
  8. import org.bukkit.event.Listener;
  9. import org.bukkit.event.server.PluginDisableEvent;
  10. import org.bukkit.event.server.PluginEnableEvent;
  11. import org.bukkit.plugin.Plugin;
  12. import com.github.zathrus_writer.commandsex.CommandsEX;
  13. import com.github.zathrus_writer.commandsex.api.economy.Economy;
  14. import net.milkbowl.vault.economy.AbstractEconomy;
  15. import net.milkbowl.vault.economy.EconomyResponse;
  16. import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
  17. public class Economy_CommandsEX extends AbstractEconomy {
  18. private static final Logger log = Logger.getLogger("Minecraft");
  19. private final String name = "CommandsEX Economy";
  20. private Plugin plugin = null;
  21. private CommandsEX economy = null;
  22. public Economy_CommandsEX(Plugin plugin){
  23. this.plugin = plugin;
  24. Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin);
  25. if (economy == null) {
  26. Plugin commandsex = plugin.getServer().getPluginManager().getPlugin("CommandsEX");
  27. if (commandsex != null && commandsex.isEnabled()) {
  28. economy = (CommandsEX) commandsex;
  29. log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
  30. }
  31. }
  32. }
  33. public class EconomyServerListener implements Listener {
  34. Economy_CommandsEX economy = null;
  35. public EconomyServerListener(Economy_CommandsEX economy) {
  36. this.economy = economy;
  37. }
  38. @EventHandler(priority = EventPriority.MONITOR)
  39. public void onPluginEnable(PluginEnableEvent event) {
  40. if (economy.economy == null) {
  41. Plugin cex = event.getPlugin();
  42. if (cex.getDescription().getName().equals("CommandsEX")) {
  43. economy.economy = (CommandsEX) cex;
  44. log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), economy.name));
  45. }
  46. }
  47. }
  48. @EventHandler(priority = EventPriority.MONITOR)
  49. public void onPluginDisable(PluginDisableEvent event) {
  50. if (economy.economy != null) {
  51. if (event.getPlugin().getDescription().getName().equals("CommandsEX")) {
  52. economy.economy = null;
  53. log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), economy.name));
  54. }
  55. }
  56. }
  57. }
  58. @Override
  59. public boolean isEnabled() {
  60. if (economy == null){
  61. return false;
  62. } else {
  63. return Economy.isEnabled();
  64. }
  65. }
  66. @Override
  67. public String getName() {
  68. return name;
  69. }
  70. @Override
  71. public boolean hasBankSupport() {
  72. return false;
  73. }
  74. @Override
  75. public int fractionalDigits() {
  76. return 2;
  77. }
  78. @Override
  79. public String format(double amount) {
  80. return Economy.getCurrencySymbol() + amount;
  81. }
  82. @Override
  83. public String currencyNamePlural() {
  84. return Economy.getCurrencyPlural();
  85. }
  86. @Override
  87. public String currencyNameSingular() {
  88. return Economy.getCurrencySingular();
  89. }
  90. @Override
  91. public boolean hasAccount(String playerName) {
  92. return Economy.hasAccount(playerName);
  93. }
  94. @Override
  95. public double getBalance(String playerName) {
  96. return Economy.getBalance(playerName);
  97. }
  98. @Override
  99. public boolean has(String playerName, double amount) {
  100. return Economy.has(playerName, amount);
  101. }
  102. @Override
  103. public EconomyResponse withdrawPlayer(String playerName, double amount) {
  104. ResponseType rt;
  105. String message;
  106. if (Economy.has(playerName, amount)){
  107. Economy.withdraw(playerName, amount);
  108. rt = ResponseType.SUCCESS;
  109. message = null;
  110. } else {
  111. rt = ResponseType.FAILURE;
  112. message = "Not enough money";
  113. }
  114. return new EconomyResponse(amount, Economy.getBalance(playerName), rt, message);
  115. }
  116. @Override
  117. public EconomyResponse depositPlayer(String playerName, double amount) {
  118. Economy.deposit(playerName, amount);
  119. return new EconomyResponse(amount, Economy.getBalance(playerName), ResponseType.SUCCESS, "Successfully deposited");
  120. }
  121. @Override
  122. public EconomyResponse createBank(String name, String player) {
  123. return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts");
  124. }
  125. @Override
  126. public EconomyResponse deleteBank(String name) {
  127. return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts");
  128. }
  129. @Override
  130. public EconomyResponse bankBalance(String name) {
  131. return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts");
  132. }
  133. @Override
  134. public EconomyResponse bankHas(String name, double amount) {
  135. return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts");
  136. }
  137. @Override
  138. public EconomyResponse bankWithdraw(String name, double amount) {
  139. return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts");
  140. }
  141. @Override
  142. public EconomyResponse bankDeposit(String name, double amount) {
  143. return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts");
  144. }
  145. @Override
  146. public EconomyResponse isBankOwner(String name, String playerName) {
  147. return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts");
  148. }
  149. @Override
  150. public EconomyResponse isBankMember(String name, String playerName) {
  151. return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts");
  152. }
  153. @Override
  154. public List<String> getBanks() {
  155. return new ArrayList<String>();
  156. }
  157. @Override
  158. public boolean createPlayerAccount(String playerName) {
  159. if (Economy.hasAccount(playerName)){
  160. return false;
  161. } else {
  162. Economy.createAccount(playerName);
  163. return true;
  164. }
  165. }
  166. @Override
  167. public boolean hasAccount(String playerName, String worldName) {
  168. return hasAccount(playerName);
  169. }
  170. @Override
  171. public double getBalance(String playerName, String world) {
  172. return getBalance(playerName);
  173. }
  174. @Override
  175. public boolean has(String playerName, String worldName, double amount) {
  176. return has(playerName, amount);
  177. }
  178. @Override
  179. public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) {
  180. return withdrawPlayer(playerName, amount);
  181. }
  182. @Override
  183. public EconomyResponse depositPlayer(String playerName, String worldName, double amount) {
  184. return depositPlayer(playerName, amount);
  185. }
  186. @Override
  187. public boolean createPlayerAccount(String playerName, String worldName) {
  188. return createPlayerAccount(playerName);
  189. }
  190. }