NPE fix, prefix

This commit is contained in:
Norbi Peti 2018-12-18 00:52:02 +01:00
parent 1878a46041
commit 21221dfeeb
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
7 changed files with 30 additions and 18 deletions

View file

@ -12,7 +12,9 @@ import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
import buttondevteam.discordplugin.mccommands.DiscordMCCommandBase;
import buttondevteam.discordplugin.mccommands.ResetMCCommand;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.architecture.ButtonPlugin;
import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.player.ChromaGamerBase;
@ -27,7 +29,6 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
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;
@ -49,7 +50,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
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 boolean stop = false;
public static IDiscordClient dc;
@ -57,8 +58,17 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
public static boolean SafeMode = true;
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
public void onEnable() {
public void pluginEnable() {
stop = false; //If not the first time
try {
Bukkit.getLogger().info("Initializing DiscordPlugin...");
@ -238,7 +248,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
public static boolean Restart;
@Override
public void onDisable() {
public void pluginDisable() {
stop = true;
for (val entry : MCChatUtils.ConnectedSenders.entrySet())
for (val valueEntry : entry.getValue().entrySet())

View file

@ -30,7 +30,7 @@ public class ConnectCommand extends DiscordCommandBase {
return false;
if (args.contains(" ")) {
DiscordPlugin.sendMessageToChannel(message.getChannel(),
"Too many arguments.\nUsage: connect <Minecraftname>");
"Too many arguments.\nUsage: " + DiscordPlugin.getPrefix() + "connect <Minecraftname>");
return true;
}
if (WaitingToConnect.inverse().containsKey(message.getAuthor().getStringID())) {
@ -68,8 +68,8 @@ public class ConnectCommand extends DiscordCommandBase {
public String[] getHelpText() {
return new String[] { //
"---- Connect command ----", //
"This commands let's you connect your acoount with a Minecraft account. This'd allow using the Minecraft chat and other things.", //
"Usage: connect <Minecraftname>" //
"This command lets you connect your account with a Minecraft account. This allows using the Minecraft chat and other things.", //
"Usage: /connect <Minecraftname>" //
};
}

View file

@ -3,7 +3,6 @@ package buttondevteam.discordplugin.commands;
import buttondevteam.discordplugin.DiscordPlugin;
import sx.blah.discord.handle.obj.IMessage;
import java.util.Arrays;
import java.util.stream.Collectors;
public class HelpCommand extends DiscordCommandBase {
@ -19,11 +18,11 @@ public class HelpCommand extends DiscordCommandBase {
if (args.length() == 0)
DiscordPlugin.sendMessageToChannel(message.getChannel(),
"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
DiscordPlugin.sendMessageToChannel(message.getChannel(),
(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;
}
@ -32,7 +31,7 @@ public class HelpCommand extends DiscordCommandBase {
return new String[] { //
"---- Help command ----", //
"Shows some info about a command or lists the available commands.", //
"Usage: help [command]"//
"Usage: " + DiscordPlugin.getPrefix() + "help [command]"//
};
}

View file

@ -25,7 +25,7 @@ public class MCChatCommand extends DiscordCommandBase {
MCChatPrivate.privateMCChat(message.getChannel(), mcchat, message.getAuthor(), user);
DiscordPlugin.sendMessageToChannel(message.getChannel(),
"Minecraft chat " + (mcchat //
? "enabled. Use '/mcchat' again to turn it off." //
? "enabled. Use '" + DiscordPlugin.getPrefix() + "mcchat' again to turn it off." //
: "disabled."));
} catch (Exception e) {
TBMCCoreAPI.SendException("Error while setting mcchat for user" + message.getAuthor().getName(), e);
@ -36,8 +36,9 @@ public class MCChatCommand extends DiscordCommandBase {
@Override
public String[] getHelpText() {
return new String[] { //
"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." //
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 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
}

View file

@ -86,7 +86,7 @@ public class RoleCommand extends DiscordCommandBase {
public String[] getHelpText() {
return new String[]{ //
"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", //
};
}

View file

@ -91,7 +91,8 @@ public class UserinfoCommand extends DiscordCommandBase {
"---- User information ----", //
"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.", //
"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" //
};
}

View file

@ -382,8 +382,9 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
} else {// Not a command
if (dmessage.length() == 0 && event.getMessage().getAttachments().size() == 0
&& !event.getChannel().isPrivate() && event.getMessage().isSystemMessage()) {
val rtr = clmd != null ? clmd.mcchannel.filteranderrormsg.apply(clmd.dcp) : dsender.getChromaUser().channel().get().filteranderrormsg.apply(dsender);
TBMCChatAPI.SendSystemMessage(clmd != null ? clmd.mcchannel : dsender.getChromaUser().channel().get(), rtr.score, rtr.groupID,
val rtr = clmd != null ? clmd.mcchannel.getRTR(clmd.dcp)
: dsender.getChromaUser().channel().get().getRTR(dsender);
TBMCChatAPI.SendSystemMessage(clmd != null ? clmd.mcchannel : dsender.getChromaUser().channel().get(), rtr,
(dsender instanceof Player ? ((Player) dsender).getDisplayName()
: dsender.getName()) + " pinned a message on Discord.");
}