Pass optional location parameters to teleport TL keys.

This commit is contained in:
KHobbits 2014-01-12 01:23:12 +00:00
parent 4084445b5b
commit eee18f40be
11 changed files with 63 additions and 51 deletions

View File

@ -79,7 +79,8 @@ public class Teleport implements net.ess3.api.ITeleport
{
cooldown(false);
}
now(teleportOwner, new LocationTarget(loc), cause);
final ITarget target = new LocationTarget(loc);
now(teleportOwner, target, cause);
}
@Override
@ -89,29 +90,31 @@ public class Teleport implements net.ess3.api.ITeleport
{
cooldown(false);
}
now(teleportOwner, new PlayerTarget(entity), cause);
final ITarget target = new PlayerTarget(entity);
now(teleportOwner, target, cause);
teleportOwner.sendMessage(_("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ()));
}
protected void now(IUser teleportee, ITarget target, TeleportCause cause) throws Exception
{
cancel(false);
teleportee.setLastLocation();
final Location location = target.getLocation();
final Location loc = target.getLocation();
if (LocationUtil.isBlockUnsafe(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ()))
if (LocationUtil.isBlockUnsafe(loc.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()))
{
if (ess.getSettings().isTeleportSafetyEnabled())
{
teleportee.getBase().teleport(LocationUtil.getSafeDestination(teleportee, location));
teleportee.getBase().teleport(LocationUtil.getSafeDestination(teleportee, loc));
}
else
{
throw new Exception(_("unsafeTeleportDestination"));
throw new Exception(_("unsafeTeleportDestination", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
}
}
else
{
teleportee.getBase().teleport(location);
teleportee.getBase().teleport(loc);
}
}
@ -130,22 +133,30 @@ public class Teleport implements net.ess3.api.ITeleport
teleport(teleportOwner, new LocationTarget(loc), chargeFor, cause);
}
//This is used when teleporting to a player
@Override
public void teleport(Player entity, Trade chargeFor, TeleportCause cause) throws Exception
{
teleport(teleportOwner, new PlayerTarget(entity), chargeFor, cause);
ITarget target = new PlayerTarget(entity);
teleport(teleportOwner, target, chargeFor, cause);
teleportOwner.sendMessage(_("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ()));
}
//This is used when teleporting to stored location
@Override
public void teleportPlayer(IUser teleportee, Location loc, Trade chargeFor, TeleportCause cause) throws Exception
{
teleport(teleportee, new LocationTarget(loc), chargeFor, cause);
}
//This is used on /tphere
@Override
public void teleportPlayer(IUser teleportee, Player entity, Trade chargeFor, TeleportCause cause) throws Exception
{
teleport(teleportee, new PlayerTarget(entity), chargeFor, cause);
ITarget target = new PlayerTarget(entity);
teleport(teleportee, target, chargeFor, cause);
teleportee.sendMessage(_("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ()));
teleportOwner.sendMessage(_("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ()));
}
private void teleport(IUser teleportee, ITarget target, Trade chargeFor, TeleportCause cause) throws Exception
@ -228,7 +239,7 @@ public class Teleport implements net.ess3.api.ITeleport
public void warp(IUser teleportee, String warp, Trade chargeFor, TeleportCause cause) throws Exception
{
Location loc = ess.getWarps().getWarp(warp);
teleportee.sendMessage(_("warpingTo", warp));
teleportee.sendMessage(_("warpingTo", warp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
teleport(teleportee, new LocationTarget(loc), chargeFor, cause);
}
@ -236,7 +247,9 @@ public class Teleport implements net.ess3.api.ITeleport
@Override
public void back(Trade chargeFor) throws Exception
{
teleport(teleportOwner, new LocationTarget(teleportOwner.getLastLocation()), chargeFor, TeleportCause.COMMAND);
final Location loc = teleportOwner.getLastLocation();
teleportOwner.sendMessage(_("backUsageMsg", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
teleport(teleportOwner, new LocationTarget(loc), chargeFor, TeleportCause.COMMAND);
}
//This function is used to throw a user back after a jail sentence

View File

@ -27,7 +27,6 @@ public class Commandback extends EssentialsCommand
}
final Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user);
user.sendMessage(_("backUsageMsg"));
user.getTeleport().back(charge);
throw new NoChargeException();
}

View File

@ -23,8 +23,9 @@ public class Commandtop extends EssentialsCommand
final int topZ = user.getLocation().getBlockZ();
final float pitch = user.getLocation().getPitch();
final float yaw = user.getLocation().getYaw();
final Location location = LocationUtil.getSafeDestination(new Location(user.getWorld(), topX, user.getWorld().getMaxHeight(), topZ, yaw, pitch));
user.getTeleport().teleport(location, new Trade(this.getName(), ess), TeleportCause.COMMAND);
user.sendMessage(_("teleportTop"));
final Location loc = LocationUtil.getSafeDestination(new Location(user.getWorld(), topX, user.getWorld().getMaxHeight(), topZ, yaw, pitch));
user.getTeleport().teleport(loc, new Trade(this.getName(), ess), TeleportCause.COMMAND);
user.sendMessage(_("teleportTop", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
}
}

View File

@ -36,7 +36,6 @@ public class Commandtp extends EssentialsCommand
{
throw new Exception(_("noPerm", "essentials.worlds." + player.getWorld().getName()));
}
user.sendMessage(_("teleporting"));
final Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user);
user.getTeleport().teleport(player.getBase(), charge, TeleportCause.COMMAND);
@ -54,14 +53,14 @@ public class Commandtp extends EssentialsCommand
{
throw new NotEnoughArgumentsException("Value of coordinates cannot be over 30000000"); //TODO: I18n
}
final Location location = new Location(target2.getWorld(), x, y, z, target2.getLocation().getYaw(), target2.getLocation().getPitch());
final Location loc = new Location(target2.getWorld(), x, y, z, target2.getLocation().getYaw(), target2.getLocation().getPitch());
if (!target2.isTeleportEnabled())
{
throw new Exception(_("teleportDisabled", target2.getDisplayName()));
}
target2.getTeleport().now(location, false, TeleportCause.COMMAND);
user.sendMessage(_("teleporting"));
target2.sendMessage(_("teleporting"));
target2.getTeleport().now(loc, false, TeleportCause.COMMAND);
user.sendMessage(_("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
target2.sendMessage(_("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
break;
case 2:
default:
@ -85,7 +84,6 @@ public class Commandtp extends EssentialsCommand
throw new Exception(_("noPerm", "essentials.worlds." + toPlayer.getWorld().getName()));
}
target.getTeleport().now(toPlayer.getBase(), false, TeleportCause.COMMAND);
user.sendMessage(_("teleporting"));
target.sendMessage(_("teleportAtoB", user.getDisplayName(), toPlayer.getDisplayName()));
break;
}
@ -115,12 +113,14 @@ public class Commandtp extends EssentialsCommand
{
throw new NotEnoughArgumentsException("Value of coordinates cannot be over 30000000"); //TODO: I18n
}
final Location location = new Location(target.getWorld(), x, y, z, target.getLocation().getYaw(), target.getLocation().getPitch());
target.getTeleport().now(location, false, TeleportCause.COMMAND);
target.sendMessage(_("teleporting"));
} else {
final Location loc = new Location(target.getWorld(), x, y, z, target.getLocation().getYaw(), target.getLocation().getPitch());
target.getTeleport().now(loc, false, TeleportCause.COMMAND);
target.sendMessage(_("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
sender.sendMessage(_("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
}
else
{
throw new NotEnoughArgumentsException();
}
sender.sendMessage(_("teleporting"));
}
}

View File

@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
@ -59,7 +60,9 @@ public class Commandtpaccept extends EssentialsCommand
{
if (user.isTpRequestHere())
{
final Location loc = user.getTpRequestLocation();
requester.getTeleport().teleportPlayer(user, user.getTpRequestLocation(), charge, TeleportCause.COMMAND);
requester.sendMessage(_("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
}
else
{
@ -70,7 +73,7 @@ public class Commandtpaccept extends EssentialsCommand
{
user.sendMessage(_("pendingTeleportCancelled"));
ess.showError(requester.getSource(), ex, commandLabel);
}
}
user.requestTeleport(null, false);
throw new NoChargeException();
}

View File

@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
@ -35,6 +36,7 @@ public class Commandtpall extends EssentialsCommand
private void teleportAllPlayers(Server server, CommandSource sender, User target)
{
sender.sendMessage(_("teleportAll"));
final Location loc = target.getLocation();
for (Player onlinePlayer : server.getOnlinePlayers())
{
final User player = ess.getUser(onlinePlayer);
@ -50,7 +52,7 @@ public class Commandtpall extends EssentialsCommand
}
try
{
player.getTeleport().now(target.getBase(), false, TeleportCause.COMMAND);
player.getTeleport().now(loc, false, TeleportCause.COMMAND);
}
catch (Exception ex)
{

View File

@ -28,8 +28,6 @@ public class Commandtphere extends EssentialsCommand
throw new Exception(_("noPerm", "essentials.worlds." + user.getWorld().getName()));
}
user.getTeleport().teleportPlayer(player, user.getBase(), new Trade(this.getName(), ess), TeleportCause.COMMAND);
user.sendMessage(_("teleporting"));
player.sendMessage(_("teleporting"));
throw new NoChargeException();
}
}

View File

@ -28,7 +28,6 @@ public class Commandtpo extends EssentialsCommand
{
throw new Exception(_("noPerm", "essentials.worlds." + player.getWorld().getName()));
}
user.sendMessage(_("teleporting"));
user.getTeleport().now(player.getBase(), false, TeleportCause.COMMAND);
break;
@ -37,7 +36,6 @@ public class Commandtpo extends EssentialsCommand
{
throw new Exception(_("noPerm", "essentials.tp.others"));
}
user.sendMessage(_("teleporting"));
final User target = getPlayer(server, user, args, 0);
final User toPlayer = getPlayer(server, user, args, 1);

View File

@ -32,7 +32,5 @@ public class Commandtpohere extends EssentialsCommand
// Verify permission
player.getTeleport().now(user.getBase(), false, TeleportCause.COMMAND);
user.sendMessage(_("teleporting"));
}
}

View File

@ -27,14 +27,14 @@ public class Commandtppos extends EssentialsCommand
final double x = args[0].startsWith("~") ? user.getLocation().getX() + Integer.parseInt(args[0].substring(1)) : Integer.parseInt(args[0]);
final double y = args[1].startsWith("~") ? user.getLocation().getY() + Integer.parseInt(args[1].substring(1)) : Integer.parseInt(args[1]);
final double z = args[2].startsWith("~") ? user.getLocation().getZ() + Integer.parseInt(args[2].substring(1)) : Integer.parseInt(args[2]);
final Location location = new Location(user.getWorld(), x, y, z, user.getLocation().getYaw(), user.getLocation().getPitch());
final Location loc = new Location(user.getWorld(), x, y, z, user.getLocation().getYaw(), user.getLocation().getPitch());
if (args.length > 3)
{
location.setYaw((Float.parseFloat(args[3]) + 180 + 360) % 360);
loc.setYaw((Float.parseFloat(args[3]) + 180 + 360) % 360);
}
if (args.length > 4)
{
location.setPitch(Float.parseFloat(args[4]));
loc.setPitch(Float.parseFloat(args[4]));
}
if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000)
{
@ -42,8 +42,8 @@ public class Commandtppos extends EssentialsCommand
}
final Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user);
user.sendMessage(_("teleporting"));
user.getTeleport().teleport(location, charge, TeleportCause.COMMAND);
user.sendMessage(_("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
user.getTeleport().teleport(loc, charge, TeleportCause.COMMAND);
throw new NoChargeException();
}
@ -59,22 +59,22 @@ public class Commandtppos extends EssentialsCommand
final double x = args[1].startsWith("~") ? user.getLocation().getX() + Integer.parseInt(args[1].substring(1)) : Integer.parseInt(args[1]);
final double y = args[2].startsWith("~") ? user.getLocation().getY() + Integer.parseInt(args[2].substring(1)) : Integer.parseInt(args[2]);
final double z = args[3].startsWith("~") ? user.getLocation().getZ() + Integer.parseInt(args[3].substring(1)) : Integer.parseInt(args[3]);
final Location location = new Location(user.getWorld(), x, y, z, user.getLocation().getYaw(), user.getLocation().getPitch());
final Location loc = new Location(user.getWorld(), x, y, z, user.getLocation().getYaw(), user.getLocation().getPitch());
if (args.length > 4)
{
location.setYaw((Float.parseFloat(args[4]) + 180 + 360) % 360);
loc.setYaw((Float.parseFloat(args[4]) + 180 + 360) % 360);
}
if (args.length > 5)
{
location.setPitch(Float.parseFloat(args[5]));
loc.setPitch(Float.parseFloat(args[5]));
}
if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000)
{
throw new NotEnoughArgumentsException("Value of coordinates cannot be over 30000000"); //TODO: I18n
}
sender.sendMessage(_("teleporting"));
user.sendMessage(_("teleporting"));
user.getTeleport().teleport(location, null, TeleportCause.COMMAND);
sender.sendMessage(_("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
user.sendMessage(_("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
user.getTeleport().teleport(loc, null, TeleportCause.COMMAND);
}
}

View File

@ -28,16 +28,15 @@ public class Commandspawn extends EssentialsCommand
if (args.length > 0 && user.isAuthorized("essentials.spawn.others"))
{
final User otherUser = getPlayer(server, user, args, 0);
respawn(user, otherUser, charge);
respawn(user.getSource(), user, otherUser, charge);
if (!otherUser.equals(user))
{
otherUser.sendMessage(_("teleportAtoB", user.getDisplayName(), "spawn"));
user.sendMessage(_("teleporting"));
}
}
else
{
respawn(user, user, charge);
respawn(user.getSource(), user, user, charge);
}
throw new NoChargeException();
}
@ -50,15 +49,16 @@ public class Commandspawn extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
final User user = getPlayer(server, args, 0, true, false);
respawn(null, user, null);
respawn(sender, null, user, null);
user.sendMessage(_("teleportAtoB", Console.NAME, "spawn"));
sender.sendMessage(_("teleporting"));
}
private void respawn(final User teleportOwner, final User teleportee, final Trade charge) throws Exception
private void respawn(final CommandSource sender, final User teleportOwner, final User teleportee, final Trade charge) throws Exception
{
final SpawnStorage spawns = (SpawnStorage)this.module;
final Location spawn = spawns.getSpawn(teleportee.getGroup());
sender.sendMessage(_("teleporting", spawn.getWorld().getName(), spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ()));
if (teleportOwner == null)
{
teleportee.getTeleport().now(spawn, false, TeleportCause.COMMAND);