mirror of
https://github.com/Auxilor/EcoMobs.git
synced 2025-12-21 07:59:28 +00:00
Added top damager and nearby radius commands
This commit is contained in:
@@ -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<Double, ItemStack> drops;
|
||||
private final Map<ItemStack, Double> drops;
|
||||
|
||||
/**
|
||||
* The exp to drop.
|
||||
@@ -198,6 +199,24 @@ public class EcoBoss extends PluginDependent {
|
||||
@Getter
|
||||
private final List<String> deathMessages;
|
||||
|
||||
/**
|
||||
* Nearby players radius.
|
||||
*/
|
||||
@Getter
|
||||
private final double nearbyRadius;
|
||||
|
||||
/**
|
||||
* Nearby players commands.
|
||||
*/
|
||||
@Getter
|
||||
private final Map<String, Double> nearbyPlayersCommands;
|
||||
|
||||
/**
|
||||
* Top damager commands.
|
||||
*/
|
||||
@Getter
|
||||
private final Map<Integer, List<Pair<Double, String>>> 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<Pair<Double, String>> 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);
|
||||
}
|
||||
|
||||
@@ -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<ItemStack> 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<Pair<Double, String>> topDamagerCommands = boss.getTopDamagerCommands().get(i);
|
||||
for (Pair<Double, String> 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<ItemStack> drops = new ArrayList<>();
|
||||
for (Map.Entry<ItemStack, Double> 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<String, Double> 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());
|
||||
|
||||
@@ -22,18 +22,22 @@ rewards:
|
||||
minimum: 20000
|
||||
maximum: 25000
|
||||
top-damager-commands:
|
||||
# To set a chance for a command, put <chance>::<command>
|
||||
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 <chance>::<command>
|
||||
# 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 <chance>::<base64>
|
||||
drops: []
|
||||
|
||||
broadcast:
|
||||
spawn:
|
||||
|
||||
Reference in New Issue
Block a user