diff --git a/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/listeners/AttackListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/listeners/AttackListeners.java index 633ff03..9af33da 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/listeners/AttackListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/listeners/AttackListeners.java @@ -134,24 +134,36 @@ public class AttackListeners implements Listener { if (IllusionerManager.OPTIONS.getGameplayOptions().isTeleport()) { if (NumberUtils.randFloat(0, 100) < IllusionerManager.OPTIONS.getGameplayOptions().getTeleportChance()) { int range = IllusionerManager.OPTIONS.getGameplayOptions().getTeleportRange(); + List valid = new ArrayList<>(); for (int x = -range; x <= range; x++) { for (int y = -range; y <= range; y++) { for (int z = -range; z <= range; z++) { Location location = event.getEntity().getLocation().clone(); - location.setX(x); - location.setY(y); - location.setZ(z); + location.setX(location.getX() + x); + location.setY(location.getY() + y); + location.setZ(location.getZ() + z); Block block = location.getBlock(); - if (block.getType() == Material.AIR && block.getRelative(BlockFace.UP).getType() == Material.AIR) { - event.getEntity().teleport(location); - OptionedSound optionedSound = IllusionerManager.OPTIONS.getGameplayOptions().getTeleportSound(); - location.getWorld().playSound(location, optionedSound.getSound(), optionedSound.getVolume(), optionedSound.getPitch()); + if (block.getType() == Material.AIR + && block.getRelative(BlockFace.UP).getType() == Material.AIR + && !(block.getRelative(BlockFace.DOWN).isLiquid() || block.getRelative(BlockFace.DOWN).getType() == Material.AIR)) { + valid.add(location); } } } } + + if (valid.isEmpty()) { + return; + } + + Collections.shuffle(valid); + Location location = valid.get(0); + + event.getEntity().teleport(location); + OptionedSound optionedSound = IllusionerManager.OPTIONS.getGameplayOptions().getTeleportSound(); + location.getWorld().playSound(location, optionedSound.getSound(), optionedSound.getVolume(), optionedSound.getPitch()); } } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/options/GameplayOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/options/GameplayOptions.java index 100cdba..d1e7099 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/options/GameplayOptions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/options/GameplayOptions.java @@ -130,7 +130,7 @@ public class GameplayOptions extends PluginDependent { teleport = this.getPlugin().getConfigYml().getBool("teleport-on-damage.enabled"); teleportRange = this.getPlugin().getConfigYml().getInt("teleport-on-damage.range"); - teleportChance = this.getPlugin().getConfigYml().getInt("teleport-on-damage.chance"); + teleportChance = this.getPlugin().getConfigYml().getDouble("teleport-on-damage.chance"); Sound sound = Sound.valueOf(IllusionerConfigs.SOUNDS.getString("teleport.sound")); float volume = (float) IllusionerConfigs.SOUNDS.getDouble("teleport.volume"); diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index 5e23780..c650868 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -25,7 +25,7 @@ ignore-suffocation-damage: true teleport-on-damage: enabled: true - range: 10 + range: 7 chance: 15 # As a percentage spawn: