implement command teleporting to a player's last known logout location (#2505)

* implement /offlinetp command, teleports to a player's last known logout location

* send a message to /tp user when they try teleporting to an offline player

* getHidden is now false, you are no longer able to teleport to offline players using offline tp

* change /offlinetp to /tpoffline to match essentialsx conventions
This commit is contained in:
latiku 2020-03-30 23:35:23 -04:00 committed by GitHub
parent dbc0562fb0
commit 89743f9900
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 2 deletions

View File

@ -4,8 +4,10 @@ import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.Console;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import java.util.Collections;
@ -26,10 +28,16 @@ public class Commandtp extends EssentialsCommand {
throw new NotEnoughArgumentsException();
case 1:
final User player = getPlayer(server, user, args, 0);
final User player = getPlayer(server, user, args, 0, false, true);
if (!player.isTeleportEnabled()) {
throw new Exception(tl("teleportDisabled", player.getDisplayName()));
}
if (!player.getBase().isOnline() && user.isAuthorized("essentials.tpoffline")) {
throw new Exception(tl("teleportOffline", player.getDisplayName()));
}
if (user.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + player.getWorld().getName())) {
throw new Exception(tl("noPerm", "essentials.worlds." + player.getWorld().getName()));
}

View File

@ -0,0 +1,35 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.event.player.PlayerTeleportEvent;
import static com.earth2me.essentials.I18n.tl;
public class Commandtpoffline extends EssentialsCommand {
public Commandtpoffline() {
super("tpoffline");
}
@Override
public void run(final Server server, final User user, final String label, final String[] args) throws Exception {
switch (args.length) {
case 0:
throw new NotEnoughArgumentsException();
default:
final User target = getPlayer(server, args, 0, true, true);
final Location logout = target.getLogoutLocation();
if (user.getWorld() != logout.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + logout.getWorld().getName())) {
throw new Exception(tl("noPerm", "essentials.worlds." + logout.getWorld().getName()));
}
user.sendMessage(tl("teleporting", logout.getWorld().getName(), logout.getBlockX(), logout.getBlockY(), logout.getBlockZ()));
user.getTeleport().now(logout, false, PlayerTeleportEvent.TeleportCause.COMMAND);
}
}
}

View File

@ -82,7 +82,7 @@ public abstract class EssentialsCommand implements IEssentialsCommand {
return getPlayer(server, null, args, pos, getHidden, getOffline);
}
private User getPlayer(final Server server, final User sourceUser, final String[] args, final int pos, boolean getHidden, final boolean getOffline) throws PlayerNotFoundException, NotEnoughArgumentsException {
User getPlayer(final Server server, final User sourceUser, final String[] args, final int pos, boolean getHidden, final boolean getOffline) throws PlayerNotFoundException, NotEnoughArgumentsException {
if (args.length <= pos) {
throw new NotEnoughArgumentsException();
}

View File

@ -533,6 +533,7 @@ teleportRequestSpecificCancelled=\u00a76Outstanding teleport request with\u00a7c
teleportRequestTimeoutInfo=\u00a76This request will timeout after\u00a7c {0} seconds\u00a76.
teleportTop=\u00a76Teleporting to top.
teleportToPlayer=\u00a76Teleporting to \u00a7c{0}\u00a76.
teleportOffline=\u00a76The player \u00a7c{0}\u00a76 is currently offline. You are able to teleport to them using /otp.
tempbanExempt=\u00a74You may not tempban that player.
tempbanExemptOffline=\u00a74You may not tempban offline players.
tempbanJoin=You are banned from this server for {0}. Reason: {1}

View File

@ -296,6 +296,10 @@ commands:
description: May death rain upon them.
usage: /<command> [player]
aliases: [enuke]
tpoffline:
description: Teleport to a player's last known logout location
usage: /<command> <player>
aliases: [otp, offlinetp, tpoff, tpoffline]
pay:
description: Pays another player from your balance.
usage: /<command> <player> <amount>