2011-03-19 22:39:51 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2011-06-13 13:05:11 +00:00
|
|
|
import com.earth2me.essentials.Trade;
|
2011-03-19 22:39:51 +00:00
|
|
|
import com.earth2me.essentials.User;
|
2013-06-08 21:31:19 +00:00
|
|
|
import com.earth2me.essentials.utils.StringUtil;
|
2011-11-26 21:30:40 +00:00
|
|
|
import org.bukkit.Location;
|
2011-11-18 17:42:26 +00:00
|
|
|
import org.bukkit.Server;
|
2011-12-07 01:12:36 +00:00
|
|
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
2011-03-19 22:39:51 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
public class Commandhome extends EssentialsCommand {
|
|
|
|
public Commandhome() {
|
|
|
|
super("home");
|
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
// This method contains an undocumented translation parameters #EasterEgg
|
|
|
|
@Override
|
|
|
|
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
|
|
|
final Trade charge = new Trade(this.getName(), ess);
|
|
|
|
User player = user;
|
|
|
|
String homeName = "";
|
|
|
|
String[] nameParts;
|
|
|
|
if (args.length > 0) {
|
|
|
|
nameParts = args[0].split(":");
|
|
|
|
if (nameParts[0].length() == args[0].length() || !user.isAuthorized("essentials.home.others")) {
|
|
|
|
homeName = nameParts[0];
|
|
|
|
} else {
|
|
|
|
player = getPlayer(server, nameParts, 0, true, true);
|
|
|
|
if (nameParts.length > 1) {
|
|
|
|
homeName = nameParts[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
if ("bed".equalsIgnoreCase(homeName) && user.isAuthorized("essentials.home.bed")) {
|
|
|
|
final Location bed = player.getBase().getBedSpawnLocation();
|
|
|
|
if (bed != null) {
|
|
|
|
user.getTeleport().teleport(bed, charge, TeleportCause.COMMAND);
|
|
|
|
throw new NoChargeException();
|
|
|
|
} else {
|
|
|
|
throw new Exception(tl("bedMissing"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
goHome(user, player, homeName.toLowerCase(Locale.ENGLISH), charge);
|
|
|
|
} catch (NotEnoughArgumentsException e) {
|
|
|
|
Location bed = player.getBase().getBedSpawnLocation();
|
|
|
|
final List<String> homes = player.getHomes();
|
|
|
|
if (homes.isEmpty() && player.equals(user)) {
|
|
|
|
user.getTeleport().respawn(charge, TeleportCause.COMMAND);
|
|
|
|
} else if (homes.isEmpty()) {
|
|
|
|
throw new Exception(tl("noHomeSetPlayer"));
|
|
|
|
} else if (homes.size() == 1 && player.equals(user)) {
|
|
|
|
goHome(user, player, homes.get(0), charge);
|
|
|
|
} else {
|
|
|
|
final int count = homes.size();
|
|
|
|
if (user.isAuthorized("essentials.home.bed")) {
|
|
|
|
if (bed != null) {
|
|
|
|
homes.add(tl("bed"));
|
|
|
|
} else {
|
|
|
|
homes.add(tl("bedNull"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
user.sendMessage(tl("homes", StringUtil.joinList(homes), count, getHomeLimit(player)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new NoChargeException();
|
|
|
|
}
|
2012-05-20 22:58:03 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
private String getHomeLimit(final User player) {
|
|
|
|
if (!player.getBase().isOnline()) {
|
|
|
|
return "?";
|
|
|
|
}
|
|
|
|
if (player.isAuthorized("essentials.sethome.multiple.unlimited")) {
|
|
|
|
return "*";
|
|
|
|
}
|
|
|
|
return Integer.toString(ess.getSettings().getHomeLimit(player));
|
|
|
|
}
|
2013-12-21 17:42:55 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
private void goHome(final User user, final User player, final String home, final Trade charge) throws Exception {
|
|
|
|
if (home.length() < 1) {
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
|
|
|
final Location loc = player.getHome(home);
|
|
|
|
if (loc == null) {
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
|
|
|
if (user.getWorld() != loc.getWorld() && ess.getSettings().isWorldHomePermissions() && !user.isAuthorized("essentials.worlds." + loc.getWorld().getName())) {
|
|
|
|
throw new Exception(tl("noPerm", "essentials.worlds." + loc.getWorld().getName()));
|
|
|
|
}
|
|
|
|
user.getTeleport().teleport(loc, charge, TeleportCause.COMMAND);
|
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|