The refactoring continues

This commit is contained in:
Norbi Peti 2019-04-17 17:54:08 +02:00
parent 12ca6fbfb5
commit 95af050517
24 changed files with 114 additions and 118 deletions

View file

@ -3,8 +3,8 @@ package buttondevteam.discordplugin;
import buttondevteam.discordplugin.playerfaker.DiscordFakePlayer; import buttondevteam.discordplugin.playerfaker.DiscordFakePlayer;
import buttondevteam.discordplugin.playerfaker.VanillaCommandListener; import buttondevteam.discordplugin.playerfaker.VanillaCommandListener;
import lombok.Getter; import lombok.Getter;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IUser; import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.handle.obj.MessageChannel;
import java.util.UUID; import java.util.UUID;
@ -12,7 +12,7 @@ public class DiscordConnectedPlayer extends DiscordFakePlayer implements IMCPlay
private static int nextEntityId = 10000; private static int nextEntityId = 10000;
private @Getter VanillaCommandListener<DiscordConnectedPlayer> vanillaCmdListener; private @Getter VanillaCommandListener<DiscordConnectedPlayer> vanillaCmdListener;
public DiscordConnectedPlayer(IUser user, IChannel channel, UUID uuid, String mcname) { public DiscordConnectedPlayer(IUser user, MessageChannel channel, UUID uuid, String mcname) {
super(user, channel, nextEntityId++, uuid, mcname); super(user, channel, nextEntityId++, uuid, mcname);
vanillaCmdListener = new VanillaCommandListener<>(this); vanillaCmdListener = new VanillaCommandListener<>(this);
} }

View file

@ -20,7 +20,7 @@ public class DiscordPlayer extends ChromaGamerBase {
/** /**
* Returns true if player has the private Minecraft chat enabled. For setting the value, see * Returns true if player has the private Minecraft chat enabled. For setting the value, see
* {@link MCChatPrivate#privateMCChat(sx.blah.discord.handle.obj.IChannel, boolean, sx.blah.discord.handle.obj.IUser, DiscordPlayer)} * {@link MCChatPrivate#privateMCChat(sx.blah.discord.handle.obj.MessageChannel, boolean, sx.blah.discord.handle.obj.IUser, DiscordPlayer)}
*/ */
public boolean isMinecraftChatEnabled() { public boolean isMinecraftChatEnabled() {
return MCChatPrivate.isMinecraftChatEnabled(this); return MCChatPrivate.isMinecraftChatEnabled(this);

View file

@ -26,8 +26,8 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IUser; import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.handle.obj.MessageChannel;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.*; import java.util.*;
@ -38,7 +38,7 @@ public class DiscordPlayerSender extends DiscordSenderBase implements IMCPlayer<
protected Player player; protected Player player;
private @Getter VanillaCommandListener<DiscordPlayerSender> vanillaCmdListener; private @Getter VanillaCommandListener<DiscordPlayerSender> vanillaCmdListener;
public DiscordPlayerSender(IUser user, IChannel channel, Player player) { public DiscordPlayerSender(IUser user, MessageChannel channel, Player player) {
super(user, channel); super(user, channel);
this.player = player; this.player = player;
vanillaCmdListener = new VanillaCommandListener<DiscordPlayerSender>(this); vanillaCmdListener = new VanillaCommandListener<DiscordPlayerSender>(this);

View file

@ -21,8 +21,8 @@ import com.google.common.io.Files;
import discord4j.core.DiscordClient; import discord4j.core.DiscordClient;
import discord4j.core.DiscordClientBuilder; import discord4j.core.DiscordClientBuilder;
import discord4j.core.event.domain.lifecycle.ReadyEvent; import discord4j.core.event.domain.lifecycle.ReadyEvent;
import discord4j.core.object.entity.Channel;
import discord4j.core.object.entity.Guild; import discord4j.core.object.entity.Guild;
import discord4j.core.object.entity.MessageChannel;
import discord4j.core.object.entity.Role; import discord4j.core.object.entity.Role;
import discord4j.core.object.presence.Activity; import discord4j.core.object.presence.Activity;
import discord4j.core.object.presence.Presence; import discord4j.core.object.presence.Presence;
@ -65,7 +65,7 @@ public class DiscordPlugin extends ButtonPlugin {
return getIConfig().getDataPrimDef("mainServer", 219529124321034241L, id -> dc.getGuildById(Snowflake.of((long) id)).block(), g -> g.getId().asLong()); return getIConfig().getDataPrimDef("mainServer", 219529124321034241L, id -> dc.getGuildById(Snowflake.of((long) id)).block(), g -> g.getId().asLong());
} }
public ConfigData<Channel> CommandChannel() { public ConfigData<MessageChannel> CommandChannel() {
return DPUtils.channelData(getIConfig(), "commandChannel", 239519012529111040L); return DPUtils.channelData(getIConfig(), "commandChannel", 239519012529111040L);
} }
@ -100,6 +100,13 @@ public class DiscordPlugin extends ButtonPlugin {
val cb = new DiscordClientBuilder(token); val cb = new DiscordClientBuilder(token);
dc = cb.build(); dc = cb.build();
dc.getEventDispatcher().on(ReadyEvent.class).subscribe(this::handleReady); dc.getEventDispatcher().on(ReadyEvent.class).subscribe(this::handleReady);
/*dc.getEventDispatcher().on(ReadyEvent.class) // Listen for ReadyEvent(s)
.map(event -> event.getGuilds().size()) // Get how many guilds the bot is in
.flatMap(size -> dc.getEventDispatcher()
.on(GuildCreateEvent.class) // Listen for GuildCreateEvent(s)
.take(size) // Take only the first `size` GuildCreateEvent(s) to be received
.collectList()) // Take all received GuildCreateEvents and make it a List
.subscribe(events -> /* All guilds have been received, client is fully connected *);*/ //TODO
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
Bukkit.getPluginManager().disablePlugin(this); Bukkit.getPluginManager().disablePlugin(this);
@ -169,8 +176,8 @@ public class DiscordPlugin extends ButtonPlugin {
thr.setStackTrace(new StackTraceElement[0]); thr.setStackTrace(new StackTraceElement[0]);
TBMCCoreAPI.SendException("The server crashed!", thr); TBMCCoreAPI.SendException("The server crashed!", thr);
} else } else
ChromaBot.getInstance().sendMessageCustomAsWell("", new EmbedBuilder().withColor(Color.GREEN) ChromaBot.getInstance().sendMessageCustomAsWell(ch -> ch.createEmbed(ecs -> ecs.setColor(Color.GREEN)
.withTitle("Server started - chat connected.").build(), ChannelconBroadcast.RESTART); .setTitle("Server started - chat connected.")), ChannelconBroadcast.RESTART);
DiscordMCCommand.resetting = false; //This is the last event handling this flag DiscordMCCommand.resetting = false; //This is the last event handling this flag

View file

@ -6,5 +6,5 @@ import sx.blah.discord.util.RateLimitException;
@FunctionalInterface @FunctionalInterface
public interface DiscordRunnable { public interface DiscordRunnable {
public abstract void run() throws DiscordException, RateLimitException, MissingPermissionsException; void run() throws DiscordException, RateLimitException, MissingPermissionsException;
} }

View file

@ -8,8 +8,8 @@ import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment; import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IUser; import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.handle.obj.MessageChannel;
import java.util.Set; import java.util.Set;
@ -18,12 +18,12 @@ public class DiscordSender extends DiscordSenderBase implements CommandSender {
private String name; private String name;
public DiscordSender(IUser user, IChannel channel) { public DiscordSender(IUser user, MessageChannel channel) {
super(user, channel); super(user, channel);
name = user == null ? "Discord user" : user.getDisplayName(DiscordPlugin.mainServer); name = user == null ? "Discord user" : user.getDisplayName(DiscordPlugin.mainServer);
} }
public DiscordSender(IUser user, IChannel channel, String name) { public DiscordSender(IUser user, MessageChannel channel, String name) {
super(user, channel); super(user, channel);
this.name = name; this.name = name;
} }

View file

@ -4,17 +4,17 @@ import buttondevteam.lib.TBMCCoreAPI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IUser; import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.handle.obj.MessageChannel;
public abstract class DiscordSenderBase implements CommandSender { public abstract class DiscordSenderBase implements CommandSender {
/** /**
* May be null. * May be null.
*/ */
protected IUser user; protected IUser user;
protected IChannel channel; protected MessageChannel channel;
protected DiscordSenderBase(IUser user, IChannel channel) { protected DiscordSenderBase(IUser user, MessageChannel channel) {
this.user = user; this.user = user;
this.channel = channel; this.channel = channel;
} }
@ -31,7 +31,7 @@ public abstract class DiscordSenderBase implements CommandSender {
return user; return user;
} }
public IChannel getChannel() { public MessageChannel getChannel() {
return channel; return channel;
} }

View file

@ -7,5 +7,5 @@ import sx.blah.discord.util.RateLimitException;
@FunctionalInterface @FunctionalInterface
public interface DiscordSupplier<T extends IDiscordObject<T>> { public interface DiscordSupplier<T extends IDiscordObject<T>> {
public abstract T get() throws DiscordException, RateLimitException, MissingPermissionsException; T get() throws DiscordException, RateLimitException, MissingPermissionsException;
} }

View file

@ -11,23 +11,24 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import discord4j.core.object.entity.Message;
import discord4j.core.object.entity.MessageChannel;
import lombok.val; import lombok.val;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import sx.blah.discord.handle.obj.IChannel; import reactor.core.publisher.Flux;
import sx.blah.discord.handle.obj.IMessage;
import java.io.File; import java.io.File;
import java.util.List; import java.util.Objects;
public class AnnouncerModule extends Component<DiscordPlugin> { public class AnnouncerModule extends Component<DiscordPlugin> {
/** /**
* Channel to post new posts. * Channel to post new posts.
*/ */
public ConfigData<IChannel> channel() { public ConfigData<MessageChannel> channel() {
return DPUtils.channelData(getConfig(), "channel", 239519012529111040L); return DPUtils.channelData(getConfig(), "channel", 239519012529111040L);
} }
public ConfigData<IChannel> modChannel() { public ConfigData<MessageChannel> modChannel() {
return DPUtils.channelData(getConfig(), "modChannel", 239519012529111040L); return DPUtils.channelData(getConfig(), "modChannel", 239519012529111040L);
} }
@ -53,19 +54,11 @@ public class AnnouncerModule extends Component<DiscordPlugin> {
protected void enable() { protected void enable() {
if (DPUtils.disableIfConfigError(this, channel(), modChannel())) return; if (DPUtils.disableIfConfigError(this, channel(), modChannel())) return;
stop = false; //If not the first time stop = false; //If not the first time
DPUtils.performNoWait(() -> {
try {
val keepPinned = keepPinned().get(); val keepPinned = keepPinned().get();
if (keepPinned == 0) return; if (keepPinned == 0) return;
val channel = channel().get(); val channel = channel().get();
List<IMessage> msgs = channel.getPinnedMessages(); Flux<Message> msgs = channel.getPinnedMessages();
for (int i = msgs.size() - 1; i >= keepPinned; i--) { // Unpin all pinned messages except the newest 10 msgs.subscribe(Message::unpin);
channel.unpin(msgs.get(i));
Thread.sleep(10);
}
} catch (InterruptedException ignore) {
}
});
val yc = YamlConfiguration.loadConfiguration(new File("plugins/DiscordPlugin", "config.yml")); //Name change val yc = YamlConfiguration.loadConfiguration(new File("plugins/DiscordPlugin", "config.yml")); //Name change
if (lastannouncementtime().get() == 0) //Load old data if (lastannouncementtime().get() == 0) //Load old data
lastannouncementtime().set(yc.getLong("lastannouncementtime")); lastannouncementtime().set(yc.getLong("lastannouncementtime"));
@ -125,13 +118,11 @@ public class AnnouncerModule extends Component<DiscordPlugin> {
} }
} }
if (msgsb.length() > 0) if (msgsb.length() > 0)
channel().get().pin(DiscordPlugin.sendMessageToChannelWait(channel().get(), msgsb.toString())); Objects.requireNonNull(channel().get().createMessage(msgsb.toString()).block()).pin().block();
if (modmsgsb.length() > 0) if (modmsgsb.length() > 0)
DiscordPlugin.sendMessageToChannel(modChannel().get(), modmsgsb.toString()); modChannel().get().createMessage(modmsgsb.toString()).block();
if (lastannouncementtime().get() != lastanntime) { if (lastannouncementtime().get() != lastanntime)
lastannouncementtime().set(lastanntime); // If sending succeeded lastannouncementtime().set(lastanntime); // If sending succeeded
getPlugin().saveConfig(); //TODO: Won't be needed if I implement auto-saving
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View file

@ -2,20 +2,24 @@ package buttondevteam.discordplugin.commands;
import buttondevteam.discordplugin.DPUtils; import buttondevteam.discordplugin.DPUtils;
import buttondevteam.lib.chat.Command2Sender; import buttondevteam.lib.chat.Command2Sender;
import discord4j.core.object.entity.Message;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import sx.blah.discord.handle.obj.IMessage; import lombok.val;
@RequiredArgsConstructor @RequiredArgsConstructor
public class Command2DCSender implements Command2Sender { public class Command2DCSender implements Command2Sender {
private final @Getter IMessage message; private final @Getter
Message message;
@Override @Override
public void sendMessage(String message) { public void sendMessage(String message) {
if (message.length() == 0) return; if (message.length() == 0) return;
message = DPUtils.sanitizeString(message); message = DPUtils.sanitizeString(message);
message = Character.toLowerCase(message.charAt(0)) + message.substring(1); message = Character.toLowerCase(message.charAt(0)) + message.substring(1);
this.message.reply(message); val msg = message;
this.message.getChannel().flatMap(ch -> ch.createMessage(this.message.getAuthorAsMember().a->
a.getNicknameMention() + ", " + msg)))
} }
@Override @Override

View file

@ -8,8 +8,8 @@ import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.player.ChromaGamerBase; import buttondevteam.lib.player.ChromaGamerBase;
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget; import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
import lombok.val; import lombok.val;
import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IUser; import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.handle.obj.Message;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -78,7 +78,7 @@ public class UserinfoCommand extends ICommand2DC {
return true; return true;
} }
private List<IUser> getUsers(IMessage message, String args) { private List<IUser> getUsers(Message message, String args) {
final List<IUser> targets; final List<IUser> targets;
if (message.getChannel().isPrivate()) if (message.getChannel().isPrivate())
targets = DiscordPlugin.dc.getUsers().stream().filter(u -> u.getName().equalsIgnoreCase(args)) targets = DiscordPlugin.dc.getUsers().stream().filter(u -> u.getName().equalsIgnoreCase(args))

View file

@ -11,9 +11,9 @@ import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IGuild; import sx.blah.discord.handle.obj.IGuild;
import sx.blah.discord.handle.obj.IRole; import sx.blah.discord.handle.obj.IRole;
import sx.blah.discord.handle.obj.MessageChannel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -47,7 +47,7 @@ public class ExceptionListenerModule extends Component<DiscordPlugin> implements
private static void SendException(Throwable e, String sourcemessage) { private static void SendException(Throwable e, String sourcemessage) {
if (instance == null) return; if (instance == null) return;
try { try {
IChannel channel = getChannel(); MessageChannel channel = getChannel();
assert channel != null; assert channel != null;
IRole coderRole = instance.pingRole(channel.getGuild()).get(); IRole coderRole = instance.pingRole(channel.getGuild()).get();
StringBuilder sb = TBMCCoreAPI.IsTestServer() ? new StringBuilder() StringBuilder sb = TBMCCoreAPI.IsTestServer() ? new StringBuilder()
@ -69,12 +69,12 @@ public class ExceptionListenerModule extends Component<DiscordPlugin> implements
private static ExceptionListenerModule instance; private static ExceptionListenerModule instance;
public static IChannel getChannel() { public static MessageChannel getChannel() {
if (instance != null) return instance.channel().get(); if (instance != null) return instance.channel().get();
return null; return null;
} }
private ConfigData<IChannel> channel() { private ConfigData<MessageChannel> channel() {
return DPUtils.channelData(getConfig(), "channel", 239519012529111040L); return DPUtils.channelData(getConfig(), "channel", 239519012529111040L);
} }

View file

@ -80,7 +80,7 @@ public class FunModule extends Component<DiscordPlugin> implements Listener {
private static short ListC = 0; private static short ListC = 0;
public static boolean executeMemes(IMessage message) { public static boolean executeMemes(Message message) {
val fm = ComponentManager.getIfEnabled(FunModule.class); val fm = ComponentManager.getIfEnabled(FunModule.class);
if (fm == null) return false; if (fm == null) return false;
String msglowercased = message.getContent().toLowerCase(); String msglowercased = message.getContent().toLowerCase();
@ -119,7 +119,7 @@ public class FunModule extends Component<DiscordPlugin> implements Listener {
} }
private ConfigData<IChannel> fullHouseChannel() { private ConfigData<MessageChannel> fullHouseChannel() {
return DPUtils.channelData(getConfig(), "fullHouseChannel", 219626707458457603L); return DPUtils.channelData(getConfig(), "fullHouseChannel", 219626707458457603L);
} }

View file

@ -3,9 +3,9 @@ package buttondevteam.discordplugin.listeners;
import buttondevteam.discordplugin.DiscordPlugin; import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.discordplugin.commands.Command2DCSender; import buttondevteam.discordplugin.commands.Command2DCSender;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IRole; import sx.blah.discord.handle.obj.IRole;
import sx.blah.discord.handle.obj.Message;
import sx.blah.discord.handle.obj.MessageChannel;
public class CommandListener { public class CommandListener {
/** /**
@ -15,10 +15,10 @@ public class CommandListener {
* @param mentionedonly Only run the command if ChromaBot is mentioned at the start of the message * @param mentionedonly Only run the command if ChromaBot is mentioned at the start of the message
* @return Whether it ran the command * @return Whether it ran the command
*/ */
public static boolean runCommand(IMessage message, boolean mentionedonly) { public static boolean runCommand(Message message, boolean mentionedonly) {
if (message.getContent().length() == 0) if (message.getContent().length() == 0)
return false; //Pin messages and such, let the mcchat listener deal with it return false; //Pin messages and such, let the mcchat listener deal with it
final IChannel channel = message.getChannel(); final MessageChannel channel = message.getChannel();
if (!mentionedonly) { //mentionedonly conditions are in CommonListeners if (!mentionedonly) { //mentionedonly conditions are in CommonListeners
if (!message.getChannel().isPrivate() if (!message.getChannel().isPrivate()
&& !(message.getContent().charAt(0) == DiscordPlugin.getPrefix() && !(message.getContent().charAt(0) == DiscordPlugin.getPrefix()
@ -49,7 +49,7 @@ public class CommandListener {
return true; return true;
} }
private static boolean checkanddeletemention(StringBuilder cmdwithargs, String mention, IMessage message) { private static boolean checkanddeletemention(StringBuilder cmdwithargs, String mention, Message message) {
if (message.getContent().startsWith(mention)) // TODO: Resolve mentions: Compound arguments, either a mention or text if (message.getContent().startsWith(mention)) // TODO: Resolve mentions: Compound arguments, either a mention or text
if (cmdwithargs.length() > mention.length() + 1) { if (cmdwithargs.length() > mention.length() + 1) {
int i = cmdwithargs.indexOf(" ", mention.length()); int i = cmdwithargs.indexOf(" ", mention.length());

View file

@ -11,7 +11,7 @@ import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayer;
import lombok.val; import lombok.val;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import sx.blah.discord.handle.obj.IMessage; import sx.blah.discord.handle.obj.Message;
import sx.blah.discord.handle.obj.Permissions; import sx.blah.discord.handle.obj.Permissions;
import sx.blah.discord.util.PermissionUtils; import sx.blah.discord.util.PermissionUtils;
@ -124,7 +124,7 @@ public class ChannelconCommand extends ICommand2DC {
return true; return true;
} }
private boolean checkPerms(IMessage message) { private boolean checkPerms(Message message) {
if (!PermissionUtils.hasPermissions(message.getChannel(), message.getAuthor(), Permissions.MANAGE_CHANNEL)) { if (!PermissionUtils.hasPermissions(message.getChannel(), message.getAuthor(), Permissions.MANAGE_CHANNEL)) {
message.reply("you need to have manage permissions for this channel!"); message.reply("you need to have manage permissions for this channel!");
return true; return true;

View file

@ -6,8 +6,8 @@ import buttondevteam.discordplugin.DiscordConnectedPlayer;
import buttondevteam.lib.TBMCSystemChatEvent; import buttondevteam.lib.TBMCSystemChatEvent;
import lombok.NonNull; import lombok.NonNull;
import lombok.val; import lombok.val;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IUser; import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.handle.obj.MessageChannel;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
@ -21,7 +21,7 @@ public class MCChatCustom {
*/ */
static ArrayList<CustomLMD> lastmsgCustom = new ArrayList<>(); static ArrayList<CustomLMD> lastmsgCustom = new ArrayList<>();
public static void addCustomChat(IChannel channel, String groupid, Channel mcchannel, IUser user, DiscordConnectedPlayer dcp, int toggles, Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles) { public static void addCustomChat(MessageChannel channel, String groupid, Channel mcchannel, IUser user, DiscordConnectedPlayer dcp, int toggles, Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles) {
if (mcchannel instanceof ChatRoom) { if (mcchannel instanceof ChatRoom) {
((ChatRoom) mcchannel).joinRoom(dcp); ((ChatRoom) mcchannel).joinRoom(dcp);
if (groupid == null) groupid = mcchannel.getGroupID(dcp); if (groupid == null) groupid = mcchannel.getGroupID(dcp);
@ -30,16 +30,16 @@ public class MCChatCustom {
lastmsgCustom.add(lmd); lastmsgCustom.add(lmd);
} }
public static boolean hasCustomChat(IChannel channel) { public static boolean hasCustomChat(MessageChannel channel) {
return lastmsgCustom.stream().anyMatch(lmd -> lmd.channel.getLongID() == channel.getLongID()); return lastmsgCustom.stream().anyMatch(lmd -> lmd.channel.getLongID() == channel.getLongID());
} }
@Nullable @Nullable
public static CustomLMD getCustomChat(IChannel channel) { public static CustomLMD getCustomChat(MessageChannel channel) {
return lastmsgCustom.stream().filter(lmd -> lmd.channel.getLongID() == channel.getLongID()).findAny().orElse(null); return lastmsgCustom.stream().filter(lmd -> lmd.channel.getLongID() == channel.getLongID()).findAny().orElse(null);
} }
public static boolean removeCustomChat(IChannel channel) { public static boolean removeCustomChat(MessageChannel channel) {
MCChatUtils.lastmsgfromd.remove(channel.getLongID()); MCChatUtils.lastmsgfromd.remove(channel.getLongID());
return lastmsgCustom.removeIf(lmd -> { return lastmsgCustom.removeIf(lmd -> {
if (lmd.channel.getLongID() != channel.getLongID()) if (lmd.channel.getLongID() != channel.getLongID())
@ -61,7 +61,7 @@ public class MCChatCustom {
public int toggles; public int toggles;
public Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles; public Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles;
private CustomLMD(@NonNull IChannel channel, @NonNull IUser user, private CustomLMD(@NonNull MessageChannel channel, @NonNull IUser user,
@NonNull String groupid, @NonNull Channel mcchannel, @NonNull DiscordConnectedPlayer dcp, int toggles, Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles) { @NonNull String groupid, @NonNull Channel mcchannel, @NonNull DiscordConnectedPlayer dcp, int toggles, Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles) {
super(channel, user); super(channel, user);
groupID = groupid; groupID = groupid;

View file

@ -22,9 +22,9 @@ import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import sx.blah.discord.api.internal.json.objects.EmbedObject; import sx.blah.discord.api.internal.json.objects.EmbedObject;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent; import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IUser; import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.handle.obj.Message;
import sx.blah.discord.handle.obj.MessageChannel;
import sx.blah.discord.util.DiscordException; import sx.blah.discord.util.DiscordException;
import sx.blah.discord.util.EmbedBuilder; import sx.blah.discord.util.EmbedBuilder;
import sx.blah.discord.util.MissingPermissionsException; import sx.blah.discord.util.MissingPermissionsException;
@ -121,7 +121,7 @@ public class MCChatListener implements Listener {
}; };
// Checks if the given channel is different than where the message was sent from // Checks if the given channel is different than where the message was sent from
// Or if it was from MC // Or if it was from MC
Predicate<IChannel> isdifferentchannel = ch -> !(e.getSender() instanceof DiscordSenderBase) Predicate<MessageChannel> isdifferentchannel = ch -> !(e.getSender() instanceof DiscordSenderBase)
|| ((DiscordSenderBase) e.getSender()).getChannel().getLongID() != ch.getLongID(); || ((DiscordSenderBase) e.getSender()).getChannel().getLongID() != ch.getLongID();
if (e.getChannel().isGlobal() if (e.getChannel().isGlobal()
@ -276,7 +276,7 @@ public class MCChatListener implements Listener {
final String nick = u.getNicknameForGuild(DiscordPlugin.mainServer); final String nick = u.getNicknameForGuild(DiscordPlugin.mainServer);
dmessage = dmessage.replace(u.mention(true), "@" + (nick != null ? nick : u.getName())); dmessage = dmessage.replace(u.mention(true), "@" + (nick != null ? nick : u.getName()));
} }
for (IChannel ch : event.getMessage().getChannelMentions()) { for (MessageChannel ch : event.getMessage().getChannelMentions()) {
dmessage = dmessage.replace(ch.mention(), "#" + ch.getName()); // TODO: IG Formatting dmessage = dmessage.replace(ch.mention(), "#" + ch.getName()); // TODO: IG Formatting
} }
@ -285,7 +285,7 @@ public class MCChatListener implements Listener {
Function<String, String> getChatMessage = msg -> // Function<String, String> getChatMessage = msg -> //
msg + (event.getMessage().getAttachments().size() > 0 ? "\n" + event.getMessage() msg + (event.getMessage().getAttachments().size() > 0 ? "\n" + event.getMessage()
.getAttachments().stream().map(IMessage.Attachment::getUrl).collect(Collectors.joining("\n")) .getAttachments().stream().map(Message.Attachment::getUrl).collect(Collectors.joining("\n"))
: ""); : "");
MCChatCustom.CustomLMD clmd = MCChatCustom.getCustomChat(event.getChannel()); MCChatCustom.CustomLMD clmd = MCChatCustom.getCustomChat(event.getChannel());

View file

@ -9,9 +9,9 @@ import org.bukkit.Bukkit;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IPrivateChannel; import sx.blah.discord.handle.obj.IPrivateChannel;
import sx.blah.discord.handle.obj.IUser; import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.handle.obj.MessageChannel;
import java.util.ArrayList; import java.util.ArrayList;
@ -22,7 +22,7 @@ public class MCChatPrivate {
*/ */
static ArrayList<MCChatUtils.LastMsgData> lastmsgPerUser = new ArrayList<>(); static ArrayList<MCChatUtils.LastMsgData> lastmsgPerUser = new ArrayList<>();
public static boolean privateMCChat(IChannel channel, boolean start, IUser user, DiscordPlayer dp) { public static boolean privateMCChat(MessageChannel channel, boolean start, IUser user, DiscordPlayer dp) {
TBMCPlayer mcp = dp.getAs(TBMCPlayer.class); TBMCPlayer mcp = dp.getAs(TBMCPlayer.class);
if (mcp != null) { // If the accounts aren't connected, can't make a connected sender if (mcp != null) { // If the accounts aren't connected, can't make a connected sender
val p = Bukkit.getPlayer(mcp.getUUID()); val p = Bukkit.getPlayer(mcp.getUUID());

View file

@ -12,7 +12,7 @@ import com.google.common.collect.Lists;
import lombok.Getter; import lombok.Getter;
import lombok.val; import lombok.val;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import sx.blah.discord.handle.obj.IChannel; import sx.blah.discord.handle.obj.MessageChannel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Objects; import java.util.Objects;
@ -40,14 +40,14 @@ public class MinecraftChatModule extends Component<DiscordPlugin> {
/** /**
* The channel to use as the public Minecraft chat - everything public gets broadcasted here * The channel to use as the public Minecraft chat - everything public gets broadcasted here
*/ */
public ConfigData<IChannel> chatChannel() { public ConfigData<MessageChannel> chatChannel() {
return DPUtils.channelData(getConfig(), "chatChannel", 239519012529111040L); return DPUtils.channelData(getConfig(), "chatChannel", 239519012529111040L);
} }
/** /**
* The channel where the plugin can log when it mutes a player on Discord because of a Minecraft mute * The channel where the plugin can log when it mutes a player on Discord because of a Minecraft mute
*/ */
public ConfigData<IChannel> modlogChannel() { public ConfigData<MessageChannel> modlogChannel() {
return DPUtils.channelData(getConfig(), "modlogChannel", 283840717275791360L); return DPUtils.channelData(getConfig(), "modlogChannel", 283840717275791360L);
} }

View file

@ -11,8 +11,8 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.metadata.MetadataValue; import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IUser; import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.handle.obj.MessageChannel;
import java.util.*; import java.util.*;
@ -20,7 +20,7 @@ import java.util.*;
@Setter @Setter
@SuppressWarnings("deprecated") @SuppressWarnings("deprecated")
public abstract class DiscordEntity extends DiscordSenderBase implements Entity { public abstract class DiscordEntity extends DiscordSenderBase implements Entity {
protected DiscordEntity(IUser user, IChannel channel, int entityId, UUID uuid) { protected DiscordEntity(IUser user, MessageChannel channel, int entityId, UUID uuid) {
super(user, channel); super(user, channel);
this.entityId = entityId; this.entityId = entityId;
uniqueId = uuid; uniqueId = uuid;

View file

@ -16,15 +16,15 @@ import org.bukkit.map.MapView;
import org.bukkit.permissions.PermissibleBase; import org.bukkit.permissions.PermissibleBase;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Scoreboard;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IUser; import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.handle.obj.MessageChannel;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.*; import java.util.*;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class DiscordFakePlayer extends DiscordHumanEntity implements Player { public class DiscordFakePlayer extends DiscordHumanEntity implements Player {
protected DiscordFakePlayer(IUser user, IChannel channel, int entityId, UUID uuid, String mcname) { protected DiscordFakePlayer(IUser user, MessageChannel channel, int entityId, UUID uuid, String mcname) {
super(user, channel, entityId, uuid); super(user, channel, entityId, uuid);
perm = new PermissibleBase(Bukkit.getOfflinePlayer(uuid)); perm = new PermissibleBase(Bukkit.getOfflinePlayer(uuid));
name = mcname; name = mcname;

View file

@ -8,13 +8,13 @@ import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Villager; import org.bukkit.entity.Villager;
import org.bukkit.inventory.*; import org.bukkit.inventory.*;
import org.bukkit.inventory.InventoryView.Property; import org.bukkit.inventory.InventoryView.Property;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IUser; import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.handle.obj.MessageChannel;
import java.util.UUID; import java.util.UUID;
public abstract class DiscordHumanEntity extends DiscordLivingEntity implements HumanEntity { public abstract class DiscordHumanEntity extends DiscordLivingEntity implements HumanEntity {
protected DiscordHumanEntity(IUser user, IChannel channel, int entityId, UUID uuid) { protected DiscordHumanEntity(IUser user, MessageChannel channel, int entityId, UUID uuid) {
super(user, channel, entityId, uuid); super(user, channel, entityId, uuid);
} }

View file

@ -16,14 +16,14 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IUser; import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.handle.obj.MessageChannel;
import java.util.*; import java.util.*;
public abstract class DiscordLivingEntity extends DiscordEntity implements LivingEntity { public abstract class DiscordLivingEntity extends DiscordEntity implements LivingEntity {
protected DiscordLivingEntity(IUser user, IChannel channel, int entityId, UUID uuid) { protected DiscordLivingEntity(IUser user, MessageChannel channel, int entityId, UUID uuid) {
super(user, channel, entityId, uuid); super(user, channel, entityId, uuid);
} }

View file

@ -13,12 +13,6 @@ import discord4j.core.object.entity.MessageChannel;
import discord4j.core.object.entity.Role; import discord4j.core.object.entity.Role;
import lombok.val; import lombok.val;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import sx.blah.discord.handle.impl.events.guild.role.RoleCreateEvent;
import sx.blah.discord.handle.impl.events.guild.role.RoleDeleteEvent;
import sx.blah.discord.handle.impl.events.guild.role.RoleEvent;
import sx.blah.discord.handle.impl.events.guild.role.RoleUpdateEvent;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IRole;
import java.awt.*; import java.awt.*;
import java.util.List; import java.util.List;
@ -60,7 +54,7 @@ public class GameRoleModule extends Component<DiscordPlugin> {
Role role=((RoleDeleteEvent) roleEvent).getRole().orElse(null); Role role=((RoleDeleteEvent) roleEvent).getRole().orElse(null);
if(role==null) return; if(role==null) return;
if (GameRoles.remove(role.getName()) && logChannel != null) if (GameRoles.remove(role.getName()) && logChannel != null)
logChannel, "Removed " + role.getName() + " as a game role."); logChannel, "Removed " + role.getName() + " as a game role.")
} else if (roleEvent instanceof RoleUpdateEvent) { } else if (roleEvent instanceof RoleUpdateEvent) {
val event = (RoleUpdateEvent) roleEvent; val event = (RoleUpdateEvent) roleEvent;
if(!event.getOld().isPresent()) { if(!event.getOld().isPresent()) {