Skip to content

Commit

Permalink
fix: Misc bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed Dec 12, 2023
1 parent b23b8f3 commit be6c92a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ val metadata =
displayName = "NoHornyPlugin",
author = "Xpdustry",
description = "NO HORNY IN MY SERVER!",
version = "2.0.0-rc.1",
version = "2.0.0-rc.2",
minGameVersion = "146",
hidden = true,
java = true,
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/xpdustry/nohorny/NoHornyAutoBan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import mindustry.world.blocks.logic.LogicDisplay
internal class NoHornyAutoBan(private val plugin: NoHornyPlugin) : PluginListener {

override fun onPluginInit() {
onEvent<ImageAnalyzerEvent>(plugin) { (result, cluster, author) ->
onEvent<ImageAnalyzerEvent>(plugin) { (result, cluster, _, author) ->
if (result.rating == ImageAnalyzer.Rating.UNSAFE &&
plugin.config.autoBan &&
author != null) {
Expand Down
12 changes: 11 additions & 1 deletion src/main/kotlin/com/xpdustry/nohorny/NoHornyTracker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ internal class NoHornyTracker(private val plugin: NoHornyPlugin) : PluginListene
private val debug = IntSet()

override fun onPluginInit() {
onEvent<EventType.ResetEvent>(plugin) {
processors.clear()
displays.clear()
displayProcessingQueue.clear()
canvases.clear()
canvasProcessingQueue.clear()
logger.trace("Reset tracker")
}

onPlayerBuildEvent<CanvasBlock.CanvasBuild>(plugin) { canvas, breaking, player ->
if (breaking) {
removeCanvas(canvas)
Expand Down Expand Up @@ -175,6 +184,7 @@ internal class NoHornyTracker(private val plugin: NoHornyPlugin) : PluginListene
logger.trace("Begin processing of {} cluster {}", name, copy.identifier)

schedule(plugin, async = true) {
val image = render(copy)
plugin.analyzer
.analyse(render(copy))
.orTimeout(10L, TimeUnit.SECONDS)
Expand All @@ -189,7 +199,7 @@ internal class NoHornyTracker(private val plugin: NoHornyPlugin) : PluginListene
Core.app.post {
DistributorProvider.get()
.eventBus
.post(ImageAnalyzerEvent(result, copy))
.post(ImageAnalyzerEvent(result, copy, image))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ package com.xpdustry.nohorny.analyzer

import com.xpdustry.nohorny.NoHornyImage
import com.xpdustry.nohorny.geometry.Cluster
import java.awt.image.BufferedImage

public data class ImageAnalyzerEvent(
val result: ImageAnalyzer.Result,
val cluster: Cluster<out NoHornyImage>
val cluster: Cluster<out NoHornyImage>,
val image: BufferedImage
) {
public operator fun component3(): NoHornyImage.Author? = author
public operator fun component4(): NoHornyImage.Author? = author

val author: NoHornyImage.Author?
get() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public interface ClusterManager<T : Any> {

public fun removeBlock(x: Int, y: Int): List<Int>

public fun clear()

public companion object {
@JvmStatic public fun <T : Any> create(): ClusterManager<T> = SimpleClusterManager()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,9 @@ internal class SimpleClusterManager<T : Any> : ClusterManager<T> {
return modified
}

override fun clear() {
_clusters.clear()
}

private fun nextIdentifier() = generator.getAndUpdate { it.inc().coerceAtLeast(0) }
}

0 comments on commit be6c92a

Please sign in to comment.