From 4956837e5d6cdc49de0c4897bf57bdfdf023e69e Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Mon, 22 Jul 2019 22:37:23 +0200 Subject: [PATCH] Not processing messages when nobody is online --- .../java/buttondevteam/chat/ChatProcessing.java | 9 ++++++--- src/main/java/buttondevteam/chat/ChatUtils.java | 16 ++++++++++++++++ .../java/buttondevteam/chat/VanillaUtils.java | 14 +++++++++++--- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index 3b4c3de..be67739 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -122,6 +122,12 @@ public class ChatProcessing { doFunStuff(sender, e, message); + final String channelidentifier = getChannelID(channel, e.getOrigin()); + PluginMain.Instance.getServer().getConsoleSender() + .sendMessage(String.format("%s <%s§r> %s", channelidentifier, getSenderName(sender, player), message)); + + if (Bukkit.getOnlinePlayers().size() == 0) return false; //Don't try to send to nobody (errors on 1.14) + ChatPlayer mp; if (player != null) mp = TBMCPlayerBase.getPlayer(player.getUniqueId(), ChatPlayer.class); @@ -144,7 +150,6 @@ public class ChatProcessing { }).build()); } pingedconsole = false; // Will set it to true onmatch (static constructor) - final String channelidentifier = getChannelID(channel, e.getOrigin()); TellrawPart json = createTellraw(sender, message, player, mp, e.getUser(), channelidentifier, e.getOrigin()); long combinetime = System.nanoTime(); @@ -191,8 +196,6 @@ public class ChatProcessing { sender.sendMessage("§cAn error occured while sending the message."); return true; } - PluginMain.Instance.getServer().getConsoleSender() - .sendMessage(String.format("%s <%s§r> %s", channelidentifier, getSenderName(sender, player), message)); DebugCommand.SendDebugMessage( "-- Full ChatProcessing time: " + (System.nanoTime() - processstart) / 1000000f + " ms"); DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime / 1000000f + " ms"); diff --git a/src/main/java/buttondevteam/chat/ChatUtils.java b/src/main/java/buttondevteam/chat/ChatUtils.java index 247c2e2..c090a35 100644 --- a/src/main/java/buttondevteam/chat/ChatUtils.java +++ b/src/main/java/buttondevteam/chat/ChatUtils.java @@ -2,6 +2,8 @@ package buttondevteam.chat; import org.bukkit.Bukkit; +import java.util.Optional; + public final class ChatUtils { private ChatUtils() {} @@ -17,4 +19,18 @@ public final class ChatUtils { else Bukkit.dispatchCommand(PluginMain.Console, command); } + + /** + * Returns the string between the start and end strings (exclusive). + * + * @param str The original string + * @param start The start string + * @param end The end string + * @return The result string + */ + public static Optional coolSubstring(String str, String start, String end) { + int a = str.indexOf(start) + start.length(); + int b = str.indexOf(end, a); + return a != -1 && b != -1 ? Optional.of(str.substring(a, b)) : Optional.empty(); + } } diff --git a/src/main/java/buttondevteam/chat/VanillaUtils.java b/src/main/java/buttondevteam/chat/VanillaUtils.java index 68f749b..5cbd16c 100644 --- a/src/main/java/buttondevteam/chat/VanillaUtils.java +++ b/src/main/java/buttondevteam/chat/VanillaUtils.java @@ -1,11 +1,10 @@ package buttondevteam.chat; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - import buttondevteam.lib.TBMCChatEvent; import lombok.experimental.UtilityClass; import net.minecraft.server.v1_12_R1.EntityHuman.EnumChatVisibility; +import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; @UtilityClass public class VanillaUtils { @@ -15,4 +14,13 @@ public class VanillaUtils { else return -1; } + + /*private String version; + + public short getMCVersion() { + if (version != null) return version; + val v = ChatUtils.coolSubstring(Bukkit.getServer().getVersion().getClass().getPackage().getName(), + "org.bukkit.craftbukkit.v", "_R1").orElse("1_8").replace("_", ""); + return Short.parseShort(v); + }*/ }