9
0
mirror of https://github.com/Auxilor/EcoMobs.git synced 2025-12-23 17:09:27 +00:00

Updated to 2.5.0 and allowed attacking the illusioner to trigger attacks

This commit is contained in:
Auxilor
2021-02-17 20:50:46 +00:00
parent fab8535f9e
commit f190c54f6b
4 changed files with 39 additions and 11 deletions

View File

@@ -8,6 +8,6 @@ public class Attacks extends BaseConfig {
* Instantiate attacks.yml. * Instantiate attacks.yml.
*/ */
public Attacks() { public Attacks() {
super("attacks", false, IllusionerPlugin.getInstance()); super("attacks", false, IllusionerPlugin.getInstance(), "effects.", "summons.");
} }
} }

View File

@@ -9,6 +9,7 @@ import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@@ -35,13 +36,31 @@ public class AttackListeners implements Listener {
return; return;
} }
if (!(event.getEntity() instanceof Player)) {
return;
}
handleAttack((LivingEntity) event.getDamager(), (Player) event.getEntity());
}
/**
* Called when a player attacks an illusioner.
*
* @param event The event to listen for.
*/
@EventHandler(ignoreCancelled = true)
public void onAttackIllusioner(@NotNull final EntityDamageByEntityEvent event) {
if (!event.getEntity().getType().equals(EntityType.ILLUSIONER)) {
return;
}
Player temp = null; Player temp = null;
if (event.getEntity() instanceof Player) { if (event.getDamager() instanceof Player) {
temp = (Player) event.getEntity(); temp = (Player) event.getDamager();
} else if (event.getEntity() instanceof Projectile) { } else if (event.getDamager() instanceof Projectile) {
if (((Projectile) event.getEntity()).getShooter() instanceof Player) { if (((Projectile) event.getDamager()).getShooter() instanceof Player) {
temp = (Player) ((Projectile) event.getEntity()).getShooter(); temp = (Player) ((Projectile) event.getDamager()).getShooter();
} }
} }
@@ -51,11 +70,16 @@ public class AttackListeners implements Listener {
Player player = temp; Player player = temp;
handleAttack((LivingEntity) event.getEntity(), player);
}
private void handleAttack(@NotNull final LivingEntity illusioner,
@NotNull final Player player) {
OptionedSound hitSound = IllusionerManager.OPTIONS.getGameplayOptions().getHitSound(); OptionedSound hitSound = IllusionerManager.OPTIONS.getGameplayOptions().getHitSound();
if (hitSound.isBroadcast()) { if (hitSound.isBroadcast()) {
player.getWorld().playSound(event.getEntity().getLocation(), hitSound.getSound(), hitSound.getVolume(), hitSound.getPitch()); player.getWorld().playSound(illusioner.getLocation(), hitSound.getSound(), hitSound.getVolume(), hitSound.getPitch());
} else { } else {
player.playSound(event.getEntity().getLocation(), hitSound.getSound(), hitSound.getVolume(), hitSound.getPitch()); player.playSound(illusioner.getLocation(), hitSound.getSound(), hitSound.getVolume(), hitSound.getPitch());
} }
IllusionerManager.OPTIONS.getGameplayOptions().getEffectOptions().forEach(effectOption -> { IllusionerManager.OPTIONS.getGameplayOptions().getEffectOptions().forEach(effectOption -> {
@@ -95,9 +119,9 @@ public class AttackListeners implements Listener {
OptionedSound summonSound = IllusionerManager.OPTIONS.getGameplayOptions().getSummonSound(); OptionedSound summonSound = IllusionerManager.OPTIONS.getGameplayOptions().getSummonSound();
if (summonSound.isBroadcast()) { if (summonSound.isBroadcast()) {
player.getWorld().playSound(event.getEntity().getLocation(), summonSound.getSound(), summonSound.getVolume(), summonSound.getPitch()); player.getWorld().playSound(illusioner.getLocation(), summonSound.getSound(), summonSound.getVolume(), summonSound.getPitch());
} else { } else {
player.playSound(event.getEntity().getLocation(), summonSound.getSound(), summonSound.getVolume(), summonSound.getPitch()); player.playSound(illusioner.getLocation(), summonSound.getSound(), summonSound.getVolume(), summonSound.getPitch());
} }
}); });
} }

View File

@@ -6,6 +6,7 @@ import com.willfp.illusioner.config.IllusionerConfigs;
import com.willfp.illusioner.illusioner.OptionedSound; import com.willfp.illusioner.illusioner.OptionedSound;
import lombok.Getter; import lombok.Getter;
import lombok.ToString; import lombok.ToString;
import org.bukkit.Bukkit;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
@@ -148,10 +149,13 @@ public class GameplayOptions extends PluginDependent {
summonerOptions.clear(); summonerOptions.clear();
IllusionerConfigs.ATTACKS.getConfig().getConfigurationSection("summons").getKeys(false).forEach(key -> { IllusionerConfigs.ATTACKS.getConfig().getConfigurationSection("summons").getKeys(false).forEach(key -> {
Bukkit.getLogger().info(key + " bruh ");
EntityType type = EntityType.valueOf(IllusionerConfigs.ATTACKS.getString("summons." + key + ".type")); EntityType type = EntityType.valueOf(IllusionerConfigs.ATTACKS.getString("summons." + key + ".type"));
double chance = IllusionerConfigs.ATTACKS.getDouble("summons." + key + ".chance"); double chance = IllusionerConfigs.ATTACKS.getDouble("summons." + key + ".chance");
summonerOptions.add(new SummonerOption(chance, type)); summonerOptions.add(new SummonerOption(chance, type));
}); });
Bukkit.getLogger().info(summonerOptions.toString());
} }
public static class EffectOption { public static class EffectOption {

View File

@@ -1,2 +1,2 @@
version = 2.4.1 version = 2.5.0
plugin-name = Illusioner plugin-name = Illusioner