mirror of
https://github.com/essentials/Essentials.git
synced 2025-01-19 06:08:00 +01:00
[trunk] Protect, more merges
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1586 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
parent
c6ab274f2e
commit
3c05ce0d63
@ -50,8 +50,6 @@ public class EssentialsProtect extends JavaPlugin implements IConf
|
||||
|
||||
public void onEnable()
|
||||
{
|
||||
|
||||
|
||||
ess = Essentials.getStatic();
|
||||
ess.getDependancyChecker().checkProtectDependancies();
|
||||
PluginManager pm = this.getServer().getPluginManager();
|
||||
@ -90,7 +88,6 @@ public class EssentialsProtect extends JavaPlugin implements IConf
|
||||
{
|
||||
genSettings.clear();
|
||||
dataSettings.clear();
|
||||
|
||||
blockListener = null;
|
||||
playerListener = null;
|
||||
entityListener = null;
|
||||
|
@ -110,6 +110,13 @@ public class EssentialsProtectBlockListener extends BlockListener
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (event.getBlock().getType() == Material.OBSIDIAN ||
|
||||
event.getBlock().getFace(BlockFace.DOWN).getType() == Material.OBSIDIAN)
|
||||
{
|
||||
event.setCancelled(EssentialsProtect.guardSettings.get("protect.prevent.portal-creation"));
|
||||
return;
|
||||
}
|
||||
|
||||
if ((event.getCause().equals(BlockIgniteEvent.IgniteCause.SPREAD)))
|
||||
{
|
||||
event.setCancelled(EssentialsProtect.guardSettings.get("protect.prevent.fire-spread"));
|
||||
@ -127,6 +134,11 @@ public class EssentialsProtectBlockListener extends BlockListener
|
||||
event.setCancelled(EssentialsProtect.guardSettings.get("protect.prevent.lava-fire-spread"));
|
||||
return;
|
||||
}
|
||||
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.LIGHTNING))
|
||||
{
|
||||
event.setCancelled(EssentialsProtect.guardSettings.get("protect.prevent.lightning-fire-spread"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.earth2me.essentials.protect;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.EssentialsBlockListener;
|
||||
import com.earth2me.essentials.User;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@ -8,7 +9,9 @@ import java.util.List;
|
||||
import net.minecraft.server.ChunkPosition;
|
||||
import net.minecraft.server.Packet60Explosion;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
@ -25,6 +28,8 @@ import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityListener;
|
||||
import org.bukkit.event.entity.EntityTargetEvent;
|
||||
import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
|
||||
|
||||
|
||||
public class EssentialsProtectEntityListener extends EntityListener
|
||||
@ -39,22 +44,34 @@ public class EssentialsProtectEntityListener extends EntityListener
|
||||
@Override
|
||||
public void onEntityDamage(EntityDamageEvent event)
|
||||
{
|
||||
if (event.isCancelled()) return;
|
||||
if (event.isCancelled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event instanceof EntityDamageByBlockEvent)
|
||||
{
|
||||
DamageCause cause = event.getCause();
|
||||
|
||||
if (EssentialsProtect.playerSettings.get("protect.disable.contactdmg") && cause == DamageCause.CONTACT)
|
||||
if (EssentialsProtect.playerSettings.get("protect.disable.contactdmg") && cause == DamageCause.CONTACT
|
||||
&& !(event.getEntity() instanceof Player
|
||||
&& Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.contact")
|
||||
&& !Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (EssentialsProtect.playerSettings.get("protect.disable.lavadmg") && cause == DamageCause.LAVA)
|
||||
if (EssentialsProtect.playerSettings.get("protect.disable.lavadmg") && cause == DamageCause.LAVA
|
||||
&& !(event.getEntity() instanceof Player
|
||||
&& Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.lava")
|
||||
&& !Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (EssentialsProtect.guardSettings.get("protect.prevent.tnt-explosion") && cause == DamageCause.BLOCK_EXPLOSION)
|
||||
if (EssentialsProtect.guardSettings.get("protect.prevent.tnt-explosion") && cause == DamageCause.BLOCK_EXPLOSION
|
||||
&& !(event.getEntity() instanceof Player
|
||||
&& Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.tnt")
|
||||
&& !Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -85,13 +102,19 @@ public class EssentialsProtectEntityListener extends EntityListener
|
||||
//Creeper explode prevention
|
||||
if (eAttack != null && eAttack instanceof Monster)
|
||||
{
|
||||
if (eAttack instanceof Creeper && EssentialsProtect.guardSettings.get("protect.prevent.creeper-explosion"))
|
||||
if (eAttack instanceof Creeper && EssentialsProtect.guardSettings.get("protect.prevent.creeper-explosion")
|
||||
&& !(event.getEntity() instanceof Player
|
||||
&& Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.creeper")
|
||||
&& !Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (eAttack instanceof Creeper && EssentialsProtect.guardSettings.get("protect.prevent.creeper-playerdamage"))
|
||||
if (eAttack instanceof Creeper && EssentialsProtect.guardSettings.get("protect.prevent.creeper-playerdamage")
|
||||
&& !(event.getEntity() instanceof Player
|
||||
&& Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.creeper")
|
||||
&& !Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -101,9 +124,12 @@ public class EssentialsProtectEntityListener extends EntityListener
|
||||
|
||||
if (event instanceof EntityDamageByProjectileEvent)
|
||||
{
|
||||
if (event.getEntity() instanceof Player)
|
||||
if (event.getEntity() instanceof Player
|
||||
&& EssentialsProtect.playerSettings.get("protect.disable.projectiles")
|
||||
&& !Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.projectiles")
|
||||
&& !Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable"))
|
||||
{
|
||||
event.setCancelled(EssentialsProtect.playerSettings.get("protect.disable.projectiles"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -112,24 +138,39 @@ public class EssentialsProtectEntityListener extends EntityListener
|
||||
Entity casualty = event.getEntity();
|
||||
if (casualty instanceof Player)
|
||||
{
|
||||
if (EssentialsProtect.playerSettings.get("protect.disable.fall") && cause == DamageCause.FALL)
|
||||
if (EssentialsProtect.playerSettings.get("protect.disable.fall") && cause == DamageCause.FALL
|
||||
&& !(Essentials.getStatic().getUser(casualty).isAuthorized("essentials.protect.damage.fall")
|
||||
&& !Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (EssentialsProtect.playerSettings.get("protect.disable.suffocate") && cause == DamageCause.SUFFOCATION)
|
||||
if (EssentialsProtect.playerSettings.get("protect.disable.suffocate") && cause == DamageCause.SUFFOCATION
|
||||
&& !(Essentials.getStatic().getUser(casualty).isAuthorized("essentials.protect.damage.suffocation")
|
||||
&& !Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (EssentialsProtect.playerSettings.get("protect.disable.firedmg") && (cause == DamageCause.FIRE
|
||||
|| cause == DamageCause.FIRE_TICK))
|
||||
|| cause == DamageCause.FIRE_TICK)
|
||||
&& !(parent.ess.getUser(casualty).isAuthorized("essentials.protect.damage.fire")
|
||||
&& !parent.ess.getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (EssentialsProtect.playerSettings.get("protect.disable.drown") && cause == DamageCause.DROWNING)
|
||||
if (EssentialsProtect.playerSettings.get("protect.disable.drown") && cause == DamageCause.DROWNING
|
||||
&& !(parent.ess.getUser(casualty).isAuthorized("essentials.protect.damage.drowning")
|
||||
&& !parent.ess.getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (EssentialsProtect.playerSettings.get("protect.disable.lightning") && cause == DamageCause.LIGHTNING
|
||||
&& !(parent.ess.getUser(casualty).isAuthorized("essentials.protect.damage.lightning")
|
||||
&& !parent.ess.getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -140,7 +181,10 @@ public class EssentialsProtectEntityListener extends EntityListener
|
||||
@Override
|
||||
public void onEntityExplode(EntityExplodeEvent event)
|
||||
{
|
||||
if (event.isCancelled()) return;
|
||||
if (event.isCancelled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.getEntity() instanceof LivingEntity)
|
||||
{
|
||||
//Nicccccccccce plaaacccccccccce..
|
||||
@ -188,18 +232,71 @@ public class EssentialsProtectEntityListener extends EntityListener
|
||||
return;
|
||||
}
|
||||
}
|
||||
// This code will prevent explosions near protected rails, signs or protected chests
|
||||
// TODO: Use protect db instead of this code
|
||||
for (Block block : event.blockList())
|
||||
{
|
||||
if ((block.getType() == Material.RAILS || block.getFace(BlockFace.UP).getType() == Material.RAILS) && EssentialsProtect.genSettings.get("protect.protect.rails"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if ((block.getType() == Material.WALL_SIGN
|
||||
|| block.getFace(BlockFace.NORTH).getType() == Material.WALL_SIGN
|
||||
|| block.getFace(BlockFace.EAST).getType() == Material.WALL_SIGN
|
||||
|| block.getFace(BlockFace.SOUTH).getType() == Material.WALL_SIGN
|
||||
|| block.getFace(BlockFace.WEST).getType() == Material.WALL_SIGN
|
||||
|| block.getType() == Material.SIGN_POST
|
||||
|| block.getFace(BlockFace.UP).getType() == Material.SIGN_POST)
|
||||
&& EssentialsProtect.genSettings.get("protect.protect.signs"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (EssentialsBlockListener.protectedBlocks.contains(block.getType())
|
||||
&& EssentialsBlockListener.isBlockProtected(block))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event)
|
||||
{
|
||||
if (event.getEntity() instanceof CraftPlayer || event.isCancelled()){ return;}
|
||||
final String creatureName = event.getCreatureType().toString().toLowerCase();
|
||||
if (event.getEntity() instanceof CraftPlayer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.isCancelled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
String creatureName = event.getCreatureType().toString().toLowerCase();
|
||||
if (creatureName == null || creatureName.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (EssentialsProtect.guardSettings.get("protect.prevent.spawn." + creatureName))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityTarget(EntityTargetEvent event)
|
||||
{
|
||||
if (!(event.getTarget() instanceof Player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
User user = Essentials.getStatic().getUser(event.getTarget());
|
||||
if ((event.getReason() == TargetReason.CLOSEST_PLAYER
|
||||
|| event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY
|
||||
|| event.getReason() == TargetReason.PIG_ZOMBIE_TARGET)
|
||||
&& EssentialsProtect.guardSettings.get("protect.prevent.entitytarget")
|
||||
&& !user.isAuthorized("essentials.protect.entitytarget.bypass"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user