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.
131 lines
4.8 KiB
Java
Executable file
131 lines
4.8 KiB
Java
Executable file
package com.projectkorra.projectkorra.board;
|
|
|
|
import com.projectkorra.projectkorra.BendingPlayer;
|
|
import com.projectkorra.projectkorra.ability.CoreAbility;
|
|
import com.projectkorra.projectkorra.configuration.ConfigManager;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.scoreboard.DisplaySlot;
|
|
import org.bukkit.scoreboard.Objective;
|
|
import org.bukkit.scoreboard.Scoreboard;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
|
|
/**
|
|
* Represents a player's scoreboard for bending purposes
|
|
*/
|
|
public class BendingBoardInstance {
|
|
private final String[] cachedSlots = new String[10];
|
|
private final Set<String> misc = new HashSet<>(); // Stores scoreboard scores for combos and misc abilities
|
|
|
|
private final Player player;
|
|
private final BendingPlayer bendingPlayer;
|
|
|
|
private final Scoreboard bendingBoard;
|
|
private final Objective bendingSlots;
|
|
private int selectedSlot;
|
|
|
|
public BendingBoardInstance(final BendingPlayer bPlayer) {
|
|
bendingPlayer = bPlayer;
|
|
player = bPlayer.getPlayer();
|
|
selectedSlot = player.getInventory().getHeldItemSlot() + 1;
|
|
|
|
bendingBoard = Bukkit.getScoreboardManager().getNewScoreboard();
|
|
|
|
String title = ChatColor.translateAlternateColorCodes('&', ConfigManager.languageConfig.get().getString("Board.Title"));
|
|
bendingSlots = bendingBoard.registerNewObjective("Board Slots", "dummy", title);
|
|
bendingSlots.setDisplaySlot(DisplaySlot.SIDEBAR);
|
|
player.setScoreboard(bendingBoard);
|
|
|
|
Arrays.fill(cachedSlots, "");
|
|
updateAll();
|
|
}
|
|
|
|
public void disableScoreboard() {
|
|
bendingBoard.clearSlot(DisplaySlot.SIDEBAR);
|
|
bendingSlots.unregister();
|
|
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
|
|
}
|
|
|
|
private void setSlot(int slot, String name, boolean cooldown) {
|
|
if (slot < 1 || slot > 9 || !player.getScoreboard().equals(bendingBoard)) return;
|
|
String prefix = ChatColor.translateAlternateColorCodes('&', ConfigManager.languageConfig.get().getString("Board.SelectionPrefix"));
|
|
StringBuilder sb = new StringBuilder(slot == selectedSlot ? prefix : String.join("", Collections.nCopies(ChatColor.stripColor(prefix).length(), " ")));
|
|
if (name == null || name.isEmpty()) {
|
|
String emptySlot = ChatColor.translateAlternateColorCodes('&', ConfigManager.languageConfig.get().getString("Board.EmptySlot").replaceAll("\\{slot_number\\}", "" + slot));
|
|
sb.append(emptySlot);
|
|
} else {
|
|
CoreAbility coreAbility = CoreAbility.getAbility(ChatColor.stripColor(name));
|
|
if (coreAbility == null) { // MultiAbility
|
|
if (cooldown || bendingPlayer.isOnCooldown(name)) sb.append(ChatColor.STRIKETHROUGH);
|
|
sb.append(name);
|
|
} else {
|
|
sb.append(coreAbility.getMovePreviewWithoutCooldownTimer(player, cooldown));
|
|
}
|
|
}
|
|
sb.append(ChatColor.values()[slot].toString()); // Unique suffix
|
|
|
|
if (!cachedSlots[slot].equals(sb.toString())) {
|
|
bendingBoard.resetScores(cachedSlots[slot]);
|
|
}
|
|
cachedSlots[slot] = sb.toString();
|
|
bendingSlots.getScore(sb.toString()).setScore(-slot);
|
|
}
|
|
|
|
public void updateAll() {
|
|
final Map<Integer, String> boundAbilities = new HashMap<>(bendingPlayer.getAbilities());
|
|
for (int i = 1; i <= 9; i++) {
|
|
setSlot(i, boundAbilities.getOrDefault(i, ""), false);
|
|
}
|
|
}
|
|
|
|
public void clearSlot(int slot) {
|
|
setSlot(slot, null, false);
|
|
}
|
|
|
|
public void setActiveSlot(int oldSlot, int newSlot) {
|
|
if (selectedSlot != oldSlot) {
|
|
oldSlot = selectedSlot; // Fixes bug when slot is set using setHeldItemSlot
|
|
}
|
|
selectedSlot = newSlot;
|
|
setSlot(oldSlot, bendingPlayer.getAbilities().getOrDefault(oldSlot, ""), false);
|
|
setSlot(newSlot, bendingPlayer.getAbilities().getOrDefault(newSlot, ""), false);
|
|
}
|
|
|
|
public void setAbility(String name, boolean cooldown) {
|
|
final Map<Integer, String> boundAbilities = bendingPlayer.getAbilities();
|
|
boundAbilities.keySet().stream().filter(key -> name.equals(boundAbilities.get(key))).forEach(slot -> setSlot(slot, name, cooldown));
|
|
}
|
|
|
|
public void updateMisc(String text, boolean show, boolean isCombo) {
|
|
String selection = ChatColor.translateAlternateColorCodes('&', ConfigManager.languageConfig.get().getString("Board.SelectionPrefix"));
|
|
String prefix = String.join("", Collections.nCopies(ChatColor.stripColor(selection).length(), " "));
|
|
|
|
String miscSeparator = ChatColor.translateAlternateColorCodes('&', ConfigManager.languageConfig.get().getString("Board.MiscSeparator"));
|
|
String alignedText = prefix + text;
|
|
|
|
if (show) {
|
|
if (misc.isEmpty()) {
|
|
bendingSlots.getScore(miscSeparator).setScore(-10);
|
|
}
|
|
|
|
misc.add(alignedText);
|
|
bendingSlots.getScore(alignedText).setScore(isCombo ? -11 : -12);
|
|
} else {
|
|
misc.remove(alignedText);
|
|
bendingBoard.resetScores(alignedText);
|
|
|
|
if (misc.isEmpty()) {
|
|
bendingBoard.resetScores(miscSeparator);
|
|
}
|
|
}
|
|
}
|
|
}
|