-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: decentholograms support (fix #2)
- Loading branch information
1 parent
0bc85eb
commit 16d2c7a
Showing
10 changed files
with
160 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...jos/soulgravesplus/events/hologram/decentholograms/SoulExplodeDecentHologramListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
.../jos/soulgravesplus/events/hologram/decentholograms/SoulPickupDecentHologramListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...g/jos/soulgravesplus/events/hologram/decentholograms/SoulSpawnDecentHologramListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters