fixed NPE when interacting with NPC's

This commit is contained in:
Jules 2021-10-10 17:39:56 +02:00
parent 15cb4d7aa2
commit a9809dbccb
2 changed files with 17 additions and 1 deletions

View File

@ -883,6 +883,22 @@ public class PlayerData extends OfflinePlayerData {
return MMOCore.plugin.dataProvider.getDataManager().get(uuid);
}
/**
* This is used to check if the player data is loaded for a
* specific player. This might seem redundant because the given
* Player instance is linked to an online player, and data
* is always loaded for an online player.
* <p>
* In fact a Player instance can be attached to a Citizens NPC
* which has no player data loaded hence this method
*
* @param player Either a real player or an NPC
* @return If player data for that player is loaded
*/
public static boolean has(Player player) {
return MMOCore.plugin.dataProvider.getDataManager().isLoaded(player.getUniqueId());
}
public static Collection<PlayerData> getAll() {
return MMOCore.plugin.dataProvider.getDataManager().getLoaded();
}

View File

@ -11,7 +11,7 @@ public class MMOCoreTargetRestriction implements TargetRestriction {
@Override
public boolean canTarget(Player player, LivingEntity target, InteractionType interaction) {
if (interaction.isOffense() && target instanceof Player) {
if (interaction.isOffense() && target instanceof Player && PlayerData.has((Player) target)) {
PlayerData targetData = PlayerData.get(target.getUniqueId());
// Check for the same party