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); new FireBlastCharged(player);
} }
else if (abil.equalsIgnoreCase("HeatControl")) { else if (abil.equalsIgnoreCase("HeatControl")) {
new HeatControl(player, HeatControlType.SOLIDIFY); new HeatControl(player, HeatControlType.COOK);
} }
else if (abil.equalsIgnoreCase("FireBurst")) { else if (abil.equalsIgnoreCase("FireBurst")) {
new FireBurst(player); 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.MetricsLite;
import com.projectkorra.projectkorra.util.PassiveHandler; import com.projectkorra.projectkorra.util.PassiveHandler;
import com.projectkorra.projectkorra.util.RevertChecker; import com.projectkorra.projectkorra.util.RevertChecker;
import com.projectkorra.projectkorra.util.TempBlock;
import com.projectkorra.projectkorra.util.Updater; import com.projectkorra.projectkorra.util.Updater;
import com.projectkorra.projectkorra.util.logging.PKLogHandler; import com.projectkorra.projectkorra.util.logging.PKLogHandler;
import com.projectkorra.projectkorra.waterbending.WaterbendingManager; import com.projectkorra.projectkorra.waterbending.WaterbendingManager;
@ -35,8 +36,8 @@ public class ProjectKorra extends JavaPlugin {
public static ProjectKorra plugin; public static ProjectKorra plugin;
public static Logger log; public static Logger log;
public static PKLogHandler handler; public static PKLogHandler handler;
public static CollisionManager collisionManager; public static CollisionManager collisionManager;
public static CollisionInitializer collisionInitializer; public static CollisionInitializer collisionInitializer;
public static long time_step = 1; public static long time_step = 1;
public Updater updater; public Updater updater;
@ -61,11 +62,11 @@ public class ProjectKorra extends JavaPlugin {
updater = new Updater(this, "http://projectkorra.com/forums/dev-builds.16/index.rss"); updater = new Updater(this, "http://projectkorra.com/forums/dev-builds.16/index.rss");
new Commands(this); new Commands(this);
new MultiAbilityManager(); new MultiAbilityManager();
new ComboManager(); new ComboManager();
collisionManager = new CollisionManager(); collisionManager = new CollisionManager();
collisionInitializer = new CollisionInitializer(collisionManager); collisionInitializer = new CollisionInitializer(collisionManager);
CoreAbility.registerAbilities(); CoreAbility.registerAbilities();
collisionInitializer.initializeDefaultCollisions(); // must be called after abilities have been registered collisionInitializer.initializeDefaultCollisions(); // must be called after abilities have been registered
collisionManager.startCollisionDetection(); collisionManager.startCollisionDetection();
Preset.loadExternalPresets(); Preset.loadExternalPresets();
@ -90,6 +91,7 @@ public class ProjectKorra extends JavaPlugin {
getServer().getScheduler().scheduleSyncRepeatingTask(this, new ChiblockingManager(this), 0, 1); getServer().getScheduler().scheduleSyncRepeatingTask(this, new ChiblockingManager(this), 0, 1);
getServer().getScheduler().scheduleSyncRepeatingTask(this, new PassiveHandler(), 0, 1); getServer().getScheduler().scheduleSyncRepeatingTask(this, new PassiveHandler(), 0, 1);
getServer().getScheduler().runTaskTimerAsynchronously(this, new RevertChecker(this), 0, 200); getServer().getScheduler().runTaskTimerAsynchronously(this, new RevertChecker(this), 0, 200);
TempBlock.startReversion();
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
PKListener.getJumpStatistics().put(player, player.getStatistic(Statistic.JUMP)); 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.ability.util.Collision;
import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.firebending.BlazeArc; import com.projectkorra.projectkorra.firebending.BlazeArc;
import com.projectkorra.projectkorra.firebending.HeatControl;
import com.projectkorra.projectkorra.util.Information; import com.projectkorra.projectkorra.util.Information;
import com.projectkorra.projectkorra.util.ParticleEffect; import com.projectkorra.projectkorra.util.ParticleEffect;
import com.projectkorra.projectkorra.util.ParticleEffect.ParticleData; import com.projectkorra.projectkorra.util.ParticleEffect.ParticleData;
@ -233,7 +232,6 @@ public abstract class FireAbility extends ElementalAbility {
public static void stopBending() { public static void stopBending() {
BlazeArc.removeAllCleanup(); BlazeArc.removeAllCleanup();
HeatControl.revertAllInstances();
for (Location loc : TEMP_FIRE.keySet()) { for (Location loc : TEMP_FIRE.keySet()) {
revertTempFire(loc); revertTempFire(loc);
} }

View file

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

View file

@ -7,7 +7,6 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.Location; import org.bukkit.Location;
@ -16,10 +15,12 @@ import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ProjectKorra;
import com.projectkorra.projectkorra.ability.EarthAbility; import com.projectkorra.projectkorra.ability.EarthAbility;
import com.projectkorra.projectkorra.ability.FireAbility; import com.projectkorra.projectkorra.ability.FireAbility;
import com.projectkorra.projectkorra.util.ParticleEffect; import com.projectkorra.projectkorra.util.ParticleEffect;
@ -37,40 +38,30 @@ public class HeatControl extends FireAbility {
private HeatControlType heatControlType; private HeatControlType heatControlType;
/* // HeatControl Cook variables
* HeatControl Cook variables
*/
private long cookTime; private long cookTime;
private long cookInterval; private long cookInterval;
/* //HeatControl Extinguish variables
* HeatControl Extinguish variables
*/
private long extinguishCooldown; private long extinguishCooldown;
private double extinguishRadius; private double extinguishRadius;
/* //HeatControl Melt variables
* HeatControl Melt variables
*/
private double meltRange; private double meltRange;
private double meltRadius; private double meltRadius;
private Location meltLocation; private Location meltLocation;
/* //HeatControl Solidify variables
* HeatControl Solidify variables
*/
private int solidifyRadius; private int solidifyRadius;
private long solidifyDelay; private long solidifyDelay;
private long solidifyLastBlockTime; private long solidifyLastBlockTime;
private long solidifyRevertTime;
private double solidifyMaxRadius; private double solidifyMaxRadius;
private double solidifyRange; private double solidifyRange;
private boolean solidifyRevert;
private boolean solidifying; private boolean solidifying;
private Location solidifyLocation; private Location solidifyLocation;
private Random randy; 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) { public HeatControl(Player player, HeatControlType heatControlType) {
super(player); super(player);
@ -79,6 +70,11 @@ public class HeatControl extends FireAbility {
setFields(); setFields();
if (this.heatControlType == HeatControlType.COOK) { if (this.heatControlType == HeatControlType.COOK) {
if (!isCookable(player.getInventory().getItemInMainHand().getType())) {
remove();
new HeatControl(player, HeatControlType.SOLIDIFY);
return;
}
start(); start();
} else if (this.heatControlType == HeatControlType.EXTINGUISH) { } else if (this.heatControlType == HeatControlType.EXTINGUISH) {
@ -103,7 +99,7 @@ public class HeatControl extends FireAbility {
return; return;
} else if (EarthAbility.getLavaSourceBlock(player, solidifyRange) == null) { } else if (EarthAbility.getLavaSourceBlock(player, solidifyRange) == null) {
remove(); remove();
new HeatControl(player, HeatControlType.COOK); new HeatControl(player, HeatControlType.EXTINGUISH);
return; return;
} }
@ -117,7 +113,6 @@ public class HeatControl extends FireAbility {
if (this.heatControlType == HeatControlType.COOK) { if (this.heatControlType == HeatControlType.COOK) {
this.cookTime = System.currentTimeMillis(); this.cookTime = System.currentTimeMillis();
this.cookInterval = getConfig().getLong("Abilities.Fire.HeatControl.Cook.Interval"); this.cookInterval = getConfig().getLong("Abilities.Fire.HeatControl.Cook.Interval");
this.heatControlType = HeatControlType.COOK;
} else if (this.heatControlType == HeatControlType.EXTINGUISH) { } else if (this.heatControlType == HeatControlType.EXTINGUISH) {
this.extinguishCooldown = getConfig().getLong("Abilities.Fire.HeatControl.Extinguish.Cooldown"); this.extinguishCooldown = getConfig().getLong("Abilities.Fire.HeatControl.Extinguish.Cooldown");
this.extinguishRadius = getConfig().getLong("Abilities.Fire.HeatControl.Extinguish.Radius"); this.extinguishRadius = getConfig().getLong("Abilities.Fire.HeatControl.Extinguish.Radius");
@ -133,6 +128,8 @@ public class HeatControl extends FireAbility {
this.solidifyLastBlockTime = 0; this.solidifyLastBlockTime = 0;
this.solidifyMaxRadius = getConfig().getDouble("Abilities.Fire.HeatControl.Solidify.MaxRadius"); this.solidifyMaxRadius = getConfig().getDouble("Abilities.Fire.HeatControl.Solidify.MaxRadius");
this.solidifyRange = getConfig().getDouble("Abilities.Fire.HeatControl.Solidify.Range"); 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(); this.randy = new Random();
} }
} }
@ -147,7 +144,7 @@ public class HeatControl extends FireAbility {
} }
if (this.heatControlType == HeatControlType.COOK) { if (this.heatControlType == HeatControlType.COOK) {
if (!player.isSneaking()) { if (!player.isSneaking()) {
remove(); remove();
return; return;
@ -155,7 +152,6 @@ public class HeatControl extends FireAbility {
if (!isCookable(player.getInventory().getItemInMainHand().getType())) { if (!isCookable(player.getInventory().getItemInMainHand().getType())) {
remove(); remove();
new HeatControl(player, HeatControlType.EXTINGUISH);
return; return;
} }
@ -206,6 +202,10 @@ public class HeatControl extends FireAbility {
} }
Location targetLocation = GeneralMethods.getTargetedLocation(player, solidifyRange); Location targetLocation = GeneralMethods.getTargetedLocation(player, solidifyRange);
//if (isLava(targetLocation.getBlock())) {
// remove();
// new HeatControl(player, HeatControlType.EXTINGUISH);
//}
resetLocation(targetLocation); resetLocation(targetLocation);
List<Location> area = GeneralMethods.getCircle(solidifyLocation, solidifyRadius, 3, true, true, 0); List<Location> area = GeneralMethods.getCircle(solidifyLocation, solidifyRadius, 3, true, true, 0);
solidify(area); solidify(area);
@ -308,7 +308,7 @@ public class HeatControl extends FireAbility {
Block b = lava.get(randy.nextInt(lava.size())); Block b = lava.get(randy.nextInt(lava.size()));
TempBlock tempBlock; final TempBlock tempBlock;
if (TempBlock.isTempBlock(b)) { if (TempBlock.isTempBlock(b)) {
tempBlock = TempBlock.get(b); tempBlock = TempBlock.get(b);
tempBlock.setType(Material.MAGMA, (byte) 0); tempBlock.setType(Material.MAGMA, (byte) 0);
@ -316,39 +316,25 @@ public class HeatControl extends FireAbility {
tempBlock = new TempBlock(b, Material.MAGMA, (byte) 0); tempBlock = new TempBlock(b, Material.MAGMA, (byte) 0);
} }
solidifyStone.put(tempBlock, System.currentTimeMillis()); new BukkitRunnable() {
solidifyRevert.put(tempBlock, System.currentTimeMillis() + 1000); @Override
blocks.add(tempBlock); public void run() {
} if (tempBlock != null) {
if (solidifyRevert) {
@Override tempBlock.setType(Material.STONE, (byte) 0);
public void remove() { tempBlock.setRevertTime(solidifyRevertTime);
solidifying = false; } else {
} tempBlock.revertBlock();
tempBlock.getBlock().setType(Material.STONE);
public void removeInstance() { }
super.remove();
} 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) {
public void revert(TempBlock block) { tempBlock.getBlock().getWorld().playSound(tempBlock.getBlock().getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 0.5F, 1);
if (blocks.contains(block)) { }
block.revertBlock(); }
blocks.remove(block); }
} }.runTaskLater(ProjectKorra.plugin, 20);
}
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) { public void resetLocation(Location loc) {
@ -362,49 +348,6 @@ public class HeatControl extends FireAbility {
solidifyLocation = loc; 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 @Override
public boolean isSneakAbility() { public boolean isSneakAbility() {

View file

@ -1,24 +1,36 @@
package com.projectkorra.projectkorra.util; 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.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Map; import com.projectkorra.projectkorra.GeneralMethods;
import java.util.concurrent.ConcurrentHashMap; import com.projectkorra.projectkorra.ProjectKorra;
public class TempBlock { public class TempBlock {
public static Map<Block, TempBlock> instances = new ConcurrentHashMap<Block, 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 Block block;
private Material newtype; private Material newtype;
private byte newdata; private byte newdata;
private BlockState state; private BlockState state;
private long revertTime;
private boolean inRevertQueue;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public TempBlock(Block block, Material newtype, byte newdata) { public TempBlock(Block block, Material newtype, byte newdata) {
@ -105,6 +117,19 @@ public class TempBlock {
public BlockState getState() { public BlockState getState() {
return state; 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() { public void revertBlock() {
state.update(true); state.update(true);
@ -126,5 +151,26 @@ public class TempBlock {
block.setType(material); block.setType(material);
block.setData(data); 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 double CLEANUP_RANGE = 50;
private static final Map<TempBlock, Player> FROZEN_BLOCKS = new ConcurrentHashMap<>(); 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 sourceSelected;
private boolean settingUp; private boolean settingUp;
@ -38,6 +37,7 @@ public class Torrent extends WaterAbility {
private boolean launch; private boolean launch;
private boolean launching; private boolean launching;
private boolean freeze; private boolean freeze;
private boolean revert;
private int layer; private int layer;
private int maxLayer; private int maxLayer;
private int maxHits; private int maxHits;
@ -45,6 +45,7 @@ public class Torrent extends WaterAbility {
private long time; private long time;
private long interval; private long interval;
private long cooldown; private long cooldown;
private long revertTime;
private double startAngle; private double startAngle;
private double angle; private double angle;
private double radius; private double radius;
@ -80,6 +81,8 @@ public class Torrent extends WaterAbility {
this.range = getConfig().getDouble("Abilities.Water.Torrent.Range"); this.range = getConfig().getDouble("Abilities.Water.Torrent.Range");
this.selectRange = getConfig().getDouble("Abilities.Water.Torrent.SelectRange"); this.selectRange = getConfig().getDouble("Abilities.Water.Torrent.SelectRange");
this.cooldown = getConfig().getLong("Abilities.Water.Torrent.Cooldown"); 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.blocks = new ArrayList<>();
this.launchedBlocks = new ArrayList<>(); this.launchedBlocks = new ArrayList<>();
this.hurtEntities = new ArrayList<>(); this.hurtEntities = new ArrayList<>();
@ -120,7 +123,9 @@ public class Torrent extends WaterAbility {
if (isTransparent(player, block) && block.getType() != Material.ICE) { if (isTransparent(player, block) && block.getType() != Material.ICE) {
TempBlock tblock = new TempBlock(block, Material.ICE, (byte) 0); TempBlock tblock = new TempBlock(block, Material.ICE, (byte) 0);
FROZEN_BLOCKS.put(tblock, player); 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()); playIcebendingSound(block.getLocation());
} }
} }
@ -589,10 +594,6 @@ public class Torrent extends WaterAbility {
} else if (block.getBlock().getType() != Material.ICE) { } else if (block.getBlock().getType() != Material.ICE) {
FROZEN_BLOCKS.remove(block); FROZEN_BLOCKS.remove(block);
continue; 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()) { } else if (!player.isOnline()) {
thaw(block); thaw(block);
continue; continue;