Added Parrots
This commit is contained in:
BigPappa committed 2026-08-27 11:57:43 -05:00
1 parent 53739351ad
commit b0b8c2f5c0
4 files changed
+107 -1

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@ plugins {
} }
group = "com.rsscripting" group = "com.rsscripting"
version = "1.0.1" version = "1.0.2"
val pluginVersion = version.toString() val pluginVersion = version.toString()
repositories { repositories {
@@ -14,6 +14,7 @@ public final class MobDescriptorRegistry {
new CowDescriptor(), new CowDescriptor(),
new DonkeyDescriptor(), new DonkeyDescriptor(),
new HorseDescriptor(), new HorseDescriptor(),
new ParrotDescriptor(),
new PigDescriptor(), new PigDescriptor(),
new RabbitDescriptor(), new RabbitDescriptor(),
new SheepDescriptor(), new SheepDescriptor(),
@@ -0,0 +1,102 @@
package com.rsscripting.mobcage.description.descriptor;
import com.rsscripting.mobcage.description.CaptureResult;
import com.rsscripting.mobcage.description.MobAttribute;
import com.rsscripting.mobcage.description.MobDescriptionFormatter;
import com.rsscripting.mobcage.util.MobAgeUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Parrot;
import org.bukkit.entity.Player;
import java.util.List;
public class ParrotDescriptor implements MobDescriptor {
@Override
public boolean supports(LivingEntity entity) {
return entity instanceof Parrot;
}
@Override
public CaptureResult beforeCapture(LivingEntity entity, Player player) {
return CaptureResult.allowed();
}
@Override
public String getDisplayName(LivingEntity entity) {
return MobAgeUtil.getAgePrefix(entity) + "Parrot";
}
@Override
public List<MobAttribute> getAttributes(LivingEntity entity) {
Parrot parrot = (Parrot) entity;
return List.of(
new MobAttribute(
"Variant",
MobDescriptionFormatter.formatEnumName(
parrot.getVariant().toString()
)
)
);
}
@Override
public void release(Location location, List<Component> lore) {
PlainTextComponentSerializer plain =
PlainTextComponentSerializer.plainText();
boolean baby = false;
Parrot.Variant variant = Parrot.Variant.RED;
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 Parrot");
}
if (line.equals("Variant:") && i + 1 < lore.size()) {
variant = getVariant(
plain.serialize(lore.get(i + 1))
);
}
}
Parrot parrot = (Parrot) location.getWorld().spawnEntity(
location,
EntityType.PARROT
);
if (baby) {
parrot.setBaby();
} else {
parrot.setAdult();
}
parrot.setVariant(variant);
// We do not preserve taming or ownership.
parrot.setTamed(false);
}
private Parrot.Variant getVariant(String variant) {
return switch (variant) {
case "Blue" -> Parrot.Variant.BLUE;
case "Green" -> Parrot.Variant.GREEN;
case "Cyan" -> Parrot.Variant.CYAN;
case "Gray" -> Parrot.Variant.GRAY;
case "Red" -> Parrot.Variant.RED;
default -> Parrot.Variant.RED;
};
}
}
@@ -82,6 +82,9 @@ public class MobReleaseListener implements Listener {
case "Horse", "Baby Horse" -> case "Horse", "Baby Horse" ->
new HorseDescriptor().release(location, lore); new HorseDescriptor().release(location, lore);
case "Parrot", "Baby Parrot" ->
new ParrotDescriptor().release(location, lore);
case "Pig", "Baby Pig" -> case "Pig", "Baby Pig" ->
new PigDescriptor().release(location, lore); new PigDescriptor().release(location, lore);