TF-EssentialsX/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java

81 lines
3.3 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import static com.earth2me.essentials.I18n.tl;
2011-06-13 13:05:11 +00:00
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
2011-11-18 17:42:26 +00:00
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
public class Commandtppos extends EssentialsCommand
{
public Commandtppos()
{
super("tppos");
}
@Override
2011-11-18 19:30:05 +00:00
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 3)
{
throw new NotEnoughArgumentsException();
}
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 loc = new Location(user.getWorld(), x, y, z, user.getLocation().getYaw(), user.getLocation().getPitch());
if (args.length > 3)
{
loc.setYaw((Float.parseFloat(args[3]) + 180 + 360) % 360);
2011-09-18 01:34:05 +00:00
}
if (args.length > 4)
{
loc.setPitch(Float.parseFloat(args[4]));
2011-09-18 01:34:05 +00:00
}
if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000)
{
throw new NotEnoughArgumentsException(tl("teleportInvalidLocation"));
}
2011-11-18 19:30:05 +00:00
final Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user);
user.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
user.getTeleport().teleport(loc, charge, TeleportCause.COMMAND);
2011-08-30 02:42:31 +00:00
throw new NoChargeException();
}
2012-04-02 01:47:10 +00:00
@Override
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception
2012-04-02 01:47:10 +00:00
{
if (args.length < 4)
{
throw new NotEnoughArgumentsException();
}
User user = getPlayer(server, args, 0, true, false);
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 loc = new Location(user.getWorld(), x, y, z, user.getLocation().getYaw(), user.getLocation().getPitch());
2012-04-02 01:47:10 +00:00
if (args.length > 4)
{
loc.setYaw((Float.parseFloat(args[4]) + 180 + 360) % 360);
2012-04-02 01:47:10 +00:00
}
if (args.length > 5)
{
loc.setPitch(Float.parseFloat(args[5]));
2012-04-02 01:47:10 +00:00
}
if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000)
{
throw new NotEnoughArgumentsException(tl("teleportInvalidLocation"));
}
sender.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
user.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
user.getTeleport().teleport(loc, null, TeleportCause.COMMAND);
2012-04-02 01:47:10 +00:00
}
}