diff --git a/eco-core/core-plugin/src/main/java/com/willfp/illusioner/config/configs/Attacks.java b/eco-core/core-plugin/src/main/java/com/willfp/illusioner/config/configs/Attacks.java index 9ee2033..9a86154 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/illusioner/config/configs/Attacks.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/illusioner/config/configs/Attacks.java @@ -8,6 +8,6 @@ public class Attacks extends BaseConfig { * Instantiate attacks.yml. */ public Attacks() { - super("attacks", false, IllusionerPlugin.getInstance()); + super("attacks", false, IllusionerPlugin.getInstance(), "effects.", "summons."); } } 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 9af33da..bb742c2 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 @@ -9,6 +9,7 @@ import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; @@ -35,13 +36,31 @@ public class AttackListeners implements Listener { 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; - if (event.getEntity() instanceof Player) { - temp = (Player) event.getEntity(); - } else if (event.getEntity() instanceof Projectile) { - if (((Projectile) event.getEntity()).getShooter() instanceof Player) { - temp = (Player) ((Projectile) event.getEntity()).getShooter(); + if (event.getDamager() instanceof Player) { + temp = (Player) event.getDamager(); + } else if (event.getDamager() instanceof Projectile) { + if (((Projectile) event.getDamager()).getShooter() instanceof Player) { + temp = (Player) ((Projectile) event.getDamager()).getShooter(); } } @@ -51,11 +70,16 @@ public class AttackListeners implements Listener { 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(); 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 { - 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 -> { @@ -95,9 +119,9 @@ public class AttackListeners implements Listener { OptionedSound summonSound = IllusionerManager.OPTIONS.getGameplayOptions().getSummonSound(); 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 { - player.playSound(event.getEntity().getLocation(), summonSound.getSound(), summonSound.getVolume(), summonSound.getPitch()); + player.playSound(illusioner.getLocation(), summonSound.getSound(), summonSound.getVolume(), summonSound.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 d1e7099..1826d83 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 @@ -6,6 +6,7 @@ import com.willfp.illusioner.config.IllusionerConfigs; import com.willfp.illusioner.illusioner.OptionedSound; import lombok.Getter; import lombok.ToString; +import org.bukkit.Bukkit; import org.bukkit.Sound; import org.bukkit.entity.EntityType; import org.bukkit.potion.PotionEffectType; @@ -148,10 +149,13 @@ public class GameplayOptions extends PluginDependent { summonerOptions.clear(); IllusionerConfigs.ATTACKS.getConfig().getConfigurationSection("summons").getKeys(false).forEach(key -> { + Bukkit.getLogger().info(key + " bruh "); EntityType type = EntityType.valueOf(IllusionerConfigs.ATTACKS.getString("summons." + key + ".type")); double chance = IllusionerConfigs.ATTACKS.getDouble("summons." + key + ".chance"); summonerOptions.add(new SummonerOption(chance, type)); }); + + Bukkit.getLogger().info(summonerOptions.toString()); } public static class EffectOption { diff --git a/gradle.properties b/gradle.properties index af13972..097f5b3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 2.4.1 +version = 2.5.0 plugin-name = Illusioner \ No newline at end of file