1.0.4
Added: - Wolf Support
This commit is contained in:
1 parent
935c8c2530
commit
3c31fd05b7
4 files changed
+118
-1
No files matched your search
+1
-1
@@ -5,7 +5,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "com.rsscripting"
|
group = "com.rsscripting"
|
||||||
version = "1.0.3"
|
version = "1.0.4"
|
||||||
val pluginVersion = version.toString()
|
val pluginVersion = version.toString()
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
|||||||
+1
@@ -21,6 +21,7 @@ public final class MobDescriptorRegistry {
|
|||||||
new SheepDescriptor(),
|
new SheepDescriptor(),
|
||||||
new SpiderDescriptor(),
|
new SpiderDescriptor(),
|
||||||
new VillagerDescriptor(),
|
new VillagerDescriptor(),
|
||||||
|
new WolfDescriptor(),
|
||||||
new ZombieDescriptor()
|
new ZombieDescriptor()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
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 com.rsscripting.mobcage.util.MobHealthUtil;
|
||||||
|
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.Player;
|
||||||
|
import org.bukkit.entity.Wolf;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class WolfDescriptor implements MobDescriptor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supports(LivingEntity entity) {
|
||||||
|
return entity instanceof Wolf;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CaptureResult beforeCapture(LivingEntity entity, Player player) {
|
||||||
|
|
||||||
|
CaptureResult result = MobHealthUtil.validateFullHealth(entity);
|
||||||
|
|
||||||
|
if (!result.isAllowed()) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
MobAgeUtil.normalize(entity);
|
||||||
|
|
||||||
|
return CaptureResult.allowed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDisplayName(LivingEntity entity) {
|
||||||
|
return MobAgeUtil.getAgePrefix(entity) + "Wolf";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MobAttribute> getAttributes(LivingEntity entity) {
|
||||||
|
|
||||||
|
Wolf wolf = (Wolf) entity;
|
||||||
|
|
||||||
|
return List.of(
|
||||||
|
new MobAttribute(
|
||||||
|
"Variant",
|
||||||
|
MobDescriptionFormatter.formatEnumName(
|
||||||
|
wolf.getVariant().getKey().getKey()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void release(Location location, List<Component> lore) {
|
||||||
|
|
||||||
|
PlainTextComponentSerializer plain =
|
||||||
|
PlainTextComponentSerializer.plainText();
|
||||||
|
|
||||||
|
boolean baby = false;
|
||||||
|
Wolf.Variant variant = Wolf.Variant.PALE;
|
||||||
|
|
||||||
|
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 Wolf");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.equals("Variant:") && i + 1 < lore.size()) {
|
||||||
|
variant = getVariant(
|
||||||
|
plain.serialize(lore.get(i + 1))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Wolf wolf = (Wolf) location.getWorld().spawnEntity(
|
||||||
|
location,
|
||||||
|
EntityType.WOLF
|
||||||
|
);
|
||||||
|
|
||||||
|
if (baby) {
|
||||||
|
wolf.setBaby();
|
||||||
|
} else {
|
||||||
|
wolf.setAdult();
|
||||||
|
}
|
||||||
|
|
||||||
|
wolf.setVariant(variant);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Wolf.Variant getVariant(String value) {
|
||||||
|
|
||||||
|
return switch (value) {
|
||||||
|
case "Ashen" -> Wolf.Variant.ASHEN;
|
||||||
|
case "Black" -> Wolf.Variant.BLACK;
|
||||||
|
case "Chestnut" -> Wolf.Variant.CHESTNUT;
|
||||||
|
case "Pale" -> Wolf.Variant.PALE;
|
||||||
|
case "Rusty" -> Wolf.Variant.RUSTY;
|
||||||
|
case "Snowy" -> Wolf.Variant.SNOWY;
|
||||||
|
case "Spotted" -> Wolf.Variant.SPOTTED;
|
||||||
|
case "Striped" -> Wolf.Variant.STRIPED;
|
||||||
|
case "Woods" -> Wolf.Variant.WOODS;
|
||||||
|
default -> Wolf.Variant.PALE;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -103,6 +103,9 @@ public class MobReleaseListener implements Listener {
|
|||||||
case "Villager", "Baby Villager" ->
|
case "Villager", "Baby Villager" ->
|
||||||
new VillagerDescriptor().release(location, lore);
|
new VillagerDescriptor().release(location, lore);
|
||||||
|
|
||||||
|
case "Wolf", "Baby Wolf" ->
|
||||||
|
new WolfDescriptor().release(location, lore);
|
||||||
|
|
||||||
case "Zombie", "Baby Zombie" ->
|
case "Zombie", "Baby Zombie" ->
|
||||||
new ZombieDescriptor().release(location, lore);
|
new ZombieDescriptor().release(location, lore);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user