mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2024-05-15 17:31:26 +00:00
787b303c9f
## Additions * Adds a built-in bending board sidebar to visualize bound abilities and cooldowns. * The board respects worlds where bending is disabled. * Players can use the command `/pk board` to toggle the visibility of their board. * Includes an API that community developers can use in BendingBoardManager. * Adds the `"Properties.BendingBoard"` config option to enable or disable the board server. * Adds language file configuration options to control BendingBoard visuals. * `"Board.Title"` * Controls the title at the top of the board. * Supports the standard Minecraft color codes. * `"Board.SelectionPrefix"` * Controls the prefix shown corresponding to your current hot bar slot. * Supports the standard Minecraft color codes. * `"Board.EmptySlot"` * Controls what is shown for empty slots. * Supports the standard Minecraft color codes. * `{slot_number}` can be used as a placeholder for the slot number. * `"Board.MiscSeparator"` * Controls the separation between hot bar binds and temporary cooldowns such as Combos. * Supports the standard Minecraft color codes. * Adds support for KingdomsX version 1.10.19.1 * Adds ability permission check to passive abilities. They should now respect their `bending.ability.<ability name>` permissions. * Adds `AbilityVelocityAffectEntityEvent` * A cancellable event that will fire whenever an ability would alter the velocity of an entity. * Adds the `Abilities.Earth.EarthSmash.Shoot.CollisionRadius` configuration option * Sets the collision radius of shot EarthSmash. ## Fixes * Fixes FireBlast going through liquids. * Fixes duplication involving waterlogged containers. * Fixes being able to not enter the name of a Preset when using the `/pk preset create <name>` command. * Fixes getDayFactor() not being applied correctly and occasionally producing the wrong value. * Fixes a rounding issue with some Fire ability damage configuration options. * Fixes an error when attempting to start EarthGrab. * Fixes PhaseChange error when melting snow. * Fixes a memory/process leak in how cooldowns were removed. * A player's cooldowns could only be removed when they were online. If a player's cooldown expired while they weren't online, their cooldown would attempt to revert every tick until the player rejoined. This has been resolved so cooldowns can revert while a player is offline. * A side effect of this fix is that it is now possible for `PlayerCooldownChangeEvents` to fire while their corresponding Player is offline. * Fixes an issue with `MultiAbilityManager#hasMultiAbilityBound` where it would return true if any MultiAbility is bound, not if the specified MultiAbility was bound. ## Misc Changes * Updates Towny version to 0.96.2.0 * DensityShift sand blocks can now be used as a bendable source. * Changes AvatarState so that its cooldown is applied when the ability ends instead of when it starts. * Changes togglable abilities such as AvatarState, Illumination, and TremorSense to visually show when they are enabled in the BendingBoard and on BendingPreview in the same way as the ChiBlocking Stances. * Updated the text of some ability descriptions and instructions. * Adds new cache to PhaseChange to greatly improve the performance of water/ice updates.
233 lines
6.5 KiB
Java
233 lines
6.5 KiB
Java
package com.projectkorra.projectkorra.util;
|
|
|
|
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.block.Container;
|
|
import org.bukkit.block.data.Bisected;
|
|
import org.bukkit.block.data.BlockData;
|
|
import org.bukkit.block.data.Levelled;
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
import com.projectkorra.projectkorra.GeneralMethods;
|
|
import com.projectkorra.projectkorra.ProjectKorra;
|
|
|
|
import io.papermc.lib.PaperLib;
|
|
|
|
public class TempBlock {
|
|
public static Map<Block, TempBlock> instances = new ConcurrentHashMap<Block, TempBlock>();
|
|
public static final PriorityQueue<TempBlock> REVERT_QUEUE = new PriorityQueue<TempBlock>(100, new Comparator<TempBlock>() {
|
|
@Override
|
|
public int compare(final TempBlock t1, final TempBlock t2) {
|
|
return (int) (t1.revertTime - t2.revertTime);
|
|
}
|
|
});
|
|
|
|
private final Block block;
|
|
private BlockData newData;
|
|
private BlockState state;
|
|
private long revertTime;
|
|
private boolean inRevertQueue;
|
|
private RevertTask revertTask = null;
|
|
|
|
public TempBlock(final Block block, final Material newtype) {
|
|
this(block, newtype.createBlockData(), 0);
|
|
}
|
|
|
|
@Deprecated
|
|
public TempBlock(final Block block, final Material newtype, final BlockData newData) {
|
|
this(block, newData, 0);
|
|
}
|
|
|
|
public TempBlock(final Block block, final BlockData newData) {
|
|
this(block, newData, 0);
|
|
}
|
|
|
|
public TempBlock(final Block block, final BlockData newData, final long revertTime) {
|
|
this.block = block;
|
|
this.newData = newData;
|
|
|
|
if (instances.containsKey(block)) {
|
|
final TempBlock temp = instances.get(block);
|
|
if (!newData.equals(temp.block.getBlockData())) {
|
|
temp.block.setBlockData(newData, GeneralMethods.isLightEmitting(newData.getMaterial()));
|
|
temp.newData = newData;
|
|
}
|
|
this.state = temp.state;
|
|
instances.put(block, temp);
|
|
} else {
|
|
this.state = block.getState();
|
|
|
|
if (this.state instanceof Container || this.state.getType() == Material.JUKEBOX) {
|
|
return;
|
|
}
|
|
instances.put(block, this);
|
|
block.setBlockData(newData, GeneralMethods.isLightEmitting(newData.getMaterial()));
|
|
}
|
|
|
|
this.setRevertTime(revertTime);
|
|
}
|
|
|
|
public static TempBlock get(final Block block) {
|
|
if (isTempBlock(block)) {
|
|
return instances.get(block);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static boolean isTempBlock(final Block block) {
|
|
return block != null && instances.containsKey(block);
|
|
}
|
|
|
|
public static boolean isTouchingTempBlock(final Block block) {
|
|
final BlockFace[] faces = { BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN };
|
|
for (final BlockFace face : faces) {
|
|
if (instances.containsKey(block.getRelative(face))) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static void removeAll() {
|
|
for (final Block block : instances.keySet()) {
|
|
revertBlock(block, Material.AIR);
|
|
}
|
|
for (final TempBlock tempblock : REVERT_QUEUE) {
|
|
tempblock.state.update(true, GeneralMethods.isLightEmitting(tempblock.state.getType()));
|
|
if (tempblock.revertTask != null) {
|
|
tempblock.revertTask.run();
|
|
}
|
|
}
|
|
REVERT_QUEUE.clear();
|
|
}
|
|
|
|
public static void removeBlock(final Block block) {
|
|
REVERT_QUEUE.remove(instances.get(block));
|
|
instances.remove(block);
|
|
}
|
|
|
|
public static void revertBlock(final Block block, final Material defaulttype) {
|
|
if (instances.containsKey(block)) {
|
|
instances.get(block).revertBlock();
|
|
} else {
|
|
if ((defaulttype == Material.LAVA) && GeneralMethods.isAdjacentToThreeOrMoreSources(block, true)) {
|
|
final BlockData data = Material.LAVA.createBlockData();
|
|
|
|
if (data instanceof Levelled) {
|
|
((Levelled) data).setLevel(0);
|
|
}
|
|
|
|
block.setBlockData(data, GeneralMethods.isLightEmitting(data.getMaterial()));
|
|
} else if ((defaulttype == Material.WATER) && GeneralMethods.isAdjacentToThreeOrMoreSources(block)) {
|
|
final BlockData data = Material.WATER.createBlockData();
|
|
|
|
if (data instanceof Levelled) {
|
|
((Levelled) data).setLevel(0);
|
|
}
|
|
|
|
block.setBlockData(data, GeneralMethods.isLightEmitting(data.getMaterial()));
|
|
} else {
|
|
block.setType(defaulttype, GeneralMethods.isLightEmitting(defaulttype));
|
|
}
|
|
}
|
|
}
|
|
|
|
public Block getBlock() {
|
|
return this.block;
|
|
}
|
|
|
|
public BlockData getBlockData() {
|
|
return this.newData;
|
|
}
|
|
|
|
public Location getLocation() {
|
|
return this.block.getLocation();
|
|
}
|
|
|
|
public BlockState getState() {
|
|
return this.state;
|
|
}
|
|
|
|
public RevertTask getRevertTask() {
|
|
return this.revertTask;
|
|
}
|
|
|
|
public void setRevertTask(final RevertTask task) {
|
|
this.revertTask = task;
|
|
}
|
|
|
|
public long getRevertTime() {
|
|
return this.revertTime;
|
|
}
|
|
|
|
public void setRevertTime(final long revertTime) {
|
|
if(revertTime <= 0 || state instanceof Container) {
|
|
return;
|
|
}
|
|
|
|
if (this.inRevertQueue) {
|
|
REVERT_QUEUE.remove(this);
|
|
}
|
|
this.inRevertQueue = true;
|
|
this.revertTime = revertTime + System.currentTimeMillis();
|
|
REVERT_QUEUE.add(this);
|
|
}
|
|
|
|
public void revertBlock() {
|
|
PaperLib.getChunkAtAsync(this.block.getLocation()).thenAccept(result -> this.state.update(true, GeneralMethods.isLightEmitting(this.state.getType()) || !(state.getBlockData() instanceof Bisected)));
|
|
instances.remove(this.block);
|
|
REVERT_QUEUE.remove(this);
|
|
if (this.revertTask != null) {
|
|
this.revertTask.run();
|
|
}
|
|
}
|
|
|
|
public void setState(final BlockState newstate) {
|
|
this.state = newstate;
|
|
}
|
|
|
|
public void setType(final Material material) {
|
|
this.setType(material.createBlockData());
|
|
}
|
|
|
|
@Deprecated
|
|
public void setType(final Material material, final BlockData data) {
|
|
this.setType(data);
|
|
}
|
|
|
|
public void setType(final BlockData data) {
|
|
this.newData = data;
|
|
this.block.setBlockData(data, GeneralMethods.isLightEmitting(data.getMaterial()));
|
|
}
|
|
|
|
public static void startReversion() {
|
|
new BukkitRunnable() {
|
|
@Override
|
|
public void run() {
|
|
final long currentTime = System.currentTimeMillis();
|
|
while (!REVERT_QUEUE.isEmpty()) {
|
|
final TempBlock tempBlock = REVERT_QUEUE.peek();
|
|
if (currentTime >= tempBlock.revertTime) {
|
|
REVERT_QUEUE.poll();
|
|
tempBlock.revertBlock();
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}.runTaskTimer(ProjectKorra.plugin, 0, 1);
|
|
}
|
|
|
|
public interface RevertTask {
|
|
public void run();
|
|
}
|
|
}
|