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

63 lines
1.3 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
2011-06-13 13:05:11 +00:00
import com.earth2me.essentials.Trade;
import org.bukkit.Server;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import java.util.List;
public class Commandhome extends EssentialsCommand
{
public Commandhome()
{
super("home");
}
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
2011-06-13 13:05:11 +00:00
Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user);
User u = user;
String homeName = "";
String[] nameParts;
if (args.length > 0)
{
nameParts = args[0].split(":");
if (nameParts[0].length() == args[0].length())
{
homeName = nameParts[0];
}
else
{
u = getPlayer(server, nameParts[0].split(" "), 0, true);
if (nameParts.length > 1)
{
homeName = nameParts[1];
}
}
}
try
{
2011-08-23 14:37:09 +00:00
user.getTeleport().home(u, homeName.toLowerCase(), charge);
}
catch (NotEnoughArgumentsException e)
{
List<String> homes = u.getHomes();
if (homes.isEmpty())
{
throw new Exception(u == user ? Util.i18n("noHomeSet") : Util.i18n("noHomeSetPlayer"));
}
else if ((homes.size() == 1) && u == user)
{
user.getTeleport().home(u, homes.get(0), charge);
}
else
{
user.sendMessage(Util.format("homes", Util.joinList(homes)));
}
}
}
}