Update 5.22 & Update HologramAPI

This commit is contained in:
sky 2020-03-16 23:30:13 +08:00
parent 3f91fb5de8
commit 0899a6bad7
3 changed files with 46 additions and 9 deletions

View File

@ -6,7 +6,7 @@ plugins {
} }
group = 'me.skymc' group = 'me.skymc'
version = '5.21' version = '5.22'
sourceCompatibility = 1.8 sourceCompatibility = 1.8
targetCompatibility = 1.8 targetCompatibility = 1.8

View File

@ -7,6 +7,7 @@ import io.izzel.taboolib.module.packet.TPacketHandler;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -36,13 +37,28 @@ public class Hologram {
} }
} }
public Hologram autoDelete() {
this.autoDelete = true;
return this;
}
public Hologram toAll() { public Hologram toAll() {
this.viewAll = true; this.viewAll = true;
return refresh(); return refresh();
} }
public Hologram autoDelete() { public Hologram hideAll() {
this.autoDelete = true; this.viewAll = false;
return removeViewers();
}
public Hologram viewAll(Boolean viewAll) {
if (!this.viewAll && viewAll) {
toAll();
}
if (this.viewAll && !viewAll) {
hideAll();
}
return this; return this;
} }
@ -111,6 +127,13 @@ public class Hologram {
return this; return this;
} }
public Hologram flash(Vector vector, int period, int times) {
for (int i = 0; i < times; i++) {
Bukkit.getScheduler().runTaskLater(TabooLib.getPlugin(), () -> flash(location.add(vector)), period * i);
}
return this;
}
public Hologram flash(Location location) { public Hologram flash(Location location) {
if (deleted) { if (deleted) {
return this; return this;
@ -160,27 +183,39 @@ public class Hologram {
return this; return this;
} }
public void addViewer(Player player) { public Hologram addViewer(Player player) {
if (deleted) { if (deleted) {
return; return this;
} }
if (!isViewer(player)) { if (!isViewer(player)) {
HologramViewer viewer = new HologramViewer(player); HologramViewer viewer = new HologramViewer(player);
viewers.add(viewer); viewers.add(viewer);
refresh(viewer); refresh(viewer);
} }
return this;
} }
public void removeViewer(Player player) { public Hologram removeViewer(Player player) {
if (deleted) { if (deleted) {
return; return this;
} }
HologramViewer viewer = getViewer(player); HologramViewer viewer = getViewer(player);
viewers.remove(viewer); viewers.remove(viewer);
destroy(viewer); destroy(viewer);
if (viewers.isEmpty() && autoDelete) { if (viewers.isEmpty()) {
deleted = true; deleted = autoDelete;
} }
return this;
}
public Hologram removeViewers() {
if (deleted) {
return this;
}
destroy();
viewers.clear();
deleted = autoDelete;
return this;
} }
public boolean isViewer(Player player) { public boolean isViewer(Player player) {

View File

@ -54,6 +54,8 @@ public class THologram {
HologramViewer viewer = hologram.getViewer(player); HologramViewer viewer = hologram.getViewer(player);
if (viewer != null) { if (viewer != null) {
hologram.refresh(viewer); hologram.refresh(viewer);
} else if (hologram.isViewAll()) {
hologram.addViewer(player);
} }
} }
} }