|
@@ -6,7 +6,9 @@ import net.minecraft.block.Block;
|
|
import net.minecraft.block.Blocks;
|
|
import net.minecraft.block.Blocks;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.EntityType;
|
|
import net.minecraft.entity.EntityType;
|
|
-import net.minecraft.util.math.BlockPos;
|
|
|
|
|
|
+import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
+import net.minecraft.util.math.BlockRayTraceResult;
|
|
|
|
+import net.minecraft.util.math.EntityRayTraceResult;
|
|
import net.minecraft.util.math.RayTraceResult;
|
|
import net.minecraft.util.math.RayTraceResult;
|
|
import net.minecraft.world.dimension.DimensionType;
|
|
import net.minecraft.world.dimension.DimensionType;
|
|
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
|
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
|
@@ -22,43 +24,52 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
|
|
|
|
public class ProtectionEvents
|
|
public class ProtectionEvents
|
|
{
|
|
{
|
|
- private final static String PLOT_BYPASS = "plot.bypass";
|
|
|
|
-
|
|
|
|
- private final IProtection bank;
|
|
|
|
|
|
+ private final WorldPlotMap plots;
|
|
private final PermissionManager perms;
|
|
private final PermissionManager perms;
|
|
|
|
|
|
- public ProtectionEvents(IProtection bank, PermissionManager perms)
|
|
|
|
|
|
+ public ProtectionEvents(WorldPlotMap plotMap, PermissionManager perms)
|
|
{
|
|
{
|
|
- this.bank = bank;
|
|
|
|
|
|
+ this.plots = plotMap;
|
|
this.perms = perms;
|
|
this.perms = perms;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private boolean canBypass(PlayerEntity p)
|
|
|
|
+ {
|
|
|
|
+ return perms.hasPermission(p, "plot.bypass");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean shouldBeProtected(Entity ent)
|
|
|
|
+ {
|
|
|
|
+ EntityType type = ent.getType();
|
|
|
|
+ return type == EntityType.ITEM_FRAME || type == EntityType.PAINTING || type == EntityType.ARMOR_STAND;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
public void onBlockPlace(BlockEvent.EntityPlaceEvent e)
|
|
public void onBlockPlace(BlockEvent.EntityPlaceEvent e)
|
|
{
|
|
{
|
|
- if(!(e.getEntity() instanceof ModEntityPlayerMP))
|
|
|
|
|
|
+ if(e.getEntity() instanceof PlayerEntity)
|
|
{
|
|
{
|
|
- return;
|
|
|
|
- }
|
|
|
|
- ModEntityPlayerMP p = (ModEntityPlayerMP) e.getEntity();
|
|
|
|
- if(!perms.hasPermission(p, PLOT_BYPASS) && !bank.canBuild(e.getWorld(), e.getPos(), p))
|
|
|
|
- {
|
|
|
|
- e.setCanceled(true);
|
|
|
|
- }
|
|
|
|
|
|
+ PlayerEntity p = (PlayerEntity) e.getEntity();
|
|
|
|
+ if(!canBypass(p) && !plots.canPlaceBlock(e.getWorld(), e.getPos(), p))
|
|
|
|
+ {
|
|
|
|
+ e.setCanceled(true);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
public void onBlockBreak(BlockEvent.BreakEvent e)
|
|
public void onBlockBreak(BlockEvent.BreakEvent e)
|
|
{
|
|
{
|
|
- ModEntityPlayerMP p = (ModEntityPlayerMP) e.getPlayer();
|
|
|
|
- if(!perms.hasPermission(p, PLOT_BYPASS) && !bank.canBuild(e.getWorld(), e.getPos(), p))
|
|
|
|
|
|
+ PlayerEntity p = e.getPlayer();
|
|
|
|
+ if(!canBypass(p) && !plots.canBreakBlock(e.getWorld(), e.getPos(), p))
|
|
{
|
|
{
|
|
e.setCanceled(true);
|
|
e.setCanceled(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
- public void WitherDragonProtection(EntityJoinWorldEvent e)
|
|
|
|
|
|
+ public void onBossSpawn(EntityJoinWorldEvent e)
|
|
{
|
|
{
|
|
EntityType type = e.getEntity().getType();
|
|
EntityType type = e.getEntity().getType();
|
|
if(type == EntityType.WITHER && e.getWorld().getDimension().getType() != DimensionType.THE_NETHER)
|
|
if(type == EntityType.WITHER && e.getWorld().getDimension().getType() != DimensionType.THE_NETHER)
|
|
@@ -74,114 +85,78 @@ public class ProtectionEvents
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
public void onBucketFill(FillBucketEvent e)
|
|
public void onBucketFill(FillBucketEvent e)
|
|
{
|
|
{
|
|
- ModEntityPlayerMP p = (ModEntityPlayerMP) e.getEntityPlayer();
|
|
|
|
RayTraceResult ray = e.getTarget();
|
|
RayTraceResult ray = e.getTarget();
|
|
- if(ray == null || ray.hitInfo == null || ray.getType() != RayTraceResult.Type.BLOCK || perms.hasPermission(p, PLOT_BYPASS))
|
|
|
|
|
|
+ if(ray == null || ray.getType() != RayTraceResult.Type.BLOCK || canBypass(e.getPlayer()))
|
|
{
|
|
{
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- BlockPos pos = new BlockPos(ray.getHitVec());
|
|
|
|
- if(!bank.canBuild(e.getWorld(), pos, p))
|
|
|
|
|
|
+ if(!plots.canUseBucket(e.getWorld(), ((BlockRayTraceResult) ray).getPos(), e.getPlayer()))
|
|
{
|
|
{
|
|
e.setCanceled(true);
|
|
e.setCanceled(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- // TODO:protection / entity with uuids
|
|
|
|
- /*@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
|
|
- public void EntityProtection(LivingAttackEvent e)
|
|
|
|
- {
|
|
|
|
- e.getEntity().getUniqueID()
|
|
|
|
- EntityLivingBase ent = e.getEntityLiving();
|
|
|
|
- if(!this.getProtectionBank().isProtected(ent.getClass()))
|
|
|
|
- {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- World w = ent.world;
|
|
|
|
- BlockPos pos = ent.getPosition();
|
|
|
|
- if(!this.getProtectionBank().hasProtection(w, pos) ||
|
|
|
|
- (ent instanceof EntityAnimal && this.getProtectionBank().hasTag(w, pos, "animal")))
|
|
|
|
- {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(e.getSource().getImmediateSource() != null)
|
|
|
|
- {
|
|
|
|
- EntityPlayer p = Utils.getDamager(e.getSource());
|
|
|
|
- if(p != null)
|
|
|
|
- {
|
|
|
|
- if(perms.hasPermission(p, Permissions.PLOT_BYPASS) || this.getProtectionBank().canBuild(w, pos, p))
|
|
|
|
- {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- e.setCanceled(true);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- e.setCanceled(true);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
|
|
- public void EntityProtectionPotion(ThrowableImpactEvent e)
|
|
|
|
- {
|
|
|
|
- if(e.getEntityThrowable() instanceof EntityPotion)
|
|
|
|
- {
|
|
|
|
- EntityPotion potion = (EntityPotion) e.getEntityThrowable();
|
|
|
|
- EntityLivingBase ent = potion.getThrower();
|
|
|
|
- if(ent instanceof EntityPlayer && !perms.hasPermission(ent, Permissions.PLOT_BYPASS) &&
|
|
|
|
- !this.getProtectionBank().canBuild(potion.world, potion.getPosition(), (EntityPlayer) ent))
|
|
|
|
- {
|
|
|
|
- e.setCanceled(true);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }*/
|
|
|
|
-
|
|
|
|
|
|
+
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
public void onEntityHit(AttackEntityEvent e)
|
|
public void onEntityHit(AttackEntityEvent e)
|
|
{
|
|
{
|
|
- EntityType type = e.getTarget().getType();
|
|
|
|
- if(type == EntityType.ITEM_FRAME || type == EntityType.PAINTING || type == EntityType.ARMOR_STAND)
|
|
|
|
|
|
+ if(shouldBeProtected(e.getTarget()))
|
|
{
|
|
{
|
|
- ModEntityPlayerMP p = (ModEntityPlayerMP) e.getEntityPlayer();
|
|
|
|
- if(!perms.hasPermission(p, PLOT_BYPASS) &&
|
|
|
|
- !bank.canBuild(p.world, e.getTarget().getPosition(), p))
|
|
|
|
|
|
+ PlayerEntity p = e.getPlayer();
|
|
|
|
+ if(!canBypass(p) && !plots.canHitAmbientEntity(p.world, e.getTarget().getPosition(), p))
|
|
{
|
|
{
|
|
e.setCanceled(true);
|
|
e.setCanceled(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@SubscribeEvent
|
|
@SubscribeEvent
|
|
public void onThrowableImpace(ProjectileImpactEvent.Throwable e)
|
|
public void onThrowableImpace(ProjectileImpactEvent.Throwable e)
|
|
{
|
|
{
|
|
- Entity ent = e.getThrowable().getThrower();
|
|
|
|
- if(ent == null || !(ent instanceof ModEntityPlayerMP))
|
|
|
|
|
|
+ if(e.getRayTraceResult().getType() == RayTraceResult.Type.ENTITY)
|
|
{
|
|
{
|
|
- if(bank.hasPlots(0, 0, 0, PLOT_BYPASS))
|
|
|
|
|
|
+ EntityRayTraceResult result = (EntityRayTraceResult) e.getRayTraceResult();
|
|
|
|
+ if(shouldBeProtected(result.getEntity()))
|
|
{
|
|
{
|
|
- e.setCanceled(true);
|
|
|
|
|
|
+ Entity thrower = e.getThrowable().getThrower();
|
|
|
|
+ if(thrower != null && (thrower instanceof PlayerEntity))
|
|
|
|
+ {
|
|
|
|
+ PlayerEntity p = (PlayerEntity) thrower;
|
|
|
|
+ if(!canBypass(p) && !plots.canHitAmbientEntity(p.world, e.getThrowable().getPosition(), p))
|
|
|
|
+ {
|
|
|
|
+ e.setCanceled(true);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ e.setCanceled(true);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else if(!perms.hasPermission(ent, PLOT_BYPASS) && !bank.canBuild(ent.world, ent.getPosition(), (ModEntityPlayerMP) ent))
|
|
|
|
- {
|
|
|
|
- e.setCanceled(true);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@SubscribeEvent
|
|
@SubscribeEvent
|
|
- public void onThrowableImpace(ProjectileImpactEvent.Arrow e)
|
|
|
|
|
|
+ public void onThrowableImpact(ProjectileImpactEvent.Arrow e)
|
|
{
|
|
{
|
|
- Entity ent = e.getArrow().getShooter();
|
|
|
|
- if(ent == null || !(ent instanceof ModEntityPlayerMP))
|
|
|
|
|
|
+ if(e.getRayTraceResult().getType() == RayTraceResult.Type.ENTITY)
|
|
{
|
|
{
|
|
- if(bank.hasPlots(0, 0, 0, PLOT_BYPASS))
|
|
|
|
|
|
+ EntityRayTraceResult result = (EntityRayTraceResult) e.getRayTraceResult();
|
|
|
|
+ if(shouldBeProtected(result.getEntity()))
|
|
{
|
|
{
|
|
- e.setCanceled(true);
|
|
|
|
|
|
+ Entity shooter = e.getArrow().getShooter();
|
|
|
|
+ if(shooter != null && (shooter instanceof ModEntityPlayerMP))
|
|
|
|
+ {
|
|
|
|
+ PlayerEntity p = (PlayerEntity) shooter;
|
|
|
|
+ if(!canBypass(p) && !plots.canHitAmbientEntity(p.world, e.getArrow().getPosition(), p))
|
|
|
|
+ {
|
|
|
|
+ e.setCanceled(true);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ e.setCanceled(true);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else if(!perms.hasPermission(ent, PLOT_BYPASS) && !bank.canBuild(ent.world, ent.getPosition(), (ModEntityPlayerMP) ent))
|
|
|
|
- {
|
|
|
|
- e.setCanceled(true);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
@@ -193,13 +168,13 @@ public class ProtectionEvents
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
public void onPlayerInteract(PlayerInteractEvent.LeftClickBlock e)
|
|
public void onPlayerInteract(PlayerInteractEvent.LeftClickBlock e)
|
|
{
|
|
{
|
|
- ModEntityPlayerMP p = (ModEntityPlayerMP) e.getEntityPlayer();
|
|
|
|
- if(perms.hasPermission(p, PLOT_BYPASS))
|
|
|
|
|
|
+ PlayerEntity p = e.getPlayer();
|
|
|
|
+ if(canBypass(p))
|
|
{
|
|
{
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
Block b = e.getWorld().getBlockState(e.getPos()).getBlock();
|
|
Block b = e.getWorld().getBlockState(e.getPos()).getBlock();
|
|
- if(b == Blocks.FIRE && !bank.canBuild(e.getWorld(), e.getPos(), p))
|
|
|
|
|
|
+ if(b == Blocks.FIRE && !plots.canBreakBlock(e.getWorld(), e.getPos(), p))
|
|
{
|
|
{
|
|
e.setCanceled(true);
|
|
e.setCanceled(true);
|
|
}
|
|
}
|
|
@@ -208,31 +183,25 @@ public class ProtectionEvents
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
public void onPlayerInteract(PlayerInteractEvent.RightClickBlock e)
|
|
public void onPlayerInteract(PlayerInteractEvent.RightClickBlock e)
|
|
{
|
|
{
|
|
- ModEntityPlayerMP p = (ModEntityPlayerMP) e.getEntityPlayer();
|
|
|
|
- if(perms.hasPermission(p, PLOT_BYPASS))
|
|
|
|
- {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- Block b = e.getWorld().getBlockState(e.getPos()).getBlock();
|
|
|
|
- if(!bank.canBuild(e.getWorld(), e.getPos(), p))
|
|
|
|
|
|
+ PlayerEntity p = e.getPlayer();
|
|
|
|
+ if(!canBypass(p) && !plots.canInteractWithBlock(e.getWorld(), e.getPos(), p))
|
|
{
|
|
{
|
|
e.setCanceled(true);
|
|
e.setCanceled(true);
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
- public void protectFromInteract(PlayerInteractEvent.EntityInteract e)
|
|
|
|
|
|
+ public void onPlayerEntityInteract(PlayerInteractEvent.EntityInteract e)
|
|
{
|
|
{
|
|
- ModEntityPlayerMP p = (ModEntityPlayerMP) e.getEntityPlayer();
|
|
|
|
- if(!perms.hasPermission(p, PLOT_BYPASS) &&
|
|
|
|
- !bank.canBuild(e.getWorld(), e.getTarget().getPosition(), p))
|
|
|
|
|
|
+ PlayerEntity p = e.getPlayer();
|
|
|
|
+ if(!canBypass(p) && !plots.canInteractWithEntity(e.getWorld(), e.getTarget().getPosition(), p))
|
|
{
|
|
{
|
|
e.setCanceled(true);
|
|
e.setCanceled(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
|
- public void protectFromInteract(BlockEvent.FarmlandTrampleEvent e)
|
|
|
|
|
|
+ public void onFarmlandTrample(BlockEvent.FarmlandTrampleEvent e)
|
|
{
|
|
{
|
|
e.setCanceled(true);
|
|
e.setCanceled(true);
|
|
}
|
|
}
|