PageRenderTime 62ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/MineYourMind/Vault
Java | 393 lines | 323 code | 54 blank | 16 comment | 84 complexity | e20968b0a54a37e401cd5a80c5541c2e 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 com.earth2me.essentials.OfflinePlayer;
  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 ru.tehkode.permissions.PermissionGroup;
  25. import ru.tehkode.permissions.PermissionUser;
  26. import ru.tehkode.permissions.bukkit.PermissionsEx;
  27. import java.util.logging.Logger;
  28. public class Chat_PermissionsExC extends Chat {
  29. private static final Logger log = Logger.getLogger("Minecraft");
  30. private final String name = "PermissionsEx_Chat";
  31. private Plugin plugin = null;
  32. private PermissionsEx chat = null;
  33. public Chat_PermissionsExC(Plugin plugin, Permission perms) {
  34. super(perms);
  35. this.plugin = plugin;
  36. Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin);
  37. // Load Plugin in case it was loaded before
  38. if (chat == null) {
  39. Plugin p = plugin.getServer().getPluginManager().getPlugin("PermissionsEx");
  40. if (p != null) {
  41. if (p.isEnabled()) {
  42. chat = (PermissionsEx) p;
  43. log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), name));
  44. }
  45. }
  46. }
  47. }
  48. public class PermissionServerListener implements Listener {
  49. Chat_PermissionsExC chat = null;
  50. public PermissionServerListener(Chat_PermissionsExC chat) {
  51. this.chat = chat;
  52. }
  53. @EventHandler(priority = EventPriority.MONITOR)
  54. public void onPluginEnable(PluginEnableEvent event) {
  55. if (chat.chat == null) {
  56. Plugin perms = event.getPlugin();
  57. if (perms.getDescription().getName().equals("PermissionsEx")) {
  58. if (perms.isEnabled()) {
  59. chat.chat = (PermissionsEx) perms;
  60. log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), chat.name));
  61. }
  62. }
  63. }
  64. }
  65. @EventHandler(priority = EventPriority.MONITOR)
  66. public void onPluginDisable(PluginDisableEvent event) {
  67. if (chat.chat != null) {
  68. if (event.getPlugin().getDescription().getName().equals("PermissionsEx")) {
  69. chat.chat = null;
  70. log.info(String.format("[%s][Chat] %s un-hooked.", plugin.getDescription().getName(), chat.name));
  71. }
  72. }
  73. }
  74. }
  75. @Override
  76. public String getName() {
  77. return name;
  78. }
  79. @Override
  80. public boolean isEnabled() {
  81. if (chat == null)
  82. return false;
  83. else
  84. return chat.isEnabled();
  85. }
  86. private PermissionUser getUser(OfflinePlayer op) {
  87. return PermissionsEx.getPermissionManager().getUser(op.getUniqueId());
  88. }
  89. private PermissionUser getUser(String playerName) {
  90. return PermissionsEx.getPermissionManager().getUser(playerName);
  91. }
  92. @Override
  93. public int getPlayerInfoInteger(String world, String playerName, String node, int defaultValue) {
  94. return getUser(playerName).getOptionInteger(node, world, defaultValue);
  95. }
  96. @Override
  97. public double getPlayerInfoDouble(String world, String playerName, String node, double defaultValue) {
  98. return getUser(playerName).getOptionDouble(node, world, defaultValue);
  99. }
  100. @Override
  101. public boolean getPlayerInfoBoolean(String world, String playerName, String node, boolean defaultValue) {
  102. return getUser(playerName).getOptionBoolean(node, world, defaultValue);
  103. }
  104. @Override
  105. public String getPlayerInfoString(String world, String playerName, String node, String defaultValue) {
  106. return getUser(playerName).getOption(node, world, defaultValue);
  107. }
  108. public int getPlayerInfoInteger(String world, OfflinePlayer op, String node, int defaultValue) {
  109. return getUser(op).getOptionInteger(node, world, defaultValue);
  110. }
  111. public double getPlayerInfoDouble(String world, OfflinePlayer op, String node, double defaultValue) {
  112. return getUser(op).getOptionDouble(node, world, defaultValue);
  113. }
  114. public boolean getPlayerInfoBoolean(String world, OfflinePlayer op, String node, boolean defaultValue) {
  115. return getUser(op).getOptionBoolean(node, world, defaultValue);
  116. }
  117. public String getPlayerInfoString(String world, OfflinePlayer op, String node, String defaultValue) {
  118. return getUser(op).getOption(node, world, defaultValue);
  119. }
  120. public void setPlayerInfoInteger(String world, OfflinePlayer op, String node, int value) {
  121. PermissionUser user = getUser(op);
  122. if (user != null) {
  123. user.setOption(node, String.valueOf(value), world);
  124. }
  125. }
  126. public void setPlayerInfoDouble(String world, OfflinePlayer op, String node, double value) {
  127. PermissionUser user = getUser(op);
  128. if (user != null) {
  129. user.setOption(node, String.valueOf(value), world);
  130. }
  131. }
  132. public void setPlayerInfoBoolean(String world, OfflinePlayer op, String node, boolean value) {
  133. PermissionUser user = getUser(op);
  134. if (user != null) {
  135. user.setOption(node, String.valueOf(value), world);
  136. }
  137. }
  138. public void setPlayerInfoString(String world, OfflinePlayer op, String node, String value) {
  139. PermissionUser user = getUser(op);
  140. if (user != null) {
  141. user.setOption(node, String.valueOf(value), world);
  142. }
  143. }
  144. @Override
  145. public void setPlayerInfoInteger(String world, String playerName, String node, int value) {
  146. PermissionUser user = getUser(playerName);
  147. if (user != null) {
  148. user.setOption(node, String.valueOf(value), world);
  149. }
  150. }
  151. @Override
  152. public void setPlayerInfoDouble(String world, String playerName, String node, double value) {
  153. PermissionUser user = getUser(playerName);
  154. if (user != null) {
  155. user.setOption(node, String.valueOf(value), world);
  156. }
  157. }
  158. @Override
  159. public void setPlayerInfoBoolean(String world, String playerName, String node, boolean value) {
  160. PermissionUser user = getUser(playerName);
  161. if (user != null) {
  162. user.setOption(node, String.valueOf(value), world);
  163. }
  164. }
  165. @Override
  166. public void setPlayerInfoString(String world, String playerName, String node, String value) {
  167. PermissionUser user = getUser(playerName);
  168. if (user != null) {
  169. user.setOption(node, String.valueOf(value), world);
  170. }
  171. }
  172. @Override
  173. public int getGroupInfoInteger(String world, String groupName, String node, int defaultValue) {
  174. PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
  175. if (group == null) {
  176. return defaultValue;
  177. } else {
  178. return group.getOptionInteger(node, world, defaultValue);
  179. }
  180. }
  181. @Override
  182. public void setGroupInfoInteger(String world, String groupName, String node, int value) {
  183. PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
  184. if (group == null) {
  185. return;
  186. } else {
  187. group.setOption(node, world, String.valueOf(value));
  188. }
  189. }
  190. @Override
  191. public double getGroupInfoDouble(String world, String groupName, String node, double defaultValue) {
  192. PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
  193. if (group == null) {
  194. return defaultValue;
  195. } else {
  196. return group.getOptionDouble(node, world, defaultValue);
  197. }
  198. }
  199. @Override
  200. public void setGroupInfoDouble(String world, String groupName, String node, double value) {
  201. PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
  202. if (group == null) {
  203. return;
  204. } else {
  205. group.setOption(node, world, String.valueOf(value));
  206. }
  207. }
  208. @Override
  209. public boolean getGroupInfoBoolean(String world, String groupName, String node, boolean defaultValue) {
  210. PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
  211. if (group == null) {
  212. return defaultValue;
  213. } else {
  214. return group.getOptionBoolean(node, world, defaultValue);
  215. }
  216. }
  217. @Override
  218. public void setGroupInfoBoolean(String world, String groupName, String node, boolean value) {
  219. PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
  220. if (group == null) {
  221. return;
  222. } else {
  223. group.setOption(node, world, String.valueOf(value));
  224. }
  225. }
  226. @Override
  227. public String getGroupInfoString(String world, String groupName, String node, String defaultValue) {
  228. PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
  229. if (group == null) {
  230. return defaultValue;
  231. } else {
  232. return group.getOption(node, world, defaultValue);
  233. }
  234. }
  235. @Override
  236. public void setGroupInfoString(String world, String groupName, String node, String value) {
  237. PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
  238. if (group == null) {
  239. return;
  240. } else {
  241. group.setOption(node, world, value);
  242. }
  243. }
  244. public String getPlayerPrefix(String world, OfflinePlayer op) {
  245. PermissionUser user = getUser(op);
  246. if (user != null) {
  247. return user.getPrefix(world);
  248. } else {
  249. return null;
  250. }
  251. }
  252. public String getPlayerSuffix(String world, OfflinePlayer op) {
  253. PermissionUser user = getUser(op);
  254. if (user != null) {
  255. return user.getSuffix(world);
  256. } else {
  257. return null;
  258. }
  259. }
  260. public void setPlayerSuffix(String world, OfflinePlayer player, String suffix) {
  261. PermissionUser user = getUser(player);
  262. if (user != null) {
  263. user.setSuffix(suffix, world);
  264. }
  265. }
  266. public void setPlayerPrefix(String world, OfflinePlayer player, String prefix) {
  267. PermissionUser user = getUser(player);
  268. if (user != null) {
  269. user.setPrefix(prefix, world);
  270. }
  271. }
  272. @Override
  273. public String getPlayerPrefix(String world, String playerName) {
  274. PermissionUser user = getUser(playerName);
  275. if (user != null) {
  276. return user.getPrefix(world);
  277. } else {
  278. return null;
  279. }
  280. }
  281. @Override
  282. public String getPlayerSuffix(String world, String playerName) {
  283. PermissionUser user = getUser(playerName);
  284. if (user != null) {
  285. return user.getSuffix(world);
  286. } else {
  287. return null;
  288. }
  289. }
  290. @Override
  291. public void setPlayerSuffix(String world, String player, String suffix) {
  292. PermissionUser user = getUser(player);
  293. if (user != null) {
  294. user.setSuffix(suffix, world);
  295. }
  296. }
  297. @Override
  298. public void setPlayerPrefix(String world, String player, String prefix) {
  299. PermissionUser user = getUser(player);
  300. if (user != null) {
  301. user.setPrefix(prefix, world);
  302. }
  303. }
  304. @Override
  305. public String getGroupPrefix(String world, String group) {
  306. PermissionGroup pGroup = PermissionsEx.getPermissionManager().getGroup(group);
  307. if (group != null) {
  308. return pGroup.getPrefix(world);
  309. } else {
  310. return null;
  311. }
  312. }
  313. @Override
  314. public void setGroupPrefix(String world, String group, String prefix) {
  315. PermissionGroup pGroup = PermissionsEx.getPermissionManager().getGroup(group);
  316. if (group != null) {
  317. pGroup.setPrefix(prefix, world);
  318. }
  319. }
  320. @Override
  321. public String getGroupSuffix(String world, String group) {
  322. PermissionGroup pGroup = PermissionsEx.getPermissionManager().getGroup(group);
  323. if (group != null) {
  324. return pGroup.getSuffix(world);
  325. } else {
  326. return null;
  327. }
  328. }
  329. @Override
  330. public void setGroupSuffix(String world, String group, String suffix) {
  331. PermissionGroup pGroup = PermissionsEx.getPermissionManager().getGroup(group);
  332. if (group != null) {
  333. pGroup.setSuffix(suffix, world);
  334. }
  335. }
  336. }