Text update function working on v1.8 R1!
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package net.jitse.npclib.hologram;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -56,31 +55,4 @@ public abstract class HologramBase implements Hologram, HologramPacketHandler {
|
||||
|
||||
this.shown.remove(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateText(List<String> text) {
|
||||
if (this.text.size() != text.size())
|
||||
throw new IllegalArgumentException("When updating the text, the old and new text should have the same amount of lines");
|
||||
|
||||
for (int i = 0; i < text.size(); i++) {
|
||||
String oldLine = this.text.get(i);
|
||||
String newLine = text.get(i);
|
||||
|
||||
if (oldLine.equals(newLine))
|
||||
continue; // No need to update.
|
||||
|
||||
// Perhaps this should return an object so we can send all immediately to the shown players.
|
||||
createTextUpdatePacket(oldLine, newLine);
|
||||
}
|
||||
|
||||
for (UUID uuid : shown) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null || !player.isOnline()) {
|
||||
throw new IllegalStateException("Tried to update hologram for offline player");
|
||||
}
|
||||
|
||||
// sendTextUpdatePackets(player, );
|
||||
}
|
||||
this.text = text;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,4 @@ public interface HologramPacketHandler {
|
||||
void sendShowPackets(Player player);
|
||||
|
||||
void sendHidePackets(Player player);
|
||||
|
||||
void createTextUpdatePacket(String oldLine, String newLine);
|
||||
|
||||
void sendTextUpdatePackets(Player player);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.jitse.npclib.api.events.NPCShowEvent;
|
||||
import net.jitse.npclib.api.skin.Skin;
|
||||
import net.jitse.npclib.api.state.NPCSlot;
|
||||
import net.jitse.npclib.api.state.NPCState;
|
||||
import net.jitse.npclib.hologram.Hologram;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@@ -39,6 +40,7 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
|
||||
protected List<String> text;
|
||||
protected Location location;
|
||||
protected Skin skin;
|
||||
protected Hologram hologram;
|
||||
|
||||
// offHand support in 1.9 R1 and later.
|
||||
protected ItemStack helmet, chestplate, leggings, boots, inHand, offHand;
|
||||
@@ -304,7 +306,7 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
|
||||
for (UUID shownUuid : shown) {
|
||||
Player player = Bukkit.getPlayer(shownUuid);
|
||||
if (player != null && isShown(player)) {
|
||||
sendTextUpdatePackets(this.text, text, player);
|
||||
hologram.updateText(text);
|
||||
}
|
||||
}
|
||||
this.text = text;
|
||||
|
||||
Reference in New Issue
Block a user