Skip to content

Commit

Permalink
feat: ported HolographicDisplay plugin to DecentHologram
Browse files Browse the repository at this point in the history
* Since HolographicDisplay is no longer in maintenance, we port nearly every uses to DecentHologram instead

* This fixed a bug of Bedrock player not able to view newly created hologram

* The port is not yet 100%, so HolographicDisplay is still a requirement due to a use in alpslib.npc
  • Loading branch information
tintinkung committed Apr 16, 2024
1 parent 156fc5b commit c2894e2
Show file tree
Hide file tree
Showing 25 changed files with 791 additions and 114 deletions.
18 changes: 18 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<version>4.0</version>

<repositories>
<repository>
<id>opencollab-snapshot</id>
<url>https://repo.opencollab.dev/main/</url>
</repository>
<!-- WorldGuard -->
<repository>
<id>sk89q-repo</id>
Expand Down Expand Up @@ -47,6 +51,13 @@
</repositories>

<dependencies>
<!-- Geyser Connector -->
<dependency>
<groupId>org.geysermc.geyser</groupId>
<artifactId>api</artifactId>
<version>2.2.3-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- Paper -->
<dependency>
<groupId>io.papermc.paper</groupId>
Expand Down Expand Up @@ -102,6 +113,13 @@
<version>3.0.3</version>
<scope>provided</scope>
</dependency>
<!-- Decent Hologram -->
<dependency>
<groupId>com.github.decentsoftware-eu</groupId>
<artifactId>decentholograms</artifactId>
<version>2.8.6</version>
<scope>provided</scope>
</dependency>
<!-- Alps Utils -->
<dependency>
<groupId>com.alpsbte.alpslib</groupId>
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/com/alpsbte/plotsystem/PlotSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@

package com.alpsbte.plotsystem;

import com.alpsbte.alpslib.hologram.HolographicDisplay;
import com.alpsbte.alpslib.io.YamlFileFactory;
import com.alpsbte.alpslib.io.config.ConfigNotImplementedException;
import com.alpsbte.alpslib.utils.AlpsUtils;
import com.alpsbte.alpslib.utils.head.AlpsHeadEventListener;
import com.alpsbte.plotsystem.commands.*;
import com.alpsbte.plotsystem.core.holograms.HologramManager;
import com.alpsbte.plotsystem.core.holograms.MessagesManager;
import com.alpsbte.plotsystem.core.holograms.connector.DecentHologramDisplay;
import com.alpsbte.plotsystem.core.holograms.LeaderboardManager;
import com.alpsbte.plotsystem.core.system.Builder;
import com.alpsbte.plotsystem.core.system.plot.Plot;
Expand Down Expand Up @@ -181,8 +183,9 @@ public void onEnable() {
}
});

HolographicDisplay.registerPlugin(this);
LeaderboardManager.initLeaderboards();
DecentHologramDisplay.registerPlugin(this);
LeaderboardManager.init();
MessagesManager.init();
PlotUtils.checkPlotsForLastActivity();
PlotUtils.syncPlotSchematicFiles();
Utils.ChatUtils.checkForChatInputExpiry();
Expand Down Expand Up @@ -222,7 +225,7 @@ public void onDisable() {
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GRAY + "> " + ChatColor.GRAY + "GitHub: " + ChatColor.WHITE + "https://github.com/AlpsBTE/Plot-System");
Bukkit.getConsoleSender().sendMessage(ChatColor.GOLD + "------------------------------------------------------");

LeaderboardManager.getLeaderboards().forEach(HolographicDisplay::delete);
LeaderboardManager.getActiveDisplays().forEach(DecentHologramDisplay::delete);
} else {
// Unload plots
for (UUID player : PlotUtils.Cache.getCachedInProgressPlots().keySet()) {
Expand Down Expand Up @@ -284,6 +287,10 @@ private static boolean checkForRequiredDependencies() {
missingDependencies.add("HolographicDisplays");
}

if (!pluginManager.isPluginEnabled("DecentHolograms")) {
missingDependencies.add("DecentHolograms");
}

if (!pluginManager.isPluginEnabled("Multiverse-Core")) {
missingDependencies.add("Multiverse-Core");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.alpsbte.plotsystem.PlotSystem;
import com.alpsbte.plotsystem.commands.BaseCommand;
import com.alpsbte.plotsystem.core.database.DatabaseConnection;
import com.alpsbte.plotsystem.core.holograms.LeaderboardConfiguration;
import com.alpsbte.plotsystem.core.holograms.HologramConfiguration;
import com.alpsbte.plotsystem.core.holograms.LeaderboardManager;
import com.alpsbte.plotsystem.utils.Utils;
import org.bukkit.Bukkit;
Expand All @@ -50,9 +50,9 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
PlotSystem.getPlugin().reloadConfig();
sender.sendMessage(Utils.ChatUtils.getInfoFormat("Successfully reloaded config!"));

LeaderboardManager.getLeaderboards().forEach(leaderboard -> leaderboard.setPosition(LeaderboardManager
.getPosition((LeaderboardConfiguration) leaderboard)));
LeaderboardManager.reloadLeaderboards();
LeaderboardManager.getActiveDisplays().forEach(leaderboard -> leaderboard.setLocation(LeaderboardManager
.getLocation((HologramConfiguration) leaderboard)));
LeaderboardManager.reload();
sender.sendMessage(Utils.ChatUtils.getInfoFormat("Successfully reloaded leaderboards!"));

DatabaseConnection.InitializeDatabase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

package com.alpsbte.plotsystem.commands.admin;

import com.alpsbte.alpslib.hologram.HolographicDisplay;
import com.alpsbte.plotsystem.commands.BaseCommand;
import com.alpsbte.plotsystem.core.holograms.LeaderboardConfiguration;
import com.alpsbte.plotsystem.core.holograms.HologramConfiguration;
import com.alpsbte.plotsystem.core.holograms.LeaderboardManager;
import com.alpsbte.plotsystem.core.holograms.connector.DecentHologramDisplay;
import com.alpsbte.plotsystem.utils.Utils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand All @@ -54,15 +54,15 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
if (args.length != 1) {
sendInfo(sender);
player.sendMessage("§8------- §6§lLeaderboards §8-------");
for(HolographicDisplay holo : LeaderboardManager.getLeaderboards()) {
for(DecentHologramDisplay holo : LeaderboardManager.getActiveDisplays()) {
player.sendMessage(" §6> §f" + holo.getId());
}
player.sendMessage("§8--------------------------");
return true;
}

// Find leaderboard by name
HolographicDisplay leaderboard = LeaderboardManager.getLeaderboards().stream()
DecentHologramDisplay leaderboard = LeaderboardManager.getActiveDisplays().stream()
.filter(holo -> holo.getId().equalsIgnoreCase(args[0]))
.findFirst()
.orElse(null);
Expand All @@ -72,7 +72,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
player.sendMessage(Utils.ChatUtils.getAlertFormat("Leaderboard could not be found!"));
return true;
}
LeaderboardManager.savePosition(leaderboard.getId(), (LeaderboardConfiguration) leaderboard, getPlayer(sender).getLocation());
LeaderboardManager.saveLocation(leaderboard.getId(), (HologramConfiguration) leaderboard, getPlayer(sender).getLocation());
player.sendMessage(Utils.ChatUtils.getInfoFormat("Successfully updated hologram location!"));
player.playSound(player.getLocation(), Utils.SoundUtils.DONE_SOUND,1,1);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package com.alpsbte.plotsystem.core.holograms;

public interface LeaderboardConfiguration {
public interface HologramConfiguration {
String getEnablePath();
String getXPath();
String getYPath();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.alpsbte.plotsystem.core.holograms;

import com.alpsbte.plotsystem.PlotSystem;
import com.alpsbte.plotsystem.core.holograms.connector.DecentHologramDisplay;
import com.alpsbte.plotsystem.utils.Utils;
import com.alpsbte.plotsystem.utils.io.ConfigUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.logging.Level;

public abstract class HologramManager {
public static List<DecentHologramDisplay> activeDisplays = new ArrayList<>();

public static void reload() {
for (DecentHologramDisplay display : activeDisplays) {
Bukkit.getLogger().log(Level.INFO, "Enabling Hologram: " + PlotSystem.getPlugin().getConfig().getBoolean(((HologramConfiguration) display).getEnablePath()));

if (PlotSystem.getPlugin().getConfig().getBoolean(((HologramConfiguration) display).getEnablePath()))
for (Player player : Objects.requireNonNull(Bukkit.getWorld(display.getLocation().getWorld().getName())).getPlayers()) display.create(player);
else display.removeAll();
}
}

public static Location getLocation(HologramConfiguration configPaths) {
FileConfiguration config = PlotSystem.getPlugin().getConfig();

return new Location(Objects.requireNonNull(Utils.getSpawnLocation().getWorld()),
config.getDouble(configPaths.getXPath()),
config.getDouble(configPaths.getYPath()),
config.getDouble(configPaths.getZPath())
);
}

public static void saveLocation(String id, HologramConfiguration configPaths, Location newLocation) {
FileConfiguration config = PlotSystem.getPlugin().getConfig();
config.set(configPaths.getEnablePath(), true);
config.set(configPaths.getXPath(), newLocation.getX());
config.set(configPaths.getYPath(), newLocation.getY());
config.set(configPaths.getZPath(), newLocation.getZ());
ConfigUtil.getInstance().saveFiles();

LeaderboardManager.getActiveDisplays().stream().filter(leaderboard -> leaderboard.getId().equals(id)).findFirst()
.ifPresent(holo -> holo.setLocation(newLocation));
}

public static List<DecentHologramDisplay> getActiveDisplays() {
return activeDisplays;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,64 +24,18 @@

package com.alpsbte.plotsystem.core.holograms;

import com.alpsbte.alpslib.hologram.HolographicDisplay;
import com.alpsbte.plotsystem.PlotSystem;
import com.alpsbte.plotsystem.utils.Utils;
import com.alpsbte.plotsystem.utils.io.ConfigUtil;
import me.filoghost.holographicdisplays.api.Position;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import com.alpsbte.plotsystem.core.holograms.connector.DecentHologramDisplay;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public final class LeaderboardManager extends HologramManager {

public final class LeaderboardManager {
private static final List<HolographicDisplay> leaderboards = new ArrayList<>();

public static void initLeaderboards() {
leaderboards.add(new ScoreLeaderboard());
leaderboards.add(new PlotsLeaderboard());
}

public static void reloadLeaderboards() {
for (HolographicDisplay leaderboard : leaderboards) {
if (PlotSystem.getPlugin().getConfig().getBoolean(((LeaderboardConfiguration) leaderboard).getEnablePath()))
for (Player player : Objects.requireNonNull(Bukkit.getWorld(leaderboard.getPosition().getWorldName())).getPlayers()) leaderboard.create(player);
else leaderboard.removeAll();
}
}

public static Position getPosition(LeaderboardConfiguration configPaths) {
FileConfiguration config = PlotSystem.getPlugin().getConfig();
return Position.of(Objects.requireNonNull(Utils.getSpawnLocation().getWorld()).getName(),
config.getDouble(configPaths.getXPath()),
config.getDouble(configPaths.getYPath()),
config.getDouble(configPaths.getZPath())
);
public static void init() {
activeDisplays.add(new ScoreLeaderboard());
activeDisplays.add(new PlotsLeaderboard());
}

public static void savePosition(String id, LeaderboardConfiguration configPaths, Location newLocation) {
FileConfiguration config = PlotSystem.getPlugin().getConfig();
config.set(configPaths.getEnablePath(), true);
config.set(configPaths.getXPath(), newLocation.getX());
config.set(configPaths.getYPath(), newLocation.getY());
config.set(configPaths.getZPath(), newLocation.getZ());
ConfigUtil.getInstance().saveFiles();

LeaderboardManager.getLeaderboards().stream().filter(leaderboard -> leaderboard.getId().equals(id)).findFirst()
.ifPresent(holo -> holo.setPosition(Position.of(newLocation)));
}

public static class LeaderboardPositionLine extends HolographicDisplay.TextLine {
public static class LeaderboardPositionLine extends DecentHologramDisplay.TextLine {
public LeaderboardPositionLine(int position, String username, int score) {
super("§e#" + position + " " + (username != null ? "§a" + username : "§8No one, yet") + " §7- §b" + score);
}
}

public static List<HolographicDisplay> getLeaderboards() {
return leaderboards;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.alpsbte.plotsystem.core.holograms;

import com.alpsbte.plotsystem.core.holograms.connector.DecentHologramDisplay;
import eu.decentsoftware.holograms.api.DHAPI;
import eu.decentsoftware.holograms.api.holograms.Hologram;
import eu.decentsoftware.holograms.api.holograms.HologramLine;
import eu.decentsoftware.holograms.api.utils.entity.HologramEntity;
import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;

import java.util.logging.Level;

public class MessagesManager extends HologramManager {
public static void init() {
activeDisplays.add(new WelcomeMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

package com.alpsbte.plotsystem.core.holograms;

import com.alpsbte.alpslib.hologram.HolographicDisplay;
import com.alpsbte.plotsystem.PlotSystem;
import com.alpsbte.plotsystem.core.holograms.connector.DecentHologramDisplay;
import com.alpsbte.plotsystem.core.system.Builder;
import com.alpsbte.plotsystem.utils.io.ConfigPaths;
import org.bukkit.Material;
Expand All @@ -37,10 +37,10 @@
import java.util.UUID;
import java.util.logging.Level;

public class PlotsLeaderboard extends HolographicDisplay implements LeaderboardConfiguration {
public class PlotsLeaderboard extends DecentHologramDisplay implements HologramConfiguration {
protected PlotsLeaderboard() {
super(ConfigPaths.PLOTS_LEADERBOARD, null, false);
setPosition(LeaderboardManager.getPosition(this));
setLocation(LeaderboardManager.getLocation(this));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@

package com.alpsbte.plotsystem.core.holograms;

import com.alpsbte.alpslib.hologram.HolographicPagedDisplay;
import com.alpsbte.plotsystem.PlotSystem;
import com.alpsbte.plotsystem.core.holograms.connector.DecentHologramPagedDisplay;
import com.alpsbte.plotsystem.core.system.Builder;
import com.alpsbte.plotsystem.core.system.Payout;
import com.alpsbte.plotsystem.core.system.tutorial.AbstractTutorial;
import com.alpsbte.plotsystem.utils.io.ConfigPaths;
import com.alpsbte.plotsystem.utils.io.ConfigUtil;
import com.alpsbte.plotsystem.utils.io.LangPaths;
import com.alpsbte.plotsystem.utils.io.LangUtil;
import me.filoghost.holographicdisplays.api.hologram.Hologram;
import eu.decentsoftware.holograms.api.DHAPI;
import eu.decentsoftware.holograms.api.holograms.Hologram;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.BaseComponent;
Expand All @@ -48,20 +49,17 @@

import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;

public class ScoreLeaderboard extends HolographicPagedDisplay implements LeaderboardConfiguration {
public class ScoreLeaderboard extends DecentHologramPagedDisplay implements HologramConfiguration {
private final DecimalFormat df = new DecimalFormat("#.##");
private LeaderboardTimeframe sortByLeaderboard = LeaderboardTimeframe.DAILY;

protected ScoreLeaderboard() {
super("score-leaderboard", null, false, PlotSystem.getPlugin());
setPosition(LeaderboardManager.getPosition(this));
super( "score-leaderboard", null, false, PlotSystem.getPlugin());
setLocation(LeaderboardManager.getLocation(this));

new BukkitRunnable() {
@Override
Expand Down Expand Up @@ -192,10 +190,10 @@ private List<Player> showToPlayers() {
List<Player> players = new ArrayList<>();
if (!actionBarEnabled) return players;
for (Player player : Bukkit.getOnlinePlayers()) {
Hologram holo = getHologram(player.getUniqueId());
Hologram holo = DHAPI.getHologram(player.getUniqueId().toString());
if (holo == null) continue;
if (player.getWorld().getName().equals(holo.getPosition().getWorldName()) &&
holo.getPosition().distance(player.getLocation()) <= actionBarRadius) {
if (player.getWorld().getName().equals(holo.getLocation().getWorld().getName()) &&
holo.getLocation().distance(player.getLocation()) <= actionBarRadius) {
players.add(player);
}
}
Expand Down
Loading

0 comments on commit c2894e2

Please sign in to comment.