mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-04 15:41:38 +00:00
修复全局变量解析papi
This commit is contained in:
@@ -55,7 +55,7 @@ public class GlobalVariableManager implements Manageable {
|
|||||||
@Override
|
@Override
|
||||||
public void parseObject(Pack pack, Path path, net.momirealms.craftengine.core.util.Key id, Object object) throws LocalizedException {
|
public void parseObject(Pack pack, Path path, net.momirealms.craftengine.core.util.Key id, Object object) throws LocalizedException {
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
globalVariables.put(id.value(), object.toString());
|
GlobalVariableManager.this.globalVariables.put(id.value(), object.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import net.momirealms.craftengine.core.plugin.text.minimessage.*;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public final class NetworkTextReplaceContext extends AbstractChainParameterContext {
|
public final class NetworkTextReplaceContext extends AbstractChainParameterContext implements PlayerContext {
|
||||||
private final Player player;
|
private final Player player;
|
||||||
|
|
||||||
public NetworkTextReplaceContext(Player player) {
|
public NetworkTextReplaceContext(Player player) {
|
||||||
@@ -19,6 +19,7 @@ public final class NetworkTextReplaceContext extends AbstractChainParameterConte
|
|||||||
return new NetworkTextReplaceContext(player);
|
return new NetworkTextReplaceContext(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Player player() {
|
public Player player() {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package net.momirealms.craftengine.core.plugin.context;
|
||||||
|
|
||||||
|
import net.momirealms.craftengine.core.entity.player.Player;
|
||||||
|
|
||||||
|
public interface PlayerContext {
|
||||||
|
|
||||||
|
Player player();
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class PlayerOptionalContext extends AbstractChainParameterContext implements Context {
|
public class PlayerOptionalContext extends AbstractChainParameterContext implements PlayerContext {
|
||||||
public static final PlayerOptionalContext EMPTY = new PlayerOptionalContext(null, ContextHolder.EMPTY);
|
public static final PlayerOptionalContext EMPTY = new PlayerOptionalContext(null, ContextHolder.EMPTY);
|
||||||
protected final Player player;
|
protected final Player player;
|
||||||
|
|
||||||
@@ -44,6 +44,7 @@ public class PlayerOptionalContext extends AbstractChainParameterContext impleme
|
|||||||
return new PlayerOptionalContext(player, new ContextHolder(Map.of(DirectContextParameters.PLAYER, () -> player)));
|
return new PlayerOptionalContext(player, new ContextHolder(Map.of(DirectContextParameters.PLAYER, () -> player)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Player player() {
|
public Player player() {
|
||||||
return this.player;
|
return this.player;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import net.kyori.adventure.text.minimessage.tag.Tag;
|
|||||||
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
|
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||||
|
import net.momirealms.craftengine.core.plugin.context.PlayerContext;
|
||||||
import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext;
|
import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext;
|
||||||
import net.momirealms.craftengine.core.util.AdventureHelper;
|
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -26,7 +27,7 @@ public class PlaceholderTag implements TagResolver {
|
|||||||
String rawArgument = arguments.popOr("No argument relational placeholder provided").toString();
|
String rawArgument = arguments.popOr("No argument relational placeholder provided").toString();
|
||||||
if (rawArgument.contains("<")) rawArgument = AdventureHelper.resolvePlainStringTags(rawArgument, this.context.tagResolvers());
|
if (rawArgument.contains("<")) rawArgument = AdventureHelper.resolvePlainStringTags(rawArgument, this.context.tagResolvers());
|
||||||
String placeholder = "%" + rawArgument + "%";
|
String placeholder = "%" + rawArgument + "%";
|
||||||
String parsed = this.context instanceof PlayerOptionalContext playerOptionalContext ? CraftEngine.instance().compatibilityManager().parse(playerOptionalContext.player(), placeholder) : CraftEngine.instance().compatibilityManager().parse(null, placeholder);
|
String parsed = this.context instanceof PlayerContext playerContext ? CraftEngine.instance().compatibilityManager().parse(playerContext.player(), placeholder) : CraftEngine.instance().compatibilityManager().parse(null, placeholder);
|
||||||
if (parsed.equals(placeholder)) {
|
if (parsed.equals(placeholder)) {
|
||||||
parsed = arguments.popOr("No default papi value provided").toString();
|
parsed = arguments.popOr("No default papi value provided").toString();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user