9
0
mirror of https://github.com/Auxilor/EcoMobs.git synced 2025-12-20 07:29:21 +00:00

Added option to set boss gear (armor / weapon)

This commit is contained in:
Auxilor
2021-09-19 13:33:23 +01:00
parent 436e833213
commit 7ea1f8938b
7 changed files with 171 additions and 1 deletions

View File

@@ -20,6 +20,7 @@ import com.willfp.ecobosses.bosses.util.bosstype.BossEntityUtils;
import com.willfp.ecobosses.bosses.util.bosstype.BossType; import com.willfp.ecobosses.bosses.util.bosstype.BossType;
import com.willfp.ecobosses.bosses.util.obj.ArgumentedEffectName; import com.willfp.ecobosses.bosses.util.obj.ArgumentedEffectName;
import com.willfp.ecobosses.bosses.util.obj.BossbarProperties; import com.willfp.ecobosses.bosses.util.obj.BossbarProperties;
import com.willfp.ecobosses.bosses.util.obj.EquipmentPiece;
import com.willfp.ecobosses.bosses.util.obj.ExperienceOptions; import com.willfp.ecobosses.bosses.util.obj.ExperienceOptions;
import com.willfp.ecobosses.bosses.util.obj.ImmunityOptions; import com.willfp.ecobosses.bosses.util.obj.ImmunityOptions;
import com.willfp.ecobosses.bosses.util.obj.OptionedSound; import com.willfp.ecobosses.bosses.util.obj.OptionedSound;
@@ -39,6 +40,7 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
@@ -293,7 +295,7 @@ public class EcoBoss extends PluginDependent<EcoPlugin> {
private final ItemStack spawnEgg; private final ItemStack spawnEgg;
/** /**
* All the requirements needed in order to use the enchantment. * All the requirements needed in order to spawn the boss.
*/ */
private final Map<Requirement, List<String>> requirements = new HashMap<>(); private final Map<Requirement, List<String>> requirements = new HashMap<>();
@@ -302,6 +304,12 @@ public class EcoBoss extends PluginDependent<EcoPlugin> {
*/ */
private final Map<UUID, Boolean> cachedRequirements = new HashMap<>(); private final Map<UUID, Boolean> cachedRequirements = new HashMap<>();
/**
* The equipment for the boss.
*/
@Getter
private final Map<EquipmentSlot, EquipmentPiece> equipment = new HashMap<>();
/** /**
* Create a new Boss. * Create a new Boss.
* *
@@ -337,6 +345,60 @@ public class EcoBoss extends PluginDependent<EcoPlugin> {
this.movementSpeedMultiplier = this.getConfig().getInt("movement-speed"); this.movementSpeedMultiplier = this.getConfig().getInt("movement-speed");
this.timeToLive = this.getConfig().getInt("time-to-live", -1); this.timeToLive = this.getConfig().getInt("time-to-live", -1);
// Equipment
ItemStack helmet = Items.lookup(this.getConfig().getString("gear.helmet.item")).getItem();
ItemStack chestplate = Items.lookup(this.getConfig().getString("gear.chestplate.item")).getItem();
ItemStack leggings = Items.lookup(this.getConfig().getString("gear.leggings.item")).getItem();
ItemStack boots = Items.lookup(this.getConfig().getString("gear.boots.item")).getItem();
ItemStack hand = Items.lookup(this.getConfig().getString("gear.hand.item")).getItem();
if (helmet.getType() != Material.AIR) {
this.equipment.put(
EquipmentSlot.HEAD,
new EquipmentPiece(
helmet,
this.getConfig().getDouble("gear.helmet.chance")
)
);
}
if (chestplate.getType() != Material.AIR) {
this.equipment.put(
EquipmentSlot.CHEST,
new EquipmentPiece(
chestplate,
this.getConfig().getDouble("gear.chestplate.chance")
)
);
}
if (leggings.getType() != Material.AIR) {
this.equipment.put(
EquipmentSlot.LEGS,
new EquipmentPiece(
leggings,
this.getConfig().getDouble("gear.leggings.chance")
)
);
}
if (boots.getType() != Material.AIR) {
this.equipment.put(
EquipmentSlot.FEET,
new EquipmentPiece(
boots,
this.getConfig().getDouble("gear.boots.chance")
)
);
}
if (hand.getType() != Material.AIR) {
this.equipment.put(
EquipmentSlot.HAND,
new EquipmentPiece(
hand,
this.getConfig().getDouble("gear.hand.chance")
)
);
}
// Spawn Totem // Spawn Totem
this.spawnTotemEnabled = this.getConfig().getBool("spawn-totem.enabled"); this.spawnTotemEnabled = this.getConfig().getBool("spawn-totem.enabled");
this.spawnTotem = new SpawnTotem( this.spawnTotem = new SpawnTotem(

View File

@@ -11,6 +11,7 @@ import com.willfp.ecobosses.bosses.tick.tickers.BossBarTicker;
import com.willfp.ecobosses.bosses.tick.tickers.DeathTimeTicker; import com.willfp.ecobosses.bosses.tick.tickers.DeathTimeTicker;
import com.willfp.ecobosses.bosses.tick.tickers.NamePlaceholderTicker; import com.willfp.ecobosses.bosses.tick.tickers.NamePlaceholderTicker;
import com.willfp.ecobosses.bosses.tick.tickers.TargetTicker; import com.willfp.ecobosses.bosses.tick.tickers.TargetTicker;
import com.willfp.ecobosses.bosses.util.obj.EquipmentPiece;
import com.willfp.ecobosses.bosses.util.obj.OptionedSound; import com.willfp.ecobosses.bosses.util.obj.OptionedSound;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -20,6 +21,8 @@ import org.bukkit.attribute.AttributeModifier;
import org.bukkit.boss.BarFlag; import org.bukkit.boss.BarFlag;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
@@ -109,6 +112,35 @@ public class LivingEcoBoss extends PluginDependent<EcoPlugin> {
entity.setCustomName(boss.getDisplayName()); entity.setCustomName(boss.getDisplayName());
entity.setCustomNameVisible(true); entity.setCustomNameVisible(true);
EntityEquipment equipment = entity.getEquipment();
if (equipment != null) {
EquipmentPiece head = boss.getEquipment().get(EquipmentSlot.HEAD);
EquipmentPiece chest = boss.getEquipment().get(EquipmentSlot.CHEST);
EquipmentPiece legs = boss.getEquipment().get(EquipmentSlot.LEGS);
EquipmentPiece boots = boss.getEquipment().get(EquipmentSlot.FEET);
EquipmentPiece hand = boss.getEquipment().get(EquipmentSlot.HAND);
if (head != null) {
equipment.setHelmet(head.itemStack(), true);
equipment.setHelmetDropChance((float) head.chance());
}
if (chest != null) {
equipment.setChestplate(chest.itemStack(), true);
equipment.setChestplateDropChance((float) chest.chance());
}
if (legs != null) {
equipment.setLeggings(legs.itemStack(), true);
equipment.setLeggingsDropChance((float) legs.chance());
}
if (boots != null) {
equipment.setBoots(boots.itemStack(), true);
equipment.setBootsDropChance((float) boots.chance());
}
if (hand != null) {
equipment.setItemInMainHand(hand.itemStack(), true);
equipment.setItemInMainHandDropChance((float) hand.chance());
}
}
AttributeInstance movementSpeed = entity.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED); AttributeInstance movementSpeed = entity.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
assert movementSpeed != null; assert movementSpeed != null;
movementSpeed.addModifier(new AttributeModifier(entity.getUniqueId(), "ecobosses-movement-multiplier", boss.getMovementSpeedMultiplier() - 1, AttributeModifier.Operation.MULTIPLY_SCALAR_1)); movementSpeed.addModifier(new AttributeModifier(entity.getUniqueId(), "ecobosses-movement-multiplier", boss.getMovementSpeedMultiplier() - 1, AttributeModifier.Operation.MULTIPLY_SCALAR_1));

View File

@@ -0,0 +1,8 @@
package com.willfp.ecobosses.bosses.util.obj;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public record EquipmentPiece(@NotNull ItemStack itemStack,
double chance) {
}

View File

@@ -91,6 +91,23 @@ effects:
- "give-potion-effect:wither:4:200:10" - "give-potion-effect:wither:4:200:10"
- "give-potion-effect:hunger:10:600:10" - "give-potion-effect:hunger:10:600:10"
gear:
helmet:
item: ""
chance: 100
chestplate:
item: ""
chance: 100
leggings:
item: ""
chance: 100
boots:
item: ""
chance: 100
hand:
item: ""
chance: 100
defence: defence:
immunities: immunities:
explosion: false explosion: false

View File

@@ -94,6 +94,23 @@ effects:
- "give-potion-effect:blindness:1:40:20" - "give-potion-effect:blindness:1:40:20"
- "teleport:7:15" - "teleport:7:15"
gear:
helmet:
item: ""
chance: 100
chestplate:
item: ""
chance: 100
leggings:
item: ""
chance: 100
boots:
item: ""
chance: 100
hand:
item: ""
chance: 100
defence: defence:
immunities: immunities:
explosion: true explosion: true

View File

@@ -95,6 +95,23 @@ effects:
- "give-potion-effect:slow:5:100:20" - "give-potion-effect:slow:5:100:20"
- "give-potion-effect:levitation:3:50:10" - "give-potion-effect:levitation:3:50:10"
gear:
helmet:
item: ""
chance: 100
chestplate:
item: ""
chance: 100
leggings:
item: ""
chance: 100
boots:
item: ""
chance: 100
hand:
item: ""
chance: 100
defence: defence:
immunities: immunities:
explosion: true explosion: true

View File

@@ -95,6 +95,23 @@ effects:
- "give-potion-effect:hunger:5:400:10" - "give-potion-effect:hunger:5:400:10"
- "give-potion-effect:slow_digging:3:40:10" - "give-potion-effect:slow_digging:3:40:10"
gear:
helmet:
item: ""
chance: 100
chestplate:
item: ""
chance: 100
leggings:
item: ""
chance: 100
boots:
item: ""
chance: 100
hand:
item: ""
chance: 100
defence: defence:
immunities: immunities:
explosion: false explosion: false