mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-05 20:12:54 +00:00

add new messages to messages.properties add new messages to messages_en.properties add new messages to messages_cs.properties add new messages to messages_da.properties add new messages to messages_de.properties add new messages to messages_es.properties add new messages to messages_fi.properties add new messages to messages_fr.properties add new messages to messages_it.properties add new messages to messages_nl.properties add new messages to messages_pl.properties add new messages to messages_pt.properties add new messages to messages_se.properties remove color from bedNull remove color from bedNull remove color from bedNull remove color from bedNull remove color from bedNull remove color from bedNull remove color from bedNull remove color from bedNull remove color from bedNull remove color from bedNull remove color from bedNull remove color from bedNull
111 lines
2.8 KiB
Java
111 lines
2.8 KiB
Java
package com.earth2me.essentials.commands;
|
|
|
|
import static com.earth2me.essentials.I18n._;
|
|
import com.earth2me.essentials.Trade;
|
|
import com.earth2me.essentials.User;
|
|
import com.earth2me.essentials.Util;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.Server;
|
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
|
|
|
|
|
public class Commandhome extends EssentialsCommand
|
|
{
|
|
public Commandhome()
|
|
{
|
|
super("home");
|
|
}
|
|
|
|
@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);
|
|
if (nameParts.length > 1)
|
|
{
|
|
homeName = nameParts[1];
|
|
}
|
|
}
|
|
}
|
|
try
|
|
{
|
|
if ("bed".equalsIgnoreCase(homeName) && user.isAuthorized("essentials.home.bed"))
|
|
{
|
|
final Location bed = player.getBedSpawnLocation();
|
|
if (bed != null)
|
|
{
|
|
user.getTeleport().teleport(bed, charge, TeleportCause.COMMAND);
|
|
throw new NoChargeException();
|
|
}
|
|
else
|
|
{
|
|
throw new Exception(_("bedMissing"));
|
|
}
|
|
}
|
|
goHome(user, player, homeName.toLowerCase(Locale.ENGLISH), charge);
|
|
}
|
|
catch (NotEnoughArgumentsException e)
|
|
{
|
|
Location bed = player.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(_("noHomeSetPlayer"));
|
|
}
|
|
else if (homes.size() == 1 && player.equals(user))
|
|
{
|
|
goHome(user, player, homes.get(0), charge);
|
|
}
|
|
else
|
|
{
|
|
if (user.isAuthorized("essentials.home.bed"))
|
|
{
|
|
if (bed != null)
|
|
{
|
|
homes.add(_("bed"));
|
|
}
|
|
else
|
|
{
|
|
homes.add(_("bedNull"));
|
|
}
|
|
}
|
|
user.sendMessage(_("homes", Util.joinList(homes)));
|
|
}
|
|
}
|
|
throw new NoChargeException();
|
|
}
|
|
|
|
private void goHome(final User user, final User player, final String home, final Trade charge) throws Exception
|
|
{
|
|
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(_("noPerm", "essentials.worlds." + loc.getWorld().getName()));
|
|
}
|
|
user.getTeleport().home(loc, charge);
|
|
}
|
|
}
|