mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-11 21:06:55 +00:00
prevent null players being forwarded to events and message sending logic edge case
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.youhavetrouble.preventstabby</groupId>
|
||||
<artifactId>PreventStabby</artifactId>
|
||||
<version>2.1.2</version>
|
||||
<version>2.1.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>PreventStabby</name>
|
||||
|
||||
@@ -46,15 +46,16 @@ public class PlayerManager {
|
||||
for (PlayerData playerData : playerList.values()) {
|
||||
if (playerData == null) continue;
|
||||
Player player = Bukkit.getPlayer(playerData.getPlayerUuid());
|
||||
if (player == null || !player.isOnline()) {
|
||||
// player not online, so check for related entities
|
||||
playerData.getRelatedEntities().removeIf( uuid -> {
|
||||
Entity entity = Bukkit.getEntity(uuid);
|
||||
return entity == null;
|
||||
});
|
||||
if (player == null || !player.isOnline()) {
|
||||
// player not online, so check for related entities
|
||||
if (playerData.getRelatedEntities().isEmpty()) continue;
|
||||
}
|
||||
playerData.refreshCacheTime(); // Refresh cache timer if player is online
|
||||
playerData.refreshCacheTime();
|
||||
if (player == null || !player.isOnline()) continue; // If player is offline, skip the rest of the logic
|
||||
// leaving combat logic
|
||||
if (playerData.getLastCombatCheckState() && !playerData.isInCombat()) {
|
||||
PlayerLeaveCombatEvent leaveCombatEvent = null;
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -33,12 +34,12 @@ public class PluginMessages {
|
||||
return PreventStabby.getPlugin().getServer().getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||
}
|
||||
|
||||
public static void sendMessage(CommandSender sender, String message) {
|
||||
public static void sendMessage(@NotNull CommandSender sender, String message) {
|
||||
if ("".equals(message)) return;
|
||||
sender.sendMessage(parseMessage(sender, message));
|
||||
}
|
||||
|
||||
public static void sendActionBar(Player player, String message) {
|
||||
public static void sendActionBar(@NotNull Player player, String message) {
|
||||
if ("".equals(message)) return;
|
||||
Component parsedMessage = parseMessage(player, message);
|
||||
player.sendActionBar(parsedMessage);
|
||||
|
||||
Reference in New Issue
Block a user