mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-23 01:27:40 +01:00
New behavior of the /home command and beds
- The behavior has been altered to match the vanilla server. - Using a bed will no longer create a home in the users file, if config option bed-sethome is set - The config option bed-sethome has been removed - It's now possible to go to /home bed or /home playername:bed - Bed locations stored before installing Essentials will be used - Players respawn at their bed location (if set) instead of the spawn, if respawn-at-home is set to false - The default value of spawn-if-no-home is set to true - If spawn-if-no-home is set and the player has not set a home, he will be either teleported to his bed location (if set) or the spawn, when he uses the /home command
This commit is contained in:
parent
f9d14697b6
commit
b21b7b7e15
@ -178,7 +178,6 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
pm.registerEvent(Type.PLAYER_MOVE, playerListener, Priority.High, this);
|
pm.registerEvent(Type.PLAYER_MOVE, playerListener, Priority.High, this);
|
||||||
pm.registerEvent(Type.PLAYER_LOGIN, playerListener, Priority.High, this);
|
pm.registerEvent(Type.PLAYER_LOGIN, playerListener, Priority.High, this);
|
||||||
pm.registerEvent(Type.PLAYER_TELEPORT, playerListener, Priority.High, this);
|
pm.registerEvent(Type.PLAYER_TELEPORT, playerListener, Priority.High, this);
|
||||||
pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.High, this);
|
|
||||||
pm.registerEvent(Type.PLAYER_EGG_THROW, playerListener, Priority.High, this);
|
pm.registerEvent(Type.PLAYER_EGG_THROW, playerListener, Priority.High, this);
|
||||||
pm.registerEvent(Type.PLAYER_BUCKET_EMPTY, playerListener, Priority.High, this);
|
pm.registerEvent(Type.PLAYER_BUCKET_EMPTY, playerListener, Priority.High, this);
|
||||||
pm.registerEvent(Type.PLAYER_ANIMATION, playerListener, Priority.High, this);
|
pm.registerEvent(Type.PLAYER_ANIMATION, playerListener, Priority.High, this);
|
||||||
|
@ -231,12 +231,12 @@ public class EssentialsPlayerListener extends PlayerListener
|
|||||||
|
|
||||||
private void updateCompass(final User user)
|
private void updateCompass(final User user)
|
||||||
{
|
{
|
||||||
try
|
Location loc = user.getHome(user.getLocation());
|
||||||
{
|
if (loc == null) {
|
||||||
user.setCompassTarget(user.getHome(user.getLocation()));
|
loc = user.getBedSpawnLocation();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
if (loc != null) {
|
||||||
{
|
user.setCompassTarget(loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,32 +255,6 @@ public class EssentialsPlayerListener extends PlayerListener
|
|||||||
updateCompass(user);
|
updateCompass(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPlayerInteract(final PlayerInteractEvent event)
|
|
||||||
{
|
|
||||||
if (event.isCancelled())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ess.getSettings().getBedSetsHome() && event.getClickedBlock().getType() == Material.BED_BLOCK)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final User user = ess.getUser(event.getPlayer());
|
|
||||||
user.setHome();
|
|
||||||
user.sendMessage(_("homeSetToBed"));
|
|
||||||
}
|
|
||||||
catch (Throwable ex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerEggThrow(final PlayerEggThrowEvent event)
|
public void onPlayerEggThrow(final PlayerEggThrowEvent event)
|
||||||
{
|
{
|
||||||
@ -387,7 +361,7 @@ public class EssentialsPlayerListener extends PlayerListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerChangedWorld(PlayerChangedWorldEvent event)
|
public void onPlayerChangedWorld(final PlayerChangedWorldEvent event)
|
||||||
{
|
{
|
||||||
if (ess.getSettings().getNoGodWorlds().contains(event.getPlayer().getLocation().getWorld().getName())) {
|
if (ess.getSettings().getNoGodWorlds().contains(event.getPlayer().getLocation().getWorld().getName())) {
|
||||||
User user = ess.getUser(event.getPlayer());
|
User user = ess.getUser(event.getPlayer());
|
||||||
@ -395,5 +369,5 @@ public class EssentialsPlayerListener extends PlayerListener
|
|||||||
user.sendMessage(_("noGodWorldWarning"));
|
user.sendMessage(_("noGodWorldWarning"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,6 @@ public interface ISettings extends IConf
|
|||||||
|
|
||||||
long getBackupInterval();
|
long getBackupInterval();
|
||||||
|
|
||||||
boolean getBedSetsHome();
|
|
||||||
|
|
||||||
String getChatFormat(String group);
|
String getChatFormat(String group);
|
||||||
|
|
||||||
int getChatRadius();
|
int getChatRadius();
|
||||||
|
@ -36,12 +36,6 @@ public class Settings implements ISettings
|
|||||||
return config.getBoolean("respawn-at-home", false);
|
return config.getBoolean("respawn-at-home", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean getBedSetsHome()
|
|
||||||
{
|
|
||||||
return config.getBoolean("bed-sethome", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getMultipleHomes()
|
public List<String> getMultipleHomes()
|
||||||
{
|
{
|
||||||
|
@ -130,27 +130,32 @@ public abstract class UserData extends PlayerExtension implements IConf
|
|||||||
return loc;
|
return loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getHome(Location world) throws Exception
|
public Location getHome(final Location world)
|
||||||
{
|
{
|
||||||
Location loc;
|
try
|
||||||
for (String home : getHomes())
|
|
||||||
{
|
{
|
||||||
loc = config.getLocation("homes." + home, getServer());
|
Location loc;
|
||||||
if (world.getWorld() == loc.getWorld())
|
for (String home : getHomes())
|
||||||
{
|
{
|
||||||
return loc;
|
loc = config.getLocation("homes." + home, getServer());
|
||||||
}
|
if (world.getWorld() == loc.getWorld())
|
||||||
|
{
|
||||||
|
return loc;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
loc = config.getLocation("homes." + getHomes().get(0), getServer());
|
||||||
|
return loc;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
loc = config.getLocation("homes." + getHomes().get(0), getServer());
|
|
||||||
return loc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getHomes()
|
public List<String> getHomes()
|
||||||
{
|
{
|
||||||
List<String> list = new ArrayList(homes.keySet());
|
return new ArrayList(homes.keySet());
|
||||||
return list;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHome(String name, Location loc)
|
public void setHome(String name, Location loc)
|
||||||
|
@ -6,6 +6,7 @@ import com.earth2me.essentials.User;
|
|||||||
import com.earth2me.essentials.Util;
|
import com.earth2me.essentials.Util;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
|
||||||
|
|
||||||
@ -42,14 +43,32 @@ public class Commandhome extends EssentialsCommand
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if ("bed".equalsIgnoreCase(homeName)) {
|
||||||
|
final Location bed = player.getBedSpawnLocation();
|
||||||
|
if (bed != null)
|
||||||
|
{
|
||||||
|
user.getTeleport().teleport(bed, charge);
|
||||||
|
}
|
||||||
|
}
|
||||||
user.getTeleport().home(player, homeName.toLowerCase(Locale.ENGLISH), charge);
|
user.getTeleport().home(player, homeName.toLowerCase(Locale.ENGLISH), charge);
|
||||||
}
|
}
|
||||||
catch (NotEnoughArgumentsException e)
|
catch (NotEnoughArgumentsException e)
|
||||||
{
|
{
|
||||||
final List<String> homes = player.getHomes();
|
final List<String> homes = player.getHomes();
|
||||||
if (homes.isEmpty() && player.equals(user) && ess.getSettings().spawnIfNoHome())
|
if (homes.isEmpty() && player.equals(user))
|
||||||
{
|
{
|
||||||
user.getTeleport().respawn(ess.getSpawn(), charge);
|
final Location loc = player.getBedSpawnLocation();
|
||||||
|
if (loc == null)
|
||||||
|
{
|
||||||
|
if (ess.getSettings().spawnIfNoHome())
|
||||||
|
{
|
||||||
|
user.getTeleport().respawn(ess.getSpawn(), charge);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
user.getTeleport().teleport(loc, charge);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (homes.isEmpty())
|
else if (homes.isEmpty())
|
||||||
{
|
{
|
||||||
@ -61,6 +80,7 @@ public class Commandhome extends EssentialsCommand
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
homes.add("bed");
|
||||||
user.sendMessage(_("homes", Util.joinList(homes)));
|
user.sendMessage(_("homes", Util.joinList(homes)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -236,15 +236,11 @@ no-god-in-worlds:
|
|||||||
# +------------------------------------------------------+ #
|
# +------------------------------------------------------+ #
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
# When users die, should they respawn at their homes, instead of the spawnpoint?
|
# When users die, should they respawn at their first home, instead of the spawnpoint or bed?
|
||||||
respawn-at-home: false
|
respawn-at-home: false
|
||||||
|
|
||||||
# When a user interacts with a bed, should their home be set to that location?
|
# If no home is set send you to bed or spawn when /home is used
|
||||||
# If you enable this and remove default user access to the /sethome command, you can make beds the only way for players to set their home location.
|
spawn-if-no-home: true
|
||||||
bed-sethome: false
|
|
||||||
|
|
||||||
# If no home is set send you to spawn when /home is used
|
|
||||||
spawn-if-no-home: false
|
|
||||||
|
|
||||||
# Allow players to have multiple homes.
|
# Allow players to have multiple homes.
|
||||||
# Define different amounts of multiple homes for different permissions, e.g. essentials.sethome.multiple.vip
|
# Define different amounts of multiple homes for different permissions, e.g. essentials.sethome.multiple.vip
|
||||||
|
@ -54,21 +54,15 @@ public class UserTest extends TestCase
|
|||||||
user.setHome();
|
user.setHome();
|
||||||
OfflinePlayer base2 = server.createPlayer(base1.getName(), ess);
|
OfflinePlayer base2 = server.createPlayer(base1.getName(), ess);
|
||||||
User user2 = ess.getUser(base2);
|
User user2 = ess.getUser(base2);
|
||||||
try
|
|
||||||
{
|
|
||||||
Location home = user2.getHome(loc);
|
|
||||||
assertEquals(loc.getWorld().getName(), home.getWorld().getName());
|
|
||||||
assertEquals(loc.getX(), home.getX());
|
|
||||||
assertEquals(loc.getY(), home.getY());
|
|
||||||
assertEquals(loc.getZ(), home.getZ());
|
|
||||||
assertEquals(loc.getYaw(), home.getYaw());
|
|
||||||
assertEquals(loc.getPitch(), home.getPitch());
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
fail("Exception");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Location home = user2.getHome(loc);
|
||||||
|
assertNotNull(home);
|
||||||
|
assertEquals(loc.getWorld().getName(), home.getWorld().getName());
|
||||||
|
assertEquals(loc.getX(), home.getX());
|
||||||
|
assertEquals(loc.getY(), home.getY());
|
||||||
|
assertEquals(loc.getZ(), home.getZ());
|
||||||
|
assertEquals(loc.getYaw(), home.getYaw());
|
||||||
|
assertEquals(loc.getPitch(), home.getPitch());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMoney()
|
public void testMoney()
|
||||||
|
@ -15,8 +15,9 @@ public class EssentialsSpawnPlayerListener extends PlayerListener
|
|||||||
{
|
{
|
||||||
private final transient IEssentials ess;
|
private final transient IEssentials ess;
|
||||||
|
|
||||||
public EssentialsSpawnPlayerListener(IEssentials ess)
|
public EssentialsSpawnPlayerListener(final IEssentials ess)
|
||||||
{
|
{
|
||||||
|
super();
|
||||||
this.ess = ess;
|
this.ess = ess;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,28 +26,24 @@ public class EssentialsSpawnPlayerListener extends PlayerListener
|
|||||||
{
|
{
|
||||||
final User user = ess.getUser(event.getPlayer());
|
final User user = ess.getUser(event.getPlayer());
|
||||||
|
|
||||||
try
|
if (ess.getSettings().getRespawnAtHome())
|
||||||
{
|
{
|
||||||
if (ess.getSettings().getRespawnAtHome())
|
Location home = user.getHome(user.getLocation());
|
||||||
|
if (home == null)
|
||||||
|
{
|
||||||
|
home = user.getBedSpawnLocation();
|
||||||
|
}
|
||||||
|
if (home != null)
|
||||||
{
|
{
|
||||||
Location home = user.getHome(user.getLocation());
|
|
||||||
if (home == null)
|
|
||||||
{
|
|
||||||
throw new Exception();
|
|
||||||
}
|
|
||||||
event.setRespawnLocation(home);
|
event.setRespawnLocation(home);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Throwable ex)
|
final Location spawn = ess.getSpawn().getSpawn(user.getGroup());
|
||||||
|
if (spawn != null)
|
||||||
{
|
{
|
||||||
|
event.setRespawnLocation(spawn);
|
||||||
}
|
}
|
||||||
Location spawn = ess.getSpawn().getSpawn(user.getGroup());
|
|
||||||
if (spawn == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
event.setRespawnLocation(spawn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -54,7 +51,7 @@ public class EssentialsSpawnPlayerListener extends PlayerListener
|
|||||||
{
|
{
|
||||||
final User user = ess.getUser(event.getPlayer());
|
final User user = ess.getUser(event.getPlayer());
|
||||||
|
|
||||||
if (!user.isNew())
|
if (!user.isNew() || user.getBedSpawnLocation() != null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user