New HeatControl & fixed NPE (#633)

* New HeatControl & NPE fix

* Updated to latest

* Cleaned up HeatControl

* Updated PKListener to use HeatControlType instead of Function

* Cleaned up, cleaned up HeatControl

* Removed melt(...)

* Final changes
This commit is contained in:
Sobki 2016-10-23 16:03:05 +10:00 committed by Christopher Martin
parent 5f0dace64e
commit d34c1ffc20
11 changed files with 475 additions and 687 deletions

View file

@ -579,7 +579,7 @@ public class GeneralMethods {
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
if (ConfigManager.defaultConfig.get().getBoolean("Properties.BendingPreview") == true) {
if (ability != null) {
if (ability != null && bPlayer != null) {
if (bPlayer.isOnCooldown(ability)) {
displayedMessage = ability.getElement().getColor() + "" + ChatColor.STRIKETHROUGH + ability.getName();
@ -1004,16 +1004,17 @@ public class GeneralMethods {
if (avoid.contains(entity)) {
continue;
}
if (entity.getWorld().equals(origin.getWorld())) {
if (entity.getLocation().distanceSquared(origin) < longestr * longestr
&& getDistanceFromLine(direction, origin, entity.getLocation()) < 2
&& (entity instanceof LivingEntity)
&& entity.getEntityId() != player.getEntityId()
&& entity.getLocation().distanceSquared(origin.clone().add(direction)) < entity.getLocation().distanceSquared(origin.clone().add(direction.clone().multiply(-1)))
&& entity.getWorld().equals(origin.getWorld())) {
&& entity.getLocation().distanceSquared(origin.clone().add(direction)) < entity.getLocation().distanceSquared(origin.clone().add(direction.clone().multiply(-1)))) {
target = entity;
longestr = entity.getLocation().distance(origin);
}
}
}
if (target != null) {
List<Block> blocklist = new ArrayList<Block>();
blocklist = GeneralMethods.getBlocksAlongLine(player.getLocation(), target.getLocation(), player.getWorld());

View file

@ -138,8 +138,8 @@ import com.projectkorra.projectkorra.firebending.FireCombo;
import com.projectkorra.projectkorra.firebending.FireDamageTimer;
import com.projectkorra.projectkorra.firebending.FireJet;
import com.projectkorra.projectkorra.firebending.FireShield;
import com.projectkorra.projectkorra.firebending.HeatControlExtinguish;
import com.projectkorra.projectkorra.firebending.HeatControlSolidify;
import com.projectkorra.projectkorra.firebending.HeatControl;
import com.projectkorra.projectkorra.firebending.HeatControl.HeatControlType;
import com.projectkorra.projectkorra.firebending.Illumination;
import com.projectkorra.projectkorra.firebending.Lightning;
import com.projectkorra.projectkorra.firebending.WallOfFire;
@ -794,7 +794,7 @@ public class PKListener implements Listener {
}
if (bPlayer.canBendPassive(Element.FIRE) && bPlayer.hasElement(Element.FIRE) && (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK)) {
event.setCancelled(!HeatControlExtinguish.canBurn(player));
event.setCancelled(!HeatControl.canBurn(player));
}
if (bPlayer.hasElement(Element.EARTH) && event.getCause() == DamageCause.SUFFOCATION && TempBlock.isTempBlock(player.getEyeLocation().getBlock())) {
@ -1345,7 +1345,7 @@ public class PKListener implements Listener {
new FireBlastCharged(player);
}
else if (abil.equalsIgnoreCase("HeatControl")) {
new HeatControlSolidify(player);
new HeatControl(player, HeatControlType.SOLIDIFY);
}
else if (abil.equalsIgnoreCase("FireBurst")) {
new FireBurst(player);
@ -1578,7 +1578,7 @@ public class PKListener implements Listener {
new FireJet(player);
}
else if (abil.equalsIgnoreCase("HeatControl")) {
new HeatControlExtinguish(player);
new HeatControl(player, HeatControlType.MELT);
}
else if (abil.equalsIgnoreCase("Illumination")) {
if (ConfigManager.defaultConfig.get().getBoolean("Abilities.Fire.Illumination.Passive")) {

View file

@ -1,13 +1,12 @@
package com.projectkorra.projectkorra.ability;
import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.firebending.BlazeArc;
import com.projectkorra.projectkorra.firebending.HeatControlSolidify;
import com.projectkorra.projectkorra.util.Information;
import com.projectkorra.projectkorra.util.ParticleEffect;
import com.projectkorra.rpg.RPGMethods;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@ -18,13 +17,14 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.firebending.BlazeArc;
import com.projectkorra.projectkorra.firebending.HeatControl;
import com.projectkorra.projectkorra.util.Information;
import com.projectkorra.projectkorra.util.ParticleEffect;
import com.projectkorra.rpg.RPGMethods;
public abstract class FireAbility extends ElementalAbility {
@ -218,7 +218,7 @@ public abstract class FireAbility extends ElementalAbility {
public static void stopBending() {
BlazeArc.removeAllCleanup();
HeatControlSolidify.revertAllInstances();
HeatControl.revertAllInstances();
for (Location loc : TEMP_FIRE.keySet()) {
revertTempFire(loc);
}

View file

@ -310,7 +310,7 @@ public class ConfigManager {
config.addDefault("Abilities.Fire.FireJet.Description", "This ability is used for a limited burst of flight for firebenders. Clicking with this " + "ability selected will launch you in the direction you're looking, granting you " + "controlled flight for a short time. This ability can be used mid-air to prevent falling " + "to your death, but on the ground it can only be used if standing on a block that's " + "ignitable (e.g. not snow or water).");
config.addDefault("Abilities.Fire.FireShield.Description", "FireShield is a basic defensive ability. " + "Clicking with this ability selected will create a " + "small disc of fire in front of you, which will block most " + "attacks and bending. Alternatively, pressing and holding " + "sneak creates a very small shield of fire, blocking most attacks. " + "Creatures that contact this fire are ignited.");
config.addDefault("Abilities.Fire.FireShield.DeathMessage", "{victim} scorched theirself on {attacker}'s {ability}");
config.addDefault("Abilities.Fire.HeatControl.Description", "While this ability is selected, the firebender becomes impervious " + "to fire damage and cannot be ignited. " + "If the user left-clicks with this ability, the targeted area will be " + "extinguished, although it will leave any creature burning engulfed in flames. " + "This ability can also cool lava. If this ability is used while targetting ice or snow, it" + " will instead melt blocks in that area. Finally, sneaking with this ability will cook any food in your hand.");
config.addDefault("Abilities.Fire.HeatControl.Description", "While this ability is selected, the firebender becomes impervious " + "to fire damage and cannot be ignited. " + "HeatControl has four different functions available to the user.\n" + "Cook - Hold shift while holding any raw food in your hand to cook it.\n" + "Extinguish - Hold shift, and any fire within a configurable radius will be extinguished.\n" + "Melt - Left click while looking at ice in order to melt it.\n" + "Solidify - Hold shift while looking at a body of lava to cool it, turning it into stone.");
config.addDefault("Abilities.Fire.Illumination.Description", "This ability gives firebenders a means of illuminating the area. It is a toggle - clicking " + "will create a torch that follows you around. The torch will only appear on objects that are " + "ignitable and can hold a torch (e.g. not leaves or ice). If you get too far away from the torch, " + "it will disappear, but will reappear when you get on another ignitable block. Clicking again " + "dismisses this torch.");
config.addDefault("Abilities.Fire.Lightning.Description", "Hold sneak while selecting this ability to charge up a lightning strike. Once charged, release sneak to discharge the lightning to the targeted location.");
config.addDefault("Abilities.Fire.Lightning.DeathMessage", "{victim} was electrocuted by {attacker}'s {ability}");
@ -1016,15 +1016,15 @@ public class ConfigManager {
config.addDefault("Abilities.Fire.FireShield.FireTicks", 2);
config.addDefault("Abilities.Fire.HeatControl.Enabled", true);
config.addDefault("Abilities.Fire.HeatControl.Extinguish.Range", 20);
config.addDefault("Abilities.Fire.HeatControl.Extinguish.Radius", 7);
config.addDefault("Abilities.Fire.HeatControl.Extinguish.Cooldown", 500);
config.addDefault("Abilities.Fire.HeatControl.Solidify.Range", 10);
config.addDefault("Abilities.Fire.HeatControl.Solidify.Radius", 7);
config.addDefault("Abilities.Fire.HeatControl.Solidify.RevertTime", 20000);
config.addDefault("Abilities.Fire.HeatControl.Cook.Interval", 1000);
config.addDefault("Abilities.Fire.HeatControl.Extinguish.Cooldown", 5000);
config.addDefault("Abilities.Fire.HeatControl.Extinguish.Radius", 6);
config.addDefault("Abilities.Fire.HeatControl.Melt.Range", 15);
config.addDefault("Abilities.Fire.HeatControl.Melt.Radius", 5);
config.addDefault("Abilities.Fire.HeatControl.Cook.CookTime", 2000);
config.addDefault("Abilities.Fire.HeatControl.Solidify.MaxRadius", 10);
config.addDefault("Abilities.Fire.HeatControl.Solidify.Range", 7);
config.addDefault("Abilities.Fire.HeatControl.Solidify.Revert", true);
config.addDefault("Abilities.Fire.HeatControl.Solidify.RevertTime", 120000);
config.addDefault("Abilities.Fire.Illumination.Enabled", true);
config.addDefault("Abilities.Fire.Illumination.Passive", true);

View file

@ -45,7 +45,7 @@ public class FireDamageTimer {
public static void dealFlameDamage(Entity entity) {
if (INSTANCES.containsKey(entity) && entity instanceof LivingEntity) {
if (entity instanceof Player) {
if (!HeatControlExtinguish.canBurn((Player) entity)) {
if (!HeatControl.canBurn((Player) entity)) {
return;
}
}

View file

@ -17,5 +17,6 @@ public class FirebendingManager implements Runnable {
FirePassive.handlePassive();
BlazeArc.dissipateAll();
FireAbility.removeFire();
HeatControl.manageSolidify();
}
}

View file

@ -0,0 +1,434 @@
package com.projectkorra.projectkorra.firebending;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ability.EarthAbility;
import com.projectkorra.projectkorra.ability.FireAbility;
import com.projectkorra.projectkorra.util.ParticleEffect;
import com.projectkorra.projectkorra.util.TempBlock;
import com.projectkorra.projectkorra.waterbending.PhaseChangeMelt;
public class HeatControl extends FireAbility {
public enum HeatControlType {
COOK, EXTINGUISH, MELT, SOLIDIFY
}
private static final Material[] COOKABLE_MATERIALS = { Material.RAW_BEEF, Material.RAW_CHICKEN,
Material.RAW_FISH, Material.PORK, Material.POTATO_ITEM, Material.RABBIT, Material.MUTTON };
private HeatControlType heatControlType;
/*
* HeatControl Cook variables
*/
private long cookTime;
private long cookInterval;
/*
* HeatControl Extinguish variables
*/
private long extinguishCooldown;
private double extinguishRadius;
/*
* HeatControl Melt variables
*/
private double meltRange;
private double meltRadius;
private Location meltLocation;
/*
* HeatControl Solidify variables
*/
private int solidifyRadius;
private long solidifyDelay;
private long solidifyLastBlockTime;
private double solidifyMaxRadius;
private double solidifyRange;
private boolean solidifying;
private Location solidifyLocation;
private Random randy;
private ConcurrentHashMap<TempBlock, Long> solidifyStone = new ConcurrentHashMap<>();
private ConcurrentHashMap<TempBlock, Long> solidifyRevert = new ConcurrentHashMap<>();
private List<TempBlock> blocks = new ArrayList<>();
public HeatControl(Player player, HeatControlType heatControlType) {
super(player);
this.heatControlType = heatControlType;
setFields();
if (this.heatControlType == HeatControlType.COOK) {
start();
} else if (this.heatControlType == HeatControlType.EXTINGUISH) {
if (bPlayer.isOnCooldown(getName() + "Extinguish")) {
remove();
return;
}
start();
} else if (this.heatControlType == HeatControlType.MELT) {
meltLocation = GeneralMethods.getTargetedLocation(player, meltRange);
for (Block block : GeneralMethods.getBlocksAroundPoint(meltLocation, meltRadius)) {
if (isMeltable(block)) {
PhaseChangeMelt.melt(player, block);
}
}
} else if (this.heatControlType == HeatControlType.SOLIDIFY) {
if (!bPlayer.canBend(this)) {
return;
} else if (EarthAbility.getLavaSourceBlock(player, solidifyRange) == null) {
remove();
new HeatControl(player, HeatControlType.COOK);
return;
}
solidifyLastBlockTime = System.currentTimeMillis();
start();
}
}
public void setFields() {
if (this.heatControlType == HeatControlType.COOK) {
this.cookTime = System.currentTimeMillis();
this.cookInterval = getConfig().getLong("Abilities.Fire.HeatControl.Cook.Interval");
this.heatControlType = HeatControlType.COOK;
} else if (this.heatControlType == HeatControlType.EXTINGUISH) {
this.extinguishCooldown = getConfig().getLong("Abilities.Fire.HeatControl.Extinguish.Cooldown");
this.extinguishRadius = getConfig().getLong("Abilities.Fire.HeatControl.Extinguish.Radius");
this.extinguishRadius = getDayFactor(this.extinguishRadius);
} else if (this.heatControlType == HeatControlType.MELT) {
this.meltRange = getConfig().getDouble("Abilities.Fire.HeatControl.Melt.Range");
this.meltRadius = getConfig().getDouble("Abilities.Fire.HeatControl.Melt.Radius");
this.meltRange = getDayFactor(this.meltRange);
this.meltRadius = getDayFactor(this.meltRadius);
} else if (this.heatControlType == HeatControlType.SOLIDIFY) {
this.solidifyRadius = 1;
this.solidifyDelay = 50;
this.solidifyLastBlockTime = 0;
this.solidifyMaxRadius = getConfig().getDouble("Abilities.Fire.HeatControl.Solidify.MaxRadius");
this.solidifyRange = getConfig().getDouble("Abilities.Fire.HeatControl.Solidify.Range");
this.randy = new Random();
}
}
@SuppressWarnings("deprecation")
@Override
public void progress() {
if (!bPlayer.canBend(this)) {
remove();
return;
}
if (this.heatControlType == HeatControlType.COOK) {
if (!player.isSneaking()) {
remove();
return;
}
if (!isCookable(player.getInventory().getItemInMainHand().getType())) {
remove();
new HeatControl(player, HeatControlType.EXTINGUISH);
return;
}
if (System.currentTimeMillis() - cookTime > cookInterval) {
cook();
cookTime = System.currentTimeMillis();
return;
}
displayCookParticles();
} else if (this.heatControlType == HeatControlType.EXTINGUISH) {
if (!player.isSneaking()) {
bPlayer.addCooldown(getName() + "Extinguish", extinguishCooldown);
remove();
return;
}
Set<Material> blocks = new HashSet<>();
for (int material : GeneralMethods.NON_OPAQUE) {
blocks.add(Material.getMaterial(material));
}
for (Block block : GeneralMethods.getBlocksAroundPoint(player.getLocation(), extinguishRadius)) {
Material material = block.getType();
if (material == Material.FIRE && !GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) {
block.setType(Material.AIR);
block.getWorld().playEffect(block.getLocation(), Effect.EXTINGUISH, 0);
}
}
} else if (this.heatControlType == HeatControlType.SOLIDIFY) {
if (solidifyRadius >= solidifyMaxRadius) {
remove();
return;
}
if (!player.isSneaking()) {
remove();
return;
}
if (!solidifying) {
solidifying = true;
}
Location targetLocation = GeneralMethods.getTargetedLocation(player, solidifyRange);
resetLocation(targetLocation);
List<Location> area = GeneralMethods.getCircle(solidifyLocation, solidifyRadius, 3, true, true, 0);
solidify(area);
}
}
private void cook() {
ItemStack cooked = getCooked(player.getInventory().getItemInMainHand());
HashMap<Integer, ItemStack> cantFit = player.getInventory().addItem(cooked);
for (int id : cantFit.keySet()) {
player.getWorld().dropItem(player.getEyeLocation(), cantFit.get(id));
}
int amount = player.getInventory().getItemInMainHand().getAmount();
if (amount == 1) {
player.getInventory().clear(player.getInventory().getHeldItemSlot());
} else {
player.getInventory().getItemInMainHand().setAmount(amount - 1);
}
}
private ItemStack getCooked(ItemStack is) {
ItemStack cooked = new ItemStack(Material.AIR);
Material material = is.getType();
switch (material) {
case RAW_BEEF:
cooked = new ItemStack(Material.COOKED_BEEF, 1);
break;
case RAW_FISH:
ItemStack salmon = new ItemStack(Material.RAW_FISH, 1, (short) 1);
if (is.getDurability() == salmon.getDurability()) {
cooked = new ItemStack(Material.COOKED_FISH, 1, (short) 1);
} else {
cooked = new ItemStack(Material.COOKED_FISH, 1);
}
break;
case RAW_CHICKEN:
cooked = new ItemStack(Material.COOKED_CHICKEN, 1);
break;
case PORK:
cooked = new ItemStack(Material.GRILLED_PORK, 1);
break;
case POTATO_ITEM:
cooked = new ItemStack(Material.BAKED_POTATO, 1);
break;
case MUTTON:
cooked = new ItemStack(Material.COOKED_MUTTON);
break;
case RABBIT:
cooked = new ItemStack(Material.COOKED_RABBIT);
break;
default:
break;
}
return cooked;
}
public void displayCookParticles() {
ParticleEffect.FLAME.display(player.getLocation().clone().add(0, 1, 0), 0.5F, 0.5F, 0.5F, 0, 3);
ParticleEffect.SMOKE.display(player.getLocation().clone().add(0, 1, 0), 0.5F, 0.5F, 0.5F, 0, 2);
}
public static boolean isCookable(Material material) {
return Arrays.asList(COOKABLE_MATERIALS).contains(material);
}
public static boolean canBurn(Player player) {
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
if (bPlayer == null) {
return true;
} else if (bPlayer.getBoundAbilityName().equals("HeatControl") || hasAbility(player, FireJet.class)) {
player.setFireTicks(-1);
return false;
} else if (player.getFireTicks() > 80 && bPlayer.canBendPassive(Element.FIRE)) {
player.setFireTicks(80);
}
return true;
}
public void solidify(List<Location> area) {
if (System.currentTimeMillis() < solidifyLastBlockTime + solidifyDelay) {
return;
}
List<Block> lava = new ArrayList<Block>();
for (Location l : area) {
if (isLava(l.getBlock())) {
lava.add(l.getBlock());
}
}
solidifyLastBlockTime = System.currentTimeMillis();
if (lava.size() == 0) {
solidifyRadius++;
return;
}
Block b = lava.get(randy.nextInt(lava.size()));
TempBlock tempBlock;
if (TempBlock.isTempBlock(b)) {
tempBlock = TempBlock.get(b);
tempBlock.setType(Material.MAGMA, (byte) 0);
} else {
tempBlock = new TempBlock(b, Material.MAGMA, (byte) 0);
}
solidifyStone.put(tempBlock, System.currentTimeMillis());
solidifyRevert.put(tempBlock, System.currentTimeMillis() + 1000);
blocks.add(tempBlock);
}
@Override
public void remove() {
solidifying = false;
}
public void removeInstance() {
super.remove();
}
public void revert(TempBlock block) {
if (blocks.contains(block)) {
block.revertBlock();
blocks.remove(block);
}
}
public void revertAll() {
for (TempBlock tempBlock : blocks) {
tempBlock.revertBlock();
}
blocks.clear();
}
public static void revertAllInstances() {
for (HeatControl heatControl : getAbilities(HeatControl.class)) {
heatControl.revertAll();
}
}
public void resetLocation(Location loc) {
if (solidifyLocation == null) {
solidifyLocation = loc;
return;
}
if (!loc.equals(solidifyLocation)) {
solidifyRadius = 1;
solidifyLocation = loc;
}
}
public static void manageSolidify() {
for (HeatControl heatControl : getAbilities(HeatControl.class)) {
for (TempBlock tempBlock : heatControl.solidifyStone.keySet()) {
if (System.currentTimeMillis() - heatControl.solidifyStone.get(tempBlock) > 1000) {
if (getConfig().getBoolean("Abilities.Fire.HeatControl.Solidify.Revert")) {
tempBlock.setType(Material.STONE, (byte) 0);
heatControl.solidifyRevert.put(tempBlock, System.currentTimeMillis());
} else {
tempBlock.revertBlock();
tempBlock.getBlock().setType(Material.STONE);
}
ParticleEffect.SMOKE.display(tempBlock.getBlock().getLocation().clone().add(0.5, 1, 0.5), 0.1F, 0.1F, 0.1F, 0.01F, 3);
// TODO play the smoke in a line from the block to above the player's head.
tempBlock.getBlock().getWorld().playSound(tempBlock.getBlock().getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 1, 1);
heatControl.solidifyStone.remove(tempBlock);
}
}
for (TempBlock tempBlock : heatControl.solidifyRevert.keySet()) {
if (System.currentTimeMillis() - heatControl.solidifyRevert.get(tempBlock) > getConfig().getLong("Abilities.Fire.HeatControl.Solidify.RevertTime")) {
heatControl.revert(tempBlock);
heatControl.solidifyRevert.remove(tempBlock);
}
}
if (heatControl.solidifyStone.isEmpty() && heatControl.solidifyRevert.isEmpty() && !heatControl.solidifying) {
heatControl.removeInstance();
}
}
}
@Override
public boolean isSneakAbility() {
return true;
}
@Override
public boolean isHarmlessAbility() {
return true;
}
@Override
public long getCooldown() {
return 0;
}
@Override
public String getName() {
return "HeatControl";
}
@Override
public Location getLocation() {
return player.getLocation();
}
}

View file

@ -1,166 +0,0 @@
package com.projectkorra.projectkorra.firebending;
import com.projectkorra.projectkorra.ability.FireAbility;
import com.projectkorra.projectkorra.util.ParticleEffect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
import java.util.HashMap;
public class HeatControlCook extends FireAbility {
private static final Material[] COOKABLE_MATERIALS = { Material.RAW_BEEF, Material.RAW_CHICKEN,
Material.RAW_FISH, Material.PORK, Material.POTATO_ITEM, Material.RABBIT, Material.MUTTON };
private long time;
private long cookTime;
private ItemStack item;
public HeatControlCook(Player player) {
super(player);
this.time = System.currentTimeMillis();
this.cookTime = getConfig().getLong("Abilities.Fire.HeatControl.Cook.CookTime");
this.item = player.getInventory().getItemInMainHand();
if (isCookable(item.getType())) {
start();
}
}
private void cook() {
ItemStack cooked = getCooked(item);
HashMap<Integer, ItemStack> cantFit = player.getInventory().addItem(cooked);
for (int id : cantFit.keySet()) {
player.getWorld().dropItem(player.getEyeLocation(), cantFit.get(id));
}
int amount = item.getAmount();
if (amount == 1) {
player.getInventory().clear(player.getInventory().getHeldItemSlot());
} else {
item.setAmount(amount - 1);
}
}
private ItemStack getCooked(ItemStack is) {
ItemStack cooked = new ItemStack(Material.AIR);
Material material = is.getType();
switch (material) {
case RAW_BEEF:
cooked = new ItemStack(Material.COOKED_BEEF, 1);
break;
case RAW_FISH:
ItemStack salmon = new ItemStack(Material.RAW_FISH, 1, (short) 1);
if (is.getDurability() == salmon.getDurability()) {
cooked = new ItemStack(Material.COOKED_FISH, 1, (short) 1);
} else {
cooked = new ItemStack(Material.COOKED_FISH, 1);
}
break;
case RAW_CHICKEN:
cooked = new ItemStack(Material.COOKED_CHICKEN, 1);
break;
case PORK:
cooked = new ItemStack(Material.GRILLED_PORK, 1);
break;
case POTATO_ITEM:
cooked = new ItemStack(Material.BAKED_POTATO, 1);
break;
case MUTTON:
cooked = new ItemStack(Material.COOKED_MUTTON);
break;
case RABBIT:
cooked = new ItemStack(Material.COOKED_RABBIT);
break;
default:
break;
}
return cooked;
}
@Override
public void progress() {
if (!bPlayer.canBendIgnoreCooldowns(this)) {
remove();
return;
} else if (!item.equals(player.getInventory().getItemInMainHand())) {
time = System.currentTimeMillis();
item = player.getInventory().getItemInMainHand();
}
if (!isCookable(item.getType())) {
remove();
return;
} else if (System.currentTimeMillis() > time + cookTime) {
cook();
time = System.currentTimeMillis();
}
ParticleEffect.FLAME.display(player.getEyeLocation(), 0.6F, 0.6F, 0.6F, 0, 3);
ParticleEffect.SMOKE.display(player.getEyeLocation(), 0.6F, 0.6F, 0.6F, 0, 1);
}
public static boolean isCookable(Material material) {
return Arrays.asList(COOKABLE_MATERIALS).contains(material);
}
@Override
public String getName() {
return "HeatControl";
}
@Override
public Location getLocation() {
return player != null ? player.getLocation() : null;
}
@Override
public long getCooldown() {
return 0;
}
@Override
public boolean isSneakAbility() {
return false;
}
@Override
public boolean isHarmlessAbility() {
return true;
}
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
public long getCookTime() {
return cookTime;
}
public void setCookTime(long cookTime) {
this.cookTime = cookTime;
}
public ItemStack getItem() {
return item;
}
public void setItem(ItemStack item) {
this.item = item;
}
public static Material[] getCookableMaterials() {
return COOKABLE_MATERIALS;
}
}

View file

@ -1,129 +0,0 @@
package com.projectkorra.projectkorra.firebending;
import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ability.FireAbility;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import java.util.HashSet;
import java.util.Set;
public class HeatControlExtinguish extends FireAbility {
private double range;
private double radius;
private long cooldown;
private Location location;
@SuppressWarnings("deprecation")
public HeatControlExtinguish(Player player) {
super(player);
if (!bPlayer.canBend(this) || bPlayer.isOnCooldown("HeatControlExtinguish")) {
return;
}
this.range = getConfig().getDouble("Abilities.Fire.HeatControl.Extinguish.Range");
this.radius = getConfig().getDouble("Abilities.Fire.HeatControl.Extinguish.Radius");
this.cooldown = getConfig().getLong("Abilities.Fire.HeatControl.Extinguish.Cooldown");
this.range = getDayFactor(this.range);
this.radius = getDayFactor(this.radius);
Set<Material> blocks = new HashSet<Material>();
for (Integer mat : GeneralMethods.NON_OPAQUE) {
blocks.add(Material.getMaterial(mat));
}
if (isMeltable(player.getTargetBlock(blocks, (int) range))) {
new HeatControlMelt(player);
return;
}
location = player.getTargetBlock((HashSet<Material>) null, (int) range).getLocation();
for (Block block : GeneralMethods.getBlocksAroundPoint(location, radius)) {
Material mat = block.getType();
if (mat != Material.FIRE) {
continue;
} else if (GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) {
continue;
} else if (block.getType() == Material.FIRE) {
block.setType(Material.AIR);
block.getWorld().playEffect(block.getLocation(), Effect.EXTINGUISH, 0);
}
}
bPlayer.addCooldown("HeatControlExtinguish", cooldown);
}
public static boolean canBurn(Player player) {
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
if (bPlayer == null) {
return true;
} else if (bPlayer.getBoundAbilityName().equals("HeatControl") || hasAbility(player, FireJet.class)) {
player.setFireTicks(-1);
return false;
} else if (player.getFireTicks() > 80 && bPlayer.canBendPassive(Element.FIRE)) {
player.setFireTicks(80);
}
return true;
}
@Override
public String getName() {
return "HeatControl";
}
@Override
public void progress() {
}
@Override
public Location getLocation() {
return location;
}
@Override
public long getCooldown() {
return cooldown;
}
@Override
public boolean isSneakAbility() {
return false;
}
@Override
public boolean isHarmlessAbility() {
return true;
}
public double getRange() {
return range;
}
public void setRange(double range) {
this.range = range;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public void setCooldown(long cooldown) {
this.cooldown = cooldown;
}
public void setLocation(Location location) {
this.location = location;
}
}

View file

@ -1,98 +0,0 @@
package com.projectkorra.projectkorra.firebending;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ability.FireAbility;
import com.projectkorra.projectkorra.waterbending.PhaseChangeMelt;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
public class HeatControlMelt extends FireAbility {
private double range = getConfig().getDouble("Abilities.Fire.HeatControl.Melt.Range");
private double radius = getConfig().getDouble("Abilities.Fire.HeatControl.Melt.Radius");
private Location location;
public HeatControlMelt(Player player) {
super(player);
this.range = getConfig().getDouble("Abilities.Fire.HeatControl.Melt.Range");
this.radius = getConfig().getDouble("Abilities.Fire.HeatControl.Melt.Radius");
this.range = getDayFactor(range);
this.radius = getDayFactor(radius);
location = GeneralMethods.getTargetedLocation(player, range);
for (Block block : GeneralMethods.getBlocksAroundPoint(location, radius)) {
if (isMeltable(block)) {
PhaseChangeMelt.melt(player, block);
} else if (isHeatable(block)) {
heat(block);
}
}
}
@SuppressWarnings("deprecation")
private static void heat(Block block) {
if (block.getType() == Material.OBSIDIAN) {
block.setType(Material.LAVA);
block.setData((byte) 0x0);
}
}
private static boolean isHeatable(Block block) {
return false;
}
@Override
public String getName() {
return "HeatControl";
}
@Override
public void progress() {
}
@Override
public Location getLocation() {
return location;
}
@Override
public long getCooldown() {
return 0;
}
@Override
public boolean isSneakAbility() {
return false;
}
@Override
public boolean isHarmlessAbility() {
return true;
}
public double getRange() {
return range;
}
public void setRange(double range) {
this.range = range;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public void setLocation(Location location) {
this.location = location;
}
}

View file

@ -1,255 +0,0 @@
package com.projectkorra.projectkorra.firebending;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ProjectKorra;
import com.projectkorra.projectkorra.ability.EarthAbility;
import com.projectkorra.projectkorra.ability.FireAbility;
import com.projectkorra.projectkorra.util.ParticleEffect;
import com.projectkorra.projectkorra.util.TempBlock;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class HeatControlSolidify extends FireAbility {
private int radius;
private long delay;
private long lastBlockTime;
private long lastParticleTime;
private long revertTime;
private double maxRadius;
private double range;
private Location location;
private Random random;
private ArrayList<TempBlock> tempBlocks;
public HeatControlSolidify(Player player) {
super(player);
this.radius = 1;
this.delay = 50;
this.lastBlockTime = 0;
this.lastParticleTime = 0;
this.revertTime = getConfig().getLong("Abilities.Fire.HeatControl.Solidify.RevertTime");
this.maxRadius = getConfig().getDouble("Abilities.Fire.HeatControl.Solidify.Radius");
this.range = getConfig().getDouble("Abilities.Fire.HeatControl.Solidify.Range");
this.random = new Random();
this.tempBlocks = new ArrayList<>();
if (!bPlayer.canBend(this)) {
return;
} else if (EarthAbility.getLavaSourceBlock(player, range) == null) {
new HeatControlCook(player);
return;
}
lastBlockTime = System.currentTimeMillis();
start();
}
@SuppressWarnings("deprecation")
public void freeze(List<Location> area) {
if (System.currentTimeMillis() < lastBlockTime + delay) {
return;
}
List<Block> lava = new ArrayList<Block>();
for (Location l : area) {
if (isLava(l.getBlock())) {
lava.add(l.getBlock());
}
}
lastBlockTime = System.currentTimeMillis();
if (lava.size() == 0) {
radius++;
return;
}
Block b = lava.get(random.nextInt(lava.size()));
TempBlock tb;
if (TempBlock.isTempBlock(b)) {
tb = TempBlock.get(b);
tb.setType(Material.STONE);
} else {
tb = new TempBlock(b, Material.STONE, b.getData());
}
if (!tempBlocks.contains(tb)) {
tempBlocks.add(tb);
}
}
public void particles(List<Location> area) {
if (System.currentTimeMillis() < lastParticleTime + 300) {
return;
}
lastParticleTime = System.currentTimeMillis();
for (Location l : area) {
if (isLava(l.getBlock())) {
ParticleEffect.SMOKE.display(l, 0, 0, 0, 0.1f, 2);
}
}
}
@Override
public void progress() {
if (!bPlayer.canBendIgnoreCooldowns(this)) {
remove();
return;
} else if (radius >= maxRadius) {
remove();
return;
}
Location targetlocation = GeneralMethods.getTargetedLocation(player, range);
resetLocation(targetlocation);
List<Location> area = GeneralMethods.getCircle(location, radius, 3, true, true, 0);
particles(area);
freeze(area);
}
@Override
public void remove() {
if(Bukkit.getServer().getPluginManager().isPluginEnabled(ProjectKorra.plugin.getName())) {
revert();
} else {
HeatControlSolidify.super.remove();
}
}
public void revert() {
new BukkitRunnable() {
@Override
public void run() {
revertAll();
HeatControlSolidify.super.remove();
}
}.runTaskLater(ProjectKorra.plugin, revertTime);
}
public static void revertAllInstances() {
for (HeatControlSolidify heatControlSolidify : getAbilities(HeatControlSolidify.class)) {
heatControlSolidify.revertAll();
}
}
public void resetLocation(Location loc) {
if (location == null) {
location = loc;
return;
}
if (!loc.equals(location)) {
radius = 1;
location = loc;
}
}
public void revertAll() {
for (TempBlock tb : tempBlocks) {
tb.revertBlock();
}
tempBlocks.clear();
}
@Override
public String getName() {
return "HeatControl";
}
@Override
public Location getLocation() {
return location;
}
@Override
public long getCooldown() {
return 0;
}
@Override
public boolean isSneakAbility() {
return false;
}
@Override
public boolean isHarmlessAbility() {
return true;
}
public int getRadius() {
return radius;
}
public void setRadius(int radius) {
this.radius = radius;
}
public long getDelay() {
return delay;
}
public void setDelay(long delay) {
this.delay = delay;
}
public long getLastBlockTime() {
return lastBlockTime;
}
public void setLastBlockTime(long lastBlockTime) {
this.lastBlockTime = lastBlockTime;
}
public long getLastParticleTime() {
return lastParticleTime;
}
public void setLastParticleTime(long lastParticleTime) {
this.lastParticleTime = lastParticleTime;
}
public long getRevertTime() {
return revertTime;
}
public void setRevertTime(long revertTime) {
this.revertTime = revertTime;
}
public double getMaxRadius() {
return maxRadius;
}
public void setMaxRadius(double maxRadius) {
this.maxRadius = maxRadius;
}
public double getRange() {
return range;
}
public void setRange(double range) {
this.range = range;
}
public ArrayList<TempBlock> getTempBlocks() {
return tempBlocks;
}
public void setLocation(Location location) {
this.location = location;
}
}