NPE fix, prefix
This commit is contained in:
parent
1878a46041
commit
21221dfeeb
7 changed files with 30 additions and 18 deletions
|
@ -12,7 +12,9 @@ import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
|
||||||
import buttondevteam.discordplugin.mccommands.DiscordMCCommandBase;
|
import buttondevteam.discordplugin.mccommands.DiscordMCCommandBase;
|
||||||
import buttondevteam.discordplugin.mccommands.ResetMCCommand;
|
import buttondevteam.discordplugin.mccommands.ResetMCCommand;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
|
import buttondevteam.lib.architecture.ButtonPlugin;
|
||||||
import buttondevteam.lib.architecture.Component;
|
import buttondevteam.lib.architecture.Component;
|
||||||
|
import buttondevteam.lib.architecture.ConfigData;
|
||||||
import buttondevteam.lib.chat.Channel;
|
import buttondevteam.lib.chat.Channel;
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
import buttondevteam.lib.player.ChromaGamerBase;
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
|
@ -27,7 +29,6 @@ import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import sx.blah.discord.api.ClientBuilder;
|
import sx.blah.discord.api.ClientBuilder;
|
||||||
import sx.blah.discord.api.IDiscordClient;
|
import sx.blah.discord.api.IDiscordClient;
|
||||||
|
@ -49,7 +50,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
public class DiscordPlugin extends ButtonPlugin 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";
|
||||||
private static boolean stop = false;
|
private static boolean stop = false;
|
||||||
public static IDiscordClient dc;
|
public static IDiscordClient dc;
|
||||||
|
@ -57,8 +58,17 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
public static boolean SafeMode = true;
|
public static boolean SafeMode = true;
|
||||||
public static List<String> GameRoles;
|
public static List<String> GameRoles;
|
||||||
|
|
||||||
|
public ConfigData<Character> Prefix() {
|
||||||
|
return getData("prefix", '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static char getPrefix() {
|
||||||
|
if (plugin == null) return '/';
|
||||||
|
return plugin.Prefix().get();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void pluginEnable() {
|
||||||
stop = false; //If not the first time
|
stop = false; //If not the first time
|
||||||
try {
|
try {
|
||||||
Bukkit.getLogger().info("Initializing DiscordPlugin...");
|
Bukkit.getLogger().info("Initializing DiscordPlugin...");
|
||||||
|
@ -238,7 +248,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
public static boolean Restart;
|
public static boolean Restart;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void pluginDisable() {
|
||||||
stop = true;
|
stop = true;
|
||||||
for (val entry : MCChatUtils.ConnectedSenders.entrySet())
|
for (val entry : MCChatUtils.ConnectedSenders.entrySet())
|
||||||
for (val valueEntry : entry.getValue().entrySet())
|
for (val valueEntry : entry.getValue().entrySet())
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class ConnectCommand extends DiscordCommandBase {
|
||||||
return false;
|
return false;
|
||||||
if (args.contains(" ")) {
|
if (args.contains(" ")) {
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
"Too many arguments.\nUsage: connect <Minecraftname>");
|
"Too many arguments.\nUsage: " + DiscordPlugin.getPrefix() + "connect <Minecraftname>");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (WaitingToConnect.inverse().containsKey(message.getAuthor().getStringID())) {
|
if (WaitingToConnect.inverse().containsKey(message.getAuthor().getStringID())) {
|
||||||
|
@ -68,8 +68,8 @@ public class ConnectCommand extends DiscordCommandBase {
|
||||||
public String[] getHelpText() {
|
public String[] getHelpText() {
|
||||||
return new String[] { //
|
return new String[] { //
|
||||||
"---- Connect command ----", //
|
"---- Connect command ----", //
|
||||||
"This commands let's you connect your acoount with a Minecraft account. This'd allow using the Minecraft chat and other things.", //
|
"This command lets you connect your account with a Minecraft account. This allows using the Minecraft chat and other things.", //
|
||||||
"Usage: connect <Minecraftname>" //
|
"Usage: /connect <Minecraftname>" //
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package buttondevteam.discordplugin.commands;
|
||||||
import buttondevteam.discordplugin.DiscordPlugin;
|
import buttondevteam.discordplugin.DiscordPlugin;
|
||||||
import sx.blah.discord.handle.obj.IMessage;
|
import sx.blah.discord.handle.obj.IMessage;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class HelpCommand extends DiscordCommandBase {
|
public class HelpCommand extends DiscordCommandBase {
|
||||||
|
@ -19,11 +18,11 @@ public class HelpCommand extends DiscordCommandBase {
|
||||||
if (args.length() == 0)
|
if (args.length() == 0)
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
"Available commands:\n" + DiscordCommandBase.commands.values().stream()
|
"Available commands:\n" + DiscordCommandBase.commands.values().stream()
|
||||||
.map(dc -> dc.getCommandName()).collect(Collectors.joining("\n")));
|
.map(dc -> DiscordPlugin.getPrefix() + dc.getCommandName()).collect(Collectors.joining("\n")));
|
||||||
else
|
else
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
(argdc = DiscordCommandBase.commands.get(args)) == null ? "Command not found: " + args
|
(argdc = DiscordCommandBase.commands.get(args)) == null ? "Command not found: " + args
|
||||||
: Arrays.stream(argdc.getHelpText()).collect(Collectors.joining("\n")));
|
: String.join("\n", argdc.getHelpText()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +31,7 @@ public class HelpCommand extends DiscordCommandBase {
|
||||||
return new String[] { //
|
return new String[] { //
|
||||||
"---- Help command ----", //
|
"---- Help command ----", //
|
||||||
"Shows some info about a command or lists the available commands.", //
|
"Shows some info about a command or lists the available commands.", //
|
||||||
"Usage: help [command]"//
|
"Usage: " + DiscordPlugin.getPrefix() + "help [command]"//
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class MCChatCommand extends DiscordCommandBase {
|
||||||
MCChatPrivate.privateMCChat(message.getChannel(), mcchat, message.getAuthor(), user);
|
MCChatPrivate.privateMCChat(message.getChannel(), mcchat, message.getAuthor(), user);
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
"Minecraft chat " + (mcchat //
|
"Minecraft chat " + (mcchat //
|
||||||
? "enabled. Use '/mcchat' again to turn it off." //
|
? "enabled. Use '" + DiscordPlugin.getPrefix() + "mcchat' again to turn it off." //
|
||||||
: "disabled."));
|
: "disabled."));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TBMCCoreAPI.SendException("Error while setting mcchat for user" + message.getAuthor().getName(), e);
|
TBMCCoreAPI.SendException("Error while setting mcchat for user" + message.getAuthor().getName(), e);
|
||||||
|
@ -36,8 +36,9 @@ public class MCChatCommand extends DiscordCommandBase {
|
||||||
@Override
|
@Override
|
||||||
public String[] getHelpText() {
|
public String[] getHelpText() {
|
||||||
return new String[] { //
|
return new String[] { //
|
||||||
"mcchat enables or disables the Minecraft chat in private messages.", //
|
DiscordPlugin.getPrefix() + "mcchat enables or disables the Minecraft chat in private messages.", //
|
||||||
"It can be useful if you don't want your messages to be visible, for example when talking a private channel." //
|
"It can be useful if you don't want your messages to be visible, for example when talking in a private channel.", //
|
||||||
|
"You can also run all of the ingame commands you have access to using this command, if you have your accounts connected." //
|
||||||
}; // TODO: Pin channel switching to indicate the current channel
|
}; // TODO: Pin channel switching to indicate the current channel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class RoleCommand extends DiscordCommandBase {
|
||||||
public String[] getHelpText() {
|
public String[] getHelpText() {
|
||||||
return new String[]{ //
|
return new String[]{ //
|
||||||
"Add or remove game roles from yourself.", //
|
"Add or remove game roles from yourself.", //
|
||||||
"Usage: role add|remove <name> or role list", //
|
"Usage: " + DiscordPlugin.getPrefix() + "role add|remove <name> or role list", //
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,8 @@ public class UserinfoCommand extends DiscordCommandBase {
|
||||||
"---- User information ----", //
|
"---- User information ----", //
|
||||||
"Shows some information about users, from Discord, from Minecraft or from Reddit if they have these accounts connected.", //
|
"Shows some information about users, from Discord, from Minecraft or from Reddit if they have these accounts connected.", //
|
||||||
"If used without args, shows your info.", //
|
"If used without args, shows your info.", //
|
||||||
"Usage: userinfo [username/nickname[#tag]/ping]\nExamples:\nuserinfo ChromaBot\nuserinfo ChromaBot#6338\nuserinfo @ChromaBot#6338" //
|
"Usage: " + DiscordPlugin.getPrefix() + "userinfo [username/nickname[#tag]/ping]", //
|
||||||
|
"Examples:\n" + DiscordPlugin.getPrefix() + "userinfo ChromaBot\n" + DiscordPlugin.getPrefix() + "userinfo ChromaBot#6338\n" + DiscordPlugin.getPrefix() + "userinfo @ChromaBot#6338" //
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -382,8 +382,9 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
} else {// Not a command
|
} else {// Not a command
|
||||||
if (dmessage.length() == 0 && event.getMessage().getAttachments().size() == 0
|
if (dmessage.length() == 0 && event.getMessage().getAttachments().size() == 0
|
||||||
&& !event.getChannel().isPrivate() && event.getMessage().isSystemMessage()) {
|
&& !event.getChannel().isPrivate() && event.getMessage().isSystemMessage()) {
|
||||||
val rtr = clmd != null ? clmd.mcchannel.filteranderrormsg.apply(clmd.dcp) : dsender.getChromaUser().channel().get().filteranderrormsg.apply(dsender);
|
val rtr = clmd != null ? clmd.mcchannel.getRTR(clmd.dcp)
|
||||||
TBMCChatAPI.SendSystemMessage(clmd != null ? clmd.mcchannel : dsender.getChromaUser().channel().get(), rtr.score, rtr.groupID,
|
: dsender.getChromaUser().channel().get().getRTR(dsender);
|
||||||
|
TBMCChatAPI.SendSystemMessage(clmd != null ? clmd.mcchannel : dsender.getChromaUser().channel().get(), rtr,
|
||||||
(dsender instanceof Player ? ((Player) dsender).getDisplayName()
|
(dsender instanceof Player ? ((Player) dsender).getDisplayName()
|
||||||
: dsender.getName()) + " pinned a message on Discord.");
|
: dsender.getName()) + " pinned a message on Discord.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue