🚧 Add hologram

This commit is contained in:
Maxlego08 2024-02-22 18:20:24 +01:00
parent 8762b3c63e
commit fe6f486b27
13 changed files with 262 additions and 20 deletions

Binary file not shown.

View File

@ -191,5 +191,12 @@
<artifactId>zSchedulers</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>com.github.decentsoftware-eu</groupId>
<artifactId>decentholograms</artifactId>
<version>2.8.6</version>
<systemPath>${basedir}/libs/DecentHolograms-2.8.6.jar</systemPath>
<scope>system</scope>
</dependency>
</dependencies>
</project>

View File

@ -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;
}
}

View File

@ -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<String> startCommands, List<String> 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<String> startCommands, List<String> 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;
}
}

View File

@ -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<Player> onScoreboard();
HologramConfig getHologramConfig();
String replaceMessage(String string);
}

View File

@ -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();
}

View File

@ -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<String> lines;
private final Location location;
public HologramConfig(boolean isEnable, List<String> 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<String> getLines() {
return lines;
}
}

View File

@ -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<Koth, Hologram> holograms = new HashMap<Koth, Hologram>();
@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<String> 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();
}
}

View File

@ -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
}
}

View File

@ -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<HologramConfig> {
@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<String> 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());
}
}

View File

@ -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<Koth> {
private final KothPlugin plugin;
private final Loader<Location> locationLoader = new LocationLoader();
private final Loader<ScoreboardConfiguration> scoreboardLoaderLoader = new ScoreboardLoader();
private final Loader<HologramConfig> hologramConfigLoader = new HologramLoader();
public KothLoader(KothPlugin plugin) {
this.plugin = plugin;
@ -41,9 +43,10 @@ public class KothLoader extends ZUtils implements Loader<Koth> {
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<Koth> {
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.");
}
}

View File

@ -9,7 +9,7 @@ public enum Plugins {
CITIZENS("Citizens"),
TRANSLATIONAPI("TranslationAPI"),
ZTRANSLATOR("zTranslator"),
DH("DecentHolograms"),
ZSCHEDULERS("zSchedulers"),
;

View File

@ -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