diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md index dfb5a3ad2..2948bee8b 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -19,7 +19,9 @@ assignees: '' - +1. +2. +3. ## :bulb: Expected behavior (REQUIRED) @@ -34,7 +36,7 @@ assignees: '' ## :open_file_folder: /error-reports/ Folder - + @@ -46,7 +48,7 @@ assignees: '' - - Server Software (Spigot/Paper): - - Minecraft Version: - - Slimefun Version: - - CS-CoreLib Version: + - Server Software: + - Minecraft Version: + - Slimefun Version: + - CS-CoreLib Version: diff --git a/CHANGELOG.md b/CHANGELOG.md index 583e7c82d..2cb901fe3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ * Fixed ghost blocks to some extent (ghost blocks will now drop and be replaced) * Fixed #2636 * Fixed some backpack opening issues +* Fixed #2647 ## Release Candidate 18 (03 Dec 2020) diff --git a/pom.xml b/pom.xml index a3811bef9..93ce3821e 100644 --- a/pom.xml +++ b/pom.xml @@ -348,7 +348,7 @@ com.konghq unirest-java - 3.11.06 + 3.11.09 compile diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/StomperBoots.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/StomperBoots.java index 8438d7950..da217cf57 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/StomperBoots.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/StomperBoots.java @@ -1,5 +1,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.armor; +import javax.annotation.Nonnull; + import org.bukkit.Bukkit; import org.bukkit.Effect; import org.bukkit.Location; @@ -25,7 +27,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; /** * The Boots of the Stomper are boots which damage nearby enemies whenever the {@link Player} * takes fall damage. - * + * * @author TheBusyBiscuit * */ @@ -37,49 +39,49 @@ public class StomperBoots extends SlimefunItem { /** * This will apply the "stomp" effect to the given {@link EntityDamageEvent}. - * + * * @param fallDamageEvent * The {@link EntityDamageEvent} in which the {@link Player} has taken fall damage */ public void stomp(EntityDamageEvent fallDamageEvent) { - Player p = (Player) fallDamageEvent.getEntity(); - p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR, 1F, 2F); - p.setVelocity(new Vector(0, 0.7, 0)); + Player player = (Player) fallDamageEvent.getEntity(); + player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR, 1F, 2F); + player.setVelocity(new Vector(0, 0.7, 0)); - for (Entity n : p.getNearbyEntities(4, 4, 4)) { - if (n instanceof LivingEntity && n.isValid() && !n.getUniqueId().equals(p.getUniqueId())) { - Vector velocity = getShockwave(p.getLocation(), n.getLocation()); - n.setVelocity(velocity); + for (Entity entity : player.getNearbyEntities(4, 4, 4)) { + if (entity instanceof LivingEntity && canPush(player, (LivingEntity) entity)) { + Vector velocity = getShockwave(player.getLocation(), entity.getLocation()); + entity.setVelocity(velocity); // Check if it's not a Player or if PvP is enabled - if (!(n instanceof Player) || (p.getWorld().getPVP() && SlimefunPlugin.getProtectionManager().hasPermission(p, n.getLocation(), ProtectableAction.ATTACK_PLAYER))) { - EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(p, n, DamageCause.ENTITY_ATTACK, fallDamageEvent.getDamage() / 2); + if (!(entity instanceof Player) || (player.getWorld().getPVP() && SlimefunPlugin.getProtectionManager().hasPermission(player, entity.getLocation(), ProtectableAction.ATTACK_PLAYER))) { + EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(player, entity, DamageCause.ENTITY_ATTACK, fallDamageEvent.getDamage() / 2); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { - ((LivingEntity) n).damage(event.getDamage()); + ((LivingEntity) entity).damage(event.getDamage()); } } } } for (BlockFace face : BlockFace.values()) { - Block b = p.getLocation().getBlock().getRelative(BlockFace.DOWN).getRelative(face); - p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType()); + Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN).getRelative(face); + player.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType()); } } /** * This gives us the "shockwave" {@link Vector} for a given target. - * + * * @param origin * The {@link Location} of our {@link Player} * @param target * The {@link Location} of the {@link Entity} we are pushing away - * + * * @return A {@link Vector} to determine the velocity for our {@link Entity} */ - private Vector getShockwave(Location origin, Location target) { + private Vector getShockwave(@Nonnull Location origin, @Nonnull Location target) { // As the distance approaches zero we might slip into a "division by zero" when normalizing if (origin.distanceSquared(target) < 0.05) { return new Vector(0, 1, 0); @@ -89,4 +91,21 @@ public class StomperBoots extends SlimefunItem { } } + /** + * Checks if the stomper boots can move an entity and is not the player who is using the boots. + *

+ * For developers: If you're spawning an immovable NPC, you should be denying + * collision with {@link LivingEntity#setCollidable(boolean)} or + * gravity with {@link LivingEntity#setGravity(boolean)}. + * + * @param entity + * The {@link LivingEntity} to check. + * @param player + * The {@link Player} using the {@link StomperBoots}. + * @return If the entity can move. + */ + protected boolean canPush(@Nonnull Player player, @Nonnull LivingEntity entity) { + return entity.isValid() && !entity.getUniqueId().equals(player.getUniqueId()) + && entity.isCollidable() && entity.hasGravity(); + } }