Skip to content

Commit

Permalink
Fixed internal hologram and added support for FancyHolograms
Browse files Browse the repository at this point in the history
  • Loading branch information
AerWyn81 committed Aug 1, 2024
1 parent e3586c3 commit 3985716
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 30 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id("java")
}

version = "2.5.4"
version = "2.5.5"

allprojects {
repositories {
Expand All @@ -13,5 +13,6 @@ allprojects {
maven("https://repo.codemc.org/repository/maven-public")
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
maven("https://jitpack.io")
maven("https://repo.fancyplugins.de/releases")
}
}
5 changes: 3 additions & 2 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ dependencies {
compileOnly("me.filoghost.holographicdisplays:holographicdisplays-api:3.0.4")
compileOnly(files("../libs/CMILib1.4.7.16.jar"))
compileOnly(files("../libs/CMI-9.7.3.2.jar"))
implementation(files("../libs/holoeasy-core-3.4.1.jar"))
compileOnly("de.oliver:FancyHolograms:2.3.0")
implementation(files("../libs/holoeasy-core-3.4.4.jar"))
//implementation("com.github.unldenis.holoeasy:holoeasy-core:3.4.0")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.21")
implementation("redis.clients:jedis:5.1.3")
Expand Down Expand Up @@ -56,7 +57,7 @@ bukkit {
authors = listOf("AerWyn81")
apiVersion = "1.13"
description = "Challenge your players to find all the heads and earn rewards"
softDepend = listOf("PlaceholderAPI", "HeadDatabase", "ProtocolLib", "DecentHolograms", "CMI")
softDepend = listOf("PlaceholderAPI", "HeadDatabase", "ProtocolLib", "DecentHolograms", "CMI", "FancyHolograms")
version = rootProject.version.toString()
website = "https://just2craft.fr"

Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/fr/aerwyn81/headblocks/HeadBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public final class HeadBlocks extends JavaPlugin {
public static boolean isProtocolLibActive;
public static boolean isDecentHologramsActive;
public static boolean isHolographicDisplaysActive;
public static boolean isFancyHologramsActive;
public static boolean isCMIActive;
public static boolean isHeadDatabaseActive;

Expand Down Expand Up @@ -80,6 +81,7 @@ public void onEnable() {
isDecentHologramsActive = Bukkit.getPluginManager().isPluginEnabled("DecentHolograms");
isHolographicDisplaysActive = Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays");
isCMIActive = Bukkit.getPluginManager().isPluginEnabled("CMI");
isFancyHologramsActive = Bukkit.getPluginManager().isPluginEnabled("FancyHolograms");

ConfigService.initialize(configFile);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ public enum EnumTypeHologram {
DEFAULT("DEFAULT"),
DECENT("DecentHolograms"),
HD("HD"),
CMI("CMI");
CMI("CMI"),
FH("FancyHolograms");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package fr.aerwyn81.headblocks.holograms;

import fr.aerwyn81.headblocks.holograms.types.CMIHologram;
import fr.aerwyn81.headblocks.holograms.types.DecentHologram;
import fr.aerwyn81.headblocks.holograms.types.DefaultHologram;
import fr.aerwyn81.headblocks.holograms.types.HolographicDisplaysHologram;
import fr.aerwyn81.headblocks.holograms.types.*;
import org.bukkit.Location;
import org.bukkit.entity.Player;

Expand All @@ -29,6 +26,9 @@ public InternalHologram(EnumTypeHologram enumTypeHologram) {
case DEFAULT:
hologram = new DefaultHologram();
break;
case FH:
hologram = new FHHologram();
break;
default:
hologram = null; //todo
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ public EnumTypeHologram getTypeHologram() {
public boolean isVisible(Player player) {
return false; // Not used
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void delete() {

@Override
public IHologram create(String name, Location location, List<String> lines, int displayRange) {
HoloLibSingleton.getHologramPool().registerHolograms(() -> hologram = hologram(location.subtract(0, 1.3, 0),
HoloLibSingleton.getHologramPool().registerHolograms(() -> hologram = hologram(location.subtract(0, 2.3, 0),
() -> lines.forEach(HologramBuilder::textline)));

for (Player pl : Collections.synchronizedCollection(Bukkit.getOnlinePlayers())) {
Expand All @@ -53,4 +53,5 @@ public EnumTypeHologram getTypeHologram() {
public boolean isVisible(Player player) {
return hologram.isShownFor(player);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package fr.aerwyn81.headblocks.holograms.types;

import de.oliver.fancyholograms.api.FancyHologramsPlugin;
import de.oliver.fancyholograms.api.HologramManager;
import de.oliver.fancyholograms.api.data.TextHologramData;
import de.oliver.fancyholograms.api.data.property.visibility.Visibility;
import de.oliver.fancyholograms.api.hologram.Hologram;
import fr.aerwyn81.headblocks.HeadBlocks;
import fr.aerwyn81.headblocks.holograms.EnumTypeHologram;
import fr.aerwyn81.headblocks.holograms.IHologram;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Display;
import org.bukkit.entity.Player;

import java.util.List;
import java.util.UUID;

public class FHHologram implements IHologram {
Hologram hologram;
final HologramManager manager;

public FHHologram() {
manager = FancyHologramsPlugin.get().getHologramManager();
}

@Override
public void show(Player player) {
Bukkit.getScheduler().runTaskAsynchronously(HeadBlocks.getInstance(), () -> {
hologram.forceShowHologram(player);
hologram.forceUpdateShownStateFor(player);
});
}

@Override
public void hide(Player player) {
Bukkit.getScheduler().runTaskAsynchronously(HeadBlocks.getInstance(), () -> {
hologram.hideHologram(player);
hologram.forceHideHologram(player);
});
}

@Override
public void delete() {
Bukkit.getScheduler().runTaskAsynchronously(HeadBlocks.getInstance(),
() -> {
for (var uuid : hologram.getViewers()) {
var p = Bukkit.getPlayer(uuid);
if (p != null) {
hologram.forceHideHologram(p);
}
}
hologram.deleteHologram();
});
}

@Override
public IHologram create(String name, Location location, List<String> lines, int displayRange) {
var hologramData = new TextHologramData(UUID.randomUUID().toString(), location);

hologramData.setBillboard(Display.Billboard.CENTER);

hologramData.setText(lines)
.setBackground(Hologram.TRANSPARENT)
.setSeeThrough(false)
.setTextShadow(false)
.setVisibilityDistance(displayRange)
.setVisibility(Visibility.ALL)
.setPersistent(false);

hologram = manager.create(hologramData);
return this;
}

@Override
public EnumTypeHologram getTypeHologram() {
return EnumTypeHologram.FH;
}

@Override
public boolean isVisible(Player player) {
return hologram.isViewer(player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ public EnumTypeHologram getTypeHologram() {
public boolean isVisible(Player player) {
return hologram.getVisibilitySettings().isVisibleTo(player);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import fr.aerwyn81.headblocks.utils.bukkit.LocationUtils;
import fr.aerwyn81.headblocks.utils.internal.InternalUtils;
import fr.aerwyn81.headblocks.utils.message.MessageUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

public class HologramService {
Expand All @@ -22,6 +22,8 @@ public class HologramService {
private static boolean enable;
private static EnumTypeHologram enumTypeHologram;

private static BukkitTask hideHoloTooFarTask;

static {
enable = true;
}
Expand All @@ -30,6 +32,12 @@ public static void load() {
foundHolograms = new HashMap<>();
notFoundHolograms = new HashMap<>();

if (hideHoloTooFarTask != null) {
hideHoloTooFarTask.cancel();
Bukkit.getScheduler().cancelTask(hideHoloTooFarTask.getTaskId());
hideHoloTooFarTask = null;
}

enable = ConfigService.isHologramsEnabled();
if (!enable) {
return;
Expand All @@ -47,16 +55,47 @@ public static void load() {
if ((enumTypeHologram == EnumTypeHologram.DECENT && !HeadBlocks.isDecentHologramsActive) ||
(enumTypeHologram == EnumTypeHologram.DEFAULT && !HeadBlocks.isProtocolLibActive) ||
(enumTypeHologram == EnumTypeHologram.HD && !HeadBlocks.isHolographicDisplaysActive) ||
(enumTypeHologram == EnumTypeHologram.FH && !HeadBlocks.isFancyHologramsActive) ||
(enumTypeHologram == EnumTypeHologram.CMI && !HeadBlocks.isCMIActive)) {
enable = false;
return;
}

for (HeadLocation loc : HeadService.getHeadLocations()) {
if (loc.isCharged()) {
createHolograms(loc.getLocation());
}
}

if (enumTypeHologram == EnumTypeHologram.FH) {
hideHoloTooFarTask = startTimerHideHoloTooFar();
}
}

private static BukkitTask startTimerHideHoloTooFar() {
return Bukkit.getScheduler().runTaskTimerAsynchronously(HeadBlocks.getInstance(), () -> {
var players = Collections.synchronizedCollection(Bukkit.getOnlinePlayers());

foundHolograms.values().forEach(h -> players.stream()
.filter(h::isHologramVisible)
.filter(p -> !isWithinVisibilityDistance(p, h.getLocation()))
.forEach(h::hide));

notFoundHolograms.values().forEach(h -> players.stream()
.filter(h::isHologramVisible)
.filter(p -> !isWithinVisibilityDistance(p, h.getLocation()))
.forEach(h::hide));
}, 0, 20L);
}

public static boolean isWithinVisibilityDistance(Player player, Location holoLoc) {
if (!player.getWorld().equals(holoLoc.getWorld())) {
return false;
}

int visibilityDistance = ConfigService.getHologramParticlePlayerViewDistance();
double distanceSquared = holoLoc.distanceSquared(player.getLocation());

return distanceSquared <= visibilityDistance * visibilityDistance;
}

public static void createHolograms(Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,36 @@
import fr.aerwyn81.headblocks.utils.message.MessageUtils;
import org.bukkit.Bukkit;

import java.util.Arrays;

public enum VersionUtils {
v1_16_R1(1161),
v1_16_R2(1162),
v1_16_R3(1163),
v1_17_R1(1171),
v1_18_R1(1181),
v1_18_R2(1182),
v1_19_R1(1191),
v1_19_R2(1192),
v1_19_R3(1193),
v1_20_R1(1201),
v1_20_R1(120, 1201),
v1_20_R2(1202),
v1_20_R3(1203),
v1_20_R4(1204),
v1_20_R5(1205),
v1_20_R6(1206),
v1_21_R1(1211);
v1_21_R1(121, 1211);

private static VersionUtils version;
private final int versionId;
private final int[] versionId;

VersionUtils(int id) {
private final int currentVersionId;
VersionUtils(int... id) {
this.versionId = id;
this.currentVersionId = id[0];
}

public int getVersionId() {
return versionId;
return currentVersionId;
}

public static VersionUtils getVersion() {
if (version != null) {
return version;
}
try {
version = extractFromString(Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]);
version = extractFromString(Bukkit.getBukkitVersion().split("\\.")[3]);
} catch (Exception e) {
try {
version = extractFromString(Bukkit.getServer().getBukkitVersion().split("-")[0].replaceAll("\\.", ""));
Expand All @@ -53,7 +48,7 @@ public static VersionUtils getVersion() {

private static VersionUtils extractFromString(String ver) throws IllegalArgumentException {
for (VersionUtils version : VersionUtils.values())
if (ver.equals(String.valueOf(version.versionId)))
if (Arrays.stream(version.versionId).anyMatch(v -> ver.equals(String.valueOf(v))))
return version;

throw new RuntimeException("Unknown version " + ver + ". Please report to developer. HeadBlocks will use latest.");
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ headClick:
# DECENT : DecentHolograms
# HD : HolographicDisplays
# CMI : CMI
# FH : FancyHolograms
# DEFAULT : Internal need ProtocolLib
holograms:
plugin: DEFAULT
Expand Down

0 comments on commit 3985716

Please sign in to comment.