This commit is contained in:
Jitse Boonstra 2020-08-08 18:40:54 +02:00
commit 03af1d08aa
2 changed files with 39 additions and 2 deletions

View File

@ -26,7 +26,24 @@ public interface NPC {
Hologram getPlayerHologram(Player player);
/**
* @param uniqueLines The text that the targetPlayer will see
*
* @param targetPlayer The target player
* @return object instance
* @author Gatt
*/
NPC removePlayerLines(Player targetPlayer);
/**
*
* @param targetPlayer The target player
* @param update whether or not to update the hologram
* @return object instance
* @author Gatt
*/
NPC removePlayerLines(Player targetPlayer, boolean update);
/**
*
* @param uniqueLines The text that the targetPlayer will see. Null to remove
* @param targetPlayer The target player
* @return object instance
* @author Gatt
@ -45,6 +62,7 @@ public interface NPC {
/**
* @param targetPlayer The target player
* @return the lines that the targetPlayer will see, if null; default lines.
* @author Gatt
*/
List<String> getPlayerLines(Player targetPlayer);

View File

@ -74,10 +74,26 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
return playerHologram;
}
@Override
public NPC removePlayerLines(Player targetPlayer) {
Validate.notNull(targetPlayer, "Player cannot be null.");
setPlayerLines(null, targetPlayer);
return this;
}
@Override
public NPC removePlayerLines(Player targetPlayer, boolean update) {
Validate.notNull(targetPlayer, "Player cannot be null.");
setPlayerLines(null, targetPlayer, update);
return this;
}
@Override
public NPC setPlayerLines(List<String> uniqueLines, Player targetPlayer) {
Validate.notNull(targetPlayer, "Player cannot be null.");
uniqueText.put(targetPlayer.getUniqueId(), uniqueLines);
if (uniqueLines == null) uniqueText.remove(targetPlayer.getUniqueId());
else uniqueText.put(targetPlayer.getUniqueId(), uniqueLines);
return this;
}
@ -87,6 +103,9 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
List<String> originalLines = getPlayerLines(targetPlayer);
setPlayerLines(uniqueLines, targetPlayer);
if (update) {
uniqueLines = getPlayerLines(targetPlayer); // retrieve the player lines from this function, incase it's been removed.
if (originalLines.size() != uniqueLines.size()) { // recreate the entire hologram
Hologram originalhologram = getPlayerHologram(targetPlayer);
originalhologram.hide(targetPlayer); // essentially destroy the hologram