Skip to content

Commit 585f2be

Browse files
authored
Merge pull request #2310 from pop4959/command-tpauto
Implement tpauto command
2 parents 017ea1a + 64930e3 commit 585f2be

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

Essentials/src/com/earth2me/essentials/UserData.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,22 @@ public void setTeleportEnabled(boolean set) {
446446
config.save();
447447
}
448448

449+
private boolean autoTeleportEnabled;
450+
451+
private boolean _getAutoTeleportEnabled() {
452+
return config.getBoolean("teleportauto", false);
453+
}
454+
455+
public boolean isAutoTeleportEnabled() {
456+
return autoTeleportEnabled;
457+
}
458+
459+
public void setAutoTeleportEnabled(boolean set) {
460+
autoTeleportEnabled = set;
461+
config.setProperty("teleportauto", set);
462+
config.save();
463+
}
464+
449465
private List<String> ignoredPlayers;
450466

451467
public List<String> _getIgnoredPlayers() {

Essentials/src/com/earth2me/essentials/commands/Commandtpa.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.earth2me.essentials.commands;
22

3+
import com.earth2me.essentials.Teleport;
4+
import com.earth2me.essentials.Trade;
35
import com.earth2me.essentials.User;
46
import org.bukkit.Server;
7+
import org.bukkit.event.player.PlayerTeleportEvent;
58

69
import java.util.Collections;
710
import java.util.List;
@@ -35,6 +38,15 @@ public void run(Server server, User user, String commandLabel, String[] args) th
3538
&& player.isTpRequestHere() == false) { // Make sure the last teleport request was actually tpa and not tpahere
3639
throw new Exception(tl("requestSentAlready", player.getDisplayName()));
3740
}
41+
if (player.isAutoTeleportEnabled() && !player.isIgnoredPlayer(user)) {
42+
final Trade charge = new Trade(this.getName(), ess);
43+
Teleport teleport = user.getTeleport();
44+
teleport.setTpType(Teleport.TeleportType.TPA);
45+
teleport.teleport(player.getBase(), charge, PlayerTeleportEvent.TeleportCause.COMMAND);
46+
player.sendMessage(tl("requestAcceptedAuto", user.getDisplayName()));
47+
user.sendMessage(tl("requestAcceptedFromAuto", player.getDisplayName()));
48+
return;
49+
}
3850

3951
if (!player.isIgnoredPlayer(user)) {
4052
player.requestTeleport(user, false);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.earth2me.essentials.commands;
2+
3+
import com.earth2me.essentials.CommandSource;
4+
import com.earth2me.essentials.User;
5+
import org.bukkit.Server;
6+
7+
import static com.earth2me.essentials.I18n.tl;
8+
9+
10+
public class Commandtpauto extends EssentialsToggleCommand {
11+
public Commandtpauto() {
12+
super("tpauto", "essentials.tpauto.others");
13+
}
14+
15+
@Override
16+
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
17+
toggleOtherPlayers(server, sender, args);
18+
}
19+
20+
@Override
21+
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
22+
handleToggleWithArgs(server, user, args);
23+
}
24+
25+
@Override
26+
void togglePlayer(CommandSource sender, User user, Boolean enabled) {
27+
if (enabled == null) {
28+
enabled = !user.isAutoTeleportEnabled();
29+
}
30+
31+
user.setAutoTeleportEnabled(enabled);
32+
33+
user.sendMessage(enabled ? tl("autoTeleportEnabled") : tl("autoTeleportDisabled"));
34+
if (enabled && !user.isTeleportEnabled()) {
35+
user.sendMessage(tl("teleportationDisabledWarning"));
36+
}
37+
if (!sender.isPlayer() || !user.getBase().equals(sender.getPlayer())) {
38+
sender.sendMessage(enabled ? tl("autoTeleportEnabledFor", user.getDisplayName()) : tl("autoTeleportDisabledFor", user.getDisplayName()));
39+
}
40+
}
41+
}

Essentials/src/messages_en.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ antiBuildInteract=\u00a74You are not permitted to interact with\u00a7c {0}\u00a7
1919
antiBuildPlace=\u00a74You are not permitted to place\u00a7c {0} \u00a74here.
2020
antiBuildUse=\u00a74You are not permitted to use\u00a7c {0}\u00a74.
2121
autoAfkKickReason=You have been kicked for idling more than {0} minutes.
22+
autoTeleportDisabled=\u00a76You are no longer automatically approving teleport requests.
23+
autoTeleportDisabledFor=\u00a7c{0}\u00a76 is no longer automatically approving teleport requests.
24+
autoTeleportEnabled=\u00a76You are now automatically approving teleport requests.
25+
autoTeleportEnabledFor=\u00a7c{0}\u00a76 is now automatically approving teleport requests.
2226
backAfterDeath=\u00a76Use the /back command to return to your death point.
2327
backupDisabled=\u00a74An external backup script has not been configured.
2428
backupFinished=\u00a76Backup finished.
@@ -448,7 +452,9 @@ repairEnchanted=\u00a74You are not allowed to repair enchanted items.
448452
repairInvalidType=\u00a74This item cannot be repaired.
449453
repairNone=\u00a74There were no items that needed repairing.
450454
requestAccepted=\u00a76Teleport request accepted.
455+
requestAcceptedAuto=\u00a76Automatically accepted a teleport request from {0}.
451456
requestAcceptedFrom=\u00a7c{0} \u00a76accepted your teleport request.
457+
requestAcceptedFromAuto=\u00a7c{0} \u00a76accepted your teleport request automatically.
452458
requestDenied=\u00a76Teleport request denied.
453459
requestDeniedFrom=\u00a7c{0} \u00a76denied your teleport request.
454460
requestSent=\u00a76Request sent to\u00a7c {0}\u00a76.
@@ -504,6 +510,7 @@ teleportAll=\u00a76Teleporting all players...
504510
teleportationCommencing=\u00a76Teleportation commencing...
505511
teleportationDisabled=\u00a76Teleportation \u00a7cdisabled\u00a76.
506512
teleportationDisabledFor=\u00a76Teleportation \u00a7cdisabled \u00a76for \u00a7c{0}\u00a76.
513+
teleportationDisabledWarning=\u00a76You must enable teleportation before other players can teleport to you.
507514
teleportationEnabled=\u00a76Teleportation \u00a7cenabled\u00a76.
508515
teleportationEnabledFor=\u00a76Teleportation \u00a7cenabled \u00a76for \u00a7c{0}\u00a76.
509516
teleportAtoB=\u00a7c{0}\u00a76 teleported you to \u00a7c{1}\u00a76.

Essentials/src/plugin.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,10 @@ commands:
444444
description: Teleport all online players to another player.
445445
usage: /<command> <player>
446446
aliases: [etpall]
447+
tpauto:
448+
description: Automatically accept teleportation requests.
449+
usage: /<command> <player>
450+
aliases: [etpauto]
447451
tpacancel:
448452
description: Cancel all outstanding teleport requests. Specify [player] to cancel requests with them.
449453
usage: /<command> [player]

0 commit comments

Comments
 (0)