PageRenderTime 63ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/MineYourMind/Vault
Java | 229 lines | 168 code | 44 blank | 17 comment | 9 complexity | c4e426789815ec6c40b9dab842166b20 MD5 | raw file
  1. /* This file is part of Vault.
  2. Vault is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU Lesser General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. Vault is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU Lesser General Public License for more details.
  10. You should have received a copy of the GNU Lesser General Public License
  11. along with Vault. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. package net.milkbowl.vault.economy.plugins;
  14. import java.util.List;
  15. import java.util.logging.Logger;
  16. import org.bukkit.plugin.Plugin;
  17. import org.bukkit.event.EventHandler;
  18. import org.bukkit.event.EventPriority;
  19. import org.bukkit.event.Listener;
  20. import org.bukkit.event.server.PluginDisableEvent;
  21. import org.bukkit.event.server.PluginEnableEvent;
  22. import com.github.omwah.SDFEconomy.SDFEconomy;
  23. import com.github.omwah.SDFEconomy.SDFEconomyAPI;
  24. import net.milkbowl.vault.economy.AbstractEconomy;
  25. import net.milkbowl.vault.economy.EconomyResponse;
  26. public class Economy_SDFEconomy extends AbstractEconomy {
  27. private static final Logger log = Logger.getLogger("Minecraft");
  28. private Plugin plugin = null;
  29. private final String name = "SDFEconomy";
  30. private SDFEconomyAPI api = null;
  31. public Economy_SDFEconomy(Plugin _plugin) {
  32. plugin = _plugin;
  33. // Register a listener to wait for plugin being loaded
  34. plugin.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin);
  35. // Try and Load API in case plugin was loaded before Vault
  36. load_api();
  37. }
  38. public void load_api() {
  39. SDFEconomy pluginSDF = (SDFEconomy) plugin.getServer().getPluginManager().getPlugin("SDFEconomy");
  40. if(!isEnabled() && pluginSDF != null) {
  41. api = pluginSDF.getAPI();
  42. log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
  43. }
  44. }
  45. public void unload_api() {
  46. SDFEconomy pluginSDF = (SDFEconomy) plugin.getServer().getPluginManager().getPlugin("SDFEconomy");
  47. if(isEnabled() && pluginSDF != null) {
  48. api = null;
  49. log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), name));
  50. }
  51. }
  52. public class EconomyServerListener implements Listener {
  53. Economy_SDFEconomy economy = null;
  54. public EconomyServerListener(Economy_SDFEconomy economy) {
  55. this.economy = economy;
  56. }
  57. @EventHandler(priority = EventPriority.MONITOR)
  58. public void onPluginEnable(PluginEnableEvent event) {
  59. if (event.getPlugin().getDescription().getName().equals("SDFEconomy")) {
  60. economy.load_api();
  61. }
  62. }
  63. @EventHandler(priority = EventPriority.MONITOR)
  64. public void onPluginDisable(PluginDisableEvent event) {
  65. if (event.getPlugin().getDescription().getName().equals("SDFEconomy")) {
  66. economy.unload_api();
  67. }
  68. }
  69. }
  70. @Override
  71. public boolean isEnabled() {
  72. return api != null;
  73. }
  74. @Override
  75. public String getName() {
  76. return "SDFEconomy";
  77. }
  78. @Override
  79. public boolean hasBankSupport() {
  80. return api.hasBankSupport();
  81. }
  82. @Override
  83. public int fractionalDigits() {
  84. return api.fractionalDigits();
  85. }
  86. @Override
  87. public String format(double amount) {
  88. return api.format(amount);
  89. }
  90. @Override
  91. public String currencyNamePlural() {
  92. return api.currencyNamePlural();
  93. }
  94. @Override
  95. public String currencyNameSingular() {
  96. return api.currencyNameSingular();
  97. }
  98. @Override
  99. public boolean hasAccount(String playerName) {
  100. return api.hasAccount(playerName);
  101. }
  102. @Override
  103. public double getBalance(String playerName) {
  104. return api.getBalance(playerName);
  105. }
  106. @Override
  107. public boolean has(String playerName, double amount) {
  108. return api.has(playerName, amount);
  109. }
  110. @Override
  111. public EconomyResponse withdrawPlayer(String playerName, double amount) {
  112. return api.withdrawPlayer(playerName, amount);
  113. }
  114. @Override
  115. public EconomyResponse depositPlayer(String playerName, double amount) {
  116. return api.depositPlayer(playerName, amount);
  117. }
  118. @Override
  119. public EconomyResponse createBank(String name, String player) {
  120. return api.createBank(name, player);
  121. }
  122. @Override
  123. public EconomyResponse deleteBank(String name) {
  124. return api.deleteBank(name);
  125. }
  126. @Override
  127. public EconomyResponse bankBalance(String name) {
  128. return api.bankBalance(name);
  129. }
  130. @Override
  131. public EconomyResponse bankHas(String name, double amount) {
  132. return api.bankHas(name, amount);
  133. }
  134. @Override
  135. public EconomyResponse bankWithdraw(String name, double amount) {
  136. return api.bankWithdraw(name, amount);
  137. }
  138. @Override
  139. public EconomyResponse bankDeposit(String name, double amount) {
  140. return api.bankDeposit(name, amount);
  141. }
  142. @Override
  143. public EconomyResponse isBankOwner(String name, String playerName) {
  144. return api.isBankOwner(name, playerName);
  145. }
  146. @Override
  147. public EconomyResponse isBankMember(String name, String playerName) {
  148. return api.isBankMember(name, playerName);
  149. }
  150. @Override
  151. public List<String> getBanks() {
  152. return api.getBankNames();
  153. }
  154. @Override
  155. public boolean createPlayerAccount(String playerName) {
  156. return api.createPlayerAccount(playerName);
  157. }
  158. @Override
  159. public boolean hasAccount(String playerName, String worldName) {
  160. return hasAccount(playerName);
  161. }
  162. @Override
  163. public double getBalance(String playerName, String world) {
  164. return getBalance(playerName);
  165. }
  166. @Override
  167. public boolean has(String playerName, String worldName, double amount) {
  168. return has(playerName, amount);
  169. }
  170. @Override
  171. public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) {
  172. return withdrawPlayer(playerName, amount);
  173. }
  174. @Override
  175. public EconomyResponse depositPlayer(String playerName, String worldName, double amount) {
  176. return depositPlayer(playerName, amount);
  177. }
  178. @Override
  179. public boolean createPlayerAccount(String playerName, String worldName) {
  180. return createPlayerAccount(playerName);
  181. }
  182. }