-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCodeCommand.java
More file actions
58 lines (49 loc) · 2.6 KB
/
CodeCommand.java
File metadata and controls
58 lines (49 loc) · 2.6 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
46
47
48
49
50
51
52
53
54
55
56
57
58
package de.blazemcworld.fireflow.command;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import de.blazemcworld.fireflow.messages.Messages;
import de.blazemcworld.fireflow.space.Space;
import de.blazemcworld.fireflow.space.SpaceInfo;
import de.blazemcworld.fireflow.space.SpaceManager;
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 CodeCommand {
public static void register(CommandDispatcher<ServerCommandSource> cd) {
register(cd, "code");
register(cd, "dev");
}
private static void register(CommandDispatcher<ServerCommandSource> cd, String alias) {
cd.register(CommandManager.literal(alias)
.executes(ctx -> {
ServerPlayerEntity player = CommandHelper.getPlayer(ctx.getSource());
Space space = CommandHelper.getSpace(player);
if (!CommandHelper.isDeveloperOrOwner(player, space)) return Command.SINGLE_SUCCESS;
ModeManager.move(player, ModeManager.Mode.CODE, space);
return Command.SINGLE_SUCCESS;
})
.then(CommandManager.argument("id", IntegerArgumentType.integer())
.executes(ctx -> {
ServerPlayerEntity player = CommandHelper.getPlayer(ctx.getSource());
if (player == null) return Command.SINGLE_SUCCESS;
int id = IntegerArgumentType.getInteger(ctx, "id");
SpaceInfo info = SpaceManager.getInfo(id);
if (info == null) {
Messages.sendMessage("Could not find space with id " + id + "!", Messages.ERROR, player);
return Command.SINGLE_SUCCESS;
}
if (!info.isOwnerOrDeveloper(player.getUuid())) {
Messages.sendMessage("You are not allowed to do that!", Messages.ERROR, player);
return Command.SINGLE_SUCCESS;
}
ModeManager.move(player, ModeManager.Mode.CODE, SpaceManager.getOrLoadSpace(info));
return Command.SINGLE_SUCCESS;
})
)
);
}
}