From 5e9f4d72d9c73777d90aff94555e666d3ef53f42 Mon Sep 17 00:00:00 2001 From: nathank33 Date: Sun, 7 Sep 2014 13:01:21 -0700 Subject: [PATCH 1/3] AirSwipe Crash Prevention Added a protective measure to check the amount of entities that are about to have their velocities changed before moving them all. If there are too many entities around it will damage them without changing their velocity, that way we don't lag out and crash due to the firing of too many EntityCollisionEvents. --- .../ProjectKorra/airbending/AirSwipe.java | 70 +++++++++++-------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/src/com/projectkorra/ProjectKorra/airbending/AirSwipe.java b/src/com/projectkorra/ProjectKorra/airbending/AirSwipe.java index edee0184..cda6f140 100644 --- a/src/com/projectkorra/ProjectKorra/airbending/AirSwipe.java +++ b/src/com/projectkorra/ProjectKorra/airbending/AirSwipe.java @@ -2,6 +2,7 @@ package com.projectkorra.ProjectKorra.airbending; import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; @@ -11,6 +12,7 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; import com.projectkorra.ProjectKorra.BendingPlayer; @@ -28,7 +30,7 @@ import com.projectkorra.ProjectKorra.waterbending.WaterManipulation; public class AirSwipe { private static FileConfiguration config = ProjectKorra.plugin.getConfig(); - + private final int MAX_AFFECTABLE_ENTITIES = 10; public static ConcurrentHashMap instances = new ConcurrentHashMap(); private static int ID = Integer.MIN_VALUE; @@ -228,36 +230,44 @@ public class AirSwipe { private void affectPeople(Location location, Vector direction) { Methods.removeSpouts(location, player); - for (Entity entity : Methods.getEntitiesAroundPoint(location, affectingradius)) { - if (Methods.isRegionProtectedFromBuild(player, "AirSwipe", entity.getLocation())) - continue; - if (entity.getEntityId() != player.getEntityId()) { - if (entity instanceof Player) { - if (Commands.invincible.contains(((Player) entity).getName())) continue; + final List entities = Methods.getEntitiesAroundPoint(location, affectingradius); + final List surroundingEntities = Methods.getEntitiesAroundPoint(location, 4); + final Vector fDirection = direction; + + for(int i = 0; i < entities.size(); i++){ + final Entity entity = entities.get(i); + new BukkitRunnable(){ + public void run(){ + if (Methods.isRegionProtectedFromBuild(player, "AirSwipe", entity.getLocation())) + return; + if (entity.getEntityId() != player.getEntityId()) { + if (entity instanceof Player) { + if (Commands.invincible.contains(((Player) entity).getName())) + return; + } + if(surroundingEntities.size() < MAX_AFFECTABLE_ENTITIES){ + if (AvatarState.isAvatarState(player)) { + entity.setVelocity(fDirection.multiply(AvatarState.getValue(pushfactor))); + } else { + entity.setVelocity(fDirection.multiply(pushfactor)); + } + } + if (entity instanceof LivingEntity + && !affectedentities.contains(entity)) { + if (damage != 0) + Methods.damageEntity(player, entity, damage); + affectedentities.add(entity); + } + if (entity instanceof Player) { + new Flight((Player) entity, player); + } + Methods.breakBreathbendingHold(entity); + if (elements.containsKey(fDirection)) { + elements.remove(fDirection); + } + } } - if (AvatarState.isAvatarState(player)) { - entity.setVelocity(direction.multiply(AvatarState.getValue(pushfactor))); - } else { - entity.setVelocity(direction.multiply(pushfactor)); - } - - if (entity instanceof LivingEntity - && !affectedentities.contains(entity)) { - if (damage != 0) - Methods.damageEntity(player, entity, damage); - affectedentities.add(entity); - } - - if (entity instanceof Player) { - new Flight((Player) entity, player); - } - - Methods.breakBreathbendingHold(entity); - - if (elements.containsKey(direction)) { - elements.remove(direction); - } - } + }.runTaskLater(ProjectKorra.plugin, i / MAX_AFFECTABLE_ENTITIES); } } From 86ce948fa03c4e6f5a6780bd9116146d6df25aa2 Mon Sep 17 00:00:00 2001 From: nathank33 Date: Tue, 9 Sep 2014 21:12:41 -0700 Subject: [PATCH 2/3] LavaFlow not cleaning while shift held. Fixed a bug where LavaFlow was not being removed if the user kept the shift button held down. Now it cleans up regardless of whether they are still trying to bend a LavaFlow. --- .../projectkorra/ProjectKorra/earthbending/LavaFlow.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/com/projectkorra/ProjectKorra/earthbending/LavaFlow.java b/src/com/projectkorra/ProjectKorra/earthbending/LavaFlow.java index 2504ff25..7a8f5dda 100644 --- a/src/com/projectkorra/ProjectKorra/earthbending/LavaFlow.java +++ b/src/com/projectkorra/ProjectKorra/earthbending/LavaFlow.java @@ -143,7 +143,12 @@ public class LavaFlow remove(); return; } - + + double removeDelay = AvatarState.isAvatarState(player) ? AS_SHIFT_REMOVE_DELAY : SHIFT_REMOVE_DELAY; + if(System.currentTimeMillis() - time > removeDelay){ + remove(); + return; + } if(type == AbilityType.SHIFT) { From d68a519fd73c820bfcc8b8cfdf8dc359e9e8ccbe Mon Sep 17 00:00:00 2001 From: nathank33 Date: Tue, 9 Sep 2014 22:10:19 -0700 Subject: [PATCH 3/3] WaterWave now works with Passive, and doesn't create currents WaterWave previously was not working with WaterPassive, now it does. WaterWave was also removing the block of water that the user was using as a source, which was causing currents to form in the water. --- .../projectkorra/ProjectKorra/waterbending/WaterPassive.java | 2 +- src/com/projectkorra/ProjectKorra/waterbending/WaterWave.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/com/projectkorra/ProjectKorra/waterbending/WaterPassive.java b/src/com/projectkorra/ProjectKorra/waterbending/WaterPassive.java index e43c1954..e4b33df9 100644 --- a/src/com/projectkorra/ProjectKorra/waterbending/WaterPassive.java +++ b/src/com/projectkorra/ProjectKorra/waterbending/WaterPassive.java @@ -31,7 +31,7 @@ public class WaterPassive { if (Methods.canBendPassive(player.getName(), Element.Water)) { if (WaterSpout.instances.containsKey(player) || EarthArmor.instances.containsKey(player)) { continue; - } else if (ability == null || !AbilityModuleManager.shiftabilities.contains(ability)) { + } else if (ability == null || !AbilityModuleManager.shiftabilities.contains(ability) || ability.equalsIgnoreCase("WaterWave")) { if (player.isSneaking() && Methods.isWater(player.getLocation().getBlock())) { player.setVelocity(player.getEyeLocation().getDirection().clone().normalize().multiply(swimFactor)); } diff --git a/src/com/projectkorra/ProjectKorra/waterbending/WaterWave.java b/src/com/projectkorra/ProjectKorra/waterbending/WaterWave.java index e7076a63..c1bec027 100644 --- a/src/com/projectkorra/ProjectKorra/waterbending/WaterWave.java +++ b/src/com/projectkorra/ProjectKorra/waterbending/WaterWave.java @@ -118,8 +118,8 @@ public class WaterWave currentLoc = origin.clone(); if(Methods.isPlant(origin.getBlock())) new Plantbending(origin.getBlock()); - else - Methods.addTempAirBlock(origin.getBlock()); + //else + // Methods.addTempAirBlock(origin.getBlock()); }