mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-05 12:02:53 +00:00

Adds `/tpr` and `/settpr` commands, which respectively allow you to teleport randomly or set teleportation parameters. Server owners are expected to set the center with `/settpr` before players can use `/tpr`. They can also set the minimum and maximum range to be teleported from the center (default 0-1000). Also includes an event where plugins can adjust or cancel the teleport. Closes #3154.
43 lines
1.5 KiB
Java
43 lines
1.5 KiB
Java
package com.earth2me.essentials.commands;
|
|
|
|
import com.earth2me.essentials.RandomTeleport;
|
|
import com.earth2me.essentials.User;
|
|
import org.bukkit.Server;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
|
public class Commandsettpr extends EssentialsCommand {
|
|
public Commandsettpr() {
|
|
super("settpr");
|
|
}
|
|
|
|
@Override
|
|
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception {
|
|
RandomTeleport randomTeleport = ess.getRandomTeleport();
|
|
randomTeleport.getCachedLocations().clear();
|
|
if (args.length == 0 || "center".equalsIgnoreCase(args[0])) {
|
|
randomTeleport.setCenter(user.getLocation());
|
|
user.sendMessage(tl("settpr"));
|
|
} else if (args.length > 1) {
|
|
if ("minrange".equalsIgnoreCase(args[0])) {
|
|
randomTeleport.setMinRange(Double.parseDouble(args[1]));
|
|
} else if ("maxrange".equalsIgnoreCase(args[0])) {
|
|
randomTeleport.setMaxRange(Double.parseDouble(args[1]));
|
|
}
|
|
user.sendMessage(tl("settprValue", args[0].toLowerCase(), args[1].toLowerCase()));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
|
|
if (args.length == 1) {
|
|
return Arrays.asList("center", "minrange", "maxrange");
|
|
}
|
|
return Collections.emptyList();
|
|
}
|
|
}
|