/src/tk/funnytopia/funny/Admin.java

https://github.com/FunnyJ2/AdminAssistorDev · Java · 170 lines · 129 code · 30 blank · 11 comment · 13 complexity · 802bcc6ed61b7420a5f6d13533ade7b6 MD5 · raw file

  1. package tk.funnytopia.funny;
  2. import java.io.File;
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.logging.Logger;
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.event.Event;
  10. import org.bukkit.event.Event.Priority;
  11. import org.bukkit.plugin.PluginDescriptionFile;
  12. import org.bukkit.plugin.PluginManager;
  13. import org.bukkit.plugin.java.JavaPlugin;
  14. public class Admin extends JavaPlugin {
  15. Logger log = Logger.getLogger("Minecraft");
  16. private StixPlayerListener stixplayerListener = new StixPlayerListener(this);
  17. private FreezePlayerListener freezeplayerListener = new FreezePlayerListener(this);
  18. private MutePlayerListener muteplayerListener = new MutePlayerListener(this);
  19. private MuteAllListener muteallListener = new MuteAllListener(this);
  20. private ChatLogListener chatlogListener = new ChatLogListener(this);
  21. public ArrayList<String> activePlayers = new ArrayList<String>();
  22. public ArrayList<String> freeze = new ArrayList<String>();
  23. public ArrayList<String> mute = new ArrayList<String>();
  24. public ArrayList<String> misc = new ArrayList<String>();
  25. public String combineSplit(int startIndex, String[] string, String seperator) {
  26. final StringBuilder builder = new StringBuilder();
  27. for (int i = startIndex; i < string.length; i++) {
  28. builder.append(string[i]);
  29. builder.append(seperator);
  30. }
  31. builder.deleteCharAt(builder.length() - seperator.length());
  32. return builder.toString();
  33. }
  34. public void chatLog(String playername, String message, String tag){
  35. final File chatlog;
  36. chatlog = new File("plugins/AdminAssistor/chatlog.txt");
  37. try {
  38. String newline = System.getProperty("line.separator");
  39. FileWriter wrt = new FileWriter(chatlog, true);
  40. String towrite = tag + "<" + playername + "> " + message;
  41. wrt.write(towrite + newline);
  42. wrt.close();
  43. } catch (IOException e) {
  44. e.printStackTrace();
  45. }
  46. //(tag + "<" + playername + "> " + message)
  47. }
  48. public void adminChatMsg(String message, String playername) {
  49. for (final Player player : this.getServer().getOnlinePlayers()) {
  50. if (player.isOp() || player.hasPermission("adminassistor.chat")) {
  51. player.sendMessage(ChatColor.GOLD + "[Private]" + ChatColor.WHITE + "<" + ChatColor.LIGHT_PURPLE + playername + ChatColor.WHITE + "> " + ChatColor.WHITE + message);
  52. this.logInfo("[Private]" + playername + ": " + message);
  53. }
  54. }
  55. }
  56. public void tellAdmin(String message) {
  57. for (final Player player : this.getServer().getOnlinePlayers()) {
  58. if (player.isOp() || player.hasPermission("adminassistor.admin")) {
  59. player.sendMessage(message);
  60. }
  61. }
  62. }
  63. public void fakeChat(String msg, Player player) {
  64. player.chat(msg);
  65. }
  66. public void tellAll(String message, String amessage) {
  67. for (final Player player : this.getServer().getOnlinePlayers()) {
  68. if(player.isOp() || player.hasPermission("adminassistor.admin")){
  69. //admin
  70. player.sendMessage(amessage);
  71. } else {
  72. //normal user
  73. player.sendMessage(message);
  74. }
  75. }
  76. }
  77. public void loadConfiguration(){
  78. //config stuff
  79. String shutdown = "enable-shutdown-command";
  80. String end = "enable-end-command";
  81. String stix = "enable-stix";
  82. getConfig().addDefault(end, false);
  83. getConfig().addDefault(shutdown, false);
  84. getConfig().addDefault(stix, true);
  85. getConfig().options().copyDefaults(true);
  86. saveConfig();
  87. }
  88. public void logInfo(String message) {
  89. log.info("[AdminAssistor] " + message);
  90. }
  91. @Override
  92. public void onDisable() {
  93. }
  94. @Override
  95. public void onEnable() {
  96. loadConfiguration();
  97. PluginDescriptionFile pdfFile = this.getDescription();
  98. this.logInfo(pdfFile.getVersion() + " enabled");
  99. this.getCommand("a").setExecutor(new ACommand(this));
  100. this.getCommand("judge").setExecutor(new JudgeCommand(this));
  101. this.getCommand("g").setExecutor(new GCommand(this));
  102. this.getCommand("mode").setExecutor(new ModeCommand(this));
  103. this.getCommand("shutdown").setExecutor(new ShutDownCommand(this));
  104. this.getCommand("whois").setExecutor(new WhoisCommand(this));
  105. this.getCommand("perm").setExecutor(new PermCommand(this));
  106. this.getCommand("end").setExecutor(new EndCommand(this));
  107. this.getCommand("stix").setExecutor(new StixCommand(this));
  108. this.getCommand("freeze").setExecutor(new FreezeCommand(this));
  109. this.getCommand("mute").setExecutor(new MuteCommand(this));
  110. this.getCommand("muteall").setExecutor(new MuteAllCommand(this));
  111. //note to self: write down perm nodes you lazy bitch!
  112. //chatlog stuff
  113. final File chatlog;
  114. chatlog = new File("plugins/AdminAssistor/chatlog.txt");
  115. if (!chatlog.exists()) {
  116. try {
  117. chatlog.createNewFile();
  118. } catch (IOException e) {
  119. e.printStackTrace();
  120. }
  121. } else {
  122. this.logInfo("Chatlog is ready to log");
  123. }
  124. PluginManager pm = getServer().getPluginManager();
  125. //stix
  126. pm.registerEvent(Event.Type.PLAYER_INTERACT, this.stixplayerListener, Priority.High, this);
  127. //freeze
  128. pm.registerEvent(Event.Type.PLAYER_INTERACT, this.freezeplayerListener, Priority.High, this);
  129. pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, this.freezeplayerListener, Priority.High, this);
  130. pm.registerEvent(Event.Type.PLAYER_CHAT, this.freezeplayerListener, Priority.High, this);
  131. pm.registerEvent(Event.Type.PLAYER_INTERACT_ENTITY, this.freezeplayerListener, Priority.High, this);
  132. //mute
  133. pm.registerEvent(Event.Type.PLAYER_CHAT, this.muteplayerListener, Priority.High, this);
  134. //muteall
  135. pm.registerEvent(Event.Type.PLAYER_CHAT, this.muteallListener, Priority.High, this);
  136. pm.registerEvent(Event.Type.PLAYER_JOIN, muteallListener, Priority.High, this);
  137. //chatlog
  138. pm.registerEvent(Event.Type.PLAYER_CHAT, chatlogListener, Priority.Highest, this);
  139. }
  140. }