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

78 lines
1.8 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import java.util.Locale;
2011-11-18 17:42:26 +00:00
import org.bukkit.Server;
public class Commandsethome extends EssentialsCommand
{
public Commandsethome()
{
super("sethome");
}
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
if (args.length > 0)
{
//Allowing both formats /sethome khobbits house | /sethome khobbits:house
final String[] nameParts = args[0].split(":");
if (nameParts[0].length() != args[0].length())
{
args = nameParts;
}
if (args.length < 2)
{
if (user.isAuthorized("essentials.sethome.multiple"))
{
if ((user.isAuthorized("essentials.sethome.multiple.unlimited")) || (user.getHomes().size() < ess.getSettings().getHomeLimit(user))
|| (user.getHomes().contains(args[0].toLowerCase(Locale.ENGLISH))))
{
user.setHome(args[0].toLowerCase(Locale.ENGLISH));
}
else
{
throw new Exception(_("maxHomes", ess.getSettings().getHomeLimit(user)));
}
}
else
{
throw new Exception(_("maxHomes", 1));
}
}
else
{
if (user.isAuthorized("essentials.sethome.others"))
{
User usersHome = ess.getUser(ess.getServer().getPlayer(args[0]));
if (usersHome == null)
{
usersHome = ess.getOfflineUser(args[0]);
}
2011-08-11 02:33:45 +00:00
if (usersHome == null)
{
throw new Exception(_("playerNotFound"));
2011-08-11 02:33:45 +00:00
}
String name = args[1].toLowerCase(Locale.ENGLISH);
if (!user.isAuthorized("essentials.sethome.multiple"))
{
name = "home";
}
usersHome.setHome(name, user.getLocation());
}
}
}
2011-06-28 09:13:18 +00:00
else
{
user.setHome();
2011-06-28 09:13:18 +00:00
}
user.sendMessage(_("homeSet"));
2011-06-28 09:13:18 +00:00
}
}