Fix custom chat PL update NPE (#124)
This commit is contained in:
parent
1fa2635317
commit
ffdf5a2f18
4 changed files with 11 additions and 15 deletions
|
@ -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
|
||||||
|
|
6
pom.xml
6
pom.xml
|
@ -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>
|
||||||
|
|
|
@ -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()) {
|
||||||
|
|
|
@ -49,7 +49,8 @@ public class MCChatUtils {
|
||||||
* May contain P<DiscordID> as key for public chat
|
* May contain P<DiscordID> 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(", "));
|
||||||
|
@ -106,12 +109,12 @@ public class MCChatUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends DiscordSenderBase> T addSender(HashMap<String, HashMap<Snowflake, T>> senders,
|
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);
|
return addSender(senders, user.getId().asString(), sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends DiscordSenderBase> T addSender(HashMap<String, HashMap<Snowflake, T>> senders,
|
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);
|
var map = senders.get(did);
|
||||||
if (map == null)
|
if (map == null)
|
||||||
map = new HashMap<>();
|
map = new HashMap<>();
|
||||||
|
@ -121,7 +124,7 @@ public class MCChatUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends DiscordSenderBase> T getSender(HashMap<String, HashMap<Snowflake, T>> senders,
|
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());
|
var map = senders.get(user.getId().asString());
|
||||||
if (map != null)
|
if (map != null)
|
||||||
return map.get(channel);
|
return map.get(channel);
|
||||||
|
@ -129,7 +132,7 @@ public class MCChatUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends DiscordSenderBase> T removeSender(HashMap<String, HashMap<Snowflake, T>> senders,
|
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());
|
var map = senders.get(user.getId().asString());
|
||||||
if (map != null)
|
if (map != null)
|
||||||
return map.remove(channel);
|
return map.remove(channel);
|
||||||
|
|
Loading…
Reference in a new issue