From f12912c735e184066c56245ead843d4949e3d84b Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 30 Jan 2019 21:16:02 +0100 Subject: [PATCH 1/2] Added /press command, Dynmap NC support #40 Both tested and work --- .../buttondevteam/chat/ChatProcessing.java | 2 +- .../java/buttondevteam/chat/PluginMain.java | 4 +- .../chat/commands/UnlolCommand.java | 2 +- .../chat/commands/ucmds/HistoryCommand.java | 2 +- .../commands/ucmds/admin/UpdatePlugin.java | 80 +++++++++---------- .../chat/components/fun/FunComponent.java | 18 +++++ .../chat/components/fun/PressCommand.java | 42 ++++++++++ .../towncolors/TownColorComponent.java | 19 +++-- .../towncolors/admin/NationColorCommand.java | 2 +- .../towncolors/admin/TownColorCommand.java | 17 ++-- .../chat/components/towny/TownyAnnouncer.java | 2 +- .../chat/components/towny/TownyComponent.java | 2 +- .../chat/listener/PlayerListener.java | 6 +- src/main/resources/plugin.yml | 2 +- .../java/buttondevteam/chat/ChatFormatIT.java | 2 +- 15 files changed, 137 insertions(+), 65 deletions(-) create mode 100644 src/main/java/buttondevteam/chat/components/fun/FunComponent.java create mode 100644 src/main/java/buttondevteam/chat/components/fun/PressCommand.java diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index 053d0b9..9404259 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -7,7 +7,7 @@ import buttondevteam.chat.formatting.TellrawEvent; import buttondevteam.chat.formatting.TellrawPart; import buttondevteam.chat.formatting.TellrawSerializer; import buttondevteam.chat.listener.PlayerListener; -import buttondevteam.component.channel.Channel; +import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.TBMCChatEvent; import buttondevteam.lib.TBMCChatEventBase; import buttondevteam.lib.TBMCCoreAPI; diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java index 16cd62f..e1c8b14 100644 --- a/src/main/java/buttondevteam/chat/PluginMain.java +++ b/src/main/java/buttondevteam/chat/PluginMain.java @@ -3,12 +3,13 @@ package buttondevteam.chat; import buttondevteam.chat.commands.YeehawCommand; 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; -import buttondevteam.component.channel.Channel; +import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.architecture.ButtonPlugin; import buttondevteam.lib.architecture.Component; @@ -67,6 +68,7 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15 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()); } public static Essentials essentials = null; diff --git a/src/main/java/buttondevteam/chat/commands/UnlolCommand.java b/src/main/java/buttondevteam/chat/commands/UnlolCommand.java index 3c5d1de..7ab2311 100644 --- a/src/main/java/buttondevteam/chat/commands/UnlolCommand.java +++ b/src/main/java/buttondevteam/chat/commands/UnlolCommand.java @@ -1,6 +1,6 @@ package buttondevteam.chat.commands; -import buttondevteam.component.channel.Channel; +import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.TBMCChatEventBase; import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.TBMCCommandBase; diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/HistoryCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/HistoryCommand.java index 5bbe364..3dfd6d5 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/HistoryCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/HistoryCommand.java @@ -1,6 +1,6 @@ package buttondevteam.chat.commands.ucmds; -import buttondevteam.component.channel.Channel; +import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.chat.ChatMessage; import buttondevteam.lib.chat.CommandClass; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/admin/UpdatePlugin.java b/src/main/java/buttondevteam/chat/commands/ucmds/admin/UpdatePlugin.java index be6f274..d78379d 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/admin/UpdatePlugin.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/admin/UpdatePlugin.java @@ -1,40 +1,40 @@ -package buttondevteam.chat.commands.ucmds.admin; - -import buttondevteam.chat.PluginMain; -import buttondevteam.component.updater.PluginUpdater; -import buttondevteam.lib.TBMCCoreAPI; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; - -public class UpdatePlugin extends AdminCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { // - "§6---- Update plugin ----", // - "This command downloads the latest version of a TBMC plugin from GitHub", // - "To update a plugin: /" + alias + " ", // - "To list the plugin names: /" + alias // - }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> { - if (args.length == 0) { - sender.sendMessage("Downloading plugin names..."); - boolean first = true; - for (String plugin : PluginUpdater.GetPluginNames()) { - if (first) { - sender.sendMessage("§6---- Plugin names ----"); - first = false; - } - sender.sendMessage("- " + plugin); - } - } else - TBMCCoreAPI.UpdatePlugin(args[0], sender, args.length == 1 ? "master" : args[1]); - }); - return true; - } - -} +package buttondevteam.chat.commands.ucmds.admin; + +import buttondevteam.chat.PluginMain; +import buttondevteam.core.component.updater.PluginUpdater; +import buttondevteam.lib.TBMCCoreAPI; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; + +public class UpdatePlugin extends AdminCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { // + "§6---- Update plugin ----", // + "This command downloads the latest version of a TBMC plugin from GitHub", // + "To update a plugin: /" + alias + " ", // + "To list the plugin names: /" + alias // + }; + } + + @Override + public boolean OnCommand(CommandSender sender, String alias, String[] args) { + Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> { + if (args.length == 0) { + sender.sendMessage("Downloading plugin names..."); + boolean first = true; + for (String plugin : PluginUpdater.GetPluginNames()) { + if (first) { + sender.sendMessage("§6---- Plugin names ----"); + first = false; + } + sender.sendMessage("- " + plugin); + } + } else + TBMCCoreAPI.UpdatePlugin(args[0], sender, args.length == 1 ? "master" : args[1]); + }); + return true; + } + +} diff --git a/src/main/java/buttondevteam/chat/components/fun/FunComponent.java b/src/main/java/buttondevteam/chat/components/fun/FunComponent.java new file mode 100644 index 0000000..068fa0a --- /dev/null +++ b/src/main/java/buttondevteam/chat/components/fun/FunComponent.java @@ -0,0 +1,18 @@ +package buttondevteam.chat.components.fun; + +import buttondevteam.lib.architecture.Component; +import lombok.val; + +public class FunComponent extends Component { + @Override + protected void enable() { + val pc = new PressCommand(); + registerCommand(pc); + registerListener(pc); + } + + @Override + protected void disable() { + + } +} diff --git a/src/main/java/buttondevteam/chat/components/fun/PressCommand.java b/src/main/java/buttondevteam/chat/components/fun/PressCommand.java new file mode 100644 index 0000000..7923d21 --- /dev/null +++ b/src/main/java/buttondevteam/chat/components/fun/PressCommand.java @@ -0,0 +1,42 @@ +package buttondevteam.chat.components.fun; + +import buttondevteam.core.component.restart.ScheduledRestartCommand; +import buttondevteam.lib.ScheduledServerRestartEvent; +import buttondevteam.lib.ThorpeUtils; +import buttondevteam.lib.chat.Command2MC; +import buttondevteam.lib.chat.CommandClass; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import java.util.HashSet; + +@CommandClass +public class PressCommand extends Command2MC implements Listener { + private HashSet pressers; //Will be cleared with this class on shutdown/disable + private ScheduledRestartCommand command; + private int startTicks; + + @Subcommand + public void def(CommandSender sender) { + if (command == null) { + sender.sendMessage("§cThe timer isn't ticking... yet."); + return; + } + if (pressers.contains(sender)) { + sender.sendMessage("§cYou cannot press more than once."); + return; + } + pressers.add(sender); + Bukkit.broadcastMessage(String.format("§b-- %s §bpressed at %.0fs", ThorpeUtils.getDisplayName(sender), command.getRestartCounter() / 20f)); + command.setRestartCounter(startTicks); + } + + @EventHandler + public void restartEvent(ScheduledServerRestartEvent event) { + command = event.getCommand(); + pressers = new HashSet<>(); + startTicks = event.getRestartTicks(); + } +} diff --git a/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java b/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java index cbbb8e6..02c8b42 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java @@ -77,8 +77,17 @@ public class TownColorComponent extends Component { val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny"); if (dtp == null) return; - for (val entry : TownColors.entrySet()) - setTownColor(dtp, buttondevteam.chat.components.towncolors.admin.TownColorCommand.getTownNameCased(entry.getKey()), entry.getValue()); + for (val entry : TownColors.entrySet()) { + try { + val nation = TownyComponent.TU.getTownsMap().get(entry.getKey()).getNation(); + Color nc; + if (nation == null || (nc = NationColor.get(nation.getName().toLowerCase())) == null) + nc = Color.White; + setTownColor(dtp, buttondevteam.chat.components.towncolors.admin.TownColorCommand.getTownNameCased(entry.getKey()), entry.getValue(), nc); + } catch (Exception e) { + TBMCCoreAPI.SendException("Error while setting town color for town " + entry.getKey() + "!", e); + } + } }); registerCommand(new TownColorCommand()); @@ -104,11 +113,11 @@ public class TownColorComponent extends Component { * @param colors The town's colors */ - public static void setTownColor(DynmapTownyPlugin dtp, String town, Color[] colors) { + public static void setTownColor(DynmapTownyPlugin dtp, String town, Color[] colors, Color nationcolor) { Function c2i = c -> c.getRed() << 16 | c.getGreen() << 8 | c.getBlue(); try { - DTBridge.setTownColor(dtp, town, c2i.apply(colors[0]), - c2i.apply(colors.length > 1 ? colors[1] : colors[0])); + DTBridge.setTownColor(dtp, town, c2i.apply(nationcolor == null ? colors[0] : nationcolor), + c2i.apply(colors.length > 1 && nationcolor != null ? colors[1] : colors[0])); } catch (Exception e) { TBMCCoreAPI.SendException("Failed to set town color for town " + town + "!", e); } diff --git a/src/main/java/buttondevteam/chat/components/towncolors/admin/NationColorCommand.java b/src/main/java/buttondevteam/chat/components/towncolors/admin/NationColorCommand.java index 3d7c216..4187685 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/admin/NationColorCommand.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/admin/NationColorCommand.java @@ -54,7 +54,7 @@ public class NationColorCommand extends AdminCommandBase { for (Town t : nation.getTowns()) TownyListener.updateTownMembers(t); }); - sender.sendMessage("§bNation color set to §" + TownColorCommand.getColorText(c.get())); + sender.sendMessage("§bNation color set to " + TownColorCommand.getColorText(c.get())); return true; } } diff --git a/src/main/java/buttondevteam/chat/components/towncolors/admin/TownColorCommand.java b/src/main/java/buttondevteam/chat/components/towncolors/admin/TownColorCommand.java index 8905d9d..b4d5391 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/admin/TownColorCommand.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/admin/TownColorCommand.java @@ -50,20 +50,21 @@ public class TownColorCommand extends AdminCommandBase { return true; clrs[i - 1] = c.get(); } + Color tnc; + try { + tnc = TownColorComponent.NationColor.get(targetTown.getNation().getName().toLowerCase()); + } catch (Exception e) { + tnc = null; + } + if (tnc == null) tnc = Color.White; //Default nation color - TODO: Make configurable for (Map.Entry other : TownColorComponent.TownColors.entrySet()) { - Color nc, tnc; + Color nc; try { nc = TownColorComponent.NationColor.get(TownyComponent.TU.getTownsMap().get(other.getKey()).getNation().getName().toLowerCase()); } catch (Exception e) { //Too lazy for lots of null-checks and it may throw exceptions anyways nc = null; } if (nc == null) nc = Color.White; //Default nation color - try { - tnc = TownColorComponent.NationColor.get(targetTown.getNation().getName().toLowerCase()); - } catch (Exception e) { - tnc = null; - } - if (tnc == null) tnc = Color.White; //Default nation color - TODO: Make configurable if (nc.getName().equals(tnc.getName())) { int C = 0; if (clrs.length == other.getValue().length) @@ -86,7 +87,7 @@ public class TownColorCommand extends AdminCommandBase { PluginMain.Instance.getLogger().warning("Dynmap-Towny not found for setting town color!"); return true; } - TownColorComponent.setTownColor(dtp, targetTown.getName(), clrs); + TownColorComponent.setTownColor(dtp, targetTown.getName(), clrs, tnc); sender.sendMessage("§bColor(s) set."); return true; } diff --git a/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java b/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java index dc579d3..f6788e8 100644 --- a/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java +++ b/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java @@ -2,7 +2,7 @@ package buttondevteam.chat.components.towny; import buttondevteam.chat.ChatProcessing; import buttondevteam.chat.PluginMain; -import buttondevteam.component.channel.Channel; +import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.chat.TBMCChatAPI; import com.palmergames.bukkit.towny.TownyLogger; import lombok.val; diff --git a/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java b/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java index c93cf7e..298ece8 100644 --- a/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java +++ b/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java @@ -1,7 +1,7 @@ package buttondevteam.chat.components.towny; import buttondevteam.chat.PluginMain; -import buttondevteam.component.channel.Channel; +import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.architecture.Component; import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.TBMCChatAPI; diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index 43309f7..86feab5 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -6,10 +6,10 @@ import buttondevteam.chat.PluginMain; import buttondevteam.chat.commands.ucmds.HistoryCommand; import buttondevteam.chat.components.flair.FlairComponent; import buttondevteam.chat.components.towncolors.TownColorComponent; -import buttondevteam.component.channel.Channel; -import buttondevteam.component.channel.ChatChannelRegisterEvent; -import buttondevteam.component.channel.ChatRoom; import buttondevteam.core.ComponentManager; +import buttondevteam.core.component.channel.Channel; +import buttondevteam.core.component.channel.ChatChannelRegisterEvent; +import buttondevteam.core.component.channel.ChatRoom; import buttondevteam.lib.TBMCChatEvent; import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.chat.ChatMessage; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b66a288..05cbe74 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -36,7 +36,7 @@ depend: - Towny - Votifier - Vault -- ButtonCore +- ThorpeCore soft-depend: - Minigames - Dynmap-Towny diff --git a/src/test/java/buttondevteam/chat/ChatFormatIT.java b/src/test/java/buttondevteam/chat/ChatFormatIT.java index 73d5c80..4531c16 100644 --- a/src/test/java/buttondevteam/chat/ChatFormatIT.java +++ b/src/test/java/buttondevteam/chat/ChatFormatIT.java @@ -7,8 +7,8 @@ import buttondevteam.chat.formatting.TellrawEvent; import buttondevteam.chat.formatting.TellrawEvent.ClickAction; import buttondevteam.chat.formatting.TellrawEvent.HoverAction; import buttondevteam.chat.formatting.TellrawPart; -import buttondevteam.component.channel.Channel; import buttondevteam.core.TestPrepare; +import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.chat.Color; import net.milkbowl.vault.permission.Permission; import org.bukkit.command.CommandSender; -- 2.30.2 From 185b0df8e0a1a22956bcd5c8f2ce5c4912e1caf6 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 30 Jan 2019 23:33:16 +0100 Subject: [PATCH 2/2] A change and a fix Say the nation name which already uses the color History command help text fix --- .../buttondevteam/chat/commands/ucmds/HistoryCommand.java | 2 +- .../components/towncolors/admin/NationColorCommand.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/HistoryCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/HistoryCommand.java index 3dfd6d5..74a3628 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/HistoryCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/HistoryCommand.java @@ -43,7 +43,7 @@ public class HistoryCommand extends UCommandBase { } else { Optional och = Channel.getChannels().filter(chan -> chan.ID.equalsIgnoreCase(args[0])).findAny(); if (!och.isPresent()) { - sender.sendMessage("§cChannel not found. Use the ID, for example: /" + (hc == null ? "u history" : hc.GetCommandPath()) + " ooc"); + sender.sendMessage("§cChannel not found. Use the ID, for example: /" + (hc == null ? "u history" : hc.GetCommandPath()) + " g"); return true; } stream = Stream.of(och.get()); diff --git a/src/main/java/buttondevteam/chat/components/towncolors/admin/NationColorCommand.java b/src/main/java/buttondevteam/chat/components/towncolors/admin/NationColorCommand.java index 4187685..70ae07b 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/admin/NationColorCommand.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/admin/NationColorCommand.java @@ -42,9 +42,9 @@ public class NationColorCommand extends AdminCommandBase { val c = TownColorCommand.getColorOrSendError(args[1], sender); if (!c.isPresent()) return true; if (!c.get().getName().equals(Color.White.getName())) { //Default nation color - for (val nc : TownColorComponent.NationColor.values()) { - if (nc.getName().equals(c.get().getName())) { - sender.sendMessage("§cAnother nation already uses this color!"); + for (val e : TownColorComponent.NationColor.entrySet()) { + if (e.getValue().getName().equals(c.get().getName())) { + sender.sendMessage("§The nation " + e.getKey() + " already uses this color!"); return true; } } -- 2.30.2