PageRenderTime 55ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/MineYourMind/Vault
Java | 247 lines | 186 code | 45 blank | 16 comment | 20 complexity | 1f5103e0dbab1f1dd18fa50b41b90199 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.Bukkit;
  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 org.bukkit.plugin.Plugin;
  23. import me.igwb.GoldenChest.GoldenChestEconomy;
  24. import net.milkbowl.vault.economy.AbstractEconomy;
  25. import net.milkbowl.vault.economy.EconomyResponse;
  26. import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
  27. public class Economy_GoldenChestEconomy extends AbstractEconomy {
  28. private static final Logger log = Logger.getLogger("Minecraft");
  29. private final String name = "GoldenChestEconomy";
  30. private Plugin plugin = null;
  31. private GoldenChestEconomy economy = null;
  32. public Economy_GoldenChestEconomy (Plugin plugin) {
  33. this.plugin = plugin;
  34. Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin);
  35. // Load Plugin in case it was loaded before
  36. if (economy == null) {
  37. Plugin ec = plugin.getServer().getPluginManager().getPlugin("GoldenChestEconomy");
  38. if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("me.igwb.GoldenChest.GoldenChestEconomy")) {
  39. economy = (GoldenChestEconomy) ec;
  40. log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
  41. }
  42. }
  43. }
  44. public class EconomyServerListener implements Listener {
  45. Economy_GoldenChestEconomy economy = null;
  46. public EconomyServerListener(Economy_GoldenChestEconomy economy_GoldenChestEconomy) {
  47. this.economy = economy_GoldenChestEconomy;
  48. }
  49. @EventHandler(priority = EventPriority.MONITOR)
  50. public void onPluginEnable(PluginEnableEvent event) {
  51. if (economy.economy == null) {
  52. Plugin ec = event.getPlugin();
  53. if (ec.getDescription().getName().equals("GoldenChestEconomy") && ec.getClass().getName().equals("me.igwb.GoldenChest.GoldenChestEconomy")) {
  54. economy.economy = (GoldenChestEconomy) ec;
  55. log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), economy.name));
  56. }
  57. }
  58. }
  59. @EventHandler(priority = EventPriority.MONITOR)
  60. public void onPluginDisable(PluginDisableEvent event) {
  61. if (economy.economy != null) {
  62. if (event.getPlugin().getDescription().getName().equals("GoldenChestEconomy")) {
  63. economy.economy = null;
  64. log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), economy.name));
  65. }
  66. }
  67. }
  68. }
  69. @Override
  70. public boolean isEnabled() {
  71. if (economy == null) {
  72. return false;
  73. } else {
  74. return economy.isEnabled();
  75. }
  76. }
  77. @Override
  78. public String getName() {
  79. return name;
  80. }
  81. @Override
  82. public boolean hasBankSupport() {
  83. return false;
  84. }
  85. @Override
  86. public int fractionalDigits() {
  87. return economy.getVaultConnector().fractionalDigits();
  88. }
  89. @Override
  90. public String format(double amount) {
  91. return economy.getVaultConnector().format(amount);
  92. }
  93. @Override
  94. public String currencyNamePlural() {
  95. return economy.getVaultConnector().currencyNamePlural();
  96. }
  97. @Override
  98. public String currencyNameSingular() {
  99. return economy.getVaultConnector().currencyNameSingular();
  100. }
  101. @Override
  102. public boolean hasAccount(String playerName) {
  103. return economy.getVaultConnector().hasAccount(playerName);
  104. }
  105. @Override
  106. public boolean hasAccount(String playerName, String worldName) {
  107. return economy.getVaultConnector().hasAccount(playerName, worldName);
  108. }
  109. @Override
  110. public double getBalance(String playerName) {
  111. return economy.getVaultConnector().getBalance(playerName);
  112. }
  113. @Override
  114. public double getBalance(String playerName, String world) {
  115. return economy.getVaultConnector().getBalance(playerName, world);
  116. }
  117. @Override
  118. public boolean has(String playerName, double amount) {
  119. return economy.getVaultConnector().has(playerName, amount);
  120. }
  121. @Override
  122. public boolean has(String playerName, String worldName, double amount) {
  123. return economy.getVaultConnector().has(playerName, worldName, amount);
  124. }
  125. @Override
  126. public EconomyResponse withdrawPlayer(String playerName, double amount) {
  127. if (amount < 0) {
  128. return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds");
  129. }
  130. if (has(playerName, amount)) {
  131. economy.getVaultConnector().withdrawPlayer(playerName, amount);
  132. return new EconomyResponse(amount, getBalance(playerName), ResponseType.SUCCESS, null);
  133. } else {
  134. return new EconomyResponse(0, getBalance(playerName), ResponseType.FAILURE, "Insufficient funds");
  135. }
  136. }
  137. @Override
  138. public EconomyResponse withdrawPlayer(String playerName, String worldName,
  139. double amount) {
  140. return withdrawPlayer(playerName, amount);
  141. }
  142. @Override
  143. public EconomyResponse depositPlayer(String playerName, double amount) {
  144. if (amount < 0) {
  145. return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds");
  146. }
  147. economy.getVaultConnector().depositPlayer(playerName, amount);
  148. return new EconomyResponse(amount, getBalance(playerName), EconomyResponse.ResponseType.SUCCESS, null);
  149. }
  150. @Override
  151. public EconomyResponse depositPlayer(String playerName, String worldName,
  152. double amount) {
  153. return depositPlayer(playerName, amount);
  154. }
  155. @Override
  156. public EconomyResponse createBank(String name, String player) {
  157. return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Banks are not supported!");
  158. }
  159. @Override
  160. public EconomyResponse deleteBank(String name) {
  161. return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Banks are not supported!");
  162. }
  163. @Override
  164. public EconomyResponse bankBalance(String name) {
  165. return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Banks are not supported!");
  166. }
  167. @Override
  168. public EconomyResponse bankHas(String name, double amount) {
  169. return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Banks are not supported!");
  170. }
  171. @Override
  172. public EconomyResponse bankWithdraw(String name, double amount) {
  173. return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Banks are not supported!");
  174. }
  175. @Override
  176. public EconomyResponse bankDeposit(String name, double amount) {
  177. return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Banks are not supported!");
  178. }
  179. @Override
  180. public EconomyResponse isBankOwner(String name, String playerName) {
  181. return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Banks are not supported!");
  182. }
  183. @Override
  184. public EconomyResponse isBankMember(String name, String playerName) {
  185. return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Banks are not supported!");
  186. }
  187. @Override
  188. public List<String> getBanks() {
  189. return null;
  190. }
  191. @Override
  192. public boolean createPlayerAccount(String playerName) {
  193. return economy.getVaultConnector().createPlayerAccount(playerName);
  194. }
  195. @Override
  196. public boolean createPlayerAccount(String playerName, String worldName) {
  197. return economy.getVaultConnector().createPlayerAccount(playerName, worldName);
  198. }
  199. }