uyh7777777777777777777777777777777777

This commit is contained in:
Draycia committed 2020-07-14 03:16:44 -07:00
1 parent 9f98f6a42d
commit 15f2c6c20f
7 files changed
+53 -32

No files matched your search

@@ -5,6 +5,7 @@ import net.draycia.simplechat.channels.ChatChannel;
import net.draycia.simplechat.events.ChatComponentEvent; import net.draycia.simplechat.events.ChatComponentEvent;
import net.draycia.simplechat.events.ChatFormatEvent; import net.draycia.simplechat.events.ChatFormatEvent;
import net.draycia.simplechat.storage.ChatUser; import net.draycia.simplechat.storage.ChatUser;
import net.kyori.adventure.audience.MessageType;
import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@@ -97,9 +98,9 @@ public class SimpleChatChannel extends ChatChannel {
if (isUserSpying(user, chatUser)) { if (isUserSpying(user, chatUser)) {
prefix = prefix.replace("<color>", "<color:" + getColor() + ">"); prefix = prefix.replace("<color>", "<color:" + getColor() + ">");
chatUser.sendMessage(simpleChat.processMessage(prefix).append(componentEvent.getComponent())); chatUser.sendMessage(simpleChat.processMessage(prefix).append(componentEvent.getComponent()), MessageType.CHAT);
} else if (componentEvent.getRecipients().contains(chatUser)) { } else if (componentEvent.getRecipients().contains(chatUser)) {
chatUser.sendMessage(componentEvent.getComponent()); chatUser.sendMessage(componentEvent.getComponent(), MessageType.CHAT);
} }
} else { } else {
prefix = prefix.replace("<color>", "<color:" + prefix = prefix.replace("<color>", "<color:" +
@@ -125,7 +126,7 @@ public class SimpleChatChannel extends ChatChannel {
Bukkit.getPluginManager().callEvent(newEvent); Bukkit.getPluginManager().callEvent(newEvent);
chatUser.sendMessage(newEvent.getComponent()); chatUser.sendMessage(newEvent.getComponent(), MessageType.CHAT);
} }
} }
@@ -266,7 +267,7 @@ public class SimpleChatChannel extends ChatChannel {
@Override @Override
public TextColor getColor() { public TextColor getColor() {
return TextColor.fromHexString(getSetting("color")); return TextColor.fromHexString(getString("color"));
} }
@Override @Override
@@ -277,73 +278,73 @@ public class SimpleChatChannel extends ChatChannel {
@Override @Override
public Boolean isDefault() { public Boolean isDefault() {
return getSetting("default") == null ? false : getSetting("default"); return getBoolean("default");
} }
@Override @Override
public Boolean isIgnorable() { public Boolean isIgnorable() {
return getSetting("ignorable"); return getBoolean("ignorable");
} }
@Override @Override
public Boolean shouldBungee() { public Boolean shouldBungee() {
return getSetting("should-bungee"); return getBoolean("should-bungee");
} }
@Override @Override
public String getName() { public String getName() {
String name = getSetting("name"); String name = getString("name");
return name == null ? key : name; return name == null ? key : name;
} }
@Override @Override
public Double getDistance() { public Double getDistance() {
return this.getSetting("distance"); return getDouble("distance");
} }
@Override @Override
public String getSwitchMessage() { public String getSwitchMessage() {
return getSetting("switch-message"); return getString("switch-message");
} }
@Override @Override
public String getSwitchOtherMessage() { public String getSwitchOtherMessage() {
return getSetting("switch-other-message"); return getString("switch-other-message");
} }
@Override @Override
public String getToggleOffMessage() { public String getToggleOffMessage() {
return getSetting("toggle-off-message"); return getString("toggle-off-message");
} }
@Override @Override
public String getToggleOnMessage() { public String getToggleOnMessage() {
return getSetting("toggle-on-message"); return getString("toggle-on-message");
} }
@Override @Override
public String getToggleOtherOnMessage() { public String getToggleOtherOnMessage() {
return getSetting("toggle-other-on"); return getString("toggle-other-on");
} }
@Override @Override
public String getToggleOtherOffMessage() { public String getToggleOtherOffMessage() {
return getSetting("toggle-other-off"); return getString("toggle-other-off");
} }
@Override @Override
public String getCannotUseMessage() { public String getCannotUseMessage() {
return getSetting("cannot-use-channel"); return getString("cannot-use-channel");
} }
@Override @Override
public Boolean shouldForwardFormatting() { public Boolean shouldForwardFormatting() {
return getSetting("forward-format"); return getBoolean("forward-format");
} }
@Override @Override
public Boolean firstMatchingGroup() { public Boolean firstMatchingGroup() {
return getSetting("first-matching-group"); return getBoolean("first-matching-group");
} }
@Override @Override
@@ -357,38 +358,55 @@ public class SimpleChatChannel extends ChatChannel {
return itemPatterns; return itemPatterns;
} }
private <T> T getSetting(String key) { private String getString(String key) {
ConfigurationSection channelsSection = simpleChat.getConfig().getConfigurationSection("channels"); ConfigurationSection channelsSection = simpleChat.getConfig().getConfigurationSection("channels");
ConfigurationSection section = channelsSection.getConfigurationSection(getKey()); ConfigurationSection section = channelsSection.getConfigurationSection(getKey());
if (section != null && section.contains(key)) { if (section != null && section.contains(key)) {
return (T)section.get(key); return section.getString(key);
} }
ConfigurationSection defaultSection = simpleChat.getConfig().getConfigurationSection("default"); ConfigurationSection defaultSection = simpleChat.getConfig().getConfigurationSection("default");
if (defaultSection != null && defaultSection.contains(key)) { if (defaultSection != null && defaultSection.contains(key)) {
return (T)defaultSection.get(key); return defaultSection.getString(key);
} }
return null; return null;
} }
private <T> T getSetting(String key, T def) { private boolean getBoolean(String key) {
ConfigurationSection channelsSection = simpleChat.getConfig().getConfigurationSection("channels"); ConfigurationSection channelsSection = simpleChat.getConfig().getConfigurationSection("channels");
ConfigurationSection section = channelsSection.getConfigurationSection(getKey()); ConfigurationSection section = channelsSection.getConfigurationSection(getKey());
if (section != null && section.contains(key)) { if (section != null && section.contains(key)) {
return (T)section.get(key, def); return section.getBoolean(key);
} }
ConfigurationSection defaultSection = simpleChat.getConfig().getConfigurationSection("default"); ConfigurationSection defaultSection = simpleChat.getConfig().getConfigurationSection("default");
if (defaultSection != null && defaultSection.contains(key)) { if (defaultSection != null && defaultSection.contains(key)) {
return (T)defaultSection.get(key, def); return defaultSection.getBoolean(key);
} }
return null; return false;
}
private double getDouble(String key) {
ConfigurationSection channelsSection = simpleChat.getConfig().getConfigurationSection("channels");
ConfigurationSection section = channelsSection.getConfigurationSection(getKey());
if (section != null && section.contains(key)) {
return section.getDouble(key);
}
ConfigurationSection defaultSection = simpleChat.getConfig().getConfigurationSection("default");
if (defaultSection != null && defaultSection.contains(key)) {
return defaultSection.getDouble(key);
}
return 0;
} }
@Override @Override
@@ -398,7 +416,7 @@ public class SimpleChatChannel extends ChatChannel {
@Override @Override
public String getAliases() { public String getAliases() {
String aliases = getSetting("aliases"); String aliases = getString("aliases");
if (aliases == null) { if (aliases == null) {
return getKey(); return getKey();
@@ -28,7 +28,7 @@ public class ChannelRegisterEvent extends Event {
private Registry<ChatChannel> registry; private Registry<ChatChannel> registry;
public ChannelRegisterEvent(List<ChatChannel> registeredChannels, Registry<ChatChannel> registry) { public ChannelRegisterEvent(List<ChatChannel> registeredChannels, Registry<ChatChannel> registry) {
super(Bukkit.isPrimaryThread()); super(!Bukkit.isPrimaryThread());
this.registeredChannels = registeredChannels; this.registeredChannels = registeredChannels;
this.registry = registry; this.registry = registry;
@@ -38,4 +38,7 @@ public class ChannelRegisterEvent extends Event {
registry.register(chatChannel.getKey(), chatChannel); registry.register(chatChannel.getKey(), chatChannel);
} }
public List<ChatChannel> getRegisteredChannels() {
return registeredChannels;
}
} }
@@ -25,7 +25,7 @@ public class ChannelSwitchEvent extends Event {
private ChatUser user; private ChatUser user;
public ChannelSwitchEvent(ChatChannel channel, ChatUser user) { public ChannelSwitchEvent(ChatChannel channel, ChatUser user) {
super(Bukkit.isPrimaryThread()); super(!Bukkit.isPrimaryThread());
this.channel = channel; this.channel = channel;
this.user = user; this.user = user;
@@ -28,7 +28,7 @@ public class ChatComponentEvent extends Event implements Cancellable {
} }
public ChatComponentEvent(ChatUser user, ChatChannel chatChannel, TextComponent component, String originalMessage, List<ChatUser> recipients, boolean customPlayerFormat) { public ChatComponentEvent(ChatUser user, ChatChannel chatChannel, TextComponent component, String originalMessage, List<ChatUser> recipients, boolean customPlayerFormat) {
super(Bukkit.isPrimaryThread()); super(!Bukkit.isPrimaryThread());
this.user = user; this.user = user;
this.chatChannel = chatChannel; this.chatChannel = chatChannel;
@@ -19,7 +19,7 @@ public class ChatFormatEvent extends Event implements Cancellable {
private String message; private String message;
public ChatFormatEvent(ChatUser user, ChatChannel chatChannel, String format, String message) { public ChatFormatEvent(ChatUser user, ChatChannel chatChannel, String format, String message) {
super(Bukkit.isPrimaryThread()); super(!Bukkit.isPrimaryThread());
this.user = user; this.user = user;
this.chatChannel = chatChannel; this.chatChannel = chatChannel;
@@ -28,7 +28,7 @@ public class PrivateMessageEvent extends Event {
private final String message; private final String message;
public PrivateMessageEvent(ChatUser sender, ChatUser target, Component senderComponent, Component targetComponent, String message) { public PrivateMessageEvent(ChatUser sender, ChatUser target, Component senderComponent, Component targetComponent, String message) {
super(Bukkit.isPrimaryThread()); super(!Bukkit.isPrimaryThread());
this.sender = sender; this.sender = sender;
this.target = target; this.target = target;
@@ -75,7 +75,7 @@ public class SimpleChatUser implements ChatUser, ForwardingAudience {
@Override @Override
public void setSelectedChannel(ChatChannel chatChannel) { public void setSelectedChannel(ChatChannel chatChannel) {
this.selectedChannel = chatChannel.getName(); this.selectedChannel = chatChannel.getKey();
syncToRedis(); syncToRedis();
Bukkit.getPluginManager().callEvent(new ChannelSwitchEvent(chatChannel, this)); Bukkit.getPluginManager().callEvent(new ChannelSwitchEvent(chatChannel, this));