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;
|
||||
|
||||
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.mccommands.DiscordMCCommandBase;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
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 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.internal.json.objects.EmbedObject;
|
||||
import sx.blah.discord.handle.impl.events.ReadyEvent;
|
||||
import sx.blah.discord.handle.impl.obj.ReactionEmoji;
|
||||
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> {
|
||||
private static final String SubredditURL = "https://www.reddit.com/r/ChromaGamers";
|
||||
|
@ -91,6 +92,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
@Override
|
||||
public void handle(ReadyEvent event) {
|
||||
try {
|
||||
dc.changePresence(StatusType.DND, ActivityType.PLAYING, "booting");
|
||||
task = Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
|
||||
if (mainServer == null || devServer == null) {
|
||||
mainServer = event.getClient().getGuildByID(125813020357165056L);
|
||||
|
@ -107,7 +109,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
officechannel = devServer.getChannelByID(219626707458457603L); // developers-office
|
||||
updatechannel = devServer.getChannelByID(233724163519414272L); // server-updates
|
||||
devofficechannel = officechannel; // developers-office
|
||||
dc.online("on TBMC");
|
||||
dc.changePresence(StatusType.ONLINE, ActivityType.PLAYING, "Chromacraft");
|
||||
} else {
|
||||
botchannel = devServer.getChannelByID(239519012529111040L); // bot-room
|
||||
annchannel = botchannel; // bot-room
|
||||
|
@ -117,7 +119,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
officechannel = devServer.getChannelByID(219626707458457603L); // developers-office
|
||||
updatechannel = botchannel;
|
||||
devofficechannel = botchannel;// bot-room
|
||||
dc.online("testing");
|
||||
dc.changePresence(StatusType.ONLINE, ActivityType.PLAYING, "testing");
|
||||
}
|
||||
if (botchannel == null || annchannel == null || genchannel == null || botroomchannel == null
|
||||
|| chatchannel == null || officechannel == null || updatechannel == null)
|
||||
|
@ -146,7 +148,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
genchannel.unpin(msgs.get(i));
|
||||
Thread.sleep(10);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
} catch (InterruptedException ignore) {
|
||||
}
|
||||
});
|
||||
sent = true;
|
||||
|
@ -224,10 +226,11 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
+ "asked *politely* to leave the server for a bit.")
|
||||
: "")
|
||||
.build()));
|
||||
ChromaBot.getInstance().updatePlayerList();
|
||||
try {
|
||||
SafeMode = true; // Stop interacting with Discord
|
||||
ChromaBot.delete();
|
||||
dc.online("on TBMC");
|
||||
dc.changePresence(StatusType.IDLE, ActivityType.PLAYING, "Chromacraft"); //No longer using the same account for testing
|
||||
dc.logout();
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("An error occured while disabling DiscordPlugin!", e);
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import buttondevteam.discordplugin.DPUtils;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import sx.blah.discord.handle.obj.IMessage;
|
||||
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 {
|
||||
|
||||
@Override
|
||||
|
@ -50,20 +51,18 @@ public class RoleCommand extends DiscordCommandBase {
|
|||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||
"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")) {
|
||||
if (!message.getAuthor().getRolesForGuild(DiscordPlugin.mainServer).stream()
|
||||
.anyMatch(r -> r.getLongID() == 126030201472811008L)) {
|
||||
if (message.getAuthor().getRolesForGuild(DiscordPlugin.mainServer).stream()
|
||||
.noneMatch(r -> r.getLongID() == 126030201472811008L)) {
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||
"You need to be a moderator to use this command.");
|
||||
return;
|
||||
}
|
||||
if (argsa.length < 2) {
|
||||
if (argsa.length < 3) {
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||
"Add a role to the game role list.\nUsage: " + argsa[0] + " <rolename>");
|
||||
return;
|
||||
}
|
||||
String rolename = argsa[1];
|
||||
for (int i = 2; i < argsa.length; i++)
|
||||
rolename += " " + argsa[i];
|
||||
String rolename = Arrays.stream(argsa).skip(2).collect(Collectors.joining(" "));
|
||||
final List<IRole> roles = (TBMCCoreAPI.IsTestServer() ? DiscordPlugin.devServer : DiscordPlugin.mainServer)
|
||||
.getRolesByName(rolename);
|
||||
if (roles.size() == 0) {
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
package buttondevteam.discordplugin.listeners;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.function.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import buttondevteam.discordplugin.*;
|
||||
import buttondevteam.discordplugin.playerfaker.VanillaCommandListener;
|
||||
import buttondevteam.lib.TBMCChatEvent;
|
||||
import buttondevteam.lib.TBMCChatPreprocessEvent;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
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.entity.Player;
|
||||
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.PlayerQuitEvent;
|
||||
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.internal.json.objects.EmbedObject;
|
||||
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
|
||||
import sx.blah.discord.handle.obj.*;
|
||||
import sx.blah.discord.util.*;
|
||||
import sx.blah.discord.handle.obj.IChannel;
|
||||
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> {
|
||||
private BukkitTask sendtask;
|
||||
|
@ -65,7 +78,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
DPUtils.embedWithHead(
|
||||
embed.withAuthorUrl("https://tbmcplugins.github.io/profile.html?type=minecraft&id="
|
||||
+ ((Player) e.getSender()).getUniqueId()),
|
||||
((Player) e.getSender()).getName());
|
||||
e.getSender().getName());
|
||||
else if (e.getSender() instanceof DiscordSenderBase)
|
||||
embed.withAuthorIcon(((DiscordSenderBase) e.getSender()).getUser().getAvatarURL())
|
||||
.withAuthorUrl("https://tbmcplugins.github.io/profile.html?type=discord&id="
|
||||
|
|
Loading…
Reference in a new issue