Fix for channel topic update
parent
72703055d0
commit
baf3b44d31
|
@ -18,14 +18,16 @@ import chikachi.discord.core.DiscordClient;
|
|||
import chikachi.discord.core.DiscordIntegrationLogger;
|
||||
import chikachi.discord.core.TextFormatter;
|
||||
import chikachi.discord.core.config.Configuration;
|
||||
import chikachi.discord.core.config.discord.DiscordChannelConfig;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.lang.Thread.sleep;
|
||||
|
||||
public class DiscordThread implements Runnable {
|
||||
private HashMap<Long, Integer> channelDescriptionIndexMap;
|
||||
private HashMap<Long, Integer> channelDescriptionIndexMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -49,26 +51,29 @@ public class DiscordThread implements Runnable {
|
|||
|
||||
TextFormatter tf = new TextFormatter()
|
||||
.addArgument("PLAYERCOUNT", MinecraftInformationHandler.getOnlineRealPlayerCount())
|
||||
.addArgument("UNIQUEPLAYERCOUNT", MinecraftInformationHandler.getUniquePlayerCount())
|
||||
.addArgument("MAXPLAYERCOUNT", MinecraftInformationHandler.getMaxPlayerCount())
|
||||
.addArgument("TPS", MinecraftInformationHandler.getAverageTickCount())
|
||||
.addArgument("TICKCOUNT", MinecraftInformationHandler.getAverageTPS());
|
||||
|
||||
Configuration.getConfig().discord.channels.channels.
|
||||
entrySet().stream()
|
||||
.filter(channel -> channel.getValue().updateDescription)
|
||||
.filter(channel -> channel.getValue().descriptions.size() > 0)
|
||||
.forEach(channel -> {
|
||||
ArrayList<String> descriptions = channel.getValue().descriptions;
|
||||
HashMap<Long, DiscordChannelConfig> channels = Configuration.getConfig().discord.channels.channels;
|
||||
for (Map.Entry<Long, DiscordChannelConfig> channelEntry : channels.entrySet()) {
|
||||
DiscordChannelConfig channel = channelEntry.getValue();
|
||||
Long channelID = channelEntry.getKey();
|
||||
|
||||
int newMessageIndex = channelDescriptionIndexMap.getOrDefault(channel.getKey(), -1) + 1;
|
||||
if (channel != null && channel.updateDescription && channel.descriptions.size() > 0) {
|
||||
ArrayList<String> descriptions = channel.descriptions;
|
||||
|
||||
int newMessageIndex = channelDescriptionIndexMap.getOrDefault(channelID, -1) + 1;
|
||||
if (newMessageIndex >= descriptions.size())
|
||||
newMessageIndex = 0;
|
||||
channelDescriptionIndexMap.put(channel.getKey(), newMessageIndex);
|
||||
channelDescriptionIndexMap.put(channelID, newMessageIndex);
|
||||
|
||||
String actualMessage = tf.format(descriptions.get(newMessageIndex));
|
||||
|
||||
DiscordClient.getInstance().updateChannelDescription(channel.getKey(), actualMessage);
|
||||
});
|
||||
DiscordClient.getInstance().updateChannelDescription(channelID, actualMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePlayerCountInPresence() {
|
||||
|
|
|
@ -30,6 +30,9 @@ public abstract class MinecraftInformationHandler {
|
|||
public static int getMaxPlayerCount() {
|
||||
return FMLCommonHandler.instance().getMinecraftServerInstance().getMaxPlayers();
|
||||
}
|
||||
public static int getUniquePlayerCount() {
|
||||
return FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerProfileCache().getUsernames().length;
|
||||
}
|
||||
|
||||
public static double getAverageTickCount() {
|
||||
MinecraftServer minecraftServer = FMLCommonHandler.instance().getMinecraftServerInstance();
|
||||
|
|
Loading…
Reference in New Issue