Added option for Torrent revert & fixed Bloodbending NPE (#646)

* Added option for Torrent revert & fixed Bloodbending NPE

* Fixed minor boo boo
This commit is contained in:
Sobki 2016-11-05 07:54:00 +10:00 committed by Christopher Martin
parent e6850e8139
commit 51e2226f09
3 changed files with 55 additions and 36 deletions

View file

@ -709,6 +709,8 @@ public class ConfigManager {
config.addDefault("Abilities.Water.Torrent.MaxUpwardForce", 0.2); config.addDefault("Abilities.Water.Torrent.MaxUpwardForce", 0.2);
config.addDefault("Abilities.Water.Torrent.Interval", 30); config.addDefault("Abilities.Water.Torrent.Interval", 30);
config.addDefault("Abilities.Water.Torrent.Cooldown", 0); config.addDefault("Abilities.Water.Torrent.Cooldown", 0);
config.addDefault("Abilities.Water.Torrent.Revert", true);
config.addDefault("Abilities.Water.Torrent.RevertTime", 60000);
config.addDefault("Abilities.Water.Torrent.Wave.Radius", 12); config.addDefault("Abilities.Water.Torrent.Wave.Radius", 12);
config.addDefault("Abilities.Water.Torrent.Wave.Knockback", 1.5); config.addDefault("Abilities.Water.Torrent.Wave.Knockback", 1.5);
config.addDefault("Abilities.Water.Torrent.Wave.Height", 1); config.addDefault("Abilities.Water.Torrent.Wave.Height", 1);

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Creature; import org.bukkit.entity.Creature;
@ -88,7 +89,7 @@ public class Bloodbending extends BloodAbility {
} else { } else {
//Location location = GeneralMethods.getTargetedLocation(player, 6, getTransparentMaterial()); //Location location = GeneralMethods.getTargetedLocation(player, 6, getTransparentMaterial());
//List<Entity> entities = GeneralMethods.getEntitiesAroundPoint(location, 1.5); //List<Entity> entities = GeneralMethods.getEntitiesAroundPoint(location, 1.5);
List<Entity> entities = new ArrayList<Entity>(); List<Entity> entities = new CopyOnWriteArrayList<Entity>();
for (int i = 0; i < range; i++) { for (int i = 0; i < range; i++) {
Location location = GeneralMethods.getTargetedLocation(player, i, getTransparentMaterial()); Location location = GeneralMethods.getTargetedLocation(player, i, getTransparentMaterial());
entities = GeneralMethods.getEntitiesAroundPoint(location, 1.7); entities = GeneralMethods.getEntitiesAroundPoint(location, 1.7);

View file

@ -29,6 +29,7 @@ public class Torrent extends WaterAbility {
private static final double CLEANUP_RANGE = 50; private static final double CLEANUP_RANGE = 50;
private static final Map<TempBlock, Player> FROZEN_BLOCKS = new ConcurrentHashMap<>(); private static final Map<TempBlock, Player> FROZEN_BLOCKS = new ConcurrentHashMap<>();
private static final Map<TempBlock, Long> FROZEN_BLOCKS_DELAY = new ConcurrentHashMap<>();
private boolean sourceSelected; private boolean sourceSelected;
private boolean settingUp; private boolean settingUp;
@ -99,7 +100,8 @@ public class Torrent extends WaterAbility {
} }
time = System.currentTimeMillis(); time = System.currentTimeMillis();
sourceBlock = BlockSource.getWaterSourceBlock(player, selectRange, ClickType.LEFT_CLICK, true, true, bPlayer.canPlantbend()); sourceBlock = BlockSource.getWaterSourceBlock(player, selectRange, ClickType.LEFT_CLICK, true, true,
bPlayer.canPlantbend());
if (sourceBlock != null && !GeneralMethods.isRegionProtectedFromBuild(this, sourceBlock.getLocation())) { if (sourceBlock != null && !GeneralMethods.isRegionProtectedFromBuild(this, sourceBlock.getLocation())) {
sourceSelected = true; sourceSelected = true;
start(); start();
@ -118,6 +120,7 @@ public class Torrent extends WaterAbility {
if (isTransparent(player, block) && block.getType() != Material.ICE) { if (isTransparent(player, block) && block.getType() != Material.ICE) {
TempBlock tblock = new TempBlock(block, Material.ICE, (byte) 0); TempBlock tblock = new TempBlock(block, Material.ICE, (byte) 0);
FROZEN_BLOCKS.put(tblock, player); FROZEN_BLOCKS.put(tblock, player);
FROZEN_BLOCKS_DELAY.put(tblock, System.currentTimeMillis());
playIcebendingSound(block.getLocation()); playIcebendingSound(block.getLocation());
} }
} }
@ -222,8 +225,10 @@ public class Torrent extends WaterAbility {
double dy = 0; double dy = 0;
double dz = Math.sin(phi) * radius; double dz = Math.sin(phi) * radius;
loc.add(dx, dy, dz); loc.add(dx, dy, dz);
if(isWater(loc.getBlock()) && GeneralMethods.isAdjacentToThreeOrMoreSources(loc.getBlock())) { if (isWater(loc.getBlock()) && GeneralMethods.isAdjacentToThreeOrMoreSources(loc.getBlock())) {
ParticleEffect.WATER_BUBBLE.display((float) Math.random(), (float) Math.random(), (float) Math.random(), 0f, 5, loc.getBlock().getLocation().clone().add(.5,.5,.5), 255.0); ParticleEffect.WATER_BUBBLE.display((float) Math.random(), (float) Math.random(),
(float) Math.random(), 0f, 5, loc.getBlock().getLocation().clone().add(.5, .5, .5),
255.0);
} }
loc.subtract(dx, dy, dz); loc.subtract(dx, dy, dz);
} }
@ -330,7 +335,8 @@ public class Torrent extends WaterAbility {
} }
Block locBlock = location.getBlock(); Block locBlock = location.getBlock();
if (location.distanceSquared(player.getLocation()) > range * range || GeneralMethods.isRegionProtectedFromBuild(this, location)) { if (location.distanceSquared(player.getLocation()) > range * range
|| GeneralMethods.isRegionProtectedFromBuild(this, location)) {
if (layer < maxLayer) { if (layer < maxLayer) {
if (freeze || layer < 1) { if (freeze || layer < 1) {
layer++; layer++;
@ -362,7 +368,8 @@ public class Torrent extends WaterAbility {
} }
if (locBlock.getLocation().distanceSquared(targetLoc) > 1) { if (locBlock.getLocation().distanceSquared(targetLoc) > 1) {
if (isWater(locBlock)) { if (isWater(locBlock)) {
ParticleEffect.WATER_BUBBLE.display((float) Math.random(), (float) Math.random(), (float) Math.random(), 0f, 5, locBlock.getLocation().clone().add(.5,.5,.5), 255.0); ParticleEffect.WATER_BUBBLE.display((float) Math.random(), (float) Math.random(),
(float) Math.random(), 0f, 5, locBlock.getLocation().clone().add(.5, .5, .5), 255.0);
} }
newBlocks.add(new TempBlock(locBlock, Material.STATIONARY_WATER, (byte) 8)); newBlocks.add(new TempBlock(locBlock, Material.STATIONARY_WATER, (byte) 8));
} else { } else {
@ -390,11 +397,15 @@ public class Torrent extends WaterAbility {
if (entity.getWorld() != block.getBlock().getWorld()) { if (entity.getWorld() != block.getBlock().getWorld()) {
continue; continue;
} }
if (entity.getLocation().distanceSquared(block.getLocation()) <= 1.5 * 1.5 && !affectedEntities.contains(entity)) { if (entity.getLocation().distanceSquared(block.getLocation()) <= 1.5 * 1.5
&& !affectedEntities.contains(entity)) {
if (i == 0) { if (i == 0) {
affect(entity, dir); affect(entity, dir);
} else { } else {
affect(entity, GeneralMethods.getDirection(block.getLocation(), launchedBlocks.get(i - 1).getLocation()).normalize()); affect(entity,
GeneralMethods
.getDirection(block.getLocation(), launchedBlocks.get(i - 1).getLocation())
.normalize());
} }
affectedEntities.add(entity); affectedEntities.add(entity);
} }
@ -435,7 +446,8 @@ public class Torrent extends WaterAbility {
if (entity.getWorld() != blockLoc.getWorld()) { if (entity.getWorld() != blockLoc.getWorld()) {
continue; continue;
} }
if (!affectedEntities.contains(entity) && entity.getLocation().distanceSquared(blockLoc) <= 1.5 * 1.5) { if (!affectedEntities.contains(entity)
&& entity.getLocation().distanceSquared(blockLoc) <= 1.5 * 1.5) {
deflect(entity); deflect(entity);
} }
} }
@ -483,7 +495,7 @@ public class Torrent extends WaterAbility {
Location eyeLoc = player.getEyeLocation(); Location eyeLoc = player.getEyeLocation();
Block block = eyeLoc.add(eyeLoc.getDirection().normalize()).getBlock(); Block block = eyeLoc.add(eyeLoc.getDirection().normalize()).getBlock();
if (isTransparent(player, block) && isTransparent(player, eyeLoc.getBlock())) { if (isTransparent(player, block) && isTransparent(player, eyeLoc.getBlock())) {
if(block.getType() != Material.WATER) { if (block.getType() != Material.WATER) {
block.setType(Material.STATIONARY_WATER); block.setType(Material.STATIONARY_WATER);
block.setData((byte) 8); block.setData((byte) 8);
} }
@ -577,6 +589,10 @@ public class Torrent extends WaterAbility {
} else if (block.getBlock().getType() != Material.ICE) { } else if (block.getBlock().getType() != Material.ICE) {
FROZEN_BLOCKS.remove(block); FROZEN_BLOCKS.remove(block);
continue; continue;
} else if (getConfig().getBoolean("Abilities.Water.Torrent.Revert") && System.currentTimeMillis()
- FROZEN_BLOCKS_DELAY.get(block) > getConfig().getLong("Abilities.Water.Torrent.RevertTime")) {
thaw(block);
continue;
} else if (!player.isOnline()) { } else if (!player.isOnline()) {
thaw(block); thaw(block);
continue; continue;