forked from John-Paul-R/Essential-Commands
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWarpTpCommand.java
More file actions
66 lines (53 loc) · 2.36 KB
/
Copy pathWarpTpCommand.java
File metadata and controls
66 lines (53 loc) · 2.36 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
65
66
package com.fibermc.essentialcommands.commands;
import com.fibermc.essentialcommands.ManagerLocator;
import com.fibermc.essentialcommands.teleportation.PlayerTeleporter;
import com.fibermc.essentialcommands.text.ECText;
import com.fibermc.essentialcommands.text.TextFormatType;
import com.fibermc.essentialcommands.types.WarpLocation;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.level.ServerPlayer;
public class WarpTpCommand implements Command<CommandSourceStack> {
public WarpTpCommand() {}
@Override
public int run(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
ServerPlayer senderPlayer = context.getSource().getPlayer();
exec(context, senderPlayer);
return SINGLE_SUCCESS;
}
private void exec(
CommandContext<CommandSourceStack> context,
ServerPlayer targetPlayer) throws CommandSyntaxException
{
var worldDataManager = ManagerLocator.getInstance().getWorldDataManager();
var senderPlayer = context.getSource().getPlayerOrException();
var ecText = ECText.access(senderPlayer);
String warpName = StringArgumentType.getString(context, "warp_name");
var warpNameText = ecText.accent(warpName);
WarpLocation loc = worldDataManager.getWarp(warpName);
if (loc == null) {
throw CommandUtil.createSimpleException(ecText.getText(
"cmd.warp.tp.error.not_found",
TextFormatType.Error,
warpNameText));
}
if (!loc.hasPermission(senderPlayer)) {
throw CommandUtil.createSimpleException(ecText.getText(
"cmd.warp.tp.error.permission",
TextFormatType.Error,
warpNameText));
}
// Teleport & chat message
PlayerTeleporter.requestTeleport(
targetPlayer,
loc,
ecText.getText("cmd.warp.location_name", warpNameText));
}
public int runOther(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
exec(context, NicknameTargetResolver.getPlayer(context, "target_player"));
return 0;
}
}