From f10084d523efcea3e6537cebe39c07d0091a6aa6 Mon Sep 17 00:00:00 2001 From: mani1232 Date: Tue, 27 Sep 2022 11:04:39 +0200 Subject: [PATCH 1/6] Custom default animation feature --- .../src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt | 2 +- .../src/main/kotlin/com/willfp/ecopets/pets/Pet.kt | 2 ++ .../willfp/ecopets/pets/entity/ModelEnginePetEntity.kt | 8 +++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt index 7588773..1642195 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt @@ -54,7 +54,7 @@ class EcoPetsPlugin : LibReforgePlugin() { return listOf( IntegrationLoader("ModelEngine") { PetEntity.registerPetEntity("modelengine") { pet, id -> - ModelEnginePetEntity(pet, id) + ModelEnginePetEntity(pet, id, pet.entityAnimation) } } ) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt index 45edae6..db12756 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt @@ -114,6 +114,8 @@ class Pet( val entityTexture = config.getString("entity-texture") + val entityAnimation = config.getString("default-animation") + private val levelXpRequirements = listOf(0) + config.getInts("level-xp-requirements") val maxLevel = levelXpRequirements.size diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt index 133074c..2636480 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt @@ -7,12 +7,18 @@ import org.bukkit.entity.ArmorStand class ModelEnginePetEntity( pet: Pet, - private val modelID: String + private val modelID: String, + private val animationString: String, ) : PetEntity(pet) { override fun spawn(location: Location): ArmorStand { val stand = emptyArmorStandAt(location, pet) val model = ModelEngineAPI.createActiveModel(modelID) + val animationHandler = model.animationHandler; + val modelAnimation = animationHandler.getAnimation(animationString); + + if (modelAnimation != null) animationHandler.playAnimation(modelAnimation, true); + val modelled = ModelEngineAPI.createModeledEntity(stand) modelled.addModel(model, true) From c67eee5af97eb594b8acadeb58fe2ad3737400b2 Mon Sep 17 00:00:00 2001 From: mani1232 Date: Tue, 27 Sep 2022 11:07:38 +0200 Subject: [PATCH 2/6] small changes --- .../com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt index 2636480..9a7e552 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt @@ -15,9 +15,9 @@ class ModelEnginePetEntity( val model = ModelEngineAPI.createActiveModel(modelID) val animationHandler = model.animationHandler; - val modelAnimation = animationHandler.getAnimation(animationString); + val animationProperty = animationHandler.getAnimation(animationString); - if (modelAnimation != null) animationHandler.playAnimation(modelAnimation, true); + if (animationProperty != null) animationHandler.playAnimation(animationProperty, true); val modelled = ModelEngineAPI.createModeledEntity(stand) modelled.addModel(model, true) From f1b5bac9cd489ad3afb6f571391b19ca41be7445 Mon Sep 17 00:00:00 2001 From: mani1232 Date: Tue, 27 Sep 2022 11:29:40 +0200 Subject: [PATCH 3/6] add else if model animation not found --- .../com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt index 9a7e552..1f68128 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt @@ -1,6 +1,7 @@ package com.willfp.ecopets.pets.entity import com.ticxo.modelengine.api.ModelEngineAPI +import com.willfp.ecopets.EcoPetsPlugin import com.willfp.ecopets.pets.Pet import org.bukkit.Location import org.bukkit.entity.ArmorStand @@ -17,7 +18,9 @@ class ModelEnginePetEntity( val animationHandler = model.animationHandler; val animationProperty = animationHandler.getAnimation(animationString); - if (animationProperty != null) animationHandler.playAnimation(animationProperty, true); + if (animationProperty != null) { + animationHandler.playAnimation(animationProperty, true) + } else { EcoPetsPlugin.instance.logger.warning("$animationString not found in model $modelID") } val modelled = ModelEngineAPI.createModeledEntity(stand) modelled.addModel(model, true) From db3120f1dec4fc89e39c6dc7dc0373217946563a Mon Sep 17 00:00:00 2001 From: mani1232 Date: Tue, 27 Sep 2022 11:50:18 +0200 Subject: [PATCH 4/6] add default animation walk if not set --- .../src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt | 2 +- .../src/main/kotlin/com/willfp/ecopets/pets/Pet.kt | 2 +- .../com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt | 6 +++--- .../main/kotlin/com/willfp/ecopets/pets/entity/PetEntity.kt | 4 ++++ 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt index 1642195..7588773 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt @@ -54,7 +54,7 @@ class EcoPetsPlugin : LibReforgePlugin() { return listOf( IntegrationLoader("ModelEngine") { PetEntity.registerPetEntity("modelengine") { pet, id -> - ModelEnginePetEntity(pet, id, pet.entityAnimation) + ModelEnginePetEntity(pet, id) } } ) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt index db12756..685b2ce 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt @@ -114,7 +114,7 @@ class Pet( val entityTexture = config.getString("entity-texture") - val entityAnimation = config.getString("default-animation") + var entityAnimation = config.getStringOrNull("default-animation") private val levelXpRequirements = listOf(0) + config.getInts("level-xp-requirements") diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt index 1f68128..4052bf1 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt @@ -9,18 +9,18 @@ import org.bukkit.entity.ArmorStand class ModelEnginePetEntity( pet: Pet, private val modelID: String, - private val animationString: String, ) : PetEntity(pet) { override fun spawn(location: Location): ArmorStand { val stand = emptyArmorStandAt(location, pet) + val entityAnimation = pet.entityAnimation; val model = ModelEngineAPI.createActiveModel(modelID) val animationHandler = model.animationHandler; - val animationProperty = animationHandler.getAnimation(animationString); + val animationProperty = animationHandler.getAnimation(entityAnimation); if (animationProperty != null) { animationHandler.playAnimation(animationProperty, true) - } else { EcoPetsPlugin.instance.logger.warning("$animationString not found in model $modelID") } + } else { EcoPetsPlugin.instance.logger.warning("$entityAnimation not found in model $modelID") } val modelled = ModelEngineAPI.createModeledEntity(stand) modelled.addModel(model, true) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/PetEntity.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/PetEntity.kt index 058952c..9d2724c 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/PetEntity.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/PetEntity.kt @@ -27,6 +27,10 @@ abstract class PetEntity( return SkullPetEntity(pet) } + if (pet.entityAnimation == null){ + pet.entityAnimation = "walk"; + } + val id = texture.split(":")[0] val parse = registrations[id] ?: return SkullPetEntity(pet) return parse(pet, texture.removePrefix("$id:")) From 571b39f0a72294234b5773680c722024bb6d5a01 Mon Sep 17 00:00:00 2001 From: mani1232 Date: Tue, 27 Sep 2022 11:54:40 +0200 Subject: [PATCH 5/6] refactor default animation walk if not set --- .../src/main/kotlin/com/willfp/ecopets/pets/Pet.kt | 2 +- .../willfp/ecopets/pets/entity/ModelEnginePetEntity.kt | 10 +++++++++- .../kotlin/com/willfp/ecopets/pets/entity/PetEntity.kt | 4 ---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt index 685b2ce..db12756 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt @@ -114,7 +114,7 @@ class Pet( val entityTexture = config.getString("entity-texture") - var entityAnimation = config.getStringOrNull("default-animation") + val entityAnimation = config.getString("default-animation") private val levelXpRequirements = listOf(0) + config.getInts("level-xp-requirements") diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt index 4052bf1..be71e89 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt @@ -20,7 +20,15 @@ class ModelEnginePetEntity( if (animationProperty != null) { animationHandler.playAnimation(animationProperty, true) - } else { EcoPetsPlugin.instance.logger.warning("$entityAnimation not found in model $modelID") } + } else { + EcoPetsPlugin.instance.logger.warning("$entityAnimation not found in model $modelID, im use walk animation") + val animationPropertyWalk = animationHandler.getAnimation("walk"); + if (animationPropertyWalk != null) { + animationHandler.playAnimation(animationPropertyWalk, true) + } else { + EcoPetsPlugin.instance.logger.warning("walk animation not found in $modelID, you have any animation!?") + } + } val modelled = ModelEngineAPI.createModeledEntity(stand) modelled.addModel(model, true) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/PetEntity.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/PetEntity.kt index 9d2724c..058952c 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/PetEntity.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/PetEntity.kt @@ -27,10 +27,6 @@ abstract class PetEntity( return SkullPetEntity(pet) } - if (pet.entityAnimation == null){ - pet.entityAnimation = "walk"; - } - val id = texture.split(":")[0] val parse = registrations[id] ?: return SkullPetEntity(pet) return parse(pet, texture.removePrefix("$id:")) From b1fcadc46ddcbd3ba574f1b93533bc4ae9ee6bee Mon Sep 17 00:00:00 2001 From: mani1232 Date: Tue, 27 Sep 2022 15:31:24 +0200 Subject: [PATCH 6/6] remove , and ; --- .../willfp/ecopets/pets/entity/ModelEnginePetEntity.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt index be71e89..5e39d5b 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt @@ -8,21 +8,21 @@ import org.bukkit.entity.ArmorStand class ModelEnginePetEntity( pet: Pet, - private val modelID: String, + private val modelID: String ) : PetEntity(pet) { override fun spawn(location: Location): ArmorStand { val stand = emptyArmorStandAt(location, pet) - val entityAnimation = pet.entityAnimation; + val entityAnimation = pet.entityAnimation val model = ModelEngineAPI.createActiveModel(modelID) - val animationHandler = model.animationHandler; - val animationProperty = animationHandler.getAnimation(entityAnimation); + val animationHandler = model.animationHandler + val animationProperty = animationHandler.getAnimation(entityAnimation) if (animationProperty != null) { animationHandler.playAnimation(animationProperty, true) } else { EcoPetsPlugin.instance.logger.warning("$entityAnimation not found in model $modelID, im use walk animation") - val animationPropertyWalk = animationHandler.getAnimation("walk"); + val animationPropertyWalk = animationHandler.getAnimation("walk") if (animationPropertyWalk != null) { animationHandler.playAnimation(animationPropertyWalk, true) } else {