9
0
mirror of https://github.com/Auxilor/EcoMobs.git synced 2025-12-23 08:59:31 +00:00

Moved teleportation into effects

This commit is contained in:
Auxilor
2021-04-05 13:44:19 +01:00
parent b7453b801c
commit 4430c10546
9 changed files with 78 additions and 101 deletions

View File

@@ -16,7 +16,6 @@ import com.willfp.ecobosses.bosses.util.obj.ImmunityOptions;
import com.willfp.ecobosses.bosses.util.obj.OptionedSound;
import com.willfp.ecobosses.bosses.util.obj.SpawnTotem;
import com.willfp.ecobosses.bosses.util.obj.TargetMode;
import com.willfp.ecobosses.bosses.util.obj.TeleportOptions;
import lombok.AccessLevel;
import lombok.Getter;
import org.bukkit.Bukkit;
@@ -171,18 +170,6 @@ public class EcoBoss extends PluginDependent {
@Getter
private final List<OptionedSound> summonSounds;
/**
* If the boss can teleport.
*/
@Getter
private final boolean teleportationEnabled;
/**
* Teleport options.
*/
@Getter
private final TeleportOptions teleportOptions;
/**
* Spawn messages.
*/
@@ -380,13 +367,6 @@ public class EcoBoss extends PluginDependent {
this.deathMessages.add(StringUtils.translate(string));
}
// Teleportation
this.teleportationEnabled = this.getConfig().getBool("defence.teleport.enabled");
this.teleportOptions = new TeleportOptions(
this.getConfig().getInt("defence.teleport.range"),
this.getConfig().getDouble("defence.teleport.chance")
);
// Top Damager Commands
this.topDamagerCommands = new HashMap<>();
for (int i = 1; i <= 3; i++) {

View File

@@ -6,6 +6,7 @@ import com.willfp.ecobosses.bosses.effects.effects.EffectGivePotionEffect;
import com.willfp.ecobosses.bosses.effects.effects.EffectLightningNearbyEntities;
import com.willfp.ecobosses.bosses.effects.effects.EffectShuffleHotbar;
import com.willfp.ecobosses.bosses.effects.effects.EffectSummon;
import com.willfp.ecobosses.bosses.effects.effects.EffectTeleport;
import lombok.experimental.UtilityClass;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -25,6 +26,7 @@ public class Effects {
.put("summon", EffectSummon::new)
.put("give-potion-effect", EffectGivePotionEffect::new)
.put("shuffle-hotbar", EffectShuffleHotbar::new)
.put("teleport", EffectTeleport::new)
.build();
/**

View File

@@ -0,0 +1,75 @@
package com.willfp.ecobosses.bosses.effects.effects;
import com.willfp.eco.util.NumberUtils;
import com.willfp.ecobosses.bosses.EcoBoss;
import com.willfp.ecobosses.bosses.effects.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class EffectTeleport extends Effect {
private final int range;
private final double chance;
public EffectTeleport(@NotNull final List<String> args) {
super(args);
if (args.size() < 2) {
showConfigError("Incorrect amount of arguments!");
}
range = Integer.parseInt(args.get(0));
chance = Double.parseDouble(args.get(1));
}
@Override
public String getUsage() {
return "teleport:<range>:<chance>";
}
@Override
public void onAttack(@NotNull final EcoBoss boss,
@NotNull final LivingEntity entity,
@NotNull final Player player) {
if (NumberUtils.randFloat(0, 100) > this.chance) {
return;
}
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 = entity.getLocation().clone();
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
&& !(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);
entity.teleport(location);
}
}

View File

@@ -2,16 +2,11 @@ package com.willfp.ecobosses.bosses.listeners;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.util.NumberUtils;
import com.willfp.ecobosses.bosses.EcoBoss;
import com.willfp.ecobosses.bosses.LivingEcoBoss;
import com.willfp.ecobosses.bosses.util.BossUtils;
import com.willfp.ecobosses.bosses.util.obj.DamagerProperty;
import com.willfp.ecobosses.bosses.util.obj.ImmunityOptions;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
@@ -22,8 +17,6 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -200,39 +193,5 @@ public class AttackListeners extends PluginDependent implements Listener {
event.setDamage(event.getDamage() * entry.getValue());
}
}
if (boss.isTeleportationEnabled()) {
if (NumberUtils.randFloat(0, 100) < boss.getTeleportOptions().getChance()) {
int range = boss.getTeleportOptions().getRange();
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(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
&& !(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);
}
}
}
}

View File

@@ -1,16 +0,0 @@
package com.willfp.ecobosses.bosses.util.obj;
import lombok.Data;
@Data
public class TeleportOptions {
/**
* The teleportation range.
*/
private final int range;
/**
* The chance to teleport.
*/
private final double chance;
}

View File

@@ -71,12 +71,6 @@ defence:
melee: 1.1
projectile: 0.3
# If the boss should teleport when damaged
teleport:
enabled: false
range: 7
chance: 15 # As a percentage
attacks:
# Chance is rolled when boss attacks player
on-injure: true # If chance should be rolled when boss is attacked too

View File

@@ -60,6 +60,7 @@ effects:
- "shuffle-hotbar:10"
- "give-potion-effect:confusion:10:200:10"
- "give-potion-effect:blindness:1:40:20"
- "teleport:7:15"
defence:
immunities:
@@ -73,12 +74,6 @@ defence:
melee: 1
projectile: 0.6
# If the boss should teleport when damaged
teleport:
enabled: true
range: 7
chance: 15 # As a percentage
attacks:
# Chance is rolled when boss attacks player
on-injure: true # If chance should be rolled when boss is attacked too

View File

@@ -75,12 +75,6 @@ defence:
melee: 0.8
projectile: 0.2
# If the boss should teleport when damaged
teleport:
enabled: false
range: 7
chance: 15 # As a percentage
attacks:
# Chance is rolled when boss attacks player
on-injure: true # If chance should be rolled when boss is attacked too

View File

@@ -75,12 +75,6 @@ defence:
melee: 0.6
projectile: 0.3
# If the boss should teleport when damaged
teleport:
enabled: false
range: 7
chance: 15 # As a percentage
attacks:
# Chance is rolled when boss attacks player
on-injure: true # If chance should be rolled when boss is attacked too