From 400857f18b18530c7da1b03a8bf715316e0cbfb8 Mon Sep 17 00:00:00 2001 From: PiggyPiglet Date: Sat, 24 Jan 2026 19:29:13 +0800 Subject: [PATCH] Add gradle publishing config, remove remaining player usage --- build.gradle.kts | 38 ++++++++++- .../helpch/placeholderapi/PlaceholderAPI.java | 4 +- .../commands/PlaceholderCommand.java | 1 - .../commands/impl/local/CommandParse.java | 65 +++++++++++-------- .../expansion/PlaceholderExpansion.java | 17 +++++ .../placeholderapi/expansion/Relational.java | 3 +- .../replacer/CharsReplacer.java | 2 +- 7 files changed, 98 insertions(+), 32 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 56933b0..cdcb82a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } group = "at.helpch" -version = "1.0.0-experifuckingmental" +version = "1.0.0" description = "An awesome placeholder provider!" @@ -37,8 +37,44 @@ java { disableAutoTargetJvm() } +val javaComponent: SoftwareComponent = components["java"] + tasks { processResources { eachFile { expand("version" to project.version) } } + + withType { + archiveClassifier.set("") + + relocate("org.yaml.snakeyaml", "at.helpch.placeholderapi.libs.yaml") + + exclude("META-INF/versions/**") + } + + publishing { + publications { + create("maven") { + artifactId = "placeholderapi-hytale" + from(javaComponent) + } + } + + repositories { + maven { + if ("-DEV" in version.toString()) { + url = uri("https://repo.extendedclip.com/snapshots") + } else { + url = uri("https://repo.extendedclip.com/releases") + } + + credentials { + username = System.getenv("JENKINS_USER") + password = System.getenv("JENKINS_PASS") + } + } + } + } + + publish.get().setDependsOn(listOf(build.get())) } \ No newline at end of file diff --git a/src/main/java/at/helpch/placeholderapi/PlaceholderAPI.java b/src/main/java/at/helpch/placeholderapi/PlaceholderAPI.java index 499fade..1ddad4b 100644 --- a/src/main/java/at/helpch/placeholderapi/PlaceholderAPI.java +++ b/src/main/java/at/helpch/placeholderapi/PlaceholderAPI.java @@ -209,7 +209,7 @@ public final class PlaceholderAPI { * @param text Text to parse the placeholders in * @return The text containing the parsed relational placeholders */ - public static String setRelationalPlaceholders(Player one, Player two, String text) { + public static String setRelationalPlaceholders(PlayerRef one, PlayerRef two, String text) { final Matcher matcher = RELATIONAL_PLACEHOLDER_PATTERN.matcher(text); while (matcher.find()) { @@ -248,7 +248,7 @@ public final class PlaceholderAPI { * @param text text to parse the placeholder values to * @return The text containing the parsed relational placeholders */ - public static List setRelationalPlaceholders(Player one, Player two, List text) { + public static List setRelationalPlaceholders(PlayerRef one, PlayerRef two, List text) { return text.stream().map(line -> setRelationalPlaceholders(one, two, line)) .collect(Collectors.toList()); } diff --git a/src/main/java/at/helpch/placeholderapi/commands/PlaceholderCommand.java b/src/main/java/at/helpch/placeholderapi/commands/PlaceholderCommand.java index e15e792..091764f 100644 --- a/src/main/java/at/helpch/placeholderapi/commands/PlaceholderCommand.java +++ b/src/main/java/at/helpch/placeholderapi/commands/PlaceholderCommand.java @@ -107,5 +107,4 @@ public abstract class PlaceholderCommand { @NotNull @Unmodifiable final List params, @NotNull final List suggestions) { } - } diff --git a/src/main/java/at/helpch/placeholderapi/commands/impl/local/CommandParse.java b/src/main/java/at/helpch/placeholderapi/commands/impl/local/CommandParse.java index 46670fb..fb1bbcd 100644 --- a/src/main/java/at/helpch/placeholderapi/commands/impl/local/CommandParse.java +++ b/src/main/java/at/helpch/placeholderapi/commands/impl/local/CommandParse.java @@ -30,6 +30,7 @@ import at.helpch.placeholderapi.PlaceholderAPIPlugin; import at.helpch.placeholderapi.commands.PlaceholderCommand; import at.helpch.placeholderapi.expansion.PlaceholderExpansion; import com.hypixel.hytale.server.core.Message; +import com.hypixel.hytale.server.core.NameMatching; import com.hypixel.hytale.server.core.command.system.CommandSender; import com.hypixel.hytale.server.core.entity.entities.Player; import com.hypixel.hytale.server.core.universe.PlayerRef; @@ -99,20 +100,24 @@ public final class CommandParse extends PlaceholderCommand { return; } - Player player; + PlayerRef player; - if ("me".equalsIgnoreCase(params.get(0))) { - if (!(sender instanceof Player)) { + if ("me".equalsIgnoreCase(params.getFirst())) { + if (!(sender instanceof Player) && !(sender instanceof PlayerRef)) { sender.sendMessage(Message.raw("You must be a player to use ").color(Color.RED).insert(Message.raw("me").color(Color.GRAY)).insert(Message.raw(" as a target!").color(Color.RED))); // Msg.msg(sender, "&cYou must be a player to use &7me&c as a target!"); return; } - player = ((Player) sender); + if (sender instanceof Player) { + player = ((Player) sender).getPlayerRef(); + } + + player = (PlayerRef) sender; } else if ("--null".equalsIgnoreCase(params.get(0))) { player = null; } else { - final Player target = resolvePlayer(params.get(0), sender instanceof Player ? ((Player) sender).getWorld() : Universe.get().getDefaultWorld()); + final PlayerRef target = resolvePlayer(params.get(0)); if (target == null) { sender.sendMessage(Message.raw("Failed to find player: ").color(Color.RED).insert(Message.raw(params.get(0)).color(Color.WHITE))); // Msg.msg(sender, "&cFailed to find player: &7" + params.get(0)); @@ -152,10 +157,10 @@ public final class CommandParse extends PlaceholderCommand { return; } - Player playerOne; + PlayerRef playerOne; if ("me".equalsIgnoreCase(params.get(0))) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player) && !(sender instanceof PlayerRef)) { sender.sendMessage(Message.raw("You must be a player to use ").color(Color.RED) .insert(Message.raw("me").color(Color.GRAY)) .insert(Message.raw(" as a target!").color(Color.RED))); @@ -163,9 +168,13 @@ public final class CommandParse extends PlaceholderCommand { return; } - playerOne = ((Player) sender); + if (sender instanceof Player) { + playerOne = ((Player) sender).getPlayerRef(); + } + + playerOne = (PlayerRef) sender; } else { - playerOne = resolvePlayer(params.get(0), sender instanceof Player ? ((Player) sender).getWorld() : Universe.get().getDefaultWorld()); + playerOne = resolvePlayer(params.get(0)); } if (playerOne == null/* || !playerOne.isOnline()*/) { @@ -174,18 +183,22 @@ public final class CommandParse extends PlaceholderCommand { return; } - Player playerTwo; + PlayerRef playerTwo; if ("me".equalsIgnoreCase(params.get(1))) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player) && !(sender instanceof PlayerRef)) { sender.sendMessage(Message.raw("You must be a player to use ").color(Color.RED).insert(Message.raw("me").color(Color.GRAY)).insert(Message.raw(" as a target!").color(Color.RED))); // Msg.msg(sender, "&cYou must be a player to use &7me&c as a target!"); return; } - playerTwo = ((Player) sender); + if (sender instanceof Player) { + playerTwo = ((Player) sender).getPlayerRef(); + } + + playerTwo = (PlayerRef) sender; } else { - playerTwo = resolvePlayer(params.get(1), sender instanceof Player ? ((Player) sender).getWorld() : Universe.get().getDefaultWorld()); + playerTwo = resolvePlayer(params.get(1)); } if (playerTwo == null/* || !playerTwo.isOnline()*/) { @@ -195,7 +208,7 @@ public final class CommandParse extends PlaceholderCommand { } final String message = PlaceholderAPI - .setRelationalPlaceholders((Player) playerOne, (Player) playerTwo, + .setRelationalPlaceholders(playerOne, playerTwo, String.join(" ", params.subList(2, params.size()))); sender.sendMessage(Message.raw(message)); @@ -260,20 +273,20 @@ public final class CommandParse extends PlaceholderCommand { @Nullable - private Player resolvePlayer(@NotNull final String name, @NotNull final World world) { + private PlayerRef resolvePlayer(@NotNull final String name) { // Player target = Universe.get().getPlayerByUsername(name, NameMatching.EXACT); - final Optional target = world.getPlayers().stream().filter(player -> player.getDisplayName().equals(name)).findAny(); - - if (target.isEmpty()) { - // Not the best option, but Spigot doesn't offer a good replacement (as usual) -// target = Bukkit.getOfflinePlayer(name); +// final Optional target = world.getPlayers().stream().filter(player -> player.getDisplayName().equals(name)).findAny(); // -// return target.hasPlayedBefore() ? target : null; - return null; - } - - return target.get(); - +// if (target.isEmpty()) { +// // Not the best option, but Spigot doesn't offer a good replacement (as usual) +//// target = Bukkit.getOfflinePlayer(name); +//// +//// return target.hasPlayedBefore() ? target : null; +// return null; +// } +// +// return target.get(); + return Universe.get().getPlayerByUsername(name, NameMatching.EXACT); } } diff --git a/src/main/java/at/helpch/placeholderapi/expansion/PlaceholderExpansion.java b/src/main/java/at/helpch/placeholderapi/expansion/PlaceholderExpansion.java index 0975d06..d4f16e3 100644 --- a/src/main/java/at/helpch/placeholderapi/expansion/PlaceholderExpansion.java +++ b/src/main/java/at/helpch/placeholderapi/expansion/PlaceholderExpansion.java @@ -26,8 +26,13 @@ import java.util.regex.Pattern; import at.helpch.placeholderapi.PlaceholderAPIPlugin; import at.helpch.placeholderapi.PlaceholderHook; +import com.hypixel.hytale.component.Ref; +import com.hypixel.hytale.component.Store; import com.hypixel.hytale.server.core.HytaleServer; +import com.hypixel.hytale.server.core.entity.entities.Player; import com.hypixel.hytale.server.core.plugin.PluginBase; +import com.hypixel.hytale.server.core.universe.PlayerRef; +import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -526,4 +531,16 @@ public abstract class PlaceholderExpansion implements PlaceholderHook { } + @Nullable + public static Player player(@NotNull final PlayerRef target) { + final Ref ref = target.getReference(); + + if (ref == null || !ref.isValid()) { + return null; + } + + final Store store = ref.getStore(); + + return store.isInThread() ? store.getComponent(ref, Player.getComponentType()) : null; + } } diff --git a/src/main/java/at/helpch/placeholderapi/expansion/Relational.java b/src/main/java/at/helpch/placeholderapi/expansion/Relational.java index 2d8453d..ee7dedb 100644 --- a/src/main/java/at/helpch/placeholderapi/expansion/Relational.java +++ b/src/main/java/at/helpch/placeholderapi/expansion/Relational.java @@ -21,6 +21,7 @@ package at.helpch.placeholderapi.expansion; import com.hypixel.hytale.server.core.entity.entities.Player; +import com.hypixel.hytale.server.core.universe.PlayerRef; /** * Implementing this interface allows your {@link at.helpch.placeholderapi.expansion.PlaceholderExpansion PlaceholderExpansion} @@ -39,5 +40,5 @@ public interface Relational { * @param identifier The text right after the expansion's name (%expansion_identifier%) * @return Parsed String from the expansion. */ - String onPlaceholderRequest(Player one, Player two, String identifier); + String onPlaceholderRequest(PlayerRef one, PlayerRef two, String identifier); } diff --git a/src/main/java/at/helpch/placeholderapi/replacer/CharsReplacer.java b/src/main/java/at/helpch/placeholderapi/replacer/CharsReplacer.java index d0bfed8..ab9a113 100644 --- a/src/main/java/at/helpch/placeholderapi/replacer/CharsReplacer.java +++ b/src/main/java/at/helpch/placeholderapi/replacer/CharsReplacer.java @@ -117,7 +117,7 @@ public final class CharsReplacer implements Replacer { continue; } - final String replacement = placeholder.onRequest(player, parametersString); + final String replacement = placeholder.onPlaceholderRequest(player, parametersString); if (replacement == null) { builder.append(closure.head).append(identifierString);