diff --git a/libs/DecentHolograms-2.8.6.jar b/libs/DecentHolograms-2.8.6.jar new file mode 100644 index 0000000..0298f74 Binary files /dev/null and b/libs/DecentHolograms-2.8.6.jar differ diff --git a/pom.xml b/pom.xml index 82ca1bf..fdb94a1 100644 --- a/pom.xml +++ b/pom.xml @@ -191,5 +191,12 @@ zSchedulers 1.0.5 + + com.github.decentsoftware-eu + decentholograms + 2.8.6 + ${basedir}/libs/DecentHolograms-2.8.6.jar + system + \ No newline at end of file diff --git a/src/fr/maxlego08/koth/KothPlugin.java b/src/fr/maxlego08/koth/KothPlugin.java index 17396cb..3ed2a1d 100644 --- a/src/fr/maxlego08/koth/KothPlugin.java +++ b/src/fr/maxlego08/koth/KothPlugin.java @@ -1,7 +1,9 @@ package fr.maxlego08.koth; +import fr.maxlego08.koth.api.KothHologram; import fr.maxlego08.koth.api.KothScoreboard; import fr.maxlego08.koth.command.commands.CommandKoth; +import fr.maxlego08.koth.hologram.DecentHologram; import fr.maxlego08.koth.hook.ScoreboardPlugin; import fr.maxlego08.koth.hook.scoreboard.DefaultHook; import fr.maxlego08.koth.placeholder.LocalPlaceholder; @@ -26,6 +28,7 @@ public class KothPlugin extends ZPlugin { private KothManager kothManager; private StorageManager storageManager; private KothScoreboard kothScoreboard = new DefaultHook(); + private KothHologram kothHologram; @Override public void onEnable() { @@ -65,6 +68,11 @@ public class KothPlugin extends ZPlugin { implementation.register(); } + if (this.isEnable(Plugins.DH)) { + Logger.info("Register DecentHologram implementation", Logger.LogType.INFO); + this.kothHologram = new DecentHologram(); + } + this.postEnable(); } @@ -73,6 +81,8 @@ public class KothPlugin extends ZPlugin { this.preDisable(); + this.kothHologram.onDisable(); + this.scoreBoardManager.setRunning(false); this.saveFiles(); this.postDisable(); @@ -93,4 +103,8 @@ public class KothPlugin extends ZPlugin { public ScoreBoardManager getScoreBoardManager() { return scoreBoardManager; } + + public KothHologram getKothHologram() { + return kothHologram; + } } diff --git a/src/fr/maxlego08/koth/ZKoth.java b/src/fr/maxlego08/koth/ZKoth.java index 708217d..efb656c 100644 --- a/src/fr/maxlego08/koth/ZKoth.java +++ b/src/fr/maxlego08/koth/ZKoth.java @@ -11,6 +11,7 @@ import fr.maxlego08.koth.api.events.KothSpawnEvent; import fr.maxlego08.koth.api.events.KothStartEvent; import fr.maxlego08.koth.api.events.KothStopEvent; import fr.maxlego08.koth.api.events.KothWinEvent; +import fr.maxlego08.koth.api.utils.HologramConfig; import fr.maxlego08.koth.api.utils.ScoreboardConfiguration; import fr.maxlego08.koth.hook.teams.NoneHook; import fr.maxlego08.koth.save.Config; @@ -54,6 +55,7 @@ public class ZKoth extends ZUtils implements Koth { private final boolean enableStartCapMessage; private final boolean enableLooseCapMessage; private final boolean enableEverySecondsCapMessage; + private final HologramConfig hologramConfig; private String name; private int captureSeconds; private Location minLocation; @@ -67,7 +69,7 @@ public class ZKoth extends ZUtils implements Koth { private TimerTask timerTask; private TimerTask timerTaskStop; - public ZKoth(KothPlugin plugin, String fileName, KothType kothType, String name, int captureSeconds, Location minLocation, Location maxLocation, List startCommands, List endCommands, ScoreboardConfiguration cooldownScoreboard, ScoreboardConfiguration startScoreboard, int cooldownStart, int stopAfterSeconds, boolean enableStartCapMessage, boolean enableLooseCapMessage, boolean enableEverySecondsCapMessage) { + public ZKoth(KothPlugin plugin, String fileName, KothType kothType, String name, int captureSeconds, Location minLocation, Location maxLocation, List startCommands, List endCommands, ScoreboardConfiguration cooldownScoreboard, ScoreboardConfiguration startScoreboard, int cooldownStart, int stopAfterSeconds, boolean enableStartCapMessage, boolean enableLooseCapMessage, boolean enableEverySecondsCapMessage, HologramConfig hologramConfig) { this.plugin = plugin; this.fileName = fileName; this.kothType = kothType; @@ -84,6 +86,7 @@ public class ZKoth extends ZUtils implements Koth { this.enableStartCapMessage = enableStartCapMessage; this.enableLooseCapMessage = enableLooseCapMessage; this.enableEverySecondsCapMessage = enableEverySecondsCapMessage; + this.hologramConfig = hologramConfig; } public ZKoth(KothPlugin plugin, String fileName, KothType kothType, String name, int captureSeconds, Location minLocation, Location maxLocation) { @@ -101,6 +104,7 @@ public class ZKoth extends ZUtils implements Koth { this.enableStartCapMessage = true; this.enableLooseCapMessage = true; this.enableEverySecondsCapMessage = false; + this.hologramConfig = new HologramConfig(false, new ArrayList<>(), getCenter()); } @Override @@ -250,7 +254,7 @@ public class ZKoth extends ZUtils implements Koth { // this.resetBlocks(); if (this.timerTaskStop != null) this.timerTaskStop.cancel(); - // this.plugin.getHologram().end(this); + this.plugin.getKothHologram().end(this); } @Override @@ -357,13 +361,13 @@ public class ZKoth extends ZUtils implements Koth { this.timerTaskStop = new TimerTask() { @Override public void run() { - // plugin.getHologram().end(koth); + // plugin.getKothHologram().end(koth); Bukkit.getScheduler().runTask(plugin, () -> stop(Bukkit.getConsoleSender())); } }; timer.schedule(this.timerTaskStop, this.stopAfterSeconds * 1000L); - // this.plugin.getHologram().start(this); + this.plugin.getKothHologram().start(this); /*if (Config.discordWebhookConfig != null) { Config.discordWebhookConfig.send(this.plugin, this); @@ -389,7 +393,7 @@ public class ZKoth extends ZUtils implements Koth { this.currentPlayer = player; this.startCap(player); - // this.plugin.getHologram().update(this); + this.plugin.getKothHologram().update(this); } else if (this.currentPlayer != null && !cuboid.contains(this.currentPlayer.getLocation())) { @@ -398,7 +402,7 @@ public class ZKoth extends ZUtils implements Koth { if (event.isCancelled()) return; - // this.plugin.getHologram().update(this); + this.plugin.getKothHologram().update(this); broadcast(Message.EVENT_LOOSE); if (this.timerTask != null) { @@ -439,7 +443,7 @@ public class ZKoth extends ZUtils implements Koth { Cuboid cuboid = getCuboid(); // this.changeBlocks(Config.onePersonneCapturingMaterial, false); - // this.plugin.getHologram().update(this); + this.plugin.getKothHologram().update(this); scheduleFix(this.plugin, 0, 1000, (task, isCancelled) -> { @@ -460,7 +464,7 @@ public class ZKoth extends ZUtils implements Koth { if (this.currentPlayer != null) { if (!this.currentPlayer.isValid() || !this.currentPlayer.isOnline() || !cuboid.contains(this.currentPlayer.getLocation())) { this.currentPlayer = null; - // this.plugin.getHologram().update(this); + this.plugin.getKothHologram().update(this); } } @@ -486,7 +490,7 @@ public class ZKoth extends ZUtils implements Koth { broadcast(Message.EVENT_LOOSE); } - // this.plugin.getHologram().update(this); + this.plugin.getKothHologram().update(this); return; } @@ -517,7 +521,7 @@ public class ZKoth extends ZUtils implements Koth { break; } - // this.plugin.getHologram().update(this); + this.plugin.getKothHologram().update(this); } }); } @@ -529,7 +533,7 @@ public class ZKoth extends ZUtils implements Koth { if (kothWinEvent.isCancelled()) return; - // this.plugin.getHologram().end(this); + this.plugin.getKothHologram().end(this); task.cancel(); broadcast(Message.EVENT_WIN); @@ -661,7 +665,8 @@ public class ZKoth extends ZUtils implements Koth { } } - private String replaceMessage(String string) { + @Override + public String replaceMessage(String string) { string = string.replace("%playerName%", this.currentPlayer != null ? this.currentPlayer.getName() : Config.noPlayer); string = string.replace("%teamName%", this.currentPlayer != null ? this.currentPlayer.getName() : Config.noPlayer); @@ -702,4 +707,9 @@ public class ZKoth extends ZUtils implements Koth { return scoreboard.getLines().stream().map(e -> color(papi(replaceMessage(e), player))).collect(Collectors.toList()); }; } + + @Override + public HologramConfig getHologramConfig() { + return this.hologramConfig; + } } diff --git a/src/fr/maxlego08/koth/api/Koth.java b/src/fr/maxlego08/koth/api/Koth.java index 596482d..ce53cab 100644 --- a/src/fr/maxlego08/koth/api/Koth.java +++ b/src/fr/maxlego08/koth/api/Koth.java @@ -1,6 +1,7 @@ package fr.maxlego08.koth.api; import fr.maxlego08.koth.KothPlugin; +import fr.maxlego08.koth.api.utils.HologramConfig; import fr.maxlego08.koth.api.utils.ScoreboardConfiguration; import fr.maxlego08.koth.zcore.utils.Cuboid; import fr.maxlego08.koth.zcore.utils.interfaces.CollectionConsumer; @@ -65,4 +66,8 @@ public interface Koth { boolean isEnableEverySecondsCapMessage(); CollectionConsumer onScoreboard(); + + HologramConfig getHologramConfig(); + + String replaceMessage(String string); } diff --git a/src/fr/maxlego08/koth/api/KothHologram.java b/src/fr/maxlego08/koth/api/KothHologram.java new file mode 100644 index 0000000..a5bde5f --- /dev/null +++ b/src/fr/maxlego08/koth/api/KothHologram.java @@ -0,0 +1,13 @@ +package fr.maxlego08.koth.api; + +public interface KothHologram { + + void start(Koth koth); + + void end(Koth koth); + + void update(Koth koth); + + void onDisable(); + +} diff --git a/src/fr/maxlego08/koth/api/utils/HologramConfig.java b/src/fr/maxlego08/koth/api/utils/HologramConfig.java new file mode 100644 index 0000000..9cb217d --- /dev/null +++ b/src/fr/maxlego08/koth/api/utils/HologramConfig.java @@ -0,0 +1,40 @@ +package fr.maxlego08.koth.api.utils; + +import org.bukkit.Location; + +import java.util.List; + +public class HologramConfig { + + private final boolean isEnable; + private final List lines; + private final Location location; + + public HologramConfig(boolean isEnable, List lines, Location location) { + this.isEnable = isEnable; + this.lines = lines; + this.location = location; + } + + /** + * @return the location + */ + public Location getLocation() { + return location; + } + + /** + * @return the isEnable + */ + public boolean isEnable() { + return isEnable; + } + + /** + * @return the linge + */ + public List getLines() { + return lines; + } + +} diff --git a/src/fr/maxlego08/koth/hologram/DecentHologram.java b/src/fr/maxlego08/koth/hologram/DecentHologram.java new file mode 100644 index 0000000..57d64e5 --- /dev/null +++ b/src/fr/maxlego08/koth/hologram/DecentHologram.java @@ -0,0 +1,66 @@ +package fr.maxlego08.koth.hologram; + +import eu.decentsoftware.holograms.api.DHAPI; +import eu.decentsoftware.holograms.api.holograms.Hologram; +import fr.maxlego08.koth.api.Koth; +import fr.maxlego08.koth.api.KothHologram; +import fr.maxlego08.koth.api.utils.HologramConfig; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class DecentHologram implements KothHologram { + + private final Map holograms = new HashMap(); + + @Override + public void start(Koth koth) { + + HologramConfig config = koth.getHologramConfig(); + if (!config.isEnable()) return; + + Hologram hologram = DHAPI.createHologram("ZKOTH-" + koth.getFileName(), config.getLocation()); + this.holograms.put(koth, hologram); + updateLine(koth, hologram); + } + + @Override + public void end(Koth koth) { + + HologramConfig config = koth.getHologramConfig(); + if (!config.isEnable()) return; + + if (this.holograms.containsKey(koth)) { + Hologram hologram = this.holograms.get(koth); + hologram.destroy(); + } + this.holograms.remove(koth); + } + + @Override + public void update(Koth koth) { + + HologramConfig config = koth.getHologramConfig(); + if (!config.isEnable() || !this.holograms.containsKey(koth)) return; + + Hologram hologram = this.holograms.get(koth); + updateLine(koth, hologram); + } + + private void updateLine(Koth koth, Hologram hologram) { + HologramConfig config = koth.getHologramConfig(); + if (!config.isEnable()) return; + + List lines = config.getLines(); + DHAPI.setHologramLines(hologram, lines.stream().map(koth::replaceMessage).collect(Collectors.toList())); + } + + @Override + public void onDisable() { + this.holograms.values().forEach(Hologram::destroy); + this.holograms.clear(); + } + +} diff --git a/src/fr/maxlego08/koth/hologram/EmptyHologram.java b/src/fr/maxlego08/koth/hologram/EmptyHologram.java new file mode 100644 index 0000000..3067c28 --- /dev/null +++ b/src/fr/maxlego08/koth/hologram/EmptyHologram.java @@ -0,0 +1,32 @@ +package fr.maxlego08.koth.hologram; + +import fr.maxlego08.koth.api.Koth; +import fr.maxlego08.koth.api.KothHologram; + +public class EmptyHologram implements KothHologram { + + @Override + public void start(Koth koth) { + // TODO Auto-generated method stub + + } + + @Override + public void end(Koth koth) { + // TODO Auto-generated method stub + + } + + @Override + public void update(Koth koth) { + // TODO Auto-generated method stub + + } + + @Override + public void onDisable() { + // TODO Auto-generated method stub + + } + +} diff --git a/src/fr/maxlego08/koth/loader/HologramLoader.java b/src/fr/maxlego08/koth/loader/HologramLoader.java new file mode 100644 index 0000000..8a973a4 --- /dev/null +++ b/src/fr/maxlego08/koth/loader/HologramLoader.java @@ -0,0 +1,40 @@ +package fr.maxlego08.koth.loader; + +import fr.maxlego08.koth.api.utils.HologramConfig; +import fr.maxlego08.koth.zcore.utils.loader.Loader; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.util.List; + +public class HologramLoader implements Loader { + + @Override + public HologramConfig load(YamlConfiguration configuration, String path, File file) { + + String worldName = configuration.getString(path + "world", "world"); + int x = configuration.getInt(path + "x"); + int y = configuration.getInt(path + "y"); + int z = configuration.getInt(path + "z"); + boolean isEnable = configuration.getBoolean(path + "enable"); + List lines = configuration.getStringList(path + "lines"); + + Location location = new Location(Bukkit.getWorld(worldName), x, y, z); + return new HologramConfig(isEnable, lines, location); + } + + @Override + public void save(HologramConfig hologramConfig, YamlConfiguration configuration, String path) { + + Location location = hologramConfig.getLocation(); + configuration.set(path + "enable", hologramConfig.isEnable()); + configuration.set(path + "lines", hologramConfig.getLines()); + configuration.set(path + "world", location.getWorld().getName()); + configuration.set(path + "x", location.getBlockX()); + configuration.set(path + "y", location.getBlockY()); + configuration.set(path + "z", location.getBlockZ()); + + } +} diff --git a/src/fr/maxlego08/koth/loader/KothLoader.java b/src/fr/maxlego08/koth/loader/KothLoader.java index c7a695c..f66c5d7 100644 --- a/src/fr/maxlego08/koth/loader/KothLoader.java +++ b/src/fr/maxlego08/koth/loader/KothLoader.java @@ -4,6 +4,7 @@ import fr.maxlego08.koth.KothPlugin; import fr.maxlego08.koth.ZKoth; import fr.maxlego08.koth.api.Koth; import fr.maxlego08.koth.api.KothType; +import fr.maxlego08.koth.api.utils.HologramConfig; import fr.maxlego08.koth.api.utils.ScoreboardConfiguration; import fr.maxlego08.koth.zcore.utils.ZUtils; import fr.maxlego08.koth.zcore.utils.loader.Loader; @@ -18,6 +19,7 @@ public class KothLoader extends ZUtils implements Loader { private final KothPlugin plugin; private final Loader locationLoader = new LocationLoader(); private final Loader scoreboardLoaderLoader = new ScoreboardLoader(); + private final Loader hologramConfigLoader = new HologramLoader(); public KothLoader(KothPlugin plugin) { this.plugin = plugin; @@ -41,9 +43,10 @@ public class KothLoader extends ZUtils implements Loader { Location maxLocation = locationLoader.load(configuration, "maxLocation.", file); ScoreboardConfiguration cooldownScoreboard = scoreboardLoaderLoader.load(configuration, "scoreboard.cooldown.", file); ScoreboardConfiguration startScoreboard = scoreboardLoaderLoader.load(configuration, "scoreboard.start.", file); + HologramConfig hologramConfig = hologramConfigLoader.load(configuration, "hologram.", file); return new ZKoth(this.plugin, fileName, kothType, name, captureSeconds, minLocation, maxLocation, startCommands, endCommands, cooldownScoreboard, - startScoreboard, cooldownStart, stopAfterSeconds, enableStartCapMessage, enableLooseCapMessage, enableEverySecondsCapMessage); + startScoreboard, cooldownStart, stopAfterSeconds, enableStartCapMessage, enableLooseCapMessage, enableEverySecondsCapMessage, hologramConfig); } @Override @@ -63,6 +66,7 @@ public class KothLoader extends ZUtils implements Loader { locationLoader.save(koth.getMaxLocation(), configuration, "maxLocation."); scoreboardLoaderLoader.save(koth.getCooldownScoreboard(), configuration, "scoreboard.cooldown."); scoreboardLoaderLoader.save(koth.getStartScoreboard(), configuration, "scoreboard.start."); + hologramConfigLoader.save(koth.getHologramConfig(), configuration, "hologram."); } } diff --git a/src/fr/maxlego08/koth/zcore/utils/plugins/Plugins.java b/src/fr/maxlego08/koth/zcore/utils/plugins/Plugins.java index 9e8867c..b566371 100644 --- a/src/fr/maxlego08/koth/zcore/utils/plugins/Plugins.java +++ b/src/fr/maxlego08/koth/zcore/utils/plugins/Plugins.java @@ -9,7 +9,7 @@ public enum Plugins { CITIZENS("Citizens"), TRANSLATIONAPI("TranslationAPI"), ZTRANSLATOR("zTranslator"), - + DH("DecentHolograms"), ZSCHEDULERS("zSchedulers"), ; diff --git a/src/main/resources/koth-example.yml b/src/main/resources/koth-example.yml index 59b73e2..a4b31da 100644 --- a/src/main/resources/koth-example.yml +++ b/src/main/resources/koth-example.yml @@ -51,15 +51,15 @@ endCommands: [] minLocation: world: world - x: 81 - y: 121 - z: 12 + x: 0 + y: 0 + z: 0 manLocation: world: world - x: 77 - y: 123 - z: 8 + x: 0 + y: 0 + z: 0 scoreboard: cooldown: @@ -87,3 +87,14 @@ scoreboard: - "#16db47Time left:" - " #636363◊ #ffffff%captureFormat%" - "&r" + +hologram: + enable: false + lines: + - "&fCoordinate: &b%centerX% %centerY% %centerZ%" + - "" + - "&fTimer: &b%captureFormat%" + world: world + x: 0 + y: 0 + z: 0 \ No newline at end of file