From f7c1106d1c8bf8b21c6bedda26149eec70c63ff0 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 27 Feb 2019 16:41:49 +0100 Subject: [PATCH] Replaced (almost) all broadcasts --- .idea/ButtonChat.iml | 29 +++++++++++++++++++ .../announce/AnnouncerComponent.java | 9 +++++- .../chat/components/fun/FunComponent.java | 14 ++++++--- .../chat/components/fun/PressCommand.java | 5 +++- .../chat/components/fun/UnlolCommand.java | 12 ++++++-- 5 files changed, 60 insertions(+), 9 deletions(-) diff --git a/.idea/ButtonChat.iml b/.idea/ButtonChat.iml index 9b778e4..aba73b5 100644 --- a/.idea/ButtonChat.iml +++ b/.idea/ButtonChat.iml @@ -42,5 +42,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/buttondevteam/chat/components/announce/AnnouncerComponent.java b/src/main/java/buttondevteam/chat/components/announce/AnnouncerComponent.java index fce4422..f841a2b 100644 --- a/src/main/java/buttondevteam/chat/components/announce/AnnouncerComponent.java +++ b/src/main/java/buttondevteam/chat/components/announce/AnnouncerComponent.java @@ -1,7 +1,10 @@ package buttondevteam.chat.components.announce; +import buttondevteam.core.component.channel.Channel; +import buttondevteam.lib.TBMCSystemChatEvent; import buttondevteam.lib.architecture.Component; import buttondevteam.lib.architecture.ConfigData; +import buttondevteam.lib.chat.TBMCChatAPI; import org.bukkit.Bukkit; import java.util.ArrayList; @@ -14,6 +17,9 @@ public class AnnouncerComponent extends Component implements Runnable { public ConfigData AnnounceTime() { return getConfig().getData("announceTime", 15 * 60 * 1000); } + + private TBMCSystemChatEvent.BroadcastTarget target; + private static int AnnounceMessageIndex = 0; @Override @@ -26,7 +32,7 @@ public class AnnouncerComponent extends Component implements Runnable { } if (Bukkit.getOnlinePlayers().size() == 0) continue; //Don't post to Discord if nobody is on if (AnnounceMessages().get().size() > AnnounceMessageIndex) { - Bukkit.broadcastMessage(AnnounceMessages().get().get(AnnounceMessageIndex)); + TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, AnnounceMessages().get().get(AnnounceMessageIndex), target); AnnounceMessageIndex++; if (AnnounceMessageIndex == AnnounceMessages().get().size()) AnnounceMessageIndex = 0; @@ -36,6 +42,7 @@ public class AnnouncerComponent extends Component implements Runnable { @Override protected void enable() { + target= TBMCSystemChatEvent.BroadcastTarget.add("announcements"); registerCommand(new AddCommand()); registerCommand(new EditCommand()); registerCommand(new ListCommand()); diff --git a/src/main/java/buttondevteam/chat/components/fun/FunComponent.java b/src/main/java/buttondevteam/chat/components/fun/FunComponent.java index 53bfb23..9053635 100644 --- a/src/main/java/buttondevteam/chat/components/fun/FunComponent.java +++ b/src/main/java/buttondevteam/chat/components/fun/FunComponent.java @@ -2,6 +2,7 @@ package buttondevteam.chat.components.fun; import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.PluginMain; +import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.TBMCChatEventBase; import buttondevteam.lib.TBMCCommandPreprocessEvent; import buttondevteam.lib.TBMCSystemChatEvent; @@ -10,6 +11,7 @@ import buttondevteam.lib.architecture.Component; import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.player.ChromaGamerBase; import buttondevteam.lib.player.TBMCPlayer; +import lombok.Getter; import lombok.val; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -35,13 +37,15 @@ public class FunComponent extends Component implements Listener { private ArrayList Fs = new ArrayList<>(); private UnlolCommand command; private TBMCSystemChatEvent.BroadcastTarget unlolTarget; + private TBMCSystemChatEvent.BroadcastTarget fTarget; @Override protected void enable() { unlolTarget = TBMCSystemChatEvent.BroadcastTarget.add("unlol"); + fTarget = TBMCSystemChatEvent.BroadcastTarget.add("respect"); val pc = new PressCommand(); registerCommand(pc); registerListener(pc); - registerCommand(command=new UnlolCommand()); + registerCommand(command=new UnlolCommand(unlolTarget)); registerListener(this); registerCommand(new FTopCommand()); } @@ -81,8 +85,9 @@ public class FunComponent extends Component implements Listener { ActiveF = false; if (FPlayer != null && FPlayer.FCount().get() < Integer.MAX_VALUE - 1) FPlayer.FCount().set(FPlayer.FCount().get() + Fs.size()); - Bukkit.broadcastMessage("§b" + Fs.size() + " " + (Fs.size() == 1 ? "person" : "people") - + " paid their respects.§r"); + TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, + "§b" + Fs.size() + " " + (Fs.size() == 1 ? "person" : "people") + + " paid their respects.§r", fTarget); Fs.clear(); } }; @@ -94,7 +99,8 @@ public class FunComponent extends Component implements Listener { Fs.clear(); FPlayer = TBMCPlayer.getPlayer(e.getEntity().getUniqueId(), ChatPlayer.class); FPlayer.FDeaths().set(FPlayer.FDeaths().get() + 1); - Bukkit.broadcastMessage("§bPress F to pay respects.§r"); + TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, + "§bPress F to pay respects.§r", fTarget); Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, tt, 15 * 20); } } diff --git a/src/main/java/buttondevteam/chat/components/fun/PressCommand.java b/src/main/java/buttondevteam/chat/components/fun/PressCommand.java index b9ddc7d..123aab5 100644 --- a/src/main/java/buttondevteam/chat/components/fun/PressCommand.java +++ b/src/main/java/buttondevteam/chat/components/fun/PressCommand.java @@ -1,11 +1,14 @@ package buttondevteam.chat.components.fun; +import buttondevteam.core.component.channel.Channel; +import buttondevteam.core.component.restart.RestartComponent; import buttondevteam.core.component.restart.ScheduledRestartCommand; import buttondevteam.lib.ScheduledServerRestartEvent; import buttondevteam.lib.ThorpeUtils; import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.ICommand2MC; +import buttondevteam.lib.chat.TBMCChatAPI; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.event.EventHandler; @@ -30,7 +33,7 @@ public class PressCommand extends ICommand2MC implements Listener { return; } pressers.add(sender); - Bukkit.broadcastMessage(String.format("§b-- %s §bpressed at %.0fs", ThorpeUtils.getDisplayName(sender), command.getRestartCounter() / 20f)); + TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, String.format("§b-- %s §bpressed at %.0fs", ThorpeUtils.getDisplayName(sender), command.getRestartCounter() / 20f), command.getComponent().getRestartBroadcast()); command.setRestartCounter(startTicks); } diff --git a/src/main/java/buttondevteam/chat/components/fun/UnlolCommand.java b/src/main/java/buttondevteam/chat/components/fun/UnlolCommand.java index 683be84..8de6c9e 100644 --- a/src/main/java/buttondevteam/chat/components/fun/UnlolCommand.java +++ b/src/main/java/buttondevteam/chat/components/fun/UnlolCommand.java @@ -2,8 +2,11 @@ package buttondevteam.chat.components.fun; import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.TBMCChatEventBase; +import buttondevteam.lib.TBMCSystemChatEvent; +import buttondevteam.lib.ThorpeUtils; import buttondevteam.lib.chat.*; import lombok.Data; +import lombok.RequiredArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -20,10 +23,13 @@ import java.util.Map; "It will make the last person saying one of the recognized laugh strings blind for a few seconds", "Note that you can only unlaugh laughs that weren't unlaughed before" }) +@RequiredArgsConstructor public final class UnlolCommand extends ICommand2MC { public Map Lastlol = new HashMap<>(); + private final TBMCSystemChatEvent.BroadcastTarget target; + @Command2.Subcommand public boolean def(CommandSender sender) { LastlolData lol = Lastlol.values().stream().filter(lld -> lld.Chatevent.shouldSendTo(sender)) @@ -33,10 +39,10 @@ public final class UnlolCommand extends ICommand2MC { if (lol.Lolowner instanceof Player) ((Player) lol.Lolowner) .addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 2 * 20, 5, false, false)); - String msg = (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName()) + String msg = ThorpeUtils.getDisplayName(sender) + (lol.Lolornot ? " unlolled " : " unlaughed ") - + (lol.Lolowner instanceof Player ? ((Player) lol.Lolowner).getDisplayName() : lol.Lolowner.getName()); - Bukkit.broadcastMessage(msg); + + ThorpeUtils.getDisplayName(lol.Lolowner); + TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, msg, target); Lastlol.remove(lol.Chatevent.getChannel()); return true; }