From 4744f2edf97e18f26847b802cc6c3fdf29bd03f1 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 1 Mar 2019 17:58:40 +0100 Subject: [PATCH] Supporting clean installs And other fixes Also moved the Votifier reward to the core Checking if Towny is present (only a soft-depend now) --- .idea/ButtonChat.iml | 32 ------------------- pom.xml | 9 ------ .../buttondevteam/chat/ChatProcessing.java | 19 ++++------- .../java/buttondevteam/chat/PluginMain.java | 11 +++---- .../towncolors/TownColorComponent.java | 1 + .../chat/components/towny/TownyAnnouncer.java | 15 ++++++--- .../chat/components/towny/TownyComponent.java | 24 +++++++++++--- .../chat/listener/PlayerListener.java | 17 ---------- src/main/resources/plugin.yml | 3 +- 9 files changed, 43 insertions(+), 88 deletions(-) diff --git a/.idea/ButtonChat.iml b/.idea/ButtonChat.iml index aba73b5..3d32cdf 100644 --- a/.idea/ButtonChat.iml +++ b/.idea/ButtonChat.iml @@ -11,8 +11,6 @@ - - @@ -28,36 +26,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/pom.xml b/pom.xml index aaac3ac..5626ea8 100644 --- a/pom.xml +++ b/pom.xml @@ -155,10 +155,6 @@ Essentials http://repo.ess3.net/content/repositories/essrel/ - - Votifier - https://dl.bintray.com/nuvotifier/maven/ - Minigames http://maven.addstar.com.au/artifactory/release @@ -207,11 +203,6 @@ Towny 8d3b6b6 - - com.vexsoftware - nuvotifier-universal - 2.3.4 - diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index 5486a2a..b9afa17 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -1,9 +1,9 @@ package buttondevteam.chat; +import buttondevteam.chat.commands.ucmds.admin.DebugCommand; import buttondevteam.chat.components.chatonly.ChatOnlyComponent; import buttondevteam.chat.components.fun.FunComponent; -import buttondevteam.chat.components.fun.UnlolCommand; -import buttondevteam.chat.commands.ucmds.admin.DebugCommand; +import buttondevteam.chat.components.towny.TownyComponent; import buttondevteam.chat.formatting.ChatFormatter; import buttondevteam.chat.formatting.TellrawEvent; import buttondevteam.chat.formatting.TellrawPart; @@ -178,16 +178,11 @@ public class ChatProcessing { if (score < 0) // Never send messages to score below 0 sender.sendMessage("§cYou don't have permission to send this message or something went wrong"); else { - PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, - String.format("tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, score, channel.ID, - score, jsonstr)); - if (e.getChannel().ID.equals(PluginMain.TownChat.ID) - || e.getChannel().ID.equals(PluginMain.NationChat.ID)) { - ((List) json.getExtra()).add(0, new TellrawPart("[SPY]")); - jsonstr = toJson(json); - Bukkit.getServer().dispatchCommand(PluginMain.Console, String.format( - "tellraw @a[score_%s=1000,score_%s_min=1000] %s", channel.ID, channel.ID, jsonstr)); - } + PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, + String.format("tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, score, channel.ID, + score, jsonstr)); + val tc = ComponentManager.getIfEnabled(TownyComponent.class); + if (tc != null) tc.handleSpies(channel, json, ChatProcessing::toJson); } } else PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java index 7a57a49..2361d37 100644 --- a/src/main/java/buttondevteam/chat/PluginMain.java +++ b/src/main/java/buttondevteam/chat/PluginMain.java @@ -5,7 +5,6 @@ import buttondevteam.chat.components.announce.AnnouncerComponent; import buttondevteam.chat.components.flair.FlairComponent; import buttondevteam.chat.components.fun.FunComponent; import buttondevteam.chat.components.towncolors.TownColorComponent; -import buttondevteam.chat.components.towncolors.TownyListener; import buttondevteam.chat.components.towny.TownyComponent; import buttondevteam.chat.listener.PlayerJoinLeaveListener; import buttondevteam.chat.listener.PlayerListener; @@ -33,9 +32,6 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15 public static Scoreboard SB; - public static Channel TownChat; - public static Channel NationChat; - public ConfigData notificationSound() { return getIConfig().getData("notificationSound", ""); } @@ -52,20 +48,21 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15 TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this); TBMCCoreAPI.RegisterEventsForExceptions(new PlayerJoinLeaveListener(), this); - TBMCCoreAPI.RegisterEventsForExceptions(new TownyListener(), this); TBMCChatAPI.AddCommands(this, YeehawCommand.class); Console = this.getServer().getConsoleSender(); SB = getServer().getScoreboardManager().getMainScoreboard(); // Main can be detected with @a[score_...] - Component.registerComponent(this, new TownyComponent()); + if (Bukkit.getPluginManager().isPluginEnabled("Towny")) + Component.registerComponent(this, new TownyComponent()); TBMCChatAPI.RegisterChatChannel(new Channel("§7RP§f", Color.Gray, "rp", null)); //Since it's null, it's recognised as global if (!setupEconomy() || !setupPermissions()) TBMCCoreAPI.SendException("We're in trouble", new Exception("Failed to set up economy or permissions!")); - Component.registerComponent(this, new TownColorComponent()); + if (Bukkit.getPluginManager().isPluginEnabled("Towny")) + Component.registerComponent(this, new TownColorComponent()); Component.registerComponent(this, new FlairComponent()); //The original purpose of this plugin Component.registerComponent(this, new AnnouncerComponent()); Component.registerComponent(this, new FunComponent()); diff --git a/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java b/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java index b94d993..c7917fa 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java @@ -97,6 +97,7 @@ public class TownColorComponent extends Component { registerCommand(new buttondevteam.chat.components.towncolors.admin.TownColorCommand()); registerCommand(new buttondevteam.chat.components.towncolors.admin.NationColorCommand()); registerCommand(new TCCount()); + registerListener(new TownyListener()); } @Override diff --git a/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java b/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java index dc69adf..55702c7 100644 --- a/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java +++ b/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java @@ -1,7 +1,6 @@ package buttondevteam.chat.components.towny; import buttondevteam.chat.ChatProcessing; -import buttondevteam.chat.PluginMain; import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.TBMCSystemChatEvent; import buttondevteam.lib.chat.TBMCChatAPI; @@ -23,12 +22,14 @@ public class TownyAnnouncer { String groupID = m.group(2); //The group ID is correctly cased switch (String.valueOf(m.group(1))) { //valueOf: Handles null case "Town": - TBMCChatAPI.SendSystemMessage(PluginMain.TownChat, + if (townChannel == null) return; + TBMCChatAPI.SendSystemMessage(townChannel, new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, false), groupID), logRecord.getMessage(), target, ChatProcessing.MCORIGIN); break; case "Nation": - TBMCChatAPI.SendSystemMessage(PluginMain.NationChat, + if (nationChannel == null) return; + TBMCChatAPI.SendSystemMessage(nationChannel, new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, true), groupID), logRecord.getMessage(), target, ChatProcessing.MCORIGIN); break; @@ -52,15 +53,21 @@ public class TownyAnnouncer { }; private static TBMCSystemChatEvent.BroadcastTarget target; + private static Channel townChannel; + private static Channel nationChannel; - public static void setup() { + public static void setup(Channel townChannel, Channel nationChannel) { target = TBMCSystemChatEvent.BroadcastTarget.add("towny"); + TownyAnnouncer.townChannel = townChannel; + TownyAnnouncer.nationChannel = nationChannel; TownyLogger.log.addHandler(HANDLER); } public static void setdown() { TBMCSystemChatEvent.BroadcastTarget.remove(target); target = null; + TownyAnnouncer.townChannel = null; + TownyAnnouncer.nationChannel = null; TownyLogger.log.removeHandler(HANDLER); } } diff --git a/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java b/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java index 298ece8..6f3d283 100644 --- a/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java +++ b/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java @@ -1,6 +1,7 @@ package buttondevteam.chat.components.towny; import buttondevteam.chat.PluginMain; +import buttondevteam.chat.formatting.TellrawPart; import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.architecture.Component; import buttondevteam.lib.chat.Color; @@ -17,6 +18,8 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; import java.util.stream.Collectors; public class TownyComponent extends Component { @@ -24,16 +27,19 @@ public class TownyComponent extends Component { private static ArrayList Towns; private static ArrayList Nations; + private Channel TownChat; + private Channel NationChat; + @Override protected void enable() { TU = ((Towny) Bukkit.getPluginManager().getPlugin("Towny")).getTownyUniverse(); Towns = TU.getTownsMap().values().stream().map(Town::getName).collect(Collectors.toCollection(ArrayList::new)); // Creates a snapshot of towns, new towns will be added when needed Nations = TU.getNationsMap().values().stream().map(Nation::getName).collect(Collectors.toCollection(ArrayList::new)); // Same here but with nations TBMCChatAPI.RegisterChatChannel( - PluginMain.TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false))); + TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false))); TBMCChatAPI.RegisterChatChannel( - PluginMain.NationChat = new Channel("§6NC§f", Color.Gold, "nc", s -> checkTownNationChat(s, true))); - TownyAnnouncer.setup(); + NationChat = new Channel("§6NC§f", Color.Gold, "nc", s -> checkTownNationChat(s, true))); + TownyAnnouncer.setup(TownChat, NationChat); } @Override @@ -41,6 +47,14 @@ public class TownyComponent extends Component { TownyAnnouncer.setdown(); } + public void handleSpies(Channel channel, TellrawPart json, Function toJson) { + if (channel.ID.equals(TownChat.ID) || channel.ID.equals(NationChat.ID)) { + ((List) json.getExtra()).add(0, new TellrawPart("[SPY]")); + String jsonstr = toJson.apply(json); + Bukkit.getServer().dispatchCommand(PluginMain.Console, String.format( + "tellraw @a[score_%s=1000,score_%s_min=1000] %s", channel.ID, channel.ID, jsonstr)); + } + } /** * Return the error message for the message sender if they can't send it and the score @@ -49,13 +63,13 @@ public class TownyComponent extends Component { if (!(sender instanceof Player)) return new Channel.RecipientTestResult("§cYou are not a player!"); Resident resident = TU.getResidentMap().get(sender.getName().toLowerCase()); - Channel.RecipientTestResult result = checkTownNationChatInternal(sender, nationchat, resident); + Channel.RecipientTestResult result = checkTownNationChatInternal(nationchat, resident); if (result.errormessage != null && resident != null && resident.getModes().contains("spy")) // Only use spy if they wouldn't see it result = new Channel.RecipientTestResult(1000, "allspies"); // There won't be more than a thousand towns/nations probably return result; } - private static Channel.RecipientTestResult checkTownNationChatInternal(CommandSender sender, boolean nationchat, + private static Channel.RecipientTestResult checkTownNationChatInternal(boolean nationchat, Resident resident) { try { /* diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index 28fb592..8dee232 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -22,8 +22,6 @@ import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayerGetInfoEvent; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; -import com.vexsoftware.votifier.model.Vote; -import com.vexsoftware.votifier.model.VotifierEvent; import lombok.val; import net.ess3.api.events.NickChangeEvent; import org.bukkit.Bukkit; @@ -139,21 +137,6 @@ public class PlayerListener implements Listener { } } - @EventHandler - @SuppressWarnings("deprecation") - public void onVotifierEvent(VotifierEvent event) { //TODO: Move to teh Core eh - Vote vote = event.getVote(); - PluginMain.Instance.getLogger().info("Vote: " + vote); - org.bukkit.OfflinePlayer op = Bukkit.getOfflinePlayer(vote.getUsername()); - Player p = Bukkit.getPlayer(vote.getUsername()); - if (op != null) { - PluginMain.economy.depositPlayer(op, 50.0); - } - if (p != null) { - p.sendMessage("§bThanks for voting! $50 was added to your account."); - } - } - @EventHandler(priority = EventPriority.HIGHEST) public void onConsoleCommand(ServerCommandEvent event) { if (onCommandPreprocess(event.getSender(), event.getCommand())) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 05cbe74..25ff051 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -33,13 +33,12 @@ commands: author: NorbiPeti depend: - Essentials -- Towny -- Votifier - Vault - ThorpeCore soft-depend: - Minigames - Dynmap-Towny +- Towny permissions: tbmc.admin: description: Gives access to /un- commands and /u admin commands