Added toggle to party as well and made it so it can be added to other channels if needed
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
package com.alttd.chat.commands;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.objects.channels.CustomChannel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.defaults.BukkitCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
@@ -17,8 +16,8 @@ public class ChatChannel extends BukkitCommand {
|
||||
|
||||
CustomChannel channel;
|
||||
String command;
|
||||
ToggleableForCustomChannel toggleableForCustomChannel;
|
||||
private static List<ChatChannel> activeCommands = new ArrayList<>();
|
||||
private HashSet<UUID> toggledUsers = new HashSet<>();
|
||||
|
||||
public ChatChannel(CustomChannel channel) {
|
||||
super(channel.getChannelName().toLowerCase());
|
||||
@@ -28,28 +27,7 @@ public class ChatChannel extends BukkitCommand {
|
||||
this.usageMessage = "/" + command + " <message>";
|
||||
this.setAliases(Collections.emptyList());
|
||||
activeCommands.add(this);
|
||||
}
|
||||
|
||||
public static ChatChannel getActiveChannel(UUID uuid) {
|
||||
for (ChatChannel activeCommand : activeCommands) {
|
||||
if (activeCommand.toggledUsers.contains(uuid))
|
||||
return activeCommand;
|
||||
}
|
||||
return (null);
|
||||
}
|
||||
|
||||
private void toggleChannel(UUID uuid) {
|
||||
if (toggledUsers.contains(uuid)) {
|
||||
toggledUsers.remove(uuid);
|
||||
return;
|
||||
}
|
||||
ChatChannel activeChannel = getActiveChannel(uuid);
|
||||
if (activeChannel == null) {
|
||||
toggledUsers.add(uuid);
|
||||
return;
|
||||
}
|
||||
activeChannel.toggleChannel(uuid);
|
||||
toggledUsers.add(uuid);
|
||||
this.toggleableForCustomChannel = new ToggleableForCustomChannel(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,28 +35,19 @@ public class ChatChannel extends BukkitCommand {
|
||||
if(!(sender instanceof Player player)) { // must be a player
|
||||
return true;
|
||||
}
|
||||
|
||||
if(args.length == 0) {
|
||||
toggleChannel(player.getUniqueId());
|
||||
player.sendMiniMessage(Config.PARTY_TOGGLED, TagResolver.resolver(
|
||||
Placeholder.unparsed("channel", channel.getChannelName()),
|
||||
Placeholder.unparsed("status", toggleableForCustomChannel.toggle(player.getUniqueId())
|
||||
? "<green>on</green>" : "<red>off</red>")));
|
||||
return false;
|
||||
}
|
||||
|
||||
String message = StringUtils.join(args, " ", 0, args.length);
|
||||
|
||||
sendChannelMessage(message, player);
|
||||
toggleableForCustomChannel.sendMessage(player, message);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void sendChannelMessage(Component message, Player player) {
|
||||
sendChannelMessage(PlainTextComponentSerializer.plainText().serialize(message), player);
|
||||
}
|
||||
|
||||
public void sendChannelMessage(String message, Player player) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChatPlugin.getInstance().getChatHandler().chatChannel(player, channel, message);
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.alttd.chat.commands;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.objects.Toggleable;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@@ -13,7 +12,12 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PartyChat implements CommandExecutor {
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PartyChat extends Toggleable implements CommandExecutor {
|
||||
|
||||
private final HashSet<UUID> toggledUsers = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
@@ -22,7 +26,8 @@ public class PartyChat implements CommandExecutor {
|
||||
}
|
||||
|
||||
if(args.length == 0) {
|
||||
// TODO: 08/08/2021 lock into party chat
|
||||
player.sendMiniMessage(Config.PARTY_TOGGLED, Placeholder.unparsed("status",
|
||||
toggle(player.getUniqueId()) ? "<green>on</green>" : "<red>off</red>"));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -37,4 +42,30 @@ public class PartyChat implements CommandExecutor {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isToggled(UUID uuid) {
|
||||
return toggledUsers.contains(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOff(UUID uuid) {
|
||||
disableToggles(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOn(UUID uuid) {
|
||||
disableToggles(uuid);
|
||||
toggledUsers.add(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(Player player, String message) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChatPlugin.getInstance().getChatHandler().partyMessage(player, message);
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.alttd.chat.commands;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.objects.Toggleable;
|
||||
import com.alttd.chat.objects.channels.CustomChannel;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ToggleableForCustomChannel extends Toggleable {
|
||||
|
||||
private final CustomChannel customChannel;
|
||||
|
||||
public ToggleableForCustomChannel(CustomChannel customChannel) {
|
||||
super();
|
||||
this.customChannel = customChannel;
|
||||
}
|
||||
|
||||
private final HashSet<UUID> toggledUsers = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public boolean isToggled(UUID uuid) {
|
||||
return toggledUsers.contains(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOff(UUID uuid) {
|
||||
disableToggles(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOn(UUID uuid) {
|
||||
disableToggles(uuid);
|
||||
toggledUsers.add(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(Player player, String message) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChatPlugin.getInstance().getChatHandler().chatChannel(player, customChannel, message);
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.alttd.chat.listeners;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.commands.ChatChannel;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.handler.ChatHandler;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.ModifiableString;
|
||||
import com.alttd.chat.objects.Toggleable;
|
||||
import com.alttd.chat.util.GalaxyUtility;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import io.papermc.paper.chat.ChatRenderer;
|
||||
@@ -26,10 +26,10 @@ public class ChatListener implements Listener, ChatRenderer {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerChat(AsyncChatEvent event) {
|
||||
ChatChannel activeChannel = ChatChannel.getActiveChannel(event.getPlayer().getUniqueId());
|
||||
if (activeChannel != null) {
|
||||
Toggleable toggleable = Toggleable.getToggleable(event.getPlayer().getUniqueId());
|
||||
if (toggleable != null) {
|
||||
event.setCancelled(true);
|
||||
activeChannel.sendChannelMessage(event.message(), event.getPlayer());
|
||||
toggleable.sendMessage(event.getPlayer(), event.message());
|
||||
return;
|
||||
}
|
||||
if (ChatPlugin.getInstance().serverMuted() && !event.getPlayer().hasPermission("chat.bypass-server-muted")) {
|
||||
|
||||
Reference in New Issue
Block a user