Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.kronix.staffchat;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.java.JavaPlugin;
- public class StaffChat extends JavaPlugin{
- @Override
- public void onEnable(){
- loadConfiguration();
- }
- public void loadConfiguration(){
- getConfig().options().copyDefaults(true);
- saveConfig();
- }
- public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
- if(sender instanceof Player) {
- Player p = (Player) sender;
- //---- Reload
- if(cmdLabel.equalsIgnoreCase("vpc") && args[0].equalsIgnoreCase("reload") && (p.isOp() || p.hasPermission("vippluschat.admin"))) {
- this.reloadConfig();
- pMessage(getConfig().getString("Messages.reload"), p);
- return true;
- }
- //---- End Reload
- //---- Chat
- if((cmdLabel.equalsIgnoreCase("mod") || cmdLabel.equalsIgnoreCase("mo")) && p.hasPermission("vippluschat.chat.mod")) {
- String msg = "";
- for(int i = 0; i < args.length; i++){
- String arg = args[i] + " ";
- msg = msg + arg;
- }
- if (getConfig().getString("Enabled.Mod") == "true") {
- sendMessages(msg, p, "vippluschat.chat.mod", "Mod");
- } else {
- pMessage(getConfig().getString("Messages.chat-disabled").replace("%CHAT_NAME%", "Mod").replace("%PLAYER%", p.getName()), p);
- }
- return true;
- }
- if((cmdLabel.equalsIgnoreCase("admin") || cmdLabel.equalsIgnoreCase("ad")) && p.hasPermission("vippluschat.chat.admin")) {
- String msg = "";
- for(int i = 0; i < args.length; i++){
- String arg = args[i] + " ";
- msg = msg + arg;
- }
- if (getConfig().getString("Enabled.Admin") == "true") {
- sendMessages(msg, p, "vippluschat.chat.admin", "Admin");
- } else {
- pMessage(getConfig().getString("Messages.chat-disabled").replace("%CHAT_NAME%", "Admin").replace("%PLAYER%", p.getName()), p);
- }
- return true;
- }
- if((cmdLabel.equalsIgnoreCase("owner") || cmdLabel.equalsIgnoreCase("ow")) && p.hasPermission("vippluschat.chat.owner")) {
- String msg = "";
- for(int i = 0; i < args.length; i++){
- String arg = args[i] + " ";
- msg = msg + arg;
- }
- if (getConfig().getString("Enabled.Owner") == "true") {
- sendMessages(msg, p, "vippluschat.chat.owner", "Owner");
- } else {
- pMessage(getConfig().getString("Messages.chat-disabled").replace("%CHAT_NAME%", "Owner").replace("%PLAYER%", p.getName()), p);
- }
- return true;
- }
- if((cmdLabel.equalsIgnoreCase("vip") || cmdLabel.equalsIgnoreCase("v")) && p.hasPermission("vippluschat.chat.vip")) {
- String msg = "";
- for(int i = 0; i < args.length; i++){
- String arg = args[i] + " ";
- msg = msg + arg;
- }
- if (getConfig().getString("Enabled.VIP") == "true") {
- sendMessages(msg, p, "vippluschat.chat.vip", "VIP");
- } else {
- pMessage(getConfig().getString("Messages.chat-disabled").replace("%CHAT_NAME%", "VIP").replace("%PLAYER%", p.getName()), p);
- }
- return true;
- }
- if((cmdLabel.equalsIgnoreCase("dev") || cmdLabel.equalsIgnoreCase("de")) && p.hasPermission("vippluschat.chat.dev")) {
- String msg = "";
- for(int i = 0; i < args.length; i++){
- String arg = args[i] + " ";
- msg = msg + arg;
- }
- if (getConfig().getString("Enabled.Dev") == "true") {
- sendMessages(msg, p, "vippluschat.chat.dev", "Dev");
- } else {
- pMessage(getConfig().getString("Messages.chat-disabled").replace("%CHAT_NAME%", "Dev").replace("%PLAYER%", p.getName()), p);
- }
- return true;
- }
- if((cmdLabel.equalsIgnoreCase("donator") || cmdLabel.equalsIgnoreCase("do")) && p.hasPermission("vippluschat.chat.donator")) {
- String msg = "";
- for(int i = 0; i < args.length; i++){
- String arg = args[i] + " ";
- msg = msg + arg;
- }
- if (getConfig().getString("Enabled.Donator") == "true") {
- sendMessages(msg, p, "vippluschat.chat.donator", "Donator");
- } else {
- pMessage(getConfig().getString("Messages.chat-disabled").replace("%CHAT_NAME%", "Donator").replace("%PLAYER%", p.getName()), p);
- }
- return true;
- }
- if((cmdLabel.equalsIgnoreCase("special") || cmdLabel.equalsIgnoreCase("sp")) && p.hasPermission("vippluschat.chat.special")) {
- String msg = "";
- for(int i = 0; i < args.length; i++){
- String arg = args[i] + " ";
- msg = msg + arg;
- }
- if (getConfig().getString("Enabled.Special") == "true") {
- sendMessages(msg, p, "vippluschat.chat.special", "Special");
- } else {
- pMessage(getConfig().getString("Messages.chat-disabled").replace("%CHAT_NAME%", "Special").replace("%PLAYER%", p.getName()), p);
- }
- return true;
- }
- if((cmdLabel.equalsIgnoreCase("elite") || cmdLabel.equalsIgnoreCase("el")) && p.hasPermission("vippluschat.chat.elite")) {
- String msg = "";
- for(int i = 0; i < args.length; i++){
- String arg = args[i] + " ";
- msg = msg + arg;
- }
- if (getConfig().getString("Enabled.Elite") == "true") {
- sendMessages(msg, p, "vippluschat.chat.elite", "Elite");
- } else {
- pMessage(getConfig().getString("Messages.chat-disabled").replace("%CHAT_NAME%", "Elite").replace("%PLAYER%", p.getName()), p);
- }
- return true;
- }
- if((cmdLabel.equalsIgnoreCase("staff") || cmdLabel.equalsIgnoreCase("st")) && p.hasPermission("vippluschat.chat.staff")) {
- String msg = "";
- for(int i = 0; i < args.length; i++){
- String arg = args[i] + " ";
- msg = msg + arg;
- }
- if (getConfig().getString("Enabled.Staff") == "true") {
- sendMessages(msg, p, "vippluschat.chat.staff", "Staff");
- } else {
- pMessage(getConfig().getString("Messages.chat-disabled").replace("%CHAT_NAME%", "Staff").replace("%PLAYER%", p.getName()), p);
- }
- return true;
- }
- //---- Chat End
- //---- Un/Ignore
- if (cmdLabel.equalsIgnoreCase("vpc") && args.length == 2 && p.hasPermission("vippluschat.chat.ignore")) {
- if (args[0].equalsIgnoreCase("ignore") || args[0].equalsIgnoreCase("unignore") ) {
- if ((args[1].equalsIgnoreCase("mod") || args[1].equalsIgnoreCase("admin")
- || args[1].equalsIgnoreCase("owner") || args[1].equalsIgnoreCase("dev") || args[1].equalsIgnoreCase("staff") || args[1].equalsIgnoreCase("vip")
- || args[1].equalsIgnoreCase("donator") || args[1].equalsIgnoreCase("special") || args[1].equalsIgnoreCase("elite"))) {
- if (getConfig().getBoolean("Tag." + args[1] + ".allow-ignore")) {
- if (args[0].equalsIgnoreCase("ignore")) {
- boolean b = false;
- for (String a: getConfig().getString("Other.ignore-blacklist").split(",")) {
- if (a.equalsIgnoreCase(p.getName())) {
- pMessage(getConfig().getString("Messages.ignore-blacklist"), p);
- return false;
- }
- }
- for (String a: getConfig().getString("Other.ignore." + args[1].toLowerCase()).split(",")) {
- if (a.equalsIgnoreCase(p.getName())) {
- b = true;
- }
- }
- if (!b) {
- if (getConfig().getString("Other.ignore." + args[1].toLowerCase()).contains("none")) {
- getConfig().set("Other.ignore." + args[1].toLowerCase(), p.getName());
- saveConfig();
- pMessage(ct(getConfig().getString("Messages.ignore").replace("%CHAT_NAME%", args[1]).replace("%STATUS%", "ignored").replace("%PLAYER%", p.getName())), p);
- return true;
- } else {
- getConfig().set("Other.ignore." + args[1].toLowerCase(), getConfig().getString("Other.ignore." + args[1].toLowerCase()) + "," + p.getName());
- saveConfig();
- pMessage(ct(getConfig().getString("Messages.ignore").replace("%CHAT_NAME%", args[1]).replace("%STATUS%", "ignored").replace("%PLAYER%", p.getName())), p);
- return true;
- }
- } else {
- pMessage(ct(getConfig().getString("Messages.ignore-already").replace("%CHAT_NAME%", args[1]).replace("%STATUS%", "ignored").replace("%PLAYER%", p.getName())), p);
- return true;
- }
- } else {
- //Un
- boolean b = false;
- String c = "";
- int d = 0;
- for (String a: getConfig().getString("Other.ignore." + args[1].toLowerCase()).split(",")) {
- if (a.equalsIgnoreCase(p.getName())) {
- b = true;
- } else {
- if (d == 0) {
- d += 1;
- String e = c;
- c = a;
- } else {
- String e = c;
- c = e + "," + a;
- }
- }
- }
- if (!b) {
- pMessage(ct(getConfig().getString("Messages.ignore-not-found").replace("%CHAT_NAME%", args[1]).replace("%STATUS%", "unignored").replace("%PLAYER%", p.getName())), p);
- return true;
- } else {
- getConfig().set("Other.ignore." + args[1].toLowerCase(), c);
- saveConfig();
- if (c.length() == 0) {
- c = "none";
- }
- getConfig().set("Other.ignore." + args[1].toLowerCase(), c);
- saveConfig();
- pMessage(ct(getConfig().getString("Messages.ignore").replace("%CHAT_NAME%", args[1]).replace("%STATUS%", "unignored").replace("%PLAYER%", p.getName())), p);
- return true;
- }
- }
- } else {
- pMessage(getConfig().getString("Messages.ignore-disabled").replace("%CHAT_NAME%", args[1]),p);
- }
- } else {
- pMessage(ct(getConfig().getString("Messages.ignore-fail").replace("%CHAT_NAME%", args[1]).replace("%STATUS%", "unignored").replace("%PLAYER%", p.getName())), p);
- }
- }
- }
- //---- Ignore End
- //---- Get Ignore List
- if (cmdLabel.equalsIgnoreCase("vpc") && args.length == 2 && p.hasPermission("vippluschat.admin")) {
- if (args[0].equalsIgnoreCase("ignored")) {
- if (args[1].equalsIgnoreCase("mod") || args[1].equalsIgnoreCase("admin")
- || args[1].equalsIgnoreCase("owner") || args[1].equalsIgnoreCase("dev") || args[1].equalsIgnoreCase("staff") || args[1].equalsIgnoreCase("vip")
- || args[1].equalsIgnoreCase("donator") || args[1].equalsIgnoreCase("special") || args[1].equalsIgnoreCase("elite")) {
- pMessage(getConfig().getString("Messages.ignore-list").replace("%CHAT_NAME%", args[1]).replace("%LIST%", getConfig().getString("Other.ignore." + args[1].toLowerCase())), p);
- return true;
- } else {
- pMessage(getConfig().getString("Messages.ignore-fail"), p);
- return true;
- }
- }
- }
- //---- Toggle Chat
- if (cmdLabel.equalsIgnoreCase("vpc") && args.length == 3 && (p.isOp() || p.hasPermission("vippluschat.admin"))) {
- if(args[0].equalsIgnoreCase("toggle") && (args[2].equalsIgnoreCase("true") || args[2].equalsIgnoreCase("false")) && (args[1].equalsIgnoreCase("mod")
- || args[1].equalsIgnoreCase("admin")
- || args[1].equalsIgnoreCase("owner") || args[1].equalsIgnoreCase("dev") || args[1].equalsIgnoreCase("staff") || args[1].equalsIgnoreCase("vip")
- || args[1].equalsIgnoreCase("donator") || args[1].equalsIgnoreCase("special") || args[1].equalsIgnoreCase("elite"))) {
- try{
- if (p.hasPermission("vipplushchat.toggle." + args[1])) {
- getConfig().get("Enabled." + args[1]);
- boolean st = Boolean.valueOf(args[2]);
- getConfig().set("Enabled." + args[1], st);
- saveConfig();
- reloadConfig();
- pMessage(getConfig().getString("Messages.toggle").replace("%CHAT_NAME%", args[1]).replace("%STATE%", args[2]), p);
- } else {
- pMessage(getConfig().getString("Messages.no-permissions"), p);
- }
- }catch(NullPointerException e){
- pMessage(getConfig().getString("Messages.error"), p);
- }
- return true;
- }
- }
- //---- End Toggle Chat
- }
- return false;
- }
- public static String ct(String text) {
- return text.replace("&0", ChatColor.BLACK + "").replace("&1", ChatColor.DARK_BLUE + "").replace("&2", ChatColor.DARK_GREEN + "").replace("&3", ChatColor.DARK_AQUA + "").replace("&4", ChatColor.DARK_RED + "").replace("&5", ChatColor.DARK_PURPLE + "").replace("&6", ChatColor.GOLD + "").replace("&7", ChatColor.GRAY + "").replace("&8", ChatColor.DARK_GRAY + "").replace("&9", ChatColor.BLUE + "").replace("&a", ChatColor.GREEN + "").replace("&b", ChatColor.AQUA + "").replace("&c", ChatColor.RED + "").replace("&d", ChatColor.LIGHT_PURPLE + "").replace("&e", ChatColor.YELLOW + "").replace("&f", ChatColor.WHITE + "").replace("&l", ChatColor.BOLD + "").replace("&m", ChatColor.STRIKETHROUGH + "").replace("&n", ChatColor.UNDERLINE + "").replace("&o", ChatColor.ITALIC + "").replace("&r", ChatColor.RESET + "");
- }
- public static void Broadcast(String msg) {
- String tag = ct("&8[&9VPC&8] &2");
- Bukkit.getServer().broadcastMessage(tag + ct(msg));
- }
- public Boolean checkColorCodes(String rank, String code) {
- System.out.println(code + " - End of list");
- for (String a: getConfig().getString("Tag." + rank + ".colors").split(" ")) {
- if (a.equalsIgnoreCase(code)) {
- return true;
- }
- }
- for (String a: getConfig().getString("Tag." + rank + ".color-codes").split(" ")) {
- if (a.equalsIgnoreCase(code)) {
- return true;
- }
- }
- return false;
- }
- //---- Ingore Check
- public Boolean checkIgnore(String user, String chat) {
- boolean b = false;
- for (String a: getConfig().getString("Other.ignore." + chat.toLowerCase()).split(",")) {
- if (a.equalsIgnoreCase(user)) {
- b = true;
- }
- }
- if (b) {
- return true;
- }
- return false;
- }
- //---- Ignore Check End
- public String chatCleaner(String text , String rank) {
- if (text.contains("&0") && checkColorCodes(rank, "black") == true) { text = text.replace("&0", ChatColor.BLACK + ""); } else { text = text.replace("&0", "");}
- if (text.contains("&1") && checkColorCodes(rank, "dark_blue") == true) { text = text.replace("&1", ChatColor.DARK_BLUE + ""); } else { text = text.replace("&1", "");}
- if (text.contains("&2") && checkColorCodes(rank, "dark_green") == true) { text = text.replace("&2", ChatColor.DARK_GREEN + ""); } else { text = text.replace("&2", "");}
- if (text.contains("&3") && checkColorCodes(rank, "dark_aqua") == true) { text = text.replace("&3", ChatColor.DARK_AQUA + ""); } else { text = text.replace("&3", "");}
- if (text.contains("&4") && checkColorCodes(rank, "dark_red") == true) { text = text.replace("&4", ChatColor.DARK_RED + ""); } else { text = text.replace("&4", "");}
- if (text.contains("&5") && checkColorCodes(rank, "dark_purple") == true) { text = text.replace("&5", ChatColor.DARK_PURPLE + ""); } else { text = text.replace("&5", "");}
- if (text.contains("&6") && checkColorCodes(rank, "gold") == true) { text = text.replace("&6", ChatColor.GOLD + ""); } else { text = text.replace("&6", "");}
- if (text.contains("&7") && checkColorCodes(rank, "gray") == true) { text = text.replace("&7", ChatColor.GRAY + ""); } else { text = text.replace("&7", "");}
- if (text.contains("&8") && checkColorCodes(rank, "dark_gray") == true) { text = text.replace("&8", ChatColor.DARK_GRAY + ""); } else { text = text.replace("&8", "");}
- if (text.contains("&9") && checkColorCodes(rank, "blue") == true) { text = text.replace("&9", ChatColor.BLUE + ""); } else { text = text.replace("&9", "");}
- if (text.contains("&a") && checkColorCodes(rank, "green") == true) { text = text.replace("&a", ChatColor.GREEN + ""); } else { text = text.replace("&a", "");}
- if (text.contains("&b") && checkColorCodes(rank, "aqua") == true) { text = text.replace("&b", ChatColor.AQUA + ""); } else { text = text.replace("&b", "");}
- if (text.contains("&c") && checkColorCodes(rank, "red") == true) { text = text.replace("&c", ChatColor.RED + ""); } else { text = text.replace("&c", "");}
- if (text.contains("&d") && checkColorCodes(rank, "light_purple") == true) { text = text.replace("&d", ChatColor.LIGHT_PURPLE + ""); } else { text = text.replace("&d", "");}
- if (text.contains("&e") && checkColorCodes(rank, "yellow") == true) { text = text.replace("&e", ChatColor.YELLOW + ""); } else { text = text.replace("&e", "");}
- if (text.contains("&f") && checkColorCodes(rank, "white") == true) { text = text.replace("&f", ChatColor.WHITE + ""); } else { text = text.replace("&f", "");}
- if (text.contains("&k") && checkColorCodes(rank, "obfuscated") == true) { text = text.replace("&k", ChatColor.MAGIC + ""); } else { text = text.replace("&k", "");}
- if (text.contains("&l") && checkColorCodes(rank, "bold") == true) { text = text.replace("&l", ChatColor.BOLD + ""); } else { text = text.replace("&l", "");}
- if (text.contains("&m") && checkColorCodes(rank, "strikethrough") == true) { text = text.replace("&m", ChatColor.STRIKETHROUGH + ""); } else { text = text.replace("&m", "");}
- if (text.contains("&n") && checkColorCodes(rank, "underline") == true) { text = text.replace("&n", ChatColor.UNDERLINE + ""); } else { text = text.replace("&n", "");}
- if (text.contains("&o") && checkColorCodes(rank, "italic") == true) { text = text.replace("&o", ChatColor.ITALIC + ""); } else { text = text.replace("&o", "");}
- if (text.contains("&r") && checkColorCodes(rank, "reset") == true) { text = text.replace("&r", ChatColor.RESET + ""); } else { text = text.replace("&r", "");}
- return text;
- }
- public void pMessage(String msg, Player p) {
- p.sendMessage(ct("&8[&9VPC&8] &2" + msg));
- }
- public String pSend(String msg, Player p1, Player p2, String rank) {
- String tag = "";
- if(rank == "Mod") { tag = ct(getConfig().getString("Tag.mod.layout")).replace("%PLAYER%", p2.getName()).replace("%MESSAGE%", chatCleaner(msg, "mod")).replace("%WORLD%", p1.getWorld().getName()).replace("%GAMEMODE%", p1.getGameMode().toString()); }
- if(rank == "Admin") { tag = ct(getConfig().getString("Tag.admin.layout")).replace("%PLAYER%", p2.getName()).replace("%MESSAGE%", chatCleaner(msg, "admin")).replace("%WORLD%", p1.getWorld().getName()).replace("%GAMEMODE%", p1.getGameMode().toString()); }
- if(rank == "Staff") { tag = ct(getConfig().getString("Tag.staff.layout")).replace("%PLAYER%", p2.getName()).replace("%MESSAGE%", chatCleaner(msg, "staff")).replace("%WORLD%", p1.getWorld().getName()).replace("%GAMEMODE%", p1.getGameMode().toString()); }
- if(rank == "Owner") { tag = ct(getConfig().getString("Tag.owner.layout")).replace("%PLAYER%", p2.getName()).replace("%MESSAGE%", chatCleaner(msg, "owner")).replace("%WORLD%", p1.getWorld().getName()).replace("%GAMEMODE%", p1.getGameMode().toString()); }
- if(rank == "Dev") { tag = ct(getConfig().getString("Tag.dev.layout")).replace("%PLAYER%", p2.getName()).replace("%MESSAGE%", chatCleaner(msg, "dev")).replace("%WORLD%", p1.getWorld().getName()).replace("%GAMEMODE%", p1.getGameMode().toString()); }
- if(rank == "VIP") { tag = ct(getConfig().getString("Tag.vip.layout")).replace("%PLAYER%", p2.getName()).replace("%MESSAGE%", chatCleaner(msg, "vip")).replace("%WORLD%", p1.getWorld().getName()).replace("%GAMEMODE%", p1.getGameMode().toString()); }
- if(rank == "Donator") { tag = ct(getConfig().getString("Tag.donator.layout")).replace("%PLAYER%", p2.getName()).replace("%MESSAGE%", chatCleaner(msg, "donator")).replace("%WORLD%", p1.getWorld().getName()).replace("%GAMEMODE%", p1.getGameMode().toString()); }
- if(rank == "Special") { tag = ct(getConfig().getString("Tag.special.layout")).replace("%PLAYER%", p2.getName()).replace("%MESSAGE%", chatCleaner(msg, "special")).replace("%WORLD%", p1.getWorld().getName()).replace("%GAMEMODE%", p1.getGameMode().toString()); }
- if(rank == "Elite") { tag = ct(getConfig().getString("Tag.elite.layout")).replace("%PLAYER%", p2.getName()).replace("%MESSAGE%", chatCleaner(msg, "elite")).replace("%WORLD%", p1.getWorld().getName()).replace("%GAMEMODE%", p1.getGameMode().toString()); }
- System.out.println(tag);
- p1.sendMessage(tag);
- return "";
- }
- public void sendMessages(String msg, Player player, String permissin, String rank) {
- if(player.hasPermission(permissin) && !checkIgnore(player.getName(), rank)) {
- for(Player p : Bukkit.getOnlinePlayers()) {
- if(p.hasPermission(permissin) && !checkIgnore(p.getName(), rank)) {
- pSend(msg, p, player, rank);
- }
- }
- } else {
- pMessage("You are currently ignoring this chat.", player);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement