TF-ProjectKorra/src/com/projectkorra/projectkorra/util/MovementHandler.java
Christopher Martin 102112ffdd 1.8.6 (#825)
## Fixes
* Fixed Combos and possibly Passives appearing in `/pk b <Ability>` auto-tabbing.
* Fixed Combos not loading properly on certain servers.
* Fixed issue with `PreciousStones` by updating to the latest version to resolve API change issues.
* Fixed `RapidPunch` damage.
* Fixed incorrect summation of chiblocking chance.
* Fixed possible issue in PKListener#onPlayerInteraction()
* Fixed `Earth.LavaSound`.
* Fixed Chi attempting to chiblock targets with any move.
* Fixed hitting an entity with `TempArmor` not ignoring armor.
* Fixed `Immobilize` config path.

## Additions
* Added "Contributing" section to the `README` to help guide active community members.
* Added more detail to the `PULL_REQUEST_TEMPLATE` to allow for more uniform pull requests. 
* Added many new blocks to our ability block interaction.
* Added check to combo collisions to discard dead entities.
* Added functionality to allow chiblocking abilities to affect all entities.
* Added exception handling to the configurable `Sound` options to prevent `IllegalArgumentExcpetions`.
* Added sounds and `ActionBar` messages to being Bloodbent, Electrocuted, Immobilized, MetalClipped, and Paralyzed. (Abilities: `Bloodbending`, `Lightning`, `Immobilize`, `MetalClips`, and `Paralyze`)
* Added sound and `ActionBar` message for being Chiblocked.
* Added interval config option to `RapidPunch`. (time between each punch)

## API Changes
* Updated to `Spigot 1.12.1`.
    * Confirmed to be backward compatible with `Spigot 1.12` and `Spigot 1.11.2`.
* Renamed `ElementalAbility#getTransparentMaterial()` to `ElementalAbility#getTransparentMaterials()`.
* Converted most `byte`/`int` dependent `Material` logic to use `Material` instead. 
    * `ElementalAbility#getTransparentMaterialSet()` now returns a `HashSet<Material>` instead of a `HashSet<Byte>`.
    * `ElementalAbility#getTransparentMaterials()` and `GeneralMethods.NON_OPAQUE` now return `Material[]` instead of `Integer[]`.
    * `GeneralMethods#getTargetedLocation()` now takes a `varargs Material[]` instead of a `varargs Integer[]`.
* Removed `ElementalAbility.TRANSPARENT_MATERIAL`. It was outdated and became irrelevent after `GeneralMethods.NON_OPAQUE` was updated.
* Removed `Java 7` Travi-CI  JDK check.
* Updated `pom.xml` to build in `Java 8`.
* Added new `MovementHandler` utility class to control entity movement. (currently only capable of stopping movement.
2017-08-06 00:18:12 -07:00

113 lines
2.5 KiB
Java

package com.projectkorra.projectkorra.util;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.scheduler.BukkitRunnable;
import com.projectkorra.projectkorra.ProjectKorra;
/**
* An object to control how an entity moves.
* <br>Current functions include <b>stopping</b>.
* @author Simplicitee
*
*/
public class MovementHandler {
private LivingEntity entity;
private BukkitRunnable runnable;
private ResetTask reset = null;
public MovementHandler(LivingEntity entity) {
this.entity = entity;
}
/**
* This stops the movement of the entity once
* they land on the ground, acting as a "paralyze"
* @param duration how long the entity should be stopped for <b>(in ticks)</b>
*/
public void stop(long duration, String message) {
if (entity instanceof Player) {
long start = System.currentTimeMillis();
Player player = (Player) entity;
player.setMetadata("movement:stop", new FixedMetadataValue(ProjectKorra.plugin, 0));
runnable = new BukkitRunnable() {
@Override
public void run() {
ActionBar.sendActionBar(message, player);
if (System.currentTimeMillis() >= start + duration/20*1000) {
player.removeMetadata("movement:stop", ProjectKorra.plugin);
reset();
}
}
};
runnable.runTaskTimer(ProjectKorra.plugin, 0, 1);
} else {
runnable = new BukkitRunnable() {
@Override
public void run() {
allowMove();
}
};
new BukkitRunnable() {
@Override
public void run() {
if (entity.isOnGround()) {
entity.setAI(false);
cancel();
runnable.runTaskLater(ProjectKorra.plugin, duration);
}
}
}.runTaskTimer(ProjectKorra.plugin, 0, 1);
}
}
private void allowMove() {
if (!(entity instanceof Player)) {
entity.setAI(true);
}
if (reset != null) {
reset.run();
}
}
/**
* Cancels the current task and allows the entity to move freely
*/
public void reset() {
runnable.cancel();
allowMove();
}
public LivingEntity getEntity() {
return entity;
}
public void setResetTask(ResetTask reset) {
this.reset = reset;
}
/**
* Functional interface, called when the entity is allowed to
* move again, therefore "reseting" it's AI
* @author Simplicitee
*
*/
public interface ResetTask {
public void run();
}
public static boolean isStopped(Entity entity) {
return entity.hasMetadata("movement:stop");
}
}