Added Donkeys
This commit is contained in:
BigPappa committed 2026-08-13 20:39:10 -05:00
1 parent 182054771a
commit 5965a815c2
7 files changed
+177 -53

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@ plugins {
} }
group = "com.rsscripting" group = "com.rsscripting"
version = "1.0.0" version = "1.0.1"
val pluginVersion = version.toString() val pluginVersion = version.toString()
repositories { repositories {
@@ -0,0 +1,86 @@
package com.rsscripting.mobcage.description.descriptor;
import com.rsscripting.mobcage.description.CaptureResult;
import com.rsscripting.mobcage.description.MobAttribute;
import com.rsscripting.mobcage.util.MobAgeUtil;
import com.rsscripting.mobcage.util.MobHealthUtil;
import com.rsscripting.mobcage.MobCage;
import com.rsscripting.mobcage.util.MobEquipmentUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Location;
import org.bukkit.entity.Donkey;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.util.List;
public class DonkeyDescriptor implements MobDescriptor {
@Override
public boolean supports(LivingEntity entity) {
return entity instanceof Donkey;
}
@Override
public CaptureResult beforeCapture(LivingEntity entity, Player player) {
CaptureResult result = MobHealthUtil.validateFullHealth(entity);
if (!result.isAllowed()) {
return result;
}
MobAgeUtil.normalize(entity);
MobEquipmentUtil.handleEquipmentOnCapture(
MobCage.getInstance(),
entity,
player
);
return CaptureResult.allowed();
}
@Override
public String getDisplayName(LivingEntity entity) {
return MobAgeUtil.getAgePrefix(entity) + "Donkey";
}
@Override
public List<MobAttribute> getAttributes(LivingEntity entity) {
return List.of();
}
@Override
public void release(Location location, List<Component> lore) {
PlainTextComponentSerializer plain =
PlainTextComponentSerializer.plainText();
boolean baby = false;
for (int i = 0; i < lore.size(); i++) {
String line = plain.serialize(lore.get(i));
if (line.equals("Contains:") && i + 1 < lore.size()) {
baby = plain.serialize(lore.get(i + 1)).equals("Baby Donkey");
}
}
Donkey donkey = (Donkey) location.getWorld().spawnEntity(
location,
EntityType.DONKEY
);
if (baby) {
donkey.setBaby();
} else {
donkey.setAdult();
}
donkey.setPersistent(true);
}
}
@@ -13,7 +13,6 @@ import org.bukkit.Location;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Horse; import org.bukkit.entity.Horse;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.List; import java.util.List;
@@ -11,6 +11,7 @@ public final class MobDescriptorRegistry {
new CaveSpiderDescriptor(), new CaveSpiderDescriptor(),
new ChickenDescriptor(), new ChickenDescriptor(),
new CowDescriptor(), new CowDescriptor(),
new DonkeyDescriptor(),
new HorseDescriptor(), new HorseDescriptor(),
new PigDescriptor(), new PigDescriptor(),
new SheepDescriptor(), new SheepDescriptor(),
@@ -73,6 +73,9 @@ public class MobReleaseListener implements Listener {
case "Cow", "Baby Cow" -> case "Cow", "Baby Cow" ->
new CowDescriptor().release(location, lore); new CowDescriptor().release(location, lore);
case "Donkey", "Baby Donkey" ->
new DonkeyDescriptor().release(location, lore);
case "Horse", "Baby Horse" -> case "Horse", "Baby Horse" ->
new HorseDescriptor().release(location, lore); new HorseDescriptor().release(location, lore);
@@ -1,6 +1,8 @@
package com.rsscripting.mobcage.util; package com.rsscripting.mobcage.util;
import com.rsscripting.mobcage.MobCage; import com.rsscripting.mobcage.MobCage;
import org.bukkit.Material;
import org.bukkit.entity.ChestedHorse;
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.EntityEquipment;
@@ -16,55 +18,109 @@ public class MobEquipmentUtil {
EntityEquipment equipment = entity.getEquipment(); EntityEquipment equipment = entity.getEquipment();
if (equipment == null) { boolean hasEquipment =
return; hasItem(equipment != null ? equipment.getHelmet() : null) ||
hasItem(equipment != null ? equipment.getChestplate() : null) ||
hasItem(equipment != null ? equipment.getLeggings() : null) ||
hasItem(equipment != null ? equipment.getBoots() : null) ||
hasItem(equipment != null ? equipment.getItemInMainHand() : null) ||
hasItem(equipment != null ? equipment.getItemInOffHand() : null);
boolean hasChestedHorseEquipment = false;
if (entity instanceof ChestedHorse chestedHorse) {
if (hasItem(chestedHorse.getInventory().getSaddle())) {
hasChestedHorseEquipment = true;
}
if (chestedHorse.isCarryingChest()) {
hasChestedHorseEquipment = true;
for (ItemStack item : chestedHorse.getInventory().getStorageContents()) {
if (hasItem(item)) {
hasChestedHorseEquipment = true;
break;
}
}
}
} }
boolean hasEquipment = if (!hasEquipment && !hasChestedHorseEquipment) {
(equipment.getHelmet() != null && !equipment.getHelmet().getType().isAir()) ||
(equipment.getChestplate() != null && !equipment.getChestplate().getType().isAir()) ||
(equipment.getLeggings() != null && !equipment.getLeggings().getType().isAir()) ||
(equipment.getBoots() != null && !equipment.getBoots().getType().isAir()) ||
(equipment.getItemInMainHand() != null && !equipment.getItemInMainHand().getType().isAir()) ||
(equipment.getItemInOffHand() != null && !equipment.getItemInOffHand().getType().isAir());
if (!hasEquipment) {
return; return;
} }
boolean dropEquipment = boolean dropEquipment =
plugin.getConfig().getBoolean("drop-equip-on-capture"); plugin.getConfig().getBoolean("drop-equip-on-capture");
String message =
plugin.getConfig().getString("equipment-drop-message", "");
if (dropEquipment) { if (dropEquipment) {
dropItem(entity, equipment.getHelmet()); if (equipment != null) {
dropItem(entity, equipment.getChestplate()); dropItem(entity, equipment.getHelmet());
dropItem(entity, equipment.getLeggings()); dropItem(entity, equipment.getChestplate());
dropItem(entity, equipment.getBoots()); dropItem(entity, equipment.getLeggings());
dropItem(entity, equipment.getItemInMainHand()); dropItem(entity, equipment.getBoots());
dropItem(entity, equipment.getItemInOffHand()); dropItem(entity, equipment.getItemInMainHand());
dropItem(entity, equipment.getItemInOffHand());
}
if (entity instanceof ChestedHorse chestedHorse) {
if (chestedHorse.isCarryingChest()) {
for (ItemStack item : chestedHorse.getInventory().getStorageContents()) {
dropItem(entity, item);
}
// The chest itself is also a possession.
dropItem(
entity,
new ItemStack(Material.CHEST)
);
}
}
String message =
plugin.getConfig().getString("equipment-drop-message", "");
if (!message.isBlank()) {
player.sendRichMessage(message);
}
} else {
player.sendRichMessage(
"<yellow>The mob struggled during capture. During the struggle all of the mob's possessions were destroyed.</yellow>"
);
} }
equipment.setHelmet(null); if (equipment != null) {
equipment.setChestplate(null); equipment.setHelmet(null);
equipment.setLeggings(null); equipment.setChestplate(null);
equipment.setBoots(null); equipment.setLeggings(null);
equipment.setItemInMainHand(null); equipment.setBoots(null);
equipment.setItemInOffHand(null); equipment.setItemInMainHand(null);
equipment.setItemInOffHand(null);
if (!message.isBlank()) {
player.sendRichMessage(message);
} }
if (entity instanceof ChestedHorse chestedHorse) {
chestedHorse.getInventory().setSaddle(null);
if (chestedHorse.isCarryingChest()) {
chestedHorse.getInventory().clear();
chestedHorse.setCarryingChest(false);
}
}
}
private static boolean hasItem(ItemStack item) {
return item != null && !item.getType().isAir();
} }
private static void dropItem(LivingEntity entity, ItemStack item) { private static void dropItem(LivingEntity entity, ItemStack item) {
if (item == null || item.getType().isAir()) { if (!hasItem(item)) {
return; return;
} }
@@ -73,5 +129,4 @@ public class MobEquipmentUtil {
item.clone() item.clone()
); );
} }
} }
-20
View File
@@ -1,20 +0,0 @@
## 0.1.0
Beginning of Project (Empty Project)
## 0.1.1
Create MobCage with recipe finished.
Cage can be crafted
Iron Bars | Iron Bars | Iron Bars
Iron Bars | Iron Ingot | Iron Bars
Iron Bars | Iron Bars | Iron Bars
Cage cannot be placed.
## 0.1.2
Mob capture complete.
Named mobs cannot be captured.
Players cannot be captured.
Capture Mob Logic Finished
Release Mob Logic Finished
## 0.1.3
Added Horse