Fixed role admin cmds
And some code analysis stuff
This commit is contained in:
parent
42966d0feb
commit
b31aea0c04
3 changed files with 365 additions and 350 deletions
|
@ -1,37 +1,38 @@
|
||||||
package buttondevteam.discordplugin;
|
package buttondevteam.discordplugin;
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.io.File;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
|
|
||||||
import com.google.common.io.Files;
|
|
||||||
import com.google.gson.*;
|
|
||||||
|
|
||||||
import buttondevteam.discordplugin.listeners.*;
|
import buttondevteam.discordplugin.listeners.*;
|
||||||
import buttondevteam.discordplugin.mccommands.DiscordMCCommandBase;
|
import buttondevteam.discordplugin.mccommands.DiscordMCCommandBase;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
import buttondevteam.lib.player.ChromaGamerBase;
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
|
import com.google.common.io.Files;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
import sx.blah.discord.api.*;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
import sx.blah.discord.api.ClientBuilder;
|
||||||
|
import sx.blah.discord.api.IDiscordClient;
|
||||||
import sx.blah.discord.api.events.IListener;
|
import sx.blah.discord.api.events.IListener;
|
||||||
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.ReadyEvent;
|
import sx.blah.discord.handle.impl.events.ReadyEvent;
|
||||||
import sx.blah.discord.handle.impl.obj.ReactionEmoji;
|
import sx.blah.discord.handle.impl.obj.ReactionEmoji;
|
||||||
import sx.blah.discord.handle.obj.*;
|
import sx.blah.discord.handle.obj.*;
|
||||||
import sx.blah.discord.util.*;
|
import sx.blah.discord.util.EmbedBuilder;
|
||||||
|
import sx.blah.discord.util.RequestBuffer;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
private static final String SubredditURL = "https://www.reddit.com/r/ChromaGamers";
|
private static final String SubredditURL = "https://www.reddit.com/r/ChromaGamers";
|
||||||
|
@ -91,6 +92,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
@Override
|
@Override
|
||||||
public void handle(ReadyEvent event) {
|
public void handle(ReadyEvent event) {
|
||||||
try {
|
try {
|
||||||
|
dc.changePresence(StatusType.DND, ActivityType.PLAYING, "booting");
|
||||||
task = Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
|
task = Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
|
||||||
if (mainServer == null || devServer == null) {
|
if (mainServer == null || devServer == null) {
|
||||||
mainServer = event.getClient().getGuildByID(125813020357165056L);
|
mainServer = event.getClient().getGuildByID(125813020357165056L);
|
||||||
|
@ -107,7 +109,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
officechannel = devServer.getChannelByID(219626707458457603L); // developers-office
|
officechannel = devServer.getChannelByID(219626707458457603L); // developers-office
|
||||||
updatechannel = devServer.getChannelByID(233724163519414272L); // server-updates
|
updatechannel = devServer.getChannelByID(233724163519414272L); // server-updates
|
||||||
devofficechannel = officechannel; // developers-office
|
devofficechannel = officechannel; // developers-office
|
||||||
dc.online("on TBMC");
|
dc.changePresence(StatusType.ONLINE, ActivityType.PLAYING, "Chromacraft");
|
||||||
} else {
|
} else {
|
||||||
botchannel = devServer.getChannelByID(239519012529111040L); // bot-room
|
botchannel = devServer.getChannelByID(239519012529111040L); // bot-room
|
||||||
annchannel = botchannel; // bot-room
|
annchannel = botchannel; // bot-room
|
||||||
|
@ -117,7 +119,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
officechannel = devServer.getChannelByID(219626707458457603L); // developers-office
|
officechannel = devServer.getChannelByID(219626707458457603L); // developers-office
|
||||||
updatechannel = botchannel;
|
updatechannel = botchannel;
|
||||||
devofficechannel = botchannel;// bot-room
|
devofficechannel = botchannel;// bot-room
|
||||||
dc.online("testing");
|
dc.changePresence(StatusType.ONLINE, ActivityType.PLAYING, "testing");
|
||||||
}
|
}
|
||||||
if (botchannel == null || annchannel == null || genchannel == null || botroomchannel == null
|
if (botchannel == null || annchannel == null || genchannel == null || botroomchannel == null
|
||||||
|| chatchannel == null || officechannel == null || updatechannel == null)
|
|| chatchannel == null || officechannel == null || updatechannel == null)
|
||||||
|
@ -146,7 +148,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
genchannel.unpin(msgs.get(i));
|
genchannel.unpin(msgs.get(i));
|
||||||
Thread.sleep(10);
|
Thread.sleep(10);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException ignore) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sent = true;
|
sent = true;
|
||||||
|
@ -224,10 +226,11 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
+ "asked *politely* to leave the server for a bit.")
|
+ "asked *politely* to leave the server for a bit.")
|
||||||
: "")
|
: "")
|
||||||
.build()));
|
.build()));
|
||||||
|
ChromaBot.getInstance().updatePlayerList();
|
||||||
try {
|
try {
|
||||||
SafeMode = true; // Stop interacting with Discord
|
SafeMode = true; // Stop interacting with Discord
|
||||||
ChromaBot.delete();
|
ChromaBot.delete();
|
||||||
dc.online("on TBMC");
|
dc.changePresence(StatusType.IDLE, ActivityType.PLAYING, "Chromacraft"); //No longer using the same account for testing
|
||||||
dc.logout();
|
dc.logout();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TBMCCoreAPI.SendException("An error occured while disabling DiscordPlugin!", e);
|
TBMCCoreAPI.SendException("An error occured while disabling DiscordPlugin!", e);
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
package buttondevteam.discordplugin.commands;
|
package buttondevteam.discordplugin.commands;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import buttondevteam.discordplugin.DPUtils;
|
import buttondevteam.discordplugin.DPUtils;
|
||||||
import buttondevteam.discordplugin.DiscordPlugin;
|
import buttondevteam.discordplugin.DiscordPlugin;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import sx.blah.discord.handle.obj.IMessage;
|
import sx.blah.discord.handle.obj.IMessage;
|
||||||
import sx.blah.discord.handle.obj.IRole;
|
import sx.blah.discord.handle.obj.IRole;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class RoleCommand extends DiscordCommandBase {
|
public class RoleCommand extends DiscordCommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,20 +51,18 @@ public class RoleCommand extends DiscordCommandBase {
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
"List of game roles:\n" + DiscordPlugin.GameRoles.stream().collect(Collectors.joining("\n")));
|
"List of game roles:\n" + DiscordPlugin.GameRoles.stream().collect(Collectors.joining("\n")));
|
||||||
} else if (argsa[0].equalsIgnoreCase("admin") && argsa.length > 1 && argsa[1].equalsIgnoreCase("addrole")) {
|
} else if (argsa[0].equalsIgnoreCase("admin") && argsa.length > 1 && argsa[1].equalsIgnoreCase("addrole")) {
|
||||||
if (!message.getAuthor().getRolesForGuild(DiscordPlugin.mainServer).stream()
|
if (message.getAuthor().getRolesForGuild(DiscordPlugin.mainServer).stream()
|
||||||
.anyMatch(r -> r.getLongID() == 126030201472811008L)) {
|
.noneMatch(r -> r.getLongID() == 126030201472811008L)) {
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
"You need to be a moderator to use this command.");
|
"You need to be a moderator to use this command.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (argsa.length < 2) {
|
if (argsa.length < 3) {
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
"Add a role to the game role list.\nUsage: " + argsa[0] + " <rolename>");
|
"Add a role to the game role list.\nUsage: " + argsa[0] + " <rolename>");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String rolename = argsa[1];
|
String rolename = Arrays.stream(argsa).skip(2).collect(Collectors.joining(" "));
|
||||||
for (int i = 2; i < argsa.length; i++)
|
|
||||||
rolename += " " + argsa[i];
|
|
||||||
final List<IRole> roles = (TBMCCoreAPI.IsTestServer() ? DiscordPlugin.devServer : DiscordPlugin.mainServer)
|
final List<IRole> roles = (TBMCCoreAPI.IsTestServer() ? DiscordPlugin.devServer : DiscordPlugin.mainServer)
|
||||||
.getRolesByName(rolename);
|
.getRolesByName(rolename);
|
||||||
if (roles.size() == 0) {
|
if (roles.size() == 0) {
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
package buttondevteam.discordplugin.listeners;
|
package buttondevteam.discordplugin.listeners;
|
||||||
|
|
||||||
import java.awt.Color;
|
import buttondevteam.discordplugin.*;
|
||||||
import java.util.*;
|
import buttondevteam.discordplugin.playerfaker.VanillaCommandListener;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import buttondevteam.lib.TBMCChatEvent;
|
||||||
import java.util.function.*;
|
import buttondevteam.lib.TBMCChatPreprocessEvent;
|
||||||
import java.util.stream.Collectors;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import java.util.stream.Stream;
|
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||||
|
import buttondevteam.lib.chat.Channel;
|
||||||
|
import buttondevteam.lib.chat.ChatRoom;
|
||||||
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
|
import buttondevteam.lib.player.TBMCPlayer;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.val;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
@ -14,21 +19,29 @@ import org.bukkit.event.Listener;
|
||||||
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 org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import buttondevteam.discordplugin.*;
|
|
||||||
import buttondevteam.discordplugin.playerfaker.VanillaCommandListener;
|
|
||||||
import buttondevteam.lib.*;
|
|
||||||
import buttondevteam.lib.chat.Channel;
|
|
||||||
import buttondevteam.lib.chat.ChatRoom;
|
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.val;
|
|
||||||
import sx.blah.discord.api.events.IListener;
|
import sx.blah.discord.api.events.IListener;
|
||||||
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.*;
|
import sx.blah.discord.handle.obj.IChannel;
|
||||||
import sx.blah.discord.util.*;
|
import sx.blah.discord.handle.obj.IMessage;
|
||||||
|
import sx.blah.discord.handle.obj.IPrivateChannel;
|
||||||
|
import sx.blah.discord.handle.obj.IUser;
|
||||||
|
import sx.blah.discord.util.DiscordException;
|
||||||
|
import sx.blah.discord.util.EmbedBuilder;
|
||||||
|
import sx.blah.discord.util.MissingPermissionsException;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class MCChatListener implements Listener, IListener<MessageReceivedEvent> {
|
public class MCChatListener implements Listener, IListener<MessageReceivedEvent> {
|
||||||
private BukkitTask sendtask;
|
private BukkitTask sendtask;
|
||||||
|
@ -65,7 +78,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
DPUtils.embedWithHead(
|
DPUtils.embedWithHead(
|
||||||
embed.withAuthorUrl("https://tbmcplugins.github.io/profile.html?type=minecraft&id="
|
embed.withAuthorUrl("https://tbmcplugins.github.io/profile.html?type=minecraft&id="
|
||||||
+ ((Player) e.getSender()).getUniqueId()),
|
+ ((Player) e.getSender()).getUniqueId()),
|
||||||
((Player) e.getSender()).getName());
|
e.getSender().getName());
|
||||||
else if (e.getSender() instanceof DiscordSenderBase)
|
else if (e.getSender() instanceof DiscordSenderBase)
|
||||||
embed.withAuthorIcon(((DiscordSenderBase) e.getSender()).getUser().getAvatarURL())
|
embed.withAuthorIcon(((DiscordSenderBase) e.getSender()).getUser().getAvatarURL())
|
||||||
.withAuthorUrl("https://tbmcplugins.github.io/profile.html?type=discord&id="
|
.withAuthorUrl("https://tbmcplugins.github.io/profile.html?type=discord&id="
|
||||||
|
|
Loading…
Reference in a new issue