Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.65 KB | None | 0 0
  1. package me.ExAlePloit.bungeestaffchat;
  2.  
  3. import me.ExAlePloit.bungeestaffchat.commands.Sc;
  4. import me.ExAlePloit.bungeestaffchat.commands.ScDisable;
  5. import me.ExAlePloit.bungeestaffchat.commands.ScInfo;
  6. import me.ExAlePloit.bungeestaffchat.commands.ScReload;
  7. import me.ExAlePloit.bungeestaffchat.commands.ScReply;
  8. import me.ExAlePloit.bungeestaffchat.commands.ScSpy;
  9. import me.ExAlePloit.bungeestaffchat.commands.ScToggle;
  10. import me.ExAlePloit.bungeestaffchat.listeners.PlayerListener;
  11. import me.ExAlePloit.bungeestaffchat.player.ScPlayerManager;
  12. import me.ExAlePloit.bungeestaffchat.commands.ScMsg;
  13. import me.ExAlePloit.bungeestaffchat.commands.ScPriority;
  14.  
  15. import java.io.BufferedWriter;
  16. import java.io.IOException;
  17. import java.nio.charset.Charset;
  18. import java.nio.file.Files;
  19. import java.nio.file.OpenOption;
  20. import java.nio.file.Path;
  21. import java.nio.file.Paths;
  22. import java.nio.file.StandardOpenOption;
  23. import java.nio.file.attribute.FileAttribute;
  24. import java.text.SimpleDateFormat;
  25. import java.util.Date;
  26. import net.md_5.bungee.api.ChatColor;
  27. import net.md_5.bungee.api.plugin.Command;
  28. import net.md_5.bungee.api.plugin.Listener;
  29. import net.md_5.bungee.api.plugin.Plugin;
  30. import net.md_5.bungee.config.Configuration;
  31. import net.md_5.bungee.config.YamlConfiguration;
  32.  
  33. public class BungeeStaffChat extends Plugin {
  34.   private static BungeeStaffChat instance;
  35.  
  36.   private ScPlayerManager playerManager;
  37.  
  38.   private Configuration config;
  39.  
  40.   private Configuration lang;
  41.  
  42.   private boolean shortcutEnabled;
  43.  
  44.   private char shortcut;
  45.  
  46.   private String scLayout;
  47.  
  48.   private String scMsgLayout;
  49.  
  50.   private String scReplyLayout;
  51.  
  52.   private String scSpyLayout;
  53.  
  54.   private boolean scPriorityEnabled;
  55.  
  56.   private boolean bungeePerms;
  57.  
  58.   private boolean keepLog;
  59.  
  60.   private Path logPath;
  61.  
  62.   public static BungeeStaffChat getInstance() {
  63.     return instance;
  64.   }
  65.  
  66.   public static String getVersion() {
  67.     return "2.0-BETA";
  68.   }
  69.  
  70.   public void onLoad() {
  71.     setupConfig();
  72.   }
  73.  
  74.   public void onEnable() {
  75.     instance = this;
  76.     this.playerManager = new ScPlayerManager();
  77.     getProxy().getPluginManager().registerCommand(this, (Command)new Sc(getConfig().getString("sc-command", "/sc").replaceAll("/", "")));
  78.     getProxy().getPluginManager().registerCommand(this, (Command)new ScDisable(getConfig().getString("scdisable-command", "/scdisable").replaceAll("/", "")));
  79.     getProxy().getPluginManager().registerCommand(this, (Command)new ScReload(getConfig().getString("screload-command", "/screload").replaceAll("/", "")));
  80.     getProxy().getPluginManager().registerCommand(this, (Command)new ScToggle(getConfig().getString("sctoggle-command", "/sctoggle").replaceAll("/", "")));
  81.     getProxy().getPluginManager().registerCommand(this, (Command)new ScPriority(getConfig().getString("scpriority-command", "/scpriority").replaceAll("/", "")));
  82.     getProxy().getPluginManager().registerCommand(this, (Command)new ScMsg(getConfig().getString("scmsg-command", "/scmsg").replaceAll("/", "")));
  83.     getProxy().getPluginManager().registerCommand(this, (Command)new ScReply(getConfig().getString("screply-command", "/screply").replaceAll("/", "")));
  84.     getProxy().getPluginManager().registerCommand(this, (Command)new ScSpy(getConfig().getString("scspy-command", "/scspy").replaceAll("/", "")));
  85.     getProxy().getPluginManager().registerCommand(this, (Command)new ScInfo());
  86.     getProxy().getPluginManager().registerListener(this, (Listener)new PlayerListener());
  87.     this.scPriorityEnabled = false;
  88.     if (getProxy().getPluginManager().getPlugin("BungeePerms") != null)
  89.       this.bungeePerms = true;
  90.   }
  91.  
  92.   private void setupConfig() {
  93.     Path dirPath = getDataFolder().toPath();
  94.     Path configPath = Paths.get(dirPath.toAbsolutePath().toString(), new String[] { "config.yml" });
  95.     Path langPath = Paths.get(dirPath.toAbsolutePath().toString(), new String[] { "lang.yml" });
  96.     if (!Files.exists(dirPath, new java.nio.file.LinkOption[0]))
  97.       try {
  98.         Files.createDirectory(dirPath, (FileAttribute<?>[])new FileAttribute[0]);
  99.       } catch (IOException e) {
  100.         e.printStackTrace();
  101.       }  
  102.     if (!Files.exists(configPath, new java.nio.file.LinkOption[0]))
  103.       try {
  104.         Files.copy(getResourceAsStream("config.yml"), configPath, new java.nio.file.CopyOption[0]);
  105.       } catch (IOException e) {
  106.         e.printStackTrace();
  107.       }  
  108.     if (!Files.exists(langPath, new java.nio.file.LinkOption[0]))
  109.       try {
  110.         Files.copy(getResourceAsStream("lang.yml"), langPath, new java.nio.file.CopyOption[0]);
  111.       } catch (IOException e) {
  112.         e.printStackTrace();
  113.       }  
  114.     try {
  115.       this.config = YamlConfiguration.getProvider(YamlConfiguration.class).load(configPath.toFile());
  116.       this.lang = YamlConfiguration.getProvider(YamlConfiguration.class).load(langPath.toFile());
  117.     } catch (IOException e) {
  118.       e.printStackTrace();
  119.     }
  120.     this.scLayout = getConfig().getString("sc-layout");
  121.     this.scMsgLayout = getConfig().getString("scmsg-layout");
  122.     this.scReplyLayout = getConfig().getString("screply-layout");
  123.     this.scSpyLayout = getConfig().getString("scspy-layout");
  124.     this.shortcutEnabled = getConfig().getBoolean("shortcut-enabled", false);
  125.     this.keepLog = getConfig().getBoolean("keep-log", false);
  126.     if (this.shortcutEnabled)
  127.       this.shortcut = getConfig().getString("shortcut").toCharArray()[0];
  128.     if (this.keepLog) {
  129.       this.logPath = Paths.get(dirPath.toAbsolutePath().toString(), new String[] { "staffchat.log" });
  130.       if (!Files.exists(this.logPath, new java.nio.file.LinkOption[0]))
  131.         try {
  132.           Files.createFile(this.logPath, (FileAttribute<?>[])new FileAttribute[0]);
  133.         } catch (IOException e) {
  134.           e.printStackTrace();
  135.         }  
  136.     }
  137.   }
  138.  
  139.   public Configuration getConfig() {
  140.     return this.config;
  141.   }
  142.  
  143.   public Configuration getLang() {
  144.     return this.lang;
  145.   }
  146.  
  147.   public String getScReplyLayout() {
  148.     return ChatColor.translateAlternateColorCodes('&', this.scReplyLayout);
  149.   }
  150.  
  151.   public String getScMsgLayout() {
  152.     return ChatColor.translateAlternateColorCodes('&', this.scMsgLayout);
  153.   }
  154.  
  155.   public String getScLayout() {
  156.     return ChatColor.translateAlternateColorCodes('&', this.scLayout);
  157.   }
  158.  
  159.   public String getScSpyLayout() {
  160.     return this.scSpyLayout;
  161.   }
  162.  
  163.   public char getShortcut() {
  164.     return this.shortcut;
  165.   }
  166.  
  167.   public boolean isShortcutEnabled() {
  168.     return this.shortcutEnabled;
  169.   }
  170.  
  171.   public ScPlayerManager getPlayerManager() {
  172.     return this.playerManager;
  173.   }
  174.  
  175.   public boolean isScPriorityEnabled() {
  176.     return this.scPriorityEnabled;
  177.   }
  178.  
  179.   public void setScPriorityEnabled(boolean scPriorityEnabled) {
  180.     this.scPriorityEnabled = scPriorityEnabled;
  181.   }
  182.  
  183.   public boolean isBungeePerms() {
  184.     return this.bungeePerms;
  185.   }
  186.  
  187.   public boolean keepLog() {
  188.     return this.keepLog;
  189.   }
  190.  
  191.   public void appendToLog(String line) {
  192.     try {
  193.       BufferedWriter out = Files.newBufferedWriter(this.logPath, Charset.defaultCharset(), new OpenOption[] { StandardOpenOption.APPEND });
  194.       out.append((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date())).append(": ").append(line);
  195.       out.newLine();
  196.       out.close();
  197.     } catch (IOException e) {
  198.       e.printStackTrace();
  199.     }
  200.   }
  201.  
  202.   public void reload() {
  203.     try {
  204.       this.config = YamlConfiguration.getProvider(YamlConfiguration.class).load(Paths.get(getDataFolder().getAbsolutePath(), new String[] { "config.yml" }).toFile());
  205.       this.lang = YamlConfiguration.getProvider(YamlConfiguration.class).load(Paths.get(getDataFolder().getAbsolutePath(), new String[] { "lang.yml" }).toFile());
  206.     } catch (IOException e) {
  207.       e.printStackTrace();
  208.     }
  209.     this.scLayout = getConfig().getString("sc-layout");
  210.     this.scMsgLayout = getConfig().getString("scmsg-layout");
  211.     this.scReplyLayout = getConfig().getString("screply-layout");
  212.     this.scSpyLayout = getConfig().getString("scspy-layout");
  213.     this.shortcutEnabled = getConfig().getBoolean("shortcut-enabled", false);
  214.     this.keepLog = getConfig().getBoolean("keep-log", false);
  215.     if (this.shortcutEnabled)
  216.       this.shortcut = getConfig().getString("shortcut").toCharArray()[0];
  217.     if (this.keepLog) {
  218.       this.logPath = Paths.get(getDataFolder().toPath().toAbsolutePath().toString(), new String[] { "staffchat.log" });
  219.       if (!Files.exists(this.logPath, new java.nio.file.LinkOption[0]))
  220.         try {
  221.           Files.createFile(this.logPath, (FileAttribute<?>[])new FileAttribute[0]);
  222.         } catch (IOException e) {
  223.           e.printStackTrace();
  224.         }  
  225.     }
  226.   }
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement