removing per player lines

This commit is contained in:
Gatt 2020-08-04 14:40:26 +10:00
parent 627ffb5617
commit d5e9ebddbe
2 changed files with 38 additions and 2 deletions

View File

@ -28,7 +28,23 @@ public interface NPC {
/** /**
* *
* @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 * @param targetPlayer The target player
* @return object instance * @return object instance
* @author Gatt * @author Gatt
@ -49,6 +65,7 @@ public interface NPC {
* *
* @param targetPlayer The target player * @param targetPlayer The target player
* @return the lines that the targetPlayer will see, if null; default lines. * @return the lines that the targetPlayer will see, if null; default lines.
* @author Gatt
*/ */
List<String> getPlayerLines(Player targetPlayer); List<String> getPlayerLines(Player targetPlayer);

View File

@ -73,10 +73,26 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
return playerHologram; 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 @Override
public NPC setPlayerLines(List<String> uniqueLines, Player targetPlayer) { public NPC setPlayerLines(List<String> uniqueLines, Player targetPlayer) {
Validate.notNull(targetPlayer, "Player cannot be null."); 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; return this;
} }
@ -86,6 +102,9 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
List<String> originalLines = getPlayerLines(targetPlayer); List<String> originalLines = getPlayerLines(targetPlayer);
setPlayerLines(uniqueLines, targetPlayer); setPlayerLines(uniqueLines, targetPlayer);
if (update) { 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 if (originalLines.size() != uniqueLines.size()) { // recreate the entire hologram
Hologram originalhologram = getPlayerHologram(targetPlayer); Hologram originalhologram = getPlayerHologram(targetPlayer);
originalhologram.hide(targetPlayer); // essentially destroy the hologram originalhologram.hide(targetPlayer); // essentially destroy the hologram