Synchronizes master with wip and fixes debug command (#1066)

## Fixes
* Fixes the `/pk debug` command causing `ClassNotFoundException` and `NoClassDefFoundError` due to missing hook dependencies in the compiled jar.

## Copy Pasted
Credit goes to the authors of all of the changes below. I simply copy-pasted them so that they can be directly committed to master rather than have to re-align the wip and master branches due to them not being synched.

* e4f2f4fc8f
* 3cc64a2246
* b153748741
* 964de778d9
This commit is contained in:
Vahagn Tovmasian 2020-07-17 22:27:41 -07:00 committed by GitHub
parent ca2bb791ea
commit bd5c1fb45c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 76 additions and 45 deletions

View file

@ -1994,22 +1994,27 @@ public class GeneralMethods {
final ClassLoader loader = ProjectKorra.class.getClassLoader();
try {
for (final ClassPath.ClassInfo info : ClassPath.from(loader).getTopLevelClasses()) {
if (info.getName().startsWith("com.projectkorra.")) {
final Class<?> clazz = info.load();
for (final Field field : clazz.getDeclaredFields()) {
final String simpleName = clazz.getSimpleName();
field.setAccessible(true);
try {
final Object obj = field.get(null);
if (obj instanceof Collection) {
writeToDebug(simpleName + ": " + field.getName() + " size=" + ((Collection<?>) obj).size());
} else if (obj instanceof Map) {
writeToDebug(simpleName + ": " + field.getName() + " size=" + ((Map<?, ?>) obj).size());
}
} catch (final Exception e) {
if (info.getName().startsWith("com.projectkorra.") && !info.getName().contains("hooks")) {
try {
final Class<?> clazz = info.load();
for (final Field field : clazz.getDeclaredFields()) {
final String simpleName = clazz.getSimpleName();
field.setAccessible(true);
try {
final Object obj = field.get(null);
if (obj instanceof Collection) {
writeToDebug(simpleName + ": " + field.getName() + " size=" + ((Collection<?>) obj).size());
} else if (obj instanceof Map) {
writeToDebug(simpleName + ": " + field.getName() + " size=" + ((Map<?, ?>) obj).size());
}
} catch (final Exception e) {
}
}
} catch (Exception e) {
continue;
}
}
}
} catch (final IOException e) {

View file

@ -61,6 +61,7 @@ import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
@ -197,6 +198,7 @@ public class PKListener implements Listener {
private static final HashMap<Player, String> BENDING_PLAYER_DEATH = new HashMap<>(); // Player killed by Bending.
private static final List<UUID> RIGHT_CLICK_INTERACT = new ArrayList<UUID>(); // Player right click block.
private static final ArrayList<UUID> TOGGLED_OUT = new ArrayList<>(); // Stands for toggled = false while logging out.
private static final List<Player> PLAYER_DROPPED_ITEM = new ArrayList<>(); // Player dropped an item.
private static final Map<Player, Integer> JUMPS = new HashMap<>();
private static MCTiming TimingPhysicsWaterManipulationCheck, TimingPhysicsEarthPassiveCheck, TimingPhysicsIlluminationTorchCheck, TimingPhysicsEarthAbilityCheck, TimingPhysicsAirTempBlockBelowFallingBlockCheck;
@ -1062,6 +1064,24 @@ public class PKListener implements Listener {
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerItemDrop(PlayerDropItemEvent event) {
Player player = event.getPlayer();
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
if (event.isCancelled())
return;
if (bPlayer == null)
return;
if (bPlayer.getBoundAbility() == null)
return;
if (!PLAYER_DROPPED_ITEM.contains(player))
PLAYER_DROPPED_ITEM.add(player);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerInteraction(final PlayerInteractEvent event) {
final Player player = event.getPlayer();
@ -1588,6 +1608,11 @@ public class PKListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerSwing(final PlayerInteractEvent event) {
final Player player = event.getPlayer();
if (PLAYER_DROPPED_ITEM.contains(player)) {
PLAYER_DROPPED_ITEM.remove(player);
return;
}
if (event.getHand() != EquipmentSlot.HAND) {
return;
}

View file

@ -330,10 +330,12 @@ public class AirBlast extends AirAbility {
if (bf == face) {
if (!door.isOpen()) {
this.remove();
return;
}
} else if (bf.getOppositeFace() == face) {
if (door.isOpen()) {
this.remove();
return;
}
}
@ -350,10 +352,12 @@ public class AirBlast extends AirAbility {
if (this.origin.getY() < block.getY()) {
if (!tDoor.isOpen()) {
this.remove();
return;
}
} else {
if (tDoor.isOpen()) {
this.remove();
return;
}
}

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -149,7 +150,7 @@ public class Suffocate extends AirAbility {
public void progress() {
for (int i = 0; i < this.targets.size(); i++) {
final LivingEntity target = this.targets.get(i);
if (target.isDead() || !target.getWorld().equals(this.player.getWorld()) || target.getLocation().distanceSquared(this.player.getEyeLocation()) > this.range * this.range || GeneralMethods.isRegionProtectedFromBuild(this, target.getLocation())) {
if (target.isDead() || !target.getWorld().equals(this.player.getWorld()) || target.getLocation().distanceSquared(this.player.getEyeLocation()) > this.range * this.range || GeneralMethods.isRegionProtectedFromBuild(this, target.getLocation()) || target instanceof ArmorStand) {
this.breakSuffocateLocal(target);
i--;
} else if (target instanceof Player) {
@ -190,8 +191,7 @@ public class Suffocate extends AirAbility {
return;
} else if (!this.started) {
this.started = true;
for (final LivingEntity targ : this.targets) {
final LivingEntity target = targ;
for (final LivingEntity target : this.targets) {
final BukkitRunnable br1 = new BukkitRunnable() {
@Override
public void run() {
@ -220,7 +220,10 @@ public class Suffocate extends AirAbility {
}
}
this.animate();
for (final LivingEntity target : this.targets) {
this.animate(target);
}
if (!this.player.isSneaking()) {
this.remove();
return;
@ -290,7 +293,7 @@ public class Suffocate extends AirAbility {
* specific time (dt) the ability will create a different set of
* SuffocationSpirals.
*/
public void animate() {
public void animate(final LivingEntity target) {
final int steps = 8 * this.particleCount;
final long curTime = System.currentTimeMillis();
final long dt = curTime - this.getStartTime() - this.chargeTime;
@ -299,28 +302,25 @@ public class Suffocate extends AirAbility {
final long t2 = (long) (2500 * this.animationSpeed);
final long t3 = (long) (5000 * this.animationSpeed);
final long t4 = (long) (6000 * this.animationSpeed);
for (final LivingEntity lent : this.targets) {
final LivingEntity target = lent;
if (dt < t1) {
new SuffocateSpiral(target, steps, this.radius, delay, 0, 0.25 - (0.25 * dt / t1), 0, SpiralType.HORIZONTAL1);
new SuffocateSpiral(target, steps, this.radius, delay, 0, 0.25 - (0.25 * dt / t1), 0, SpiralType.HORIZONTAL2);
} else if (dt < t2) {
new SuffocateSpiral(target, steps, this.radius, delay, 0, 0, 0, SpiralType.HORIZONTAL1);
new SuffocateSpiral(target, steps * 2, this.radius, delay, 0, 0, 0, SpiralType.VERTICAL1);
new SuffocateSpiral(target, steps * 2, this.radius, delay, 0, 0, 0, SpiralType.VERTICAL2);
} else if (dt < t3) {
new SuffocateSpiral(target, steps, this.radius, delay, 0, 0, 0, SpiralType.HORIZONTAL1);
new SuffocateSpiral(target, steps, this.radius, delay, 0, 0, 0, SpiralType.VERTICAL1);
new SuffocateSpiral(target, steps, this.radius, delay, 0, 0, 0, SpiralType.VERTICAL2);
} else if (dt < t4) {
new SuffocateSpiral(target, steps, this.radius - Math.min(this.radius * 3 / 4, (this.radius * 3.0 / 4 * ((double) (dt - t3) / (double) (t4 - t3)))), delay, 0, 0, 0, SpiralType.HORIZONTAL1);
new SuffocateSpiral(target, steps, this.radius - Math.min(this.radius * 3 / 4, (this.radius * 3.0 / 4 * ((double) (dt - t3) / (double) (t4 - t3)))), delay, 0, 0, 0, SpiralType.VERTICAL1);
new SuffocateSpiral(target, steps, this.radius - Math.min(this.radius * 3 / 4, (this.radius * 3.0 / 4 * ((double) (dt - t3) / (double) (t4 - t3)))), delay, 0, 0, 0, SpiralType.VERTICAL2);
} else {
new SuffocateSpiral(target, steps, this.radius - (this.radius * 3.0 / 4.0), delay, 0, 0, 0, SpiralType.HORIZONTAL1);
new SuffocateSpiral(target, steps, this.radius - (this.radius * 3.0 / 4.0), delay, 0, 0, 0, SpiralType.VERTICAL1);
new SuffocateSpiral(target, steps, this.radius - (this.radius * 3.0 / 4.0), delay, 0, 0, 0, SpiralType.VERTICAL2);
}
if (dt < t1) {
new SuffocateSpiral(target, steps, this.radius, delay, 0, 0.25 - (0.25 * dt / t1), 0, SpiralType.HORIZONTAL1);
new SuffocateSpiral(target, steps, this.radius, delay, 0, 0.25 - (0.25 * dt / t1), 0, SpiralType.HORIZONTAL2);
} else if (dt < t2) {
new SuffocateSpiral(target, steps, this.radius, delay, 0, 0, 0, SpiralType.HORIZONTAL1);
new SuffocateSpiral(target, steps * 2, this.radius, delay, 0, 0, 0, SpiralType.VERTICAL1);
new SuffocateSpiral(target, steps * 2, this.radius, delay, 0, 0, 0, SpiralType.VERTICAL2);
} else if (dt < t3) {
new SuffocateSpiral(target, steps, this.radius, delay, 0, 0, 0, SpiralType.HORIZONTAL1);
new SuffocateSpiral(target, steps, this.radius, delay, 0, 0, 0, SpiralType.VERTICAL1);
new SuffocateSpiral(target, steps, this.radius, delay, 0, 0, 0, SpiralType.VERTICAL2);
} else if (dt < t4) {
new SuffocateSpiral(target, steps, this.radius - Math.min(this.radius * 3 / 4, (this.radius * 3.0 / 4 * ((double) (dt - t3) / (double) (t4 - t3)))), delay, 0, 0, 0, SpiralType.HORIZONTAL1);
new SuffocateSpiral(target, steps, this.radius - Math.min(this.radius * 3 / 4, (this.radius * 3.0 / 4 * ((double) (dt - t3) / (double) (t4 - t3)))), delay, 0, 0, 0, SpiralType.VERTICAL1);
new SuffocateSpiral(target, steps, this.radius - Math.min(this.radius * 3 / 4, (this.radius * 3.0 / 4 * ((double) (dt - t3) / (double) (t4 - t3)))), delay, 0, 0, 0, SpiralType.VERTICAL2);
} else {
new SuffocateSpiral(target, steps, this.radius - (this.radius * 3.0 / 4.0), delay, 0, 0, 0, SpiralType.HORIZONTAL1);
new SuffocateSpiral(target, steps, this.radius - (this.radius * 3.0 / 4.0), delay, 0, 0, 0, SpiralType.VERTICAL1);
new SuffocateSpiral(target, steps, this.radius - (this.radius * 3.0 / 4.0), delay, 0, 0, 0, SpiralType.VERTICAL2);
}
}

View file

@ -9,8 +9,6 @@ import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.ProjectKorra;
import com.projectkorra.projectkorra.ability.CoreAbility;
import com.projectkorra.projectkorra.configuration.ConfigManager;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
public class PlaceholderAPIHook extends PlaceholderExpansion {

View file

@ -3,7 +3,6 @@ package com.projectkorra.projectkorra.hooks;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
import com.projectkorra.projectkorra.ProjectKorra;
public class WorldGuardFlag {

View file

@ -178,7 +178,7 @@ public class WaterArmsSpear extends WaterAbility {
return;
}
new TempBlock(this.location.getBlock(), Material.WATER, GeneralMethods.getWaterData(0));
new TempBlock(this.location.getBlock(), Material.WATER);
getIceBlocks().put(this.location.getBlock(), System.currentTimeMillis() + 600L);
final Vector direction = GeneralMethods.getDirection(this.initLocation, GeneralMethods.getTargetedLocation(this.player, this.spearRange, getTransparentMaterials())).normalize();
@ -256,7 +256,7 @@ public class WaterArmsSpear extends WaterAbility {
private boolean canPlaceBlock(final Block block) {
if (!isTransparent(this.player, block) && !((isWater(block) || this.isIcebendable(block)) && (TempBlock.isTempBlock(block) && !getIceBlocks().containsKey(block)))) {
return false;
} else if (GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) {
} else if (GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation()) || GeneralMethods.isSolid(block)) {
return false;
} else if (WaterArms.isUnbreakable(block) && !isWater(block)) {
return false;