[trunk] adding new setting to send a person to spawn if /home is used with no home set

git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1187 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
ementalo 2011-04-14 09:36:25 +00:00
parent b3d6c32b71
commit dd164d2e38
3 changed files with 200 additions and 47 deletions

View File

@ -435,4 +435,9 @@ public class Settings implements IConf
} }
return epBreakList; return epBreakList;
} }
public Boolean spawnIfNoHome()
{
return config.getBoolean("spawn-if-no-home", true);
}
} }

View File

@ -14,7 +14,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.reader.UnicodeReader; import org.yaml.snakeyaml.reader.UnicodeReader;
public class User extends PlayerExtension implements Comparable<User>, IReplyTo public class User extends PlayerExtension implements Comparable<User>, IReplyTo
{ {
private static final Logger logger = Logger.getLogger("Minecraft"); private static final Logger logger = Logger.getLogger("Minecraft");
private final Yaml yaml = new Yaml(new SafeConstructor()); private final Yaml yaml = new Yaml(new SafeConstructor());
@ -62,18 +62,18 @@ public class User extends PlayerExtension implements Comparable<User>, IReplyTo
{ {
if (base == null) if (base == null)
return null; return null;
if (base instanceof User) if (base instanceof User)
return (User)base; return (User)base;
if (users.containsKey(base.getName())) if (users.containsKey(base.getName()))
return users.get(base.getName()).update(base); return users.get(base.getName()).update(base);
User u = new User(base); User u = new User(base);
users.put(u.getName(), u); users.put(u.getName(), u);
return u; return u;
} }
public static <T> void charge(T base, IEssentialsCommand cmd) throws Exception public static <T> void charge(T base, IEssentialsCommand cmd) throws Exception
{ {
if (base instanceof Player) if (base instanceof Player)
@ -138,13 +138,15 @@ public class User extends PlayerExtension implements Comparable<User>, IReplyTo
public void teleportCooldown(boolean justCheck) throws Exception public void teleportCooldown(boolean justCheck) throws Exception
{ {
long now = Calendar.getInstance().getTimeInMillis(); long now = Calendar.getInstance().getTimeInMillis();
if (lastTeleport > 0) { if (lastTeleport > 0)
{
long cooldown = Essentials.getSettings().getTeleportCooldown(); long cooldown = Essentials.getSettings().getTeleportCooldown();
long left = lastTeleport + cooldown - now; long left = lastTeleport + cooldown - now;
if (left > 0 && !isOp() && !isAuthorized("essentials.teleport.cooldown.bypass")) { if (left > 0 && !isOp() && !isAuthorized("essentials.teleport.cooldown.bypass"))
{
throw new Exception("Time before next teleport: " + Essentials.FormatTime(left)); throw new Exception("Time before next teleport: " + Essentials.FormatTime(left));
} }
} }
// if justCheck is set, don't update lastTeleport; we're just checking // if justCheck is set, don't update lastTeleport; we're just checking
if (!justCheck) lastTeleport = now; if (!justCheck) lastTeleport = now;
} }
@ -157,10 +159,12 @@ public class User extends PlayerExtension implements Comparable<User>, IReplyTo
public void healCooldown() throws Exception public void healCooldown() throws Exception
{ {
long now = Calendar.getInstance().getTimeInMillis(); long now = Calendar.getInstance().getTimeInMillis();
if (lastHeal > 0) { if (lastHeal > 0)
{
long cooldown = Essentials.getSettings().getHealCooldown(); long cooldown = Essentials.getSettings().getHealCooldown();
long left = lastHeal + cooldown - now; long left = lastHeal + cooldown - now;
if (left > 0 && !isOp() && !isAuthorized("essentials.heal.cooldown.bypass")) { if (left > 0 && !isOp() && !isAuthorized("essentials.heal.cooldown.bypass"))
{
throw new Exception("Time before next heal: " + Essentials.FormatTime(left)); throw new Exception("Time before next heal: " + Essentials.FormatTime(left));
} }
} }
@ -267,10 +271,11 @@ public class User extends PlayerExtension implements Comparable<User>, IReplyTo
load(); load();
if (data.containsKey("money")) if (data.containsKey("money"))
{ {
if (data.get("money") instanceof Number) { if (data.get("money") instanceof Number)
{
return ((Number)data.get("money")).doubleValue(); return ((Number)data.get("money")).doubleValue();
} }
logger.log(Level.SEVERE, "Can't convert money value to double:"+ data.get("money")); logger.log(Level.SEVERE, "Can't convert money value to double:" + data.get("money"));
} }
try try
@ -336,8 +341,9 @@ public class User extends PlayerExtension implements Comparable<User>, IReplyTo
public void charge(String cmd) throws Exception public void charge(String cmd) throws Exception
{ {
if (isAuthorized("essentials.nocommandcost.all") || if (isAuthorized("essentials.nocommandcost.all")
isAuthorized("essentials.nocommandcost."+cmd)) { || isAuthorized("essentials.nocommandcost." + cmd))
{
return; return;
} }
double mon = getMoney(); double mon = getMoney();
@ -431,7 +437,7 @@ public class User extends PlayerExtension implements Comparable<User>, IReplyTo
sendMessage("§cError: " + ex.getMessage()); sendMessage("§cError: " + ex.getMessage());
} }
} }
public void DoCancel() public void DoCancel()
{ {
cancelTeleport(); cancelTeleport();
@ -481,7 +487,7 @@ public class User extends PlayerExtension implements Comparable<User>, IReplyTo
sendMessage("§cError: " + ex.getMessage()); sendMessage("§cError: " + ex.getMessage());
} }
} }
public void DoCancel() public void DoCancel()
{ {
cancelTeleport(); cancelTeleport();
@ -501,10 +507,12 @@ public class User extends PlayerExtension implements Comparable<User>, IReplyTo
{ {
List<Object> vals = (List<Object>)data.get("home"); List<Object> vals = (List<Object>)data.get("home");
World world = getServer() == null ? null : getServer().getWorlds().get(0); World world = getServer() == null ? null : getServer().getWorlds().get(0);
if (vals.size() > 5 && getServer() != null) { if (vals.size() > 5 && getServer() != null)
{
world = getServer().getWorld((String)vals.get(5)); world = getServer().getWorld((String)vals.get(5));
} }
if (world == null) { if (world == null)
{
throw new Exception(); throw new Exception();
} }
return new Location( return new Location(
@ -521,18 +529,20 @@ public class User extends PlayerExtension implements Comparable<User>, IReplyTo
Map<String, Object> gdata = Essentials.getData(this); Map<String, Object> gdata = Essentials.getData(this);
List<Object> vals = (List<Object>)gdata.get("home"); List<Object> vals = (List<Object>)gdata.get("home");
World world = getServer().getWorlds().get(0); World world = getServer().getWorlds().get(0);
if (vals.size() > 5) { if (vals.size() > 5)
{
world = getServer().getWorld((String)vals.get(5)); world = getServer().getWorld((String)vals.get(5));
} }
if (world == null) { if (world == null)
{
throw new Exception(); throw new Exception();
} }
return new Location(world, return new Location(world,
((Number)vals.get(0)).doubleValue(), ((Number)vals.get(0)).doubleValue(),
((Number)vals.get(1)).doubleValue(), ((Number)vals.get(1)).doubleValue(),
((Number)vals.get(2)).doubleValue(), ((Number)vals.get(2)).doubleValue(),
((Number)vals.get(3)).floatValue(), ((Number)vals.get(3)).floatValue(),
((Number)vals.get(4)).floatValue()); ((Number)vals.get(4)).floatValue());
} }
catch (Throwable ex) catch (Throwable ex)
{ {
@ -552,10 +562,23 @@ public class User extends PlayerExtension implements Comparable<User>, IReplyTo
} }
catch (Throwable ex) catch (Throwable ex)
{ {
if (Essentials.getSettings().spawnIfNoHome())
{
try
{
respawn(Essentials.getStatic().spawn, null);
return;
}
catch (Throwable rex)
{
sendMessage("§cTeleport: " + rex.getMessage());
return;
}
}
sendMessage("§cTeleport: " + ex.getMessage()); sendMessage("§cTeleport: " + ex.getMessage());
return; return;
} }
if (delay <= 0 || isOp() || isAuthorized("essentials.teleport.timer.bypass")) if (delay <= 0 || isOp() || isAuthorized("essentials.teleport.timer.bypass"))
{ {
try try
@ -573,7 +596,9 @@ public class User extends PlayerExtension implements Comparable<User>, IReplyTo
} }
cancelTeleport(); cancelTeleport();
sendMessage("§7Teleportation will commence in " + Essentials.FormatTime(delay) + ". Don't move.");
sendMessage("§7Teleportation will commence in "
+ Essentials.FormatTime(delay) + ". Don't move.");
teleTimer = getServer().getScheduler().scheduleSyncRepeatingTask(Essentials.getStatic(), new TeleportTimer(this, delay) teleTimer = getServer().getScheduler().scheduleSyncRepeatingTask(Essentials.getStatic(), new TeleportTimer(this, delay)
{ {
public void DoTeleport() public void DoTeleport()
@ -588,7 +613,7 @@ public class User extends PlayerExtension implements Comparable<User>, IReplyTo
sendMessage("§cError: " + ex.getMessage()); sendMessage("§cError: " + ex.getMessage());
} }
} }
public void DoCancel() public void DoCancel()
{ {
cancelTeleport(); cancelTeleport();
@ -599,6 +624,9 @@ public class User extends PlayerExtension implements Comparable<User>, IReplyTo
public void teleportToHome() public void teleportToHome()
{ {
teleportToHome(null); teleportToHome(null);
} }
public void teleportToNow(Location loc) throws Exception public void teleportToNow(Location loc) throws Exception
@ -606,6 +634,9 @@ public class User extends PlayerExtension implements Comparable<User>, IReplyTo
cancelTeleport(); cancelTeleport();
lastLocation = getLocation(); lastLocation = getLocation();
getBase().teleport(getSafeDestination(loc)); getBase().teleport(getSafeDestination(loc));
} }
public void teleportToNow(Entity entity) public void teleportToNow(Entity entity)
@ -613,51 +644,81 @@ public class User extends PlayerExtension implements Comparable<User>, IReplyTo
cancelTeleport(); cancelTeleport();
lastLocation = getLocation(); lastLocation = getLocation();
getBase().teleport(entity); getBase().teleport(entity);
} }
public void teleportBack(final String chargeFor) public void teleportBack(final String chargeFor)
{ {
teleportTo(lastLocation, chargeFor); teleportTo(lastLocation, chargeFor);
} }
public void teleportBack() public void teleportBack()
{ {
teleportBack(null); teleportBack(null);
} }
public void dispose() public void dispose()
{ {
this.base = new OfflinePlayer(getName()); this.base = new OfflinePlayer(getName());
} }
public void charge(IEssentialsCommand cmd) throws Exception public void charge(IEssentialsCommand cmd) throws Exception
{ {
charge(cmd.getName()); charge(cmd.getName());
} }
public boolean getJustPortaled() public boolean getJustPortaled()
{ {
return justPortaled; return justPortaled;
} }
public void setJustPortaled(boolean value) public void setJustPortaled(boolean value)
{ {
justPortaled = value; justPortaled = value;
} }
public void setReplyTo(CommandSender user) public void setReplyTo(CommandSender user)
{ {
replyTo = user; replyTo = user;
} }
public CommandSender getReplyTo() public CommandSender getReplyTo()
{ {
return replyTo; return replyTo;
} }
public void setHome() public void setHome()
{ {
setHome(getLocation()); setHome(getLocation());
} }
public void setHome(Location home) public void setHome(Location home)
@ -672,91 +733,177 @@ public class User extends PlayerExtension implements Comparable<User>, IReplyTo
data.put("home", vals); data.put("home", vals);
flush(); flush();
setCompassTarget(home); setCompassTarget(
home);
} }
public String getNick() public String getNick()
{ {
Essentials ess = Essentials.getStatic(); Essentials ess = Essentials.getStatic();
String name = Essentials.getSettings().isCommandDisabled("nick") ? getName() : ess.readNickname(this); String name = Essentials.getSettings().isCommandDisabled("nick") ? getName() : ess.readNickname(this);
if (isOp() && ess.getConfiguration().getString("ops-name-color", "c").matches("^[0-9a-f]$")) {
if (isOp() && ess.getConfiguration().getString("ops-name-color", "c").matches("^[0-9a-f]$"))
{
name = "§" + ess.getConfiguration().getString("ops-name-color", "c") + name + "§f"; name = "§" + ess.getConfiguration().getString("ops-name-color", "c") + name + "§f";
} }
return name; return name;
} }
public void warpTo(String warp, final String chargeFor) throws Exception public void warpTo(String warp, final String chargeFor) throws Exception
{ {
lastLocation = getLocation(); lastLocation = getLocation();
Location loc = Essentials.getWarps().getWarp(warp); Location loc = Essentials.getWarps().getWarp(warp);
teleportTo(loc, chargeFor); teleportTo(
sendMessage("§7Warping to " + warp + "."); loc, chargeFor);
sendMessage(
"§7Warping to " + warp + ".");
} }
public void warpTo(String string) throws Exception public void warpTo(String string) throws Exception
{ {
warpTo(string, null); warpTo(string, null);
} }
public void clearNewFlag() public void clearNewFlag()
{ {
isNew = false; isNew = false;
} }
public int compareTo(User t) { public int compareTo(User t)
{
return ChatColor.stripColor(this.getDisplayName()).compareToIgnoreCase(ChatColor.stripColor(t.getDisplayName())); return ChatColor.stripColor(this.getDisplayName()).compareToIgnoreCase(ChatColor.stripColor(t.getDisplayName()));
} }
public Boolean canSpawnItem(int itemId) public Boolean canSpawnItem(int itemId)
{ {
return !Essentials.getSettings().itemSpawnBlacklist().contains(itemId); return !Essentials.getSettings().itemSpawnBlacklist().contains(itemId);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public List<Integer> getUnlimited() { public List<Integer> getUnlimited()
if (!data.containsKey("unlimited")) { {
if (!data.containsKey("unlimited"))
{
return new ArrayList<Integer>(); return new ArrayList<Integer>();
} }
return (List<Integer>)data.get("unlimited"); return (List<Integer>)data.get("unlimited");
} }
public boolean hasUnlimited(ItemStack stack) { public boolean hasUnlimited(ItemStack stack)
{
return getUnlimited().contains(stack.getTypeId()); return getUnlimited().contains(stack.getTypeId());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void setUnlimited(ItemStack stack, boolean state) { public void setUnlimited(ItemStack stack, boolean state)
{
List<Integer> items = getUnlimited(); List<Integer> items = getUnlimited();
if (items.contains(stack.getTypeId())) {
if (items.contains(stack.getTypeId()))
{
items.remove(Integer.valueOf(stack.getTypeId())); items.remove(Integer.valueOf(stack.getTypeId()));
} }
if (state) { if (state)
{
items.add(stack.getTypeId()); items.add(stack.getTypeId());
} }
data.put("unlimited", items); data.put("unlimited", items);
flush(); flush();
} }
public String getPowertool(ItemStack stack) { public String getPowertool(ItemStack stack)
if (!data.containsKey("powertools")) { {
if (!data.containsKey("powertools"))
{
return null; return null;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<Integer, String> tools = (Map<Integer, String>)data.get("powertools"); Map<Integer, String> tools = (Map<Integer, String>)data.get("powertools");
return tools.get(stack.getTypeId()); return tools.get(stack.getTypeId());
} }
public void setPowertool(ItemStack stack, String command) { public void setPowertool(ItemStack stack, String command)
{
Map<Integer, String> tools = new HashMap<Integer, String>(); Map<Integer, String> tools = new HashMap<Integer, String>();
if (data.containsKey("powertools")) {
if (data.containsKey("powertools"))
{
tools = (Map<Integer, String>)data.get("powertools"); tools = (Map<Integer, String>)data.get("powertools");
} }
if (command == null || command.trim().isEmpty()) { if (command == null || command.trim().isEmpty())
{
tools.remove(Integer.valueOf(stack.getTypeId())); tools.remove(Integer.valueOf(stack.getTypeId()));
return; return;
} }
tools.put(Integer.valueOf(stack.getTypeId()), command.trim()); tools.put(Integer.valueOf(stack.getTypeId()), command.trim());
data.put("powertools", tools); data.put("powertools", tools);
flush(); flush();
} }
} }

View File

@ -169,7 +169,8 @@ respawn-at-home: false
# 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. # 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.
bed-sethome: false bed-sethome: false
#if no home is set send you to spawn when /home is used
spawn-if-no-home: false
############################################################ ############################################################