forked from John-Paul-R/Essential-Commands
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeleportResponseCommand.java
More file actions
53 lines (41 loc) · 2.29 KB
/
Copy pathTeleportResponseCommand.java
File metadata and controls
53 lines (41 loc) · 2.29 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
package com.fibermc.essentialcommands.commands;
import java.util.LinkedHashMap;
import java.util.UUID;
import com.fibermc.essentialcommands.playerdata.PlayerData;
import com.fibermc.essentialcommands.teleportation.TeleportRequest;
import com.fibermc.essentialcommands.text.ECText;
import com.fibermc.essentialcommands.text.TextFormatType;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.level.ServerPlayer;
public abstract class TeleportResponseCommand implements Command<CommandSourceStack> {
public int run(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
return exec(
context,
context.getSource().getPlayer(),
NicknameTargetResolver.getPlayer(context, "target_player")
);
}
public int runDefault(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
var respondingPlayer = context.getSource().getPlayerOrException();
var respondingPlayerData = PlayerData.access(respondingPlayer);
var ecText = ECText.access(respondingPlayer);
LinkedHashMap<UUID, TeleportRequest> incomingTeleportRequests = respondingPlayerData.getIncomingTeleportRequests();
if (incomingTeleportRequests.size() > 1) {
throw CommandUtil.createSimpleException(
ecText.getText("cmd.tpa_reply.error.shortcut_more_than_one", TextFormatType.Error));
} else if (incomingTeleportRequests.size() < 1) {
throw CommandUtil.createSimpleException(
ecText.getText("cmd.tpa_reply.error.shortcut_none_exist", TextFormatType.Error));
}
ServerPlayer teleportRequestSender = incomingTeleportRequests.values().stream().findFirst().get().getSenderPlayer();
if (teleportRequestSender == null) {
throw CommandUtil.createSimpleException(
ecText.getText("cmd.tpa_reply.error.no_request_from_target", TextFormatType.Error));
}
return exec(context, respondingPlayer, teleportRequestSender);
}
abstract int exec(CommandContext<CommandSourceStack> context, ServerPlayer respondingPlayer, ServerPlayer requesterPlayer);
}