Implement tpauto command

This commit is contained in:
pop4959 2018-12-19 02:50:30 -08:00
parent 492005d00a
commit 16381234e0
5 changed files with 76 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("autoteleportenabled", false);
}
public boolean isAutoTeleportEnabled() {
return autoTeleportEnabled;
}
public void setAutoTeleportEnabled(boolean set) {
autoTeleportEnabled = set;
config.setProperty("autoteleportenabled", 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,38 @@
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 (!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=\u00a76Automatic teleportation request approval \u00a7cdisabled\u00a76.
autoTeleportDisabledFor=\u00a76Automatic teleportation request approval \u00a7cdisabled \u00a76for \u00a7c{0}\u00a76.
autoTeleportEnabled=\u00a76Automatic teleportation request approval \u00a7cenabled\u00a76.
autoTeleportEnabledFor=\u00a76Automatic teleportation request approval \u00a7cenabled \u00a76for \u00a7c{0}\u00a76.
backAfterDeath=\u00a76Use the /back command to return to your death point.
backupDisabled=\u00a74An external backup script has not been configured.
backupFinished=\u00a76Backup finished.
@ -447,7 +451,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.

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]