1.0.1
Added Cats
This commit is contained in:
1 parent
5965a815c2
commit
cd6f1a7784
3 files changed
+104
No files matched your search
@@ -0,0 +1,100 @@
|
|||||||
|
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.Cat;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CatDescriptor implements MobDescriptor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supports(LivingEntity entity) {
|
||||||
|
return entity instanceof Cat;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CaptureResult beforeCapture(LivingEntity entity, Player player) {
|
||||||
|
return CaptureResult.allowed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDisplayName(LivingEntity entity) {
|
||||||
|
return MobAgeUtil.getAgePrefix(entity) + "Cat";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MobAttribute> getAttributes(LivingEntity entity) {
|
||||||
|
|
||||||
|
Cat cat = (Cat) entity;
|
||||||
|
|
||||||
|
return List.of(
|
||||||
|
new MobAttribute(
|
||||||
|
"Variant",
|
||||||
|
MobDescriptionFormatter.formatEnumName(
|
||||||
|
cat.getCatType().getKey().getKey()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
Cat.Type variant = Cat.Type.TABBY;
|
||||||
|
|
||||||
|
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 Cat");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.equals("Variant:") && i + 1 < lore.size()) {
|
||||||
|
variant = getVariant(plain.serialize(lore.get(i + 1)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Cat cat = (Cat) location.getWorld().spawnEntity(
|
||||||
|
location,
|
||||||
|
org.bukkit.entity.EntityType.CAT
|
||||||
|
);
|
||||||
|
|
||||||
|
if (baby) {
|
||||||
|
cat.setBaby();
|
||||||
|
} else {
|
||||||
|
cat.setAdult();
|
||||||
|
}
|
||||||
|
|
||||||
|
cat.setCatType(variant);
|
||||||
|
cat.setTamed(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Cat.Type getVariant(String variant) {
|
||||||
|
|
||||||
|
return switch (variant) {
|
||||||
|
case "Black" -> Cat.Type.BLACK;
|
||||||
|
case "British Shorthair" -> Cat.Type.BRITISH_SHORTHAIR;
|
||||||
|
case "Calico" -> Cat.Type.CALICO;
|
||||||
|
case "Jellie" -> Cat.Type.JELLIE;
|
||||||
|
case "Persian" -> Cat.Type.PERSIAN;
|
||||||
|
case "Ragdoll" -> Cat.Type.RAGDOLL;
|
||||||
|
case "Red" -> Cat.Type.RED;
|
||||||
|
case "Siamese" -> Cat.Type.SIAMESE;
|
||||||
|
case "Tabby" -> Cat.Type.TABBY;
|
||||||
|
case "All Black" -> Cat.Type.ALL_BLACK;
|
||||||
|
case "White" -> Cat.Type.WHITE;
|
||||||
|
default -> Cat.Type.TABBY;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -8,6 +8,7 @@ public final class MobDescriptorRegistry {
|
|||||||
|
|
||||||
private static final List<MobDescriptor> DESCRIPTORS = List.of(
|
private static final List<MobDescriptor> DESCRIPTORS = List.of(
|
||||||
new BeeDescriptor(),
|
new BeeDescriptor(),
|
||||||
|
new CatDescriptor(),
|
||||||
new CaveSpiderDescriptor(),
|
new CaveSpiderDescriptor(),
|
||||||
new ChickenDescriptor(),
|
new ChickenDescriptor(),
|
||||||
new CowDescriptor(),
|
new CowDescriptor(),
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ public class MobReleaseListener implements Listener {
|
|||||||
case "Bee", "Baby Bee" ->
|
case "Bee", "Baby Bee" ->
|
||||||
new BeeDescriptor().release(location, lore);
|
new BeeDescriptor().release(location, lore);
|
||||||
|
|
||||||
|
case "Cat", "Baby Cat" ->
|
||||||
|
new CatDescriptor().release(location, lore);
|
||||||
|
|
||||||
case "Cave Spider" ->
|
case "Cave Spider" ->
|
||||||
new CaveSpiderDescriptor().release(location, lore);
|
new CaveSpiderDescriptor().release(location, lore);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user