forked from QuiltServerTools/HeyThatsMine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUntrustCommand.java
More file actions
64 lines (56 loc) · 2.53 KB
/
UntrustCommand.java
File metadata and controls
64 lines (56 loc) · 2.53 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
59
60
61
62
63
64
package com.github.fabricservertools.htm.command.subcommands;
import com.github.fabricservertools.htm.Utility;
import com.github.fabricservertools.htm.command.SubCommand;
import com.github.fabricservertools.htm.interactions.InteractionManager;
import com.github.fabricservertools.htm.interactions.TrustAction;
import com.github.fabricservertools.htm.world.data.GlobalTrustState;
import com.mojang.authlib.GameProfile;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.command.argument.GameProfileArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import java.util.Collection;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
public class UntrustCommand implements SubCommand {
@Override
public LiteralCommandNode<ServerCommandSource> build() {
return literal("untrust")
.requires(Permissions.require("htm.command.trust", true))
.then(argument("target", GameProfileArgumentType.gameProfile())
.executes(ctx -> untrust(
ctx.getSource(),
GameProfileArgumentType.getProfileArgument(ctx, "target"),
false
))
.then(literal("global")
.executes(ctx -> untrust(
ctx.getSource(),
GameProfileArgumentType.getProfileArgument(ctx, "target"),
true
))
))
.build();
}
@SuppressWarnings("SameReturnValue")
private int untrust(ServerCommandSource source, Collection<GameProfile> gameProfiles, boolean global) throws CommandSyntaxException {
ServerPlayerEntity player = source.getPlayerOrThrow();
if (global) {
for (GameProfile gameProfile : gameProfiles) {
GlobalTrustState globalTrustState = Utility.getGlobalTrustState(source.getServer());
if (globalTrustState.removeTrust(player.getUuid(), gameProfile.getId())) {
source.sendFeedback(() -> Text.translatable("text.htm.untrust", gameProfile.getName()).append(Text.translatable("text.htm.global")), false);
} else {
source.sendFeedback(() -> Text.translatable("text.htm.error.not_trusted", gameProfile.getName()).append(Text.translatable("text.htm.global")), false);
}
}
} else {
InteractionManager.pendingActions.put(player, new TrustAction(gameProfiles, true));
source.sendFeedback(() -> Text.translatable("text.htm.select"), false);
}
return 1;
}
}