mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2024-12-01 13:03:43 +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
|
@JvmStatic
|
||||||
fun UPGRADE_FAIL() = AxMinionsAPI.INSTANCE.getMessages().get<String>("upgrades.fail")
|
fun UPGRADE_FAIL() = AxMinionsAPI.INSTANCE.getMessages().get<String>("upgrades.fail")
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun RECALC() = AxMinionsAPI.INSTANCE.getMessages().get<String>("recalc")
|
fun RESET() = AxMinionsAPI.INSTANCE.getMessages().get<String>("reset")
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun NOT_ON_ISLAND() = AxMinionsAPI.INSTANCE.getMessages().get<String>("not-on-island")
|
fun NOT_ON_ISLAND() = AxMinionsAPI.INSTANCE.getMessages().get<String>("not-on-island")
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@ -136,57 +136,19 @@ class AxMinionsCommand {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subcommand("recalc")
|
@Subcommand("reset")
|
||||||
@CommandPermission("axminions.command.recalc")
|
@CommandPermission("axminions.command.reset")
|
||||||
fun recalc(player: Player) {
|
fun reset(sender: CommandSender, offlinePlayer: OfflinePlayer) {
|
||||||
val islandId = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration()?.getIslandAt(player.location)
|
val minions = AxMinionsAPI.INSTANCE.getMinions()
|
||||||
if (islandId == null) {
|
val ownerUUID = offlinePlayer.uniqueId
|
||||||
player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.NOT_ON_ISLAND()))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
AxMinionsPlugin.dataQueue.submit {
|
AxMinionsPlugin.dataQueue.submit {
|
||||||
var original = 0
|
minions.fastFor {
|
||||||
if (islandId.isNotBlank()) {
|
if (it.getOwnerUUID() == ownerUUID) {
|
||||||
original = AxMinionsAPI.INSTANCE.getDataHandler().getIsland(islandId)
|
it.remove()
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CompletableFuture.allOf(*futures.toTypedArray()).thenRun {
|
sender.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.RESET(), Placeholder.unparsed("player", offlinePlayer.name ?: "---")))
|
||||||
player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.RECALC(), Placeholder.unparsed("from", original.toString()), Placeholder.unparsed("to", counter.toString())))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,6 +94,7 @@ class Minion(
|
|||||||
private var debugHologram: Hologram? = null
|
private var debugHologram: Hologram? = null
|
||||||
val broken = AtomicBoolean(false)
|
val broken = AtomicBoolean(false)
|
||||||
private var ownerOnline = false
|
private var ownerOnline = false
|
||||||
|
private var unbreakable = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
spawn()
|
spawn()
|
||||||
@ -444,8 +445,10 @@ class Minion(
|
|||||||
|
|
||||||
if (this.tool?.type == Material.AIR) {
|
if (this.tool?.type == Material.AIR) {
|
||||||
entity.setItem(EquipmentSlot.MAIN_HAND, null)
|
entity.setItem(EquipmentSlot.MAIN_HAND, null)
|
||||||
|
unbreakable = false
|
||||||
} else {
|
} else {
|
||||||
entity.setItem(EquipmentSlot.MAIN_HAND, WrappedItemStack.wrap(tool.clone()))
|
entity.setItem(EquipmentSlot.MAIN_HAND, WrappedItemStack.wrap(tool.clone()))
|
||||||
|
unbreakable = notDurable.contains(tool.type)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (save) {
|
if (save) {
|
||||||
@ -678,7 +681,7 @@ class Minion(
|
|||||||
val tool = tool ?: return
|
val tool = tool ?: return
|
||||||
val toolMeta = toolMeta as? Damageable ?: return
|
val toolMeta = toolMeta as? Damageable ?: return
|
||||||
|
|
||||||
if (!tool.type.isAir && notDurable.contains(tool.type)) {
|
if (!tool.type.isAir && unbreakable) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -745,7 +748,7 @@ class Minion(
|
|||||||
val tool = tool ?: return false
|
val tool = tool ?: return false
|
||||||
val toolMeta = toolMeta as? Damageable ?: return false
|
val toolMeta = toolMeta as? Damageable ?: return false
|
||||||
|
|
||||||
if (!tool.type.isAir && notDurable.contains(tool.type)) {
|
if (!tool.type.isAir && unbreakable) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ charge:
|
|||||||
tools:
|
tools:
|
||||||
wrong-tool: "<red>You can't place this item as the tool if this minion!"
|
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!"
|
not-on-island: "<#FF0000>You are currently not on an island!"
|
||||||
slot-give: "<green>You have given <player> <amount> island minion slots!"
|
slot-give: "<green>You have given <player> <amount> island minion slots!"
|
||||||
slot-receive: "<green>You were given <amount> new island minion slots! (<from> -> <to>)"
|
slot-receive: "<green>You were given <amount> new island minion slots! (<from> -> <to>)"
|
||||||
|
Loading…
Reference in New Issue
Block a user