mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-01 12:20:59 +02:00
Merge branch 'master' of github.com:essentials/Essentials
This commit is contained in:
@@ -1 +1,2 @@
|
||||
DoNotUseThreads
|
||||
SignatureDeclareThrowsException
|
||||
|
@@ -155,7 +155,7 @@ public class EssentialsConf extends Configuration
|
||||
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");
|
||||
if (worldName == null || worldName.isEmpty())
|
||||
@@ -165,7 +165,7 @@ public class EssentialsConf extends Configuration
|
||||
World world = server.getWorld(worldName);
|
||||
if (world == null)
|
||||
{
|
||||
return null;
|
||||
throw new Exception(Util.i18n("invalidWorld"));
|
||||
}
|
||||
return new Location(world,
|
||||
getDouble((path != null ? path + "." : "") + "x", 0),
|
||||
|
@@ -37,13 +37,17 @@ public class EssentialsEntityListener extends EntityListener
|
||||
User attacker = ess.getUser(eAttack);
|
||||
ItemStack is = attacker.getItemInHand();
|
||||
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);
|
||||
return;
|
||||
|
||||
if (command != null && !command.isEmpty())
|
||||
{
|
||||
attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName()));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -280,10 +280,11 @@ public class EssentialsUpgrade
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
final String defworld = (String)config.getProperty("home.default");
|
||||
final Location defloc = config.getLocation("home.worlds." + defworld, ess.getServer());
|
||||
|
||||
;
|
||||
config.setProperty("homes.home", defloc);
|
||||
final Location defloc = getFakeLocation(config,"home.worlds." + defworld);
|
||||
if (defloc != null)
|
||||
{
|
||||
config.setProperty("homes.home", defloc);
|
||||
}
|
||||
|
||||
List<String> worlds = config.getKeys("home.worlds");
|
||||
Location loc;
|
||||
@@ -299,7 +300,7 @@ public class EssentialsUpgrade
|
||||
{
|
||||
continue;
|
||||
}
|
||||
loc = config.getLocation("home.worlds." + world, ess.getServer());
|
||||
loc = getFakeLocation(config, "home.worlds." + world);
|
||||
if (loc == null)
|
||||
{
|
||||
continue;
|
||||
@@ -569,6 +570,25 @@ public class EssentialsUpgrade
|
||||
}
|
||||
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()
|
||||
{
|
||||
|
@@ -45,9 +45,9 @@ public interface IUser
|
||||
|
||||
void setLastLocation();
|
||||
|
||||
Location getHome(String name);
|
||||
Location getHome(String name) throws Exception;
|
||||
|
||||
Location getHome(Location loc);
|
||||
Location getHome(Location loc) throws Exception;
|
||||
|
||||
String getName();
|
||||
|
||||
|
@@ -193,7 +193,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
return !ess.getSettings().itemSpawnBlacklist().contains(itemId);
|
||||
}
|
||||
|
||||
public Location getHome()
|
||||
public Location getHome() throws Exception
|
||||
{
|
||||
return getHome(getHomes().get(0));
|
||||
}
|
||||
|
@@ -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());
|
||||
if (loc == null)
|
||||
@@ -128,7 +128,7 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
return loc;
|
||||
}
|
||||
|
||||
public Location getHome(Location world)
|
||||
public Location getHome(Location world) throws Exception
|
||||
{
|
||||
Location loc;
|
||||
for (String home : getHomes())
|
||||
@@ -166,9 +166,10 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
config.removeProperty("homes." + name);
|
||||
config.save();
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
//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()
|
||||
{
|
||||
return config.getLocation("lastlocation", getServer());
|
||||
try
|
||||
{
|
||||
return config.getLocation("lastlocation", getServer());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Location getLastLocation()
|
||||
|
@@ -16,26 +16,32 @@ public class Commanddelhome extends EssentialsCommand
|
||||
@Override
|
||||
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;
|
||||
if (args.length < 1)
|
||||
{
|
||||
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)
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
name = args[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
user = getPlayer(server, args, 0);
|
||||
name = args[1];
|
||||
}
|
||||
user.delHome(name.toLowerCase());
|
||||
sender.sendMessage(Util.format("deleteHome", name));
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ public class Commandhome extends EssentialsCommand
|
||||
if (args.length > 0)
|
||||
{
|
||||
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];
|
||||
}
|
||||
|
@@ -17,16 +17,23 @@ public class Commandsethome extends EssentialsCommand
|
||||
{
|
||||
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 (user.isAuthorized("essentials.sethome.multiple"))
|
||||
{
|
||||
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());
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
throw new Exception(Util.format("maxHomes", ess.getSettings().getMultipleHomes()));
|
||||
}
|
||||
@@ -46,7 +53,12 @@ public class Commandsethome extends EssentialsCommand
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -188,8 +188,13 @@ public class EssentialsSign
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@@ -184,9 +184,24 @@ public class SignBlockListener extends BlockListener
|
||||
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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -312,6 +312,14 @@ public class SignProtection extends EssentialsSign
|
||||
|
||||
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
|
||||
public boolean onBlockPush(final Block block, final IEssentials ess)
|
||||
|
@@ -46,7 +46,7 @@ public class UserTest extends TestCase
|
||||
OfflinePlayer base1alt = server.createPlayer(base1.getName(), ess);
|
||||
assertEquals(base1alt, ess.getUser(base1alt).getBase());
|
||||
}
|
||||
|
||||
|
||||
public void testHome()
|
||||
{
|
||||
User user = ess.getUser(base1);
|
||||
@@ -54,13 +54,21 @@ public class UserTest extends TestCase
|
||||
user.setHome();
|
||||
OfflinePlayer base2 = server.createPlayer(base1.getName(), ess);
|
||||
User user2 = ess.getUser(base2);
|
||||
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());
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testMoney()
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.earth2me.essentials.protect;
|
||||
|
||||
import com.earth2me.essentials.EssentialsBlockListener;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import java.util.HashSet;
|
||||
@@ -21,11 +20,11 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Fireball;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
@@ -47,7 +46,7 @@ public class EssentialsProtectEntityListener extends EntityListener
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityDamage(EntityDamageEvent event)
|
||||
public void onEntityDamage(final EntityDamageEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
{
|
||||
@@ -102,7 +101,7 @@ public class EssentialsProtectEntityListener extends EntityListener
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//Creeper explode prevention
|
||||
if (eAttack instanceof Creeper && prot.getSettingBool(ProtectConfig.prevent_creeper_explosion)
|
||||
&& !(target instanceof Player
|
||||
@@ -121,7 +120,7 @@ public class EssentialsProtectEntityListener extends EntityListener
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (eAttack instanceof Fireball && prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg)
|
||||
&& !(target instanceof Player
|
||||
&& user.isAuthorized("essentials.protect.damage.fireball")
|
||||
@@ -130,7 +129,7 @@ public class EssentialsProtectEntityListener extends EntityListener
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (eAttack instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_playerdmg)
|
||||
&& !(target instanceof Player
|
||||
&& user.isAuthorized("essentials.protect.damage.tnt")
|
||||
@@ -139,17 +138,20 @@ public class EssentialsProtectEntityListener extends EntityListener
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (event instanceof EntityDamageByProjectileEvent
|
||||
&& target instanceof Player
|
||||
&& prot.getSettingBool(ProtectConfig.disable_projectiles)
|
||||
&& !(user.isAuthorized("essentials.protect.damage.projectiles")
|
||||
&& !user.isAuthorized("essentials.protect.damage.disable")))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
((EntityDamageByProjectileEvent)event).setBounce(true);
|
||||
return;
|
||||
if (edEvent.getDamager() instanceof Projectile
|
||||
&& target instanceof Player
|
||||
&& ((prot.getSettingBool(ProtectConfig.disable_projectiles)
|
||||
&& !(user.isAuthorized("essentials.protect.damage.projectiles")
|
||||
&& !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);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final DamageCause cause = event.getCause();
|
||||
@@ -201,7 +203,7 @@ public class EssentialsProtectEntityListener extends EntityListener
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityExplode(EntityExplodeEvent event)
|
||||
public void onEntityExplode(final EntityExplodeEvent event)
|
||||
{
|
||||
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,
|
||||
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);
|
||||
return;
|
||||
}
|
||||
@@ -279,12 +281,6 @@ public class EssentialsProtectEntityListener extends EntityListener
|
||||
event.setCancelled(true);
|
||||
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)
|
||||
{
|
||||
if (event.getEntity() instanceof CraftFireball
|
||||
&& prot.getSettingBool(ProtectConfig.prevent_fireball_fire))
|
||||
&& prot.getSettingBool(ProtectConfig.prevent_fireball_fire))
|
||||
{
|
||||
event.setFire(false);
|
||||
}
|
||||
|
Reference in New Issue
Block a user