Fixes a potential NPE when calling getPlayerHologram at the wrong time
This commit is contained in:
parent
6037711d30
commit
8a308a00f9
|
@ -16,6 +16,7 @@ import net.jitse.npclib.api.state.NPCSlot;
|
|||
import net.jitse.npclib.api.state.NPCState;
|
||||
import net.jitse.npclib.hologram.Hologram;
|
||||
import net.jitse.npclib.utilities.MathUtil;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
@ -67,18 +68,21 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
|
|||
|
||||
@Override
|
||||
public Hologram getPlayerHologram(Player player){
|
||||
Validate.notNull(player, "Player cannot be null.");
|
||||
Hologram playerHologram = textDisplayHolograms.getOrDefault(player.getUniqueId(), null);
|
||||
return playerHologram;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC setPlayerLines(List<String> uniqueLines, Player targetPlayer) {
|
||||
Validate.notNull(targetPlayer, "Player cannot be null.");
|
||||
uniqueText.put(targetPlayer.getUniqueId(), uniqueLines);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC setPlayerLines(List<String> uniqueLines, Player targetPlayer, boolean update) {
|
||||
Validate.notNull(targetPlayer, "Player cannot be null.");
|
||||
List<String> originalLines = getPlayerLines(targetPlayer);
|
||||
setPlayerLines(uniqueLines, targetPlayer);
|
||||
if (update){
|
||||
|
@ -99,6 +103,7 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
|
|||
|
||||
@Override
|
||||
public List<String> getPlayerLines(Player targetPlayer) {
|
||||
Validate.notNull(targetPlayer, "Player cannot be null.");
|
||||
return uniqueText.getOrDefault(targetPlayer.getUniqueId(), text);
|
||||
}
|
||||
|
||||
|
@ -133,8 +138,10 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
|
|||
continue;
|
||||
}
|
||||
Player plyr = Bukkit.getPlayer(uuid); // destroy the per player holograms
|
||||
getPlayerHologram(plyr).hide(plyr);
|
||||
hide(plyr, true);
|
||||
if (plyr != null) {
|
||||
getPlayerHologram(plyr).hide(plyr);
|
||||
hide(plyr, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue