Refactor cannon explosion effect for clarity

This commit is contained in:
cnr 2016-04-17 13:30:06 -05:00
parent 9c6d23f11e
commit e375db5aec
1 changed files with 13 additions and 26 deletions

View File

@ -1,6 +1,8 @@
package mineplex.game.clans.clans.siege.weapon;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.bukkit.Location;
import org.bukkit.Material;
@ -41,6 +43,7 @@ import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile;
import mineplex.game.clans.clans.siege.weapon.util.AccessRule;
import mineplex.game.clans.clans.siege.weapon.util.AccessType;
import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo;
import mineplex.game.clans.core.repository.ClanTerritory;
public class Cannon extends SiegeWeapon
{
@ -425,32 +428,16 @@ public class Cannon extends SiegeWeapon
@EventHandler
public void explosionEffects(SiegeWeaponExplodeEvent event)
{
// for (int i = 0; i < 8; i++)
// {
// // Explosion particle effects.
// Location point = UtilAlg.getRandomLocation(event.getProjectile().getLocation(), 5);
// UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, point, 0, 0, 0, 1, 2, ViewDist.MAX);
// }
// Block explosion.
ArrayList<Block> blocks = new ArrayList<>();
int attempts = 0;
while (blocks.size() < 10 && (attempts < 30))
{
attempts++;
Block block = UtilAlg.getRandomLocation(event.getProjectile().getLocation(), (4 * getPowerLevel())).getBlock();
ClanTerritory claim = _siegeManager.getClansManager().getClanUtility().getClaim(block.getLocation());
if (claim != null && !_siegeManager.getClansManager().getBlacklist().allowed(claim.Owner))
List<Block> blocks = Stream.generate(() -> UtilAlg.getRandomLocation(event.getProjectile().getLocation(), 4 * getPowerLevel()).getBlock())
.limit(30) // Generate up to 30
.distinct() // distinct blocks,
.filter(block -> // filter for those unclaimed,
{
continue; // This block is in a claimed territory
}
if ((block.getType() != Material.AIR) && (!blocks.contains(block)))
{
blocks.add(block);
}
}
ClanTerritory claim = _siegeManager.getClansManager().getClanUtility().getClaim(block.getLocation());
return claim == null || _siegeManager.getClansManager().getBlacklist().allowed(claim.Owner);
})
.limit(10) // and take up to 10 of them.
.collect(Collectors.toList());
_clans.getExplosion().BlockExplosion(
blocks,