Updated&Fixed HeatControl, added TempBlock delayed reversion (#656)

* Fixed all my derps 💃

* 1 more timeee
This commit is contained in:
Sobki 2016-11-26 08:02:54 +10:00 committed by Christopher Martin
parent 2d9b4e7079
commit cbb3581a12
7 changed files with 104 additions and 115 deletions

View file

@ -1345,7 +1345,7 @@ public class PKListener implements Listener {
new FireBlastCharged(player);
}
else if (abil.equalsIgnoreCase("HeatControl")) {
new HeatControl(player, HeatControlType.SOLIDIFY);
new HeatControl(player, HeatControlType.COOK);
}
else if (abil.equalsIgnoreCase("FireBurst")) {
new FireBurst(player);

View file

@ -26,6 +26,7 @@ import com.projectkorra.projectkorra.storage.DBConnection;
import com.projectkorra.projectkorra.util.MetricsLite;
import com.projectkorra.projectkorra.util.PassiveHandler;
import com.projectkorra.projectkorra.util.RevertChecker;
import com.projectkorra.projectkorra.util.TempBlock;
import com.projectkorra.projectkorra.util.Updater;
import com.projectkorra.projectkorra.util.logging.PKLogHandler;
import com.projectkorra.projectkorra.waterbending.WaterbendingManager;
@ -90,6 +91,7 @@ public class ProjectKorra extends JavaPlugin {
getServer().getScheduler().scheduleSyncRepeatingTask(this, new ChiblockingManager(this), 0, 1);
getServer().getScheduler().scheduleSyncRepeatingTask(this, new PassiveHandler(), 0, 1);
getServer().getScheduler().runTaskTimerAsynchronously(this, new RevertChecker(this), 0, 200);
TempBlock.startReversion();
for (Player player : Bukkit.getOnlinePlayers()) {
PKListener.getJumpStatistics().put(player, player.getStatistic(Statistic.JUMP));

View file

@ -22,7 +22,6 @@ import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ability.util.Collision;
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.projectkorra.util.ParticleEffect.ParticleData;
@ -233,7 +232,6 @@ public abstract class FireAbility extends ElementalAbility {
public static void stopBending() {
BlazeArc.removeAllCleanup();
HeatControl.revertAllInstances();
for (Location loc : TEMP_FIRE.keySet()) {
revertTempFire(loc);
}

View file

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

View file

@ -7,7 +7,6 @@ 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;
@ -16,10 +15,12 @@ import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.Element;
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;
@ -37,40 +38,30 @@ public class HeatControl extends FireAbility {
private HeatControlType heatControlType;
/*
* HeatControl Cook variables
*/
// HeatControl Cook variables
private long cookTime;
private long cookInterval;
/*
* HeatControl Extinguish variables
*/
//HeatControl Extinguish variables
private long extinguishCooldown;
private double extinguishRadius;
/*
* HeatControl Melt variables
*/
//HeatControl Melt variables
private double meltRange;
private double meltRadius;
private Location meltLocation;
/*
* HeatControl Solidify variables
*/
//HeatControl Solidify variables
private int solidifyRadius;
private long solidifyDelay;
private long solidifyLastBlockTime;
private long solidifyRevertTime;
private double solidifyMaxRadius;
private double solidifyRange;
private boolean solidifyRevert;
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);
@ -79,6 +70,11 @@ public class HeatControl extends FireAbility {
setFields();
if (this.heatControlType == HeatControlType.COOK) {
if (!isCookable(player.getInventory().getItemInMainHand().getType())) {
remove();
new HeatControl(player, HeatControlType.SOLIDIFY);
return;
}
start();
} else if (this.heatControlType == HeatControlType.EXTINGUISH) {
@ -103,7 +99,7 @@ public class HeatControl extends FireAbility {
return;
} else if (EarthAbility.getLavaSourceBlock(player, solidifyRange) == null) {
remove();
new HeatControl(player, HeatControlType.COOK);
new HeatControl(player, HeatControlType.EXTINGUISH);
return;
}
@ -117,7 +113,6 @@ public class HeatControl extends FireAbility {
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");
@ -133,6 +128,8 @@ public class HeatControl extends FireAbility {
this.solidifyLastBlockTime = 0;
this.solidifyMaxRadius = getConfig().getDouble("Abilities.Fire.HeatControl.Solidify.MaxRadius");
this.solidifyRange = getConfig().getDouble("Abilities.Fire.HeatControl.Solidify.Range");
this.solidifyRevert = getConfig().getBoolean("Abilities.Fire.HeatControl.Solidify.Revert");
this.solidifyRevertTime = getConfig().getLong("Abilities.Fire.HeatControl.Solidify.RevertTime");
this.randy = new Random();
}
}
@ -155,7 +152,6 @@ public class HeatControl extends FireAbility {
if (!isCookable(player.getInventory().getItemInMainHand().getType())) {
remove();
new HeatControl(player, HeatControlType.EXTINGUISH);
return;
}
@ -206,6 +202,10 @@ public class HeatControl extends FireAbility {
}
Location targetLocation = GeneralMethods.getTargetedLocation(player, solidifyRange);
//if (isLava(targetLocation.getBlock())) {
// remove();
// new HeatControl(player, HeatControlType.EXTINGUISH);
//}
resetLocation(targetLocation);
List<Location> area = GeneralMethods.getCircle(solidifyLocation, solidifyRadius, 3, true, true, 0);
solidify(area);
@ -308,7 +308,7 @@ public class HeatControl extends FireAbility {
Block b = lava.get(randy.nextInt(lava.size()));
TempBlock tempBlock;
final TempBlock tempBlock;
if (TempBlock.isTempBlock(b)) {
tempBlock = TempBlock.get(b);
tempBlock.setType(Material.MAGMA, (byte) 0);
@ -316,40 +316,26 @@ public class HeatControl extends FireAbility {
tempBlock = new TempBlock(b, Material.MAGMA, (byte) 0);
}
solidifyStone.put(tempBlock, System.currentTimeMillis());
solidifyRevert.put(tempBlock, System.currentTimeMillis() + 1000);
blocks.add(tempBlock);
}
new BukkitRunnable() {
@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) {
public void run() {
if (tempBlock != null) {
if (solidifyRevert) {
tempBlock.setType(Material.STONE, (byte) 0);
tempBlock.setRevertTime(solidifyRevertTime);
} else {
tempBlock.revertBlock();
tempBlock.getBlock().setType(Material.STONE);
}
blocks.clear();
ParticleEffect.SMOKE.display(tempBlock.getBlock().getLocation().clone().add(0.5, 1, 0.5), 0.1F, 0.1F, 0.1F, 0.01F, 3);
if (randy.nextInt(3) == 0) {
tempBlock.getBlock().getWorld().playSound(tempBlock.getBlock().getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 0.5F, 1);
}
public static void revertAllInstances() {
for (HeatControl heatControl : getAbilities(HeatControl.class)) {
heatControl.revertAll();
}
}
}.runTaskLater(ProjectKorra.plugin, 20);
}
public void resetLocation(Location loc) {
if (solidifyLocation == null) {
@ -363,49 +349,6 @@ public class HeatControl extends FireAbility {
}
}
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;

View file

@ -1,24 +1,36 @@
package com.projectkorra.projectkorra.util;
import com.projectkorra.projectkorra.GeneralMethods;
import java.util.Comparator;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ProjectKorra;
public class TempBlock {
public static Map<Block, TempBlock> instances = new ConcurrentHashMap<Block, TempBlock>();
public static final PriorityQueue<TempBlock> REVERT_QUEUE = new PriorityQueue<>(100, new Comparator<TempBlock>() {
@Override
public int compare(TempBlock t1, TempBlock t2) {
return (int) (t1.revertTime - t2.revertTime);
}
});
private Block block;
private Material newtype;
private byte newdata;
private BlockState state;
private long revertTime;
private boolean inRevertQueue;
@SuppressWarnings("deprecation")
public TempBlock(Block block, Material newtype, byte newdata) {
@ -106,6 +118,19 @@ public class TempBlock {
return state;
}
public long getRevertTime() {
return revertTime;
}
public void setRevertTime(long revertTime) {
if (inRevertQueue) {
REVERT_QUEUE.remove(this);
}
this.inRevertQueue = true;
this.revertTime = revertTime + System.currentTimeMillis();
REVERT_QUEUE.add(this);
}
public void revertBlock() {
state.update(true);
instances.remove(block);
@ -127,4 +152,25 @@ public class TempBlock {
block.setData(data);
}
public static void startReversion() {
new BukkitRunnable() {
@Override
public void run() {
long currentTime = System.currentTimeMillis();
while (!REVERT_QUEUE.isEmpty()) {
TempBlock tempBlock = REVERT_QUEUE.peek();
if (currentTime >= tempBlock.revertTime) {
REVERT_QUEUE.poll();
tempBlock.revertBlock();
//long finish = System.currentTimeMillis();
//Bukkit.broadcastMessage(String.valueOf(finish - currentTime));
} else {
break;
}
}
}
}.runTaskTimer(ProjectKorra.plugin, 0, 1);
}
}

View file

@ -29,7 +29,6 @@ public class Torrent extends WaterAbility {
private static final double CLEANUP_RANGE = 50;
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 settingUp;
@ -38,6 +37,7 @@ public class Torrent extends WaterAbility {
private boolean launch;
private boolean launching;
private boolean freeze;
private boolean revert;
private int layer;
private int maxLayer;
private int maxHits;
@ -45,6 +45,7 @@ public class Torrent extends WaterAbility {
private long time;
private long interval;
private long cooldown;
private long revertTime;
private double startAngle;
private double angle;
private double radius;
@ -80,6 +81,8 @@ public class Torrent extends WaterAbility {
this.range = getConfig().getDouble("Abilities.Water.Torrent.Range");
this.selectRange = getConfig().getDouble("Abilities.Water.Torrent.SelectRange");
this.cooldown = getConfig().getLong("Abilities.Water.Torrent.Cooldown");
this.revert = getConfig().getBoolean("Abilities.Water.Torrent.Revert");
this.revertTime = getConfig().getLong("Abilities.Water.Torrent.RevertTime");
this.blocks = new ArrayList<>();
this.launchedBlocks = new ArrayList<>();
this.hurtEntities = new ArrayList<>();
@ -120,7 +123,9 @@ public class Torrent extends WaterAbility {
if (isTransparent(player, block) && block.getType() != Material.ICE) {
TempBlock tblock = new TempBlock(block, Material.ICE, (byte) 0);
FROZEN_BLOCKS.put(tblock, player);
FROZEN_BLOCKS_DELAY.put(tblock, System.currentTimeMillis() + (new Random().nextInt((500 + 500) + 1) - 500));
if (revert) {
tblock.setRevertTime(revertTime + (new Random().nextInt((500 + 500) + 1) - 500));
}
playIcebendingSound(block.getLocation());
}
}
@ -589,10 +594,6 @@ public class Torrent extends WaterAbility {
} else if (block.getBlock().getType() != Material.ICE) {
FROZEN_BLOCKS.remove(block);
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()) {
thaw(block);
continue;