PageRenderTime 101ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://gitlab.com/MineYourMind/Vault
Java | 263 lines | 210 code | 37 blank | 16 comment | 33 complexity | 2c6af6fafcd5539266e03badacc67077 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.permissions.Permissions;
  25. import de.bananaco.permissions.info.InfoReader;
  26. public class Chat_bPermissions extends Chat {
  27. private static final Logger log = Logger.getLogger("Minecraft");
  28. private final String name = "bInfo";
  29. private Plugin plugin = null;
  30. InfoReader chat;
  31. public Chat_bPermissions(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 (chat == null) {
  37. Plugin p = plugin.getServer().getPluginManager().getPlugin("bPermissions");
  38. if (p != null) {
  39. chat = Permissions.getInfoReader();
  40. log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "bPermissions"));
  41. }
  42. }
  43. }
  44. public class PermissionServerListener implements Listener {
  45. Chat_bPermissions chat = null;
  46. public PermissionServerListener(Chat_bPermissions chat) {
  47. this.chat = chat;
  48. }
  49. @EventHandler(priority = EventPriority.MONITOR)
  50. public void onPluginEnable(PluginEnableEvent event) {
  51. if (this.chat.chat == null) {
  52. Plugin chat = event.getPlugin();
  53. if (chat.getDescription().getName().equals("bPermissions")) {
  54. this.chat.chat = Permissions.getInfoReader();
  55. log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "bPermissions"));
  56. }
  57. }
  58. }
  59. @EventHandler(priority = EventPriority.MONITOR)
  60. public void onPluginDisable(PluginDisableEvent event) {
  61. if (this.chat.chat != null) {
  62. if (event.getPlugin().getDescription().getName().equals("bPermissions")) {
  63. this.chat.chat = null;
  64. log.info(String.format("[%s][Chat] %s un-hooked.", plugin.getDescription().getName(), "bPermissions"));
  65. }
  66. }
  67. }
  68. }
  69. @Override
  70. public String getName() {
  71. return name;
  72. }
  73. @Override
  74. public boolean isEnabled() {
  75. return chat != null;
  76. }
  77. @Override
  78. public String getPlayerPrefix(String world, String player) {
  79. return chat.getPrefix(player, world);
  80. }
  81. @Override
  82. public void setPlayerPrefix(String world, String player, String prefix) {
  83. throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
  84. }
  85. @Override
  86. public String getPlayerSuffix(String world, String player) {
  87. return chat.getSuffix(player, world);
  88. }
  89. @Override
  90. public void setPlayerSuffix(String world, String player, String suffix) {
  91. throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
  92. }
  93. @Override
  94. public String getGroupPrefix(String world, String group) {
  95. return chat.getGroupPrefix(group, world);
  96. }
  97. @Override
  98. public void setGroupPrefix(String world, String group, String prefix) {
  99. throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
  100. }
  101. @Override
  102. public String getGroupSuffix(String world, String group) {
  103. return chat.getGroupSuffix(group, world);
  104. }
  105. @Override
  106. public void setGroupSuffix(String world, String group, String suffix) {
  107. throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
  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. throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
  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. throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
  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. throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
  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. throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
  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. throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
  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. throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
  204. }
  205. @Override
  206. public String getPlayerInfoString(String world, String player, String node, String defaultValue) {
  207. String val = chat.getValue(player, world, node);
  208. return (val == null || val == "BLANKWORLD") ? defaultValue : val;
  209. }
  210. @Override
  211. public void setPlayerInfoString(String world, String player, String node, String value) {
  212. throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
  213. }
  214. @Override
  215. public String getGroupInfoString(String world, String group, String node, String defaultValue) {
  216. String val = chat.getGroupValue(group, world, node);
  217. return (val == null || val == "BLANKWORLD") ? defaultValue : val;
  218. }
  219. @Override
  220. public void setGroupInfoString(String world, String group, String node, String value) {
  221. throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
  222. }
  223. }