Skip to content

Commit

Permalink
feat: decentholograms support (fix #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
JosTheDude committed Feb 18, 2025
1 parent 0bc85eb commit 16d2c7a
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 24 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = 'gg.jos'
version = '1.2'
version = '1.3'



Expand All @@ -28,6 +28,7 @@ dependencies {
compileOnly "io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT"
implementation "com.github.FaultyFunctions:SoulGraves:v1.3.0"
compileOnly "de.oliver:FancyHolograms:2.4.2"
compileOnly 'com.github.decentsoftware-eu:decentholograms:2.8.14'
}

def targetJavaVersion = 21
Expand Down
30 changes: 23 additions & 7 deletions src/main/java/gg/jos/soulgravesplus/SoulGravesPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import de.oliver.fancyholograms.api.FancyHologramsPlugin;
import de.oliver.fancyholograms.api.HologramManager;
import gg.jos.soulgravesplus.commands.ReloadCommand;
import gg.jos.soulgravesplus.events.hologram.SoulExplodeHologramListener;
import gg.jos.soulgravesplus.events.hologram.SoulPickupHologramListener;
import gg.jos.soulgravesplus.events.hologram.SoulSpawnHologramListener;
import gg.jos.soulgravesplus.events.hologram.decentholograms.SoulExplodeDecentHologramListener;
import gg.jos.soulgravesplus.events.hologram.decentholograms.SoulPickupDecentHologramListener;
import gg.jos.soulgravesplus.events.hologram.decentholograms.SoulSpawnDecentHologramListener;
import gg.jos.soulgravesplus.events.hologram.fancyholograms.SoulExplodeFancyHologramListener;
import gg.jos.soulgravesplus.events.hologram.fancyholograms.SoulPickupFancyHologramListener;
import gg.jos.soulgravesplus.events.hologram.fancyholograms.SoulSpawnFancyHologramListener;
import gg.jos.soulgravesplus.events.logger.SoulExplodeLoggerListener;
import gg.jos.soulgravesplus.events.logger.SoulPickupLoggerListener;
import gg.jos.soulgravesplus.events.logger.SoulSpawnLoggerListener;
Expand Down Expand Up @@ -33,6 +36,7 @@ public final class SoulGravesPlus extends JavaPlugin {
public boolean hologramBackground;
public String[] hologramBackgroundColor;
public List<String> hologramLines;
public String hologramManager; // Unused but exists for future needs

@Override
public void onEnable() {
Expand Down Expand Up @@ -112,15 +116,27 @@ private void loggerFeatures(SoulGravesPlus plugin) {

private void hologramFeatures(SoulGravesPlus plugin) {
if (plugin.getServer().getPluginManager().getPlugin("FancyHolograms") != null) {

plugin.hologramManager = "FancyHolograms";

HologramManager manager = FancyHologramsPlugin.get().getHologramManager();

plugin.getServer().getPluginManager().registerEvents(new SoulSpawnHologramListener(this, manager, this), this);
plugin.getServer().getPluginManager().registerEvents(new SoulPickupHologramListener(this, manager), this);
plugin.getServer().getPluginManager().registerEvents(new SoulExplodeHologramListener(this, manager), this);
plugin.getServer().getPluginManager().registerEvents(new SoulSpawnFancyHologramListener(this, manager, this), this);
plugin.getServer().getPluginManager().registerEvents(new SoulPickupFancyHologramListener(this, manager), this);
plugin.getServer().getPluginManager().registerEvents(new SoulExplodeFancyHologramListener(this, manager), this);

plugin.getLogger().info("FancyHolograms found! Hologram features enabled.");
} else if (plugin.getServer().getPluginManager().getPlugin("DecentHolograms") != null) {

plugin.hologramManager = "DecentHolograms";

plugin.getServer().getPluginManager().registerEvents(new SoulSpawnDecentHologramListener(this, this), this);
plugin.getServer().getPluginManager().registerEvents(new SoulPickupDecentHologramListener(this), this);
plugin.getServer().getPluginManager().registerEvents(new SoulExplodeDecentHologramListener(this), this);

plugin.getLogger().info("DecentHolograms found! Hologram features enabled.");
} else {
plugin.getLogger().warning("FancyHolograms not found! Hologram features disabled.");
plugin.getLogger().warning("FancyHolograms or DecentHolograms not found! Hologram features disabled.");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package gg.jos.soulgravesplus.events.hologram.decentholograms;

import de.oliver.fancyholograms.api.HologramManager;
import de.oliver.fancyholograms.api.hologram.Hologram;
import dev.faultyfunctions.soulgraves.api.event.SoulExplodeEvent;
import eu.decentsoftware.holograms.api.DHAPI;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;

public class SoulExplodeDecentHologramListener implements Listener {
private final Plugin plugin;

public SoulExplodeDecentHologramListener(Plugin plugin) {
this.plugin = plugin;
}

@EventHandler
public void onSoulExplode(SoulExplodeEvent event) {

String hologramName = "grave_hologram_" + event.getSoul().getMarkerUUID();

DHAPI.removeHologram(hologramName);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package gg.jos.soulgravesplus.events.hologram.decentholograms;

import de.oliver.fancyholograms.api.HologramManager;
import de.oliver.fancyholograms.api.hologram.Hologram;
import dev.faultyfunctions.soulgraves.api.event.SoulPickupEvent;
import eu.decentsoftware.holograms.api.DHAPI;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;

public class SoulPickupDecentHologramListener implements Listener {
private final Plugin plugin;

public SoulPickupDecentHologramListener(Plugin plugin) {
this.plugin = plugin;
}

@EventHandler
public void onSoulPickup(SoulPickupEvent event) {

String hologramName = "grave_hologram_" + event.getSoul().getMarkerUUID();

DHAPI.removeHologram(hologramName);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package gg.jos.soulgravesplus.events.hologram.decentholograms;

import de.oliver.fancyholograms.api.HologramManager;
import de.oliver.fancyholograms.api.data.TextHologramData;
import de.oliver.fancyholograms.api.hologram.Hologram;
import dev.faultyfunctions.soulgraves.api.event.SoulSpawnEvent;
import eu.decentsoftware.holograms.api.DHAPI;
import gg.jos.soulgravesplus.SoulGravesPlus;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

public class SoulSpawnDecentHologramListener implements Listener {
private final Plugin plugin;
private final SoulGravesPlus soulGravesPlus;

public SoulSpawnDecentHologramListener(Plugin plugin, SoulGravesPlus soulGravesPlus) {
this.plugin = plugin;
this.soulGravesPlus = soulGravesPlus;
}

@EventHandler
public void onSoulSpawn(SoulSpawnEvent event) {

if (!soulGravesPlus.hologramEnabled) {
return;
}

// Get the grave location and adjust it to be above the grave
Location soulLocation = event.getSoulLocation();
Location location = soulLocation.clone().add(soulGravesPlus.hologramXOffset, soulGravesPlus.hologramYOffset, soulGravesPlus.hologramZOffset);

// Fetch the hologram config
if (soulGravesPlus.hologramLines.isEmpty()) {
plugin.getLogger().warning("Hologram lines are missing in the config!");
return;
}

// Define placeholders
String soulOwner = event.getPlayer().getName();
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedTime = now.format(formatter);
String soulTime = String.valueOf(event.getSoul().getTimeLeft());

// Replace placeholders in the config lines
List<String> parsedLines = soulGravesPlus.hologramLines.stream()
.map(line -> line
.replace("{soulOwner}", soulOwner)
.replace("{formattedTime}", formattedTime)
.replace("{soulTime}", soulTime)
.replace("&", "§"))
.toList();

// Create a unique hologram name
String hologramName = "grave_hologram_" + event.getSoul().getMarkerUUID();

DHAPI.createHologram(hologramName, location, parsedLines);

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gg.jos.soulgravesplus.events.hologram;
package gg.jos.soulgravesplus.events.hologram.fancyholograms;

import de.oliver.fancyholograms.api.HologramManager;
import de.oliver.fancyholograms.api.hologram.Hologram;
Expand All @@ -7,11 +7,11 @@
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;

public class SoulExplodeHologramListener implements Listener {
public class SoulExplodeFancyHologramListener implements Listener {
private final Plugin plugin;
private final HologramManager manager;

public SoulExplodeHologramListener(Plugin plugin, HologramManager manager) {
public SoulExplodeFancyHologramListener(Plugin plugin, HologramManager manager) {
this.plugin = plugin;
this.manager = manager;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gg.jos.soulgravesplus.events.hologram;
package gg.jos.soulgravesplus.events.hologram.fancyholograms;

import de.oliver.fancyholograms.api.HologramManager;
import de.oliver.fancyholograms.api.hologram.Hologram;
Expand All @@ -7,11 +7,11 @@
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;

public class SoulPickupHologramListener implements Listener {
public class SoulPickupFancyHologramListener implements Listener {
private final Plugin plugin;
private final HologramManager manager;

public SoulPickupHologramListener(Plugin plugin, HologramManager manager) {
public SoulPickupFancyHologramListener(Plugin plugin, HologramManager manager) {
this.plugin = plugin;
this.manager = manager;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gg.jos.soulgravesplus.events.hologram;
package gg.jos.soulgravesplus.events.hologram.fancyholograms;

import de.oliver.fancyholograms.api.HologramManager;
import de.oliver.fancyholograms.api.data.TextHologramData;
Expand All @@ -15,12 +15,12 @@
import java.time.format.DateTimeFormatter;
import java.util.List;

public class SoulSpawnHologramListener implements Listener {
public class SoulSpawnFancyHologramListener implements Listener {
private final Plugin plugin;
private final HologramManager manager;
private final SoulGravesPlus soulGravesPlus;

public SoulSpawnHologramListener(Plugin plugin, HologramManager manager, SoulGravesPlus soulGravesPlus) {
public SoulSpawnFancyHologramListener(Plugin plugin, HologramManager manager, SoulGravesPlus soulGravesPlus) {
this.plugin = plugin;
this.manager = manager;
this.soulGravesPlus = soulGravesPlus;
Expand Down
11 changes: 6 additions & 5 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ hologram:

# Hologram settings
# Holograms are displayed above the soul's grave
# This features requires FancyHolograms
# This features requires FancyHolograms or DecentHolograms

# Enable/Disable this feature entirely
enabled: true

# Configure the location of the hologram relative to the soul's location
x-offset: 0.0 # x-offset from the soul's location
y-offset: 2.5 # y-offset from the soul's location
y-offset: 3.5 # y-offset from the soul's location
z-offset: 0.0 # z-offset from the soul's location

# Configure the background of the hologram, defaults to the default hologram background
# This has no effect if you are using DecentHolograms
custom-background: false # enable custom background
background-color: "1,100,255,79" # ARGB format

Expand All @@ -50,8 +51,8 @@ hologram:
# DEPRECATED: {soulTime} for configured time for soul expiry (non-updating)
lines:
- ""
- "<aqua>☠ <b>SOUL GRAVE</b> <dark_gray>» <white>{soulOwner}"
- "<gray>Passed away at {formattedTime}"
- "&b☠ &lSOUL GRAVE&r &8» &f{soulOwner}"
- "&7Passed away at &f{formattedTime}"
- ""
- "<aqua> [ᴛᴏᴜᴄʜ ᴛʜᴇ ɢʀᴀᴠᴇ ᴛᴏ ʀᴇᴛʀɪᴇᴠᴇ ᴇꜱꜱᴇɴᴄᴇ] "
- "&b [ᴛᴏᴜᴄʜ ᴛʜᴇ ɢʀᴀᴠᴇ ᴛᴏ ʀᴇᴛʀɪᴇᴠᴇ ᴇꜱꜱᴇɴᴄᴇ] &r"
- ""
3 changes: 1 addition & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ name: SoulGravesPlus
version: '${version}'
main: gg.jos.soulgravesplus.SoulGravesPlus
api-version: '1.21'
loadAfter: [SoulGraves, FancyHolograms]
softDepend: [SoulGraves, FancyHolograms]
softdepend: [SoulGraves, FancyHolograms, DecentHolograms]
authors: [JosTheDude]
website: https://jos.gg/

Expand Down

0 comments on commit 16d2c7a

Please sign in to comment.