From ee2cda7a971ffaa91dcf857cad4962d6bbe1f533 Mon Sep 17 00:00:00 2001 From: TomTom <93038247+AverageGithub@users.noreply.github.com> Date: Sat, 6 Jul 2024 14:42:44 +0200 Subject: [PATCH] performance improvement, reset cmd --- .../axminions/api/config/Messages.kt | 2 +- .../axminions/commands/AxMinionsCommand.kt | 58 ++++--------------- .../axminions/minions/Minion.kt | 7 ++- common/src/main/resources/messages.yml | 2 +- 4 files changed, 17 insertions(+), 52 deletions(-) diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/config/Messages.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/config/Messages.kt index c279f78..e92134a 100644 --- a/api/src/main/kotlin/com/artillexstudios/axminions/api/config/Messages.kt +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/config/Messages.kt @@ -78,7 +78,7 @@ class Messages(file: File, stream: InputStream) { @JvmStatic fun UPGRADE_FAIL() = AxMinionsAPI.INSTANCE.getMessages().get("upgrades.fail") @JvmStatic - fun RECALC() = AxMinionsAPI.INSTANCE.getMessages().get("recalc") + fun RESET() = AxMinionsAPI.INSTANCE.getMessages().get("reset") @JvmStatic fun NOT_ON_ISLAND() = AxMinionsAPI.INSTANCE.getMessages().get("not-on-island") @JvmStatic diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/commands/AxMinionsCommand.kt b/common/src/main/kotlin/com/artillexstudios/axminions/commands/AxMinionsCommand.kt index e0863ec..64c612d 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/commands/AxMinionsCommand.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/commands/AxMinionsCommand.kt @@ -136,57 +136,19 @@ class AxMinionsCommand { ) } - @Subcommand("recalc") - @CommandPermission("axminions.command.recalc") - fun recalc(player: Player) { - val islandId = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration()?.getIslandAt(player.location) - if (islandId == null) { - player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.NOT_ON_ISLAND())) - return - } - + @Subcommand("reset") + @CommandPermission("axminions.command.reset") + fun reset(sender: CommandSender, offlinePlayer: OfflinePlayer) { + val minions = AxMinionsAPI.INSTANCE.getMinions() + val ownerUUID = offlinePlayer.uniqueId AxMinionsPlugin.dataQueue.submit { - var original = 0 - if (islandId.isNotBlank()) { - original = AxMinionsAPI.INSTANCE.getDataHandler().getIsland(islandId) - - AxMinionsPlugin.dataHandler.islandReset(islandId) - } - - val integration = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration() - if (integration is SuperiorSkyBlock2Integration) { - Scheduler.get().run { - val island = SuperiorSkyblockAPI.getIslandAt(player.location) ?: return@run - var counter = 0 - val minions = Minions.getMinions() - val futures = arrayListOf>() - - Environment.entries.forEach { entry -> - try { - island.getAllChunksAsync(entry, true) { }.forEach { future -> - futures.add(future) - future.thenAccept { chunk -> - minions.forEach { minion -> - val ch = minion.getLocation().chunk - if (ch.x == chunk.x && ch.z == chunk.z && ch.world == chunk.world) { - AxMinionsPlugin.dataQueue.submit { - AxMinionsPlugin.dataHandler.islandPlace(islandId) - } - counter++ - } - } - } - } - } catch (_: NullPointerException) { - // SuperiorSkyBlock api does it this way aswell - } - } - - CompletableFuture.allOf(*futures.toTypedArray()).thenRun { - player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.RECALC(), Placeholder.unparsed("from", original.toString()), Placeholder.unparsed("to", counter.toString()))) - } + minions.fastFor { + if (it.getOwnerUUID() == ownerUUID) { + it.remove() } } + + sender.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.RESET(), Placeholder.unparsed("player", offlinePlayer.name ?: "---"))) } } diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt index 5b0d9ae..26f43f3 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt @@ -94,6 +94,7 @@ class Minion( private var debugHologram: Hologram? = null val broken = AtomicBoolean(false) private var ownerOnline = false + private var unbreakable = false init { spawn() @@ -444,8 +445,10 @@ class Minion( if (this.tool?.type == Material.AIR) { entity.setItem(EquipmentSlot.MAIN_HAND, null) + unbreakable = false } else { entity.setItem(EquipmentSlot.MAIN_HAND, WrappedItemStack.wrap(tool.clone())) + unbreakable = notDurable.contains(tool.type) } if (save) { @@ -678,7 +681,7 @@ class Minion( val tool = tool ?: return val toolMeta = toolMeta as? Damageable ?: return - if (!tool.type.isAir && notDurable.contains(tool.type)) { + if (!tool.type.isAir && unbreakable) { return } @@ -745,7 +748,7 @@ class Minion( val tool = tool ?: return false val toolMeta = toolMeta as? Damageable ?: return false - if (!tool.type.isAir && notDurable.contains(tool.type)) { + if (!tool.type.isAir && unbreakable) { return true } diff --git a/common/src/main/resources/messages.yml b/common/src/main/resources/messages.yml index 4e0d163..af58c56 100644 --- a/common/src/main/resources/messages.yml +++ b/common/src/main/resources/messages.yml @@ -74,7 +74,7 @@ charge: tools: wrong-tool: "You can't place this item as the tool if this minion!" -recalc: "Recalculated island minion count! -> " +reset: "You have reset 's minion count!" not-on-island: "<#FF0000>You are currently not on an island!" slot-give: "You have given island minion slots!" slot-receive: "You were given new island minion slots! ( -> )"