public BlockProjectileSource getBlockProjectileSource() { Block block = getBlock(); if (block.getType() != Material.DISPENSER) { return null; } return new CraftBlockProjectileSource(dispenser); }
@Override public @Nullable PhysicalInfo resolveShooter(ProjectileSource source) { if(source instanceof Entity) { return entityTracker.resolveEntity((Entity) source); } else if(source instanceof BlockProjectileSource) { return blockTracker.resolveBlock(((BlockProjectileSource) source).getBlock()); } return null; }
private String gB(BlockProjectileSource a) { switch (a.getBlock().getType()) { case DISPENSER: return "Dispenser"; default: return "Unknown 0x5." + a.getBlock().getType().ordinal() + " {" + a.getBlock().getType() + "}"; } }
/** * Get the source of the damage done as an instance of {@link Block}. * <p> * If the damager related to this data is an instance of {@link Projectile}, * this method will return the <em>block represented by the shooter of</em> that projectile, assuming it is an instance of {@code BlockProjectileSource}. * To get the projectile instance itself, use {@link #getSourceAsProjectile()}. * @return The source of damage, or {@code null} if it is not a block that dealt the damage. */ public Block getSourceAsBlock(){ if(_source == null || (!(_source instanceof Block) && !(_source instanceof Projectile))){ return null; } Projectile proj = getSourceAsProjectile(); ProjectileSource shooter = proj == null ? null : proj.getShooter(); if(shooter instanceof BlockProjectileSource){ return ((BlockProjectileSource)shooter).getBlock(); }else{ return (Block)_source; } }
@EventHandler public void onProjectileHit(ProjectileHitEvent event) { Projectile entity = (Projectile) event.getEntity(); Location loc = BukkitUtil.getLocation(entity); if (!PlotSquared.isPlotWorld(loc.getWorld())) { return; } Plot plot = MainUtil.getPlot(loc); if (!MainUtil.isPlotArea(loc)) { return; } ProjectileSource shooter = entity.getShooter(); if (shooter instanceof BlockProjectileSource) { if (plot == null) { entity.remove(); return; } Location sLoc = BukkitUtil.getLocation(((BlockProjectileSource) shooter).getBlock().getLocation()); Plot sPlot = MainUtil.getPlot(sLoc); if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) { entity.remove(); return; } } else if ((shooter instanceof Player)) { PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter); if (plot == null) { if (!pp.hasPermission("plots.projectile.unowned")) { entity.remove(); } return; } if (plot.isAdded(pp.getUUID())) { return; } if (pp.hasPermission("plots.projectile.other")) { return; } entity.remove(); } }
@EventHandler public boolean onProjectileHit(ProjectileHitEvent event) { Projectile entity = event.getEntity(); Location loc = BukkitUtil.getLocation(entity); if (!PS.get().hasPlotArea(loc.getWorld())) { return true; } PlotArea area = loc.getPlotArea(); if (area == null) { return true; } Plot plot = area.getPlot(loc); ProjectileSource shooter = entity.getShooter(); if (shooter instanceof Player) { PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter); if (plot == null) { if (!Permissions.hasPermission(pp, C.PERMISSION_PROJECTILE_UNOWNED)) { entity.remove(); return false; } return true; } if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_PROJECTILE_OTHER)) { return true; } entity.remove(); return false; } if (!(shooter instanceof Entity) && shooter != null) { if (plot == null) { entity.remove(); return false; } Location sLoc = BukkitUtil.getLocation(((BlockProjectileSource) shooter).getBlock().getLocation()); if (!area.contains(sLoc.getX(), sLoc.getZ())) { entity.remove(); return false; } Plot sPlot = area.getOwnedPlotAbs(sLoc); if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) { entity.remove(); return false; } } return true; }
@Override public BlockProjectileSource getBlockProjectileSource() { return PoreBlockProjectileSource.of(getTileEntity()); }
/** * Gets the BlockProjectileSource object for this dispenser. * <p> * If the block is no longer a dispenser, this will return null. * * @return a BlockProjectileSource if valid, otherwise null */ public BlockProjectileSource getBlockProjectileSource();
BlockProjectileSource getBlockProjectileSource();