-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Cubxity/dev
Release 0.1.2
- Loading branch information
Showing
17 changed files
with
241 additions
and
42 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
bukkit/src/main/kotlin/dev/cubxity/plugins/metrics/bukkit/metric/tps/NMSTPSProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* UnifiedMetrics is a fully-featured metrics collection plugin for Minecraft servers. | ||
* Copyright (C) 2021 Cubxity | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.cubxity.plugins.metrics.bukkit.metric.tps | ||
|
||
import dev.cubxity.plugins.metrics.bukkit.util.getNMSClass | ||
import dev.cubxity.plugins.metrics.bukkit.util.getStaticMethodHandle | ||
|
||
class NMSTPSProvider : TPSProvider { | ||
private val minecraftServerClass = getNMSClass("MinecraftServer") | ||
private val getServerMethod = minecraftServerClass.getStaticMethodHandle("getServer", minecraftServerClass) | ||
private val recentTpsField = minecraftServerClass.getDeclaredField("recentTps") | ||
private val recentTickTimes = minecraftServerClass.getDeclaredField("h") | ||
|
||
override val tps: Double | ||
get() { | ||
val server = getServerMethod.invoke() | ||
val recentTps = recentTpsField.get(server) as DoubleArray | ||
return recentTps[0] | ||
} | ||
override val mspt: Long | ||
get() { | ||
val server = getServerMethod.invoke() | ||
val recentMspt = recentTickTimes.get(server) as LongArray | ||
return recentMspt[0] | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
bukkit/src/main/kotlin/dev/cubxity/plugins/metrics/bukkit/metric/tps/PaperTPSProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* UnifiedMetrics is a fully-featured metrics collection plugin for Minecraft servers. | ||
* Copyright (C) 2021 Cubxity | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.cubxity.plugins.metrics.bukkit.metric.tps | ||
|
||
import org.bukkit.Bukkit | ||
|
||
class PaperTPSProvider : TPSProvider { | ||
override val tps: Double | ||
get() = Bukkit.getServer().tps[0] | ||
override val mspt: Long | ||
get() = Bukkit.getServer().tickTimes[0] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
bukkit/src/main/kotlin/dev/cubxity/plugins/metrics/bukkit/metric/tps/TPSProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* UnifiedMetrics is a fully-featured metrics collection plugin for Minecraft servers. | ||
* Copyright (C) 2021 Cubxity | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.cubxity.plugins.metrics.bukkit.metric.tps | ||
|
||
interface TPSProvider { | ||
/** | ||
* Ticks per second | ||
*/ | ||
val tps: Double | ||
|
||
/** | ||
* Tick time in nanoseconds | ||
*/ | ||
val mspt: Long | ||
} |
37 changes: 37 additions & 0 deletions
37
bukkit/src/main/kotlin/dev/cubxity/plugins/metrics/bukkit/util/Environment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* UnifiedMetrics is a fully-featured metrics collection plugin for Minecraft servers. | ||
* Copyright (C) 2021 Cubxity | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.cubxity.plugins.metrics.bukkit.util | ||
|
||
import org.bukkit.Bukkit | ||
|
||
object Environment { | ||
val isPaper: Boolean = classExists("com.destroystokyo.paper.PaperConfig") | ||
val serverApiVersion: String = Bukkit.getServer().javaClass.`package`.name.split('.')[3] | ||
val majorMinecraftVersion: Int = serverApiVersion.split('_')[1].toInt() | ||
|
||
private fun classExists(name: String): Boolean { | ||
try { | ||
Class.forName(name) | ||
return true | ||
} catch (ignored: ClassNotFoundException) { | ||
// Ignore | ||
} | ||
return false | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
bukkit/src/main/kotlin/dev/cubxity/plugins/metrics/bukkit/util/MethodHandleUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* UnifiedMetrics is a fully-featured metrics collection plugin for Minecraft servers. | ||
* Copyright (C) 2021 Cubxity | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.cubxity.plugins.metrics.bukkit.util | ||
|
||
import java.lang.invoke.MethodHandle | ||
import java.lang.invoke.MethodHandles | ||
import java.lang.invoke.MethodType | ||
|
||
private val lookup = MethodHandles.publicLookup() | ||
|
||
fun Class<*>.getStaticMethodHandle(name: String, returnType: Class<*>, vararg parameters: Class<*>): MethodHandle { | ||
val type = MethodType.methodType(returnType, parameters) | ||
return lookup.findStatic(this, name, type) | ||
} |
22 changes: 22 additions & 0 deletions
22
bukkit/src/main/kotlin/dev/cubxity/plugins/metrics/bukkit/util/NMSUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* UnifiedMetrics is a fully-featured metrics collection plugin for Minecraft servers. | ||
* Copyright (C) 2021 Cubxity | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.cubxity.plugins.metrics.bukkit.util | ||
|
||
fun getNMSClass(name: String): Class<*> = | ||
Class.forName("net.minecraft.server.${Environment.serverApiVersion}.$name") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
name: UnifiedMetrics | ||
main: dev.cubxity.plugins.metrics.bukkit.bootstrap.UnifiedMetricsBukkitBootstrap | ||
description: "Fully-featured metrics plugin for Minecraft servers" | ||
api-version: 1.16 | ||
author: Cubxity | ||
version: @version@ | ||
load: STARTUP |
Oops, something went wrong.