Merge branch 'master' of github.com:essentials/Essentials

This commit is contained in:
okamosy 2011-08-26 21:03:25 +01:00
commit aa47499656
15 changed files with 150 additions and 67 deletions

View file

@ -1 +1,2 @@
DoNotUseThreads DoNotUseThreads
SignatureDeclareThrowsException

View file

@ -155,7 +155,7 @@ public class EssentialsConf extends Configuration
return getProperty(path) != null; return getProperty(path) != null;
} }
public Location getLocation(String path, Server server) public Location getLocation(String path, Server server) throws Exception
{ {
String worldName = getString((path != null ? path + "." : "") + "world"); String worldName = getString((path != null ? path + "." : "") + "world");
if (worldName == null || worldName.isEmpty()) if (worldName == null || worldName.isEmpty())
@ -165,7 +165,7 @@ public class EssentialsConf extends Configuration
World world = server.getWorld(worldName); World world = server.getWorld(worldName);
if (world == null) if (world == null)
{ {
return null; throw new Exception(Util.i18n("invalidWorld"));
} }
return new Location(world, return new Location(world,
getDouble((path != null ? path + "." : "") + "x", 0), getDouble((path != null ? path + "." : "") + "x", 0),

View file

@ -37,8 +37,11 @@ public class EssentialsEntityListener extends EntityListener
User attacker = ess.getUser(eAttack); User attacker = ess.getUser(eAttack);
ItemStack is = attacker.getItemInHand(); ItemStack is = attacker.getItemInHand();
List<String> commandList = attacker.getPowertool(is); List<String> commandList = attacker.getPowertool(is);
for(String command : commandList) if (commandList != null && !commandList.isEmpty())
{ {
for (String command : commandList)
{
if (command != null && !command.isEmpty()) if (command != null && !command.isEmpty())
{ {
attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName())); attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName()));
@ -48,6 +51,7 @@ public class EssentialsEntityListener extends EntityListener
} }
} }
} }
}
if (event instanceof EntityDamageEvent || event instanceof EntityDamageByBlockEvent || event instanceof EntityDamageByProjectileEvent) if (event instanceof EntityDamageEvent || event instanceof EntityDamageByBlockEvent || event instanceof EntityDamageByProjectileEvent)
{ {

View file

@ -280,10 +280,11 @@ public class EssentialsUpgrade
{ {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final String defworld = (String)config.getProperty("home.default"); final String defworld = (String)config.getProperty("home.default");
final Location defloc = config.getLocation("home.worlds." + defworld, ess.getServer()); final Location defloc = getFakeLocation(config,"home.worlds." + defworld);
if (defloc != null)
; {
config.setProperty("homes.home", defloc); config.setProperty("homes.home", defloc);
}
List<String> worlds = config.getKeys("home.worlds"); List<String> worlds = config.getKeys("home.worlds");
Location loc; Location loc;
@ -299,7 +300,7 @@ public class EssentialsUpgrade
{ {
continue; continue;
} }
loc = config.getLocation("home.worlds." + world, ess.getServer()); loc = getFakeLocation(config, "home.worlds." + world);
if (loc == null) if (loc == null)
{ {
continue; continue;
@ -569,6 +570,25 @@ public class EssentialsUpgrade
} }
return null; return null;
} }
public Location getFakeLocation(EssentialsConf config, String path)
{
String worldName = config.getString((path != null ? path + "." : "") + "world");
if (worldName == null || worldName.isEmpty())
{
return null;
}
World world = getFakeWorld(worldName);
if (world == null)
{
return null;
}
return new Location(world,
config.getDouble((path != null ? path + "." : "") + "x", 0),
config.getDouble((path != null ? path + "." : "") + "y", 0),
config.getDouble((path != null ? path + "." : "") + "z", 0),
(float)config.getDouble((path != null ? path + "." : "") + "yaw", 0),
(float)config.getDouble((path != null ? path + "." : "") + "pitch", 0));
}
public void beforeSettings() public void beforeSettings()
{ {

View file

@ -45,9 +45,9 @@ public interface IUser
void setLastLocation(); void setLastLocation();
Location getHome(String name); Location getHome(String name) throws Exception;
Location getHome(Location loc); Location getHome(Location loc) throws Exception;
String getName(); String getName();

View file

@ -193,7 +193,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
return !ess.getSettings().itemSpawnBlacklist().contains(itemId); return !ess.getSettings().itemSpawnBlacklist().contains(itemId);
} }
public Location getHome() public Location getHome() throws Exception
{ {
return getHome(getHomes().get(0)); return getHome(getHomes().get(0));
} }

View file

@ -106,7 +106,7 @@ public abstract class UserData extends PlayerExtension implements IConf
} }
public Location getHome(String name) public Location getHome(String name) throws Exception
{ {
Location loc = config.getLocation("homes." + name, getServer()); Location loc = config.getLocation("homes." + name, getServer());
if (loc == null) if (loc == null)
@ -128,7 +128,7 @@ public abstract class UserData extends PlayerExtension implements IConf
return loc; return loc;
} }
public Location getHome(Location world) public Location getHome(Location world) throws Exception
{ {
Location loc; Location loc;
for (String home : getHomes()) for (String home : getHomes())
@ -166,9 +166,10 @@ public abstract class UserData extends PlayerExtension implements IConf
config.removeProperty("homes." + name); config.removeProperty("homes." + name);
config.save(); config.save();
} }
else { else
{
//TODO: move this message to messages file //TODO: move this message to messages file
throw new Exception("Home "+name+" doesn't exist"); throw new Exception("Home " + name + " doesn't exist");
} }
} }
@ -260,9 +261,16 @@ public abstract class UserData extends PlayerExtension implements IConf
private Location lastLocation; private Location lastLocation;
private Location _getLastLocation() private Location _getLastLocation()
{
try
{ {
return config.getLocation("lastlocation", getServer()); return config.getLocation("lastlocation", getServer());
} }
catch (Exception e)
{
return null;
}
}
public Location getLastLocation() public Location getLastLocation()
{ {

View file

@ -16,26 +16,32 @@ public class Commanddelhome extends EssentialsCommand
@Override @Override
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{ {
User user; //Allowing both formats /delhome khobbits house | /delhome khobbits:house
final String[] nameParts = args[0].split(":");
if (nameParts[0].length() != args[0].length())
{
args = nameParts;
}
User user = ess.getUser(sender);
String name; String name;
if (args.length < 1) if (args.length < 1)
{ {
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
else if (args.length < 2) else if (args.length > 1 && (user == null || user.isAuthorized("essentials.delhome.others")))
{
user = getPlayer(server, args, 0);
name = args[1];
}
else
{ {
user = ess.getUser(sender);
if (user == null) if (user == null)
{ {
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
name = args[0]; name = args[0];
} }
else
{
user = getPlayer(server, args, 0);
name = args[1];
}
user.delHome(name.toLowerCase()); user.delHome(name.toLowerCase());
sender.sendMessage(Util.format("deleteHome", name)); sender.sendMessage(Util.format("deleteHome", name));
} }

View file

@ -25,7 +25,7 @@ public class Commandhome extends EssentialsCommand
if (args.length > 0) if (args.length > 0)
{ {
nameParts = args[0].split(":"); nameParts = args[0].split(":");
if (nameParts[0].length() == args[0].length()) if (nameParts[0].length() == args[0].length() || !user.isAuthorized("essentials.home.others"))
{ {
homeName = nameParts[0]; homeName = nameParts[0];
} }

View file

@ -17,6 +17,13 @@ public class Commandsethome extends EssentialsCommand
{ {
if (args.length > 0) if (args.length > 0)
{ {
//Allowing both formats /sethome khobbits house | /sethome khobbits:house
final String[] nameParts = args[0].split(":");
if (nameParts[0].length() != args[0].length())
{
args = nameParts;
}
if (args.length < 2) if (args.length < 2)
{ {
if (user.isAuthorized("essentials.sethome.multiple")) if (user.isAuthorized("essentials.sethome.multiple"))
@ -46,7 +53,12 @@ public class Commandsethome extends EssentialsCommand
{ {
throw new Exception(Util.i18n("playerNotFound")); throw new Exception(Util.i18n("playerNotFound"));
} }
usersHome.setHome(args[1].toLowerCase(), user.getLocation()); String name = args[1].toLowerCase();
if (!user.isAuthorized("essentials.sethome.multiple"))
{
name = "home";
}
usersHome.setHome(name, user.getLocation());
} }
} }
} }

View file

@ -189,7 +189,12 @@ public class EssentialsSign
return true; return true;
} }
public boolean onBlockPush(Block block, IEssentials ess) public boolean onBlockIgnite(final Block block, final IEssentials ess)
{
return true;
}
public boolean onBlockPush(final Block block, final IEssentials ess)
{ {
return true; return true;
} }

View file

@ -184,9 +184,24 @@ public class SignBlockListener extends BlockListener
return; return;
} }
if (protectSignsAndBlocks(event.getBlock(), event.getPlayer())) final Block block = event.getBlock();
if (((block.getType() == Material.WALL_SIGN
|| block.getType() == Material.SIGN_POST)
&& EssentialsSign.isValidSign(new EssentialsSign.BlockSign(block)))
|| EssentialsSign.checkIfBlockBreaksSigns(block))
{ {
event.setCancelled(true); event.setCancelled(true);
return;
}
for (Signs signs : Signs.values())
{
final EssentialsSign sign = signs.getSign();
if (sign.getBlocks().contains(block.getType())
&& !sign.onBlockIgnite(block, ess))
{
event.setCancelled(true);
return;
}
} }
} }

View file

@ -313,6 +313,14 @@ public class SignProtection extends EssentialsSign
return state == SignProtectionState.NOSIGN; return state == SignProtectionState.NOSIGN;
} }
@Override
public boolean onBlockIgnite(final Block block, final IEssentials ess)
{
final SignProtectionState state = isBlockProtected(block, null, null, false);
return state == SignProtectionState.NOSIGN;
}
@Override @Override
public boolean onBlockPush(final Block block, final IEssentials ess) public boolean onBlockPush(final Block block, final IEssentials ess)
{ {

View file

@ -54,6 +54,8 @@ 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); Location home = user2.getHome(loc);
assertEquals(loc.getWorld().getName(), home.getWorld().getName()); assertEquals(loc.getWorld().getName(), home.getWorld().getName());
assertEquals(loc.getX(), home.getX()); assertEquals(loc.getX(), home.getX());
@ -62,6 +64,12 @@ public class UserTest extends TestCase
assertEquals(loc.getYaw(), home.getYaw()); assertEquals(loc.getYaw(), home.getYaw());
assertEquals(loc.getPitch(), home.getPitch()); assertEquals(loc.getPitch(), home.getPitch());
} }
catch (Exception ex)
{
fail("Exception");
}
}
public void testMoney() public void testMoney()
{ {

View file

@ -1,6 +1,5 @@
package com.earth2me.essentials.protect; package com.earth2me.essentials.protect;
import com.earth2me.essentials.EssentialsBlockListener;
import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import java.util.HashSet; import java.util.HashSet;
@ -21,11 +20,11 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Fireball; import org.bukkit.entity.Fireball;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
@ -47,7 +46,7 @@ public class EssentialsProtectEntityListener extends EntityListener
} }
@Override @Override
public void onEntityDamage(EntityDamageEvent event) public void onEntityDamage(final EntityDamageEvent event)
{ {
if (event.isCancelled()) if (event.isCancelled())
{ {
@ -139,18 +138,21 @@ public class EssentialsProtectEntityListener extends EntityListener
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
}
if (event instanceof EntityDamageByProjectileEvent if (edEvent.getDamager() instanceof Projectile
&& target instanceof Player && target instanceof Player
&& prot.getSettingBool(ProtectConfig.disable_projectiles) && ((prot.getSettingBool(ProtectConfig.disable_projectiles)
&& !(user.isAuthorized("essentials.protect.damage.projectiles") && !(user.isAuthorized("essentials.protect.damage.projectiles")
&& !user.isAuthorized("essentials.protect.damage.disable"))) && !user.isAuthorized("essentials.protect.damage.disable")))
|| (((Projectile)edEvent.getDamager()).getShooter() instanceof Player
&& prot.getSettingBool(ProtectConfig.disable_pvp)
&& (!user.isAuthorized("essentials.protect.pvp")
|| !ess.getUser(((Projectile)edEvent.getDamager()).getShooter()).isAuthorized("essentials.protect.pvp")))))
{ {
event.setCancelled(true); event.setCancelled(true);
((EntityDamageByProjectileEvent)event).setBounce(true);
return; return;
} }
}
final DamageCause cause = event.getCause(); final DamageCause cause = event.getCause();
if (target instanceof Player) if (target instanceof Player)
@ -201,7 +203,7 @@ public class EssentialsProtectEntityListener extends EntityListener
} }
@Override @Override
public void onEntityExplode(EntityExplodeEvent event) public void onEntityExplode(final EntityExplodeEvent event)
{ {
if (event.isCancelled()) if (event.isCancelled())
{ {
@ -279,12 +281,6 @@ public class EssentialsProtectEntityListener extends EntityListener
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
/*if (EssentialsBlockListener.protectedBlocks.contains(block.getType())
&& EssentialsBlockListener.isBlockProtected(block))
{
event.setCancelled(true);
return;
}*/
} }
} }