1.0.1
Added Rabbits
This commit is contained in:
1 parent
cd6f1a7784
commit
53739351ad
3 files changed
+102
No files matched your search
+1
@@ -15,6 +15,7 @@ public final class MobDescriptorRegistry {
|
||||
new DonkeyDescriptor(),
|
||||
new HorseDescriptor(),
|
||||
new PigDescriptor(),
|
||||
new RabbitDescriptor(),
|
||||
new SheepDescriptor(),
|
||||
new SpiderDescriptor(),
|
||||
new VillagerDescriptor(),
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
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 org.bukkit.Location;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Rabbit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RabbitDescriptor implements MobDescriptor {
|
||||
|
||||
@Override
|
||||
public boolean supports(LivingEntity entity) {
|
||||
return entity instanceof Rabbit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CaptureResult beforeCapture(LivingEntity entity, Player player) {
|
||||
return CaptureResult.allowed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName(LivingEntity entity) {
|
||||
return MobAgeUtil.getAgePrefix(entity) + "Rabbit";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MobAttribute> getAttributes(LivingEntity entity) {
|
||||
|
||||
Rabbit rabbit = (Rabbit) entity;
|
||||
|
||||
return List.of(
|
||||
new MobAttribute(
|
||||
"Variant",
|
||||
MobDescriptionFormatter.formatEnumName(
|
||||
rabbit.getRabbitType().toString()
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release(
|
||||
Location location,
|
||||
List<net.kyori.adventure.text.Component> lore
|
||||
) {
|
||||
|
||||
net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer plain =
|
||||
net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer.plainText();
|
||||
|
||||
boolean baby = false;
|
||||
Rabbit.Type variant = Rabbit.Type.BROWN;
|
||||
|
||||
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 Rabbit");
|
||||
}
|
||||
|
||||
if (line.equals("Variant:") && i + 1 < lore.size()) {
|
||||
variant = getVariant(plain.serialize(lore.get(i + 1)));
|
||||
}
|
||||
}
|
||||
|
||||
Rabbit rabbit = (Rabbit) location.getWorld().spawnEntity(
|
||||
location,
|
||||
org.bukkit.entity.EntityType.RABBIT
|
||||
);
|
||||
|
||||
if (baby) {
|
||||
rabbit.setBaby();
|
||||
} else {
|
||||
rabbit.setAdult();
|
||||
}
|
||||
|
||||
rabbit.setRabbitType(variant);
|
||||
}
|
||||
|
||||
private Rabbit.Type getVariant(String variant) {
|
||||
|
||||
return switch (variant) {
|
||||
case "Brown" -> Rabbit.Type.BROWN;
|
||||
case "White" -> Rabbit.Type.WHITE;
|
||||
case "Black" -> Rabbit.Type.BLACK;
|
||||
case "Black And White" -> Rabbit.Type.BLACK_AND_WHITE;
|
||||
case "Gold" -> Rabbit.Type.GOLD;
|
||||
case "Salt And Pepper" -> Rabbit.Type.SALT_AND_PEPPER;
|
||||
case "The Killer Bunny" -> Rabbit.Type.THE_KILLER_BUNNY;
|
||||
default -> Rabbit.Type.BROWN;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,9 @@ public class MobReleaseListener implements Listener {
|
||||
case "Pig", "Baby Pig" ->
|
||||
new PigDescriptor().release(location, lore);
|
||||
|
||||
case "Rabbit", "Baby Rabbit" ->
|
||||
new RabbitDescriptor().release(location, lore);
|
||||
|
||||
case "Sheep", "Baby Sheep" ->
|
||||
new SheepDescriptor().release(location, lore);
|
||||
|
||||
|
||||
Reference in new issue
Block a user