TF-ProjectKorra/src/com/projectkorra/projectkorra/BendingManager.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

147 lines
5 KiB
Java

package com.projectkorra.projectkorra;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.projectkorra.projectkorra.ability.CoreAbility;
import com.projectkorra.projectkorra.ability.FireAbility;
import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.earthbending.metal.MetalClips;
import com.projectkorra.projectkorra.object.HorizontalVelocityTracker;
import com.projectkorra.projectkorra.util.ActionBar;
import com.projectkorra.projectkorra.util.Flight;
import com.projectkorra.projectkorra.util.RevertChecker;
import com.projectkorra.projectkorra.util.TempPotionEffect;
import com.projectkorra.projectkorra.waterbending.blood.Bloodbending;
import com.projectkorra.rpg.RPGMethods;
public class BendingManager implements Runnable {
private static BendingManager instance;
public static HashMap<World, String> events = new HashMap<World, String>(); // holds any current event.
long time;
long interval;
private final HashMap<World, Boolean> times = new HashMap<World, Boolean>(); // true if day time
public BendingManager() {
instance = this;
time = System.currentTimeMillis();
}
public static BendingManager getInstance() {
return instance;
}
public void handleCooldowns() {
for (UUID uuid : BendingPlayer.getPlayers().keySet()) {
BendingPlayer bPlayer = BendingPlayer.getPlayers().get(uuid);
for (String abil : bPlayer.getCooldowns().keySet()) {
if (System.currentTimeMillis() >= bPlayer.getCooldown(abil)) {
bPlayer.removeCooldown(abil);
}
}
}
}
public void handleDayNight() {
for (World world : Bukkit.getServer().getWorlds()) {
if (!times.containsKey(world)) {
if (FireAbility.isDay(world)) {
times.put(world, true);
} else {
times.put(world, false);
}
} else {
if (GeneralMethods.hasRPG()) {
if (RPGMethods.isFullMoon(world) || RPGMethods.isLunarEclipse(world) || RPGMethods.isSolarEclipse(world) || RPGMethods.isSozinsComet(world)) {
continue;
}
}
if (times.get(world) && !FireAbility.isDay(world)) {
// The hashmap says it is day, but it is not.
times.put(world, false); // Sets time to night.
for (Player player : world.getPlayers()) {
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
if (bPlayer == null) {
continue;
}
if (bPlayer.hasElement(Element.WATER) && player.hasPermission("bending.message.daymessage")) {
player.sendMessage(Element.WATER.getColor() + getMoonriseMessage());
}
if (bPlayer.hasElement(Element.FIRE) && player.hasPermission("bending.message.nightmessage")) {
player.sendMessage(Element.FIRE.getColor() + getSunsetMessage());
}
}
}
if (!times.get(world) && FireAbility.isDay(world)) {
// The hashmap says it is night, but it is day.
times.put(world, true);
for (Player player : world.getPlayers()) {
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
if (bPlayer == null) {
continue;
}
if (bPlayer.hasElement(Element.WATER) && player.hasPermission("bending.message.nightmessage")) {
player.sendMessage(Element.WATER.getColor() + getMoonsetMessage());
}
if (bPlayer.hasElement(Element.FIRE) && player.hasPermission("bending.message.daymessage")) {
player.sendMessage(Element.FIRE.getColor() + getSunriseMessage());
}
}
}
}
}
}
public void run() {
try {
interval = System.currentTimeMillis() - time;
time = System.currentTimeMillis();
ProjectKorra.time_step = interval;
CoreAbility.progressAll();
TempPotionEffect.progressAll();
handleDayNight();
Flight.handle();
RevertChecker.revertAirBlocks();
HorizontalVelocityTracker.updateAll();
handleCooldowns();
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (MetalClips.isControlled(player)) {
ActionBar.sendActionBar(Element.METAL.getColor() + "* MetalClipped *", player);
} else if (Bloodbending.isBloodbent(player)) {
ActionBar.sendActionBar(Element.BLOOD.getColor() + "* Bloodbent *", player);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
public static String getSunriseMessage() {
return ChatColor.translateAlternateColorCodes('&', ConfigManager.languageConfig.get().getString("Extras.Fire.DayMessage"));
}
public static String getSunsetMessage() {
return ChatColor.translateAlternateColorCodes('&', ConfigManager.languageConfig.get().getString("Extras.Fire.NightMessage"));
}
public static String getMoonriseMessage() {
return ChatColor.translateAlternateColorCodes('&', ConfigManager.languageConfig.get().getString("Extras.Water.NightMessage"));
}
public static String getMoonsetMessage() {
return ChatColor.translateAlternateColorCodes('&', ConfigManager.languageConfig.get().getString("Extras.Water.DayMessage"));
}
}