Merge pull request #2310 from pop4959/command-tpauto

Implement tpauto command
This commit is contained in:
md678685 2019-03-08 17:19:31 +00:00 committed by GitHub
commit 585f2bef07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 0 deletions

View File

@ -446,6 +446,22 @@ public abstract class UserData extends PlayerExtension implements IConf {
config.save();
}
private boolean autoTeleportEnabled;
private boolean _getAutoTeleportEnabled() {
return config.getBoolean("teleportauto", false);
}
public boolean isAutoTeleportEnabled() {
return autoTeleportEnabled;
}
public void setAutoTeleportEnabled(boolean set) {
autoTeleportEnabled = set;
config.setProperty("teleportauto", set);
config.save();
}
private List<String> ignoredPlayers;
public List<String> _getIgnoredPlayers() {

View File

@ -1,7 +1,10 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.Teleport;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import org.bukkit.Server;
import org.bukkit.event.player.PlayerTeleportEvent;
import java.util.Collections;
import java.util.List;
@ -35,6 +38,15 @@ public class Commandtpa extends EssentialsCommand {
&& player.isTpRequestHere() == false) { // Make sure the last teleport request was actually tpa and not tpahere
throw new Exception(tl("requestSentAlready", player.getDisplayName()));
}
if (player.isAutoTeleportEnabled() && !player.isIgnoredPlayer(user)) {
final Trade charge = new Trade(this.getName(), ess);
Teleport teleport = user.getTeleport();
teleport.setTpType(Teleport.TeleportType.TPA);
teleport.teleport(player.getBase(), charge, PlayerTeleportEvent.TeleportCause.COMMAND);
player.sendMessage(tl("requestAcceptedAuto", user.getDisplayName()));
user.sendMessage(tl("requestAcceptedFromAuto", player.getDisplayName()));
return;
}
if (!player.isIgnoredPlayer(user)) {
player.requestTeleport(user, false);

View File

@ -0,0 +1,41 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import org.bukkit.Server;
import static com.earth2me.essentials.I18n.tl;
public class Commandtpauto extends EssentialsToggleCommand {
public Commandtpauto() {
super("tpauto", "essentials.tpauto.others");
}
@Override
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
toggleOtherPlayers(server, sender, args);
}
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
handleToggleWithArgs(server, user, args);
}
@Override
void togglePlayer(CommandSource sender, User user, Boolean enabled) {
if (enabled == null) {
enabled = !user.isAutoTeleportEnabled();
}
user.setAutoTeleportEnabled(enabled);
user.sendMessage(enabled ? tl("autoTeleportEnabled") : tl("autoTeleportDisabled"));
if (enabled && !user.isTeleportEnabled()) {
user.sendMessage(tl("teleportationDisabledWarning"));
}
if (!sender.isPlayer() || !user.getBase().equals(sender.getPlayer())) {
sender.sendMessage(enabled ? tl("autoTeleportEnabledFor", user.getDisplayName()) : tl("autoTeleportDisabledFor", user.getDisplayName()));
}
}
}

View File

@ -19,6 +19,10 @@ antiBuildInteract=\u00a74You are not permitted to interact with\u00a7c {0}\u00a7
antiBuildPlace=\u00a74You are not permitted to place\u00a7c {0} \u00a74here.
antiBuildUse=\u00a74You are not permitted to use\u00a7c {0}\u00a74.
autoAfkKickReason=You have been kicked for idling more than {0} minutes.
autoTeleportDisabled=\u00a76You are no longer automatically approving teleport requests.
autoTeleportDisabledFor=\u00a7c{0}\u00a76 is no longer automatically approving teleport requests.
autoTeleportEnabled=\u00a76You are now automatically approving teleport requests.
autoTeleportEnabledFor=\u00a7c{0}\u00a76 is now automatically approving teleport requests.
backAfterDeath=\u00a76Use the /back command to return to your death point.
backupDisabled=\u00a74An external backup script has not been configured.
backupFinished=\u00a76Backup finished.
@ -448,7 +452,9 @@ repairEnchanted=\u00a74You are not allowed to repair enchanted items.
repairInvalidType=\u00a74This item cannot be repaired.
repairNone=\u00a74There were no items that needed repairing.
requestAccepted=\u00a76Teleport request accepted.
requestAcceptedAuto=\u00a76Automatically accepted a teleport request from {0}.
requestAcceptedFrom=\u00a7c{0} \u00a76accepted your teleport request.
requestAcceptedFromAuto=\u00a7c{0} \u00a76accepted your teleport request automatically.
requestDenied=\u00a76Teleport request denied.
requestDeniedFrom=\u00a7c{0} \u00a76denied your teleport request.
requestSent=\u00a76Request sent to\u00a7c {0}\u00a76.
@ -504,6 +510,7 @@ teleportAll=\u00a76Teleporting all players...
teleportationCommencing=\u00a76Teleportation commencing...
teleportationDisabled=\u00a76Teleportation \u00a7cdisabled\u00a76.
teleportationDisabledFor=\u00a76Teleportation \u00a7cdisabled \u00a76for \u00a7c{0}\u00a76.
teleportationDisabledWarning=\u00a76You must enable teleportation before other players can teleport to you.
teleportationEnabled=\u00a76Teleportation \u00a7cenabled\u00a76.
teleportationEnabledFor=\u00a76Teleportation \u00a7cenabled \u00a76for \u00a7c{0}\u00a76.
teleportAtoB=\u00a7c{0}\u00a76 teleported you to \u00a7c{1}\u00a76.

View File

@ -444,6 +444,10 @@ commands:
description: Teleport all online players to another player.
usage: /<command> <player>
aliases: [etpall]
tpauto:
description: Automatically accept teleportation requests.
usage: /<command> <player>
aliases: [etpauto]
tpacancel:
description: Cancel all outstanding teleport requests. Specify [player] to cancel requests with them.
usage: /<command> [player]