PageRenderTime 101ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/src/net/milkbowl/vault/chat/plugins/Chat_bPermissions2.java

https://gitlab.com/MineYourMind/Vault
Java | 264 lines | 210 code | 38 blank | 16 comment | 33 complexity | a7ea11073a521707ee5ed4a5b93bbae3 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.chat.plugins;
  14. import java.util.logging.Logger;
  15. import net.milkbowl.vault.chat.Chat;
  16. import net.milkbowl.vault.permission.Permission;
  17. import org.bukkit.Bukkit;
  18. import org.bukkit.event.EventHandler;
  19. import org.bukkit.event.EventPriority;
  20. import org.bukkit.event.Listener;
  21. import org.bukkit.event.server.PluginDisableEvent;
  22. import org.bukkit.event.server.PluginEnableEvent;
  23. import org.bukkit.plugin.Plugin;
  24. import de.bananaco.bpermissions.api.ApiLayer;
  25. import de.bananaco.bpermissions.api.CalculableType;
  26. public class Chat_bPermissions2 extends Chat {
  27. private static final Logger log = Logger.getLogger("Minecraft");
  28. private final String name = "bInfo";
  29. private Plugin plugin = null;
  30. private boolean hooked = false;
  31. public Chat_bPermissions2(Plugin plugin, Permission perms) {
  32. super(perms);
  33. this.plugin = plugin;
  34. Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin);
  35. // Load Plugin in case it was loaded before
  36. if (!hooked) {
  37. Plugin p = plugin.getServer().getPluginManager().getPlugin("bPermissions");
  38. if (p != null) {
  39. hooked = true;
  40. log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "bPermissions2"));
  41. }
  42. }
  43. }
  44. public class PermissionServerListener implements Listener {
  45. Chat_bPermissions2 chat = null;
  46. public PermissionServerListener(Chat_bPermissions2 chat) {
  47. this.chat = chat;
  48. }
  49. @EventHandler(priority = EventPriority.MONITOR)
  50. public void onPluginEnable(PluginEnableEvent event) {
  51. if (!hooked) {
  52. Plugin chat = event.getPlugin();
  53. if (chat.getDescription().getName().equals("bPermissions")) {
  54. hooked = true;
  55. log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "bPermissions2"));
  56. }
  57. }
  58. }
  59. @EventHandler(priority = EventPriority.MONITOR)
  60. public void onPluginDisable(PluginDisableEvent event) {
  61. if (hooked) {
  62. if (event.getPlugin().getDescription().getName().equals("bPermissions")) {
  63. hooked = false;
  64. log.info(String.format("[%s][Chat] %s un-hooked.", plugin.getDescription().getName(), "bPermissions2"));
  65. }
  66. }
  67. }
  68. }
  69. @Override
  70. public String getName() {
  71. return name;
  72. }
  73. @Override
  74. public boolean isEnabled() {
  75. return hooked;
  76. }
  77. @Override
  78. public String getPlayerPrefix(String world, String player) {
  79. return ApiLayer.getValue(world, CalculableType.USER, player, "prefix");
  80. }
  81. @Override
  82. public void setPlayerPrefix(String world, String player, String prefix) {
  83. ApiLayer.setValue(world, CalculableType.USER, player, "prefix", prefix);
  84. }
  85. @Override
  86. public String getPlayerSuffix(String world, String player) {
  87. return ApiLayer.getValue(world, CalculableType.USER, player, "suffix");
  88. }
  89. @Override
  90. public void setPlayerSuffix(String world, String player, String suffix) {
  91. ApiLayer.setValue(world, CalculableType.USER, player, "suffix", suffix);
  92. }
  93. @Override
  94. public String getGroupPrefix(String world, String group) {
  95. return ApiLayer.getValue(world, CalculableType.GROUP, group, "prefix");
  96. }
  97. @Override
  98. public void setGroupPrefix(String world, String group, String prefix) {
  99. ApiLayer.setValue(world, CalculableType.GROUP, group, "prefix", prefix);
  100. }
  101. @Override
  102. public String getGroupSuffix(String world, String group) {
  103. return ApiLayer.getValue(world, CalculableType.GROUP, group, "suffix");
  104. }
  105. @Override
  106. public void setGroupSuffix(String world, String group, String suffix) {
  107. ApiLayer.setValue(world, CalculableType.GROUP, group, "suffix", suffix);
  108. }
  109. @Override
  110. public int getPlayerInfoInteger(String world, String player, String node, int defaultValue) {
  111. String s = getPlayerInfoString(world, player, node, null);
  112. if (s == null) {
  113. return defaultValue;
  114. }
  115. try {
  116. int i = Integer.valueOf(s);
  117. return i;
  118. } catch (NumberFormatException e) {
  119. return defaultValue;
  120. }
  121. }
  122. @Override
  123. public void setPlayerInfoInteger(String world, String player, String node, int value) {
  124. ApiLayer.setValue(world, CalculableType.USER, player, node, String.valueOf(value));
  125. }
  126. @Override
  127. public int getGroupInfoInteger(String world, String group, String node, int defaultValue) {
  128. String s = getGroupInfoString(world, group, node, null);
  129. if (s == null) {
  130. return defaultValue;
  131. }
  132. try {
  133. int i = Integer.valueOf(s);
  134. return i;
  135. } catch (NumberFormatException e) {
  136. return defaultValue;
  137. }
  138. }
  139. @Override
  140. public void setGroupInfoInteger(String world, String group, String node, int value) {
  141. ApiLayer.setValue(world, CalculableType.GROUP, group, node, String.valueOf(value));
  142. }
  143. @Override
  144. public double getPlayerInfoDouble(String world, String player, String node, double defaultValue) {
  145. String s = getPlayerInfoString(world, player, node, null);
  146. if (s == null) {
  147. return defaultValue;
  148. }
  149. try {
  150. double d = Double.valueOf(s);
  151. return d;
  152. } catch (NumberFormatException e) {
  153. return defaultValue;
  154. }
  155. }
  156. @Override
  157. public void setPlayerInfoDouble(String world, String player, String node, double value) {
  158. ApiLayer.setValue(world, CalculableType.USER, player, node, String.valueOf(value));
  159. }
  160. @Override
  161. public double getGroupInfoDouble(String world, String group, String node, double defaultValue) {
  162. String s = getGroupInfoString(world, group, node, null);
  163. if (s == null) {
  164. return defaultValue;
  165. }
  166. try {
  167. double d = Double.valueOf(s);
  168. return d;
  169. } catch (NumberFormatException e) {
  170. return defaultValue;
  171. }
  172. }
  173. @Override
  174. public void setGroupInfoDouble(String world, String group, String node, double value) {
  175. ApiLayer.setValue(world, CalculableType.GROUP, group, node, String.valueOf(value));
  176. }
  177. @Override
  178. public boolean getPlayerInfoBoolean(String world, String player, String node, boolean defaultValue) {
  179. String s = getPlayerInfoString(world, player, node, null);
  180. if (s == null) {
  181. return defaultValue;
  182. } else {
  183. Boolean val = Boolean.valueOf(s);
  184. return val != null ? val : defaultValue;
  185. }
  186. }
  187. @Override
  188. public void setPlayerInfoBoolean(String world, String player, String node, boolean value) {
  189. ApiLayer.setValue(world, CalculableType.USER, player, node, String.valueOf(value));
  190. }
  191. @Override
  192. public boolean getGroupInfoBoolean(String world, String group, String node, boolean defaultValue) {
  193. String s = getGroupInfoString(world, group, node, null);
  194. if (s == null) {
  195. return defaultValue;
  196. } else {
  197. Boolean val = Boolean.valueOf(s);
  198. return val != null ? val : defaultValue;
  199. }
  200. }
  201. @Override
  202. public void setGroupInfoBoolean(String world, String group, String node, boolean value) {
  203. ApiLayer.setValue(world, CalculableType.GROUP, group, node, String.valueOf(value));;
  204. }
  205. @Override
  206. public String getPlayerInfoString(String world, String player, String node, String defaultValue) {
  207. String val = ApiLayer.getValue(world, CalculableType.USER, player, node);
  208. return (val == null || val == "BLANKWORLD" || val == "") ? defaultValue : val;
  209. }
  210. @Override
  211. public void setPlayerInfoString(String world, String player, String node, String value) {
  212. ApiLayer.setValue(world, CalculableType.USER, player, node, value);
  213. }
  214. @Override
  215. public String getGroupInfoString(String world, String group, String node, String defaultValue) {
  216. String val = ApiLayer.getValue(world, CalculableType.GROUP, group, node);
  217. return (val == null || val == "BLANKWORLD" || val == "") ? defaultValue : val;
  218. }
  219. @Override
  220. public void setGroupInfoString(String world, String group, String node, String value) {
  221. ApiLayer.setValue(world, CalculableType.GROUP, group, node, value);
  222. }
  223. }