Skip to content

Commit

Permalink
feat: Hologram bedrock support
Browse files Browse the repository at this point in the history
* If cause for showing different message if a player is playing in java or bedrock

* fix hoogram enabling option not working on start
  • Loading branch information
tintinkung committed Apr 17, 2024
1 parent 2b4fc60 commit 8e950c9
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 39 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/alpsbte/plotsystem/PlotSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ private static boolean checkForRequiredDependencies() {
missingDependencies.add("HolographicDisplays");
}

if (!pluginManager.isPluginEnabled("Geyser-Spigot")) {
missingDependencies.add("Geyser-Spigot");
}


if (!pluginManager.isPluginEnabled("DecentHolograms")) {
missingDependencies.add("DecentHolograms");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ 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();
// Register and create holograms
if (PlotSystem.getPlugin().getConfig().getBoolean(((HologramConfiguration) display).getEnablePath())) {
display.setEnabled(true);
for (Player player : Objects.requireNonNull(Bukkit.getWorld(display.getLocation().getWorld().getName())).getPlayers())
display.create(player);
}
else {
display.setEnabled(false);
display.removeAll();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,26 @@

package com.alpsbte.plotsystem.core.holograms;

import com.alpsbte.plotsystem.PlotSystem;
import com.alpsbte.plotsystem.core.holograms.connector.DecentHologramDisplay;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

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

public final class LeaderboardManager extends HologramManager {

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

// Register and create holograms
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();
}
activeDisplays.add(new ScoreLeaderboard());
activeDisplays.add(new PlotsLeaderboard());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
public class PlotsLeaderboard extends DecentHologramDisplay implements HologramConfiguration {
protected PlotsLeaderboard() {
super(ConfigPaths.PLOTS_LEADERBOARD, null, false);
setLocation(LeaderboardManager.getLocation(this));
setLocation(HologramManager.getLocation(this));
setEnabled(PlotSystem.getPlugin().getConfig().getBoolean(getEnablePath()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public class ScoreLeaderboard extends DecentHologramPagedDisplay implements Holo

protected ScoreLeaderboard() {
super( "score-leaderboard", null, false, PlotSystem.getPlugin());
setLocation(LeaderboardManager.getLocation(this));
setEnabled(PlotSystem.getPlugin().getConfig().getBoolean(getEnablePath()));
setLocation(HologramManager.getLocation(this));

new BukkitRunnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.connection.GeyserConnection;
import org.jetbrains.annotations.NotNull;

import java.sql.SQLException;
Expand All @@ -21,12 +23,24 @@

public class WelcomeMessage extends DecentHologramDisplay implements HologramConfiguration {
public static String contentSeparator = "§7---------------";
public static final String EMPTY_TAG = "&f";
private final static int MAX_HOLOGRAM_LENGTH = 48; // The maximum length of a line in the hologram
private final static String HOLOGRAM_LINE_BREAKER = "%newline%";

private static ArrayList<DataLine<?>> makeContent(String header, String message1, String message2) {
final int MAX_HOLOGRAM_LENGTH = 48; // The maximum length of a line in the hologram
final String HOLOGRAM_LINE_BREAKER = "%newline%";
ArrayList<DataLine<?>> lines = new ArrayList<>();
ArrayList<String> innerLines1 = AlpsUtils.createMultilineFromString(message1, MAX_HOLOGRAM_LENGTH, HOLOGRAM_LINE_BREAKER);
ArrayList<String> innerLines2 = AlpsUtils.createMultilineFromString(message2, MAX_HOLOGRAM_LENGTH, HOLOGRAM_LINE_BREAKER);

lines.add(new TextLine("<#45b5ff>&l" + header + "</#30f8ff>"));
innerLines1.forEach(innerLine -> lines.add(new TextLine(innerLine)));
innerLines2.forEach(innerLine -> lines.add(new TextLine(innerLine)));
return lines;
}

public WelcomeMessage() {
super(ConfigPaths.WELCOME_MESSAGE, null, false);
setLocation(LeaderboardManager.getLocation(this));
setEnabled(PlotSystem.getPlugin().getConfig().getBoolean(getEnablePath()));
setLocation(HologramManager.getLocation(this));
}

@Override
Expand All @@ -36,17 +50,24 @@ public ItemStack getItem() {

@Override
public List<DataLine<?>> getContent(UUID playerUUID) {
ArrayList<DataLine<?>> lines = new ArrayList<>();
lines.add(new TextLine("<#45b5ff>&l" + LangUtil.getInstance().get(playerUUID, LangPaths.WelcomeMessage.JAVA_TITLE1) + "</#30f8ff>"));
String content = LangUtil.getInstance().get(playerUUID, LangPaths.WelcomeMessage.JAVA_MESSAGE1);
List<String> innerLines = AlpsUtils.createMultilineFromString(content, MAX_HOLOGRAM_LENGTH, HOLOGRAM_LINE_BREAKER);
innerLines.forEach(innerLine -> lines.add(new TextLine(innerLine)));
return lines;
GeyserConnection connection = GeyserApi.api().connectionByUuid(playerUUID);
String header = LangUtil.getInstance().get(playerUUID, LangPaths.WelcomeMessage.WELCOME_HEADER);

if(connection == null) {
return makeContent(header, // Java Player Message
LangUtil.getInstance().get(playerUUID, LangPaths.WelcomeMessage.WELCOME_JAVA1),
LangUtil.getInstance().get(playerUUID, LangPaths.WelcomeMessage.WELCOME_JAVA2));
}

return makeContent(header, // Bedrock Player Message
LangUtil.getInstance().get(playerUUID, LangPaths.WelcomeMessage.WELCOME_BEDROCK1),
LangUtil.getInstance().get(playerUUID, LangPaths.WelcomeMessage.WELCOME_BEDROCK2));
}

@Override
public String getTitle(UUID playerUUID) {
return "<#ANIM:burn:<#fc3903>,<#fcba03>&l>" + LangUtil.getInstance().get(playerUUID, LangPaths.WelcomeMessage.WELCOME_TITLE2) + "</#ANIM>";
String title = LangUtil.getInstance().get(playerUUID, LangPaths.WelcomeMessage.WELCOME_HEADER);
return "<#ANIM:burn:<#fc3903>,<#fcba03>&l>" + title + "</#ANIM>";
}
@Override
public List<DataLine<?>> getFooter(UUID playerUUID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
Expand Down Expand Up @@ -49,7 +48,7 @@ public abstract class DecentHologramDisplay implements DecentHologramContent {
public static final String EMPTY_TAG = "&f";
private final String id;
private Location position;
private final boolean isPlaceholdersEnabled;
private boolean isEnabled;
protected final HashMap<UUID, Hologram> holograms = new HashMap<>();
private AbstractTutorialHologram.ClickAction clickListener;

Expand All @@ -58,14 +57,15 @@ public static void registerPlugin(Plugin plugin) {
plugin.getServer().getPluginManager().registerEvents(new DecentHologramListener(), plugin);
}

public DecentHologramDisplay(@NotNull String id, Location position, boolean enablePlaceholders) {
public DecentHologramDisplay(@NotNull String id, Location position, boolean isEnabled) {
this.id = id;
this.position = position;
this.isPlaceholdersEnabled = enablePlaceholders;
this.isEnabled = isEnabled;
activeDisplays.add(this);
}

public void create(Player player) {
if(!isEnabled) return;
if (this.hasViewPermission(player.getUniqueId())) {
if (this.holograms.containsKey(player.getUniqueId())) {
this.reload(player.getUniqueId());
Expand Down Expand Up @@ -153,9 +153,10 @@ public void setLocation(Location newPosition) {

}

public boolean isPlaceholdersEnabled() {
return this.isPlaceholdersEnabled;
public boolean isEnabled() {
return this.isEnabled;
}
public void setEnabled(boolean isEnabled) { this.isEnabled = isEnabled; }

public Hologram getHologram(UUID playerUUID) {
return this.holograms.get(playerUUID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public DecentHologramListener() {

@EventHandler
public void onPlayerJoinEvent(PlayerJoinEvent event) {

// Create player's hologram each time they join
for (DecentHologramDisplay display : DecentHologramDisplay.activeDisplays) {
if (display.getLocation() == null) return;
if (display.getLocation().getWorld().getName().equals(event.getPlayer().getWorld().getName()))
Expand Down Expand Up @@ -44,15 +44,9 @@ public void onPlayerChangedWorldEvent(PlayerChangedWorldEvent event) {
@EventHandler
public void onHologramClick(HologramClickEvent event) {
for (DecentHologramDisplay display : DecentHologramDisplay.activeDisplays) {
if (display.getLocation() == null) return;
if (display.getLocation() == null | display.getClickListender() == null) continue;
if (display.getHologram(event.getPlayer().getUniqueId()).equals(event.getHologram()))
if(display.getClickListender() != null)
display.getClickListender().onClick(event);
}

Bukkit.getLogger().info("Hologram clicked on an entity: "
+ event.getEntityId()
+ " with hologram lines: "
+ event.getHologram().getPage(event.getPlayer()).getLines());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public abstract class DecentHologramPagedDisplay extends DecentHologramDisplay {
private static String contentSeparator = "§7---------------";
protected boolean automaticallySkipPage = true;

public DecentHologramPagedDisplay(@NotNull String id, Location position, boolean enablePlaceholders, @NotNull Plugin plugin) {
super(id, position, enablePlaceholders);
public DecentHologramPagedDisplay(@NotNull String id, Location position, boolean isEnabled, @NotNull Plugin plugin) {
super(id, position, isEnabled);
this.plugin = plugin;
}

Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/alpsbte/plotsystem/utils/io/LangPaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,12 @@ public static final class Error {

public static final class WelcomeMessage {
private static final String WELCOME = "welcome-message.";
public static final String WELCOME_TITLE1 = WELCOME + "title-1";
public static final String WELCOME_TITLE2 = WELCOME + "title-2";
public static final String JAVA_TITLE1 = WELCOME + "java-title-1";
public static final String JAVA_MESSAGE1 = WELCOME + "java-message-1";
public static final String WELCOME_TITLE = WELCOME + "title";
public static final String WELCOME_HEADER = WELCOME + "header";
public static final String WELCOME_JAVA1 = WELCOME + "java-message-1";
public static final String WELCOME_JAVA2 = WELCOME + "java-message-2";
public static final String WELCOME_BEDROCK1 = WELCOME + "bedrock-message-1";
public static final String WELCOME_BEDROCK2 = WELCOME + "bedrock-message-2";
}

public static final class Leaderboards {
Expand Down
8 changes: 5 additions & 3 deletions src/main/resources/lang/en_GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,12 @@ message:
tutorial-disabled: 'Tutorials are disabled on this server.'
tutorial-already-running: "You already have a tutorial running! Complete it before starting a new one."
welcome-message:
title-1: "Welcome"
title-2: "ASEAN Build The Earth"
java-title-1: "Getting Started"
title: "ASEAN Build The Earth"
header: "To Start Building"
java-message-1: "Use your §bCompanion§r to see available plots and start creating your first build!"
java-message-2: "§7Look up our §9Discord Server§r%newline%§7to get help from our staff."
bedrock-message-1: "Look at the §bCountry Board§r on the left to see all of our available plots."
bedrock-message-2: "Using §9plot ID§r from the board, you may use the command §e/plot create §e<§9ID§r§e>§r and start creating your first build!"
leaderboards:
pages:
DAILY: "Daily"
Expand Down

0 comments on commit 8e950c9

Please sign in to comment.