|
1 | 1 | package org.skriptlang.skript.bukkit.command.custom; |
2 | 2 |
|
3 | 3 | import ch.njol.skript.Skript; |
| 4 | +import ch.njol.skript.classes.ClassInfo; |
| 5 | +import ch.njol.skript.classes.registry.RegistryClassInfo; |
4 | 6 | import ch.njol.skript.lang.Literal; |
5 | 7 | import ch.njol.skript.lang.ParseContext; |
6 | 8 | import ch.njol.skript.lang.SkriptParser; |
|
20 | 22 | import com.mojang.brigadier.suggestion.SuggestionsBuilder; |
21 | 23 | import io.papermc.paper.command.brigadier.argument.ArgumentTypes; |
22 | 24 | import io.papermc.paper.command.brigadier.argument.CustomArgumentType; |
| 25 | +import io.papermc.paper.registry.RegistryKey; |
| 26 | +import org.bukkit.GameMode; |
| 27 | +import org.bukkit.World; |
| 28 | +import org.bukkit.block.BlockState; |
| 29 | +import org.bukkit.block.data.BlockData; |
23 | 30 | import org.bukkit.entity.Entity; |
24 | 31 | import org.bukkit.entity.Player; |
| 32 | +import org.bukkit.inventory.ItemStack; |
25 | 33 | import org.jetbrains.annotations.ApiStatus; |
26 | 34 | import org.jetbrains.annotations.NotNull; |
| 35 | +import org.jetbrains.annotations.Nullable; |
27 | 36 |
|
28 | 37 | import java.util.Iterator; |
29 | 38 | import java.util.Locale; |
30 | 39 | import java.util.Map; |
| 40 | +import java.util.UUID; |
31 | 41 | import java.util.concurrent.CompletableFuture; |
32 | 42 | import java.util.function.Function; |
33 | 43 | import java.util.function.Supplier; |
@@ -69,7 +79,7 @@ public NativeArgumentData(Function<ArgumentData<?>, ArgumentType<?>> mapper) { |
69 | 79 | /** |
70 | 80 | * Pre-defined mappings of types that are acceptable to map to other native argument types. |
71 | 81 | */ |
72 | | - public static final Map<Class<?>, NativeArgumentData> ARGUMENT_TYPE_MAPPINGS = Map.of( |
| 82 | + private static final Map<Class<?>, NativeArgumentData> ARGUMENT_TYPE_MAPPINGS = Map.of( |
73 | 83 | Boolean.class, new NativeArgumentData(ignored -> BoolArgumentType.bool()), |
74 | 84 | Long.class, new NativeArgumentData(false, true, data -> { |
75 | 85 | Long min = (Long) data.min(); |
@@ -100,9 +110,38 @@ Number.class, new NativeArgumentData(false, true, data -> { |
100 | 110 | Player.class, new NativeArgumentData(true, false, data -> |
101 | 111 | data.isSingle() ? ArgumentTypes.player() : ArgumentTypes.players()), |
102 | 112 | Entity.class, new NativeArgumentData(true, false, data -> |
103 | | - data.isSingle() ? ArgumentTypes.entity() : ArgumentTypes.entities()) |
| 113 | + data.isSingle() ? ArgumentTypes.entity() : ArgumentTypes.entities()), |
| 114 | + GameMode.class, new NativeArgumentData(ignored -> ArgumentTypes.gameMode()), |
| 115 | + World.class, new NativeArgumentData(ignored -> ArgumentTypes.world()), |
| 116 | + UUID.class, new NativeArgumentData(ignored -> ArgumentTypes.uuid()), |
| 117 | + BlockData.class, new NativeArgumentData(ignored -> new Converted<BlockData, BlockState>() { |
| 118 | + @Override |
| 119 | + public @NotNull ArgumentType<BlockState> getNativeType() { |
| 120 | + return ArgumentTypes.blockState(); |
| 121 | + } |
| 122 | + @Override |
| 123 | + public @NotNull BlockData convert(@NotNull BlockState blockState) { |
| 124 | + return blockState.getBlockData(); |
| 125 | + } |
| 126 | + }), |
| 127 | + ItemStack.class, new NativeArgumentData(ignored -> ArgumentTypes.itemStack()) |
104 | 128 | ); |
105 | 129 |
|
| 130 | + public static @Nullable NativeArgumentData getNativeData(ClassInfo<?> classInfo) { |
| 131 | + NativeArgumentData nativeArgumentData = ARGUMENT_TYPE_MAPPINGS.get(classInfo.getC()); |
| 132 | + if (nativeArgumentData != null) { |
| 133 | + return nativeArgumentData; |
| 134 | + } |
| 135 | + if (classInfo instanceof RegistryClassInfo<?> registryClassInfo) { |
| 136 | + // TODO need to map RegistryClassInfo to RegistryKey |
| 137 | + RegistryKey<?> key = null; |
| 138 | + if (key != null) { |
| 139 | + return new NativeArgumentData(ignored -> ArgumentTypes.resource(key)); |
| 140 | + } |
| 141 | + } |
| 142 | + return null; |
| 143 | + } |
| 144 | + |
106 | 145 | private static final DynamicCommandExceptionType ERROR_PARSER_ERROR = new DynamicCommandExceptionType( |
107 | 146 | input -> new LiteralMessage((String) input)); |
108 | 147 |
|
|
0 commit comments