Skip to content

Commit 40b73e6

Browse files
created some more argument types
1 parent 4d2c561 commit 40b73e6

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

src/main/java/com/datasiqn/commandcore/argument/type/ArgumentType.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
import com.datasiqn.commandcore.command.CommandContext;
66
import com.datasiqn.resultapi.None;
77
import com.datasiqn.resultapi.Result;
8+
import org.bukkit.Bukkit;
9+
import org.bukkit.Location;
810
import org.bukkit.Material;
11+
import org.bukkit.World;
12+
import org.bukkit.entity.EntityType;
913
import org.bukkit.entity.Player;
14+
import org.bukkit.loot.LootTable;
1015
import org.bukkit.util.Vector;
1116
import org.jetbrains.annotations.Contract;
1217
import org.jetbrains.annotations.NotNull;
@@ -64,6 +69,33 @@ public interface ArgumentType<T> {
6469
*/
6570
ArgumentType<Vector> VECTOR = new VectorArgumentType();
6671

72+
/**
73+
* {@code ArgumentType} that represents a loaded world
74+
*/
75+
ArgumentType<World> WORLD = new WorldArgumentType();
76+
77+
/**
78+
* {@code ArgumentType} that represents an entity
79+
*/
80+
ArgumentType<EntityType> ENTITY = new EnumArgumentType<>(EntityType.class, "entity");
81+
82+
/**
83+
* {@code ArgumentType} that represents an entity that is living
84+
*/
85+
ArgumentType<EntityType> LIVING_ENTITY = new FilteredEnumArgumentType<>(EntityType.class, EntityType::isAlive, "living entity");
86+
87+
/**
88+
* {@code ArgumentType} that represents an entity that can be spawned using {@link org.bukkit.World#spawnEntity(Location, EntityType)}.
89+
* <br>
90+
* This is the same as the {@code ENTITY} argument type, except that this omits the {@code Player} entity type
91+
*/
92+
ArgumentType<EntityType> SPAWNABLE_ENTITY = new FilteredEnumArgumentType<>(EntityType.class, entityType -> entityType != EntityType.PLAYER, "living entity");
93+
94+
/**
95+
* {@code ArgumentType} that represents a loot table
96+
*/
97+
ArgumentType<LootTable> LOOT_TABLE = new LootTableArgumentType();
98+
6799
/**
68100
* {@code ArgumentType} that represents a material
69101
*/
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.datasiqn.commandcore.argument.type;
2+
3+
import com.datasiqn.commandcore.command.CommandContext;
4+
import com.datasiqn.resultapi.None;
5+
import com.datasiqn.resultapi.Result;
6+
import org.bukkit.loot.LootTable;
7+
import org.bukkit.loot.LootTables;
8+
import org.jetbrains.annotations.NotNull;
9+
10+
import java.util.Arrays;
11+
import java.util.List;
12+
import java.util.stream.Collectors;
13+
14+
class LootTableArgumentType implements SimpleArgumentType<LootTable> {
15+
private final List<String> tabCompletes = Arrays.stream(LootTables.values()).map(LootTables::name).collect(Collectors.toList());
16+
17+
@Override
18+
public @NotNull String getTypeName() {
19+
return "loot table";
20+
}
21+
22+
@Override
23+
public @NotNull Result<LootTable, None> parseWord(String word) {
24+
return Result.resolve(() -> LootTables.valueOf(word.toUpperCase())).map(LootTables::getLootTable);
25+
}
26+
27+
@Override
28+
public @NotNull List<String> getTabComplete(@NotNull CommandContext context) {
29+
return tabCompletes;
30+
}
31+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.datasiqn.commandcore.argument.type;
2+
3+
import com.datasiqn.commandcore.command.CommandContext;
4+
import com.datasiqn.resultapi.None;
5+
import com.datasiqn.resultapi.Result;
6+
import org.bukkit.Bukkit;
7+
import org.bukkit.World;
8+
import org.jetbrains.annotations.NotNull;
9+
10+
import java.util.List;
11+
import java.util.stream.Collectors;
12+
13+
class WorldArgumentType implements SimpleArgumentType<World> {
14+
@Override
15+
public @NotNull String getTypeName() {
16+
return "world";
17+
}
18+
19+
@Override
20+
public @NotNull Result<World, None> parseWord(String word) {
21+
return Result.ofNullable(Bukkit.getWorld(word), None.NONE);
22+
}
23+
24+
@Override
25+
public @NotNull List<String> getTabComplete(@NotNull CommandContext context) {
26+
return Bukkit.getWorlds().stream().map(World::getName).collect(Collectors.toList());
27+
}
28+
}

0 commit comments

Comments
 (0)