package btym;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.*;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class TPC extends JavaPlugin
{
Logger log = Logger.getLogger("TPC");
public boolean validCoords(String[] args)
{
try
{
Double.parseDouble(args[0]);
Double.parseDouble(args[1]);
Double.parseDouble(args[2]);
return true;
}
catch (Exception e)
{
try
{
Integer.parseInt(args[0]);
Integer.parseInt(args[1]);
Integer.parseInt(args[2]);
return true;
}
catch (Exception e2)
{
return false;
}
}
}
public boolean validRelativeCoords(String[] args)
{
if (args[0].endsWith("-") || args[1].endsWith("-") || args[2].endsWith("-") || args[0].endsWith("+") || args[1].endsWith("+") || args[2].endsWith("+"))
{
try
{
Double.parseDouble(args[0].replace("-", ""));
Double.parseDouble(args[1].replace("-", ""));
Double.parseDouble(args[2].replace("-", ""));
Double.parseDouble(args[0].replace("+", ""));
Double.parseDouble(args[1].replace("+", ""));
Double.parseDouble(args[2].replace("+", ""));
return true;
} catch (Exception e)
{
return false;
}
} else
{
return false;
}
}
public void onEnable()
{
log.info("TPC loaded - by Loud");
}
public void onDisable()
{
}
public void tpc2(CommandSender sender, Command command, String commandLabel, String[] args)
{
Player player = (Player) sender;
Location current = player.getLocation();
Double x = 0.0;
Double y = 0.0;
Double z = 0.0;
if (args[0].endsWith("-"))
{
x = current.getX() - Double.parseDouble(args[0].replace("-", ""));
} else if (args[0].endsWith("+"))
{
x = current.getX() + Double.parseDouble(args[0].replace("+", ""));
} else
{
x = Double.parseDouble(args[0]);
}
if (args[1].endsWith("-"))
{
y = current.getY() - Double.parseDouble(args[1].replace("-", ""));
} else if (args[1].endsWith("+"))
{
y = current.getY() + Double.parseDouble(args[1].replace("+", ""));
} else
{
y = Double.parseDouble(args[1]);
}
if (args[1].endsWith("-"))
{
z = current.getZ() - Double.parseDouble(args[1].replace("-", ""));
} else if (args[1].endsWith("+"))
{
z = current.getZ() + Double.parseDouble(args[1].replace("+", ""));
} else
{
z = Double.parseDouble(args[1]);
}
Location loc = new Location(player.getWorld(), x, y, z);
player.teleport(loc);
}
public void tpc1(CommandSender sender, Command command, String commandLabel, String[] args)
{
if (sender.hasPermission("tpc.tpc"))
{
if (validCoords(args))
{
Player player = (Player) sender;
World world = player.getWorld();
Double x = Double.parseDouble(args[0]);
Double y = Double.parseDouble(args[1]);
Double z = Double.parseDouble(args[2]);
Location loc = new Location(world, x, y, z);
player.teleport(loc);
} else
{
try
{
tpc2(sender, command, commandLabel, args);
}
catch (Exception ee)
{
sender.sendMessage(ChatColor.RED + "Invalid input! Usage: /tpc <x> <y> <z>");
}
}
}
else
{
sender.sendMessage(ChatColor.DARK_RED + "You do not have permission to use that command.");
}
}
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args)
{
if(command.getName().equalsIgnoreCase("tpc"))
{
tpc1(sender, command, commandLabel, args);
}
return true;
}
}
Comments