diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBoss.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBoss.java index 84987d1..0ceda9f 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBoss.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBoss.java @@ -5,6 +5,7 @@ import com.willfp.eco.util.NumberUtils; import com.willfp.eco.util.StringUtils; import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.eco.util.tuples.Pair; import com.willfp.ecobosses.bosses.util.bosstype.BossEntityUtils; import com.willfp.ecobosses.bosses.util.bosstype.BossType; import com.willfp.ecobosses.bosses.util.obj.BossbarProperties; @@ -118,7 +119,7 @@ public class EcoBoss extends PluginDependent { * The drops. */ @Getter - private final Map drops; + private final Map drops; /** * The exp to drop. @@ -198,6 +199,24 @@ public class EcoBoss extends PluginDependent { @Getter private final List deathMessages; + /** + * Nearby players radius. + */ + @Getter + private final double nearbyRadius; + + /** + * Nearby players commands. + */ + @Getter + private final Map nearbyPlayersCommands; + + /** + * Top damager commands. + */ + @Getter + private final Map>> topDamagerCommands; + /** * Create a new Boss. * @@ -253,7 +272,7 @@ public class EcoBoss extends PluginDependent { e.printStackTrace(); } ItemStack itemStack = tempConfig.getItemStack("drop-key"); - this.drops.put(chance, itemStack); + this.drops.put(itemStack, chance); } this.experienceOptions = new ExperienceOptions( this.getConfig().getInt("rewards.xp.minimum"), @@ -375,6 +394,35 @@ public class EcoBoss extends PluginDependent { this.getConfig().getDouble("defence.teleport.chance") ); + // Top Damager Commands + this.topDamagerCommands = new HashMap<>(); + for (int i = 1; i <= 3; i++) { + for (String string : this.getConfig().getStrings("rewards.top-damager-commands." + i)) { + double chance = 100; + if (string.contains("::")) { + String[] split = string.split("::"); + chance = Double.parseDouble(split[0]); + string = split[1]; + } + List> commands = this.topDamagerCommands.get(i) == null ? new ArrayList<>() : this.topDamagerCommands.get(i); + commands.add(new Pair<>(chance, string)); + this.topDamagerCommands.put(i, commands); + } + } + + // Nearby Rewards + this.nearbyRadius = this.getConfig().getDouble("rewards.nearby-player-commands.radius"); + this.nearbyPlayersCommands = new HashMap<>(); + for (String string : this.getConfig().getStrings("rewards.nearby-player-commands.commands")) { + double chance = 100; + if (string.contains("::")) { + String[] split = string.split("::"); + chance = Double.parseDouble(split[0]); + string = split[1]; + } + this.nearbyPlayersCommands.put(string, chance); + } + if (this.getConfig().getBool("enabled")) { EcoBosses.addBoss(this); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/DeathListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/DeathListeners.java index f1fe40d..61893d9 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/DeathListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/DeathListeners.java @@ -6,12 +6,15 @@ import com.willfp.eco.util.StringUtils; import com.willfp.eco.util.events.entitydeathbyentity.EntityDeathByEntityEvent; import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.eco.util.tuples.Pair; import com.willfp.ecobosses.bosses.EcoBoss; import com.willfp.ecobosses.bosses.util.BossUtils; import com.willfp.ecobosses.bosses.util.obj.DamagerProperty; import com.willfp.ecobosses.bosses.util.obj.OptionedSound; import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -21,6 +24,7 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; +import java.util.Map; public class DeathListeners extends PluginDependent implements Listener { /** @@ -105,12 +109,44 @@ public class DeathListeners extends PluginDependent implements Listener { ); } - List drops = new ArrayList<>(); - boss.getDrops().forEach((aDouble, itemStack) -> { - if (NumberUtils.randFloat(0, 100) < aDouble) { - drops.add(itemStack); + for (int i = 1; i <= 3; i++) { + List> topDamagerCommands = boss.getTopDamagerCommands().get(i); + for (Pair pair : topDamagerCommands) { + if (top != null && i == 1) { + if (NumberUtils.randFloat(0, 100) < pair.getFirst()) { + Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), pair.getSecond().replace("%player%", top.getPlayer().getName())); + } + } + if (second != null && i == 2) { + if (NumberUtils.randFloat(0, 100) < pair.getFirst()) { + Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), pair.getSecond().replace("%player%", second.getPlayer().getName())); + } + } + if (third != null && i == 3) { + if (NumberUtils.randFloat(0, 100) < pair.getFirst()) { + Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), pair.getSecond().replace("%player%", third.getPlayer().getName())); + } + } } - }); + } + + List drops = new ArrayList<>(); + for (Map.Entry entry : boss.getDrops().entrySet()) { + if (NumberUtils.randFloat(0, 100) < entry.getValue()) { + drops.add(entry.getKey()); + } + } + + for (Entity nearby : entity.getNearbyEntities(boss.getNearbyRadius(), boss.getNearbyRadius(), boss.getNearbyRadius())) { + if (nearby instanceof Player) { + String playerName = nearby.getName(); + for (Map.Entry entry : boss.getNearbyPlayersCommands().entrySet()) { + if (NumberUtils.randFloat(0, 100) < entry.getValue()) { + Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), entry.getKey().replace("%player%", playerName)); + } + } + } + } event.getDrops().addAll(drops); event.setDroppedExp(boss.getExperienceOptions().generateXp()); diff --git a/eco-core/core-plugin/src/main/resources/bosses/illusioner.yml b/eco-core/core-plugin/src/main/resources/bosses/illusioner.yml index a9998e3..bc78b51 100644 --- a/eco-core/core-plugin/src/main/resources/bosses/illusioner.yml +++ b/eco-core/core-plugin/src/main/resources/bosses/illusioner.yml @@ -22,18 +22,22 @@ rewards: minimum: 20000 maximum: 25000 top-damager-commands: + # To set a chance for a command, put :: 1: - - "40::give %player% diamond_block" + - "give %player% diamond_block" 2: - "25::give %player% emerald_block" 3: - "10::give %player% iron_block" nearby-player-commands: radius: 10 + # To set a chance for a command, put :: + # Use %player% as the placeholder for the player name commands: [] - drops: - # Get items to add here by copying the console output for /ebdrop - # To set the chance for a drop, put :: + + # Get items to add here by copying the console output for /ebdrop + # To set the chance for a drop, put :: + drops: [] broadcast: spawn: