mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 14:38:49 +00:00
Rip out discord
This commit is contained in:
1 parent
00190e97a0
commit
71b247826f
22 files changed
+23
-827
No files matched your search
@@ -1,9 +1,7 @@
|
|||||||
package net.draycia.simplechat;
|
package net.draycia.simplechat;
|
||||||
|
|
||||||
import net.draycia.simplechat.channels.ChatChannel;
|
import net.draycia.simplechat.channels.ChatChannel;
|
||||||
import net.draycia.simplechat.listeners.PlayerListener;
|
import net.draycia.simplechat.listeners.*;
|
||||||
import net.draycia.simplechat.listeners.VoteListener;
|
|
||||||
import net.draycia.simplechat.listeners.chat.*;
|
|
||||||
import net.draycia.simplechat.managers.*;
|
import net.draycia.simplechat.managers.*;
|
||||||
import net.draycia.simplechat.storage.UserService;
|
import net.draycia.simplechat.storage.UserService;
|
||||||
import net.draycia.simplechat.storage.impl.JSONUserService;
|
import net.draycia.simplechat.storage.impl.JSONUserService;
|
||||||
@@ -23,7 +21,6 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
private Permission permission;
|
private Permission permission;
|
||||||
|
|
||||||
private PluginMessageManager pluginMessageManager;
|
private PluginMessageManager pluginMessageManager;
|
||||||
private DiscordManager discordManager;
|
|
||||||
private CommandManager commandManager;
|
private CommandManager commandManager;
|
||||||
private ChannelManager channelManager;
|
private ChannelManager channelManager;
|
||||||
|
|
||||||
@@ -52,7 +49,6 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
|
|
||||||
// Initialize managers
|
// Initialize managers
|
||||||
pluginMessageManager = new PluginMessageManager(this);
|
pluginMessageManager = new PluginMessageManager(this);
|
||||||
discordManager = new DiscordManager(this);
|
|
||||||
commandManager = new CommandManager(this);
|
commandManager = new CommandManager(this);
|
||||||
channelManager = new ChannelManager(this);
|
channelManager = new ChannelManager(this);
|
||||||
|
|
||||||
@@ -79,12 +75,6 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
private void setupListeners() {
|
private void setupListeners() {
|
||||||
PluginManager pluginManager = getServer().getPluginManager();
|
PluginManager pluginManager = getServer().getPluginManager();
|
||||||
|
|
||||||
pluginManager.registerEvents(new PlayerListener(this), this);
|
|
||||||
|
|
||||||
if (pluginManager.isPluginEnabled("Votifier")) {
|
|
||||||
pluginManager.registerEvents(new VoteListener(this), this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register chat listeners
|
// Register chat listeners
|
||||||
pluginManager.registerEvents(new FilterHandler(this), this);
|
pluginManager.registerEvents(new FilterHandler(this), this);
|
||||||
pluginManager.registerEvents(new ItemLinkHandler(this), this);
|
pluginManager.registerEvents(new ItemLinkHandler(this), this);
|
||||||
@@ -128,10 +118,6 @@ public final class SimpleChat extends JavaPlugin {
|
|||||||
return permission;
|
return permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiscordManager getDiscordManager() {
|
|
||||||
return discordManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommandManager getCommandManager() {
|
public CommandManager getCommandManager() {
|
||||||
return commandManager;
|
return commandManager;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,21 +18,11 @@ public abstract class ChatChannel {
|
|||||||
*/
|
*/
|
||||||
public abstract TextColor getColor();
|
public abstract TextColor getColor();
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The ID of the discord channel to read messages from for chat bridging.
|
|
||||||
*/
|
|
||||||
public abstract long getChannelId();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The MiniMessage styled format for the group in this channel.
|
* @return The MiniMessage styled format for the group in this channel.
|
||||||
*/
|
*/
|
||||||
public abstract String getFormat(String group);
|
public abstract String getFormat(String group);
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The url of the webhook used to send messages to discord for chat bridging.
|
|
||||||
*/
|
|
||||||
public abstract String getWebhook();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return If this is the default (typically Global) channel players use when they're in no other channel.
|
* @return If this is the default (typically Global) channel players use when they're in no other channel.
|
||||||
*/
|
*/
|
||||||
@@ -131,17 +121,13 @@ public abstract class ChatChannel {
|
|||||||
|
|
||||||
public abstract void sendComponent(ChatUser user, Component component);
|
public abstract void sendComponent(ChatUser user, Component component);
|
||||||
|
|
||||||
public abstract void processDiscordMessage(MessageCreateEvent event);
|
|
||||||
|
|
||||||
public String processPlaceholders(ChatUser user, String input) { return input; }
|
public String processPlaceholders(ChatUser user, String input) { return input; }
|
||||||
|
|
||||||
public static abstract class Builder {
|
public static abstract class Builder {
|
||||||
public abstract ChatChannel build(SimpleChat simpleChat);
|
public abstract ChatChannel build(SimpleChat simpleChat);
|
||||||
public abstract ChatChannel.Builder setColor(TextColor color);
|
public abstract ChatChannel.Builder setColor(TextColor color);
|
||||||
public abstract ChatChannel.Builder setColor(String color);
|
public abstract ChatChannel.Builder setColor(String color);
|
||||||
public abstract ChatChannel.Builder setId(long id);
|
|
||||||
public abstract ChatChannel.Builder setFormats(Map<String, String> formats);
|
public abstract ChatChannel.Builder setFormats(Map<String, String> formats);
|
||||||
public abstract ChatChannel.Builder setWebhook(String webhook);
|
|
||||||
public abstract ChatChannel.Builder setIsDefault(boolean aDefault);
|
public abstract ChatChannel.Builder setIsDefault(boolean aDefault);
|
||||||
public abstract ChatChannel.Builder setIgnorable(boolean ignorable);
|
public abstract ChatChannel.Builder setIgnorable(boolean ignorable);
|
||||||
public abstract ChatChannel.Builder setName(String name);
|
public abstract ChatChannel.Builder setName(String name);
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class AllianceChatChannel extends SimpleChatChannel {
|
public class AllianceChatChannel extends SimpleChatChannel {
|
||||||
|
|
||||||
AllianceChatChannel(TextColor color, long id, Map<String, String> formats, String webhook, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, boolean firstMatchingGroup, SimpleChat simpleChat) {
|
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, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
super(color, formats, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -66,9 +66,7 @@ public class AllianceChatChannel extends SimpleChatChannel {
|
|||||||
public static class Builder extends ChatChannel.Builder {
|
public static class Builder extends ChatChannel.Builder {
|
||||||
|
|
||||||
private TextColor color = TextColor.of(255, 255, 255);
|
private TextColor color = TextColor.of(255, 255, 255);
|
||||||
private long id = -1;
|
|
||||||
private Map<String, String> formats = new HashMap<>();
|
private Map<String, String> formats = new HashMap<>();
|
||||||
private String webhook = null;
|
|
||||||
private boolean isDefault = false;
|
private boolean isDefault = false;
|
||||||
private boolean ignorable = true;
|
private boolean ignorable = true;
|
||||||
private String name;
|
private String name;
|
||||||
@@ -87,7 +85,7 @@ public class AllianceChatChannel extends SimpleChatChannel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AllianceChatChannel build(SimpleChat simpleChat) {
|
public AllianceChatChannel build(SimpleChat simpleChat) {
|
||||||
return new AllianceChatChannel(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
return new AllianceChatChannel(color, formats, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -102,13 +100,6 @@ public class AllianceChatChannel extends SimpleChatChannel {
|
|||||||
return setColor(TextColor.fromHexString(color));
|
return setColor(TextColor.fromHexString(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public AllianceChatChannel.Builder setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AllianceChatChannel.Builder setFormats(Map<String, String> formats) {
|
public AllianceChatChannel.Builder setFormats(Map<String, String> formats) {
|
||||||
this.formats = formats;
|
this.formats = formats;
|
||||||
@@ -116,13 +107,6 @@ public class AllianceChatChannel extends SimpleChatChannel {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public AllianceChatChannel.Builder setWebhook(String webhook) {
|
|
||||||
this.webhook = webhook;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AllianceChatChannel.Builder setIsDefault(boolean aDefault) {
|
public AllianceChatChannel.Builder setIsDefault(boolean aDefault) {
|
||||||
this.isDefault = aDefault;
|
this.isDefault = aDefault;
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class NationChatChannel extends SimpleChatChannel {
|
public class NationChatChannel extends SimpleChatChannel {
|
||||||
|
|
||||||
NationChatChannel(TextColor color, long id, Map<String, String> formats, String webhook, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, boolean firstMatchingGroup, SimpleChat simpleChat) {
|
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, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
super(color, formats, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -89,9 +89,7 @@ public class NationChatChannel extends SimpleChatChannel {
|
|||||||
public static class Builder extends ChatChannel.Builder {
|
public static class Builder extends ChatChannel.Builder {
|
||||||
|
|
||||||
private TextColor color = TextColor.of(255, 255, 255);
|
private TextColor color = TextColor.of(255, 255, 255);
|
||||||
private long id = -1;
|
|
||||||
private Map<String, String> formats = new HashMap<>();
|
private Map<String, String> formats = new HashMap<>();
|
||||||
private String webhook = null;
|
|
||||||
private boolean isDefault = false;
|
private boolean isDefault = false;
|
||||||
private boolean ignorable = true;
|
private boolean ignorable = true;
|
||||||
private String name;
|
private String name;
|
||||||
@@ -110,7 +108,7 @@ public class NationChatChannel extends SimpleChatChannel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NationChatChannel build(SimpleChat simpleChat) {
|
public NationChatChannel build(SimpleChat simpleChat) {
|
||||||
return new NationChatChannel(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
return new NationChatChannel(color, formats, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -125,13 +123,6 @@ public class NationChatChannel extends SimpleChatChannel {
|
|||||||
return setColor(TextColor.fromHexString(color));
|
return setColor(TextColor.fromHexString(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public NationChatChannel.Builder setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NationChatChannel.Builder setFormats(Map<String, String> formats) {
|
public NationChatChannel.Builder setFormats(Map<String, String> formats) {
|
||||||
this.formats = formats;
|
this.formats = formats;
|
||||||
@@ -139,13 +130,6 @@ public class NationChatChannel extends SimpleChatChannel {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public NationChatChannel.Builder setWebhook(String webhook) {
|
|
||||||
this.webhook = webhook;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NationChatChannel.Builder setIsDefault(boolean aDefault) {
|
public NationChatChannel.Builder setIsDefault(boolean aDefault) {
|
||||||
this.isDefault = aDefault;
|
this.isDefault = aDefault;
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class PartyChatChannel extends SimpleChatChannel {
|
public class PartyChatChannel extends SimpleChatChannel {
|
||||||
|
|
||||||
PartyChatChannel(TextColor color, long id, Map<String, String> formats, String webhook, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, boolean firstMatchingGroup, SimpleChat simpleChat) {
|
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, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
super(color, formats, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,9 +62,7 @@ public class PartyChatChannel extends SimpleChatChannel {
|
|||||||
public static class Builder extends ChatChannel.Builder {
|
public static class Builder extends ChatChannel.Builder {
|
||||||
|
|
||||||
private TextColor color = TextColor.of(255, 255, 255);
|
private TextColor color = TextColor.of(255, 255, 255);
|
||||||
private long id = -1;
|
|
||||||
private Map<String, String> formats = new HashMap<>();
|
private Map<String, String> formats = new HashMap<>();
|
||||||
private String webhook = null;
|
|
||||||
private boolean isDefault = false;
|
private boolean isDefault = false;
|
||||||
private boolean ignorable = true;
|
private boolean ignorable = true;
|
||||||
private String name;
|
private String name;
|
||||||
@@ -83,7 +81,7 @@ public class PartyChatChannel extends SimpleChatChannel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PartyChatChannel build(SimpleChat simpleChat) {
|
public PartyChatChannel build(SimpleChat simpleChat) {
|
||||||
return new PartyChatChannel(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
return new PartyChatChannel(color, formats, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -98,13 +96,6 @@ public class PartyChatChannel extends SimpleChatChannel {
|
|||||||
return setColor(TextColor.fromHexString(color));
|
return setColor(TextColor.fromHexString(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public PartyChatChannel.Builder setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PartyChatChannel.Builder setFormats(Map<String, String> formats) {
|
public PartyChatChannel.Builder setFormats(Map<String, String> formats) {
|
||||||
this.formats = formats;
|
this.formats = formats;
|
||||||
@@ -112,13 +103,6 @@ public class PartyChatChannel extends SimpleChatChannel {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public PartyChatChannel.Builder setWebhook(String webhook) {
|
|
||||||
this.webhook = webhook;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PartyChatChannel.Builder setIsDefault(boolean aDefault) {
|
public PartyChatChannel.Builder setIsDefault(boolean aDefault) {
|
||||||
this.isDefault = aDefault;
|
this.isDefault = aDefault;
|
||||||
|
|||||||
@@ -5,30 +5,21 @@ 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.draycia.simplechat.util.DiscordWebhook;
|
|
||||||
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;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.javacord.api.entity.channel.ServerTextChannel;
|
|
||||||
import org.javacord.api.entity.message.MessageAuthor;
|
|
||||||
import org.javacord.api.entity.permission.Role;
|
|
||||||
import org.javacord.api.event.message.MessageCreateEvent;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class SimpleChatChannel extends ChatChannel {
|
public class SimpleChatChannel extends ChatChannel {
|
||||||
|
|
||||||
private TextColor color;
|
private TextColor color;
|
||||||
private long id;
|
|
||||||
private Map<String, String> formats;
|
private Map<String, String> formats;
|
||||||
private String webhook;
|
|
||||||
private boolean isDefault;
|
private boolean isDefault;
|
||||||
private boolean ignorable;
|
private boolean ignorable;
|
||||||
private String name;
|
private String name;
|
||||||
@@ -41,19 +32,15 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
private boolean filterEnabled;
|
private boolean filterEnabled;
|
||||||
private boolean firstMatchingGroup;
|
private boolean firstMatchingGroup;
|
||||||
|
|
||||||
private DiscordWebhook discordWebhook = null;
|
|
||||||
|
|
||||||
private SimpleChat simpleChat;
|
private SimpleChat simpleChat;
|
||||||
|
|
||||||
private ArrayList<Pattern> itemPatterns = new ArrayList<>();
|
private ArrayList<Pattern> itemPatterns = new ArrayList<>();
|
||||||
|
|
||||||
private SimpleChatChannel() { }
|
private SimpleChatChannel() { }
|
||||||
|
|
||||||
SimpleChatChannel(TextColor color, long id, Map<String, String> formats, String webhook, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, boolean firstMatchingGroup, SimpleChat simpleChat) {
|
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.color = color;
|
||||||
this.id = id;
|
|
||||||
this.formats = formats;
|
this.formats = formats;
|
||||||
this.webhook = webhook;
|
|
||||||
this.isDefault = isDefault;
|
this.isDefault = isDefault;
|
||||||
this.ignorable = ignorable;
|
this.ignorable = ignorable;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -68,14 +55,6 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
|
|
||||||
this.simpleChat = simpleChat;
|
this.simpleChat = simpleChat;
|
||||||
|
|
||||||
if (getChannelId() > 0 && simpleChat.getDiscordManager().getDiscordAPI() != null) {
|
|
||||||
simpleChat.getDiscordManager().getDiscordAPI().addMessageCreateListener(this::processDiscordMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getWebhook() != null && !getWebhook().isEmpty()) {
|
|
||||||
discordWebhook = new DiscordWebhook(getWebhook());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String entry : simpleChat.getConfig().getStringList("item-link-placeholders")) {
|
for (String entry : simpleChat.getConfig().getStringList("item-link-placeholders")) {
|
||||||
itemPatterns.add(Pattern.compile(Pattern.quote(entry)));
|
itemPatterns.add(Pattern.compile(Pattern.quote(entry)));
|
||||||
}
|
}
|
||||||
@@ -107,38 +86,6 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
return audience;
|
return audience;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void processDiscordMessage(MessageCreateEvent event) {
|
|
||||||
if (event.getChannel().getId() != getChannelId() || !event.getMessageAuthor().isRegularUser()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String message = MiniMessage.get().escapeTokens(event.getMessageContent()).replace("~", "\\~")
|
|
||||||
.replace("_", "\\_").replace("*", "\\*").replace("\n", "");
|
|
||||||
|
|
||||||
MessageAuthor author = event.getMessageAuthor();
|
|
||||||
ServerTextChannel channel = (ServerTextChannel)event.getChannel();
|
|
||||||
|
|
||||||
String role = "";
|
|
||||||
|
|
||||||
if (author.asUser().isPresent() && event.getServer().isPresent()) {
|
|
||||||
List<Role> roles = author.asUser().get().getRoles(event.getServer().get());
|
|
||||||
|
|
||||||
if (!roles.isEmpty()) {
|
|
||||||
role = roles.get(roles.size() - 1).getName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Placeholders: username, displayname, channel, server, message, primaryrole
|
|
||||||
Component component = MiniMessage.get().parse(getDiscordFormatting(), "message", message,
|
|
||||||
"username", author.getName(), "displayname", author.getDisplayName(), "channel", channel.getName(),
|
|
||||||
"server", event.getServer().get().getName(), "primaryrole", role);
|
|
||||||
|
|
||||||
for (ChatUser user : getAudience(null)) {
|
|
||||||
user.sendMessage(component);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(ChatUser user, String message, boolean fromBungee) {
|
public void sendMessage(ChatUser user, String message, boolean fromBungee) {
|
||||||
// Get player's formatting
|
// Get player's formatting
|
||||||
@@ -230,8 +177,6 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
} else if (shouldBungee()) {
|
} else if (shouldBungee()) {
|
||||||
sendMessageToBungee(user.asPlayer(), message);
|
sendMessageToBungee(user.asPlayer(), message);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessageToDiscord(user, message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,22 +199,6 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
System.out.println(LegacyComponentSerializer.legacy().serialize(component));
|
System.out.println(LegacyComponentSerializer.legacy().serialize(component));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessageToDiscord(ChatUser user, String message) {
|
|
||||||
if (getWebhook() == null || discordWebhook == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
discordWebhook.setUsername(user.asOfflinePlayer().getName());
|
|
||||||
discordWebhook.setContent(message.replace("@", "@\u200B"));
|
|
||||||
discordWebhook.setAvatarUrl("https://minotar.net/helm/" + user.getUUID().toString() + "/100.png");
|
|
||||||
|
|
||||||
try {
|
|
||||||
discordWebhook.execute();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendMessageToBungee(Player player, Component component) {
|
public void sendMessageToBungee(Player player, Component component) {
|
||||||
simpleChat.getPluginMessageManager().sendComponent(this, player, component);
|
simpleChat.getPluginMessageManager().sendComponent(this, player, component);
|
||||||
}
|
}
|
||||||
@@ -348,21 +277,11 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getChannelId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFormat(String group) {
|
public String getFormat(String group) {
|
||||||
return getFormats().getOrDefault(group, getFormats().getOrDefault("default", "<white><%player_displayname%<white>> <message>"));
|
return getFormats().getOrDefault(group, getFormats().getOrDefault("default", "<white><%player_displayname%<white>> <message>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getWebhook() {
|
|
||||||
return webhook;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDefault() {
|
public boolean isDefault() {
|
||||||
return isDefault;
|
return isDefault;
|
||||||
@@ -430,9 +349,7 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
public static class Builder extends ChatChannel.Builder {
|
public static class Builder extends ChatChannel.Builder {
|
||||||
|
|
||||||
private TextColor color = TextColor.of(255, 255, 255);
|
private TextColor color = TextColor.of(255, 255, 255);
|
||||||
private long id = -1;
|
|
||||||
private Map<String, String> formats = new HashMap<>();
|
private Map<String, String> formats = new HashMap<>();
|
||||||
private String webhook = null;
|
|
||||||
private boolean isDefault = false;
|
private boolean isDefault = false;
|
||||||
private boolean ignorable = true;
|
private boolean ignorable = true;
|
||||||
private String name;
|
private String name;
|
||||||
@@ -453,7 +370,7 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SimpleChatChannel build(SimpleChat simpleChat) {
|
public SimpleChatChannel build(SimpleChat simpleChat) {
|
||||||
return new SimpleChatChannel(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
return new SimpleChatChannel(color, formats, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -468,13 +385,6 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
return setColor(TextColor.fromHexString(color));
|
return setColor(TextColor.fromHexString(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Builder setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder setFormats(Map<String, String> formats) {
|
public Builder setFormats(Map<String, String> formats) {
|
||||||
this.formats = formats;
|
this.formats = formats;
|
||||||
@@ -482,13 +392,6 @@ public class SimpleChatChannel extends ChatChannel {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Builder setWebhook(String webhook) {
|
|
||||||
this.webhook = webhook;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder setIsDefault(boolean aDefault) {
|
public Builder setIsDefault(boolean aDefault) {
|
||||||
this.isDefault = aDefault;
|
this.isDefault = aDefault;
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class TownChatChannel extends SimpleChatChannel {
|
public class TownChatChannel extends SimpleChatChannel {
|
||||||
|
|
||||||
TownChatChannel(TextColor color, long id, Map<String, String> formats, String webhook, boolean isDefault, boolean ignorable, String name, double distance, String switchMessage, String toggleOffMessage, String toggleOnMessage, boolean forwardFormatting, boolean shouldBungee, boolean filterEnabled, boolean firstMatchingGroup, SimpleChat simpleChat) {
|
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, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
super(color, formats, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -105,7 +105,7 @@ public class TownChatChannel extends SimpleChatChannel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TownChatChannel build(SimpleChat simpleChat) {
|
public TownChatChannel build(SimpleChat simpleChat) {
|
||||||
return new TownChatChannel(color, id, formats, webhook, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
return new TownChatChannel(color, formats, isDefault, ignorable, name, distance, switchMessage, toggleOffMessage, toggleOnMessage, forwardFormatting, shouldBungee, filterEnabled, firstMatchingGroup, simpleChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -120,13 +120,6 @@ public class TownChatChannel extends SimpleChatChannel {
|
|||||||
return setColor(TextColor.fromHexString(color));
|
return setColor(TextColor.fromHexString(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public TownChatChannel.Builder setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TownChatChannel.Builder setFormats(Map<String, String> formats) {
|
public TownChatChannel.Builder setFormats(Map<String, String> formats) {
|
||||||
this.formats = formats;
|
this.formats = formats;
|
||||||
@@ -134,13 +127,6 @@ public class TownChatChannel extends SimpleChatChannel {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public TownChatChannel.Builder setWebhook(String webhook) {
|
|
||||||
this.webhook = webhook;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TownChatChannel.Builder setIsDefault(boolean aDefault) {
|
public TownChatChannel.Builder setIsDefault(boolean aDefault) {
|
||||||
this.isDefault = aDefault;
|
this.isDefault = aDefault;
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package net.draycia.simplechat.listeners.chat;
|
package net.draycia.simplechat.listeners;
|
||||||
|
|
||||||
import net.draycia.simplechat.SimpleChat;
|
import net.draycia.simplechat.SimpleChat;
|
||||||
import net.draycia.simplechat.channels.ChatChannel;
|
import net.draycia.simplechat.channels.ChatChannel;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package net.draycia.simplechat.listeners.chat;
|
package net.draycia.simplechat.listeners;
|
||||||
|
|
||||||
import net.draycia.simplechat.SimpleChat;
|
import net.draycia.simplechat.SimpleChat;
|
||||||
import net.draycia.simplechat.events.ChatComponentEvent;
|
import net.draycia.simplechat.events.ChatComponentEvent;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package net.draycia.simplechat.listeners.chat;
|
package net.draycia.simplechat.listeners;
|
||||||
|
|
||||||
import net.draycia.simplechat.events.ChatFormatEvent;
|
import net.draycia.simplechat.events.ChatFormatEvent;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package net.draycia.simplechat.listeners.chat;
|
package net.draycia.simplechat.listeners;
|
||||||
|
|
||||||
import net.draycia.simplechat.events.ChatFormatEvent;
|
import net.draycia.simplechat.events.ChatFormatEvent;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package net.draycia.simplechat.listeners.chat;
|
package net.draycia.simplechat.listeners;
|
||||||
|
|
||||||
import net.draycia.simplechat.events.ChatFormatEvent;
|
import net.draycia.simplechat.events.ChatFormatEvent;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package net.draycia.simplechat.listeners.chat;
|
package net.draycia.simplechat.listeners;
|
||||||
|
|
||||||
import net.draycia.simplechat.SimpleChat;
|
import net.draycia.simplechat.SimpleChat;
|
||||||
import net.draycia.simplechat.events.ChatComponentEvent;
|
import net.draycia.simplechat.events.ChatComponentEvent;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package net.draycia.simplechat.listeners.chat;
|
package net.draycia.simplechat.listeners;
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import net.draycia.simplechat.SimpleChat;
|
import net.draycia.simplechat.SimpleChat;
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
package net.draycia.simplechat.listeners;
|
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
|
||||||
import net.draycia.simplechat.SimpleChat;
|
|
||||||
import net.draycia.simplechat.channels.ChatChannel;
|
|
||||||
import net.draycia.simplechat.storage.ChatUser;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
import org.javacord.api.DiscordApi;
|
|
||||||
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener {
|
|
||||||
|
|
||||||
private SimpleChat simpleChat;
|
|
||||||
|
|
||||||
public PlayerListener(SimpleChat simpleChat) {
|
|
||||||
this.simpleChat = simpleChat;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Chat messages
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void onPlayerchat(AsyncPlayerChatEvent event) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
ChatUser user = simpleChat.getUserService().wrap(event.getPlayer());
|
|
||||||
|
|
||||||
if (event.isAsynchronous()) {
|
|
||||||
user.getSelectedChannel().sendMessage(user, event.getMessage(), false);
|
|
||||||
} else {
|
|
||||||
Bukkit.getScheduler().scheduleAsyncDelayedTask(simpleChat, () -> {
|
|
||||||
user.getSelectedChannel().sendMessage(user, event.getMessage(), false);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Player joins
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
|
||||||
if (!simpleChat.getConfig().getBoolean("listeners.join")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatChannel chatChannel = simpleChat.getDefaultChannel();
|
|
||||||
|
|
||||||
if (chatChannel != null && chatChannel.getChannelId() > -1) {
|
|
||||||
DiscordApi api = simpleChat.getDiscordManager().getDiscordAPI();
|
|
||||||
String message = simpleChat.getConfig().getString("language.player-joined");
|
|
||||||
|
|
||||||
api.getServerTextChannelById(chatChannel.getChannelId()).ifPresent(channel -> {
|
|
||||||
channel.sendMessage(PlaceholderAPI.setPlaceholders(event.getPlayer(), message));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Player quits
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
|
||||||
if (!simpleChat.getConfig().getBoolean("listeners.leave")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatChannel chatChannel = simpleChat.getDefaultChannel();
|
|
||||||
|
|
||||||
if (chatChannel != null && chatChannel.getChannelId() > -1) {
|
|
||||||
DiscordApi api = simpleChat.getDiscordManager().getDiscordAPI();
|
|
||||||
String message = simpleChat.getConfig().getString("language.player-left");
|
|
||||||
|
|
||||||
api.getServerTextChannelById(chatChannel.getChannelId()).ifPresent(channel -> {
|
|
||||||
channel.sendMessage(PlaceholderAPI.setPlaceholders(event.getPlayer(), message));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Player deaths
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
|
||||||
if (!simpleChat.getConfig().getBoolean("listeners.death")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatChannel chatChannel = simpleChat.getDefaultChannel();
|
|
||||||
|
|
||||||
if (chatChannel != null && chatChannel.getChannelId() > -1) {
|
|
||||||
DiscordApi api = simpleChat.getDiscordManager().getDiscordAPI();
|
|
||||||
|
|
||||||
api.getServerTextChannelById(chatChannel.getChannelId()).ifPresent(channel -> {
|
|
||||||
channel.sendMessage(event.getDeathMessage());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package net.draycia.simplechat.listeners.chat;
|
package net.draycia.simplechat.listeners;
|
||||||
|
|
||||||
import net.draycia.simplechat.events.ChatComponentEvent;
|
import net.draycia.simplechat.events.ChatComponentEvent;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package net.draycia.simplechat.listeners;
|
|
||||||
|
|
||||||
import com.vexsoftware.votifier.model.VotifierEvent;
|
|
||||||
import net.draycia.simplechat.SimpleChat;
|
|
||||||
import net.draycia.simplechat.channels.ChatChannel;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.javacord.api.DiscordApi;
|
|
||||||
|
|
||||||
public class VoteListener implements Listener {
|
|
||||||
|
|
||||||
private SimpleChat simpleChat;
|
|
||||||
|
|
||||||
public VoteListener(SimpleChat simpleChat) {
|
|
||||||
this.simpleChat = simpleChat;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void onVote(VotifierEvent event) {
|
|
||||||
if (!simpleChat.getConfig().getBoolean("listeners.vote")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatChannel chatChannel = simpleChat.getDefaultChannel();
|
|
||||||
|
|
||||||
if (chatChannel != null && chatChannel.getChannelId() > -1) {
|
|
||||||
DiscordApi api = simpleChat.getDiscordManager().getDiscordAPI();
|
|
||||||
|
|
||||||
String message = simpleChat.getConfig().getString("language.vote-received")
|
|
||||||
.replace("<service>", event.getVote().getServiceName())
|
|
||||||
.replace("<player>", event.getVote().getUsername());
|
|
||||||
|
|
||||||
api.getServerTextChannelById(chatChannel.getChannelId()).ifPresent(channel -> {
|
|
||||||
channel.sendMessage(message);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -42,10 +42,6 @@ public class ChannelManager {
|
|||||||
builder = SimpleChatChannel.builder(key);
|
builder = SimpleChatChannel.builder(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (section.contains("id")) {
|
|
||||||
builder.setId(section.getLong("id"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (section.contains("formats")) {
|
if (section.contains("formats")) {
|
||||||
HashMap<String, String> formats = new HashMap<>();
|
HashMap<String, String> formats = new HashMap<>();
|
||||||
|
|
||||||
@@ -68,10 +64,6 @@ public class ChannelManager {
|
|||||||
builder.setFormats(formats);
|
builder.setFormats(formats);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (section.contains("webhook")) {
|
|
||||||
builder.setWebhook(section.getString("webhook"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (section.contains("switch-message")) {
|
if (section.contains("switch-message")) {
|
||||||
builder.setSwitchMessage(section.getString("switch-message"));
|
builder.setSwitchMessage(section.getString("switch-message"));
|
||||||
} else if (defaults != null && defaults.contains("switch-message")) {
|
} else if (defaults != null && defaults.contains("switch-message")) {
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
package net.draycia.simplechat.managers;
|
|
||||||
|
|
||||||
import net.draycia.simplechat.SimpleChat;
|
|
||||||
import org.javacord.api.DiscordApi;
|
|
||||||
import org.javacord.api.DiscordApiBuilder;
|
|
||||||
|
|
||||||
public class DiscordManager {
|
|
||||||
|
|
||||||
private DiscordApi discordAPI = null;
|
|
||||||
|
|
||||||
public DiscordManager(SimpleChat simpleChat) {
|
|
||||||
if (simpleChat.getConfig().contains("bot-token") && !simpleChat.getConfig().getString("bot-token").isEmpty()) {
|
|
||||||
try {
|
|
||||||
discordAPI = new DiscordApiBuilder().setToken(simpleChat.getConfig().getString("bot-token")).login().join();
|
|
||||||
} catch (IllegalStateException exception) {
|
|
||||||
simpleChat.getLogger().warning("Unable to start bot. Reason: " + exception.getMessage());
|
|
||||||
simpleChat.getLogger().warning("If you're getting \"Websocket closed\", check that your bot token is valid!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public DiscordApi getDiscordAPI() {
|
|
||||||
return discordAPI;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package net.draycia.simplechat.util;
|
|
||||||
|
|
||||||
import com.google.gson.TypeAdapter;
|
|
||||||
import com.google.gson.stream.JsonReader;
|
|
||||||
import com.google.gson.stream.JsonWriter;
|
|
||||||
import net.draycia.simplechat.SimpleChat;
|
|
||||||
import net.draycia.simplechat.channels.ChatChannel;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class ChatChannelAdapter extends TypeAdapter<ChatChannel> {
|
|
||||||
|
|
||||||
private SimpleChat simpleChat;
|
|
||||||
|
|
||||||
public ChatChannelAdapter(SimpleChat simpleChat) {
|
|
||||||
this.simpleChat = simpleChat;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(JsonWriter out, ChatChannel value) throws IOException {
|
|
||||||
if (value != null) {
|
|
||||||
out.beginObject();
|
|
||||||
out.name("name").value(value.getName());
|
|
||||||
out.endObject();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChatChannel read(JsonReader in) throws IOException {
|
|
||||||
ChatChannel channel;
|
|
||||||
|
|
||||||
in.beginObject();
|
|
||||||
|
|
||||||
if (in.hasNext()) {
|
|
||||||
String key = in.nextName();
|
|
||||||
String value = in.nextString();
|
|
||||||
|
|
||||||
channel = simpleChat.getChannel(value);
|
|
||||||
} else {
|
|
||||||
channel = simpleChat.getDefaultChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
in.endObject();
|
|
||||||
|
|
||||||
return channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,391 +0,0 @@
|
|||||||
package net.draycia.simplechat.util;
|
|
||||||
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.lang.reflect.Array;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class used to execute Discord Webhooks with low effort
|
|
||||||
*/
|
|
||||||
public class DiscordWebhook {
|
|
||||||
|
|
||||||
private final String url;
|
|
||||||
private String content;
|
|
||||||
private String username;
|
|
||||||
private String avatarUrl;
|
|
||||||
private boolean tts;
|
|
||||||
private List<EmbedObject> embeds = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new DiscordWebhook instance
|
|
||||||
*
|
|
||||||
* @param url The webhook URL obtained in Discord
|
|
||||||
*/
|
|
||||||
public DiscordWebhook(String url) {
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContent(String content) {
|
|
||||||
this.content = content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsername(String username) {
|
|
||||||
this.username = username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAvatarUrl(String avatarUrl) {
|
|
||||||
this.avatarUrl = avatarUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTts(boolean tts) {
|
|
||||||
this.tts = tts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addEmbed(EmbedObject embed) {
|
|
||||||
this.embeds.add(embed);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void execute() throws IOException {
|
|
||||||
if (this.content == null && this.embeds.isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("Set content or add at least one EmbedObject");
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONObject json = new JSONObject();
|
|
||||||
|
|
||||||
json.put("content", this.content);
|
|
||||||
json.put("username", this.username);
|
|
||||||
json.put("avatar_url", this.avatarUrl);
|
|
||||||
json.put("tts", this.tts);
|
|
||||||
|
|
||||||
if (!this.embeds.isEmpty()) {
|
|
||||||
List<JSONObject> embedObjects = new ArrayList<>();
|
|
||||||
|
|
||||||
for (EmbedObject embed : this.embeds) {
|
|
||||||
JSONObject jsonEmbed = new JSONObject();
|
|
||||||
|
|
||||||
jsonEmbed.put("title", embed.getTitle());
|
|
||||||
jsonEmbed.put("description", embed.getDescription());
|
|
||||||
jsonEmbed.put("url", embed.getUrl());
|
|
||||||
|
|
||||||
if (embed.getColor() != null) {
|
|
||||||
Color color = embed.getColor();
|
|
||||||
int rgb = color.getRed();
|
|
||||||
rgb = (rgb << 8) + color.getGreen();
|
|
||||||
rgb = (rgb << 8) + color.getBlue();
|
|
||||||
|
|
||||||
jsonEmbed.put("color", rgb);
|
|
||||||
}
|
|
||||||
|
|
||||||
EmbedObject.Footer footer = embed.getFooter();
|
|
||||||
EmbedObject.Image image = embed.getImage();
|
|
||||||
EmbedObject.Thumbnail thumbnail = embed.getThumbnail();
|
|
||||||
EmbedObject.Author author = embed.getAuthor();
|
|
||||||
List<EmbedObject.Field> fields = embed.getFields();
|
|
||||||
|
|
||||||
if (footer != null) {
|
|
||||||
JSONObject jsonFooter = new JSONObject();
|
|
||||||
|
|
||||||
jsonFooter.put("text", footer.getText());
|
|
||||||
jsonFooter.put("icon_url", footer.getIconUrl());
|
|
||||||
jsonEmbed.put("footer", jsonFooter);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (image != null) {
|
|
||||||
JSONObject jsonImage = new JSONObject();
|
|
||||||
|
|
||||||
jsonImage.put("url", image.getUrl());
|
|
||||||
jsonEmbed.put("image", jsonImage);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (thumbnail != null) {
|
|
||||||
JSONObject jsonThumbnail = new JSONObject();
|
|
||||||
|
|
||||||
jsonThumbnail.put("url", thumbnail.getUrl());
|
|
||||||
jsonEmbed.put("thumbnail", jsonThumbnail);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (author != null) {
|
|
||||||
JSONObject jsonAuthor = new JSONObject();
|
|
||||||
|
|
||||||
jsonAuthor.put("name", author.getName());
|
|
||||||
jsonAuthor.put("url", author.getUrl());
|
|
||||||
jsonAuthor.put("icon_url", author.getIconUrl());
|
|
||||||
jsonEmbed.put("author", jsonAuthor);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<JSONObject> jsonFields = new ArrayList<>();
|
|
||||||
for (EmbedObject.Field field : fields) {
|
|
||||||
JSONObject jsonField = new JSONObject();
|
|
||||||
|
|
||||||
jsonField.put("name", field.getName());
|
|
||||||
jsonField.put("value", field.getValue());
|
|
||||||
jsonField.put("inline", field.isInline());
|
|
||||||
|
|
||||||
jsonFields.add(jsonField);
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonEmbed.put("fields", jsonFields.toArray());
|
|
||||||
embedObjects.add(jsonEmbed);
|
|
||||||
}
|
|
||||||
|
|
||||||
json.put("embeds", embedObjects.toArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
URL url = new URL(this.url);
|
|
||||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
|
||||||
connection.addRequestProperty("Content-Type", "application/json");
|
|
||||||
connection.addRequestProperty("User-Agent", "Java-DiscordWebhook-BY-Gelox_");
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
connection.setRequestMethod("POST");
|
|
||||||
|
|
||||||
OutputStream stream = connection.getOutputStream();
|
|
||||||
stream.write(json.toString().getBytes());
|
|
||||||
stream.flush();
|
|
||||||
stream.close();
|
|
||||||
|
|
||||||
connection.getInputStream().close(); //I'm not sure why but it doesn't work without getting the InputStream
|
|
||||||
connection.disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class EmbedObject {
|
|
||||||
private String title;
|
|
||||||
private String description;
|
|
||||||
private String url;
|
|
||||||
private Color color;
|
|
||||||
|
|
||||||
private Footer footer;
|
|
||||||
private Thumbnail thumbnail;
|
|
||||||
private Image image;
|
|
||||||
private Author author;
|
|
||||||
private List<Field> fields = new ArrayList<>();
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Color getColor() {
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Footer getFooter() {
|
|
||||||
return footer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Thumbnail getThumbnail() {
|
|
||||||
return thumbnail;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Image getImage() {
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Author getAuthor() {
|
|
||||||
return author;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Field> getFields() {
|
|
||||||
return fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EmbedObject setTitle(String title) {
|
|
||||||
this.title = title;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EmbedObject setDescription(String description) {
|
|
||||||
this.description = description;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EmbedObject setUrl(String url) {
|
|
||||||
this.url = url;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EmbedObject setColor(Color color) {
|
|
||||||
this.color = color;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EmbedObject setFooter(String text, String icon) {
|
|
||||||
this.footer = new Footer(text, icon);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EmbedObject setThumbnail(String url) {
|
|
||||||
this.thumbnail = new Thumbnail(url);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EmbedObject setImage(String url) {
|
|
||||||
this.image = new Image(url);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EmbedObject setAuthor(String name, String url, String icon) {
|
|
||||||
this.author = new Author(name, url, icon);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EmbedObject addField(String name, String value, boolean inline) {
|
|
||||||
this.fields.add(new Field(name, value, inline));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Footer {
|
|
||||||
private String text;
|
|
||||||
private String iconUrl;
|
|
||||||
|
|
||||||
private Footer(String text, String iconUrl) {
|
|
||||||
this.text = text;
|
|
||||||
this.iconUrl = iconUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getText() {
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getIconUrl() {
|
|
||||||
return iconUrl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Thumbnail {
|
|
||||||
private String url;
|
|
||||||
|
|
||||||
private Thumbnail(String url) {
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Image {
|
|
||||||
private String url;
|
|
||||||
|
|
||||||
private Image(String url) {
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Author {
|
|
||||||
private String name;
|
|
||||||
private String url;
|
|
||||||
private String iconUrl;
|
|
||||||
|
|
||||||
private Author(String name, String url, String iconUrl) {
|
|
||||||
this.name = name;
|
|
||||||
this.url = url;
|
|
||||||
this.iconUrl = iconUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getIconUrl() {
|
|
||||||
return iconUrl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Field {
|
|
||||||
private String name;
|
|
||||||
private String value;
|
|
||||||
private boolean inline;
|
|
||||||
|
|
||||||
private Field(String name, String value, boolean inline) {
|
|
||||||
this.name = name;
|
|
||||||
this.value = value;
|
|
||||||
this.inline = inline;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isInline() {
|
|
||||||
return inline;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class JSONObject {
|
|
||||||
|
|
||||||
private final HashMap<String, Object> map = new HashMap<>();
|
|
||||||
|
|
||||||
void put(String key, Object value) {
|
|
||||||
if (value != null) {
|
|
||||||
map.put(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
Set<Map.Entry<String, Object>> entrySet = map.entrySet();
|
|
||||||
builder.append("{");
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
for (Map.Entry<String, Object> entry : entrySet) {
|
|
||||||
Object val = entry.getValue();
|
|
||||||
builder.append(quote(entry.getKey())).append(":");
|
|
||||||
|
|
||||||
if (val instanceof String) {
|
|
||||||
builder.append(quote(String.valueOf(val)));
|
|
||||||
} else if (val instanceof Integer) {
|
|
||||||
builder.append(Integer.valueOf(String.valueOf(val)));
|
|
||||||
} else if (val instanceof Boolean) {
|
|
||||||
builder.append(val);
|
|
||||||
} else if (val instanceof JSONObject) {
|
|
||||||
builder.append(val.toString());
|
|
||||||
} else if (val.getClass().isArray()) {
|
|
||||||
builder.append("[");
|
|
||||||
int len = Array.getLength(val);
|
|
||||||
for (int j = 0; j < len; j++) {
|
|
||||||
builder.append(Array.get(val, j).toString()).append(j != len - 1 ? "," : "");
|
|
||||||
}
|
|
||||||
builder.append("]");
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.append(++i == entrySet.size() ? "}" : ",");
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String quote(String string) {
|
|
||||||
return "\"" + string + "\"";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -35,10 +35,6 @@ channels:
|
|||||||
global:
|
global:
|
||||||
name: 'Global'
|
name: 'Global'
|
||||||
aliases: 'global|g'
|
aliases: 'global|g'
|
||||||
# Discord channel ID for bridging
|
|
||||||
id: -1
|
|
||||||
# Webhook URL for bridging
|
|
||||||
webhook: ''
|
|
||||||
# If this channel is the default channel
|
# If this channel is the default channel
|
||||||
default: true
|
default: true
|
||||||
announcements:
|
announcements:
|
||||||
@@ -57,8 +53,6 @@ filter-text: '****'
|
|||||||
replacements:
|
replacements:
|
||||||
'%shrug%': '¯\_(ツ)_/¯'
|
'%shrug%': '¯\_(ツ)_/¯'
|
||||||
|
|
||||||
bot-token: ""
|
|
||||||
|
|
||||||
language:
|
language:
|
||||||
ignoring-user: '<green>You are now ignoring <gold><player><green>!'
|
ignoring-user: '<green>You are now ignoring <gold><player><green>!'
|
||||||
not-ignoring-user: '<green>You are no longer ignoring <gold><player><green>!'
|
not-ignoring-user: '<green>You are no longer ignoring <gold><player><green>!'
|
||||||
|
|||||||
Reference in new issue
Block a user