Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kieaer committed May 11, 2024
1 parent 4391527 commit 9b2fbb8
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 52 deletions.
22 changes: 10 additions & 12 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
id("com.github.node-gradle.node") version "5.0.0"
id("maven-publish")
id("jacoco")
id("org.sonarqube") version "4.4.1.3373"
}

java {
Expand Down Expand Up @@ -177,21 +178,18 @@ configurations.all {
}
}

publishing {
publications {
create<MavenPublication>("maven") {
groupId = "com.github.kieaer"
artifactId = "Essentials"
version = "v18"
from(components["java"])
}
}
}

tasks.jacocoTestReport {
dependsOn("test")
reports {
xml.required.set(true)
xml.outputLocation.set(file("build/reports/jacoco/test/jacoco.xml"))
}
}

sonar {
properties {
property("sonar.projectKey", "Kieaer_Essentials")
property("sonar.organization", "kieaer")
property("sonar.host.url", "https://sonarcloud.io")
property("sonar.coverage.jacoco.xmlReportPaths", "build/reports/jacoco/test/jacoco.xml")
}
}
5 changes: 3 additions & 2 deletions src/main/kotlin/essentials/Commands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import java.text.MessageFormat
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.*
import java.util.random.RandomGenerator
import kotlin.math.abs
import kotlin.math.floor
import kotlin.math.pow
Expand Down Expand Up @@ -261,7 +262,7 @@ class Commands(var handler: CommandHandler, isClient: Boolean) {

fun change(data: DB.PlayerData) {
transaction {
if (DB.Player.select(DB.Player.name).where(DB.Player.name eq(arg[0])).fetchSize!! > 0) {
if (DB.Player.select(DB.Player.name).where(DB.Player.name eq (arg[0])).toList().isNotEmpty()) {
err("command.changename.exists", arg[0])
} else {
Events.fire(PlayerNameChanged(data.name, arg[0], data.uuid))
Expand Down Expand Up @@ -2228,7 +2229,7 @@ class Commands(var handler: CommandHandler, isClient: Boolean) {
}
try {
val duration = arg[1].toInt()
Call.createWeather(weather, (Math.random() * 100).toFloat(), (duration * 8).toFloat(), 10f, 10f)
Call.createWeather(weather, (RandomGenerator.of("random").nextDouble() * 100).toFloat(), (duration * 8).toFloat(), 10f, 10f)
} catch (e : NumberFormatException) {
err("command.weather.not.number")
}
Expand Down
46 changes: 21 additions & 25 deletions src/main/kotlin/essentials/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import java.time.LocalDateTime
import java.time.LocalTime
import java.time.format.DateTimeFormatter
import java.util.*
import java.util.random.RandomGenerator
import java.util.regex.Pattern
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
Expand Down Expand Up @@ -93,7 +94,7 @@ object Event {
var worldHistory = Seq<TileLog>()
var voterCooltime = ObjectMap<String, Int>()

private var random = Random()
private var random = RandomGenerator.of("random")
private var dateformat = SimpleDateFormat("HH:mm:ss")
var blockExp = ObjectMap<String, Int>()
var dosBlacklist = ObjectSet<String>()
Expand Down Expand Up @@ -557,7 +558,7 @@ object Event {
}
}

if (!state.rules.infiniteResources && it.tile != null && it.tile.build != null && it.tile.build.maxHealth() == it.tile.block().health.toFloat()) {
if (!state.rules.infiniteResources && it.tile != null && it.tile.build != null && it.tile.build.maxHealth() == it.tile.block().health.toFloat() && (!buf.isEmpty && buf.last().tile != it.tile.block().name)) {
target.blockPlaceCount++
target.exp += blockExp[block.name]
target.currentExp += blockExp[block.name]
Expand Down Expand Up @@ -963,32 +964,28 @@ object Event {
saveDirectory.child("rollback.msav")
}

if (savePath.exists()) {
try {
val mode = state.rules.mode()
val reloader = WorldReloader()
try {
val mode = state.rules.mode()
val reloader = WorldReloader()

reloader.begin()
reloader.begin()

if (map != null) {
world.loadMap(map, map.applyRules(mode))
} else {
SaveIO.load(savePath)
}
if (map != null) {
world.loadMap(map, map.applyRules(mode))
} else {
SaveIO.load(savePath)
}

state.rules = state.map.applyRules(mode)
state.rules = state.map.applyRules(mode)

logic.play()
reloader.end()
logic.play()
reloader.end()

savePath.delete()
} catch (t: Exception) {
t.printStackTrace()
}
if (map == null) send("command.vote.back.done")
} else {
send("command.vote.failed")
savePath.delete()
} catch (t: Exception) {
t.printStackTrace()
}
if (map == null) send("command.vote.back.done")
}
}

Expand Down Expand Up @@ -1543,7 +1540,6 @@ object Event {
send("command.vote.random.done")
Thread {
var map: Map
val random = Random()
send("command.vote.random.is")
sleep(3000)
when (random.nextInt(7)) {
Expand Down Expand Up @@ -1590,7 +1586,7 @@ object Event {
state.teams.cores(voteStarter!!.player.team())
.first().items.add(
it,
Random().nextInt(2000)
random.nextInt(2000)
)
}
}
Expand All @@ -1600,7 +1596,7 @@ object Event {
state.teams.cores(Team.sharded)
.first().items.add(
it,
Random().nextInt(2000)
random.nextInt(2000)
)
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/essentials/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,19 @@ class Main: Plugin() {
data.currentControlCount += e.unitIDs.size
}

when {
return@addActionFilter when {
isHub != null && isHub == state.map.name() -> {
return@addActionFilter Permission.check(data, "hub.build")
Permission.check(data, "hub.build")
}
data.strict -> {
return@addActionFilter false
false
}
Config.authType == Config.AuthType.Discord && data.discord.isNullOrEmpty() -> {
e.player.sendMessage(Bundle(e.player.locale)["event.discord.not.registered"])
return@addActionFilter false
false
}
else -> {
return@addActionFilter true
true
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/test/kotlin/ClientCommandTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import PluginTest.Companion.loadGame
import PluginTest.Companion.loadPlugin
import PluginTest.Companion.log
import PluginTest.Companion.newPlayer
import PluginTest.Companion.path
import PluginTest.Companion.player
import PluginTest.Companion.setPermission
import arc.Events
Expand All @@ -23,7 +22,7 @@ import mindustry.game.EventType.GameOverEvent
import mindustry.game.Gamemode
import mindustry.game.Team
import mindustry.gen.Call
import org.junit.AfterClass
import net.datafaker.Faker
import org.junit.BeforeClass
import org.junit.Test
import org.mindrot.jbcrypt.BCrypt
Expand Down Expand Up @@ -89,8 +88,10 @@ class ClientCommandTest {

// Change other player name
val registeredUser = newPlayer()
clientCommand.handleMessage("/changename dummy ${registeredUser.first.name()}", player)
assertEquals("dummy", registeredUser.first.name())
val randomName = Faker().name().lastName()
clientCommand.handleMessage("/changename $randomName ${registeredUser.first.name()}", player)
sleep(100)
assertEquals(randomName, database.players.find { p -> p.uuid == registeredUser.second.uuid }.name)
leavePlayer(registeredUser.first)

// If target player not found
Expand Down Expand Up @@ -312,7 +313,7 @@ class ClientCommandTest {
next = true

// Un-hide other players' rankings in the ranking list
clientCommand.handleMessage("/exp hide ${dummy.second.entityid}", player)
clientCommand.handleMessage("/exp hide ${dummy.second.name}", player)
database.update(dummy.first.uuid(), dummy.second)
assertEquals(Bundle()["command.exp.ranking.unhide"], playerData.lastSentMessage)
while (next) {
Expand Down
5 changes: 2 additions & 3 deletions src/test/kotlin/FeatureTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class FeatureTest {
}*/

clientCommand.handleMessage("/status", player)
println(playerData.lastSentMessage)

println("core 개수: " + Vars.state.teams.active.size)

Expand All @@ -70,7 +69,7 @@ class FeatureTest {
println("활성화된 팀 : $s")

var players = mutableListOf<Pair<Team, Double>>()
database.players.forEach { it ->
database.players.forEach {
val rate = it.pvpVictoriesCount.toDouble() / (it.pvpVictoriesCount + it.pvpDefeatCount).toDouble()
players += Pair(it.player.team(), if (rate.equals(Double.NaN)) 0.0 else rate)
}
Expand All @@ -88,6 +87,6 @@ class FeatureTest {
}

println("플레이어 인원 : " + Groups.player.size())
println("플레이어 비율 : ${players.toString()}")
println("플레이어 비율 : $players")
}
}

0 comments on commit 9b2fbb8

Please sign in to comment.