mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Simplify channel configs
This commit is contained in:
1 parent
3491edd900
commit
f32c515136
9 files changed
+109
-803
No files matched your search
@@ -13,10 +13,12 @@ import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class SimpleChat extends JavaPlugin {
|
||||
|
||||
private ArrayList<ChatChannel> channels = new ArrayList<>();
|
||||
private ArrayList<Pattern> itemPatterns = new ArrayList<>();
|
||||
|
||||
private Permission permission;
|
||||
|
||||
@@ -70,6 +72,7 @@ public final class SimpleChat extends JavaPlugin {
|
||||
|
||||
// Setup listeners
|
||||
setupListeners();
|
||||
reloadPatterns();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -92,6 +95,14 @@ public final class SimpleChat extends JavaPlugin {
|
||||
pluginManager.registerEvents(new ShadowMuteHandler(), this);
|
||||
}
|
||||
|
||||
public void reloadPatterns() {
|
||||
itemPatterns.clear();
|
||||
|
||||
for (String entry : getConfig().getStringList("item-link-placeholders")) {
|
||||
itemPatterns.add(Pattern.compile(Pattern.quote(entry)));
|
||||
}
|
||||
}
|
||||
|
||||
public ChatChannel getDefaultChannel() {
|
||||
for (ChatChannel channel : channels) {
|
||||
if (channel.isDefault()) {
|
||||
|
||||
@@ -13,8 +13,8 @@ import java.util.Map;
|
||||
|
||||
public class AllianceChatChannel extends SimpleChatChannel {
|
||||
|
||||
AllianceChatChannel(TextColor color, Map<String, String> formats, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, boolean firstMatchingGroup, SimpleChat simpleChat) {
|
||||
super(color, formats, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
||||
public AllianceChatChannel(String name, SimpleChat simpleChat) {
|
||||
super(name, simpleChat);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,130 +59,4 @@ public class AllianceChatChannel extends SimpleChatChannel {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static AllianceChatChannel.Builder allianceBuilder(String name) {
|
||||
return new AllianceChatChannel.Builder(name);
|
||||
}
|
||||
|
||||
public static class Builder extends ChatChannel.Builder {
|
||||
|
||||
private TextColor color = TextColor.of(255, 255, 255);
|
||||
private Map<String, String> formats = new HashMap<>();
|
||||
private boolean isDefault = false;
|
||||
private boolean ignorable = true;
|
||||
private String name;
|
||||
private double distance = -1;
|
||||
private String switchMessage = "<gray>You are now in <color><channel> <gray>chat!";
|
||||
private String toggleOffMessage = "<gray>You can no longer see <color><channel> <gray>chat!";
|
||||
private String toggleOnMessage = "<gray>You can now see <color><channel> <gray>chat!";
|
||||
private boolean forwardFormatting = true;
|
||||
private boolean shouldBungee = false;
|
||||
private boolean filterEnabled = true;
|
||||
private boolean firstMatchingGroup = false;
|
||||
|
||||
Builder(String name) {
|
||||
this.name = name.toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllianceChatChannel build(SimpleChat simpleChat) {
|
||||
return new AllianceChatChannel(color, formats, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllianceChatChannel.Builder setColor(TextColor color) {
|
||||
this.color = color;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllianceChatChannel.Builder setColor(String color) {
|
||||
return setColor(TextColor.fromHexString(color));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllianceChatChannel.Builder setFormats(Map<String, String> formats) {
|
||||
this.formats = formats;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllianceChatChannel.Builder setIsDefault(boolean aDefault) {
|
||||
this.isDefault = aDefault;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllianceChatChannel.Builder setIgnorable(boolean ignorable) {
|
||||
this.ignorable = ignorable;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllianceChatChannel.Builder setName(String name) {
|
||||
this.name = name;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllianceChatChannel.Builder setDistance(double distance) {
|
||||
this.distance = distance;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllianceChatChannel.Builder setSwitchMessage(String switchMessage) {
|
||||
this.switchMessage = switchMessage;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllianceChatChannel.Builder setToggleOffMessage(String toggleOffMessage) {
|
||||
this.toggleOffMessage = toggleOffMessage;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllianceChatChannel.Builder setToggleOnMessage(String toggleOnMessage) {
|
||||
this.toggleOnMessage = toggleOnMessage;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllianceChatChannel.Builder setShouldForwardFormatting(boolean forwardFormatting) {
|
||||
this.forwardFormatting = forwardFormatting;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllianceChatChannel.Builder setShouldBungee(boolean shouldBungee) {
|
||||
this.shouldBungee = shouldBungee;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllianceChatChannel.Builder setFilterEnabled(boolean filterEnabled) {
|
||||
this.filterEnabled = filterEnabled;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllianceChatChannel.Builder setFirstMatchingGroup(boolean firstMatchingGroup) {
|
||||
this.firstMatchingGroup = firstMatchingGroup;
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,8 +14,8 @@ import java.util.Map;
|
||||
|
||||
public class NationChatChannel extends SimpleChatChannel {
|
||||
|
||||
NationChatChannel(TextColor color, Map<String, String> formats, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, boolean firstMatchingGroup, SimpleChat simpleChat) {
|
||||
super(color, formats, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
||||
public NationChatChannel(String name, SimpleChat simpleChat) {
|
||||
super(name, simpleChat);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,130 +82,4 @@ public class NationChatChannel extends SimpleChatChannel {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static NationChatChannel.Builder nationBuilder(String name) {
|
||||
return new NationChatChannel.Builder(name);
|
||||
}
|
||||
|
||||
public static class Builder extends ChatChannel.Builder {
|
||||
|
||||
private TextColor color = TextColor.of(255, 255, 255);
|
||||
private Map<String, String> formats = new HashMap<>();
|
||||
private boolean isDefault = false;
|
||||
private boolean ignorable = true;
|
||||
private String name;
|
||||
private double distance = -1;
|
||||
private String switchMessage = "<gray>You are now in <color><channel> <gray>chat!";
|
||||
private String toggleOffMessage = "<gray>You can no longer see <color><channel> <gray>chat!";
|
||||
private String toggleOnMessage = "<gray>You can now see <color><channel> <gray>chat!";
|
||||
private boolean forwardFormatting = true;
|
||||
private boolean shouldBungee = false;
|
||||
private boolean filterEnabled = true;
|
||||
private boolean firstMatchingGroup = false;
|
||||
|
||||
Builder(String name) {
|
||||
this.name = name.toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NationChatChannel build(SimpleChat simpleChat) {
|
||||
return new NationChatChannel(color, formats, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NationChatChannel.Builder setColor(TextColor color) {
|
||||
this.color = color;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NationChatChannel.Builder setColor(String color) {
|
||||
return setColor(TextColor.fromHexString(color));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NationChatChannel.Builder setFormats(Map<String, String> formats) {
|
||||
this.formats = formats;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NationChatChannel.Builder setIsDefault(boolean aDefault) {
|
||||
this.isDefault = aDefault;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NationChatChannel.Builder setIgnorable(boolean ignorable) {
|
||||
this.ignorable = ignorable;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NationChatChannel.Builder setName(String name) {
|
||||
this.name = name;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NationChatChannel.Builder setDistance(double distance) {
|
||||
this.distance = distance;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NationChatChannel.Builder setSwitchMessage(String switchMessage) {
|
||||
this.switchMessage = switchMessage;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NationChatChannel.Builder setToggleOffMessage(String toggleOffMessage) {
|
||||
this.toggleOffMessage = toggleOffMessage;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NationChatChannel.Builder setToggleOnMessage(String toggleOnMessage) {
|
||||
this.toggleOnMessage = toggleOnMessage;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NationChatChannel.Builder setShouldForwardFormatting(boolean forwardFormatting) {
|
||||
this.forwardFormatting = forwardFormatting;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NationChatChannel.Builder setShouldBungee(boolean shouldBungee) {
|
||||
this.shouldBungee = shouldBungee;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NationChatChannel.Builder setFilterEnabled(boolean filterEnabled) {
|
||||
this.filterEnabled = filterEnabled;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NationChatChannel.Builder setFirstMatchingGroup(boolean firstMatchingGroup) {
|
||||
this.firstMatchingGroup = firstMatchingGroup;
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,8 +11,8 @@ import java.util.Map;
|
||||
|
||||
public class PartyChatChannel extends SimpleChatChannel {
|
||||
|
||||
PartyChatChannel(TextColor color, Map<String, String> formats, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, boolean firstMatchingGroup, SimpleChat simpleChat) {
|
||||
super(color, formats, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
||||
public PartyChatChannel(String name, SimpleChat simpleChat) {
|
||||
super(name, simpleChat);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,130 +55,4 @@ public class PartyChatChannel extends SimpleChatChannel {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static PartyChatChannel.Builder partyBuilder(String name) {
|
||||
return new PartyChatChannel.Builder(name);
|
||||
}
|
||||
|
||||
public static class Builder extends ChatChannel.Builder {
|
||||
|
||||
private TextColor color = TextColor.of(255, 255, 255);
|
||||
private Map<String, String> formats = new HashMap<>();
|
||||
private boolean isDefault = false;
|
||||
private boolean ignorable = true;
|
||||
private String name;
|
||||
private double distance = -1;
|
||||
private String switchMessage = "<gray>You are now in <color><channel> <gray>chat!";
|
||||
private String toggleOffMessage = "<gray>You can no longer see <color><channel> <gray>chat!";
|
||||
private String toggleOnMessage = "<gray>You can now see <color><channel> <gray>chat!";
|
||||
private boolean forwardFormatting = true;
|
||||
private boolean shouldBungee = false;
|
||||
private boolean filterEnabled = true;
|
||||
private boolean firstMatchingGroup = false;
|
||||
|
||||
Builder(String name) {
|
||||
this.name = name.toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartyChatChannel build(SimpleChat simpleChat) {
|
||||
return new PartyChatChannel(color, formats, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartyChatChannel.Builder setColor(TextColor color) {
|
||||
this.color = color;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartyChatChannel.Builder setColor(String color) {
|
||||
return setColor(TextColor.fromHexString(color));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartyChatChannel.Builder setFormats(Map<String, String> formats) {
|
||||
this.formats = formats;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartyChatChannel.Builder setIsDefault(boolean aDefault) {
|
||||
this.isDefault = aDefault;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartyChatChannel.Builder setIgnorable(boolean ignorable) {
|
||||
this.ignorable = ignorable;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartyChatChannel.Builder setName(String name) {
|
||||
this.name = name;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartyChatChannel.Builder setDistance(double distance) {
|
||||
this.distance = distance;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartyChatChannel.Builder setSwitchMessage(String switchMessage) {
|
||||
this.switchMessage = switchMessage;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartyChatChannel.Builder setToggleOffMessage(String toggleOffMessage) {
|
||||
this.toggleOffMessage = toggleOffMessage;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartyChatChannel.Builder setToggleOnMessage(String toggleOnMessage) {
|
||||
this.toggleOnMessage = toggleOnMessage;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartyChatChannel.Builder setShouldForwardFormatting(boolean forwardFormatting) {
|
||||
this.forwardFormatting = forwardFormatting;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartyChatChannel.Builder setShouldBungee(boolean shouldBungee) {
|
||||
this.shouldBungee = shouldBungee;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartyChatChannel.Builder setFilterEnabled(boolean filterEnabled) {
|
||||
this.filterEnabled = filterEnabled;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartyChatChannel.Builder setFirstMatchingGroup(boolean firstMatchingGroup) {
|
||||
this.firstMatchingGroup = firstMatchingGroup;
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
@@ -19,46 +20,15 @@ import java.util.regex.Pattern;
|
||||
|
||||
public class SimpleChatChannel extends ChatChannel {
|
||||
|
||||
private TextColor color;
|
||||
private Map<String, String> formats;
|
||||
private boolean isDefault;
|
||||
private boolean ignorable;
|
||||
private String name;
|
||||
private double distance;
|
||||
private String switchMessage;
|
||||
private String toggleOffMessage;
|
||||
private String toggleOnMessage;
|
||||
private boolean forwardFormatting;
|
||||
private boolean shouldBungee;
|
||||
private boolean filterEnabled;
|
||||
private boolean firstMatchingGroup;
|
||||
|
||||
private SimpleChat simpleChat;
|
||||
|
||||
private ArrayList<Pattern> itemPatterns = new ArrayList<>();
|
||||
|
||||
private SimpleChatChannel() { }
|
||||
|
||||
SimpleChatChannel(TextColor color, Map<String, String> formats, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, boolean firstMatchingGroup, SimpleChat simpleChat) {
|
||||
this.color = color;
|
||||
this.formats = formats;
|
||||
this.isDefault = isDefault;
|
||||
this.ignorable = ignorable;
|
||||
public SimpleChatChannel(String name, SimpleChat simpleChat) {
|
||||
this.name = name;
|
||||
this.distance = distance;
|
||||
this.switchMessage = switchMessage;
|
||||
this.toggleOffMessage = toggleOffMessage;
|
||||
this.toggleOnMessage = toggleOnMessage;
|
||||
this.forwardFormatting = forwardFormatting;
|
||||
this.shouldBungee = shouldBungee;
|
||||
this.filterEnabled = filterEnabled;
|
||||
this.firstMatchingGroup = firstMatchingGroup;
|
||||
|
||||
this.simpleChat = simpleChat;
|
||||
|
||||
for (String entry : simpleChat.getConfig().getStringList("item-link-placeholders")) {
|
||||
itemPatterns.add(Pattern.compile(Pattern.quote(entry)));
|
||||
}
|
||||
}
|
||||
|
||||
SimpleChat getSimpleChat() {
|
||||
@@ -66,7 +36,7 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
}
|
||||
|
||||
private String getDiscordFormatting() {
|
||||
return formats.getOrDefault("discord-to-mc", "<gray>[<blue>Discord<gray>] <username><white>: <message>");
|
||||
return getFormats().getOrDefault("discord-to-mc", "<gray>[<blue>Discord<gray>] <username><white>: <message>");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,7 +74,7 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
// Get formatted message
|
||||
TextComponent formattedMessage = (TextComponent)MiniMessage.get().parse(formatEvent.getFormat(),
|
||||
"br", "\n",
|
||||
"color", "<color:" + color.toString() + ">",
|
||||
"color", "<color:" + getColor().toString() + ">",
|
||||
"phase", Long.toString(System.currentTimeMillis() % 25),
|
||||
"server", simpleChat.getConfig().getString("server-name", "Server"),
|
||||
"message", formatEvent.getMessage());
|
||||
@@ -230,7 +200,7 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
}
|
||||
|
||||
for (String entry : groups) {
|
||||
if (formats.containsKey(entry.toLowerCase())) {
|
||||
if (getFormats().containsKey(entry.toLowerCase())) {
|
||||
group = entry;
|
||||
break;
|
||||
}
|
||||
@@ -286,12 +256,25 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
}
|
||||
|
||||
public Map<String, String> getFormats() {
|
||||
HashMap<String, String> formats = new HashMap<>();
|
||||
|
||||
ConfigurationSection section = simpleChat.getConfig().getConfigurationSection(getName());
|
||||
ConfigurationSection formatSection = section.getConfigurationSection("formats");
|
||||
|
||||
if (formatSection == null) {
|
||||
formatSection = simpleChat.getConfig().getConfigurationSection("default").getConfigurationSection("formats");
|
||||
}
|
||||
|
||||
for (String key : formatSection.getKeys(false)) {
|
||||
formats.put(key, formatSection.getString(key));
|
||||
}
|
||||
|
||||
return formats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextColor getColor() {
|
||||
return color;
|
||||
return TextColor.fromHexString((String) getSetting("color"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -301,17 +284,17 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
|
||||
@Override
|
||||
public boolean isDefault() {
|
||||
return isDefault;
|
||||
return (Boolean) getSetting("default");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIgnorable() {
|
||||
return ignorable;
|
||||
return (Boolean)getSetting("ignorable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBungee() {
|
||||
return shouldBungee;
|
||||
return (Boolean) getSetting("should-bungee");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -321,170 +304,63 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
|
||||
@Override
|
||||
public double getDistance() {
|
||||
return distance;
|
||||
return (Integer) getSetting("distance");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSwitchMessage() {
|
||||
return switchMessage;
|
||||
return (String) getSetting("switch-message");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToggleOffMessage() {
|
||||
return toggleOffMessage;
|
||||
return (String) getSetting("toggle-off-message");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToggleOnMessage() {
|
||||
return toggleOnMessage;
|
||||
return (String) getSetting("toggle-on-message");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldForwardFormatting() {
|
||||
return forwardFormatting;
|
||||
return (Boolean) getSetting("forward-format");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean filterEnabled() {
|
||||
return filterEnabled;
|
||||
return (Boolean) getSetting("filter-enabled");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean firstMatchingGroup() {
|
||||
return firstMatchingGroup;
|
||||
return (Boolean) getSetting("first-matching-group");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pattern> getItemLinkPatterns() {
|
||||
ArrayList<Pattern> itemPatterns = new ArrayList<>();
|
||||
|
||||
for (String entry : simpleChat.getConfig().getStringList("item-link-placeholders")) {
|
||||
itemPatterns.add(Pattern.compile(Pattern.quote(entry)));
|
||||
}
|
||||
|
||||
return itemPatterns;
|
||||
}
|
||||
|
||||
public static SimpleChatChannel.Builder builder(String name) {
|
||||
return new SimpleChatChannel.Builder(name);
|
||||
private Object getSetting(String key) {
|
||||
ConfigurationSection section = simpleChat.getConfig().getConfigurationSection(getName());
|
||||
|
||||
if (section.contains(key)) {
|
||||
return section.get(key);
|
||||
}
|
||||
|
||||
ConfigurationSection defaultSection = simpleChat.getConfig().getConfigurationSection("default");
|
||||
|
||||
if (defaultSection.contains(key)) {
|
||||
return defaultSection.get(key);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class Builder extends ChatChannel.Builder {
|
||||
|
||||
private TextColor color = TextColor.of(255, 255, 255);
|
||||
private Map<String, String> formats = new HashMap<>();
|
||||
private boolean isDefault = false;
|
||||
private boolean ignorable = true;
|
||||
private String name;
|
||||
private double distance = -1;
|
||||
private String switchMessage = "<gray>You are now in <color><channel> <gray>chat!";
|
||||
private String toggleOffMessage = "<gray>You can no longer see <color><channel> <gray>chat!";
|
||||
private String toggleOnMessage = "<gray>You can now see <color><channel> <gray>chat!";
|
||||
private boolean forwardFormatting = true;
|
||||
private boolean shouldBungee = false;
|
||||
private boolean filterEnabled = true;
|
||||
private boolean firstMatchingGroup = false;
|
||||
|
||||
private Builder() { }
|
||||
|
||||
Builder(String name) {
|
||||
this.name = name.toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimpleChatChannel build(SimpleChat simpleChat) {
|
||||
return new SimpleChatChannel(color, formats, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setColor(TextColor color) {
|
||||
this.color = color;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setColor(String color) {
|
||||
return setColor(TextColor.fromHexString(color));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setFormats(Map<String, String> formats) {
|
||||
this.formats = formats;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setIsDefault(boolean aDefault) {
|
||||
this.isDefault = aDefault;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setIgnorable(boolean ignorable) {
|
||||
this.ignorable = ignorable;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setName(String name) {
|
||||
this.name = name;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setDistance(double distance) {
|
||||
this.distance = distance;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setSwitchMessage(String switchMessage) {
|
||||
this.switchMessage = switchMessage;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setToggleOffMessage(String toggleOffMessage) {
|
||||
this.toggleOffMessage = toggleOffMessage;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setToggleOnMessage(String toggleOnMessage) {
|
||||
this.toggleOnMessage = toggleOnMessage;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setShouldForwardFormatting(boolean forwardFormatting) {
|
||||
this.forwardFormatting = forwardFormatting;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setShouldBungee(boolean shouldBungee) {
|
||||
this.shouldBungee = shouldBungee;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setFilterEnabled(boolean filterEnabled) {
|
||||
this.filterEnabled = filterEnabled;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setFirstMatchingGroup(boolean firstMatchingGroup) {
|
||||
this.firstMatchingGroup = firstMatchingGroup;
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,8 +13,8 @@ import java.util.Map;
|
||||
|
||||
public class TownChatChannel extends SimpleChatChannel {
|
||||
|
||||
TownChatChannel(TextColor color, Map<String, String> formats, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, boolean firstMatchingGroup, SimpleChat simpleChat) {
|
||||
super(color, formats, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
||||
public TownChatChannel(String name, SimpleChat simpleChat) {
|
||||
super(name, simpleChat);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,133 +77,4 @@ public class TownChatChannel extends SimpleChatChannel {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static TownChatChannel.Builder townBuilder(String name) {
|
||||
return new TownChatChannel.Builder(name);
|
||||
}
|
||||
|
||||
public static class Builder extends ChatChannel.Builder {
|
||||
|
||||
private TextColor color = TextColor.of(255, 255, 255);
|
||||
private long id = -1;
|
||||
private Map<String, String> formats = new HashMap<>();
|
||||
private String webhook = null;
|
||||
private boolean isDefault = false;
|
||||
private boolean ignorable = true;
|
||||
private String name;
|
||||
private double distance = -1;
|
||||
private String switchMessage = "<gray>You are now in <color><channel> <gray>chat!";
|
||||
private String toggleOffMessage = "<gray>You can no longer see <color><channel> <gray>chat!";
|
||||
private String toggleOnMessage = "<gray>You can now see <color><channel> <gray>chat!";
|
||||
private boolean forwardFormatting = true;
|
||||
private boolean shouldBungee = false;
|
||||
private boolean filterEnabled = true;
|
||||
private boolean firstMatchingGroup = false;
|
||||
|
||||
Builder(String name) {
|
||||
this.name = name.toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TownChatChannel build(SimpleChat simpleChat) {
|
||||
return new TownChatChannel(color, formats, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TownChatChannel.Builder setColor(TextColor color) {
|
||||
this.color = color;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TownChatChannel.Builder setColor(String color) {
|
||||
return setColor(TextColor.fromHexString(color));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TownChatChannel.Builder setFormats(Map<String, String> formats) {
|
||||
this.formats = formats;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TownChatChannel.Builder setIsDefault(boolean aDefault) {
|
||||
this.isDefault = aDefault;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TownChatChannel.Builder setIgnorable(boolean ignorable) {
|
||||
this.ignorable = ignorable;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TownChatChannel.Builder setName(String name) {
|
||||
this.name = name;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TownChatChannel.Builder setDistance(double distance) {
|
||||
this.distance = distance;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TownChatChannel.Builder setSwitchMessage(String switchMessage) {
|
||||
this.switchMessage = switchMessage;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TownChatChannel.Builder setToggleOffMessage(String toggleOffMessage) {
|
||||
this.toggleOffMessage = toggleOffMessage;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TownChatChannel.Builder setToggleOnMessage(String toggleOnMessage) {
|
||||
this.toggleOnMessage = toggleOnMessage;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TownChatChannel.Builder setShouldForwardFormatting(boolean forwardFormatting) {
|
||||
this.forwardFormatting = forwardFormatting;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TownChatChannel.Builder setShouldBungee(boolean shouldBungee) {
|
||||
this.shouldBungee = shouldBungee;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TownChatChannel.Builder setFilterEnabled(boolean filterEnabled) {
|
||||
this.filterEnabled = filterEnabled;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TownChatChannel.Builder setFirstMatchingGroup(boolean firstMatchingGroup) {
|
||||
this.firstMatchingGroup = firstMatchingGroup;
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -22,8 +22,8 @@ public class ChatReloadCommand extends BaseCommand {
|
||||
@Default
|
||||
public void baseCommand(CommandSender sender) {
|
||||
simpleChat.reloadConfig();
|
||||
|
||||
// TODO: clear item patterns in SimpleChatChannel
|
||||
simpleChat.getChannelManager().reloadChannels();
|
||||
simpleChat.reloadPatterns();
|
||||
|
||||
Component message = MiniMessage.get().parse(simpleChat.getConfig().getString("language.reloaded"),
|
||||
"br", "\n");
|
||||
|
||||
@@ -8,8 +8,6 @@ import net.draycia.simplechat.commands.AliasedChannelCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ChannelManager {
|
||||
|
||||
public ChannelManager(SimpleChat simpleChat) {
|
||||
@@ -19,126 +17,48 @@ public class ChannelManager {
|
||||
boolean hasPartyChat = false;
|
||||
|
||||
for (String key : simpleChat.getConfig().getConfigurationSection("channels").getKeys(false)) {
|
||||
ChatChannel.Builder builder;
|
||||
ChatChannel channel;
|
||||
|
||||
ConfigurationSection section = simpleChat.getConfig().getConfigurationSection("channels").getConfigurationSection(key);
|
||||
ConfigurationSection defaults = simpleChat.getConfig().getConfigurationSection("default");
|
||||
|
||||
String name = key;
|
||||
|
||||
if (section.contains("is-town-chat")) {
|
||||
builder = TownChatChannel.townBuilder(key);
|
||||
hasTownChat = true;
|
||||
} else if (section.contains("is-nation-chat")) {
|
||||
builder = NationChatChannel.nationBuilder(key);
|
||||
hasNationChat = true;
|
||||
} else if (section.contains("is-alliance-chat")) {
|
||||
builder = AllianceChatChannel.allianceBuilder(key);
|
||||
hasAllianceChat = true;
|
||||
} else if (section.contains("is-party-chat")) {
|
||||
builder = PartyChatChannel.partyBuilder(key);
|
||||
hasPartyChat = true;
|
||||
} else {
|
||||
builder = SimpleChatChannel.builder(key);
|
||||
}
|
||||
|
||||
if (section.contains("formats")) {
|
||||
HashMap<String, String> formats = new HashMap<>();
|
||||
|
||||
ConfigurationSection formatSection = section.getConfigurationSection("formats");
|
||||
|
||||
for (String group : formatSection.getKeys(false)) {
|
||||
formats.put(group, formatSection.getString(group));
|
||||
}
|
||||
|
||||
builder.setFormats(formats);
|
||||
} else if (defaults != null && defaults.contains("formats")) {
|
||||
HashMap<String, String> formats = new HashMap<>();
|
||||
|
||||
ConfigurationSection formatSection = defaults.getConfigurationSection("formats");
|
||||
|
||||
for (String group : formatSection.getKeys(false)) {
|
||||
formats.put(group, formatSection.getString(group));
|
||||
}
|
||||
|
||||
builder.setFormats(formats);
|
||||
}
|
||||
|
||||
if (section.contains("switch-message")) {
|
||||
builder.setSwitchMessage(section.getString("switch-message"));
|
||||
} else if (defaults != null && defaults.contains("switch-message")) {
|
||||
builder.setSwitchMessage(defaults.getString("switch-message"));
|
||||
}
|
||||
|
||||
if (section.contains("distance")) {
|
||||
builder.setDistance(section.getDouble("distance"));
|
||||
} else if (defaults != null && defaults.contains("distance")) {
|
||||
builder.setDistance(defaults.getDouble("distance"));
|
||||
}
|
||||
|
||||
if (section.contains("name")) {
|
||||
name = section.getString("name");
|
||||
//builder.setName(section.getString("name"));
|
||||
}
|
||||
|
||||
if (section.contains("color")) {
|
||||
builder.setColor(section.getString("color"));
|
||||
} else if (defaults != null && defaults.contains("color")) {
|
||||
builder.setColor(defaults.getString("color"));
|
||||
}
|
||||
|
||||
if (section.contains("ignorable")) {
|
||||
builder.setIgnorable(section.getBoolean("ignorable"));
|
||||
} else if (defaults != null && defaults.contains("ignorable")) {
|
||||
builder.setIgnorable(defaults.getBoolean("ignorable"));
|
||||
}
|
||||
|
||||
if (section.contains("default")) {
|
||||
builder.setIsDefault(section.getBoolean("default"));
|
||||
}
|
||||
|
||||
if (section.contains("toggle-on-message")) {
|
||||
builder.setToggleOnMessage(section.getString("toggle-on-message"));
|
||||
} else if (defaults != null && defaults.contains("toggle-on-message")) {
|
||||
builder.setToggleOnMessage(defaults.getString("toggle-on-message"));
|
||||
}
|
||||
|
||||
if (section.contains("toggle-off-message")) {
|
||||
builder.setToggleOffMessage(section.getString("toggle-off-message"));
|
||||
} else if (defaults != null && defaults.contains("toggle-off-message")) {
|
||||
builder.setToggleOffMessage(defaults.getString("toggle-off-message"));
|
||||
}
|
||||
|
||||
if (section.contains("forward-format")) {
|
||||
builder.setShouldForwardFormatting(section.getBoolean("forward-format"));
|
||||
} else if (defaults != null && defaults.contains("forward-format")) {
|
||||
builder.setShouldForwardFormatting(defaults.getBoolean("forward-format"));
|
||||
}
|
||||
|
||||
if (section.contains("should-bungee")) {
|
||||
builder.setShouldBungee(section.getBoolean("should-bungee"));
|
||||
} else if (defaults != null && defaults.contains("should-bungee")) {
|
||||
builder.setShouldBungee(defaults.getBoolean("should-bungee"));
|
||||
}
|
||||
|
||||
if (section.contains("filter-enabled")) {
|
||||
builder.setFilterEnabled(section.getBoolean("filter-enabled"));
|
||||
} else if (defaults != null && defaults.contains("filter-enabled")) {
|
||||
builder.setFilterEnabled(defaults.getBoolean("filter-enabled"));
|
||||
}
|
||||
|
||||
if (section.contains("first-matching-group")) {
|
||||
builder.setFirstMatchingGroup(section.getBoolean("first-matching-group"));
|
||||
} else if (defaults != null && defaults.contains("first-matching-group")) {
|
||||
builder.setFirstMatchingGroup(defaults.getBoolean("first-matching-group"));
|
||||
}
|
||||
String name = section.contains("name") ? section.getString("name") : key;
|
||||
|
||||
if (name.length() > 16) {
|
||||
simpleChat.getLogger().warning("Channel name [" + name + "] too long! Max length: 16.");
|
||||
simpleChat.getLogger().warning("Skipping channel, please check your settings!");
|
||||
continue;
|
||||
}
|
||||
|
||||
ChatChannel channel = builder.build(simpleChat);
|
||||
String type = section.getString("type");
|
||||
|
||||
if (type == null) {
|
||||
type = "normal";
|
||||
}
|
||||
|
||||
switch (type.toLowerCase()) {
|
||||
case "towny":
|
||||
channel = new TownChatChannel(name, simpleChat);
|
||||
hasTownChat = true;
|
||||
break;
|
||||
case "nation":
|
||||
channel = new NationChatChannel(name, simpleChat);
|
||||
hasNationChat = true;
|
||||
break;
|
||||
case "alliance":
|
||||
channel = new AllianceChatChannel(name, simpleChat);
|
||||
hasAllianceChat = true;
|
||||
break;
|
||||
case "party":
|
||||
channel = new PartyChatChannel(name, simpleChat);
|
||||
hasPartyChat = true;
|
||||
break;
|
||||
case "normal":
|
||||
channel = new SimpleChatChannel(name, simpleChat);
|
||||
break;
|
||||
default:
|
||||
simpleChat.getLogger().warning("Invalid channel type for channel [" + key + "]. Skipping channel.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (channel.isTownChat() || channel.isNationChat() || channel.isAllianceChat()) {
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled("Towny")) {
|
||||
@@ -184,4 +104,8 @@ public class ChannelManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadChannels() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user