Added toggle to party as well and made it so it can be added to other channels if needed

This commit is contained in:
2022-05-24 04:17:55 +02:00
parent 60e1ad2220
commit 41897f4b16
8 changed files with 171 additions and 57 deletions
@@ -6,10 +6,11 @@ import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import io.leangen.geantyref.TypeToken;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.ConfigurationOptions;
import org.spongepowered.configurate.serialize.SerializationException;
import org.spongepowered.configurate.yaml.NodeStyle;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import java.io.File;
import java.io.IOException;
@@ -18,8 +19,6 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.regex.Pattern;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import org.spongepowered.configurate.ConfigurationOptions;
public final class Config {
private static final Pattern PATH_PATTERN = Pattern.compile("\\.");
@@ -294,6 +293,7 @@ public final class Config {
Members: <members>""";
public static Component ONLINE_PREFIX = null;
public static Component OFFLINE_PREFIX = null;
public static String PARTY_TOGGLED = "<dark_aqua>Party chat toggled <status>.</dark_aqua>";
private static void party() {
PARTY_FORMAT = getString("party.format", PARTY_FORMAT);
PARTY_SPY = getString("party.spy", PARTY_SPY);
@@ -327,6 +327,7 @@ public final class Config {
ALREADY_IN_THIS_PARTY = getString("party.messages.already-in-this-party", ALREADY_IN_THIS_PARTY);
ONLINE_PREFIX = Utility.parseMiniMessage(getString("party.messages.online-prefix", "<green>■ </green>"));
OFFLINE_PREFIX = Utility.parseMiniMessage(getString("party.messages.offline-prefix", "<red>■ </red>"));
PARTY_TOGGLED = getString("party.messages.party-toggled", PARTY_TOGGLED);
}
public static String PARTY_HELP_WRAPPER = "<gold>ChatParty help:\n<commands></gold>";
@@ -358,6 +359,7 @@ public final class Config {
PARTY_HELP_CHAT = getString("party.help.chat", PARTY_HELP_CHAT);
}
public static String CUSTOM_CHANNEL_TOGGLED = "<yellow>Toggled <channel> <status>.</yellow>";
private static void chatChannels() {
ConfigurationNode node = getNode("chat-channels");
if (node.empty()) {
@@ -375,6 +377,8 @@ public final class Config {
getList(key + "servers", Collections.EMPTY_LIST),
getBoolean(key + "proxy", false));
}
CUSTOM_CHANNEL_TOGGLED = getString("chat-channels-messages.channel-toggled", CUSTOM_CHANNEL_TOGGLED);
}
public static String SERVERMUTEPERMISSION = "chat.command.mute-server";
@@ -0,0 +1,62 @@
package com.alttd.chat.objects;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public abstract class Toggleable {
private static final List<Toggleable> togglableClasses = new ArrayList<>();
public Toggleable() {
togglableClasses.add(this);
}
public static Toggleable getToggleable(UUID uuid) {
for (Toggleable toggleableClass : togglableClasses) {
if (toggleableClass.isToggled(uuid))
return toggleableClass;
}
return null;
}
public abstract boolean isToggled(UUID uuid);
public abstract void setOff(UUID uuid);
public boolean toggle(UUID uuid) {
if (isToggled(uuid)) {
setOff(uuid);
return (false);
}
for (Toggleable toggleable : togglableClasses) {
if (toggleable.isToggled(uuid)) {
setOff(uuid);
break;
}
}
setOn(uuid);
return (true);
}
public abstract void setOn(UUID uuid);
public void disableToggles(UUID uuid) {
for (Toggleable toggleable : togglableClasses) {
if (toggleable.isToggled(uuid)) {
setOff(uuid);
}
}
}
public void sendMessage(Player player, Component message) {
sendMessage(player, PlainTextComponentSerializer.plainText().serialize(message));
}
public abstract void sendMessage(Player player, String message);
}
@@ -3,7 +3,7 @@ package com.alttd.chat.objects.channels;
import java.util.Collection;
import java.util.HashMap;
public abstract class Channel {
public class Channel {
public static HashMap<String, Channel> channels = new HashMap<>();
protected String permission;
@@ -1,6 +1,6 @@
package com.alttd.chat.objects.channels;
public class DefaultChannel extends Channel{
public abstract class DefaultChannel extends Channel{
public DefaultChannel(String channelName, String format, boolean proxy) {
super(channelName, format, proxy);
}