Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.ExAlePloit.bungeestaffchat;
- import me.ExAlePloit.bungeestaffchat.commands.Sc;
- import me.ExAlePloit.bungeestaffchat.commands.ScDisable;
- import me.ExAlePloit.bungeestaffchat.commands.ScInfo;
- import me.ExAlePloit.bungeestaffchat.commands.ScReload;
- import me.ExAlePloit.bungeestaffchat.commands.ScReply;
- import me.ExAlePloit.bungeestaffchat.commands.ScSpy;
- import me.ExAlePloit.bungeestaffchat.commands.ScToggle;
- import me.ExAlePloit.bungeestaffchat.listeners.PlayerListener;
- import me.ExAlePloit.bungeestaffchat.player.ScPlayerManager;
- import me.ExAlePloit.bungeestaffchat.commands.ScMsg;
- import me.ExAlePloit.bungeestaffchat.commands.ScPriority;
- import java.io.BufferedWriter;
- import java.io.IOException;
- import java.nio.charset.Charset;
- import java.nio.file.Files;
- import java.nio.file.OpenOption;
- import java.nio.file.Path;
- import java.nio.file.Paths;
- import java.nio.file.StandardOpenOption;
- import java.nio.file.attribute.FileAttribute;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import net.md_5.bungee.api.ChatColor;
- import net.md_5.bungee.api.plugin.Command;
- import net.md_5.bungee.api.plugin.Listener;
- import net.md_5.bungee.api.plugin.Plugin;
- import net.md_5.bungee.config.Configuration;
- import net.md_5.bungee.config.YamlConfiguration;
- public class BungeeStaffChat extends Plugin {
- private static BungeeStaffChat instance;
- private ScPlayerManager playerManager;
- private Configuration config;
- private Configuration lang;
- private boolean shortcutEnabled;
- private char shortcut;
- private String scLayout;
- private String scMsgLayout;
- private String scReplyLayout;
- private String scSpyLayout;
- private boolean scPriorityEnabled;
- private boolean bungeePerms;
- private boolean keepLog;
- private Path logPath;
- public static BungeeStaffChat getInstance() {
- return instance;
- }
- public static String getVersion() {
- return "2.0-BETA";
- }
- public void onLoad() {
- setupConfig();
- }
- public void onEnable() {
- instance = this;
- this.playerManager = new ScPlayerManager();
- getProxy().getPluginManager().registerCommand(this, (Command)new Sc(getConfig().getString("sc-command", "/sc").replaceAll("/", "")));
- getProxy().getPluginManager().registerCommand(this, (Command)new ScDisable(getConfig().getString("scdisable-command", "/scdisable").replaceAll("/", "")));
- getProxy().getPluginManager().registerCommand(this, (Command)new ScReload(getConfig().getString("screload-command", "/screload").replaceAll("/", "")));
- getProxy().getPluginManager().registerCommand(this, (Command)new ScToggle(getConfig().getString("sctoggle-command", "/sctoggle").replaceAll("/", "")));
- getProxy().getPluginManager().registerCommand(this, (Command)new ScPriority(getConfig().getString("scpriority-command", "/scpriority").replaceAll("/", "")));
- getProxy().getPluginManager().registerCommand(this, (Command)new ScMsg(getConfig().getString("scmsg-command", "/scmsg").replaceAll("/", "")));
- getProxy().getPluginManager().registerCommand(this, (Command)new ScReply(getConfig().getString("screply-command", "/screply").replaceAll("/", "")));
- getProxy().getPluginManager().registerCommand(this, (Command)new ScSpy(getConfig().getString("scspy-command", "/scspy").replaceAll("/", "")));
- getProxy().getPluginManager().registerCommand(this, (Command)new ScInfo());
- getProxy().getPluginManager().registerListener(this, (Listener)new PlayerListener());
- this.scPriorityEnabled = false;
- if (getProxy().getPluginManager().getPlugin("BungeePerms") != null)
- this.bungeePerms = true;
- }
- private void setupConfig() {
- Path dirPath = getDataFolder().toPath();
- Path configPath = Paths.get(dirPath.toAbsolutePath().toString(), new String[] { "config.yml" });
- Path langPath = Paths.get(dirPath.toAbsolutePath().toString(), new String[] { "lang.yml" });
- if (!Files.exists(dirPath, new java.nio.file.LinkOption[0]))
- try {
- Files.createDirectory(dirPath, (FileAttribute<?>[])new FileAttribute[0]);
- } catch (IOException e) {
- e.printStackTrace();
- }
- if (!Files.exists(configPath, new java.nio.file.LinkOption[0]))
- try {
- Files.copy(getResourceAsStream("config.yml"), configPath, new java.nio.file.CopyOption[0]);
- } catch (IOException e) {
- e.printStackTrace();
- }
- if (!Files.exists(langPath, new java.nio.file.LinkOption[0]))
- try {
- Files.copy(getResourceAsStream("lang.yml"), langPath, new java.nio.file.CopyOption[0]);
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- this.config = YamlConfiguration.getProvider(YamlConfiguration.class).load(configPath.toFile());
- this.lang = YamlConfiguration.getProvider(YamlConfiguration.class).load(langPath.toFile());
- } catch (IOException e) {
- e.printStackTrace();
- }
- this.scLayout = getConfig().getString("sc-layout");
- this.scMsgLayout = getConfig().getString("scmsg-layout");
- this.scReplyLayout = getConfig().getString("screply-layout");
- this.scSpyLayout = getConfig().getString("scspy-layout");
- this.shortcutEnabled = getConfig().getBoolean("shortcut-enabled", false);
- this.keepLog = getConfig().getBoolean("keep-log", false);
- if (this.shortcutEnabled)
- this.shortcut = getConfig().getString("shortcut").toCharArray()[0];
- if (this.keepLog) {
- this.logPath = Paths.get(dirPath.toAbsolutePath().toString(), new String[] { "staffchat.log" });
- if (!Files.exists(this.logPath, new java.nio.file.LinkOption[0]))
- try {
- Files.createFile(this.logPath, (FileAttribute<?>[])new FileAttribute[0]);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- public Configuration getConfig() {
- return this.config;
- }
- public Configuration getLang() {
- return this.lang;
- }
- public String getScReplyLayout() {
- return ChatColor.translateAlternateColorCodes('&', this.scReplyLayout);
- }
- public String getScMsgLayout() {
- return ChatColor.translateAlternateColorCodes('&', this.scMsgLayout);
- }
- public String getScLayout() {
- return ChatColor.translateAlternateColorCodes('&', this.scLayout);
- }
- public String getScSpyLayout() {
- return this.scSpyLayout;
- }
- public char getShortcut() {
- return this.shortcut;
- }
- public boolean isShortcutEnabled() {
- return this.shortcutEnabled;
- }
- public ScPlayerManager getPlayerManager() {
- return this.playerManager;
- }
- public boolean isScPriorityEnabled() {
- return this.scPriorityEnabled;
- }
- public void setScPriorityEnabled(boolean scPriorityEnabled) {
- this.scPriorityEnabled = scPriorityEnabled;
- }
- public boolean isBungeePerms() {
- return this.bungeePerms;
- }
- public boolean keepLog() {
- return this.keepLog;
- }
- public void appendToLog(String line) {
- try {
- BufferedWriter out = Files.newBufferedWriter(this.logPath, Charset.defaultCharset(), new OpenOption[] { StandardOpenOption.APPEND });
- out.append((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date())).append(": ").append(line);
- out.newLine();
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void reload() {
- try {
- this.config = YamlConfiguration.getProvider(YamlConfiguration.class).load(Paths.get(getDataFolder().getAbsolutePath(), new String[] { "config.yml" }).toFile());
- this.lang = YamlConfiguration.getProvider(YamlConfiguration.class).load(Paths.get(getDataFolder().getAbsolutePath(), new String[] { "lang.yml" }).toFile());
- } catch (IOException e) {
- e.printStackTrace();
- }
- this.scLayout = getConfig().getString("sc-layout");
- this.scMsgLayout = getConfig().getString("scmsg-layout");
- this.scReplyLayout = getConfig().getString("screply-layout");
- this.scSpyLayout = getConfig().getString("scspy-layout");
- this.shortcutEnabled = getConfig().getBoolean("shortcut-enabled", false);
- this.keepLog = getConfig().getBoolean("keep-log", false);
- if (this.shortcutEnabled)
- this.shortcut = getConfig().getString("shortcut").toCharArray()[0];
- if (this.keepLog) {
- this.logPath = Paths.get(getDataFolder().toPath().toAbsolutePath().toString(), new String[] { "staffchat.log" });
- if (!Files.exists(this.logPath, new java.nio.file.LinkOption[0]))
- try {
- Files.createFile(this.logPath, (FileAttribute<?>[])new FileAttribute[0]);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement