Fix custom chat PL update NPE (#124)

This commit is contained in:
Norbi Peti 2020-02-17 13:02:15 +01:00
parent 1fa2635317
commit ffdf5a2f18
4 changed files with 11 additions and 15 deletions

View file

@ -1,4 +1,4 @@
# DiscordPlugin
# Chroma-Discord
A plugin that provides Minecraft chat functionality and other features.
## Setup

View file

@ -170,12 +170,6 @@
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc.</groupId>
<artifactId>spigot</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.discord4j/Discord4J -->
<dependency>
<groupId>com.discord4j</groupId>

View file

@ -109,7 +109,7 @@ public class DiscordPlugin extends ButtonPlugin {
getLogger().info("Initializing...");
plugin = this;
manager = new Command2DC();
getCommand2MC().registerCommand(new DiscordMCCommand()); //Register so that the reset command works
registerCommand(new DiscordMCCommand()); //Register so that the reset command works
String token;
File tokenFile = new File("TBMC", "Token.txt");
if (tokenFile.exists()) //Legacy support
@ -214,7 +214,6 @@ public class DiscordPlugin extends ButtonPlugin {
TBMCCoreAPI.RegisterUserClass(DiscordPlayer.class);
ChromaGamerBase.addConverter(sender -> Optional.ofNullable(sender instanceof DiscordSenderBase
? ((DiscordSenderBase) sender).getChromaUser() : null));
setupProviders();
IHaveConfig.pregenConfig(this, null);
if (!TBMCCoreAPI.IsTestServer()) {

View file

@ -49,7 +49,8 @@ public class MCChatUtils {
* May contain P&lt;DiscordID&gt; as key for public chat
*/
public static final HashMap<String, HashMap<Snowflake, DiscordPlayerSender>> OnlineSenders = new HashMap<>();
static @Nullable LastMsgData lastmsgdata;
static @Nullable
LastMsgData lastmsgdata;
static LongObjectHashMap<Message> lastmsgfromd = new LongObjectHashMap<>(); // Last message sent by a Discord user, used for clearing checkmarks
private static MinecraftChatModule module;
private static HashMap<Class<? extends Event>, HashSet<String>> staticExcludedPlugins = new HashMap<>();
@ -91,7 +92,9 @@ public class MCChatUtils {
gid = buttondevteam.core.component.channel.Channel.GROUP_EVERYONE; // (Though it's a public chat then rn)
AtomicInteger C = new AtomicInteger();
s[s.length - 1] = "Players: " + Bukkit.getOnlinePlayers().stream()
.filter(p -> gid.equals(lmd.mcchannel.getGroupID(p))) //If they can see it
.filter(p -> (lmd.mcchannel == null
? gid.equals(buttondevteam.core.component.channel.Channel.GROUP_EVERYONE) //If null, allow if public (custom chats will have their channel stored anyway)
: gid.equals(lmd.mcchannel.getGroupID(p)))) //If they can see it
.filter(MCChatUtils::checkEssentials)
.filter(p -> C.incrementAndGet() > 0) //Always true
.map(p -> DPUtils.sanitizeString(p.getDisplayName())).collect(Collectors.joining(", "));
@ -106,12 +109,12 @@ public class MCChatUtils {
}
public static <T extends DiscordSenderBase> T addSender(HashMap<String, HashMap<Snowflake, T>> senders,
User user, T sender) {
User user, T sender) {
return addSender(senders, user.getId().asString(), sender);
}
public static <T extends DiscordSenderBase> T addSender(HashMap<String, HashMap<Snowflake, T>> senders,
String did, T sender) {
String did, T sender) {
var map = senders.get(did);
if (map == null)
map = new HashMap<>();
@ -121,7 +124,7 @@ public class MCChatUtils {
}
public static <T extends DiscordSenderBase> T getSender(HashMap<String, HashMap<Snowflake, T>> senders,
Snowflake channel, User user) {
Snowflake channel, User user) {
var map = senders.get(user.getId().asString());
if (map != null)
return map.get(channel);
@ -129,7 +132,7 @@ public class MCChatUtils {
}
public static <T extends DiscordSenderBase> T removeSender(HashMap<String, HashMap<Snowflake, T>> senders,
Snowflake channel, User user) {
Snowflake channel, User user) {
var map = senders.get(user.getId().asString());
if (map != null)
return map.remove(channel);