forked from EssentialsX/Essentials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandtp.java
More file actions
165 lines (154 loc) · 9.78 KB
/
Commandtp.java
File metadata and controls
165 lines (154 loc) · 9.78 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.Console;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import net.ess3.api.TranslatableException;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public class Commandtp extends EssentialsCommand {
public Commandtp() {
super("tp");
}
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
final CompletableFuture<Boolean> future = getNewExceptionFuture(user.getSource(), commandLabel);
switch (args.length) {
case 0:
throw new NotEnoughArgumentsException();
case 1:
final User player = getPlayer(server, user, args, 0, false, true);
if (!player.isTeleportEnabled()) {
throw new TranslatableException("teleportDisabled", player.getDisplayName());
}
if (!player.getBase().isOnline()) {
if (user.isAuthorized("essentials.tpoffline")) {
throw new TranslatableException("teleportOffline", player.getDisplayName());
}
throw new PlayerNotFoundException();
}
if (user.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + player.getWorld().getName())) {
throw new TranslatableException("noPerm", "essentials.worlds." + player.getWorld().getName());
}
final Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user);
user.getAsyncTeleport().teleport(player.getBase(), charge, TeleportCause.COMMAND, future);
throw new NoChargeException();
case 3:
if (!user.isAuthorized("essentials.tp.position")) {
throw new TranslatableException("noPerm", "essentials.tp.position");
}
final double x2 = args[0].startsWith("~") ? user.getLocation().getX() + (args[0].length() > 1 ? Double.parseDouble(args[0].substring(1)) : 0) : Double.parseDouble(args[0]);
final double y2 = args[1].startsWith("~") ? user.getLocation().getY() + (args[1].length() > 1 ? Double.parseDouble(args[1].substring(1)) : 0) : Double.parseDouble(args[1]);
final double z2 = args[2].startsWith("~") ? user.getLocation().getZ() + (args[2].length() > 1 ? Double.parseDouble(args[2].substring(1)) : 0) : Double.parseDouble(args[2]);
if (x2 > 30000000 || y2 > 30000000 || z2 > 30000000 || x2 < -30000000 || y2 < -30000000 || z2 < -30000000) {
throw new NotEnoughArgumentsException(user.playerTl("teleportInvalidLocation"));
}
final Location locpos = new Location(user.getWorld(), x2, y2, z2, user.getLocation().getYaw(), user.getLocation().getPitch());
user.getAsyncTeleport().now(locpos, false, TeleportCause.COMMAND, future);
future.thenAccept(success -> {
if (success) {
user.sendTl("teleporting", locpos.getWorld().getName(), locpos.getBlockX(), locpos.getBlockY(), locpos.getBlockZ());
}
});
break;
case 4:
if (!user.isAuthorized("essentials.tp.others")) {
throw new TranslatableException("noPerm", "essentials.tp.others");
}
if (!user.isAuthorized("essentials.tp.position")) {
throw new TranslatableException("noPerm", "essentials.tp.position");
}
final User target2 = getPlayer(server, user, args, 0);
final double x = args[1].startsWith("~") ? target2.getLocation().getX() + (args[1].length() > 1 ? Double.parseDouble(args[1].substring(1)) : 0) : Double.parseDouble(args[1]);
final double y = args[2].startsWith("~") ? target2.getLocation().getY() + (args[2].length() > 1 ? Double.parseDouble(args[2].substring(1)) : 0) : Double.parseDouble(args[2]);
final double z = args[3].startsWith("~") ? target2.getLocation().getZ() + (args[3].length() > 1 ? Double.parseDouble(args[3].substring(1)) : 0) : Double.parseDouble(args[3]);
if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000) {
throw new NotEnoughArgumentsException(user.playerTl("teleportInvalidLocation"));
}
final Location locposother = new Location(target2.getWorld(), x, y, z, target2.getLocation().getYaw(), target2.getLocation().getPitch());
if (!target2.isTeleportEnabled()) {
throw new TranslatableException("teleportDisabled", target2.getDisplayName());
}
user.sendTl("teleporting", locposother.getWorld().getName(), locposother.getBlockX(), locposother.getBlockY(), locposother.getBlockZ());
target2.getAsyncTeleport().now(locposother, false, TeleportCause.COMMAND, future);
future.thenAccept(success -> {
if (success) {
target2.sendTl("teleporting", locposother.getWorld().getName(), locposother.getBlockX(), locposother.getBlockY(), locposother.getBlockZ());
}
});
break;
case 2:
default:
if (!user.isAuthorized("essentials.tp.others")) {
throw new TranslatableException("noPerm", "essentials.tp.others");
}
final User target = getPlayer(server, user, args, 0);
final User toPlayer = getPlayer(server, user, args, 1);
if (!target.isTeleportEnabled()) {
throw new TranslatableException("teleportDisabled", target.getDisplayName());
}
if (!toPlayer.isTeleportEnabled()) {
throw new TranslatableException("teleportDisabled", toPlayer.getDisplayName());
}
if (target.getWorld() != toPlayer.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + toPlayer.getWorld().getName())) {
throw new TranslatableException("noPerm", "essentials.worlds." + toPlayer.getWorld().getName());
}
target.sendTl("teleportAtoB", user.getDisplayName(), toPlayer.getDisplayName());
target.getAsyncTeleport().now(toPlayer.getBase(), false, TeleportCause.COMMAND, future);
break;
}
}
@Override
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
if (args.length < 2) {
throw new NotEnoughArgumentsException();
}
final User target = getPlayer(server, args, 0, true, false);
if (args.length == 2) {
final User toPlayer = getPlayer(server, args, 1, true, false);
target.sendTl("teleportAtoB", Console.displayName(), toPlayer.getDisplayName());
target.getAsyncTeleport().now(toPlayer.getBase(), false, TeleportCause.COMMAND, getNewExceptionFuture(sender, commandLabel));
} else if (args.length > 3) {
final double x = args[1].startsWith("~") ? target.getLocation().getX() + (args[1].length() > 1 ? Double.parseDouble(args[1].substring(1)) : 0) : Double.parseDouble(args[1]);
final double y = args[2].startsWith("~") ? target.getLocation().getY() + (args[2].length() > 1 ? Double.parseDouble(args[2].substring(1)) : 0) : Double.parseDouble(args[2]);
final double z = args[3].startsWith("~") ? target.getLocation().getZ() + (args[3].length() > 1 ? Double.parseDouble(args[3].substring(1)) : 0) : Double.parseDouble(args[3]);
if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000) {
throw new NotEnoughArgumentsException(sender.tl("teleportInvalidLocation"));
}
final Location loc = new Location(target.getWorld(), x, y, z, target.getLocation().getYaw(), target.getLocation().getPitch());
sender.sendTl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
final CompletableFuture<Boolean> future = getNewExceptionFuture(sender, commandLabel);
target.getAsyncTeleport().now(loc, false, TeleportCause.COMMAND, future);
future.thenAccept(success -> {
if (success) {
target.sendTl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
}
});
} else {
throw new NotEnoughArgumentsException();
}
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
// Don't handle coords
if (args.length == 1 || (args.length == 2 && user.isAuthorized("essentials.tp.others"))) {
return getPlayers(user);
} else {
return Collections.emptyList();
}
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
// Don't handle coords
if (args.length == 1 || args.length == 2) {
return getPlayers(sender);
} else {
return Collections.emptyList();
}
}
}