From 28aa800faaadf4fc9753a2f814d874303abbeaad Mon Sep 17 00:00:00 2001 From: Arif Kalender Date: Sat, 26 Apr 2025 21:08:39 +0300 Subject: [PATCH 1/6] Fix /b ch SubElements for Avatar (#1384) ## Fixes * Bug where /pk ch avatar wouldn't add subelements of elements ## Misc. Changes * Line 190 | Changed the inner loop for getting subelements of an element. > * For the line `for (final SubElement sub : Element.getSubElements(e))`,(previous version: `for (final SubElement sub : Element.getSubElements(element))`, the getSubElements method would take the Element object outside of the for loop instead of the one needed in the outer for loop `for (Element e : new Element[] {Element.AIR, Element.EARTH, Element.FIRE, Element.WATER})` --- .../com/projectkorra/projectkorra/command/ChooseCommand.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/src/com/projectkorra/projectkorra/command/ChooseCommand.java b/core/src/com/projectkorra/projectkorra/command/ChooseCommand.java index 6944b3e0b..303a73b90 100644 --- a/core/src/com/projectkorra/projectkorra/command/ChooseCommand.java +++ b/core/src/com/projectkorra/projectkorra/command/ChooseCommand.java @@ -187,13 +187,11 @@ private void add(final CommandSender sender, final OfflinePlayer target, final E bPlayer.addElement(e); if (online) { - for (final SubElement sub : Element.getSubElements(element)) { + for (final SubElement sub : Element.getSubElements(e)) { if (((BendingPlayer) bPlayer).hasSubElementPermission(sub)) { PlayerChangeSubElementEvent subEvent = new PlayerChangeSubElementEvent(sender, target, sub, PlayerChangeSubElementEvent.Result.CHOOSE); - Bukkit.getServer().getPluginManager().callEvent(subEvent); if (subEvent.isCancelled()) continue; //Do nothing if cancelled - bPlayer.addSubElement(sub); } } From 4bb35a5f7e7dd9fc92acfff5bb061903bc22e01c Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Sat, 26 Apr 2025 13:11:26 -0500 Subject: [PATCH 2/6] Update to Java 21 and Minecraft 1.20 (#1383) Updates Java to 21 and Minecraft to 1.20 --- core/pom.xml | 18 +++++++++--------- .../AbilityRecalculateAttributeEvent.java | 7 ------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 7269129f1..e591a426d 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -114,7 +114,7 @@ org.spigotmc spigot-api - 1.16.5-R0.1-SNAPSHOT + 1.20-R0.1-SNAPSHOT provided @@ -257,10 +257,10 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.0 + 3.13.0 - 1.8 - 1.8 + 21 + 21 @@ -290,7 +290,7 @@ org.apache.maven.plugins maven-source-plugin - 2.2.1 + 3.2.1 attach-sources @@ -303,7 +303,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.9.1 + 3.10.1 attach-javadocs @@ -316,7 +316,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.1.1 + 3.4.2 ProjectKorra-${project.version} ../target/ @@ -325,7 +325,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.2.4 + 3.6.0 ${project.build.directory}/dependency-reduced-pom.xml @@ -361,4 +361,4 @@ ${project.build.directory} UTF-8 - + \ No newline at end of file diff --git a/core/src/com/projectkorra/projectkorra/event/AbilityRecalculateAttributeEvent.java b/core/src/com/projectkorra/projectkorra/event/AbilityRecalculateAttributeEvent.java index bcf1f56e5..e57177718 100644 --- a/core/src/com/projectkorra/projectkorra/event/AbilityRecalculateAttributeEvent.java +++ b/core/src/com/projectkorra/projectkorra/event/AbilityRecalculateAttributeEvent.java @@ -1,22 +1,15 @@ package com.projectkorra.projectkorra.event; -import com.google.common.primitives.Primitives; import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.attribute.AttributeModification; -import org.apache.commons.lang.math.NumberUtils; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import org.bukkit.util.NumberConversions; import org.jetbrains.annotations.NotNull; -import javax.lang.model.type.PrimitiveType; import java.lang.annotation.Annotation; import java.util.Comparator; -import java.util.HashMap; import java.util.Set; import java.util.TreeSet; -import java.util.function.Function; -import java.util.function.Supplier; public class AbilityRecalculateAttributeEvent extends Event { From 1268062e627d18af6bcd923a37ad70b08803ce2e Mon Sep 17 00:00:00 2001 From: OO0oo0oOOooo <97352407+OO0oo0oOOooo@users.noreply.github.com> Date: Sat, 26 Apr 2025 12:12:26 -0600 Subject: [PATCH 3/6] Fix Ice damage not being applied during slow cooldown (#1385) ## Issue This bug prevents damage from being applied consistently when using IceSpikeBlast and IceBlast. When a player is hit with IceSpikeBlast or IceBlast during the `bPlayer.slow(slowCooldown)` the attack wouldnt pass through the `if(bPlayer.canBeSlowed())` check where the damage command for players is located. ## Additions * Adds a SlowCooldown parameter to the config under "Abilities.Water.IceBlast.SlowCooldown". * IceBlast uses new SlowCooldown parameter. ## Fixes * Line 98 IceSpikeBlast > * Moves damage out of the `canBeSlowed()` check. * Line 165 IceBlast > * Moves damage out of the `canBeSlowed()` check. ## Removals * Line 99 IceSpikeBlast > * Removes recasting of entity to get the bending player. Now uses the same method as IceSpikePillar to get the bending player. --- .../configuration/ConfigManager.java | 1 + .../projectkorra/waterbending/ice/IceBlast.java | 16 +++++++++++++--- .../waterbending/ice/IceSpikeBlast.java | 11 +++-------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/core/src/com/projectkorra/projectkorra/configuration/ConfigManager.java b/core/src/com/projectkorra/projectkorra/configuration/ConfigManager.java index 843b31758..08ba19be6 100644 --- a/core/src/com/projectkorra/projectkorra/configuration/ConfigManager.java +++ b/core/src/com/projectkorra/projectkorra/configuration/ConfigManager.java @@ -1061,6 +1061,7 @@ public static void configCheck(final ConfigType type) { config.addDefault("Abilities.Water.IceBlast.CollisionRadius", 1.0); config.addDefault("Abilities.Water.IceBlast.Interval", 20); config.addDefault("Abilities.Water.IceBlast.Cooldown", 1500); + config.addDefault("Abilities.Water.IceBlast.SlowCooldown", 5000); config.addDefault("Abilities.Water.IceBlast.AllowSnow", false); config.addDefault("Abilities.Water.IceSpike.Enabled", true); diff --git a/core/src/com/projectkorra/projectkorra/waterbending/ice/IceBlast.java b/core/src/com/projectkorra/projectkorra/waterbending/ice/IceBlast.java index c772a5fd6..a4e683d49 100644 --- a/core/src/com/projectkorra/projectkorra/waterbending/ice/IceBlast.java +++ b/core/src/com/projectkorra/projectkorra/waterbending/ice/IceBlast.java @@ -38,6 +38,8 @@ public class IceBlast extends IceAbility { private long time; @Attribute(Attribute.COOLDOWN) @DayNightFactor(invert = true) private long cooldown; + @Attribute("Slow" + Attribute.COOLDOWN) @DayNightFactor(invert = true) + private long slowCooldown; private long interval; @Attribute(Attribute.RANGE) @DayNightFactor private double range; @@ -63,6 +65,7 @@ public IceBlast(final Player player) { this.range = getConfig().getDouble("Abilities.Water.IceBlast.Range"); this.damage = getConfig().getInt("Abilities.Water.IceBlast.Damage"); this.cooldown = getConfig().getInt("Abilities.Water.IceBlast.Cooldown"); + this.slowCooldown = getConfig().getLong("Abilities.Water.IceBlast.SlowCooldown"); this.allowSnow = getConfig().getBoolean("Abilities.Water.IceBlast.AllowSnow"); if (!this.bPlayer.canBend(this) || !this.bPlayer.canIcebend()) { @@ -159,17 +162,16 @@ private void returnWater() { } private void affect(final LivingEntity entity) { + DamageHandler.damageEntity(entity, this.damage, this); if (entity instanceof Player) { if (this.bPlayer.canBeSlowed()) { final PotionEffect effect = new PotionEffect(PotionEffectType.SLOW, 70, 2); new TempPotionEffect(entity, effect); - this.bPlayer.slow(10); - DamageHandler.damageEntity(entity, this.damage, this); + this.bPlayer.slow(this.slowCooldown); } } else { final PotionEffect effect = new PotionEffect(PotionEffectType.SLOW, 70, 2); new TempPotionEffect(entity, effect); - DamageHandler.damageEntity(entity, this.damage, this); } AirAbility.breakBreathbendingHold(entity); @@ -488,5 +490,13 @@ public void setCooldown(final long cooldown) { public void setLocation(final Location location) { this.location = location; } + + public long getSlowCooldown() { + return this.slowCooldown; + } + + public void setSlowCooldown(final long slowCooldown) { + this.slowCooldown = slowCooldown; + } } diff --git a/core/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikeBlast.java b/core/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikeBlast.java index a3952f8e1..5ffc2bee1 100644 --- a/core/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikeBlast.java +++ b/core/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikeBlast.java @@ -95,21 +95,16 @@ public IceSpikeBlast(final Player player) { } private void affect(final LivingEntity entity) { + DamageHandler.damageEntity(entity, this.damage, this); if (entity instanceof Player) { - final BendingPlayer targetBPlayer = BendingPlayer.getBendingPlayer((Player) entity); - if (targetBPlayer == null) { - return; - } - if (targetBPlayer.canBeSlowed()) { + if (this.bPlayer.canBeSlowed()) { final PotionEffect effect = new PotionEffect(PotionEffectType.SLOW, this.slowDuration, this.slowPotency); new TempPotionEffect(entity, effect); - targetBPlayer.slow(this.slowCooldown); - DamageHandler.damageEntity(entity, this.damage, this); + this.bPlayer.slow(this.slowCooldown); } } else { final PotionEffect effect = new PotionEffect(PotionEffectType.SLOW, this.slowDuration, this.slowPotency); new TempPotionEffect(entity, effect); - DamageHandler.damageEntity(entity, this.damage, this); } AirAbility.breakBreathbendingHold(entity); } From e32937322fff39a43b39b0c5a321728c8553211c Mon Sep 17 00:00:00 2001 From: R00tB33rMan Date: Tue, 13 May 2025 17:35:22 -0400 Subject: [PATCH 4/6] Explicit try/catch for Temorsense on shutdown (you'd have to experiment if this persists elsewhere) --- .../projectkorra/earthbending/Tremorsense.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/src/com/projectkorra/projectkorra/earthbending/Tremorsense.java b/core/src/com/projectkorra/projectkorra/earthbending/Tremorsense.java index 067138e3b..dcdad7be8 100644 --- a/core/src/com/projectkorra/projectkorra/earthbending/Tremorsense.java +++ b/core/src/com/projectkorra/projectkorra/earthbending/Tremorsense.java @@ -12,7 +12,6 @@ import org.bukkit.entity.Player; import com.projectkorra.projectkorra.BendingPlayer; -import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.EarthAbility; import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.attribute.Attribute; @@ -142,9 +141,17 @@ public void setUpBreaking() { } public void revertGlowBlock() { - if (this.block != null) { + if (this.block == null) { + return; + } + + try { this.player.sendBlockChange(this.block.getLocation(), this.block.getBlockData()); this.glowing = false; + } catch (NullPointerException ignored) { + // Ignore invalidated exception since this is not needed + } catch (Exception ignored) { + // Ignore invalidated exception since this can be ignored } } From f4770c7f8c818a9fda353aecd7cf8123edf04e58 Mon Sep 17 00:00:00 2001 From: R00tB33rMan Date: Thu, 19 Jun 2025 00:37:51 -0400 Subject: [PATCH 5/6] Push additional implementations --- core/pom.xml | 10 +-- .../projectkorra/GeneralMethods.java | 4 +- .../projectkorra/ability/CoreAbility.java | 61 ++++++++----------- .../ability/util/CollisionManager.java | 25 ++++++++ .../ability/util/FoliaThreadChecker.java | 2 +- .../projectkorra/command/BindCommand.java | 4 +- .../projectkorra/command/ChooseCommand.java | 4 ++ .../projectkorra/earthbending/EarthSmash.java | 15 ++--- .../earthbending/lava/LavaSurge.java | 4 +- .../projectkorra/util/ThreadUtil.java | 2 +- 10 files changed, 72 insertions(+), 59 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index dcf7c246e..32fcaf083 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -108,18 +108,18 @@ luminol ${project.version} - + - dev.folia - folia-api - 1.20.1-R0.1-SNAPSHOT + io.papermc.paper + paper-api + 1.20.4-R0.1-SNAPSHOT provided org.spigotmc spigot-api - 1.20-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT provided diff --git a/core/src/com/projectkorra/projectkorra/GeneralMethods.java b/core/src/com/projectkorra/projectkorra/GeneralMethods.java index 271baf41e..5bb6c66b3 100644 --- a/core/src/com/projectkorra/projectkorra/GeneralMethods.java +++ b/core/src/com/projectkorra/projectkorra/GeneralMethods.java @@ -802,7 +802,7 @@ public static String getLastUsedAbility(final Player player, final boolean check if (ComboManager.checkForValidCombo(player) != null && checkCombos) { return ComboManager.checkForValidCombo(player).getName(); } else { - return lastUsedAbility.get(0).getAbilityName(); + return lastUsedAbility.getFirst().getAbilityName(); } } return null; @@ -1083,7 +1083,7 @@ public static Block getBottomBlock(final Location loc, final int positiveY, fina } public static ArrayList getElementsWithNoWeaponBending() { - final ArrayList elements = new ArrayList(); + final ArrayList elements = new ArrayList<>(); if (!plugin.getConfig().getBoolean("Properties.Air.CanBendWithWeapons")) { elements.add(Element.AIR); diff --git a/core/src/com/projectkorra/projectkorra/ability/CoreAbility.java b/core/src/com/projectkorra/projectkorra/ability/CoreAbility.java index 7703a72fe..97c4aab27 100644 --- a/core/src/com/projectkorra/projectkorra/ability/CoreAbility.java +++ b/core/src/com/projectkorra/projectkorra/ability/CoreAbility.java @@ -108,7 +108,7 @@ public abstract class CoreAbility implements Ability { * CoreAbility via reflection in {@link #registerAbilities()}. More * specifically, {@link #registerPluginAbilities} calls * getDeclaredConstructor which is only usable with a public default - * constructor. Reflection lets us create a list of all of the plugin's + * constructor. Reflection lets us create a list of all the plugin's * abilities when the plugin first loads. * * @see #ABILITIES_BY_NAME @@ -171,12 +171,7 @@ public void start() { } if (ProjectKorra.isFolia() && !Bukkit.isOwnedByCurrentRegion(this.player)) { - ProjectKorra.log.warning("Tried to start ability " + this.getName() + " (" + this.getClass().getSimpleName() + - ".class) on a player that is not owned by the current region. This is not allowed in Folia. Please report " + - "this to the ProjectKorra team."); - for (int i = 0; i < 6 && i < Thread.currentThread().getStackTrace().length; i++) { - ProjectKorra.log.warning(Thread.currentThread().getStackTrace()[i].toString()); - } + Bukkit.getRegionScheduler().execute(ProjectKorra.plugin, player.getLocation(), this::start); return; } @@ -194,13 +189,13 @@ public void start() { final UUID uuid = this.player.getUniqueId(); if (!INSTANCES_BY_PLAYER.containsKey(clazz)) { - INSTANCES_BY_PLAYER.put(clazz, new ConcurrentHashMap>()); + INSTANCES_BY_PLAYER.put(clazz, new ConcurrentHashMap<>()); } if (!INSTANCES_BY_PLAYER.get(clazz).containsKey(uuid)) { - INSTANCES_BY_PLAYER.get(clazz).put(uuid, new ConcurrentHashMap()); + INSTANCES_BY_PLAYER.get(clazz).put(uuid, new ConcurrentHashMap<>()); } if (!INSTANCES_BY_CLASS.containsKey(clazz)) { - INSTANCES_BY_CLASS.put(clazz, Collections.newSetFromMap(new ConcurrentHashMap())); + INSTANCES_BY_CLASS.put(clazz, Collections.newSetFromMap(new ConcurrentHashMap<>())); } this.recalculateAttributes(); @@ -219,19 +214,15 @@ public void start() { this._foliaCurrentTick++; this.progressSelf(); }, 1L, 1L); - - if (ProjectKorra.isLuminol()) { //Luminol is required for collisions right now, until Folia implements API that we can use - FoliaCollisionManager.startTracking(this); - } } } /** * Causes this CoreAbility instance to be removed, and {@link #progress} - * will no longer be called every tick. If this method is overridden then + * will no longer be called every tick. If this method is overridden, then * the new method must call super.remove(). * - * {@inheritDoc} + *

{@inheritDoc}

* * @see #isRemoved() */ @@ -271,12 +262,8 @@ public void remove() { INSTANCES.remove(this); - if (ProjectKorra.isFolia()) { - ((ScheduledTask) this._foliaTask).cancel(); //Cancel the task if it exists - - if (ProjectKorra.isLuminol()) { - FoliaCollisionManager.stopTracking(this); - } + if (ProjectKorra.isFolia() && this._foliaTask instanceof ScheduledTask task) { + task.cancel(); } } @@ -320,8 +307,10 @@ private void progressSelf() { try { this.progress(); - if (ProjectKorra.isFolia()) { //Collisions don't work properly on Folia, so we spawn Markers at each location to damage - //this._foliaCollisions(); + if (ProjectKorra.isFolia()) { + for (Location location : this.getLocations()) { + CollisionManager.handleCollisions(this, location, this.getCollisionRadius()); + } } Bukkit.getServer().getPluginManager().callEvent(new AbilityProgressEvent(this)); @@ -448,7 +437,7 @@ public static ArrayList getAbilitiesByName() { } /** - * Returns a Collection of all of the player created instances for a + * Returns a Collection of all the player created instances for a * specific type of CoreAbility. * * @param clazz the class for the type of CoreAbilities @@ -479,7 +468,7 @@ public static Collection getAbilities(final Player pl } /** - * Returns a Collection of all of the CoreAbilities that are currently + * Returns a Collection of all the CoreAbilities that are currently * active for a specific player. * @param player the player that created the instances * @return The abilities @@ -500,8 +489,8 @@ public static Collection getAbilities(final Player player) { } /** - * Returns a Collection of all of the CoreAbilities that are currently active. - * @return a Collection of all of the CoreAbilities that are currently + * Returns a Collection of all the CoreAbilities that are currently active. + * @return a Collection of all the CoreAbilities that are currently * alive. Do not modify this Collection. */ public static Collection getAbilitiesByInstances() { @@ -509,7 +498,7 @@ public static Collection getAbilitiesByInstances() { } /** - * Returns an List of fake instances that were loaded by + * Returns a List of fake instances that were loaded by * {@link #registerAbilities()} filtered by Element. * * @param element the Element of the loaded abilities @@ -537,7 +526,7 @@ public static List getAbilitiesByElement(final Element element) { * for bending reload purposes
* This isn't a simple list, external use isn't recommended * - * @return a list of entrys with the plugin name and path abilities can be + * @return a list of entries with the plugin name and path abilities can be * found at */ public static List getAddonPlugins() { @@ -577,7 +566,7 @@ public static void unloadAbility(final Class clazz) { } /** - * Returns a Set of all of the players that currently have an active + * Returns a Set of all the players that currently have an active * instance of clazz. * * @param clazz the clazz for the type of CoreAbility @@ -675,8 +664,8 @@ public static void registerPluginAbilities(final JavaPlugin plugin, final String } /** - * Scans all of the Jar files inside of /ProjectKorra/folder and registers - * all of the CoreAbility class files that were found. + * Scans all the Jar files inside /ProjectKorra/folder and registers + * all the CoreAbility class files that were found. * * @param folder the name of the folder to scan * @see #getAbilities() @@ -684,7 +673,7 @@ public static void registerPluginAbilities(final JavaPlugin plugin, final String */ public static void registerAddonAbilities(final String folder) { final ProjectKorra plugin = ProjectKorra.plugin; - final File path = new File(plugin.getDataFolder().toString() + folder); + final File path = new File(plugin.getDataFolder() + folder); if (!path.exists()) { path.mkdir(); return; @@ -987,7 +976,7 @@ public double getCollisionRadius() { /** * Called when this ability instance collides with another. Some abilities - * may want advanced behavior on a Collision; e.g. FireCombos only remove + * may want advanced behavior on a Collision; e.g., FireCombos only remove * the stream that was hit rather than the entire ability. *

* collision.getAbilitySecond() - the ability that we are colliding with @@ -1058,7 +1047,7 @@ public CoreAbility setAttribute(final String attribute, final Object value) { /** * Recalculate what the ability's attributes should be. This is called * whenever an ability is created, but should be called whenever you want an - * ability to recalculate some of it's values. E.g. day turns to night, AvatarState + * ability to recalculate some of its values. E.g., day turns to night AvatarState * gets toggled, etc. */ public void recalculateAttributes() { diff --git a/core/src/com/projectkorra/projectkorra/ability/util/CollisionManager.java b/core/src/com/projectkorra/projectkorra/ability/util/CollisionManager.java index 80d72b7c8..86d071abb 100644 --- a/core/src/com/projectkorra/projectkorra/ability/util/CollisionManager.java +++ b/core/src/com/projectkorra/projectkorra/ability/util/CollisionManager.java @@ -66,6 +66,31 @@ public CollisionManager() { this.collisions = new ArrayList<>(); } + public static void handleCollisions(CoreAbility source, Location location, double radius) { + if (!source.isCollidable()) { + return; + } + + for (CoreAbility target : CoreAbility.getAbilitiesByInstances()) { + if (target == source || !target.isCollidable()) continue; + + for (Location targetLoc : target.getLocations()) { + if (location.getWorld() != targetLoc.getWorld()) continue; + if (location.distanceSquared(targetLoc) <= Math.pow(radius + target.getCollisionRadius(), 2)) { + Collision forward = new Collision(source, target, true, true, location, targetLoc); + Collision reverse = new Collision(target, source, true, true, targetLoc, location); + + AbilityCollisionEvent event = new AbilityCollisionEvent(forward); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) continue; + + source.handleCollision(forward); + target.handleCollision(reverse); + } + } + } + } + private void detectCollisions() { int activeInstanceCount = 0; diff --git a/core/src/com/projectkorra/projectkorra/ability/util/FoliaThreadChecker.java b/core/src/com/projectkorra/projectkorra/ability/util/FoliaThreadChecker.java index ab77bf248..854961405 100644 --- a/core/src/com/projectkorra/projectkorra/ability/util/FoliaThreadChecker.java +++ b/core/src/com/projectkorra/projectkorra/ability/util/FoliaThreadChecker.java @@ -11,7 +11,7 @@ */ public class FoliaThreadChecker implements Runnable { - private Player player; + private final Player player; private Location oldLocation; public FoliaThreadChecker(Player player) { diff --git a/core/src/com/projectkorra/projectkorra/command/BindCommand.java b/core/src/com/projectkorra/projectkorra/command/BindCommand.java index 22cd68fa1..e588aaf6f 100644 --- a/core/src/com/projectkorra/projectkorra/command/BindCommand.java +++ b/core/src/com/projectkorra/projectkorra/command/BindCommand.java @@ -114,10 +114,10 @@ private void bind(final CommandSender sender, final String ability, final int sl @Override protected List getTabCompletion(final CommandSender sender, final List args) { if (args.size() >= 2 || !sender.hasPermission("bending.command.bind") || !(sender instanceof Player)) { - return new ArrayList(); + return new ArrayList<>(); } - List abilities = new ArrayList(); + List abilities = new ArrayList<>(); final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(sender.getName()); if (args.size() == 0) { if (bPlayer != null) { diff --git a/core/src/com/projectkorra/projectkorra/command/ChooseCommand.java b/core/src/com/projectkorra/projectkorra/command/ChooseCommand.java index 303a73b90..5a13fcc4b 100644 --- a/core/src/com/projectkorra/projectkorra/command/ChooseCommand.java +++ b/core/src/com/projectkorra/projectkorra/command/ChooseCommand.java @@ -59,6 +59,10 @@ public void execute(final CommandSender sender, final List args) { //Don't need to bother with offline players here because the sender is always online BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(sender.getName()); + if (bPlayer == null) { + return; + } + if (bPlayer.isPermaRemoved()) { ChatUtil.sendBrandingMessage(sender, ChatColor.RED + ConfigManager.languageConfig.get().getString("Commands.Preset.BendingPermanentlyRemoved")); return; diff --git a/core/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java b/core/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java index 59d08958e..d07c5a767 100644 --- a/core/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java +++ b/core/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java @@ -79,9 +79,9 @@ public static enum State { private Block origin; private Location location; private Location destination; - private ArrayList affectedEntities; - private ArrayList currentBlocks; - private ArrayList affectedBlocks; + private final ArrayList affectedEntities; + private final ArrayList currentBlocks; + private final ArrayList affectedBlocks; public EarthSmash(final Player player, final ClickType type) { super(player); @@ -132,7 +132,6 @@ public EarthSmash(final Player player, final ClickType type) { smash.location.getWorld().playEffect(smash.location, Effect.GHAST_SHOOT, 0, 10); } } - return; } else if (type == ClickType.RIGHT_CLICK && player.isSneaking()) { final EarthSmash grabbedSmash = this.aimingAtSmashCheck(player, State.GRABBED); if (grabbedSmash != null) { @@ -142,7 +141,6 @@ public EarthSmash(final Player player, final ClickType type) { grabbedSmash.setFields(); grabbedSmash.flightStartTime = System.currentTimeMillis(); } - return; } } @@ -210,7 +208,6 @@ public void progress() { this.maxDamage = applyMetalPowerFactor(this.maxDamage, this.origin); } else { this.remove(); - return; } } else if (System.currentTimeMillis() - this.getStartTime() > this.chargeTime) { final Location tempLoc = this.player.getEyeLocation().add(this.player.getEyeLocation().getDirection().normalize().multiply(1.2)); @@ -236,10 +233,8 @@ public void progress() { } } this.draw(); - return; } else { this.state = State.LIFTED; - return; } } else if (this.state == State.SHOT) { if (System.currentTimeMillis() - this.delay >= this.shootAnimationInterval) { @@ -272,7 +267,6 @@ public void progress() { this.draw(); this.smashToSmashCollisionDetection(); } - return; } else if (this.state == State.FLYING) { if (!this.player.isSneaking()) { this.remove(); @@ -311,7 +305,6 @@ public void progress() { } if (System.currentTimeMillis() - this.flightStartTime > this.flightDuration) { this.remove(); - return; } } } @@ -457,7 +450,7 @@ public void checkRemainingBlocks() { final BlockRepresenter brep = this.currentBlocks.get(i); final Block block = this.location.clone().add(brep.getX(), brep.getY(), brep.getZ()).getBlock(); // Check for grass because sometimes the dirt turns into grass. - if (block.getType() != brep.getType() && (block.getType() != Material.GRASS) && (block.getType() != Material.COBBLESTONE)) { + if (block.getType() != brep.getType() && (block.getType() != Material.GRASS_BLOCK) && (block.getType() != Material.COBBLESTONE)) { this.currentBlocks.remove(i); i--; } diff --git a/core/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurge.java b/core/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurge.java index d18e67c14..ae30f4b8b 100644 --- a/core/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurge.java +++ b/core/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurge.java @@ -119,7 +119,9 @@ public void launch() { try { targetLocation = GeneralMethods.getTargetedEntity(this.player, this.travelRange * 2, null).getLocation(); - } catch (final NullPointerException e) {} + } catch (final NullPointerException ignored) { + // Ignore this exception too since it's not needed + } if (targetLocation == null) { this.remove(); diff --git a/core/src/com/projectkorra/projectkorra/util/ThreadUtil.java b/core/src/com/projectkorra/projectkorra/util/ThreadUtil.java index 3d4f60937..3b04b24c4 100644 --- a/core/src/com/projectkorra/projectkorra/util/ThreadUtil.java +++ b/core/src/com/projectkorra/projectkorra/util/ThreadUtil.java @@ -211,7 +211,7 @@ public static Object runSyncLater(Runnable runnable, long delay) { if (ProjectKorra.isFolia()) { return Bukkit.getGlobalRegionScheduler().runDelayed(ProjectKorra.plugin, (task) -> runnable.run(), delay); } else { - return Bukkit.getScheduler().runTaskLater(ProjectKorra.plugin, runnable, delay); + return Bukkit.getScheduler().runTaskLater(ProjectKorra.plugin, runnable, delay); } } From 98854977338efe0caccbf81af5dcf3dc09419a71 Mon Sep 17 00:00:00 2001 From: R00tB33rMan Date: Fri, 20 Jun 2025 12:43:42 -0400 Subject: [PATCH 6/6] Additional subset for experimental resolves --- .../projectkorra/ability/CoreAbility.java | 37 +++++++------------ .../ability/util/CollisionManager.java | 25 ------------- 2 files changed, 14 insertions(+), 48 deletions(-) diff --git a/core/src/com/projectkorra/projectkorra/ability/CoreAbility.java b/core/src/com/projectkorra/projectkorra/ability/CoreAbility.java index 97c4aab27..3216d0c43 100644 --- a/core/src/com/projectkorra/projectkorra/ability/CoreAbility.java +++ b/core/src/com/projectkorra/projectkorra/ability/CoreAbility.java @@ -12,13 +12,13 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentSkipListMap; import java.util.jar.JarFile; -import com.projectkorra.projectkorra.ability.util.FoliaCollisionManager; import com.projectkorra.projectkorra.attribute.*; import com.projectkorra.projectkorra.command.CooldownCommand; import com.projectkorra.projectkorra.event.AbilityRecalculateAttributeEvent; @@ -240,12 +240,12 @@ public void remove() { final Map playerMap = classMap.get(this.player.getUniqueId()); if (playerMap != null) { playerMap.remove(this.id); - if (playerMap.size() == 0) { + if (playerMap.isEmpty()) { classMap.remove(this.player.getUniqueId()); } } - if (classMap.size() == 0) { + if (classMap.isEmpty()) { INSTANCES_BY_PLAYER.remove(this.getClass()); } } @@ -259,7 +259,6 @@ public void remove() { INSTANCES_BY_CLASS.get(this.getClass()).remove(this); } - INSTANCES.remove(this); if (ProjectKorra.isFolia() && this._foliaTask instanceof ScheduledTask task) { @@ -286,7 +285,7 @@ private void progressSelf() { return; } - if (ProjectKorra.isFolia() && !Bukkit.isOwnedByCurrentRegion(this.player)) { + if (ProjectKorra.isFolia()) { //player.sendMessage(ChatColor.RED +"[Debug] " + this.getName() + " was killed because you changed regions"); this.remove(); return; @@ -306,13 +305,6 @@ private void progressSelf() { try { this.progress(); - - if (ProjectKorra.isFolia()) { - for (Location location : this.getLocations()) { - CollisionManager.handleCollisions(this, location, this.getCollisionRadius()); - } - } - Bukkit.getServer().getPluginManager().callEvent(new AbilityProgressEvent(this)); } catch (final Throwable e) { if (e instanceof NoSuchMethodError || e instanceof NoSuchFieldError || e instanceof NoClassDefFoundError) { @@ -362,7 +354,6 @@ public static void removeAll() { } catch (Exception e) { e.printStackTrace(); } - } } } @@ -424,7 +415,7 @@ public static CoreAbility getAbility(final Class clazz) { * {@link #registerAbilities()} */ public static ArrayList getAbilities() { - return new ArrayList(ABILITIES_BY_CLASS.values()); + return new ArrayList<>(ABILITIES_BY_CLASS.values()); } /** @@ -433,7 +424,7 @@ public static ArrayList getAbilities() { * {@link #registerAbilities()} */ public static ArrayList getAbilitiesByName() { - return new ArrayList(ABILITIES_BY_NAME.values()); + return new ArrayList<>(ABILITIES_BY_NAME.values()); } /** @@ -445,7 +436,7 @@ public static ArrayList getAbilitiesByName() { * @return a Collection of real instances */ public static Collection getAbilities(final Class clazz) { - if (clazz == null || INSTANCES_BY_CLASS.get(clazz) == null || INSTANCES_BY_CLASS.get(clazz).size() == 0) { + if (clazz == null || INSTANCES_BY_CLASS.get(clazz) == null || INSTANCES_BY_CLASS.get(clazz).isEmpty()) { return Collections.emptySet(); } return (Collection) CoreAbility.INSTANCES_BY_CLASS.get(clazz); @@ -556,7 +547,7 @@ public static void unloadAbility(final Class clazz) { } final String name = ABILITIES_BY_CLASS.get(clazz).getName(); for (final CoreAbility abil : INSTANCES) { - if (abil.getName() == name) { + if (Objects.equals(abil.getName(), name)) { abil.remove(); } } @@ -590,7 +581,7 @@ public static Set getPlayers(final Class clazz) { /** * Scans and loads plugin CoreAbilities, and Addon CoreAbilities that are - * located in a Jar file inside of the /ProjectKorra/Abilities/ folder. + * located in a Jar file inside the /ProjectKorra/Abilities/ folder. */ public static void registerAbilities() { ABILITIES_BY_NAME.clear(); @@ -810,7 +801,7 @@ public boolean isEnabled() { elementName = ((SubElement) this.getElement()).getParentElement().getName(); } - String tag = null; + String tag; if (this instanceof PassiveAbility) { tag = "Abilities." + elementName + ".Passive." + this.getName() + ".Enabled"; } else { @@ -1014,7 +1005,7 @@ public List getLocations() { */ @Deprecated public CoreAbility addAttributeModifier(final String attribute, final Number value, final AttributeModifier modification) { - return this;//.addAttributeModifier(attribute, value, modification, AttributePriority.MEDIUM); + return this; } /** @@ -1023,7 +1014,7 @@ public CoreAbility addAttributeModifier(final String attribute, final Number val */ @Deprecated public CoreAbility addAttributeModifier(final String attribute, final Number value, final AttributeModifier modificationType, final AttributePriority priority) { - return this;//.addAttributeModifier(attribute, value, modificationType, priority, UUID.randomUUID()); + return this; } /** @@ -1156,10 +1147,10 @@ public static String getDebugString() { } } - sb.append("Class->UUID's in memory: " + playerCounter + "\n"); + sb.append("Class->UUID's in memory: ").append(playerCounter).append("\n"); sb.append("Abilities in memory:\n"); for (final String className : classCounter.keySet()) { - sb.append(className + ": " + classCounter.get(className) + "\n"); + sb.append(className).append(": ").append(classCounter.get(className)).append("\n"); } return sb.toString(); } diff --git a/core/src/com/projectkorra/projectkorra/ability/util/CollisionManager.java b/core/src/com/projectkorra/projectkorra/ability/util/CollisionManager.java index 86d071abb..80d72b7c8 100644 --- a/core/src/com/projectkorra/projectkorra/ability/util/CollisionManager.java +++ b/core/src/com/projectkorra/projectkorra/ability/util/CollisionManager.java @@ -66,31 +66,6 @@ public CollisionManager() { this.collisions = new ArrayList<>(); } - public static void handleCollisions(CoreAbility source, Location location, double radius) { - if (!source.isCollidable()) { - return; - } - - for (CoreAbility target : CoreAbility.getAbilitiesByInstances()) { - if (target == source || !target.isCollidable()) continue; - - for (Location targetLoc : target.getLocations()) { - if (location.getWorld() != targetLoc.getWorld()) continue; - if (location.distanceSquared(targetLoc) <= Math.pow(radius + target.getCollisionRadius(), 2)) { - Collision forward = new Collision(source, target, true, true, location, targetLoc); - Collision reverse = new Collision(target, source, true, true, targetLoc, location); - - AbilityCollisionEvent event = new AbilityCollisionEvent(forward); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) continue; - - source.handleCollision(forward); - target.handleCollision(reverse); - } - } - } - } - private void detectCollisions() { int activeInstanceCount = 0;