From 4fce229ad381c641051f842e35db6636b6e3c465 Mon Sep 17 00:00:00 2001
From: TheLittle_Yang <2570984321@qq.com>
Date: Fri, 23 Aug 2024 13:52:05 +0800
Subject: [PATCH 1/2] Add more placeholders.
---
README.md | 6 +-
.../slimehud/placeholder/PlaceholderHook.java | 22 +++++-
.../slimehud/util/HudBuilder.java | 8 +--
.../slimehud/waila/HudController.java | 12 ++--
.../slimehud/waila/PlayerWAILA.java | 71 +++++++++++--------
5 files changed, 75 insertions(+), 44 deletions(-)
diff --git a/README.md b/README.md
index 8abbd29..331ff1d 100644
--- a/README.md
+++ b/README.md
@@ -10,8 +10,10 @@ The HUD lets you see what Slimefun item a block is without breaking or opening i
## PlaceholderAPI
-- `%slimehud_toggle%`
-Returns the current player's toggle state. Possible values are `true` or `false`.
+- `%slimehud_toggle%` Returns the current player's toggle state. Possible values are `true` or `false`.
+- `%slimehud_hud%` Standard hud, including block display name and additional information.
+- `%slimehud_hud_block%` Only block display names.
+- `%slimehud_hud_block_info%` Only additional information.
## Limitations
diff --git a/src/main/java/io/github/schntgaispock/slimehud/placeholder/PlaceholderHook.java b/src/main/java/io/github/schntgaispock/slimehud/placeholder/PlaceholderHook.java
index 7009c86..c70b503 100644
--- a/src/main/java/io/github/schntgaispock/slimehud/placeholder/PlaceholderHook.java
+++ b/src/main/java/io/github/schntgaispock/slimehud/placeholder/PlaceholderHook.java
@@ -1,6 +1,8 @@
package io.github.schntgaispock.slimehud.placeholder;
import io.github.schntgaispock.slimehud.SlimeHUD;
+import io.github.schntgaispock.slimehud.waila.PlayerWAILA;
+import io.github.schntgaispock.slimehud.waila.WAILAManager;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;
@@ -8,6 +10,8 @@
import javax.annotation.Nullable;
public class PlaceholderHook extends PlaceholderExpansion {
+ private final WAILAManager wailaManager = WAILAManager.getInstance();
+
@Override
public @Nonnull String getIdentifier() {
return "slimehud";
@@ -32,8 +36,22 @@ public boolean persist() {
public @Nullable String onPlaceholderRequest(Player player, @Nonnull String params) {
if (params.equalsIgnoreCase("toggle")) {
return SlimeHUD.getInstance().getPlayerData().getString(player.getUniqueId() + ".waila", "true");
- } else {
- return null;
+ } else if (params.startsWith("hud")) {
+ String[] split = params.split("_");
+ PlayerWAILA playerWAILA = wailaManager.getWailas().get(player.getUniqueId());
+ switch (split.length) {
+ case 1 -> {
+ return playerWAILA.getFacing();
+ }
+ case 2 -> {
+ return playerWAILA.getFacingBlock();
+ }
+ case 3 -> {
+ return playerWAILA.getFacingBlockInfo();
+ }
+ }
}
+
+ return null;
}
}
diff --git a/src/main/java/io/github/schntgaispock/slimehud/util/HudBuilder.java b/src/main/java/io/github/schntgaispock/slimehud/util/HudBuilder.java
index 8d89ae4..7b26848 100644
--- a/src/main/java/io/github/schntgaispock/slimehud/util/HudBuilder.java
+++ b/src/main/java/io/github/schntgaispock/slimehud/util/HudBuilder.java
@@ -22,7 +22,7 @@ public class HudBuilder {
*/
@Nonnull
public static String formatEnergyStored(int energy) {
- return "&7| " + HudBuilder.getAbbreviatedNumber(energy) + " J Stored";
+ return HudBuilder.getAbbreviatedNumber(energy) + " J Stored";
}
/**
@@ -33,7 +33,7 @@ public static String formatEnergyStored(int energy) {
*/
@Nonnull
public static String formatEnergyStored(int energy, int totalEnergy) {
- return "&7| " + HudBuilder.getAbbreviatedNumber(energy) + "/" + HudBuilder.getAbbreviatedNumber(totalEnergy) + " J";
+ return HudBuilder.getAbbreviatedNumber(energy) + "/" + HudBuilder.getAbbreviatedNumber(totalEnergy) + " J";
}
/**
@@ -44,7 +44,7 @@ public static String formatEnergyStored(int energy, int totalEnergy) {
*/
@Nonnull
public static String formatEnergyGenerated(int energy) {
- return "&7| &e⚡&7 " + HudBuilder.getAbbreviatedNumber(energy) + " J/t";
+ return "&e⚡&7 " + HudBuilder.getAbbreviatedNumber(energy) + " J/t";
}
/**
@@ -128,7 +128,7 @@ public static String formatProgressBar(int progress, int total) {
*/
@Nonnull
public static String formatProgressBar(int percentCompleted) {
- return "&7| " + HudBuilder.getProgressBar(percentCompleted) + " - " + percentCompleted + "%";
+ return HudBuilder.getProgressBar(percentCompleted) + " - " + percentCompleted + "%";
}
/**
diff --git a/src/main/java/io/github/schntgaispock/slimehud/waila/HudController.java b/src/main/java/io/github/schntgaispock/slimehud/waila/HudController.java
index 3f2fa8d..c3b5f40 100644
--- a/src/main/java/io/github/schntgaispock/slimehud/waila/HudController.java
+++ b/src/main/java/io/github/schntgaispock/slimehud/waila/HudController.java
@@ -65,7 +65,7 @@ private String processEnergyNode(@Nonnull HudRequest request) {
Network en = EnergyNet.getNetworkFromLocation(request.getLocation());
int size = getNetworkSize(en);
- return size < 0 ? "" : "&7| Network Size: " + HudBuilder.getCommaNumber(size);
+ return size < 0 ? "" : "Network Size: " + HudBuilder.getCommaNumber(size);
}
@Nonnull
@@ -99,7 +99,7 @@ private String processMachine(@Nonnull HudRequest request) {
MachineOperation operation = machine.getMachineProcessor().getOperation(request.getLocation());
if (operation == null) {
- hudText.append("&7| Idle");
+ hudText.append("Idle");
if (request.getSlimefunItem() instanceof EnergyNetComponent) {
hudText.append(" ").append(processCapacitor(request));
}
@@ -131,7 +131,7 @@ private String processGenerator(@Nonnull HudRequest request) {
if (generation > 0) {
hudText.append(HudBuilder.formatEnergyGenerated(generation));
} else {
- hudText.append("&7| Not generating");
+ hudText.append("Not generating");
}
if (gen instanceof EnergyNetComponent) {
@@ -155,7 +155,7 @@ private String processSolarGenerator(@Nonnull HudRequest request) {
if (generation > 0) {
hudText.append(HudBuilder.formatEnergyGenerated(generation));
} else {
- hudText.append("&7| Not generating");
+ hudText.append("Not generating");
}
if (gen instanceof EnergyNetComponent) {
@@ -172,7 +172,7 @@ private String processCargoNode(@Nonnull HudRequest request) {
}
CargoNode cn = (CargoNode) request.getSlimefunItem();
int channel = cn.getSelectedChannel(request.getLocation().getBlock()) + 1;
- return "&7| Channel: " + Util.getColorFromCargoChannel(channel).toString() + channel;
+ return "Channel: " + Util.getColorFromCargoChannel(channel).toString() + channel;
}
@Nonnull
@@ -183,7 +183,7 @@ private String processCargoManagerConnector(@Nonnull HudRequest request) {
Network cn = CargoNet.getNetworkFromLocation(request.getLocation());
int size = getNetworkSize(cn);
- return size < 0 ? "" : "&7| Network Size: " + HudBuilder.getCommaNumber(size);
+ return size < 0 ? "" : "Network Size: " + HudBuilder.getCommaNumber(size);
}
private int getNetworkSize(Network network) {
diff --git a/src/main/java/io/github/schntgaispock/slimehud/waila/PlayerWAILA.java b/src/main/java/io/github/schntgaispock/slimehud/waila/PlayerWAILA.java
index 064a17b..0f7f347 100644
--- a/src/main/java/io/github/schntgaispock/slimehud/waila/PlayerWAILA.java
+++ b/src/main/java/io/github/schntgaispock/slimehud/waila/PlayerWAILA.java
@@ -21,13 +21,24 @@
public class PlayerWAILA extends BukkitRunnable {
- final private @Nonnull @Getter Player player;
+ final private @Nonnull
+ @Getter Player player;
final private @Getter BossBar WAILABar; // Bossbar
final private String WAILALocation;
final private boolean useAutoBossBarColor;
final private boolean keepTextColors;
-
+ /**
+ * Returns an empty string if not a Slimefun item. Otherwise returns the
+ * formatted item name
+ */
+ @Getter
+ private String facing = "";
+ @Getter
+ private String facingBlock = "";
+ @Getter
+ private String facingBlockInfo = "";
private String previousFacing = "";
+
private @Getter boolean paused;
public PlayerWAILA(@Nonnull Player player) {
@@ -44,39 +55,13 @@ public PlayerWAILA(@Nonnull Player player) {
this.keepTextColors = SlimeHUD.getInstance().getConfig().getBoolean("waila.use-original-colors");
}
- /**
- * Returns an empty string if not a Slimefun item. Otherwise returns the
- * formatted item name
- *
- * @return Formatted item name or empty string
- */
- public String getFacing() {
- Block targetBlock = player.getTargetBlockExact(5);
- if (targetBlock == null)
- return "";
-
- Location target = targetBlock.getLocation();
- if (target == null)
- return "";
-
- SlimefunItem item = BlockStorage.check(targetBlock);
- if (item == null)
- return "";
-
- HudRequest request = new HudRequest(item, target, player);
- StringBuilder text = new StringBuilder(SlimeHUD.getTranslationManager().getItemName(player, item))
- .append(" ")
- .append(ChatColor.translateAlternateColorCodes('&',
- SlimeHUD.getHudController().processRequest(request)));
-
- return text.toString();
- }
-
/**
* Called every waila.tick-rate
ticks
*/
@Override
public void run() {
+ updateFacing();
+
if (isPaused()) {
return;
}
@@ -113,6 +98,32 @@ public void run() {
}
+ private void updateFacing() {
+ Block targetBlock = player.getTargetBlockExact(5);
+ if (targetBlock == null) {
+ clearFacing();
+ return;
+ }
+
+ SlimefunItem item = BlockStorage.check(targetBlock);
+ if (item == null) {
+ clearFacing();
+ return;
+ }
+
+ Location target = targetBlock.getLocation();
+ HudRequest request = new HudRequest(item, target, player);
+ facingBlock = SlimeHUD.getTranslationManager().getItemName(player, item);
+ facingBlockInfo = SlimeHUD.getHudController().processRequest(request);
+ facing = ChatColor.translateAlternateColorCodes('&', facingBlock + (facingBlockInfo.isEmpty() ? "" : " &7| " + facingBlockInfo));
+ }
+
+ private void clearFacing() {
+ facingBlock = "";
+ facingBlockInfo = "";
+ facing = "";
+ }
+
public void setPaused(boolean paused) {
setVisible(!previousFacing.equals("") && !paused);
this.paused = paused;
From 29e5ea2451022ac8959f2e67ff80db3cf01d6fb9 Mon Sep 17 00:00:00 2001
From: SchnTgaiSpock
Date: Wed, 28 Aug 2024 18:20:39 -0400
Subject: [PATCH 2/2] bump pom version
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 7c6c664..a0fd7e1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
io.github.schntgaispock.slimehud
SlimeHUD
- 1.2.7
+ 1.3.0
17