PageRenderTime 52ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

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