9
0
mirror of https://github.com/Auxilor/EcoMobs.git synced 2025-12-21 07:59:28 +00:00

Changed teleportation

This commit is contained in:
Auxilor
2021-01-30 12:14:24 +00:00
parent e9470f0339
commit 4e93b003d3
3 changed files with 21 additions and 9 deletions

View File

@@ -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<Location> 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());
}
}
}

View File

@@ -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");

View File

@@ -25,7 +25,7 @@ ignore-suffocation-damage: true
teleport-on-damage:
enabled: true
range: 10
range: 7
chance: 15 # As a percentage
spawn: