-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAddNodeCommand.java
More file actions
45 lines (36 loc) · 1.84 KB
/
AddNodeCommand.java
File metadata and controls
45 lines (36 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package de.blazemcworld.fireflow.command;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import de.blazemcworld.fireflow.code.EditOrigin;
import de.blazemcworld.fireflow.messages.Messages;
import de.blazemcworld.fireflow.space.Space;
import de.blazemcworld.fireflow.util.ModeManager;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
public class AddNodeCommand {
public static void register(CommandDispatcher<ServerCommandSource> cd) {
register(cd, "add", false);
register(cd, "add?", true);
}
private static void register(CommandDispatcher<ServerCommandSource> cd, String id, boolean flag) {
cd.register(CommandManager.literal(id)
.then(CommandManager.argument("node", StringArgumentType.greedyString())
.executes(ctx -> {
ServerPlayerEntity player = CommandHelper.getPlayer(ctx.getSource());
Space space = CommandHelper.getSpace(player);
if (space == null) return Command.SINGLE_SUCCESS;
if (ModeManager.getFor(player) != ModeManager.Mode.CODE) {
Messages.sendMessage("You must be in code mode to do that!", Messages.ERROR, player);
return Command.SINGLE_SUCCESS;
}
space.editor.addNode(EditOrigin.ofPlayer(player), StringArgumentType.getString(ctx, "node"), flag);
return Command.SINGLE_SUCCESS;
})
)
);
}
}