Skip to content

Commit

Permalink
Add /hud apm command
Browse files Browse the repository at this point in the history
  • Loading branch information
Kieaer committed Apr 12, 2024
1 parent 40b1862 commit 7fa7df9
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 26 deletions.
35 changes: 26 additions & 9 deletions src/main/kotlin/essentials/Commands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Commands(var handler: CommandHandler, isClient: Boolean) {
clientCommands.register("god", "[name]", "Set max player health") { a, p : Playerc -> Client(a, p).god() }
clientCommands.register("help", "[page]", "Show command lists") { a, p : Playerc -> Client(a, p).help() }
clientCommands.register("hub", "<set/zone/block/count/total/remove/reset> [ip] [parameters...]", "Create a server to server point.") { a, p : Playerc -> Client(a, p).hub() }
clientCommands.register("hud", "<health>", "Enable unit information.") { a, p : Playerc -> Client(a, p).hud() }
clientCommands.register("hud", "<health/apm>", "Enable unit information.") { a, p : Playerc -> Client(a, p).hud() }
clientCommands.register("info", "[player...]", "Show your information") { a, p: Playerc -> Client(a, p).info() }
clientCommands.register("js", "[code...]", "Execute JavaScript codes") { a, p : Playerc -> Client(a, p).js() }
clientCommands.register("kickall", "All users except yourself and the administrator will be kicked") { a, p : Playerc -> Client(a, p).kickall() }
Expand Down Expand Up @@ -817,19 +817,36 @@ class Commands(var handler: CommandHandler, isClient: Boolean) {
}

val status = if (data.hud != null) JsonObject.readJSON(data.hud).asArray() else JsonArray()

fun remove(text: String) {
var i = 0
while (i < status.size()) {
if (status[i].asString() == text) {
status.remove(i)
break
} else {
i++
}
}
}

when (arg[0]) {
"health" -> {
if (status.contains("health")) {
var i = 0
while (i < status.size()) {
if (status[i].asString() == "health") {
status.remove(i)
} else {
i++
}
}
remove("health")
send("command.hud.health.disabled")
} else {
status.add("health")
send("command.hud.health.enabled")
}
}
"apm" -> {
if (status.contains("apm")) {
remove("apm")
send("command.hud.apm.disabled")
} else {
status.add("apm")
send("command.hud.apm.enabled")
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/essentials/DB.kt
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ class DB {
var lastLeaveDate : LocalDateTime? = null
var showLevelEffects : Boolean = true
var currentPlayTime : Long = 0L
var currentUnitDestroyedCount : Int = 0
var currentBuildDestroyedCount : Int = 0
var currentBuildAttackCount : Int = 0
var apm = LinkedList<Int>()
var currentControlCount : Int = 0
var currentBuildDeconstructedCount : Int = 0
var isConnected : Boolean = false
var lastPlayedWorldName : String? = null
var lastPlayedWorldMode : String? = null
Expand Down
119 changes: 106 additions & 13 deletions src/main/kotlin/essentials/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ import kotlin.experimental.and
import kotlin.io.path.Path
import kotlin.math.abs
import kotlin.math.floor
import kotlin.math.roundToInt


object Event {
var originalBlockMultiplier = 1f
var originalUnitMultiplier = 1f
var enemyBuildingDestroyed = 0

var voting = false
var voteType : String? = null
Expand Down Expand Up @@ -108,6 +108,7 @@ object Event {
var maxdps : Float? = null
var unitLimitMessageCooldown = 0
var offlinePlayers = Seq<DB.PlayerData>()
var apmRanking = ""

private val specificTextRegex : Pattern = Pattern.compile("[!@#\$%&*()_+=|<>?{}\\[\\]~-]")
private val blockSelectRegex : Pattern = Pattern.compile("^build\\d{1,2}\$")
Expand All @@ -125,13 +126,21 @@ object Event {
if (it.tile != null && it.player.unit().item() != null && it.player.name != null) {
log(LogType.WithDraw, Bundle()["log.withdraw", it.player.plainName(), it.player.unit().item().name, it.amount, it.tile.block.name, it.tile.tileX(), it.tile.tileY()])
addLog(TileLog(System.currentTimeMillis(), it.player.name, "withdraw", it.tile.tile.x, it.tile.tile.y, checkValidBlock(it.tile.tile), it.tile.rotation, it.tile.team, it.tile.config()))
val p = findPlayerData(it.player.uuid())
if (p != null) {
p.currentControlCount++
}
}
}

Events.on(DepositEvent::class.java) {
if (it.tile != null && it.player.unit().item() != null && it.player.name != null) {
log(LogType.Deposit, Bundle()["log.deposit", it.player.plainName(), it.player.unit().item().name, it.amount, checkValidBlock(it.tile.tile), it.tile.tileX(), it.tile.tileY()])
addLog(TileLog(System.currentTimeMillis(), it.player.name, "deposit", it.tile.tile.x, it.tile.tile.y, checkValidBlock(it.tile.tile), it.tile.rotation, it.tile.team, it.tile.config()))
val p = findPlayerData(it.player.uuid())
if (p != null) {
p.currentControlCount++
}
}
}

Expand All @@ -158,6 +167,11 @@ object Event {
if (checkValidBlock(it.tile.tile).contains("message", true)) {
addLog(TileLog(System.currentTimeMillis(), it.player.name, "message", it.tile.tile.x, it.tile.tile.y, checkValidBlock(it.tile.tile), it.tile.rotation, it.tile.team, it.value))
}

val p = findPlayerData(it.player.uuid())
if (p != null) {
p.currentControlCount++
}
}
}

Expand Down Expand Up @@ -307,15 +321,32 @@ object Event {
Call.effect(two.player.con(), Fx.bigShockwave, it.tile.getX(), it.tile.getY(), 0f, Color.cyan)
}
}

data.currentControlCount++
}
}

Events.on(PickupEvent::class.java) {

if(it.unit.isPlayer) {
val p = findPlayerData(it.unit.player.uuid())
if (p != null) {
p.currentControlCount++
}
}
}

Events.on(UnitControlEvent::class.java) {
val p = findPlayerData(it.player.uuid())
if (p != null) {
p.currentControlCount++
}
}

Events.on(BuildingCommandEvent::class.java) {
val p = findPlayerData(it.player.uuid())
if (p != null) {
p.currentControlCount++
}
}

Events.on(WaveEvent::class.java) {
Expand Down Expand Up @@ -548,6 +579,8 @@ object Event {
target.currentExp -= blockExp[player.unit().buildPlan().block.name]
}
}

target.currentControlCount++
}
}
}
Expand All @@ -556,6 +589,10 @@ object Event {
if (it.builder is Playerc && it.builder.buildPlan() != null && it.tile.block() !== Blocks.air && it.breaking) {
log(LogType.Block, Bundle()["log.block.remove", (it.builder as Playerc).plainName(), checkValidBlock(it.tile), it.tile.x, it.tile.y])
addLog(TileLog(System.currentTimeMillis(), (it.builder as Playerc).plainName(), "select", it.tile.x, it.tile.y, checkValidBlock(player.unit().buildPlan().tile()), if (it.tile.build != null) it.tile.build.rotation else 0, if (it.tile.build != null) it.tile.build.team else state.rules.defaultTeam, it.tile.build.config()))
val p = findPlayerData((it.builder as Playerc).uuid())
if (p != null) {
p.currentControlCount++
}
}
}

Expand All @@ -565,13 +602,25 @@ object Event {
Damage.damage(world.tile(it.tile.pos()).team(), it.tile.getX(), it.tile.getY(), state.rules.dropZoneRadius, 1.0E8f, true)
}

if (state.rules.attackMode && it.tile.team() != state.rules.defaultTeam) {
enemyBuildingDestroyed++
if (state.rules.attackMode) {
for (a in database.players) {
if (it.tile.team() != state.rules.defaultTeam) {
a.currentBuildAttackCount++
} else {
a.currentBuildDestroyedCount++
}
}
}
}

Events.on(UnitDestroyEvent::class.java) {

if (!state.rules.pvp) {
for (a in database.players) {
if (it.unit.team() != a.player.team()) {
a.currentUnitDestroyedCount++
}
}
}
}

Events.on(UnitCreateEvent::class.java) { u ->
Expand All @@ -588,7 +637,10 @@ object Event {
}

Events.on(UnitChangeEvent::class.java) {

val p = findPlayerData(it.player.uuid())
if (p != null) {
p.currentControlCount++
}
}

Events.on(PlayerJoin::class.java) {
Expand Down Expand Up @@ -757,6 +809,11 @@ object Event {

for (data in database.players) {
data.currentPlayTime = 0
data.currentUnitDestroyedCount = 0
data.currentBuildDestroyedCount = 0
data.currentBuildAttackCount = 0
data.currentControlCount = 0
data.currentBuildDeconstructedCount = 0
}

resetVote()
Expand Down Expand Up @@ -1290,10 +1347,16 @@ object Event {
it.totalPlayTime++
it.currentPlayTime++

if (it.apm.size >= 60) {
it.apm.poll()
}
it.apm.add(it.currentControlCount)
it.currentControlCount = 0

if (it.animatedName) {
val name = it.name.replace("\\[(.*?)]".toRegex(), "")
nickcolor(name, it.player)
} else {
} else if (!it.status.containsKey("router")){
it.player.name(it.name)
}

Expand Down Expand Up @@ -1620,6 +1683,36 @@ object Event {
unitLimitMessageCooldown--
}

apmRanking = "APM\n"
val color = arrayOf("[scarlet]","[orange]","[yellow]","[green]","[white]","[gray]")
val list = LinkedHashMap<String, Int>()
database.players.forEach {
val total = it.apm.sum()
list[it.name] = (total.toDouble() / it.apm.size).roundToInt()
}
list.toList().sortedBy { (key, _) -> key }.forEach {
val colored = when (it.second) {
in 31..Int.MAX_VALUE -> color[0]
in 21..30 -> color[1]
in 11..20 -> color[2]
in 6..10 -> color[3]
in 0..5 -> color[4]
else -> color[5]
}
apmRanking += "${it.first} [white] - $colored${it.second}[white]\n"
}
apmRanking = apmRanking.substring(0, apmRanking.length - 1)
database.players.forEach {
if (it.hud != null) {
val array = JsonArray.readJSON(it.hud).asArray()
array.forEach { value ->
if (value.asString() == "apm") {
Call.infoPopup(it.player.con(), apmRanking, Time.delta, Align.left, 0, 0, 0, 0)
}
}
}
}

secondCount = 0
} else {
secondCount++
Expand Down Expand Up @@ -1839,20 +1932,20 @@ object Event {
val bundle = Bundle(target.languageTag)

if (PluginData.playtime > 300L) {
val erekirAttack = if (state.planet == Planets.erekir) state.stats.enemyUnitsDestroyed else 0
val erekirAttack = if (state.planet == Planets.erekir) target.currentUnitDestroyedCount else 0
val erekirPvP = if (state.planet == Planets.erekir) 5000 else 0

val score = if (winner == p.team()) {
if (state.rules.attackMode) {
time + (enemyBuildingDestroyed + erekirAttack) - (state.stats.buildingsDeconstructed + state.stats.buildingsDestroyed)
time + (target.currentBuildAttackCount + erekirAttack) - (target.currentBuildDeconstructedCount + target.currentBuildDestroyedCount)
} else if (state.rules.pvp) {
time + erekirPvP + 5000
} else {
0
}
} else if (p.team() != Team.derelict) {
if (state.rules.attackMode) {
time - (state.stats.buildingsDeconstructed + state.stats.buildingsDestroyed)
time - (target.currentBuildDeconstructedCount + target.currentBuildDestroyedCount)
} else if (state.rules.pvp) {
time + 5000
} else {
Expand Down Expand Up @@ -1885,9 +1978,9 @@ object Event {
resultJson.add("erekirAttack", erekirAttack)
resultJson.add("erekirPvP", erekirPvP)
resultJson.add("time", time)
resultJson.add("enemyBuildingDestroyed", enemyBuildingDestroyed)
resultJson.add("buildingsDeconstructed", state.stats.buildingsDeconstructed)
resultJson.add("buildingsDestroyed", state.stats.buildingsDestroyed)
resultJson.add("enemyBuildingDestroyed", target.currentUnitDestroyedCount)
resultJson.add("buildingsDeconstructed", target.currentBuildDeconstructedCount)
resultJson.add("buildingsDestroyed", target.currentBuildDestroyedCount)
resultJson.add("wave", state.wave)
resultJson.add("multiplier", target.expMultiplier)
resultJson.add("score", score)
Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ command.help.gg=Usage: [green]/gg [Winner team name][]\nLiterally surrender imme
command.help.god=Usage: [green]/god [sky]<player>[][]\nMakes the player's health infinite.\n[purple]== Example[]\n/god\n/god nickname\n/god Gureumi
command.help.help=Usage: [green]/help [sky]<page number or command>[][]\nView a list of commands or view a description of the command.\n[purple]== Example[]\n/help\n/help 2\n/help motd
command.help.hub=Usage: [green]/hub [sky]<set/zone/block/count/total/remove> [server IP] [options][][]\nCreate zones or blocks in your current location that allow you to move to other servers, player counters, etc.\nIn order for users to connect to the correct server, the server address must be an external IP or domain.\n\n[purple]== Example[]\n[green]/hub set[]\nBlocks building and destroying other than allowed groups on the map.\n[green]/hub zone mindustry.kr[]\nEnter this command and specify the range by clicking the start and end points.\nUnits can enter this server by entering or clicking within the specified range.\n[green]/hub block mindustry.kr owner's server[]\nIf you click the block in the current location, you will be connected to the mindustry.kr server.\nAnd in the block, a message with the description of the number of servers and owner's server is attached to the block.\nWhen you destroy the block, it automatically disappears.\n[green]/hub count mindustry.kr[]\nDisplays the number of servers in the current location as a block.\n[green]/hub total[]\nIt calculates the number of servers connected to the current location using the /hub command and displays them in blocks.\n[green]/hub remove mindustry.kr:7100[]\nDelete all blocks and entry areas moving to that server.[green]/hub reset[]\nReset all player counter.
command.help.hud=Usage: [green]/hud [sky]<type>[][]\nDisplay information on the screen.\nEntering it once more turns the HUD on and off.\n[purple]== Example[]\n/hud health - Show unit health
command.help.hud=Usage: [green]/hud [sky]<type>[][]\nDisplay information on the screen.\nEntering it once more turns the HUD on and off.\n[purple]== Example[]\n/hud health - Show unit health\n/hud apm - Show Players Actoin Per Minute
command.help.info=Usage: [green]/info [sky]<player>[][]\nDisplays the user's information.\n[purple]== Example[]\n/info\n/info Gureumi
command.help.js=Usage: [green]/js [sky]<code>[][]\nExecute the code you entered on the server.\nBecause you directly control the server, be careful when giving this command authority to other users.\n[purple]== Example[]\n/js Call.sendMessage("Hello!");\n/js Vars.netServer.admins.admins.toString();
command.help.kickall=Usage: [green]/kickall[]\nAll users except yourself and the administrator will be kicked out.\nA kicked out user can't enter the server for a certain period of time.
Expand Down Expand Up @@ -527,4 +527,8 @@ log.player.unbanned=Player {0} ({1}) has unbanned.
info.unban.title=Unban player
info.unban.comfirm=Are you sure you want to unblock {0}?
event.discord.not.registered=You are discord is not verified! Authenticate using the /discord command.
ommand.vote.back.fail=No more rollbacks!
ommand.vote.back.fail=No more rollbacks!
command.hud.health.enabled=Unit health display enabled.
command.hud.health.disabled=Unit health display disabled.
command.hud.apm.enabled=Player APM meter enabled. Please wait for update...
command.hud.apm.disabled=Player APM meter disabled.
Loading

0 comments on commit 7fa7df9

Please sign in to comment.