commit 6a8764194c70e13736e20e4be682d7525abb1af6 Author: Avior Date: Tue Jun 11 14:22:46 2019 +0200 Open Sourced! diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9824642 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +#VSCode +.vscode + +#Java +target/ +.classpath +.project +.settings/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..46bd39c --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,60 @@ +# This file is a template, and might need editing before it works on your project. +--- + +variables: + # This will supress any download for dependencies and plugins or upload messages which would clutter the console log. + # `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work. + MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true" + # As of Maven 3.3.0 instead of this you may define these options in `.mvn/maven.config` so the same config is used + # when running from the command line. + # `installAtEnd` and `deployAtEnd` are only effective with recent version of the corresponding plugins. + MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true" + +# Cache downloaded dependencies and plugins between builds. +# To keep cache across branches add 'key: "$CI_JOB_REF_NAME"' +cache: + paths: + - .m2/repository + +# For `master` branch run `mvn deploy` automatically. +# Here you need to decide whether you want to use JDK7 or 8. +# To get this working you need to define a volume while configuring your gitlab-ci-multi-runner. +# Mount your `settings.xml` as `/root/.m2/settings.xml` which holds your secrets. +# See https://maven.apache.org/settings.html +Build: + # Use stage test here, so the pages job may later pickup the created site. + stage: build + script: + - mvn -B clean install + - mvn -B test + # Archive up the built documentation site. + artifacts: + paths: + - target/ + image: maven + +Test: + # Use stage test here, so the pages job may later pickup the created site. + stage: test + script: + - mvn -B test + # Archive up the built documentation site. + artifacts: + paths: + - target/ + image: maven + +Deploy: + # Use stage test here, so the pages job may later pickup the created site. + stage: deploy + script: + - cp ./settings-security.xml $HOME/.m2/settings-security.xml + - cp ./settings.xml $HOME/.m2/settings.xml + - mvn -B deploy + only: + - tags + # Archive up the built documentation site. + artifacts: + paths: + - target + image: maven diff --git a/Chat-Manager.iml b/Chat-Manager.iml new file mode 100644 index 0000000..81e9603 --- /dev/null +++ b/Chat-Manager.iml @@ -0,0 +1,37 @@ + + + + + + + SPIGOT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..dde18c0 --- /dev/null +++ b/LICENSE @@ -0,0 +1 @@ +all rights reserved \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4bd503f --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +WIKI !!! \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..31c9159 --- /dev/null +++ b/pom.xml @@ -0,0 +1,86 @@ + + + 4.0.0 + net.DeltaWings + ChatManager + 1.4.0 + jar + + Chat Manager + + Have an Ultra customizable Chat Manager + + + UTF-8 + + http://delta-wings.net + + + clean package + Chat-Manager + + + + org.apache.maven.wagon + wagon-ftp + 1.0-beta-6 + + + + + + 3.1 + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + + package + + shade + + + true + + + + + + + + src/main/ressources + true + + + + + + + spigotmc-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + + + + org.spigotmc + spigot-api + 1.12.2-R0.1-SNAPSHOT + provided + + + org.bukkit + bukkit + 1.12.2-R0.1-SNAPSHOT + provided + + + diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Api/API.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Api/API.java new file mode 100644 index 0000000..937620c --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Api/API.java @@ -0,0 +1,191 @@ +package net.DeltaWings.Minecraft.ChatManager.Api; + +import net.DeltaWings.Minecraft.ChatManager.Custom.Config; +import net.DeltaWings.Minecraft.ChatManager.Custom.FileManager; +import net.DeltaWings.Minecraft.ChatManager.Main; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class API { + + /** + * Replace each + * @param text text to replace + * @param replacement map to replace the key by the value + * @return the replaced text + */ + public static String multiReplace(String text, HashMap replacements) { + for(Map.Entry entry : replacements.entrySet()) { + Main.log(entry.getKey()); + Main.log(entry.getValue()); + text = text.replace(entry.getKey(), entry.getValue()); + } + return text.replace("&", "§"); + } + + /** + * Send a broadcast message + * @param Sender Command sender or desired sender + * @param Message message broadcasted + */ + public static void broadcast(String Sender, String Message) { + Config a = new Config("config", "broadcast"); + HashMap replacements = new HashMap<>(); + replacements.put("[player]", Sender); + replacements.put("[message]", Message); + Bukkit.broadcastMessage(multiReplace(a.getString("format"), replacements)); + } + + /** + * Clearchat + * @param Sender the Sender is the name + * @param Receiver the receiver. if "null" will send to everyone + */ + public static void clearchat(String Sender, String Receiver) { + if(Receiver != null) { + for ( Player p : Bukkit.getServer().getOnlinePlayers() ) if ( p.getName().equalsIgnoreCase(Receiver) ) cca(p, Sender); + } else for ( Player p : Bukkit.getServer().getOnlinePlayers() ) cca(p, Sender); + } + + private static void cca(Player p, String c) { + for ( int i = 0; i < new Config("config", "clearchat").getInt("lines-to-clear"); i++ ) p.sendMessage(" "); + p.sendMessage(new Config("messages", "clearchat").getString("clear").replace("[cleaner]", c).replace("&", "§")); + } + + private static Boolean locked = false; + + /** + * lock or unlock the chat + */ + public static void lockchat() { + Config config = new Config("config", "lockchat"); + if ( locked ) { + locked = false; + Bukkit.broadcastMessage(config.getString("unlocked").replace("&", "§")); + } else { + locked = true; + Bukkit.broadcastMessage(config.getString("locked").replace("&", "§")); + } + } + + /** + * Get if the chat is locked or not + * @return the state of the chat + */ + public static Boolean isChatLocked() { + return locked; + } + + /** + * + * @param Sender Sender + * @param Player Player muted + * @param Time Time muted(-1 for perma) + * @param Type Type(all, chat, cmd) + * @param Reason reason + */ + public static void mute(CommandSender Sender, Player Player, Integer Time, String Type, String Reason) { + Config c = new Config("players", Player.getName()); + Config m = new Config("messages", "mute"); + if(Type.equalsIgnoreCase("all")) { + if ( c.getBoolean("mute.chat") && c.getBoolean("mute.cmd") ) Sender.sendMessage(""); + if(!c.getBoolean("mute.chat")) mua(Player, Time, Reason, Type, Sender); + if(!c.getBoolean("mute.cmd")) mub(Player, Time, Reason, Type, Sender); + } else if(!c.getBoolean("mute." + Type)) { + if(Type.equalsIgnoreCase("chat")) mua(Player, Time, Reason, Type, Sender); + else mub(Player, Time, Reason, Type, Sender); + } else Sender.sendMessage(m.getString("already-muted").replace("[type]", Type).replace("&", "§")); + } + + //mute from chat + private static void mua(Player p, Integer i, String r,String t, CommandSender s) { + Config c = new Config("players", p.getName()); + Config m = new Config("messages", "mute"); + c.set("mute.chat", true); + if(i == -1) c.set("mute.from", -1); + else c.set("mute.from", i * 60000 + System.currentTimeMillis()); + c.set("mute.time", i); + c.set("mute.reason", r); + c.save(); + p.sendMessage(m.getString("muted.self").replace("[from]", "chat").replace("[reason]", r).replace("&", "§")); + s.sendMessage(m.getString("muted.other").replace("[player]", p.getName()).replace("[type]", t).replace("[reason]", r).replace("&", "§")); + } + + private static void mub(Player p, Integer i, String r,String t, CommandSender s) { + Config c = new Config("players", p.getName()); + Config m = new Config("messages", "mute"); + c.set("mute.cmd", true); + if(i == -1) c.set("mute.time", new Long(i)); + else c.set("mute.time", System.currentTimeMillis() + (i * 60000)); + c.set("mute.reason", r); + c.save(); + p.sendMessage(m.getString("muted.self").replace("[from]", "commands").replace("[reason]", r).replace("&", "§")); + s.sendMessage(m.getString("muted.other").replace("[player]", p.getName()).replace("[type]", t).replace("[reason]", r).replace("&", "§")); + } + + /** + * + * @param Sender Sender of the command + * @param Player Player unmutted + * @param Type Type unmutted(chat, cmd, all) + */ + public static void unmute(CommandSender Sender, Player Player, String Type) { + Config c = new Config("players", Player.getName()); + if(Type.equalsIgnoreCase("all") || Type.equalsIgnoreCase("chat")) { + c.set("mute.chat", false); + } + if(Type.equalsIgnoreCase("all") || Type.equalsIgnoreCase("cmd")) { + c.set("mute.cmd", false); + } + c.save(); + Config m = new Config("messages", "mute"); + Sender.sendMessage(m.getString("unmutted.other").replace("[player]", Player.getName()).replace("[type]", Type).replace("&", "§")); + Player.sendMessage(m.getString("unmutted.self").replace("[type]", Type).replace("&", "§")); + } + + /** + * + * @return String list of muted players ex : [Aviortheking,1489446063044,"banned"] + */ + public static List mutedlist() { + List r = new ArrayList<>(); + for(String f : FileManager.listFiles(Main.getInstance().getDataFolder() + File.separator + "players")) { + f = f.replace(".yml", ""); + Config c = new Config("players", f); + if(c.getBoolean("mute.chat")) { + String[] l = new String[3]; + l[0] = f; + if(c.getLong("mute.from") == -1) l[1] = "permanent"; + else l[1] = c.getInt("mute.time") + " Minutes"; + l[2] = c.getString("mute.reason"); + r.add(l); + } + } + return r; + } + + static public void logMessage(String message) { + try { + File l = new File(Main.getInstance().getDataFolder(), "logs.txt"); + FileManager.createFile(l); + PrintWriter p = new PrintWriter(new FileWriter(l, true)); + p.println(message); + p.close(); + } catch (IOException e) { + Main.error("Error !"); + e.printStackTrace(); + } + + } +} diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Broadcast.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Broadcast.java new file mode 100644 index 0000000..05384cd --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Broadcast.java @@ -0,0 +1,28 @@ +package net.DeltaWings.Minecraft.ChatManager.Commands; + +import net.DeltaWings.Minecraft.ChatManager.Api.API; +import net.DeltaWings.Minecraft.ChatManager.Custom.Config; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; + +public class Broadcast implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender s, Command c, String l, String[] a) { + if((s instanceof Player && s.hasPermission("chat-manager.broadcast")) || s instanceof ConsoleCommandSender) { + if(a.length > 0) { + StringBuilder m = new StringBuilder(); + for(String r : a) m.append(r).append(" "); + API.broadcast(s.getName(), m.toString()); + return true; + } else { + return false; + } + } else s.sendMessage(new Config("messages", "global").getString("permission").replace("&", "§")); + return true; + } +} \ No newline at end of file diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Channel.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Channel.java new file mode 100644 index 0000000..ab61e92 --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Channel.java @@ -0,0 +1,483 @@ +package net.DeltaWings.Minecraft.ChatManager.Commands; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import net.DeltaWings.Minecraft.ChatManager.Custom.Config; +import net.DeltaWings.Minecraft.ChatManager.Custom.FileManager; +import net.DeltaWings.Minecraft.ChatManager.Main; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; + +public class Channel implements CommandExecutor { + + private Config a = new Config("messages", "channel"); + private Config b = new Config("config", "channel"); + private FileManager c = new FileManager(); + private Main i = Main.getInstance(); + private String j = File.separator; + private final File d = new File(i.getDataFolder() + j + "channels"); + private Config h = new Config("messages", "global"); + + @Override + public boolean onCommand(CommandSender e, Command f, String label, String[] g) { + if ( f.getName().equalsIgnoreCase("channel") ) { +// /channels list + if ( g.length == 1 && g[0].equalsIgnoreCase("list") ) { + if ( e instanceof Player ) { + if ( e.hasPermission("chat-manager.channel.list") ) a(e); + else e(e); + } else a(e); +// /channel create WORK + } else if ( g.length == 2 && g[0].equalsIgnoreCase("create") ) { + if ( e instanceof Player ) { + if ( e.hasPermission("chat-manager.channel.create") ) b(g, e); + else e(e); + } else e.sendMessage(a.getString("console-cant")); +// /channel leave WORK + } else if ( g.length == 2 && g[0].equalsIgnoreCase("leave") ) { + if(e instanceof Player) { + if(e.hasPermission("chat-manager.channel.leave")) c(g, e); + else e(e); + } else e.sendMessage(a.getString("console-cant")); +// /channel join WORK + } else if ( g.length == 2 && g[0].equalsIgnoreCase("join") ) { + if(e instanceof Player) { + if(e.hasPermission("chat-manager.channel.join")) d(g, e); + else e(e); + } else e.sendMessage(a.getString("console-cant")); +// /channel invite need multiplayers p isn't online et invited messages + } else if ( g.length == 3 && g[0].equalsIgnoreCase("invite") ) { + if(e instanceof Player) { + if(e.hasPermission("chat-manager.channel.invite")) f(g, e); + else e(e); + } else e.sendMessage(a.getString("console-cant")); +// /channel disband WORK + } else if ( g.length == 2 && g[0].equalsIgnoreCase("disband") ) { + if(e instanceof Player) { + if(e.hasPermission("chat-manager.channel.disband")) g(g, e); + else e(e); + } else g(g, e); +// /channel kick WORK + } else if ( g.length == 3 && g[0].equalsIgnoreCase("kick") ) { + if(e instanceof Player) { + if(e.hasPermission("chat-manager.channel.kick")) h(g, e); + else e(e); + } else h(g, e); +// /channel promote WORK + } else if ( g.length == 3 && g[0].equalsIgnoreCase("promote") ) { + if(e instanceof Player) { + if(e.hasPermission("chat-manager.channel.promote")) i(g, e); + else e(e); + } else e.sendMessage(a.getString("console-cant")); +// /channel demote WORK + } else if ( g.length == 3 && g[0].equalsIgnoreCase("demote") ) { + if(e instanceof Player) { + if(e.hasPermission("chat-manager.channel.demote")) j(g, e); + else e(e); + } else e.sendMessage(a.getString("console-cant")); +// / channel infos + } else if ( g.length == 2 && g[0].equalsIgnoreCase("infos") ) { + if ( e.hasPermission("chat-manager.channel.info") ) { + e.sendMessage("Work In Progress"); + /*if(config.getStringList("channels-list").contains(args[1])){ + /* + List avadmins = config.getStringList("channels."+args[1]+"admins"); + String admins = ""; + for (int i = 0; i < avadmins.size(); i++) { + String avadminst = avadmins.get(i); + admins = String.valueOf(admins) + avadminst + " "; + } + List avusers = config.getStringList("channels."+args[1]+"users"); + String users = ""; + for (int i = 0; i < avusers.size(); i++) { + users = String.valueOf(users) + avusers.get(i)+ " "; + } + + String admins = ""; + String users = ""; + String msg = "§fChannel Infos :\nName : "+args[1]+"\n§fprefix : "+config.getString("channels."+args[1]+".prefix")+"\n§fAdmins : "+admins+"\n§fUsers : "+users+"\n§fStatus : "+config.getString("channels."+args[1]+".status"); + p.sendMessage(msg.replace("&", "§")); + }*/ + } else e.sendMessage(new Config("messages", "global").getString("permission").replace("&", "§")); + +// /channel help [] + } else if ( g.length == 2 && g[0].equalsIgnoreCase("help") ) { + //help + e.sendMessage("Work In Progress"); +// /channel admin + } else if ( g.length == 1 && g[0].equalsIgnoreCase("admin") ) { + e.sendMessage("Work In Progress"); + /*if(pl.getPermissionsForCmd(p, cmd, args)){ + //join + if(args[1].equalsIgnoreCase("join")){ + //check si le groupe existe + //check si il fait déjà parti du groupe + //check si c'est le même rang que le sien + //message tu es déjà dans ce channel et ce rang + //vire de son rang et on le fout dans l'autre + //rejoindre le groupe + if(config.getStringList("channels-list").contains(args[1])){ + if(args[2].equalsIgnoreCase("admins")||args[2].equalsIgnoreCase("users")){ + if(config.getStringList("channels."+args[1]+".admins").contains(p.getName()) || config.getStringList("channels."+args[2]+".users").contains(p.getName())){ + if(config.getStringList("channels."+args[1]+"."+args[2]).contains(p.getName())){ + //message tu es déjà dans ce channel + p.sendMessage(config.getString("messages.channel.already-in").replace("&", "§")); + }else{ + List list = config.getStringList("channels."+args[1]+"."+args[2]); + list.add(p.getName()); + config.set("channels."+args[1]+"."+args[2], list); + //message tu as rejoins le channel en tant que args [2] + p.sendMessage(config.getString("messages.channel.channel-joined").replace("&", "§")); + if(args[2].equalsIgnoreCase("admins")){ + List remove = config.getStringList("channels."+args[1]+".users"); + for ( int i = 0; i < remove.size(); i++){ + String tempNamea = remove.get(i); + if(tempNamea.equals(p.getName())){ + remove.remove(i); + } + } + }else{ + List removea = config.getStringList("channels."+args[1]+".admins"); + for ( int ia = 0; ia < removea.size(); ia++){ + String tempName = removea.get(ia); + if(tempName.equals(p.getName())){ + removea.remove(ia); + } + } + } + } + }else{ + List list = config.getStringList("channels."+args[1]+"."+args[2]); + list.add(p.getName()); + config.set("channels."+args[1]+"."+args[2], list); + //message tu as rejoins le channel + p.sendMessage(config.getString("messages.channel.channel-joined").replace("&", "§")); + + } + }else{ + //il y a uniquement deux rangs ! (admins, users) + p.sendMessage(config.getString("messages.badly-written").replace("&", "§")); + + } + }else{ + //message ce groupe n'existe pas + p.sendMessage(config.getString("messages.channel.dont-exist").replace("&", "§")); + + } + }else if(args[1].equalsIgnoreCase("disband")){ + //disband + config.set("channels."+args[1]+"status", null); + config.set("channels."+args[1]+".prefix", null); + config.set("channels."+args[1]+".users", null); + config.set("channels."+args[1]+".admins", null); + config.set("channels."+args[1], null); + //message channel disbanded + p.sendMessage(config.getString("messages.channel.channel-disbanded").replace("&", "§")); + + }else{ + //Message Badly Written + p.sendMessage(config.getString("messages.badly-written").replace("&", "§")); + } + }*/ + } else { + e.sendMessage(new Config("messages", "global").getString("badly-written").replace("&", "§")); + } + } + return true; + } + + /* + //local vars + k : channels list message + l : CommandSender + m : for loop channel String + n : for loop channel config + */ + private void a(CommandSender l) { + StringBuilder k = new StringBuilder(); + if( FileManager.listFiles(d).size() != 0) { + for (String m : FileManager.listFiles(d)) { + Config n = new Config("channels", m.replace(".yml", "")); + if (n.getStringList("users").contains(l.getName())) { + k.append(b.getString("colors.user-name")).append(m.replace(".yml", "")).append(" "); + } else if (n.getStringList("admins").contains(l.getName())) { + k.append(b.getString("colors.admin-name")).append(m.replace(".yml", "")).append(" "); + } else { + k.append(b.getString("colors.default")).append(m.replace(".yml", "")).append(" "); + } + } + } + l.sendMessage(a.getString("list-start").replace("&", "§")+"\n"+ k.toString().replace("&", "§")+"\n"+a.getString("list-end").replace("&", "§")); + } + + /* + k = args + l = CommandSender + m = Channel + */ + private void b(String[] k, CommandSender l) { + if(k.length != 2) l.sendMessage(a.getString("one-word-channel").replace("&", "§")); + else { + if(!d.exists()) FileManager.createFolder(d); + Config m = new Config("channels", k[1]); + if(m.exist()) l.sendMessage(a.getString("already-exist").replace("[channel]", k[1]).replace("&", "§")); + else { + m.create(); + m.set("users"); + List n = new ArrayList<>(); + n.add(l.getName()); + m.set("admins", n); + m.set("prefix", "[&8"+k[1]+"&f]"); + m.set("status", "open"); + m.save(); + l.sendMessage(a.getString("channel-created").replace("&", "§")); + } + } + } + + /* + k = commandSender + */ + private void e(CommandSender k) { + k.sendMessage(h.getString("permission").replace("&", "§")); + } + + /* + k = args + l = CommandSender + m = Channel + n = list + o = for loop + */ + private void c(String[] k, CommandSender l) { + if ( k.length != 2 ) l.sendMessage(a.getString("one-word-channel").replace("&", "§")); + else { + if ( FileManager.listFiles(d).contains(k[1] + ".yml") ) { + Config m = new Config("channels", k[1]); + if ( m.getStringList("admins").contains(l.getName()) ) { + List n = m.getStringList("admins"); + for ( int o = 0; o < n.size(); o++ ) { + if ( n.get(o).equals(l.getName()) ) { + n.remove(o); + l.sendMessage(a.getString("deleted-from-channel").replace("&", "§")); + if ( n.size() == 0 ) { + FileManager.delete(d + j + k[1] + ".yml"); + l.sendMessage(a.getString("last-admin-delete").replace("&", "§")); + } else { + m.set("admins", n); + m.save(); + } + + } + } + } else if ( m.getStringList("channels." + k[1] + ".users").contains(l.getName()) ) { + List n = m.getStringList("users"); + for ( int o = 0; o < n.size(); o++ ) { + if ( n.get(o).equals(l.getName()) ) { + n.remove(o); + l.sendMessage(a.getString("deleted-from-channel").replace("&", "§")); + m.set("users", n); + m.save(); + } + } + } else l.sendMessage(a.getString("not-a-user").replace("&", "§")); + } else l.sendMessage(a.getString("dont-exist").replace("&", "§")); + } + } + + /* + k = args + l = CommandSender + m = Channel + n = list + o = for loop + p = pconfig + q = name list + */ + private void d(String[] k, CommandSender l) { + if ( FileManager.listFiles(d).contains(k[1] + ".yml") ) { + Config m = new Config("channels", k[1]); + if ( !m.getString("admins").contains(l.getName()) && !m.getString("users").contains(l.getName()) ) { + if ( m.getString("status").equalsIgnoreCase("public") ) { + List n = m.getStringList("users"); + n.add(l.getName()); + m.set("users", n); + m.save(); + l.sendMessage(a.getString("channel-joined").replace("&", "§")); + } else { + Config p = new Config("players", l.getName()); + if ( p.getStringList("invite").contains(k[1]) ) { + List q = p.getStringList("invite"); + for ( int ic = 0; ic < q.size(); ic++ ) if ( q.get(ic).equals(k[1]) ) q.remove(ic); + p.set("invite", q); + p.save(); + List n = m.getStringList("users"); + n.add(l.getName()); + m.set("users", n); + m.save(); + l.sendMessage(a.getString("channel-joined").replace("&", "§")); + } else l.sendMessage(a.getString("cant-join").replace("&", "§")); + } + } else l.sendMessage(a.getString("already-in").replace("&", "§")); + } + } + + /* + k = args + l = CommandSender + m = players + n = player config + o = list + */ + private void f(String[] k, CommandSender l) { + if ( k.length != 3 ) l.sendMessage(h.getString("badly-written").replace("&", "§")); + else { + if ( new Config("channels", k[2]).getStringList("users").contains(l.getName()) || new Config("channels", k[2]).getStringList("admins").contains(l.getName()) ) { + for ( Player m : Bukkit.getServer().getOnlinePlayers() ) { + if ( m.getName().equalsIgnoreCase(k[1]) ) { + Config n = new Config("players", m.getName()); + if ( !n.exist() ) n.create(); + List o = n.getStringList("invite"); + o.add(k[2]); + n.set("invite", o); + n.save(); + l.sendMessage(a.getString("you-invited").replace("[player]", k[1]).replace("&", "§")); + m.sendMessage(a.getString("invited").replace("[channel]", k[2]).replace("[player]", k[1]).replace("&", "§")); + } + } + } else l.sendMessage(a.getString("not-in-channel").replace("&", "§")); + } + } + + /* + k = args + l = CommandSender + */ + private void g(String[] k, CommandSender l) { + if ( k.length == 2 ) { + if ( FileManager.listFiles(d).contains(k[1] + ".yml") ) { + if ( l instanceof ConsoleCommandSender ||new Config("channels", k[1]).getStringList("admins").contains(l.getName()) ) { + FileManager.delete(d + j + k[1] + ".yml"); + l.sendMessage(a.getString("channel-disbanded").replace("&", "§")); + } else l.sendMessage(a.getString("cant-disband").replace("&", "§")); + } else l.sendMessage(a.getString("dont-exist").replace("&", "§")); + } else l.sendMessage(a.getString("one-word-channel").replace("&", "§")); + } + + /* + k = args + l = CommandSender + m = channel config + n = users list + o = loop + */ + private void h(String[] k, CommandSender l) { + if ( k.length != 3 ) l.sendMessage(new Config("messages", "global").getString("badly-written").replace("&", "§")); + else if ( FileManager.listFiles(d).contains(k[2] + ".yml") ) { + Config m = new Config("channels", k[2]); + if (l instanceof ConsoleCommandSender || m.getStringList("admins").contains(l.getName()) ) { + if (!(l instanceof ConsoleCommandSender) && m.getStringList("admins").contains(k[1]) ) l.sendMessage(a.getString("cant-do-admin").replace("&", "§")); + else if ( m.getStringList("users").contains(k[1]) ) { + List n = m.getStringList("users"); + for ( int o = 0; o < n.size(); o++ ) if ( n.get(o).equals(k[1]) ) n.remove(o); + m.set("users", n); + m.save(); + l.sendMessage(a.getString("kicked").replace("[player]", k[1]).replace("&", "§")); + } else l.sendMessage(a.getString("not-in-your-cannel").replace("[player]", k[1]).replace("&", "§")); + } else l.sendMessage(a.getString("cant-kick-if-not-admin").replace("&", "§")); + } else l.sendMessage(a.getString("dont-exist").replace("&", "§")); + } + + /* + k = args + l = CommandSender + m = channel config + n = users list + o = loop + */ + private void i(String[] k, CommandSender l) { + if ( k.length != 3 ) l.sendMessage(new Config("messages", "global").getString("badly-written").replace("&", "§")); + else if ( FileManager.listFiles(d).contains(k[2] + ".yml") ) { + Config m = new Config("channels", k[2]); + if ( m.getStringList("admins").contains(l.getName()) ) { + if ( m.getStringList("users").contains(k[1]) ) { + List n = m.getStringList("users"); + for ( int o = 0; o < n.size(); o++ ) if ( n.get(o).equals(k[1]) ) n.remove(o); + m.set("users", n); + List admins = m.getStringList("admins"); + admins.add(k[1]); + m.set("admins", admins); + m.save(); + l.sendMessage(a.getString("promoted").replace("[player]", k[1]).replace("&", "§")); + } else l.sendMessage(a.getString("player-is-not-channel").replace("[player]", k[1]).replace("&", "§")); + } else l.sendMessage(a.getString("cant-promote").replace("&", "§")); + } else l.sendMessage(a.getString("dont-exist").replace("&", "§")); + } + + /* + k = args + l = CommandSender + m = channel config + n = users list + o = loop + */ + private void j(String[] k, CommandSender l) { + if ( k.length != 3 ) l.sendMessage(new Config("messages", "global").getString("badly-written").replace("&", "§")); + else if ( FileManager.listFiles(d).contains(k[2] + ".yml") ) { + Config m = new Config("channels", k[2]); + if ( m.getStringList("admins").contains(l.getName()) ) { + if ( m.getStringList("admins").contains(k[1]) ) { + List n = m.getStringList("admins"); + for ( int o = 0; o < n.size(); o++ ) { + if ( n.get(o).equals(k[1]) ) { + n.remove(o); + } + } + if ( n.size() == 0 ) { + FileManager.delete(d + j + k[2] + ".yml"); + l.sendMessage(a.getString("last-admin-delete").replace("&", "§")); + } else { + m.set("admins", n); + List admins = m.getStringList("users"); + admins.add(k[1]); + m.set("users", admins); + m.save(); + l.sendMessage(a.getString("demoted").replace("[player]", k[1]).replace("&", "§")); + } + } else l.sendMessage(a.getString("is-not-user").replace("&", "§")); + } else l.sendMessage(a.getString("cant-do-admin").replace("&", "§")); + } else l.sendMessage(a.getString("dont-exist").replace("&", "§")); + } + /* + gen var + a : new Config("messages", "channel"); // ou en général + b : new Config("config", "channel"); + c : new FileManager(); + d : channels folder + e : CommandSender + f : Command + g : args + h : new Config("messages", "global"); + i : Main + j : File Separator + + methods : + a : list + b : create + c : leave + d : join + e : permission message + f : invite + g : disband + h : kick + i : promote + j : demote + */ +} \ No newline at end of file diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Chat.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Chat.java new file mode 100644 index 0000000..351b86d --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Chat.java @@ -0,0 +1,80 @@ +package net.DeltaWings.Minecraft.ChatManager.Commands; + +import net.DeltaWings.Minecraft.ChatManager.Custom.Config; +import net.DeltaWings.Minecraft.ChatManager.Custom.FileManager; +import net.DeltaWings.Minecraft.ChatManager.Main; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.io.File; + + +public class Chat implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if(sender instanceof Player){ + Player p = (Player)sender; + if(cmd.getName().equalsIgnoreCase("chat")){ + Config messages = new Config("messages", "channel"); + Config gmsg = new Config("messages", "global"); + Config gconfig = new Config("config", "channel"); + if(p.hasPermission("chat-manager.channel.chat")){ + if(args.length >= 2){ + Config config = new Config("channels", args[0]); + if( FileManager.listFiles(Main.getInstance().getDataFolder() + File.separator + "channels").contains(args[0]+".yml")){ + StringBuilder message = new StringBuilder(); + for (int i = 1; i < args.length; i++) { + message.append(args[i]).append(" "); + } + if(config.getStringList("admins").contains(p.getName())){ + String msg = gconfig.getString("chat.format").replace("[channel]", args[0]).replace("[player]", gconfig.getString("colors.admin-name")+p.getName()).replace("[message]", gconfig.getString("colors.default")+message); + //loop players qui font parti du channel + for(Player player : Bukkit.getServer().getOnlinePlayers()) { + if(config.getStringList("admins").contains(p.getName()) || config.getStringList("users").contains(p.getName())){ + player.sendMessage(msg.replace("&", "§")); + } + } + }else if(config.getStringList("users").contains(p.getName())){ + String msg = gconfig.getString("chat.format").replace("[channel]", args[0]).replace("[player]", gconfig.getString("colors.user-name")+p.getName()).replace("[message]", gconfig.getString("colors.default")+message); + //loop players qui font parti du channel + for(Player player : Bukkit.getServer().getOnlinePlayers()) { + if(config.getStringList("admins").contains(p.getName()) || config.getStringList("users").contains(p.getName())){ + player.sendMessage(msg.replace("&", "§")); + } + } + }else{ + //message tu ne peux pas envoyer de message dans un groupe dont tu ne fais pas parti + p.sendMessage(messages.getString("cant-message").replace("&", "§")); + } + }else{ + //message le channel que tu cherche n'existe pas + p.sendMessage(messages.getString("dont-exist").replace("&","§")); + } + }else{ + p.sendMessage(gmsg.getString("badly-written").replace("&","§")); + } + }else{ + //message permission + p.sendMessage(gmsg.getString("permission").replace("&", "§")); + } + } + } + return true; + } +} +// /c +/*message : + *[channel] [player] [message] + *[message] contain base color set by config file with different by player eg : + * admin = &c + * user = &b + *[channel] is set by each channel + *[player] is the player's name with a color like + *"&f[&cadmin&f]" + *"&f[&buser&f]" + */ diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/ChatManager.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/ChatManager.java new file mode 100644 index 0000000..70b3d83 --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/ChatManager.java @@ -0,0 +1,31 @@ +package net.DeltaWings.Minecraft.ChatManager.Commands; + +import net.DeltaWings.Minecraft.ChatManager.Custom.Config; +import net.DeltaWings.Minecraft.ChatManager.Main; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class ChatManager implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender s, Command c, String l, String[] a) { + Main p = Main.getInstance(); + if (s instanceof Player) { + if (s.hasPermission("chat-manager.admin.reload")) { + p.getServer().getPluginManager().disablePlugin(p); + p.getServer().getPluginManager().enablePlugin(p); + s.sendMessage("§8[§cChat§8-§cManager§8] §fPlugin reloaded !"); + Main.log("Plugin reloaded !"); + } else { + s.sendMessage(new Config("messages", "global").getString("permission").replace("&", "§")); + } + } else { + p.getServer().getPluginManager().disablePlugin(p); + p.getServer().getPluginManager().enablePlugin(p); + Main.log("Plugin reloaded !"); + } + return true; + } +} diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Clearchat.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Clearchat.java new file mode 100644 index 0000000..01840a2 --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Clearchat.java @@ -0,0 +1,18 @@ +package net.DeltaWings.Minecraft.ChatManager.Commands; + +import net.DeltaWings.Minecraft.ChatManager.Api.API; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; + +public class Clearchat implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender s, Command c, String label, String[] a) { + if(a.length == 0) if ( s instanceof Player && s.hasPermission("chat-manager.clear-chat.global") || s instanceof ConsoleCommandSender) API.clearchat(s.getName(), null); + else if(a.length == 1) if( s instanceof Player && s.hasPermission("chat-manager.clear-chat.player") || s instanceof ConsoleCommandSender) API.clearchat(s.getName(), a[0]); + return true; + } +} \ No newline at end of file diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/LockChat.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/LockChat.java new file mode 100644 index 0000000..a630b7d --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/LockChat.java @@ -0,0 +1,20 @@ +package net.DeltaWings.Minecraft.ChatManager.Commands; + +import net.DeltaWings.Minecraft.ChatManager.Api.API; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; + +public class LockChat implements CommandExecutor { + + public boolean onCommand(CommandSender s, Command c, String t, String[] a) { + if (s instanceof Player && s.hasPermission("chat-manager.lockchat.lock") || s instanceof ConsoleCommandSender) API.lockchat(); + else s.sendMessage("perms usage"); //permission message + return true; + } + + +} diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Mute.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Mute.java new file mode 100644 index 0000000..85684a1 --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Mute.java @@ -0,0 +1,41 @@ +package net.DeltaWings.Minecraft.ChatManager.Commands; + +import net.DeltaWings.Minecraft.ChatManager.Api.API; +import net.DeltaWings.Minecraft.ChatManager.Custom.Config; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; + +public class Mute implements CommandExecutor { + @Override + public boolean onCommand(CommandSender s, Command c, String jk, String[] a) { + if(s instanceof Player && s.hasPermission("chat-manager.mute.chat") || s instanceof ConsoleCommandSender) { + Player l = null; + Boolean f = false; + for(Player p : Bukkit.getServer().getOnlinePlayers()) { + if(a.length > 0)if(p.getName().equalsIgnoreCase(a[0])) { + l = p; + f = true; + } + } + if(!f) s.sendMessage(new Config("messages", "mute").getString("player.not-found").replace("&", "§")); + else if(a.length >= 3) { + StringBuilder m = new StringBuilder(); + for ( Integer y = 2; a.length > y; y++ ) m.append(a[y]).append(" "); + API.mute(s, l, Integer.parseInt(a[1]), "chat", m.toString()); + } + else if(a.length == 2) API.mute(s, l, Integer.parseInt(a[1]), "chat", new Config("config", "mute").getString("default-reason")); + else if(a.length == 1) API.mute(s, l, -1, "chat", new Config("config", "mute").getString("default-reason")); + else s.sendMessage(new Config("messages", "global").getString("badly-written").replace("&", "§")); + + } else { + s.sendMessage("perm usage"); + } + return false; + } +} +// /mute Aviortheking [time] [reason] diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Mutelist.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Mutelist.java new file mode 100644 index 0000000..495c80b --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Mutelist.java @@ -0,0 +1,27 @@ +package net.DeltaWings.Minecraft.ChatManager.Commands; + +import net.DeltaWings.Minecraft.ChatManager.Api.API; +import net.DeltaWings.Minecraft.ChatManager.Custom.Config; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; + +import java.util.List; + +public class Mutelist implements CommandExecutor { + @Override + public boolean onCommand(CommandSender s, Command command, String label, String[] args) { + if(s instanceof Player && s.hasPermission("chat-manager.mute.list") || s instanceof ConsoleCommandSender) { + List l = API.mutedlist(); + Config m = new Config("messages", "mute"); + s.sendMessage(m.getString("mutelist.top").replace("&", "§")); + for(String[] a : l) { + s.sendMessage(m.getString("mutelist.object").replace("[player]", a[0]).replace("[time]", a[1]).replace("[reason]", a[2]).replace("&", "§")); + } + s.sendMessage(m.getString("mutelist.bottom").replace("&", "§")); + } + return false; + } +} diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/StaffChat.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/StaffChat.java new file mode 100644 index 0000000..6ace558 --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/StaffChat.java @@ -0,0 +1,48 @@ +package net.DeltaWings.Minecraft.ChatManager.Commands; + +import net.DeltaWings.Minecraft.ChatManager.Custom.Config; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import net.DeltaWings.Minecraft.ChatManager.Main; + +public class StaffChat implements CommandExecutor { + + private final Main m = Main.getInstance(); + + @Override + public boolean onCommand(CommandSender s, Command c, String l, String[] a) { + if(c.getName().equalsIgnoreCase("staffchat")) { + if(s instanceof Player) { + if(s.hasPermission("chat-manager.staff-chat.send")) sendMessage(a, s.getName()); + else s.sendMessage(new Config("messages", "global").getString("permission").replace("&", "§")); + } else sendMessage(a, "Console"); + } + return true; + } + + private void sendMessage(String[] a, String s) { + StringBuilder z = new StringBuilder(); + for (String r : a) { + z.append(r).append(" "); + } + for(Player p : Bukkit.getServer().getOnlinePlayers()) { + if(p.hasPermission("chat-manager.staff-chat.read")){ + m.makeDefaultPlayerFile(p); + if(new Config("players", p.getName()).getBoolean("switch")){ + Config g = new Config("config", "staffchat"); + p.sendMessage(g.getString("chat.format").replace("[player]", g.getString("colors.player")+s).replace("[message]", g.getString("colors.default")+z).replace("&", "§")); + } + } + } + } +} + +/* + * Permissions : + * Staff chat read : chat-manager.staff-chat.read + * Staff chat send : chat-manager.staff-chat.send + */ \ No newline at end of file diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/StaffSwitch.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/StaffSwitch.java new file mode 100644 index 0000000..6646f06 --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/StaffSwitch.java @@ -0,0 +1,50 @@ +package net.DeltaWings.Minecraft.ChatManager.Commands; + +import net.DeltaWings.Minecraft.ChatManager.Custom.Config; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class StaffSwitch implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if(sender instanceof Player){ + Player p = (Player)sender; + if(cmd.getName().equalsIgnoreCase("staffswitch")){ + Config gmessage = new Config("messages", "global"); + Config smessage = new Config("messages", "switch"); + if(p.hasPermission("chat-manager.staff-chat.switch")){ + Config player = new Config("players", p.getName()); + if(player.exist()){ + if(player.getBoolean("switch")){ + player.set("switch", false); + player.save(); + p.sendMessage(smessage.getString("switch").replace("[state]", "False").replace("&", "§")); + }else{ + player.set("switch", true); + player.save(); + p.sendMessage(smessage.getString("switch").replace("[state]", "True").replace("&", "§")); + } + }else{ + //basic + player.create(); + player.set("invite"); + //end basic + player.set("switch", false); + player.save(); + p.sendMessage(smessage.getString("switch").replace("[state]", "False").replace("&", "§")); + } + }else{ + p.sendMessage(gmessage.getString("permission").replace("&", "§")); + } + } + } + return true; + } + +} + +// /staffswitch \ No newline at end of file diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Unmute.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Unmute.java new file mode 100644 index 0000000..c54d1a6 --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Commands/Unmute.java @@ -0,0 +1,32 @@ +package net.DeltaWings.Minecraft.ChatManager.Commands; + +import net.DeltaWings.Minecraft.ChatManager.Api.API; +import net.DeltaWings.Minecraft.ChatManager.Custom.Config; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; + +public class Unmute implements CommandExecutor { + @Override + public boolean onCommand(CommandSender s, Command command, String label, String[] a) { + if(s instanceof Player && s.hasPermission("chat-manager.unmute.chat") || s instanceof ConsoleCommandSender) { + Player l = null; + Boolean f = false; + for(Player p : Bukkit.getServer().getOnlinePlayers()) { + if(a.length > 0)if(p.getName().equalsIgnoreCase(a[0])) { + l = p; + f = true; + } + } + if(!f) s.sendMessage(new Config("messages", "mute").getString("player.not-found").replace("&", "§")); + else API.unmute(s, l, "chat"); + } + return false; + } +} + +//unmute \ No newline at end of file diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Custom/Config.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Custom/Config.java new file mode 100644 index 0000000..fd9a1d0 --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Custom/Config.java @@ -0,0 +1,118 @@ +package net.DeltaWings.Minecraft.ChatManager.Custom; + +import net.DeltaWings.Minecraft.ChatManager.Main; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class Config { + private final FileConfiguration config; + private final File root = Main.getInstance().getDataFolder(); + private final File folder; + private final File file; + private final FileManager fm = new FileManager(); + + public Config(String folder, String file) { + this.folder = new File(folder); + this.file = new File(root.toString() + File.separator + this.folder.toString() + File.separator + file + ".yml"); + config = YamlConfiguration.loadConfiguration(this.file); + } + + public Boolean exist() { + return file.exists(); + } + + public void set(String path, Object value) { + config.set(path, value); + } + + public void set(String path) { + config.createSection(path); + } + + public void header(String header) { + config.options().header(header); + } + + public int getInt(String path, Integer def) { + return config.getInt(path, def); + } + + public int getInt(String path) { + return config.getInt(path); + } + + public Double getDouble(String path, Double def) { + return config.getDouble(path, def); + } + + public Double getDouble(String path) { + return config.getDouble(path); + } + + public String getString(String path, String def) { + return config.getString(path, def); + } + + public String getString(String path) { + return config.getString(path); + } + + public Long getLong(String path) { + return config.getLong(path); + } + + public Long getLong(String path, Long def) { + return config.getLong(path, def); + } + + public void save() { + try { + config.save(file); + } catch ( IOException e ) { + e.printStackTrace(); + } + } + + public ArrayList getSection(String path) { + return new ArrayList<>(config.getConfigurationSection(path).getKeys(false)); + } + + public List getStringList(String path) { + return config.getStringList(path); + } + + public void create() { + if(!exist()) { + if(!root.exists()) root.mkdirs(); + File rfolder = new File(root.toString() + File.separator + folder.toString()); + if(!rfolder.exists()) rfolder.mkdirs(); + try { + file.createNewFile(); + } catch ( IOException e ) { + e.printStackTrace(); + } + } + } + + public boolean isSet(String path) { + return config.isSet(path); + } + + public boolean getBoolean(String path, Boolean def) { + return config.getBoolean(path, def); + } + + public boolean getBoolean(String path) { + return config.getBoolean(path); + } + + public void delete() { + FileManager.delete(file); + } +} \ No newline at end of file diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Custom/Custom.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Custom/Custom.java new file mode 100644 index 0000000..de8ea98 --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Custom/Custom.java @@ -0,0 +1,15 @@ +package net.DeltaWings.Minecraft.ChatManager.Custom; + +public class Custom { + public static boolean isInteger(String s) { + if (s.isEmpty()) return false; + for (int i = 0; i < s.length(); i++) { + if (i == 0 && s.charAt(i) == '-') { + if (s.length() == 1) return false; + else continue; + } + if (Character.digit(s.charAt(i), 10) < 0) return false; + } + return true; + } +} diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Custom/FileManager.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Custom/FileManager.java new file mode 100644 index 0000000..3c92183 --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Custom/FileManager.java @@ -0,0 +1,89 @@ +package net.DeltaWings.Minecraft.ChatManager.Custom; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +public class FileManager { + + + public static List listFiles(String path) { + String[] t = new File(path).list(); + if(t == null) return new ArrayList<>(); + else return Arrays.asList(t); + } + + public static List listFiles(File path) { + String[] t = path.list(); + if(t == null) return new ArrayList<>(); + else return Arrays.asList(t); + } + + public static void delete(File path) { + path.delete(); + } + + public static void delete(String path) { + File f = new File(path); + f.delete(); + } + + public static void createFile(String path) { + try { + new File(path).createNewFile(); + } catch ( IOException e ) { + e.printStackTrace(); + } + } + + public static void createFile(File path) { + try { + path.createNewFile(); + } catch ( IOException e ) { + e.printStackTrace(); + } + } + + public static void createFolder(File path) { + path.mkdirs(); + } + + public static void createFolder(String path) { + new File(path).mkdirs(); + } + + public static void archive(String srcFolder, String destZipFile) { + try { + FileOutputStream f = new FileOutputStream(destZipFile); + ZipOutputStream z = new ZipOutputStream(f); + b(srcFolder, z); + z.close(); + } catch ( Exception e ) { + e.printStackTrace(); + } + } + + private static void a(String p, String s, ZipOutputStream z) throws Exception { + File f = new File(s); + if (f.isDirectory()) b(s, z); + else { + byte[] b = new byte[1024]; + int l; + FileInputStream i = new FileInputStream(s); + z.putNextEntry(new ZipEntry(p + "/" + f.getName())); + while ((l = i.read(b)) > 0) z.write(b, 0, l); + } + } + + private static void b(String s, ZipOutputStream z) throws Exception { + File f = new File(s); + String[] l = f.list(); + if(l != null) for (String n : l) a(f.getName(), s + File.separator + n, z); + } +} \ No newline at end of file diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Custom/Notifier.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Custom/Notifier.java new file mode 100644 index 0000000..9869570 --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Custom/Notifier.java @@ -0,0 +1,42 @@ +package net.DeltaWings.Minecraft.ChatManager.Custom; + +import net.DeltaWings.Minecraft.ChatManager.Main; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; + +public class Notifier { + + public Notifier(Integer r, String b) { + Bukkit.getScheduler().scheduleSyncDelayedTask( Main.getInstance(), () -> { + try { + HttpURLConnection c = (HttpURLConnection) new URL("http://www.spigotmc.org/api/general.php").openConnection(); + c.setDoOutput(true); + c.setRequestMethod("POST"); + try (OutputStream o = c.getOutputStream()) { + o.write(("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=" + r).getBytes("UTF-8")); + } + String v; + try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(c.getInputStream()))) { + v = bufferedReader.readLine(); + } + if (v.equalsIgnoreCase(b)) Main.log("No new Version version available ! Thanks for using our plugin."); + else { + Main.log("New version available ! Version : " + v); + for (Player p : Bukkit.getServer().getOnlinePlayers()) if (p.hasPermission("chat-manager.admin.notification")) p.sendMessage("§8[§cChat§8-§cManager§8]§f New version available ! Version : " + v); + } + } catch (Exception e) { + Main.log(e.getMessage()); + Main.log(""); + Main.log("Please contact the developper and give him the code before."); + for(Player p : Bukkit.getServer().getOnlinePlayers()) if(p.hasPermission("chat-manager.admin.notification")) p.sendMessage("§8[§cChat§8-§cManager§8]§f Error while trying to check for updates ! Please look at the console for more informations."); + } + }, 0L); + } +} \ No newline at end of file diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Listeners/ChatListener.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Listeners/ChatListener.java new file mode 100644 index 0000000..18560ba --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Listeners/ChatListener.java @@ -0,0 +1,159 @@ +package net.DeltaWings.Minecraft.ChatManager.Listeners; + +import net.DeltaWings.Minecraft.ChatManager.Api.API; +import net.DeltaWings.Minecraft.ChatManager.Custom.Config; +import net.DeltaWings.Minecraft.ChatManager.Custom.Custom; +import net.DeltaWings.Minecraft.ChatManager.Main; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; + +import java.util.ArrayList; + +public class ChatListener implements Listener { + + private Integer d = 0, e = 0, r = 0, g = -1; + private Config gconfig = new Config("config", "global"); + + + @EventHandler(priority = EventPriority.HIGH) + public void AsyncPlayerChat(AsyncPlayerChatEvent e){ + e.setCancelled(true); + Config p = new Config("players", e.getPlayer().getName()); + //Calculator + if(e.getMessage().split("")[0].equalsIgnoreCase("=")) calculator(e); + //Muted Player + else if(p.getBoolean("mute.chat", false)) { + if(p.getInt("mute.from") == -1 || p.getLong("mute.time") > System.currentTimeMillis()) { + e.getPlayer().sendMessage(new Config("messages", "mute").getString("muted.self").replace("[reason]", p.getString("mute.reason")).replace("&", "§")); + } + else { + p.set("mute.chat", false); + p.save(); + } + } + //Locked chat + if(API.isChatLocked() && !p.getBoolean("mute.chat", false) && !(e.getMessage().split("")[0].equalsIgnoreCase("="))) { + Config lockchat = new Config("messages", "lockchat"); + if(e.getPlayer().hasPermission("chat-manager.lockchat.ignore")) { + e.getPlayer().sendMessage(lockchat.getString("ignored").replace("&", "§")); + sendMessage(e.getPlayer(), e.getMessage()); + } else e.getPlayer().sendMessage(lockchat.getString("locked").replace("&", "§")); + //Send Message + } else if(!p.getBoolean("mute.chat", false) && !(e.getMessage().split("")[0].equalsIgnoreCase("="))) sendMessage(e.getPlayer(), e.getMessage()); + } + /* + Calculator + */ + private void calculator(AsyncPlayerChatEvent g) { + String a = g.getMessage(); + StringBuilder f = new StringBuilder(); + for ( String b : a.split(" ") ) { + Integer l = -1; + for ( String q : b.split("") ) { + if ( Custom.isInteger(q) ) { + if ( l == -1 || l == 1 ) l = 1; + else { + l = 1; + f.append(" "); + } + } else { + if ( l == -1 || l == 0 ) l = 0; + else { + l = 0; + f.append(" "); + } + } + f.append(q); + } + f.append(" "); + } + String[] c = f.toString().split(" "); + if ( c[0].equalsIgnoreCase("=") ) start(c, g.getPlayer()); + } + + private void start(String[] b, Player p) { + r = 0; + if (b[0].equalsIgnoreCase("=")) { + for (String c : b) { + if (c.equalsIgnoreCase("+")) g = 0; + else if (c.equalsIgnoreCase("-")) g = 1; + else if (c.equalsIgnoreCase("*") || c.equalsIgnoreCase("x")) g = 2; + else if (c.equalsIgnoreCase("/")) g = 3; + if (Custom.isInteger(c)) { + if (g != -1) { + e = Integer.parseInt(c); + calc(g); + g = -1; + } else d = Integer.parseInt(c); + } + } + p.sendMessage("[Result] "+ r); + } + } + + private void calc(Integer g) { + if (g == 0) r += d + e; + else if (g == 1) r += d - e; + else if (g == 2) { + if(d != 0) r += d * e; + else r*= e; + } + else if (g == 3) { + if(d != 0) r += d / e; + else r /= e; + } + d = 0; + e = 0; + } + /* + End Calculator + */ + + private void sendMessage(Player p, String msg) { + Config config = new Config("config", "prefix"); + ArrayList plist = config.getSection("prefix"); + String prefix = ""; + + if(!plist.isEmpty()) for ( String a : plist ) if ( p.hasPermission("chat-manager.chat.prefix." + a) ) prefix = config.getString("prefix." + a); + + ArrayList slist = config.getSection("suffix"); + String suffix = ""; + + if(!slist.isEmpty()) for ( String a : slist ) if ( p.hasPermission("chat-manager.chat.suffix." + a) ) suffix = config.getString("suffix." + a); + + ArrayList nlist = config.getSection("name-color"); + String namecolor = "&f"; + if(!nlist.isEmpty()) for ( String a : nlist ) if ( p.hasPermission("chat-manager.chat.color." + a) ) namecolor = config.getString("name-color." + a); + + + if(!nlist.isEmpty()) for ( String a : nlist ) if ( p.hasPermission("chat-manager.chat.name-color." + a) ) namecolor = config.getString("name-color." + a); + + if(!p.hasPermission("chat-manager.chat.colors")) msg = msg.replaceAll("&([0-9a-f])", ""); + + msg = "&f" + msg + "&f"; + String res = gconfig.getString("format.chat"); + res = res.replace("[prefix]", prefix).replace("[player]", namecolor+p.getName()).replace("[suffix]", suffix); + Main.log(res.replace("[message]", msg)); + API.logMessage(res.replace("[message]", msg)); + for(Player pl : Bukkit.getServer().getOnlinePlayers()) { + String temp; + if(gconfig.getBoolean("name.enabled") && msg.contains(pl.getName())) temp = res.replace("[message]", msg.replace(pl.getName(), (gconfig.getString("name.color") + pl.getName() + "&f"))); + else temp = res.replace("[message]", msg); + pl.sendMessage(temp.replace("&", "§")); + } + } +} + +/* +permissions : +colors in chat : chat-manager.chat.colors +name in certain color : chat-manager.chat.name-color.NAME +prefix : chat-manager.chat.prefix.NAME +suffix : chat-manager.chat.suffix.NAME +lockchat ignore : chat-manager.lock-chat.ignore + */ \ No newline at end of file diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Listeners/DeathListener.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Listeners/DeathListener.java new file mode 100644 index 0000000..c925c9d --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Listeners/DeathListener.java @@ -0,0 +1,31 @@ +package net.DeltaWings.Minecraft.ChatManager.Listeners; + +import net.DeltaWings.Minecraft.ChatManager.Api.API; +import net.DeltaWings.Minecraft.ChatManager.Custom.Config; + +import java.util.HashMap; + +import org.bukkit.entity.Entity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; + +public class DeathListener implements Listener { + + @EventHandler + public void onPlayerDeath(PlayerDeathEvent e) { + if(new Config("config", "events").getBoolean("enabled.death", true)) { + Config msg = new Config("messages", "events"); + + e.getEntity().getLastDamageCause(); + DamageCause cause = e.getEntity().getLastDamageCause().getCause(); + Entity killer = e.getEntity().getKiller(); + HashMap replacements = new HashMap<>(); + replacements.put("[player]", e.getEntity().getName()); + if(killer != null) replacements.put("[killer]", killer.getName()); + replacements.put("[item]", e.getEntity().getDisplayName().replace("&", "§")); + e.setDeathMessage(API.multiReplace(msg.getString("death.causes."+cause.toString().toLowerCase()), replacements)); + } + } +} diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Listeners/PlayerLoginLogoutListener.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Listeners/PlayerLoginLogoutListener.java new file mode 100644 index 0000000..e0020a9 --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Listeners/PlayerLoginLogoutListener.java @@ -0,0 +1,28 @@ +package net.DeltaWings.Minecraft.ChatManager.Listeners; + +import net.DeltaWings.Minecraft.ChatManager.Api.API; +import net.DeltaWings.Minecraft.ChatManager.Custom.Config; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerLoginLogoutListener implements Listener { + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent e) { + Config joinleave = new Config("config", "events"); + if(joinleave.getBoolean("enabled.join", true)) e.setJoinMessage(new Config("messages", "events").getString("join").replace("[player]", e.getPlayer().getName()).replace("&", "§")); + else e.setJoinMessage(null); + if(joinleave.getBoolean("enabled.motd", false)) for(String line : new Config("messages", "joinleave").getStringList("motd")) e.getPlayer().sendMessage(line.replace("&", "§")); + if (API.isChatLocked()) e.getPlayer().sendMessage(new Config("messages", "lockchat").getString("locked").replace("&", "§")); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent e) { + if(new Config("config", "events").getBoolean("enabled.leave", true)) e.setQuitMessage(new Config("messages", "events").getString("leave").replace("[player]", e.getPlayer().getName()).replace("&", "§")); + else e.setQuitMessage(null); + } + +} diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Main.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Main.java new file mode 100644 index 0000000..4b13a1a --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Main.java @@ -0,0 +1,352 @@ +package net.DeltaWings.Minecraft.ChatManager; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import net.DeltaWings.Minecraft.ChatManager.Commands.*; +import net.DeltaWings.Minecraft.ChatManager.Custom.*; +import net.DeltaWings.Minecraft.ChatManager.Listeners.*; +import net.DeltaWings.Minecraft.ChatManager.Scheduler.Scheduler; + +import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + + +public class Main extends JavaPlugin { + + private static Main instance; + private PluginDescriptionFile desc; + + public static void log(String message) { + Main.getInstance().getLogger().info(message); + } + + public static void debug(String message) { + if(new Config("config", "global").getBoolean("debug", false))Main.getInstance().getLogger().info("[Debug] " + message); + } + + public static void error(String message) { + Main.getInstance().getLogger().severe(message); + } + + + public static Main getInstance() { + return instance; + } + + @Override + public void onEnable() { + desc = getDescription(); + instance = this; + PluginManager pm = getServer().getPluginManager(); + //Commands + getCommand("StaffChat").setExecutor(new StaffChat()); + getCommand("StaffSwitch").setExecutor(new StaffSwitch()); + getCommand("Channel").setExecutor(new Channel()); + getCommand("Chat").setExecutor(new Chat()); + getCommand("Broadcast").setExecutor(new Broadcast()); + getCommand("Clearchat").setExecutor(new Clearchat()); + getCommand("Chat-Manager").setExecutor(new ChatManager()); + getCommand("LockChat").setExecutor(new LockChat()); + getCommand("Mute").setExecutor(new Mute()); + getCommand("Unmute").setExecutor(new Unmute()); + getCommand("Mutelist").setExecutor(new Mutelist()); + + //Listeners + pm.registerEvents(new PlayerLoginLogoutListener(), this); + pm.registerEvents(new ChatListener(), this); + pm.registerEvents(new DeathListener(), this); + + //make config files + genconfig(); + + //Start Schedulers + new Scheduler(); + + //new Notifier(25929, desc.getVersion()); + //Metrics + Metrics metrics = new Metrics(this); + metrics.addCustomChart(new Metrics.SimplePie("auto_broadcast") { + @Override + public String getValue() { + return ""+new Config("config", "broadcast").getBoolean("auto-broadcast.enabled", false); + } + }); + + metrics.addCustomChart(new Metrics.SimplePie("auto_clearchat") { + @Override + public String getValue() { + return ""+new Config("config", "clearchat").getBoolean("auto-clear-chat.enabled", false); + } + }); + + metrics.addCustomChart(new Metrics.SingleLineChart("muted_players") { + @Override + public int getValue() { + Integer r = 0; + try { + List files = FileManager.listFiles(new File(getDataFolder() + File.separator + "players")); + for(String file : files) { + if(new Config("players", file.replace(".yml", "")).getBoolean("mute.chat")) r++; + } + } catch ( Exception e ) { + e.printStackTrace(); + } + + return r; + } + }); + metrics.addCustomChart(new Metrics.SimplePie("name_customization") { + @Override + public String getValue() { + return new Config("config", "global").getBoolean("name.enabled", false) + ""; + } + }); + + log("Successfully enabled"); + } + + private void genconfig() { + Config c; + c = new Config("config", "global"); + Boolean ver = !c.getString("version", "0.0.0").equalsIgnoreCase(desc.getVersion()); + if(ver) { + log("Because it's a new update we will now archive all your configuration and generate a new one."); + log("Before repasting into the new files check the changelogs to see what files have changed !"); + FileManager.archive(Main.getInstance().getDataFolder().toString(), Main.getInstance().getDataFolder().toString() + File.separator + "Backup-" + c.getString("version", "unknown") + ".zip"); + } + + if(!c.exist() || ver) { + c.delete(); + c.create(); + c.header("Please don't touch the version or you will break some functions"); + c.set("debug", false); + c.set("format.chat", "[prefix] [player] [suffix] > [message]"); + c.set("name.enabled", true); + c.set("name.color", "&9&o"); + c.set("version", desc.getVersion()); + c.save(); + } + + c = new Config("config", "prefix"); + if(!c.exist() || ver) { + c.delete(); + c.create(); + c.header("More infos on https://gitlab.com/Delta-Wings/Chat-Manager/snippets/1574373"); + c.set("prefix"); + c.set("suffix"); + c.set("name-color"); + c.save(); + } + + c = new Config("messages", "lockchat"); + if(!c.exist() || ver) { + c.delete(); + c.create(); + c.header("[state] stand for chat state (locked for locked chat, unlocked for unlocked chat)"); + c.set("locked", "&8 >&c The chat is locked !"); + c.set("unlocked", "&8 >&c The chat has been unlocked !"); + c.set("ignored", "&8 >&c The chat is locked but you can speak !"); + c.set("already", "&8 >&c Chat is already [state] !"); + c.save(); + } + + c = new Config("messages", "channel"); + if(!c.exist() || ver) { + c.delete(); + c.create(); + c.set("dont-exist", "&8 >&c The channel don't exist"); + c.set("list-start", "&8 >&f Channels list(&bBlue&f = user &cRed&f = Admin"); + c.set("list-end", "&8 >&c End"); + c.set("already-exist", "&8 >&c There is already a channel named \"[channel]\""); + c.set("channel-created", "&8 >&c The channel has been created !"); + c.set("one-word-channel", "&8 >&c Your channel name must be one word"); + c.set("no-chanel-name", "&8 >&c You need to tell the channel name !"); + c.set("deleted-from-channel", "&8 >&c You have been deleted from the channel"); + c.set("last-admin-delete", "&8 >&c Because you were the last admin. The channel has been deleted too"); + c.set("channel-joined", "&8 >&c You have successfully joined the channel !"); + c.set("cant-join", "&8 >&c You can't join this channel"); + c.set("already-in", "&8 >&c You are already in this channel"); + c.set("no-channel-name", "&8 >&c There is no channels with this name"); + c.set("you-invited", "&8 >&c You have successfully invited [player]"); + c.set("channel-disbanded", "&8 >&c You have successfully disbanded the channel"); + c.set("cant-disband", "&8 >&c You can't disband this channel because you are not an admin of this channel"); + c.set("cant-kick-admin", "&8 >&c You can't kick an other admin"); + c.set("kicked", "&8 >&c [player] has been kicked from the channel"); + c.set("not-in-your-channel", "&8 >&c [player] is not on your channel"); + c.set("cant-do-if-not-admin", "&8 >&c You can't do that's if you aren't a channel admin"); + c.set("promoted", "&8 >&c [player] have been promoted"); + c.set("player-is-not-channel", "&8 >&c [player] is not in the channel"); + c.set("cant-promoted", "&8 >&c You can only promote if you are an admin of a channel"); + c.set("demoted", "&8 >&c [player] have been demoted"); + c.set("is-not-user", "&8 >&c the player is not an admin of this channel"); + c.set("cant-message", "&8 >&c You can't send messages in this channel"); + c.set("not-in-channel", "&8 > &c You aren't in this channel"); + c.set("invited", "&8 >&c You have been invited in the channel : [channel]"); + c.set("one-word-channel", "&8 >&c You have misspelled the channel name !"); + c.set("console-cant", "The Console can't do this command !"); + c.set("not-a-user", "&8 >&c You aren't a user of this channel"); + c.save(); + } + + c = new Config("config", "channel"); + if(!c.exist() || ver) { + c.delete(); + c.create(); + c.set("colors.admin-name", "&c"); + c.set("colors.user-name", "&b"); + c.set("colors.default", "&f"); + c.set("chat.format", "[channel] [player] [message]"); + c.save(); + } + + c = new Config("messages", "global"); + if(!c.exist()) { + c.create(); + c.set("permission", "&8 >&c You don't have the permission to do that !"); + c.set("badly-written", "&8 >&c You have badly written somethings"); + c.set("not-online", "&8 > &c The player isn't online"); + c.save(); + } + + c = new Config("messages", "switch"); + if(!c.exist() || ver) { + c.create(); + c.set("switch", "&8 >&c You have changed your receive setting to \"[state]\""); + c.save(); + } + + Config sconf = new Config("messages", "staffchat"); + if(!sconf.exist() || ver) { + sconf.create(); + sconf.set("no-message", "&8 >&c You have to put a message after the command"); + sconf.save(); + } + + c = new Config("config", "staffchat"); + if(!c.exist() || ver) { + c.create(); + c.set("colors.player", "&c"); + c.set("colors.default", "&f"); + c.set("chat.format", "&8[&cStaffchat&8] [player] [message]"); + c.save(); + } + + c = new Config("config", "lockchat"); + if(!c.exist() || ver) { + c.create(); + c.set("locked", "The chat is now locked"); + c.set("unlocked", "The chat is now unlocked"); + c.save(); + } + + c = new Config("config", "clearchat"); + if(!c.exist() || ver) { + c.delete(); + c.create(); + c.header("Time in minutes"); + c.set("lines-to-clear", 200); + c.set("auto-clear-chat.enabled", true); + c.set("auto-clear-chat.time", 30); + c.save(); + } + + c = new Config("messages", "clearchat"); + if(!c.exist() || ver) { + c.delete(); + c.create(); + c.set("clear", "&8 >&c Your chat has been cleared by [cleaner]"); + c.save(); + } + + c = new Config("config", "broadcast"); + if(!c.exist() || ver) { + c.delete(); + c.create(); + c.set("format", " [player]&8 > &c[message]"); + c.set("auto-broadcast.enabled", true); + List t = new ArrayList<>(); + t.add("&cWelcome new players !"); + c.set("auto-broadcast.messages", t); + c.set("auto-broadcast.time", 10); + c.save(); + } + + c = new Config("config", "mute"); + if(!c.exist() || ver) { + c.delete(); + c.create(); + c.set("enabled", true); + c.set("default-reason", "You did something bad !"); + c.save(); + } + + c = new Config("messages", "mute"); + if(!c.exist() || ver) { + c.delete(); + c.create(); + c.set("muted.self", "You are muted ! Reason : [reason]"); + c.set("muted.other", "&8 >&c You have muted [player] with the reason [reason]"); + c.set("unmutted.self", "&8 >&c You have been unmutted"); + c.set("unmutted.other", "&8 >&c You have unmutted [player]"); + c.set("already-muted", "&8 >&c The player is already muted"); + c.set("player.not-found", "&8 >&c The player has not been found !"); + c.set("mutelist.top", "&8 >&c Mutelist&8 <"); + c.set("mutelist.object", "&c[player] &b[time] &areason : [reason]"); + c.set("mutelist.bottom", "&8 >&c Mutelist&8 <"); + c.save(); + } + + c = new Config("config", "events"); + if(!c.exist() || ver) { + c.delete(); + c.create(); + c.set("enabled.join", true); + c.set("enabled.death", true); + c.set("enabled.motd", true); + c.set("enabled.leave", true); + c.save(); + } + + c = new Config("messages", "events"); + if(!c.exist() || ver) { + c.delete(); + c.create(); + c.set("join", "&bWelcome [player] !"); + c.set("leave", "&cGoodbye [player] ! I'll miss you !"); + c.set("death.player", "&9[player] was killed from [killer] using [item]"); + c.set("death.mob", "&9 ahah ! [player] was killed from [mob]"); + List t = new ArrayList<>(); + t.add("Yo"); + t.add("gg"); + c.set("motd", t); + + c.save(); + } + + /* + c = new Config("messages", "joinleave"); + if(!c.exist() || ver) { + c.delete(); + c.create(); + c.save(); + } + */ + + } + + public void makeDefaultPlayerFile(Player p) { + Config c = new Config("players", p.getName()); + if(!c.exist()) { + c.create(); + c.set("switch", true); + c.set("invite"); + c.set("mute.chat", false); + c.set("mute.cmd", false); + c.save(); + } + } +} \ No newline at end of file diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Metrics.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Metrics.java new file mode 100644 index 0000000..e3a0c06 --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Metrics.java @@ -0,0 +1,1021 @@ +package net.DeltaWings.Minecraft.ChatManager; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.ServicePriority; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; + +import javax.net.ssl.HttpsURLConnection; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; +import java.util.UUID; +import java.util.logging.Level; +import java.util.zip.GZIPOutputStream; + +public class Metrics { + + static { + // Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D + final String defaultPackage = new String(new byte[] { 'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's' }); + final String examplePackage = new String(new byte[] { 'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e' }); + // We want to make sure nobody just copy & pastes the example and use the wrong package names + if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) { + throw new IllegalStateException("bStats Metrics class has not been relocated correctly!"); + } + } + + // The version of this bStats class + public static final int B_STATS_VERSION = 1; + + // The url to which the data is sent + private static final String URL = "https://bStats.org/submitData/bukkit"; + + // Should failed requests be logged? + private static boolean logFailedRequests; + + // The uuid of the server + private static String serverUUID; + + // The plugin + private final JavaPlugin plugin; + + // A list with all custom charts + private final List charts = new ArrayList<>(); + + /** + * Class constructor. + * + * @param plugin The plugin which stats should be submitted. + */ + public Metrics(JavaPlugin plugin) { + if (plugin == null) { + throw new IllegalArgumentException("Plugin cannot be null!"); + } + this.plugin = plugin; + + // Get the config file + File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats"); + File configFile = new File(bStatsFolder, "config.yml"); + YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); + + // Check if the config file exists + if (!config.isSet("serverUuid")) { + + // Add default values + config.addDefault("enabled", true); + // Every server gets it's unique random id. + config.addDefault("serverUuid", UUID.randomUUID().toString()); + // Should failed request be logged? + config.addDefault("logFailedRequests", false); + + // Inform the server owners about bStats + config.options().header( + "bStats collects some data for plugin authors like how many servers are using their plugins.\n" + + "To honor their work, you should not disable it.\n" + + "This has nearly no effect on the server performance!\n" + + "Check out https://bStats.org/ to learn more :)" + ).copyDefaults(true); + try { + config.save(configFile); + } catch (IOException ignored) { } + } + + // Load the data + serverUUID = config.getString("serverUuid"); + logFailedRequests = config.getBoolean("logFailedRequests", false); + if (config.getBoolean("enabled", true)) { + boolean found = false; + // Search for all other bStats Metrics classes to see if we are the first one + for (Class service : Bukkit.getServicesManager().getKnownServices()) { + try { + service.getField("B_STATS_VERSION"); // Our identifier :) + found = true; // We aren't the first + break; + } catch (NoSuchFieldException ignored) { } + } + // Register our service + Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal); + if (!found) { + // We are the first! + startSubmitting(); + } + } + } + + /** + * Adds a custom chart. + * + * @param chart The chart to add. + */ + public void addCustomChart(CustomChart chart) { + if (chart == null) { + throw new IllegalArgumentException("Chart cannot be null!"); + } + charts.add(chart); + } + + /** + * Starts the Scheduler which submits our data every 30 minutes. + */ + private void startSubmitting() { + final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags + timer.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + if (!plugin.isEnabled()) { // Plugin was disabled + timer.cancel(); + return; + } + // Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler + // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;) + Bukkit.getScheduler().runTask(plugin, new Runnable() { + @Override + public void run() { + submitData(); + } + }); + } + }, 1000*60*5, 1000*60*30); + // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start + // WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted! + // WARNING: Just don't do it! + } + + /** + * Gets the plugin specific data. + * This method is called using Reflection. + * + * @return The plugin specific data. + */ + public JSONObject getPluginData() { + JSONObject data = new JSONObject(); + + String pluginName = plugin.getDescription().getName(); + String pluginVersion = plugin.getDescription().getVersion(); + + data.put("pluginName", pluginName); // Append the name of the plugin + data.put("pluginVersion", pluginVersion); // Append the version of the plugin + JSONArray customCharts = new JSONArray(); + for (CustomChart customChart : charts) { + // Add the data of the custom charts + JSONObject chart = customChart.getRequestJsonObject(); + if (chart == null) { // If the chart is null, we skip it + continue; + } + customCharts.add(chart); + } + data.put("customCharts", customCharts); + + return data; + } + + /** + * Gets the server specific data. + * + * @return The server specific data. + */ + private JSONObject getServerData() { + // Minecraft specific data + int playerAmount = Bukkit.getOnlinePlayers().size(); + int onlineMode = Bukkit.getOnlineMode() ? 1 : 0; + String bukkitVersion = org.bukkit.Bukkit.getVersion(); + bukkitVersion = bukkitVersion.substring(bukkitVersion.indexOf("MC: ") + 4, bukkitVersion.length() - 1); + + // OS/Java specific data + String javaVersion = System.getProperty("java.version"); + String osName = System.getProperty("os.name"); + String osArch = System.getProperty("os.arch"); + String osVersion = System.getProperty("os.version"); + int coreCount = Runtime.getRuntime().availableProcessors(); + + JSONObject data = new JSONObject(); + + data.put("serverUUID", serverUUID); + + data.put("playerAmount", playerAmount); + data.put("onlineMode", onlineMode); + data.put("bukkitVersion", bukkitVersion); + + data.put("javaVersion", javaVersion); + data.put("osName", osName); + data.put("osArch", osArch); + data.put("osVersion", osVersion); + data.put("coreCount", coreCount); + + return data; + } + + /** + * Collects the data and sends it afterwards. + */ + private void submitData() { + final JSONObject data = getServerData(); + + JSONArray pluginData = new JSONArray(); + // Search for all other bStats Metrics classes to get their plugin data + for (Class service : Bukkit.getServicesManager().getKnownServices()) { + try { + service.getField("B_STATS_VERSION"); // Our identifier :) + } catch (NoSuchFieldException ignored) { + continue; // Continue "searching" + } + // Found one! + try { + pluginData.add(service.getMethod("getPluginData").invoke(Bukkit.getServicesManager().load(service))); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { } + } + + data.put("plugins", pluginData); + + // Create a new thread for the connection to the bStats server + new Thread(new Runnable() { + @Override + public void run() { + try { + // Send the data + sendData(data); + } catch (Exception e) { + // Something went wrong! :( + if (logFailedRequests) { + plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e); + } + } + } + }).start(); + } + + /** + * Sends the data to the bStats server. + * + * @param data The data to send. + * @throws Exception If the request failed. + */ + private static void sendData(JSONObject data) throws Exception { + if (data == null) { + throw new IllegalArgumentException("Data cannot be null!"); + } + if (Bukkit.isPrimaryThread()) { + throw new IllegalAccessException("This method must not be called from the main thread!"); + } + HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection(); + + // Compress the data to save bandwidth + byte[] compressedData = compress(data.toString()); + + // Add headers + connection.setRequestMethod("POST"); + connection.addRequestProperty("Accept", "application/json"); + connection.addRequestProperty("Connection", "close"); + connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request + connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length)); + connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format + connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION); + + // Send data + connection.setDoOutput(true); + DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream()); + outputStream.write(compressedData); + outputStream.flush(); + outputStream.close(); + + connection.getInputStream().close(); // We don't care about the response - Just send our data :) + } + + /** + * Gzips the given String. + * + * @param str The string to gzip. + * @return The gzipped String. + * @throws IOException If the compression failed. + */ + private static byte[] compress(final String str) throws IOException { + if (str == null) { + return null; + } + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + GZIPOutputStream gzip = new GZIPOutputStream(outputStream); + gzip.write(str.getBytes("UTF-8")); + gzip.close(); + return outputStream.toByteArray(); + } + + /** + * Represents a custom chart. + */ + public static abstract class CustomChart { + + // The id of the chart + protected final String chartId; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + */ + public CustomChart(String chartId) { + if (chartId == null || chartId.isEmpty()) { + throw new IllegalArgumentException("ChartId cannot be null or empty!"); + } + this.chartId = chartId; + } + + protected JSONObject getRequestJsonObject() { + JSONObject chart = new JSONObject(); + chart.put("chartId", chartId); + try { + JSONObject data = getChartData(); + if (data == null) { + // If the data is null we don't send the chart. + return null; + } + chart.put("data", data); + } catch (Throwable t) { + if (logFailedRequests) { + Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t); + } + return null; + } + return chart; + } + + protected abstract JSONObject getChartData(); + + } + + /** + * Represents a custom simple pie. + */ + public static abstract class SimplePie extends CustomChart { + + /** + * Class constructor. + * + * @param chartId The id of the chart. + */ + public SimplePie(String chartId) { + super(chartId); + } + + /** + * Gets the value of the pie. + * + * @return The value of the pie. + */ + public abstract String getValue(); + + @Override + protected JSONObject getChartData() { + JSONObject data = new JSONObject(); + String value = getValue(); + if (value == null || value.isEmpty()) { + // Null = skip the chart + return null; + } + data.put("value", value); + return data; + } + } + + /** + * Represents a custom advanced pie. + */ + public static abstract class AdvancedPie extends CustomChart { + + /** + * Class constructor. + * + * @param chartId The id of the chart. + */ + public AdvancedPie(String chartId) { + super(chartId); + } + + /** + * Gets the values of the pie. + * + * @param valueMap Just an empty map. The only reason it exists is to make your life easier. + * You don't have to create a map yourself! + * @return The values of the pie. + */ + public abstract HashMap getValues(HashMap valueMap); + + @Override + protected JSONObject getChartData() { + JSONObject data = new JSONObject(); + JSONObject values = new JSONObject(); + HashMap map = getValues(new HashMap()); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() == 0) { + continue; // Skip this invalid + } + allSkipped = false; + values.put(entry.getKey(), entry.getValue()); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + data.put("values", values); + return data; + } + } + + /** + * Represents a custom single line chart. + */ + public static abstract class SingleLineChart extends CustomChart { + + /** + * Class constructor. + * + * @param chartId The id of the chart. + */ + public SingleLineChart(String chartId) { + super(chartId); + } + + /** + * Gets the value of the chart. + * + * @return The value of the chart. + */ + public abstract int getValue(); + + @Override + protected JSONObject getChartData() { + JSONObject data = new JSONObject(); + int value = getValue(); + if (value == 0) { + // Null = skip the chart + return null; + } + data.put("value", value); + return data; + } + + } + + /** + * Represents a custom multi line chart. + */ + public static abstract class MultiLineChart extends CustomChart { + + /** + * Class constructor. + * + * @param chartId The id of the chart. + */ + public MultiLineChart(String chartId) { + super(chartId); + } + + /** + * Gets the values of the chart. + * + * @param valueMap Just an empty map. The only reason it exists is to make your life easier. + * You don't have to create a map yourself! + * @return The values of the chart. + */ + public abstract HashMap getValues(HashMap valueMap); + + @Override + protected JSONObject getChartData() { + JSONObject data = new JSONObject(); + JSONObject values = new JSONObject(); + HashMap map = getValues(new HashMap()); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() == 0) { + continue; // Skip this invalid + } + allSkipped = false; + values.put(entry.getKey(), entry.getValue()); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + data.put("values", values); + return data; + } + + } + + /** + * Represents a custom simple bar chart. + */ + public static abstract class SimpleBarChart extends CustomChart { + + /** + * Class constructor. + * + * @param chartId The id of the chart. + */ + public SimpleBarChart(String chartId) { + super(chartId); + } + + /** + * Gets the value of the chart. + * + * @param valueMap Just an empty map. The only reason it exists is to make your life easier. + * You don't have to create a map yourself! + * @return The value of the chart. + */ + public abstract HashMap getValues(HashMap valueMap); + + @Override + protected JSONObject getChartData() { + JSONObject data = new JSONObject(); + JSONObject values = new JSONObject(); + HashMap map = getValues(new HashMap()); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + for (Map.Entry entry : map.entrySet()) { + JSONArray categoryValues = new JSONArray(); + categoryValues.add(entry.getValue()); + values.put(entry.getKey(), categoryValues); + } + data.put("values", values); + return data; + } + + } + + /** + * Represents a custom advanced bar chart. + */ + public static abstract class AdvancedBarChart extends CustomChart { + + /** + * Class constructor. + * + * @param chartId The id of the chart. + */ + public AdvancedBarChart(String chartId) { + super(chartId); + } + + /** + * Gets the value of the chart. + * + * @param valueMap Just an empty map. The only reason it exists is to make your life easier. + * You don't have to create a map yourself! + * @return The value of the chart. + */ + public abstract HashMap getValues(HashMap valueMap); + + @Override + protected JSONObject getChartData() { + JSONObject data = new JSONObject(); + JSONObject values = new JSONObject(); + HashMap map = getValues(new HashMap()); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue().length == 0) { + continue; // Skip this invalid + } + allSkipped = false; + JSONArray categoryValues = new JSONArray(); + for (int categoryValue : entry.getValue()) { + categoryValues.add(categoryValue); + } + values.put(entry.getKey(), categoryValues); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + data.put("values", values); + return data; + } + + } + + /** + * Represents a custom simple map chart. + */ + public static abstract class SimpleMapChart extends CustomChart { + + /** + * Class constructor. + * + * @param chartId The id of the chart. + */ + public SimpleMapChart(String chartId) { + super(chartId); + } + + /** + * Gets the value of the chart. + * + * @return The value of the chart. + */ + public abstract Country getValue(); + + @Override + protected JSONObject getChartData() { + JSONObject data = new JSONObject(); + Country value = getValue(); + + if (value == null) { + // Null = skip the chart + return null; + } + data.put("value", value.getCountryIsoTag()); + return data; + } + + } + + /** + * Represents a custom advanced map chart. + */ + public static abstract class AdvancedMapChart extends CustomChart { + + /** + * Class constructor. + * + * @param chartId The id of the chart. + */ + public AdvancedMapChart(String chartId) { + super(chartId); + } + + /** + * Gets the value of the chart. + * + * @param valueMap Just an empty map. The only reason it exists is to make your life easier. + * You don't have to create a map yourself! + * @return The value of the chart. + */ + public abstract HashMap getValues(HashMap valueMap); + + @Override + protected JSONObject getChartData() { + JSONObject data = new JSONObject(); + JSONObject values = new JSONObject(); + HashMap map = getValues(new HashMap()); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() == 0) { + continue; // Skip this invalid + } + allSkipped = false; + values.put(entry.getKey().getCountryIsoTag(), entry.getValue()); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + data.put("values", values); + return data; + } + + } + + /** + * A enum which is used for custom maps. + */ + public enum Country { + + /** + * bStats will use the country of the server. + */ + AUTO_DETECT("AUTO", "Auto Detected"), + + ANDORRA("AD", "Andorra"), + UNITED_ARAB_EMIRATES("AE", "United Arab Emirates"), + AFGHANISTAN("AF", "Afghanistan"), + ANTIGUA_AND_BARBUDA("AG", "Antigua and Barbuda"), + ANGUILLA("AI", "Anguilla"), + ALBANIA("AL", "Albania"), + ARMENIA("AM", "Armenia"), + NETHERLANDS_ANTILLES("AN", "Netherlands Antilles"), + ANGOLA("AO", "Angola"), + ANTARCTICA("AQ", "Antarctica"), + ARGENTINA("AR", "Argentina"), + AMERICAN_SAMOA("AS", "American Samoa"), + AUSTRIA("AT", "Austria"), + AUSTRALIA("AU", "Australia"), + ARUBA("AW", "Aruba"), + ALAND_ISLANDS("AX", "Åland Islands"), + AZERBAIJAN("AZ", "Azerbaijan"), + BOSNIA_AND_HERZEGOVINA("BA", "Bosnia and Herzegovina"), + BARBADOS("BB", "Barbados"), + BANGLADESH("BD", "Bangladesh"), + BELGIUM("BE", "Belgium"), + BURKINA_FASO("BF", "Burkina Faso"), + BULGARIA("BG", "Bulgaria"), + BAHRAIN("BH", "Bahrain"), + BURUNDI("BI", "Burundi"), + BENIN("BJ", "Benin"), + SAINT_BARTHELEMY("BL", "Saint Barthélemy"), + BERMUDA("BM", "Bermuda"), + BRUNEI("BN", "Brunei"), + BOLIVIA("BO", "Bolivia"), + BONAIRE_SINT_EUSTATIUS_AND_SABA("BQ", "Bonaire, Sint Eustatius and Saba"), + BRAZIL("BR", "Brazil"), + BAHAMAS("BS", "Bahamas"), + BHUTAN("BT", "Bhutan"), + BOUVET_ISLAND("BV", "Bouvet Island"), + BOTSWANA("BW", "Botswana"), + BELARUS("BY", "Belarus"), + BELIZE("BZ", "Belize"), + CANADA("CA", "Canada"), + COCOS_ISLANDS("CC", "Cocos Islands"), + THE_DEMOCRATIC_REPUBLIC_OF_CONGO("CD", "The Democratic Republic Of Congo"), + CENTRAL_AFRICAN_REPUBLIC("CF", "Central African Republic"), + CONGO("CG", "Congo"), + SWITZERLAND("CH", "Switzerland"), + COTE_D_IVOIRE("CI", "Côte d'Ivoire"), + COOK_ISLANDS("CK", "Cook Islands"), + CHILE("CL", "Chile"), + CAMEROON("CM", "Cameroon"), + CHINA("CN", "China"), + COLOMBIA("CO", "Colombia"), + COSTA_RICA("CR", "Costa Rica"), + CUBA("CU", "Cuba"), + CAPE_VERDE("CV", "Cape Verde"), + CURACAO("CW", "Curaçao"), + CHRISTMAS_ISLAND("CX", "Christmas Island"), + CYPRUS("CY", "Cyprus"), + CZECH_REPUBLIC("CZ", "Czech Republic"), + GERMANY("DE", "Germany"), + DJIBOUTI("DJ", "Djibouti"), + DENMARK("DK", "Denmark"), + DOMINICA("DM", "Dominica"), + DOMINICAN_REPUBLIC("DO", "Dominican Republic"), + ALGERIA("DZ", "Algeria"), + ECUADOR("EC", "Ecuador"), + ESTONIA("EE", "Estonia"), + EGYPT("EG", "Egypt"), + WESTERN_SAHARA("EH", "Western Sahara"), + ERITREA("ER", "Eritrea"), + SPAIN("ES", "Spain"), + ETHIOPIA("ET", "Ethiopia"), + FINLAND("FI", "Finland"), + FIJI("FJ", "Fiji"), + FALKLAND_ISLANDS("FK", "Falkland Islands"), + MICRONESIA("FM", "Micronesia"), + FAROE_ISLANDS("FO", "Faroe Islands"), + FRANCE("FR", "France"), + GABON("GA", "Gabon"), + UNITED_KINGDOM("GB", "United Kingdom"), + GRENADA("GD", "Grenada"), + GEORGIA("GE", "Georgia"), + FRENCH_GUIANA("GF", "French Guiana"), + GUERNSEY("GG", "Guernsey"), + GHANA("GH", "Ghana"), + GIBRALTAR("GI", "Gibraltar"), + GREENLAND("GL", "Greenland"), + GAMBIA("GM", "Gambia"), + GUINEA("GN", "Guinea"), + GUADELOUPE("GP", "Guadeloupe"), + EQUATORIAL_GUINEA("GQ", "Equatorial Guinea"), + GREECE("GR", "Greece"), + SOUTH_GEORGIA_AND_THE_SOUTH_SANDWICH_ISLANDS("GS", "South Georgia And The South Sandwich Islands"), + GUATEMALA("GT", "Guatemala"), + GUAM("GU", "Guam"), + GUINEA_BISSAU("GW", "Guinea-Bissau"), + GUYANA("GY", "Guyana"), + HONG_KONG("HK", "Hong Kong"), + HEARD_ISLAND_AND_MCDONALD_ISLANDS("HM", "Heard Island And McDonald Islands"), + HONDURAS("HN", "Honduras"), + CROATIA("HR", "Croatia"), + HAITI("HT", "Haiti"), + HUNGARY("HU", "Hungary"), + INDONESIA("ID", "Indonesia"), + IRELAND("IE", "Ireland"), + ISRAEL("IL", "Israel"), + ISLE_OF_MAN("IM", "Isle Of Man"), + INDIA("IN", "India"), + BRITISH_INDIAN_OCEAN_TERRITORY("IO", "British Indian Ocean Territory"), + IRAQ("IQ", "Iraq"), + IRAN("IR", "Iran"), + ICELAND("IS", "Iceland"), + ITALY("IT", "Italy"), + JERSEY("JE", "Jersey"), + JAMAICA("JM", "Jamaica"), + JORDAN("JO", "Jordan"), + JAPAN("JP", "Japan"), + KENYA("KE", "Kenya"), + KYRGYZSTAN("KG", "Kyrgyzstan"), + CAMBODIA("KH", "Cambodia"), + KIRIBATI("KI", "Kiribati"), + COMOROS("KM", "Comoros"), + SAINT_KITTS_AND_NEVIS("KN", "Saint Kitts And Nevis"), + NORTH_KOREA("KP", "North Korea"), + SOUTH_KOREA("KR", "South Korea"), + KUWAIT("KW", "Kuwait"), + CAYMAN_ISLANDS("KY", "Cayman Islands"), + KAZAKHSTAN("KZ", "Kazakhstan"), + LAOS("LA", "Laos"), + LEBANON("LB", "Lebanon"), + SAINT_LUCIA("LC", "Saint Lucia"), + LIECHTENSTEIN("LI", "Liechtenstein"), + SRI_LANKA("LK", "Sri Lanka"), + LIBERIA("LR", "Liberia"), + LESOTHO("LS", "Lesotho"), + LITHUANIA("LT", "Lithuania"), + LUXEMBOURG("LU", "Luxembourg"), + LATVIA("LV", "Latvia"), + LIBYA("LY", "Libya"), + MOROCCO("MA", "Morocco"), + MONACO("MC", "Monaco"), + MOLDOVA("MD", "Moldova"), + MONTENEGRO("ME", "Montenegro"), + SAINT_MARTIN("MF", "Saint Martin"), + MADAGASCAR("MG", "Madagascar"), + MARSHALL_ISLANDS("MH", "Marshall Islands"), + MACEDONIA("MK", "Macedonia"), + MALI("ML", "Mali"), + MYANMAR("MM", "Myanmar"), + MONGOLIA("MN", "Mongolia"), + MACAO("MO", "Macao"), + NORTHERN_MARIANA_ISLANDS("MP", "Northern Mariana Islands"), + MARTINIQUE("MQ", "Martinique"), + MAURITANIA("MR", "Mauritania"), + MONTSERRAT("MS", "Montserrat"), + MALTA("MT", "Malta"), + MAURITIUS("MU", "Mauritius"), + MALDIVES("MV", "Maldives"), + MALAWI("MW", "Malawi"), + MEXICO("MX", "Mexico"), + MALAYSIA("MY", "Malaysia"), + MOZAMBIQUE("MZ", "Mozambique"), + NAMIBIA("NA", "Namibia"), + NEW_CALEDONIA("NC", "New Caledonia"), + NIGER("NE", "Niger"), + NORFOLK_ISLAND("NF", "Norfolk Island"), + NIGERIA("NG", "Nigeria"), + NICARAGUA("NI", "Nicaragua"), + NETHERLANDS("NL", "Netherlands"), + NORWAY("NO", "Norway"), + NEPAL("NP", "Nepal"), + NAURU("NR", "Nauru"), + NIUE("NU", "Niue"), + NEW_ZEALAND("NZ", "New Zealand"), + OMAN("OM", "Oman"), + PANAMA("PA", "Panama"), + PERU("PE", "Peru"), + FRENCH_POLYNESIA("PF", "French Polynesia"), + PAPUA_NEW_GUINEA("PG", "Papua New Guinea"), + PHILIPPINES("PH", "Philippines"), + PAKISTAN("PK", "Pakistan"), + POLAND("PL", "Poland"), + SAINT_PIERRE_AND_MIQUELON("PM", "Saint Pierre And Miquelon"), + PITCAIRN("PN", "Pitcairn"), + PUERTO_RICO("PR", "Puerto Rico"), + PALESTINE("PS", "Palestine"), + PORTUGAL("PT", "Portugal"), + PALAU("PW", "Palau"), + PARAGUAY("PY", "Paraguay"), + QATAR("QA", "Qatar"), + REUNION("RE", "Reunion"), + ROMANIA("RO", "Romania"), + SERBIA("RS", "Serbia"), + RUSSIA("RU", "Russia"), + RWANDA("RW", "Rwanda"), + SAUDI_ARABIA("SA", "Saudi Arabia"), + SOLOMON_ISLANDS("SB", "Solomon Islands"), + SEYCHELLES("SC", "Seychelles"), + SUDAN("SD", "Sudan"), + SWEDEN("SE", "Sweden"), + SINGAPORE("SG", "Singapore"), + SAINT_HELENA("SH", "Saint Helena"), + SLOVENIA("SI", "Slovenia"), + SVALBARD_AND_JAN_MAYEN("SJ", "Svalbard And Jan Mayen"), + SLOVAKIA("SK", "Slovakia"), + SIERRA_LEONE("SL", "Sierra Leone"), + SAN_MARINO("SM", "San Marino"), + SENEGAL("SN", "Senegal"), + SOMALIA("SO", "Somalia"), + SURINAME("SR", "Suriname"), + SOUTH_SUDAN("SS", "South Sudan"), + SAO_TOME_AND_PRINCIPE("ST", "Sao Tome And Principe"), + EL_SALVADOR("SV", "El Salvador"), + SINT_MAARTEN_DUTCH_PART("SX", "Sint Maarten (Dutch part)"), + SYRIA("SY", "Syria"), + SWAZILAND("SZ", "Swaziland"), + TURKS_AND_CAICOS_ISLANDS("TC", "Turks And Caicos Islands"), + CHAD("TD", "Chad"), + FRENCH_SOUTHERN_TERRITORIES("TF", "French Southern Territories"), + TOGO("TG", "Togo"), + THAILAND("TH", "Thailand"), + TAJIKISTAN("TJ", "Tajikistan"), + TOKELAU("TK", "Tokelau"), + TIMOR_LESTE("TL", "Timor-Leste"), + TURKMENISTAN("TM", "Turkmenistan"), + TUNISIA("TN", "Tunisia"), + TONGA("TO", "Tonga"), + TURKEY("TR", "Turkey"), + TRINIDAD_AND_TOBAGO("TT", "Trinidad and Tobago"), + TUVALU("TV", "Tuvalu"), + TAIWAN("TW", "Taiwan"), + TANZANIA("TZ", "Tanzania"), + UKRAINE("UA", "Ukraine"), + UGANDA("UG", "Uganda"), + UNITED_STATES_MINOR_OUTLYING_ISLANDS("UM", "United States Minor Outlying Islands"), + UNITED_STATES("US", "United States"), + URUGUAY("UY", "Uruguay"), + UZBEKISTAN("UZ", "Uzbekistan"), + VATICAN("VA", "Vatican"), + SAINT_VINCENT_AND_THE_GRENADINES("VC", "Saint Vincent And The Grenadines"), + VENEZUELA("VE", "Venezuela"), + BRITISH_VIRGIN_ISLANDS("VG", "British Virgin Islands"), + U_S__VIRGIN_ISLANDS("VI", "U.S. Virgin Islands"), + VIETNAM("VN", "Vietnam"), + VANUATU("VU", "Vanuatu"), + WALLIS_AND_FUTUNA("WF", "Wallis And Futuna"), + SAMOA("WS", "Samoa"), + YEMEN("YE", "Yemen"), + MAYOTTE("YT", "Mayotte"), + SOUTH_AFRICA("ZA", "South Africa"), + ZAMBIA("ZM", "Zambia"), + ZIMBABWE("ZW", "Zimbabwe"); + + private String isoTag; + private String name; + + Country(String isoTag, String name) { + this.isoTag = isoTag; + this.name = name; + } + + /** + * Gets the name of the country. + * + * @return The name of the country. + */ + public String getCountryName() { + return name; + } + + /** + * Gets the iso tag of the country. + * + * @return The iso tag of the country. + */ + public String getCountryIsoTag() { + return isoTag; + } + + /** + * Gets a country by it's iso tag. + * + * @param isoTag The iso tag of the county. + * @return The country with the given iso tag or null if unknown. + */ + public static Country byIsoTag(String isoTag) { + for (Country country : Country.values()) { + if (country.getCountryIsoTag().equals(isoTag)) { + return country; + } + } + return null; + } + + /** + * Gets a country by a locale. + * + * @param locale The locale. + * @return The country from the giben locale or null if unknown country or + * if the locale does not contain a country. + */ + public static Country byLocale(Locale locale) { + return byIsoTag(locale.getCountry()); + } + } +} \ No newline at end of file diff --git a/src/main/java/net/DeltaWings/Minecraft/ChatManager/Scheduler/Scheduler.java b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Scheduler/Scheduler.java new file mode 100644 index 0000000..5359d2c --- /dev/null +++ b/src/main/java/net/DeltaWings/Minecraft/ChatManager/Scheduler/Scheduler.java @@ -0,0 +1,44 @@ +package net.DeltaWings.Minecraft.ChatManager.Scheduler; + +import net.DeltaWings.Minecraft.ChatManager.Api.API; +import net.DeltaWings.Minecraft.ChatManager.Custom.Config; +import net.DeltaWings.Minecraft.ChatManager.Main; + +import org.bukkit.Bukkit; + +import java.util.List; +import java.util.Objects; + +public class Scheduler { + + private final Config clearchat = new Config("config", "clearchat"); + private final Config broadcast = new Config("config", "broadcast"); + private final List bdlist = broadcast.getStringList("auto-broadcast.messages"); + private Integer ccobjective = 0, bdobjective = 0, bdactual = 0; + + public Scheduler() { + Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), () -> { + if(clearchat.getBoolean("auto-clear-chat.enabled", false)) { + if( Objects.equals(ccobjective, clearchat.getInt("auto-clear-chat.time", 30) * 60) ) { + API.clearchat("Console", null); + ccobjective = 0; + } else { + ccobjective++; + } + } + if(broadcast.getBoolean("auto-broadcast.enabled", false)) { + if(Objects.equals(bdobjective, broadcast.getInt("auto-broadcast.time", 30) * 60)) { + Main.log(bdactual + " et " + bdlist.size()); + API.broadcast("Console", bdlist.get(bdactual)); + bdactual++; + if( Objects.equals(bdactual, bdlist.size()) ) { + bdactual = 0; + } + bdobjective = 0; + } else { + bdobjective++; + } + } + },20L,20L); + } +} \ No newline at end of file diff --git a/src/main/ressources/plugin.yml b/src/main/ressources/plugin.yml new file mode 100644 index 0000000..e1f1c59 --- /dev/null +++ b/src/main/ressources/plugin.yml @@ -0,0 +1,204 @@ +name: Chat-Manager +version: ${project.version} +main: net.DeltaWings.Minecraft.ChatManager.Main +prefix: Chat Manager +author: Delta Wings +authors: [Aviortheking, LePhoenixArdent, Aipsyllone] +description: Manage all the chat server functionnality ! +website: https://delta-wings.net +commands: + staffchat: + description: staffchat + usage: / + aliases: [sc] + staffswitch: + description: switch receive mod + usage: + aliases: [ss] + channel: + description: create/modify/delete channels + aliases: [ch] + chat: + description: allow you to chat in channels + aliases: [c] + broadcast: + description: Change a global message + aliases: [bd] + clearchat: + description: Clear the global or the player chat + aliases: [cc] + chat-manager: + description: Manage the plugin + aliases: [cm, cmanager] + lockchat: + description: Lock/unlock the chat + aliases: [lc] + mute: + description: Mute a players from using command/chat + unmute: + description: Unmute a player + mutelist: + description: List muted players + +permissions: + chat-manager.*: + default: false + description: Allow the user to have all the plugin permissions. + children: + chat-manager.chat.*: true + chat-manager.broadcast: true + chat-manager.channel.*: true + chat-manager.admin.*: true + chat-manager.clear-chat.*: true + chat-manager.lock-chat.*: true + chat-manager.staff-chat.*: true + chat-manager.mute.*: true + chat-manager.broadcast: + default: op + description: Allow the user to broadcast messages + chat-manager.chat.*: + default: false + description: See childrens for more infos + children: + chat-manager.chat.prefix.*: true + chat-manager.chat.suffix.*: true + chat-manager.chat.colors: true + chat-manager.chat.prefix.*: + default: false + description: give the user the prefix NAME (see configuration file) + chat-manager.chat.suffix.*: + default: false + description: give the user the suffix NAME (see configuration file) + chat-manager.chat.colors: + default: op + description: Allow the user to use colors in chat + chat-manager.chat.color.*: + default: false + description: in-chat colors + chat-manager.channel.*: + default: true + description: Allow the user to user every channels functions + children: + chat-manager.channel.list: true + chat-manager.channel.create: true + chat-manager.channel.leave: true + chat-manager.channel.join: true + chat-manager.channel.invite: true + chat-manager.channel.disband: true + chat-manager.channel.kick: true + chat-manager.channel.promote: true + chat-manager.channel.demote: true + chat-manager.channel.chat: true + chat-manager.channel.list: + default: true + description: Allow the user to list all the channels + chat-manager.channel.create: + default: true + description: Allow the user to create a channel + chat-manager.channel.leave: + default: true + description: Allow the user to leave a channel + chat-manager.channel.join: + default: true + description: Allow the user to join a channel + chat-manager.channel.invite: + default: true + description: Allow the user to invite a plyer in his/her channel + chat-manager.channel.disband: + default: true + description: Allow the user to disband his/her channel + chat-manager.channel.promote: + default: true + description: Allow the user to promote a player in his/her channel + chat-manager.channel.kick: + default: true + description: Allow the user to kick a player in his/her channel + chat-manager.channel.demote: + default: true + description: Allow the user to demote a player in his/her channel + chat-manager.channel.chat: + default: true + description: Allow the user to speak in the channels chats + chat-manager.admin.*: + default: op + description: Give all the Administrator related permissions + children: + chat-manager.admin.reload: true + chat-manager.admin.notification: true + chat-manager.admin.reload: + default: op + description: Allow the Administrator to reload the plugin + chat-manager.admin.notification: + default: op + description: Allow the Administrator to receive plugin updates notifications + chat-manager.clear-chat.*: + default: op + description: Give all the clear chat related permissions + children: + chat-manager.clear-chat.global: true + chat-manager.clear-chat.player: true + chat-manager.clear-chat.global: + default: op + description: Allow the Admin to clear the global chat + chat-manager.clear-chat.player: + default: op + description: Allow the Admin to clear users personal chats + chat-manager.lockchat.*: + default: op + description: Give all the lock chat related permissions + children: + chat-manager.lockchat.lock: true + chat-manager.lockchat.ignore: true + chat-manager.lockchat.lock: + default: op + description: Allow the Admin to lock the chat + chat-manager.lockchat.ignore: + default: op + description: Allow the player to ignore the locked chat + chat-manager.staff-chat.*: + default: op + description: Give all the staff chat related permissions + children: + chat-manager.staff-chat.send: true + chat-manager.staff-chat.switch: true + chat-manager.staff-chat.read: true + chat-manager.staff-chat.send: + default: op + description: Allow the Admin to send staff chat messages + chat-manager.staff-chat.switch: + default: op + description: Allow the Admin switch if he/she want to receive staff chat messages + chat-manager.staff-chat.read: + default: op + description: Allow the Admin to read staff chat messages + chat-manager.mute.*: + default: op + description: Allow the admin to use all mute commands + children: + chat-manager.mute.all: true + chat-manager.unmute.all: true + chat-manager.mute.list: true + chat-manager.mute.all: + default: op + description: Allow the user to mute every players + children: + chat-manager.mute.chat: true + chat-manager.mute.cmd: true + chat-manager.mute.chat: + default: op + description: Allow the user to chat mute every players + chat-manager.mute.cmd: + default: op + description: Allow the user to command mute avery players + chat-manager.unmute.all: + default: op + description: Allow the user to unmute avery players + chat-manager.unmute.chat: + default: op + description: Allow the user to chat unmute avery players + chat-manager.unmute.cmd: + default: op + description: Allow the user to command unmute avery players + chat-manager.mute.list: + default: true + description: Allow the user to see the muted people \ No newline at end of file