From 332fd55f0b5b2eaafd3e90f13a5b2c5b246b6e4b Mon Sep 17 00:00:00 2001 From: TomTom <93038247+AverageGithub@users.noreply.github.com> Date: Mon, 28 Nov 2022 16:04:50 +0100 Subject: [PATCH 1/3] Fix stuff --- eco-core/core-plugin/build.gradle | 2 +- .../ecopets/commands/CommandActivate.kt | 2 +- .../com/willfp/ecopets/pets/PetDisplay.kt | 32 +++++++++++-------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/eco-core/core-plugin/build.gradle b/eco-core/core-plugin/build.gradle index 22ea230..b087925 100644 --- a/eco-core/core-plugin/build.gradle +++ b/eco-core/core-plugin/build.gradle @@ -7,7 +7,7 @@ dependencies { compileOnly 'net.kyori:adventure-api:4.10.1' compileOnly 'net.essentialsx:EssentialsX:2.19.0' compileOnly 'com.github.ben-manes.caffeine:caffeine:3.0.6' - compileOnly 'com.ticxo.modelengine:api:R3.0.0' + compileOnly 'com.ticxo.modelengine:api:R3.0.1' } build.dependsOn publishToMavenLocal diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandActivate.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandActivate.kt index 963112a..4ad60ea 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandActivate.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandActivate.kt @@ -53,7 +53,7 @@ class CommandActivate(plugin: EcoPlugin) : Subcommand(plugin, "activate", "ecope if (args.size == 1) { StringUtil.copyPartialMatches( - args[1], + args[0], Pets.values().filter { sender.hasPet(it) }.map { it.id }, completions ) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/PetDisplay.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/PetDisplay.kt index f291752..ebfa13a 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/PetDisplay.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/PetDisplay.kt @@ -9,7 +9,9 @@ import org.bukkit.entity.ArmorStand import org.bukkit.entity.Player import org.bukkit.event.EventHandler import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerChangedWorldEvent import org.bukkit.event.player.PlayerQuitEvent +import org.bukkit.event.player.PlayerTeleportEvent import java.util.UUID import kotlin.math.PI import kotlin.math.abs @@ -45,17 +47,7 @@ class PetDisplay( location.y += NumberUtils.fastSin(tick / (2 * PI) * 0.5) * 0.15 if (location.world != null) { - try { - stand.teleport(location) - } catch (_: Throwable) { - /* - For anyone reading - I KNOW TO NEVER CATCH THROWABLE - but NMS is really stupid and does this sometimes: - java.lang.Throwable: null - at net.minecraft.world.entity.Entity.teleportTo(Entity.java:3336) ~[paper-1.19.2.jar:git-Paper-186] - so I guess that's what has to be done. Not sure what the actual cause is. - */ - } + stand.teleport(location) } if (!pet.entityTexture.contains(":")) { @@ -117,10 +109,24 @@ class PetDisplay( trackedEntities.clear() } + private fun remove(player: Player) { + trackedEntities[player.uniqueId]?.stand?.remove() + trackedEntities.remove(player.uniqueId) + } + @EventHandler fun onLeave(event: PlayerQuitEvent) { - trackedEntities[event.player.uniqueId]?.stand?.remove() - trackedEntities.remove(event.player.uniqueId) + remove(event.player) + } + + @EventHandler + fun onTeleport(event: PlayerTeleportEvent) { + remove(event.player) + } + + @EventHandler + fun onWorldChange(event: PlayerChangedWorldEvent) { + remove(event.player) } private data class PetArmorStand( From 56ddfeca3925da99729d9f0b06232d4e24ec5217 Mon Sep 17 00:00:00 2001 From: TomTom <93038247+AverageGithub@users.noreply.github.com> Date: Tue, 29 Nov 2022 16:11:04 +0100 Subject: [PATCH 2/3] Add being able to disable pet entities --- .../src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt | 4 ++++ eco-core/core-plugin/src/main/resources/config.yml | 1 + 2 files changed, 5 insertions(+) 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 2dc861b..0df2e69 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 @@ -41,6 +41,10 @@ class EcoPetsPlugin : LibReforgePlugin() { } override fun handleReloadAdditional() { + if (this.configYml.getBool("pet-entity.enabled")) { + return + } + this.scheduler.runTimer(1, 1) { petDisplay.tickAll() } diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index f76e15c..a69983e 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -217,6 +217,7 @@ level-gui: custom-slots: [ ] pet-entity: + enabled: true # If you disable this, there will be no floating pets name: "%player%&f's %pet%&f (Lvl. %level%)" level-up: From f44ca8a7e3630ebb30ed1084de46d7283ee2228c Mon Sep 17 00:00:00 2001 From: TomTom <93038247+AverageGithub@users.noreply.github.com> Date: Tue, 29 Nov 2022 16:19:51 +0100 Subject: [PATCH 3/3] Fix bald --- .../src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0df2e69..8b0b128 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 @@ -41,7 +41,7 @@ class EcoPetsPlugin : LibReforgePlugin() { } override fun handleReloadAdditional() { - if (this.configYml.getBool("pet-entity.enabled")) { + if (!this.configYml.getBool("pet-entity.enabled")) { return }