Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Source Code: https://github.com/TownyAdvanced/FlagWar/blob/main/LICENSE

FlagWar originally developed under the title "CellWar", then later incorporated into Towny, by Chris Holland.
(https://github.com/Zren/CellWar | https://github.com/Zren/Towny)
Towny has developed and maintained by TownyAdvanced since 2011. (https://github.com/TownyAdvanced/Towny)
Towny has been developed and maintained by TownyAdvanced since 2011. (https://github.com/TownyAdvanced/Towny)

Any prior code found on the com.palmergames.* classpath remains under previous copyrights, and
Towny's Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Expand All @@ -38,36 +38,42 @@ Towny is licensed under the Creative Commons Attribution-NonCommercial-NoDerivs
Full License: https://github.com/TownyAdvanced/Towny/blob/master/LICENSE.MD
Source Code: https://github.com/TownyAdvanced/Towny/
Copyright © 2011-2012 Chris Holland
Copyright © 2012-2022 TownyAdvanced
Copyright © 2012-2026 TownyAdvanced

/ DecentHolograms (Soft Dependency) /
/ DecentHolograms (API, Soft Dependency) /
DecentHolograms is licensed under the GNU General Public License Version 3, or any later version.
Full License: https://github.com/DecentSoftware-eu/DecentHolograms/blob/main/LICENSE
Source Code: https://github.com/DecentSoftware-eu/DecentHolograms/
Copyright © 2021-2024 DecentSoftware and Contributors (https://github.com/DecentSoftware-eu/DecentHolograms/graphs/contributors)
Copyright © 2021-2026 DecentSoftware and Contributors (https://github.com/DecentSoftware-eu/DecentHolograms/graphs/contributors)

/ CMILib & CMI-API (API, Soft Dependency) /
Provided publicly for optional interoperability with CMI.
Source Code - CMILib: https://github.com/Zrips/CMILib
Source Code - CMI-API: https://github.com/Zrips/CMI-API
Copyright © 2017-2026 Zrips, All Rights Reserved


// Annotations //
/ JetBrains Java Annotations (compile-only) /
JetBrains annotations are provided under version 2 of the Apache License. (Apache-2)
Full License: https://github.com/JetBrains/java-annotations/blob/master/LICENSE.txt
Source Code: https://github.com/JetBrains/java-annotations
Copyright © 2000-2022 JetBrains s.r.o.
Copyright © 2000-2026 JetBrains s.r.o.

/ SpotBugs Annotations (compile-only) /
Annotations for SpotBugs (or FindBugs) are licensed under the GNU Lesser General Public License,
version 2.1 or later. (LGPL-2.1 [or later]).
Full License: https://github.com/spotbugs/spotbugs/blob/master/LICENSE
Source Code: https://github.com/spotbugs/spotbugs/tree/master/spotbugs-annotations
Copyright © 2005, University of Maryland (as part of FindBugs)
Copyright © 2005, University of Maryland

// Metrics //
/ bStats /
bStats metrics are provided as a service to the plugin community.
As of version 3.0.0, it is provided under the permissive MIT license.
If you don't want bStats to collect data from your server, you can disable it in the bStats config file.
This file can be found in the /plugins/bStats/ folder on the running server.
This file can be found in the './plugins/bStats/' folder on servers using this plugin.
Privacy Policy: https://bstats.org/privacy-policy
Full License: https://github.com/Bastian/bStats-Metrics/blob/master/LICENSE
Source Code: https://github.com/Bastian/bStats-Metrics
Copyright © 2016-2022 Bastian Oppermann (AKA BtoBastian)
Copyright © 2016-2026 Bastian Oppermann (AKA BtoBastian)
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@
<version>2.9.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.Zrips</groupId>
<artifactId>CMILib</artifactId>
<version>1.5.8.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.Zrips</groupId>
<artifactId>CMI-API</artifactId>
<version>9.7.14.3</version>
<scope>provided</scope>
</dependency>
</dependencies>

<pluginRepositories>
Expand Down
104 changes: 95 additions & 9 deletions src/main/java/io/github/townyadvanced/flagwar/util/HologramUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@

package io.github.townyadvanced.flagwar.util;

import com.Zrips.CMI.CMI;
import com.Zrips.CMI.Modules.Display.CMIBillboard;
import com.Zrips.CMI.Modules.Holograms.CMIHologram;
import eu.decentsoftware.holograms.api.DHAPI;
import eu.decentsoftware.holograms.api.holograms.Hologram;
import io.github.townyadvanced.flagwar.FlagWar;
import io.github.townyadvanced.flagwar.config.FlagWarConfig;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.plugin.Plugin;
Expand Down Expand Up @@ -52,9 +56,17 @@ public static void drawHologram(final String name,
.getPlugin("DecentHolograms");
if (decentHolograms != null && decentHolograms.isEnabled()) {
drawDecentHolograms(name, location, settings, lifeTime);
} else {
Messaging.debug("Tried to draw a hologram (%s), but no supported hologram plugins loaded.", name);
return;
}

// CMI - Common paid alternative to EssentialsX. Use as last resort, add other alternatives above this point.
Plugin cmi = FlagWar.getInstance().getServer().getPluginManager().getPlugin("cmi");
if (cmi != null && cmi.isEnabled()) {
drawCMIHolograms(name, location, settings, lifeTime);
return;
}

Messaging.debug("Tried to draw a hologram (%s), but no supported hologram plugins loaded.", name);
}

/**
Expand Down Expand Up @@ -99,31 +111,93 @@ private static void drawDecentHolograms(final String name,
}
}

//Teleport
// Teleport to new offset
final double hOffset = 0.5d;
final double vOffset = 0.9d;
final double textHeight = 0.23d;
hologram.setLocation(location.add(hOffset, vOffset + (hologram.getPage(0).size() * textHeight), hOffset));

//Set Visible
// Set Visible
hologram.setDefaultVisibleState(true);
}

/**
* Draw hologram with CMI.
* @param name Hologram Name
* @param location Hologram Location
* @param settings Settings
* @param lifetime (Remaining) life span of hologram
*/
private static void drawCMIHolograms(final String name,
final Location location,
final List<Map.Entry<String, String>> settings,
final Duration lifetime) {
CMIHologram hologram = new CMIHologram(name, location);
hologram.setNewDisplayMethod(true);
hologram.setBillboard(CMIBillboard.CENTER);

// Self-Destruct - backup to #destroyHologram()
double[] tps = Bukkit.getTPS(); // Will use 5-minute average of running server.
int bufferTicks = (int) Math.round(tps[0]) * 2; // add 2s, in case the average is slower than current tick rate.
hologram.setSelfDestructIn((Math.toIntExact(lifetime.toSeconds()) * (int) Math.round(tps[0])) + bufferTicks);

// Add Lines
for (Map.Entry<String, String> holoSetting : settings) {
String type = holoSetting.getKey();
String data = holoSetting.getValue();

switch (type) {
case "item" -> {
Material material = Material.matchMaterial(data);
if (material != null) {
// Need working confirmation that this actually adds an icon.
hologram.setLine(0, "ICON:" + material.name());
}
}
case "text" -> hologram.setLine(1, data);
case "timer" -> hologram.setLine(2, FormatUtil.time(lifetime, data));
default -> hologram.addLine("");
}
}

// Offset
final double hOffset = 0.5d;
final double vOffset = 0.9d;
final double textHeight = 0.23d;
hologram.moveTo(location.add(hOffset, vOffset + (hologram.getPage(0).getHeight() * textHeight), hOffset));

// Register / Draw
CMI.getInstance().getHologramManager().addHologram(hologram);
hologram.update();
}

/**
* Destroys a given hologram by name.
* @param name Hologram name (Cell String)
*/
public static void destroyHologram(final String name) {
// DecentHolograms
Plugin decentHolograms = FlagWar.getInstance().getServer().getPluginManager()
.getPlugin("DecentHolograms");
if (decentHolograms != null && decentHolograms.isEnabled()) {
Hologram hologram = DHAPI.getHologram(name);
if (hologram != null) {
hologram.destroy();
}
} else {
Messaging.debug("Tried to destroy a hologram (%s), but no supported plugins are in use.", name);
return;
}

// CMI
Plugin cmi = FlagWar.getInstance().getServer().getPluginManager().getPlugin("cmi");
if (cmi != null && cmi.isEnabled()) {
CMIHologram hologram = CMI.getInstance().getHologramManager().getByName(name);
if (hologram != null) {
hologram.remove();
}
return;
}

Messaging.debug("Tried to destroy a hologram (%s), but no supported plugins are in use.", name);
}

/**
Expand All @@ -132,16 +206,28 @@ public static void destroyHologram(final String name) {
* @param lifeTime Flag duration
*/
public static void updateHologramTimer(final String name, final Duration lifeTime) {
// DecentHolograms
Plugin decentHolograms = FlagWar.getInstance().getServer().getPluginManager()
.getPlugin("DecentHolograms");
if (decentHolograms != null && decentHolograms.isEnabled()) {
Hologram hologram = DHAPI.getHologram(name);

if (hologram != null) {
DHAPI.setHologramLine(hologram, 2, FormatUtil.time(lifeTime, FlagWarConfig.getTimerText()));
}
} else {
Messaging.debug("Tried to update a hologram's timer (%s), but no supported plugins are in use.", name);
return;
}

// CMI
Plugin cmi = FlagWar.getInstance().getServer().getPluginManager().getPlugin("cmi");
if (cmi != null && cmi.isEnabled()) {
CMIHologram hologram = CMI.getInstance().getHologramManager().getByName(name);
if (hologram != null) {
hologram.setLine(2, FormatUtil.time(lifeTime, FlagWarConfig.getTimerText()));
hologram.refresh();
}
return;
}

Messaging.debug("Tried to update a hologram's timer (%s), but no supported plugins are in use.", name);
}
}
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ folia-supported: true

softdepend:
- DecentHolograms
- CMI

depend:
- Towny
Loading