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,13 +37,17 @@ 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())
{ {
if (command != null && !command.isEmpty()) for (String command : commandList)
{ {
attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName()));
event.setCancelled(true); if (command != null && !command.isEmpty())
return; {
attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName()));
event.setCancelled(true);
return;
}
} }
} }
} }

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");
} }
} }
@ -261,7 +262,14 @@ public abstract class UserData extends PlayerExtension implements IConf
private Location _getLastLocation() private Location _getLastLocation()
{ {
return config.getLocation("lastlocation", getServer()); try
{
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,16 +17,23 @@ 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"))
{ {
if ((user.isAuthorized("essentials.sethome.multiple.unlimited")) || (user.getHomes().size() < ess.getSettings().getMultipleHomes()) if ((user.isAuthorized("essentials.sethome.multiple.unlimited")) || (user.getHomes().size() < ess.getSettings().getMultipleHomes())
|| (user.getHomes().contains(args[0].toLowerCase()))) || (user.getHomes().contains(args[0].toLowerCase())))
{ {
user.setHome(args[0].toLowerCase()); user.setHome(args[0].toLowerCase());
} }
else else
{ {
throw new Exception(Util.format("maxHomes", ess.getSettings().getMultipleHomes())); throw new Exception(Util.format("maxHomes", ess.getSettings().getMultipleHomes()));
} }
@ -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

@ -188,8 +188,13 @@ public class EssentialsSign
{ {
return true; return true;
} }
public boolean onBlockIgnite(final Block block, final IEssentials ess)
{
return true;
}
public boolean onBlockPush(Block block, IEssentials ess) 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

@ -312,6 +312,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

@ -46,7 +46,7 @@ public class UserTest extends TestCase
OfflinePlayer base1alt = server.createPlayer(base1.getName(), ess); OfflinePlayer base1alt = server.createPlayer(base1.getName(), ess);
assertEquals(base1alt, ess.getUser(base1alt).getBase()); assertEquals(base1alt, ess.getUser(base1alt).getBase());
} }
public void testHome() public void testHome()
{ {
User user = ess.getUser(base1); User user = ess.getUser(base1);
@ -54,13 +54,21 @@ 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);
Location home = user2.getHome(loc); try
assertEquals(loc.getWorld().getName(), home.getWorld().getName()); {
assertEquals(loc.getX(), home.getX()); Location home = user2.getHome(loc);
assertEquals(loc.getY(), home.getY()); assertEquals(loc.getWorld().getName(), home.getWorld().getName());
assertEquals(loc.getZ(), home.getZ()); assertEquals(loc.getX(), home.getX());
assertEquals(loc.getYaw(), home.getYaw()); assertEquals(loc.getY(), home.getY());
assertEquals(loc.getPitch(), home.getPitch()); assertEquals(loc.getZ(), home.getZ());
assertEquals(loc.getYaw(), home.getYaw());
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())
{ {
@ -102,7 +101,7 @@ public class EssentialsProtectEntityListener extends EntityListener
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
//Creeper explode prevention //Creeper explode prevention
if (eAttack instanceof Creeper && prot.getSettingBool(ProtectConfig.prevent_creeper_explosion) if (eAttack instanceof Creeper && prot.getSettingBool(ProtectConfig.prevent_creeper_explosion)
&& !(target instanceof Player && !(target instanceof Player
@ -121,7 +120,7 @@ public class EssentialsProtectEntityListener extends EntityListener
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (eAttack instanceof Fireball && prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg) if (eAttack instanceof Fireball && prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg)
&& !(target instanceof Player && !(target instanceof Player
&& user.isAuthorized("essentials.protect.damage.fireball") && user.isAuthorized("essentials.protect.damage.fireball")
@ -130,7 +129,7 @@ public class EssentialsProtectEntityListener extends EntityListener
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (eAttack instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_playerdmg) if (eAttack instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_playerdmg)
&& !(target instanceof Player && !(target instanceof Player
&& user.isAuthorized("essentials.protect.damage.tnt") && user.isAuthorized("essentials.protect.damage.tnt")
@ -139,17 +138,20 @@ 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
event.setCancelled(true); && prot.getSettingBool(ProtectConfig.disable_pvp)
((EntityDamageByProjectileEvent)event).setBounce(true); && (!user.isAuthorized("essentials.protect.pvp")
return; || !ess.getUser(((Projectile)edEvent.getDamager()).getShooter()).isAuthorized("essentials.protect.pvp")))))
{
event.setCancelled(true);
return;
}
} }
final DamageCause cause = event.getCause(); final DamageCause cause = event.getCause();
@ -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())
{ {
@ -240,7 +242,7 @@ public class EssentialsProtectEntityListener extends EntityListener
} }
((CraftServer)ess.getServer()).getHandle().sendPacketNearby(loc.getX(), loc.getY(), loc.getZ(), 64.0D, ((CraftWorld)loc.getWorld()).getHandle().worldProvider.dimension, ((CraftServer)ess.getServer()).getHandle().sendPacketNearby(loc.getX(), loc.getY(), loc.getZ(), 64.0D, ((CraftWorld)loc.getWorld()).getHandle().worldProvider.dimension,
new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0f, set)); new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0f, set));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -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;
}*/
} }
} }
@ -340,7 +336,7 @@ public class EssentialsProtectEntityListener extends EntityListener
public void onExplosionPrime(ExplosionPrimeEvent event) public void onExplosionPrime(ExplosionPrimeEvent event)
{ {
if (event.getEntity() instanceof CraftFireball if (event.getEntity() instanceof CraftFireball
&& prot.getSettingBool(ProtectConfig.prevent_fireball_fire)) && prot.getSettingBool(ProtectConfig.prevent_fireball_fire))
{ {
event.setFire(false); event.setFire(false);
} }