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