Not processing messages when nobody is online

This commit is contained in:
Norbi Peti 2019-07-22 22:37:23 +02:00
parent 8907d5308f
commit 4956837e5d
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
3 changed files with 33 additions and 6 deletions

View file

@ -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");

View file

@ -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<String> 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();
}
}

View file

@ -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);
}*/
}