Skip to content

Commit

Permalink
Pass optional location parameters to teleport TL keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
khobbits committed Jan 12, 2014
1 parent 4084445 commit eee18f4
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 51 deletions.
35 changes: 24 additions & 11 deletions Essentials/src/com/earth2me/essentials/Teleport.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public void now(Location loc, boolean cooldown, TeleportCause cause) throws Exce
{
cooldown(false);
}
now(teleportOwner, new LocationTarget(loc), cause);
final ITarget target = new LocationTarget(loc);
now(teleportOwner, target, cause);
}

@Override
Expand All @@ -89,29 +90,31 @@ public void now(Player entity, boolean cooldown, TeleportCause cause) throws Exc
{
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);
}
}

Expand All @@ -130,22 +133,30 @@ public void teleport(Location loc, Trade chargeFor, TeleportCause cause) throws
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
Expand Down Expand Up @@ -228,15 +239,17 @@ protected void respawnNow(IUser teleportee, TeleportCause cause) throws Exceptio
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);
}

//The back function is a wrapper used to teleportPlayer a player /back to their previous location.
@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ protected void run(final Server server, final User user, final String commandLab
}
final Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user);
user.sendMessage(_("backUsageMsg"));
user.getTeleport().back(charge);
throw new NoChargeException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public void run(final Server server, final User user, final String commandLabel,
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()));

}
}
22 changes: 11 additions & 11 deletions Essentials/src/com/earth2me/essentials/commands/Commandtp.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public void run(final Server server, final User user, final String commandLabel,
{
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);
Expand All @@ -54,14 +53,14 @@ public void run(final Server server, final User user, final String commandLabel,
{
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:
Expand All @@ -85,7 +84,6 @@ public void run(final Server server, final User user, final String commandLabel,
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;
}
Expand Down Expand Up @@ -115,12 +113,14 @@ else if (args.length > 3)
{
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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;

Expand Down Expand Up @@ -59,7 +60,9 @@ public void run(final Server server, final User user, final String commandLabel,
{
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
{
Expand All @@ -70,7 +73,7 @@ public void run(final Server server, final User user, final String commandLabel,
{
user.sendMessage(_("pendingTeleportCancelled"));
ess.showError(requester.getSource(), ex, commandLabel);
}
}
user.requestTeleport(null, false);
throw new NoChargeException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand Down Expand Up @@ -35,6 +36,7 @@ public void run(final Server server, final CommandSource sender, final String co
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);
Expand All @@ -50,7 +52,7 @@ private void teleportAllPlayers(Server server, CommandSource sender, User target
}
try
{
player.getTeleport().now(target.getBase(), false, TeleportCause.COMMAND);
player.getTeleport().now(loc, false, TeleportCause.COMMAND);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public void run(final Server server, final User user, final String commandLabel,
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public void run(final Server server, final User user, final String commandLabel,
{
throw new Exception(_("noPerm", "essentials.worlds." + player.getWorld().getName()));
}
user.sendMessage(_("teleporting"));
user.getTeleport().now(player.getBase(), false, TeleportCause.COMMAND);
break;

Expand All @@ -37,7 +36,6 @@ public void run(final Server server, final User user, final String commandLabel,
{
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,5 @@ public void run(final Server server, final User user, final String commandLabel,

// Verify permission
player.getTeleport().now(user.getBase(), false, TeleportCause.COMMAND);
user.sendMessage(_("teleporting"));

}
}
22 changes: 11 additions & 11 deletions Essentials/src/com/earth2me/essentials/commands/Commandtppos.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ public void run(final Server server, final User user, final String commandLabel,
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)
{
throw new NotEnoughArgumentsException("Value of coordinates cannot be over 30000000"); //TODO: I18n
}
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();
}

Expand All @@ -59,22 +59,22 @@ public void run(final Server server, final CommandSource sender, final String co
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);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ public void run(final Server server, final User user, final String commandLabel,
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();
}
Expand All @@ -50,15 +49,16 @@ protected void run(final Server server, final CommandSource sender, final String
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);
Expand Down

0 comments on commit eee18f4

Please sign in to comment.