mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 01:49:30 +00:00
添加关闭物品栏函数
This commit is contained in:
@@ -58,6 +58,7 @@ public class EventFunctions {
|
||||
register(CommonFunctions.SET_EXP, new SetExpFunction.FactoryImpl<>(EventConditions::fromMap));
|
||||
register(CommonFunctions.SET_LEVEL, new SetLevelFunction.FactoryImpl<>(EventConditions::fromMap));
|
||||
register(CommonFunctions.PLAY_TOTEM_ANIMATION, new PlayTotemAnimationFunction.FactoryImpl<>(EventConditions::fromMap));
|
||||
register(CommonFunctions.CLOSE_INVENTORY, new CloseInventoryFunction.FactoryImpl<>(EventConditions::fromMap));
|
||||
}
|
||||
|
||||
public static void register(Key key, FunctionFactory<Context> factory) {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package net.momirealms.craftengine.core.plugin.context.function;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.plugin.context.Condition;
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
|
||||
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelector;
|
||||
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelectors;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CloseInventoryFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> {
|
||||
private final PlayerSelector<CTX> selector;
|
||||
|
||||
public CloseInventoryFunction(List<Condition<CTX>> predicates, @Nullable PlayerSelector<CTX> selector) {
|
||||
super(predicates);
|
||||
this.selector = selector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runInternal(CTX ctx) {
|
||||
if (this.selector == null) {
|
||||
ctx.getOptionalParameter(DirectContextParameters.PLAYER).ifPresent(Player::closeInventory);
|
||||
} else {
|
||||
for (Player viewer : this.selector.get(ctx)) {
|
||||
viewer.closeInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return CommonFunctions.TITLE;
|
||||
}
|
||||
|
||||
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
|
||||
|
||||
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
|
||||
super(factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function<CTX> create(Map<String, Object> arguments) {
|
||||
return new CloseInventoryFunction<>(getPredicates(arguments), PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,4 +49,5 @@ public final class CommonFunctions {
|
||||
public static final Key SET_EXP = Key.of("craftengine:set_exp");
|
||||
public static final Key SET_LEVEL = Key.of("craftengine:set_level");
|
||||
public static final Key PLAY_TOTEM_ANIMATION = Key.of("craftengine:play_totem_animation");
|
||||
public static final Key CLOSE_INVENTORY = Key.of("craftengine:close_inventory");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user