mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-10-22 12:20:26 +02:00
add support for Holograms plugin
This commit is contained in:
parent
708f55768b
commit
c565de42e9
5
pom.xml
5
pom.xml
@ -44,6 +44,11 @@
|
||||
<artifactId>holographicdisplays-api</artifactId>
|
||||
<version>2.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sainttx.holograms</groupId>
|
||||
<artifactId>holograms</artifactId>
|
||||
<version>2.9.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.tnemc</groupId>
|
||||
<artifactId>Reserve</artifactId>
|
||||
|
@ -122,6 +122,11 @@ public class HologramManager {
|
||||
defaultHolo.removeHologram(location);
|
||||
}
|
||||
|
||||
public static void removeAllHolograms() {
|
||||
if (defaultHolo != null)
|
||||
defaultHolo.removeAllHolograms();
|
||||
}
|
||||
|
||||
public static void updateHologram(Location location, String line) {
|
||||
if (defaultHolo != null)
|
||||
defaultHolo.updateHologram(location, line);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.core.library.hologram;
|
||||
|
||||
import com.songoda.core.library.hologram.holograms.Holograms;
|
||||
import com.songoda.core.library.hologram.holograms.HologramsHolograms;
|
||||
import com.songoda.core.library.hologram.holograms.HolographicDisplaysHolograms;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -10,7 +11,9 @@ import java.util.logging.Level;
|
||||
|
||||
public enum HologramType {
|
||||
|
||||
HOLOGRAPHIC_DISPLAYS("HolographicDisplays", HolographicDisplaysHolograms.class);
|
||||
HOLOGRAPHIC_DISPLAYS("HolographicDisplays", HolographicDisplaysHolograms.class),
|
||||
HOLOGRAMS("Holograms", HologramsHolograms.class)
|
||||
;
|
||||
|
||||
public final String plugin;
|
||||
protected final Class managerClass;
|
||||
|
@ -9,7 +9,7 @@ import java.util.List;
|
||||
public abstract class Holograms {
|
||||
|
||||
protected double xOffset = 0.5;
|
||||
protected double yOffset = 1.5;
|
||||
protected double yOffset = 0.5;
|
||||
protected double zOffset = 0.5;
|
||||
|
||||
protected final JavaPlugin plugin;
|
||||
@ -35,9 +35,11 @@ public abstract class Holograms {
|
||||
double x = location.getX();
|
||||
double y = location.getY();
|
||||
double z = location.getZ();
|
||||
return location.clone().add((x - (int) x) + xOffset, (y - (int) y) + yOffset, (z - (int) z) + zOffset);
|
||||
return location.clone().add((x - (int) x) + xOffset, (y - (int) y) + yOffset + defaultHeightOffset(), (z - (int) z) + zOffset);
|
||||
}
|
||||
|
||||
protected abstract double defaultHeightOffset();
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public void createHologram(Location location, String line) {
|
||||
@ -54,4 +56,5 @@ public abstract class Holograms {
|
||||
|
||||
public abstract void updateHologram(Location location, List<String> lines);
|
||||
|
||||
public abstract void removeAllHolograms();
|
||||
}
|
||||
|
@ -0,0 +1,97 @@
|
||||
package com.songoda.core.library.hologram.holograms;
|
||||
|
||||
import com.sainttx.holograms.api.Hologram;
|
||||
import com.sainttx.holograms.api.HologramPlugin;
|
||||
import com.sainttx.holograms.api.line.HologramLine;
|
||||
import com.sainttx.holograms.api.line.TextLine;
|
||||
import java.util.HashSet;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class HologramsHolograms extends Holograms {
|
||||
|
||||
HologramPlugin hologramPlugin;
|
||||
HashSet<String> ourHolograms = new HashSet();
|
||||
|
||||
public HologramsHolograms(JavaPlugin plugin) {
|
||||
super(plugin);
|
||||
hologramPlugin = (HologramPlugin) Bukkit.getPluginManager().getPlugin("Holograms");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Holograms";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double defaultHeightOffset() {
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createHologram(Location location, List<String> lines) {
|
||||
createAt(fixLocation(location), lines);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHologram(Location location) {
|
||||
location = fixLocation(location);
|
||||
final String id = locStr(location);
|
||||
Hologram hologram = hologramPlugin.getHologramManager().getHologram(id);
|
||||
if (hologram != null) {
|
||||
hologram.despawn();
|
||||
hologramPlugin.getHologramManager().removeActiveHologram(hologram);
|
||||
}
|
||||
ourHolograms.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllHolograms() {
|
||||
for(String id : ourHolograms) {
|
||||
Hologram hologram = hologramPlugin.getHologramManager().getHologram(id);
|
||||
if (hologram != null) {
|
||||
hologram.despawn();
|
||||
hologramPlugin.getHologramManager().removeActiveHologram(hologram);
|
||||
}
|
||||
}
|
||||
ourHolograms.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateHologram(Location location, List<String> lines) {
|
||||
location = fixLocation(location);
|
||||
Hologram hologram = hologramPlugin.getHologramManager().getHologram(locStr(location));
|
||||
if (hologram != null) {
|
||||
for(HologramLine line : hologram.getLines().toArray(new HologramLine[0])) {
|
||||
hologram.removeLine(line);
|
||||
}
|
||||
for (String line : lines) {
|
||||
hologram.addLine(new TextLine(hologram, line));
|
||||
}
|
||||
return;
|
||||
}
|
||||
createAt(location, lines);
|
||||
}
|
||||
|
||||
private String locStr(Location loc) {
|
||||
return String.format("%s-%d-%d-%d", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
}
|
||||
|
||||
private void createAt(Location location, List<String> lines) {
|
||||
|
||||
final String id = locStr(location);
|
||||
Hologram hologram = new Hologram(id, location);
|
||||
for (String line : lines) {
|
||||
hologram.addLine(new TextLine(hologram, line));
|
||||
}
|
||||
|
||||
hologramPlugin.getHologramManager().addActiveHologram(hologram);
|
||||
|
||||
if(!ourHolograms.contains(id))
|
||||
ourHolograms.add(id);
|
||||
}
|
||||
|
||||
}
|
@ -18,6 +18,11 @@ public class HolographicDisplaysHolograms extends Holograms {
|
||||
return "HolographicDisplays";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double defaultHeightOffset() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createHologram(Location location, List<String> lines) {
|
||||
createAt(fixLocation(location), lines);
|
||||
@ -57,4 +62,9 @@ public class HolographicDisplaysHolograms extends Holograms {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllHolograms() {
|
||||
HologramsAPI.getHolograms(plugin).stream().forEach(x -> x.delete());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user