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. A plugin that provides Minecraft chat functionality and other features.
## Setup ## Setup

View file

@ -170,12 +170,6 @@
<version>1.12.2-R0.1-SNAPSHOT</version> <version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </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 --> <!-- https://mvnrepository.com/artifact/com.discord4j/Discord4J -->
<dependency> <dependency>
<groupId>com.discord4j</groupId> <groupId>com.discord4j</groupId>

View file

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

View file

@ -49,7 +49,8 @@ public class MCChatUtils {
* May contain P&lt;DiscordID&gt; as key for public chat * May contain P&lt;DiscordID&gt; as key for public chat
*/ */
public static final HashMap<String, HashMap<Snowflake, DiscordPlayerSender>> OnlineSenders = new HashMap<>(); 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 static LongObjectHashMap<Message> lastmsgfromd = new LongObjectHashMap<>(); // Last message sent by a Discord user, used for clearing checkmarks
private static MinecraftChatModule module; private static MinecraftChatModule module;
private static HashMap<Class<? extends Event>, HashSet<String>> staticExcludedPlugins = new HashMap<>(); 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) gid = buttondevteam.core.component.channel.Channel.GROUP_EVERYONE; // (Though it's a public chat then rn)
AtomicInteger C = new AtomicInteger(); AtomicInteger C = new AtomicInteger();
s[s.length - 1] = "Players: " + Bukkit.getOnlinePlayers().stream() 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(MCChatUtils::checkEssentials)
.filter(p -> C.incrementAndGet() > 0) //Always true .filter(p -> C.incrementAndGet() > 0) //Always true
.map(p -> DPUtils.sanitizeString(p.getDisplayName())).collect(Collectors.joining(", ")); .map(p -> DPUtils.sanitizeString(p.getDisplayName())).collect(Collectors.joining(", "));