Add gradle publishing config, remove remaining player usage

This commit is contained in:
PiggyPiglet
2026-01-24 19:29:13 +08:00
parent 7111fef559
commit 400857f18b
7 changed files with 98 additions and 32 deletions

View File

@@ -7,7 +7,7 @@ plugins {
} }
group = "at.helpch" group = "at.helpch"
version = "1.0.0-experifuckingmental" version = "1.0.0"
description = "An awesome placeholder provider!" description = "An awesome placeholder provider!"
@@ -37,8 +37,44 @@ java {
disableAutoTargetJvm() disableAutoTargetJvm()
} }
val javaComponent: SoftwareComponent = components["java"]
tasks { tasks {
processResources { processResources {
eachFile { expand("version" to project.version) } eachFile { expand("version" to project.version) }
} }
withType<ShadowJar> {
archiveClassifier.set("")
relocate("org.yaml.snakeyaml", "at.helpch.placeholderapi.libs.yaml")
exclude("META-INF/versions/**")
}
publishing {
publications {
create<MavenPublication>("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()))
} }

View File

@@ -209,7 +209,7 @@ public final class PlaceholderAPI {
* @param text Text to parse the placeholders in * @param text Text to parse the placeholders in
* @return The text containing the parsed relational placeholders * @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); final Matcher matcher = RELATIONAL_PLACEHOLDER_PATTERN.matcher(text);
while (matcher.find()) { while (matcher.find()) {
@@ -248,7 +248,7 @@ public final class PlaceholderAPI {
* @param text text to parse the placeholder values to * @param text text to parse the placeholder values to
* @return The text containing the parsed relational placeholders * @return The text containing the parsed relational placeholders
*/ */
public static List<String> setRelationalPlaceholders(Player one, Player two, List<String> text) { public static List<String> setRelationalPlaceholders(PlayerRef one, PlayerRef two, List<String> text) {
return text.stream().map(line -> setRelationalPlaceholders(one, two, line)) return text.stream().map(line -> setRelationalPlaceholders(one, two, line))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }

View File

@@ -107,5 +107,4 @@ public abstract class PlaceholderCommand {
@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) { @NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions) {
} }
} }

View File

@@ -30,6 +30,7 @@ import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import at.helpch.placeholderapi.commands.PlaceholderCommand; import at.helpch.placeholderapi.commands.PlaceholderCommand;
import at.helpch.placeholderapi.expansion.PlaceholderExpansion; import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
import com.hypixel.hytale.server.core.Message; 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.command.system.CommandSender;
import com.hypixel.hytale.server.core.entity.entities.Player; import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.universe.PlayerRef; import com.hypixel.hytale.server.core.universe.PlayerRef;
@@ -99,20 +100,24 @@ public final class CommandParse extends PlaceholderCommand {
return; return;
} }
Player player; PlayerRef player;
if ("me".equalsIgnoreCase(params.get(0))) { if ("me".equalsIgnoreCase(params.getFirst())) {
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))); 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!"); // Msg.msg(sender, "&cYou must be a player to use &7me&c as a target!");
return; return;
} }
player = ((Player) sender); if (sender instanceof Player) {
player = ((Player) sender).getPlayerRef();
}
player = (PlayerRef) sender;
} else if ("--null".equalsIgnoreCase(params.get(0))) { } else if ("--null".equalsIgnoreCase(params.get(0))) {
player = null; player = null;
} else { } 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) { if (target == null) {
sender.sendMessage(Message.raw("Failed to find player: ").color(Color.RED).insert(Message.raw(params.get(0)).color(Color.WHITE))); 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)); // Msg.msg(sender, "&cFailed to find player: &7" + params.get(0));
@@ -152,10 +157,10 @@ public final class CommandParse extends PlaceholderCommand {
return; return;
} }
Player playerOne; PlayerRef playerOne;
if ("me".equalsIgnoreCase(params.get(0))) { 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) sender.sendMessage(Message.raw("You must be a player to use ").color(Color.RED)
.insert(Message.raw("me").color(Color.GRAY)) .insert(Message.raw("me").color(Color.GRAY))
.insert(Message.raw(" as a target!").color(Color.RED))); .insert(Message.raw(" as a target!").color(Color.RED)));
@@ -163,9 +168,13 @@ public final class CommandParse extends PlaceholderCommand {
return; return;
} }
playerOne = ((Player) sender); if (sender instanceof Player) {
playerOne = ((Player) sender).getPlayerRef();
}
playerOne = (PlayerRef) sender;
} else { } 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()*/) { if (playerOne == null/* || !playerOne.isOnline()*/) {
@@ -174,18 +183,22 @@ public final class CommandParse extends PlaceholderCommand {
return; return;
} }
Player playerTwo; PlayerRef playerTwo;
if ("me".equalsIgnoreCase(params.get(1))) { 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))); 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!"); // Msg.msg(sender, "&cYou must be a player to use &7me&c as a target!");
return; return;
} }
playerTwo = ((Player) sender); if (sender instanceof Player) {
playerTwo = ((Player) sender).getPlayerRef();
}
playerTwo = (PlayerRef) sender;
} else { } 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()*/) { if (playerTwo == null/* || !playerTwo.isOnline()*/) {
@@ -195,7 +208,7 @@ public final class CommandParse extends PlaceholderCommand {
} }
final String message = PlaceholderAPI final String message = PlaceholderAPI
.setRelationalPlaceholders((Player) playerOne, (Player) playerTwo, .setRelationalPlaceholders(playerOne, playerTwo,
String.join(" ", params.subList(2, params.size()))); String.join(" ", params.subList(2, params.size())));
sender.sendMessage(Message.raw(message)); sender.sendMessage(Message.raw(message));
@@ -260,20 +273,20 @@ public final class CommandParse extends PlaceholderCommand {
@Nullable @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); // Player target = Universe.get().getPlayerByUsername(name, NameMatching.EXACT);
final Optional<Player> target = world.getPlayers().stream().filter(player -> player.getDisplayName().equals(name)).findAny(); // final Optional<Player> 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);
// //
// return target.hasPlayedBefore() ? target : null; // if (target.isEmpty()) {
return null; // // Not the best option, but Spigot doesn't offer a good replacement (as usual)
} //// target = Bukkit.getOfflinePlayer(name);
////
return target.get(); //// return target.hasPlayedBefore() ? target : null;
// return null;
// }
//
// return target.get();
return Universe.get().getPlayerByUsername(name, NameMatching.EXACT);
} }
} }

View File

@@ -26,8 +26,13 @@ import java.util.regex.Pattern;
import at.helpch.placeholderapi.PlaceholderAPIPlugin; import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import at.helpch.placeholderapi.PlaceholderHook; 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.HytaleServer;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.plugin.PluginBase; 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.ApiStatus;
import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull; 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<EntityStore> ref = target.getReference();
if (ref == null || !ref.isValid()) {
return null;
}
final Store<EntityStore> store = ref.getStore();
return store.isInThread() ? store.getComponent(ref, Player.getComponentType()) : null;
}
} }

View File

@@ -21,6 +21,7 @@
package at.helpch.placeholderapi.expansion; package at.helpch.placeholderapi.expansion;
import com.hypixel.hytale.server.core.entity.entities.Player; 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} * 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_<b>identifier</b>%) * @param identifier The text right after the expansion's name (%expansion_<b>identifier</b>%)
* @return Parsed String from the expansion. * @return Parsed String from the expansion.
*/ */
String onPlaceholderRequest(Player one, Player two, String identifier); String onPlaceholderRequest(PlayerRef one, PlayerRef two, String identifier);
} }

View File

@@ -117,7 +117,7 @@ public final class CharsReplacer implements Replacer {
continue; continue;
} }
final String replacement = placeholder.onRequest(player, parametersString); final String replacement = placeholder.onPlaceholderRequest(player, parametersString);
if (replacement == null) { if (replacement == null) {
builder.append(closure.head).append(identifierString); builder.append(closure.head).append(identifierString);