diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index f45f28bb2..7f85223f2 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -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 ignoredPlayers; public List _getIgnoredPlayers() { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java index 5a6db08a8..bdff28454 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java @@ -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); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpauto.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpauto.java new file mode 100644 index 000000000..e2bc526ac --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpauto.java @@ -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())); + } + } +} diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index 2dab6ca75..93a989fa1 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -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. diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index d5d45b7ac..d02544e33 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -444,6 +444,10 @@ commands: description: Teleport all online players to another player. usage: / aliases: [etpall] + tpauto: + description: Automatically accept teleportation requests. + usage: / + aliases: [etpauto] tpacancel: description: Cancel all outstanding teleport requests. Specify [player] to cancel requests with them. usage: / [player]