mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2024-11-28 12:35:38 +01:00
performance improvement, reset cmd
This commit is contained in:
parent
416db6867f
commit
ee2cda7a97
@ -78,7 +78,7 @@ class Messages(file: File, stream: InputStream) {
|
||||
@JvmStatic
|
||||
fun UPGRADE_FAIL() = AxMinionsAPI.INSTANCE.getMessages().get<String>("upgrades.fail")
|
||||
@JvmStatic
|
||||
fun RECALC() = AxMinionsAPI.INSTANCE.getMessages().get<String>("recalc")
|
||||
fun RESET() = AxMinionsAPI.INSTANCE.getMessages().get<String>("reset")
|
||||
@JvmStatic
|
||||
fun NOT_ON_ISLAND() = AxMinionsAPI.INSTANCE.getMessages().get<String>("not-on-island")
|
||||
@JvmStatic
|
||||
|
@ -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<CompletableFuture<Chunk>>()
|
||||
|
||||
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
|
||||
minions.fastFor {
|
||||
if (it.getOwnerUUID() == ownerUUID) {
|
||||
it.remove()
|
||||
}
|
||||
}
|
||||
|
||||
CompletableFuture.allOf(*futures.toTypedArray()).thenRun {
|
||||
player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.RECALC(), Placeholder.unparsed("from", original.toString()), Placeholder.unparsed("to", counter.toString())))
|
||||
}
|
||||
}
|
||||
}
|
||||
sender.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.RESET(), Placeholder.unparsed("player", offlinePlayer.name ?: "---")))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ charge:
|
||||
tools:
|
||||
wrong-tool: "<red>You can't place this item as the tool if this minion!"
|
||||
|
||||
recalc: "<green>Recalculated island minion count! <from> -> <to>"
|
||||
reset: "<green>You have reset <player>'s minion count!"
|
||||
not-on-island: "<#FF0000>You are currently not on an island!"
|
||||
slot-give: "<green>You have given <player> <amount> island minion slots!"
|
||||
slot-receive: "<green>You were given <amount> new island minion slots! (<from> -> <to>)"
|
||||
|
Loading…
Reference in New Issue
Block a user