mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-06 20:43:11 +00:00

This PR adds support for players to receive multiple teleport requests, which are queued and can be managed independently of one another. All commands should retain their current behavior but have some new additions; * `/tpaccept`: now allows you to specify a player or `*` to accept a specific player's or all players' teleport request(s) respectively. - Using a wildcard will only accept all tpahere requests, as players can't teleport to multiple places simultaneously. * `/tpdeny`: now allows you to specify a player or `*` to deny a specific player's or all players' teleport request(s) respectively. This PR also adds a new setting for the maximum amount of pending TPA requests a user can have at once. ```yml # The maximum amount of simultaneous tpa requests that can be pending for any given user. # Once at this threshold, any new tpa requests will bump the oldest tpa requests out of queue. # Defaults to 5. tpa-max-amount: 5 ``` Closes #3769 Closes #1550 Co-authored-by: Mariell Hoversholm <proximyst@proximy.st> Co-authored-by: MD <1917406+mdcfe@users.noreply.github.com>
72 lines
2.7 KiB
Java
72 lines
2.7 KiB
Java
package com.earth2me.essentials.commands;
|
|
|
|
import com.earth2me.essentials.CommandSource;
|
|
import com.earth2me.essentials.User;
|
|
import net.ess3.api.events.TPARequestEvent;
|
|
import org.bukkit.Server;
|
|
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
public class Commandtpaall extends EssentialsCommand {
|
|
public Commandtpaall() {
|
|
super("tpaall");
|
|
}
|
|
|
|
@Override
|
|
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
|
if (args.length < 1) {
|
|
if (sender.isPlayer()) {
|
|
tpaAll(sender, ess.getUser(sender.getPlayer()));
|
|
return;
|
|
}
|
|
throw new NotEnoughArgumentsException();
|
|
}
|
|
|
|
final User target = getPlayer(server, sender, args, 0);
|
|
tpaAll(sender, target);
|
|
}
|
|
|
|
private void tpaAll(final CommandSource sender, final User target) {
|
|
sender.sendMessage(tl("teleportAAll"));
|
|
for (final User player : ess.getOnlineUsers()) {
|
|
if (target == player) {
|
|
continue;
|
|
}
|
|
if (!player.isTeleportEnabled()) {
|
|
continue;
|
|
}
|
|
if (sender.getSender().equals(target.getBase()) && target.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !target.isAuthorized("essentials.worlds." + target.getWorld().getName())) {
|
|
continue;
|
|
}
|
|
|
|
try {
|
|
final TPARequestEvent tpaEvent = new TPARequestEvent(sender, player, true);
|
|
ess.getServer().getPluginManager().callEvent(tpaEvent);
|
|
if (tpaEvent.isCancelled()) {
|
|
sender.sendMessage(tl("teleportRequestCancelled", player.getDisplayName()));
|
|
continue;
|
|
}
|
|
player.requestTeleport(target, true);
|
|
player.sendMessage(tl("teleportHereRequest", target.getDisplayName()));
|
|
player.sendMessage(tl("typeTpaccept"));
|
|
if (ess.getSettings().getTpaAcceptCancellation() != 0) {
|
|
player.sendMessage(tl("teleportRequestTimeoutInfo", ess.getSettings().getTpaAcceptCancellation()));
|
|
}
|
|
} catch (final Exception ex) {
|
|
ess.showError(sender, ex, getName());
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
|
|
if (args.length == 1) {
|
|
return getPlayers(server, sender);
|
|
} else {
|
|
return Collections.emptyList();
|
|
}
|
|
}
|
|
}
|