From f4674fe8a6fa3c36f343d4218e1c83c48ea5c55d Mon Sep 17 00:00:00 2001 From: Pepich Date: Sun, 5 Feb 2017 20:52:06 +0100 Subject: [PATCH] After spending half an hour trying to fix them, DELETED them instead. --- src/com/redstoner/misc/Main.java | 9 +- src/com/redstoner/modules/mentio/Mentio.java | 326 ------------------ .../redstoner/modules/nametags/NameTags.java | 120 ------- src/com/redstoner/modules/nametags/Rank.java | 89 ----- 4 files changed, 4 insertions(+), 540 deletions(-) delete mode 100644 src/com/redstoner/modules/mentio/Mentio.java delete mode 100644 src/com/redstoner/modules/nametags/NameTags.java delete mode 100644 src/com/redstoner/modules/nametags/Rank.java diff --git a/src/com/redstoner/misc/Main.java b/src/com/redstoner/misc/Main.java index 3c09f27..99d76b4 100644 --- a/src/com/redstoner/misc/Main.java +++ b/src/com/redstoner/misc/Main.java @@ -16,10 +16,8 @@ import com.redstoner.modules.damnspam.DamnSpam; import com.redstoner.modules.imout.Imout; import com.redstoner.modules.lagchunks.LagChunks; import com.redstoner.modules.loginsecurity.LoginSecurity; -import com.redstoner.modules.mentio.Mentio; import com.redstoner.modules.misc.Misc; import com.redstoner.modules.motd.Motd; -import com.redstoner.modules.nametags.NameTags; import com.redstoner.modules.pmtoggle.Pmtoggle; import com.redstoner.modules.saylol.Saylol; import com.redstoner.modules.scriptutils.Scriptutils; @@ -32,7 +30,7 @@ import com.redstoner.modules.webtoken.WebToken; /** Main class. Duh. * * @author Pepich */ -@Version(major = 1, minor = 3, revision = 9, compatible = -1) +@Version(major = 1, minor = 3, revision = 10, compatible = -1) public class Main extends JavaPlugin { public static JavaPlugin plugin; @@ -47,6 +45,7 @@ public class Main extends JavaPlugin ModuleLoader.addModule(Abot.class); ModuleLoader.addModule(Adminchat.class); ModuleLoader.addModule(AdminNotes.class); + // TODO: ModuleLoader.addModule(BlockplaceMods.class); // TODO: ModuleLoader.addModule(Calc.class); // TODO: ModuleLoader.addModule(Chatalias.class); ModuleLoader.addModule(Cycle.class); @@ -58,10 +57,10 @@ public class Main extends JavaPlugin ModuleLoader.addModule(Imout.class); ModuleLoader.addModule(LagChunks.class); ModuleLoader.addModule(LoginSecurity.class); - ModuleLoader.addModule(Mentio.class); + // TODO: ModuleLoader.addModule(Mentio.class); ModuleLoader.addModule(Misc.class); ModuleLoader.addModule(Motd.class); - ModuleLoader.addModule(NameTags.class); + // TODO: ModuleLoader.addModule(NameTags.class); ModuleLoader.addModule(Pmtoggle.class); // TODO: ModuleLoader.addModule(Reports.class); ModuleLoader.addModule(Saylol.class); diff --git a/src/com/redstoner/modules/mentio/Mentio.java b/src/com/redstoner/modules/mentio/Mentio.java deleted file mode 100644 index b51fe7d..0000000 --- a/src/com/redstoner/modules/mentio/Mentio.java +++ /dev/null @@ -1,326 +0,0 @@ -package com.redstoner.modules.mentio; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.bukkit.ChatColor; -import org.bukkit.Sound; -import org.bukkit.command.CommandSender; -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 org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import org.json.simple.parser.ParseException; - -import com.nemez.cmdmgr.Command; -import com.redstoner.annotations.AutoRegisterListener; -import com.redstoner.annotations.Version; -import com.redstoner.misc.Main; -import com.redstoner.misc.Utils; -import com.redstoner.modules.Module; - -@Version(major = 1, minor = 0, revision = 0) -@AutoRegisterListener -public class Mentio implements Module, Listener { - private boolean enabled = false; - private File configFile; - private Map> mentions; - - @Override - public void onEnable() { - enabled = enableModule(); - } - - @Override - public void onDisable() { - enabled = false; - } - - @Override - public boolean enabled() { - return enabled; - } - - private boolean enableModule() { - configFile = new File(Main.plugin.getDataFolder(), "mentio.json"); - - if (!configFile.exists()) { - try { - FileWriter writer = new FileWriter(configFile); - - writer.write("{}"); - writer.flush(); - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - - Utils.error("Could not create blank mentions file! Disabling."); - - return false; - } - - } - - mentions = new HashMap<>(); - - try { - FileReader reader = new FileReader(configFile); - JSONObject json = (JSONObject) new JSONParser().parse(reader); - - for (Object key : json.keySet()) { - JSONArray mentionsJSONArray = (JSONArray) json.get(key); - List mentionsArray = new ArrayList(); - - for (Object obj : mentionsJSONArray.toArray()) { - mentionsArray.add(obj.toString()); - } - - mentions.put((String) key, mentionsArray); - } - } catch (IOException | ParseException e) { - e.printStackTrace(); - - Utils.error("Could not get mentions from file! Disabling."); - - return false; - } - - return true; - } - - @SuppressWarnings("unchecked") - private boolean saveMentions() { - JSONObject data = new JSONObject(); - - for (String key : mentions.keySet()) { - JSONArray array = new JSONArray(); - - for (String mention : mentions.get(key)) { - array.add(mention); - } - - data.put(key, array); - } - - try { - PrintWriter writer = new PrintWriter(configFile); - - writer.write(data.toJSONString()); - writer.close(); - - return true; - } catch (FileNotFoundException e) { - e.printStackTrace(); - return false; - } - } - - private String findAllColors(String s) { - String colors = ""; - - for (int i = s.indexOf("§"); i >= 0; i = s.indexOf("§", i + 1)) { - colors += "§" + s.charAt(i + 1); - } - - return colors; - } - - private String getDisplayNameWithoutSuffix(Player player) { - return ChatColor.stripColor(player.getDisplayName().toLowerCase()).replaceAll("\\$", "").replaceAll("•", "").trim(); - } - - @Command(hook = "addWord") - public void addWord(CommandSender sender, String word) { - Player player = (Player) sender; - String uuid = player.getUniqueId().toString(); - List playerMentions = mentions.get(uuid); - - List oldMentions = new ArrayList(); - List newMentions = new ArrayList(); - - if (playerMentions == null) { - newMentions.add(player.getName().toLowerCase()); - newMentions.add(getDisplayNameWithoutSuffix(player)); - } else { - oldMentions.addAll(playerMentions); - newMentions.addAll(playerMentions); - } - - newMentions.add(word.toLowerCase()); - mentions.put(uuid, newMentions); - - if (!saveMentions()) { - Utils.sendErrorMessage(player, null, "&cCould not save mentions! Please contact an admin!", '&'); - - if (playerMentions == null) { - mentions.remove(uuid); - } else { - mentions.put(uuid, oldMentions); - } - - return; - } - - Utils.sendMessage(player, null, "&aSuccessfully added mention: &e" + word, '&'); - } - - @Command(hook = "delWord") - public void delWord(CommandSender sender, String word) { - Player player = (Player) sender; - String uuid = player.getUniqueId().toString(); - List playerMentions = mentions.get(uuid); - - List oldMentions = new ArrayList(); - List newMentions = new ArrayList(); - - if (playerMentions == null) { - newMentions.add(player.getName().toLowerCase()); - newMentions.add(getDisplayNameWithoutSuffix(player)); - } else { - oldMentions.addAll(playerMentions); - newMentions.addAll(playerMentions); - } - - if (!oldMentions.contains(word.toLowerCase())) { - Utils.sendMessage(player, null, "&cYou do not have \"" + word + "\" added as a mention!", '&'); - return; - } - - newMentions.remove(word.toLowerCase()); - mentions.put(uuid, newMentions); - - if (!saveMentions()) { - Utils.sendErrorMessage(player, null, "&cCould not save mentions! Please contact an admin!", '&'); - - if (playerMentions == null) { - mentions.remove(uuid); - } else { - mentions.put(uuid, oldMentions); - } - - return; - } - - Utils.sendMessage(player, null, "&aSuccessfully removed mention: &e" + word, '&'); - } - - @Command(hook = "listWords") - public void listWords(CommandSender sender) { - Player player = (Player) sender; - String uuid = player.getUniqueId().toString(); - List playerMentions = mentions.get(uuid); - - Utils.sendMessage(player, null, "&aWords you are currently listening for (case ignored):"); - - if (playerMentions == null) { - Utils.sendMessage(player, null, "&c - &3" + player.getName().toLowerCase(), '&'); - Utils.sendMessage(player, null, "&c - &3" + getDisplayNameWithoutSuffix(player), '&'); - return; - } - - if (playerMentions.size() == 0) { - Utils.sendMessage(player, null, "&cYou are currently not litstening for any words!", '&'); - return; - } - - for (String word : playerMentions) { - Utils.sendMessage(player, null, "&c - &3" + word, '&'); - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onChat(AsyncPlayerChatEvent e) { - List words = new ArrayList(Arrays.asList(e.getMessage().split(" "))); - - for (Player recipient : e.getRecipients()) { - String uuid = recipient.getUniqueId().toString(); - List playerMentions = mentions.get(uuid); - - if (playerMentions == null) { - playerMentions = new ArrayList(); - playerMentions.add(recipient.getName()); - playerMentions.add(getDisplayNameWithoutSuffix(recipient)); - } - - List mentioColoredWords = new ArrayList(words); - boolean isMentioned = false; - - for (String listenWord : playerMentions) { - for (int i = 0; i < mentioColoredWords.size(); i++) { - String word = mentioColoredWords.get(i); - - if (word.toLowerCase().contains(listenWord.toLowerCase())) { - isMentioned = true; - String formatting = ""; - - for (int j = 0; j <= words.indexOf(word); j++) { - formatting += words.get(j); - } - - formatting = findAllColors(formatting); - - mentioColoredWords.set(i, "&a&o" + ChatColor.stripColor(word) + formatting); - } - } - } - - if (isMentioned) { - try { - e.getRecipients().remove(recipient); - } catch (UnsupportedOperationException ex) { - ex.printStackTrace(); - continue; - } - - String message = String.join(" ", mentioColoredWords.toArray(new String[0])); - - // this is purposely not Utils.sendMessage, prefixes are not wanted! - recipient.sendMessage(e.getFormat().replace("%1$s", e.getPlayer().getDisplayName()).replace("%2$s", message)); - recipient.playSound(recipient.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 2); - } - } - } - - @Override - public String getCommandString() { - StringBuilder sb = new StringBuilder(); - - sb.append("command mentio {"); - sb.append(" perm utils.mentio;"); - sb.append(" "); - sb.append(" add [string:word] {"); - sb.append(" run addWord word;"); - sb.append(" help Adds a word to your mentions.;"); - sb.append(" type player;"); - sb.append(" }"); - sb.append(" "); - sb.append(" del [string:word] {"); - sb.append(" run delWord word;"); - sb.append(" help Removes a word from your mentions.;"); - sb.append(" type player;"); - sb.append(" }"); - sb.append(" "); - sb.append(" list {"); - sb.append(" run listWords;"); - sb.append(" help Lists words that mention you.;"); - sb.append(" type player;"); - sb.append(" }"); - sb.append("}"); - - return sb.toString(); - } - -} diff --git a/src/com/redstoner/modules/nametags/NameTags.java b/src/com/redstoner/modules/nametags/NameTags.java deleted file mode 100644 index d4eee38..0000000 --- a/src/com/redstoner/modules/nametags/NameTags.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.redstoner.modules.nametags; - -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; - -import com.nemez.cmdmgr.Command; -import com.redstoner.annotations.AutoRegisterListener; -import com.redstoner.annotations.Version; -import com.redstoner.misc.Utils; -import com.redstoner.modules.Module; - -@Version(major = 1, minor = 0, revision = 0) -@AutoRegisterListener -public class NameTags implements Module, Listener { - private boolean enabled = false; - private Scoreboard scoreboard = null; - - @Override - public void onEnable() { - scoreboard = Bukkit.getScoreboardManager().getMainScoreboard(); - - for (Rank rank : Rank.values()) { - if (scoreboard.getTeam(rank.getScoreboardName()) == null) { - scoreboard.registerNewTeam(rank.getScoreboardName()); - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "scoreboard teams option " + rank.getScoreboardName() + " color " + rank.getColor()); - } - } - - enabled = true; - } - - @Override - public void onDisable() { - enabled = false; - } - - @Override - public boolean enabled() { - return enabled; - } - - @Override - public String getCommandString() { - StringBuilder sb = new StringBuilder(); - - sb.append("command nametags {"); - sb.append(" resort {"); - sb.append(" help Re-sorts tab;"); - sb.append(" perm utils.nametags.sort;"); - sb.append(" run nt_resort;"); - sb.append(" }"); - sb.append("}"); - - return sb.toString(); - } - - @Command(hook = "nt_resort") - public void resortCmd(CommandSender sender) { - reSort(); - Utils.sendMessage(sender, "Nametags", "&aResorted all players in tab! :P", '&'); - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent e) { - reSort(e.getPlayer()); - } - - @EventHandler - public void onCommand(PlayerCommandPreprocessEvent e) { - if (!e.isCancelled()) { - String[] cmdSplit = e.getMessage().split(" ")[0].split(":"); - String cmd = cmdSplit[cmdSplit.length - 1].replaceFirst("/", ""); - - if (cmd.equalsIgnoreCase("promote") || cmd.equalsIgnoreCase("demote")) { - reSort(); - } else if (cmd.equalsIgnoreCase("pex")) { - String[] splitMsg = e.getMessage().split(" "); - if (splitMsg.length > 1 && (splitMsg[1].equalsIgnoreCase("promote") || splitMsg[1].equalsIgnoreCase("demote"))) { - reSort(); - } - } - } - } - - private void reSort() { - for (Player player : Bukkit.getOnlinePlayers()) { - reSort(player); - } - } - - private void reSort(Player player) { - String playerName = player.getName(); - Rank rank = Rank.VISITOR; - - for (Rank r : Rank.values()) { - if (player.hasPermission(r.getPermission())) { - if (r.getPriority() > rank.getPriority()) { - rank = r; - } - } - } - - for (Rank r : Rank.values()) { - Team team = scoreboard.getTeam(r.getScoreboardName()); - - if (team.hasEntry(playerName)) { - team.removeEntry(playerName); - } - } - - scoreboard.getTeam(rank.getScoreboardName()).addEntry(playerName); - } -} diff --git a/src/com/redstoner/modules/nametags/Rank.java b/src/com/redstoner/modules/nametags/Rank.java deleted file mode 100644 index 9959321..0000000 --- a/src/com/redstoner/modules/nametags/Rank.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.redstoner.modules.nametags; - -public enum Rank { - VISITOR, MEMBER, BUILDER, TRUSTED, TRAININGMOD, MOD, ADMIN; - - public String getScoreboardName() { - switch (this) { - case VISITOR: - return "g_visitor"; - case MEMBER: - return "f_member"; - case BUILDER: - return "e_builder"; - case TRUSTED: - return "d_trusted"; - case TRAININGMOD: - return "c_trainingmod"; - case MOD: - return "b_mod"; - case ADMIN: - return "a_admin"; - default: - return "g_visitor"; - } - } - - public String getPermission() { - switch (this) { - case VISITOR: - return "group.visitor"; - case MEMBER: - return "group.member"; - case BUILDER: - return "group.builder"; - case TRUSTED: - return "group.trusted"; - case TRAININGMOD: - return "group.trainingmod"; - case MOD: - return "group.mod"; - case ADMIN: - return "group.admin"; - default: - return "group.visitor"; - } - } - - public int getPriority() { - switch (this) { - case VISITOR: - return 1; - case MEMBER: - return 2; - case BUILDER: - return 3; - case TRUSTED: - return 4; - case TRAININGMOD: - return 5; - case MOD: - return 6; - case ADMIN: - return 7; - default: - return 1; - } - } - - public String getColor() { - switch (this) { - case VISITOR: - return "gray"; - case MEMBER: - return "white"; - case BUILDER: - return "green"; - case TRUSTED: - return "dark_aqua"; - case TRAININGMOD: - return "red"; - case MOD: - return "red"; - case ADMIN: - return "dark_red"; - default: - return "gray"; - } - } -}