Skip to content

Commit eda48e6

Browse files
Merge branch 'version/1.21.10' into fix/18-whitelist-command-classcastexeption
2 parents 5d8b0ef + 2d01a5e commit eda48e6

File tree

7 files changed

+103
-4
lines changed

7 files changed

+103
-4
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
kotlin.code.style=official
22
kotlin.stdlib.default.dependency=false
33
org.gradle.parallel=true
4-
version=1.21.10-2.0.5-SNAPSHOT
4+
version=1.21.10-2.0.6-SNAPSHOT

src/main/kotlin/dev/slne/surf/essentials/PaperCommandManager.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ object PaperCommandManager {
2525
giveCommand()
2626
infoCommand()
2727
itemEditCommand()
28-
signCommand()
2928
teleportCommand()
3029
teleportOfflineCommand()
3130
teleportRandomCommand()
@@ -62,7 +61,12 @@ object PaperCommandManager {
6261
soundCommand()
6362
stopCommand()
6463
restartCommand()
65-
makeSpecialCommand()
64+
65+
if (!plugin.isSurvivalServer()) {
66+
makeSpecialCommand()
67+
signCommand()
68+
}
69+
6670
knightCommand()
6771
toolCommand()
6872
experienceCommand()
@@ -71,5 +75,6 @@ object PaperCommandManager {
7175
timeCommand()
7276
skinChangeCommand()
7377
worldCommand()
78+
pingCommand()
7479
}
7580
}

src/main/kotlin/dev/slne/surf/essentials/PaperMain.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.slne.surf.essentials
22

33
import com.github.shynixn.mccoroutine.folia.SuspendingJavaPlugin
4+
import dev.slne.surf.surfapi.bukkit.api.extensions.pluginManager
45
import org.bukkit.plugin.java.JavaPlugin
56

67
val plugin get() = JavaPlugin.getPlugin(PaperMain::class.java)
@@ -18,4 +19,6 @@ class PaperMain : SuspendingJavaPlugin() {
1819
override fun onDisable() {
1920
super.onDisable()
2021
}
22+
23+
fun isSurvivalServer() = pluginManager.isPluginEnabled("surf-freebuild-bukkit")
2124
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package dev.slne.surf.essentials.command
2+
3+
import dev.jorel.commandapi.kotlindsl.*
4+
import dev.slne.surf.essentials.util.permission.EssentialsPermissionRegistry
5+
import dev.slne.surf.essentials.util.util.coloredPing
6+
import dev.slne.surf.surfapi.core.api.messages.adventure.sendText
7+
import org.bukkit.entity.Player
8+
9+
fun pingCommand() = commandTree("ping") {
10+
withPermission(EssentialsPermissionRegistry.PING_COMMAND)
11+
playerExecutor { player, _ ->
12+
val ping = player.ping.toLong()
13+
14+
player.sendText {
15+
appendPrefix()
16+
info("Du hast einen Ping von ")
17+
coloredPing(ping)
18+
info(".")
19+
}
20+
}
21+
22+
entitySelectorArgumentOnePlayer("target") {
23+
withPermission(EssentialsPermissionRegistry.PING_COMMAND_OTHER)
24+
anyExecutor { executor, args ->
25+
val target: Player by args
26+
27+
val ping = target.ping.toLong()
28+
29+
executor.sendText {
30+
appendPrefix()
31+
variableValue(target.name)
32+
info(" hat einen Ping von ")
33+
coloredPing(ping)
34+
info(".")
35+
}
36+
}
37+
}
38+
}

src/main/kotlin/dev/slne/surf/essentials/listener/SpecialItemListener.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.slne.surf.essentials.listener
22

3+
import dev.slne.surf.essentials.plugin
34
import dev.slne.surf.essentials.service.specialItemService
45
import dev.slne.surf.essentials.util.util.appendNewLineArrow
56
import dev.slne.surf.essentials.util.util.translatable
@@ -28,6 +29,10 @@ object SpecialItemListener : Listener {
2829
val player = event.entity as? Player ?: return
2930
val itemStack = event.item.itemStack
3031

32+
if (plugin.isSurvivalServer()) {
33+
return
34+
}
35+
3136
if (!specialItemService.isSpecial(itemStack)) {
3237
return
3338
}

src/main/kotlin/dev/slne/surf/essentials/util/permission/EssentialsPermissionRegistry.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,6 @@ object EssentialsPermissionRegistry : PermissionRegistry() {
108108
val WORLD_COMMAND_LIST = create("$PREFIX.world.command.list")
109109
val WORLD_COMMAND_JOIN = create("$PREFIX.world.command.join")
110110
val WORLD_BYPASS = create("$PREFIX.world.bypass")
111+
val PING_COMMAND = create("$PREFIX.ping.command")
112+
val PING_COMMAND_OTHER = create("$PREFIX.ping.command.other")
111113
}

src/main/kotlin/dev/slne/surf/essentials/util/util/surf-util.kt

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,50 @@ fun Duration.userContent(): String {
8989
if (parts.isEmpty() && millis > 0) parts.add("$millis Millisekunden")
9090

9191
return parts.joinToString(", ")
92-
}
92+
}
93+
94+
fun SurfComponentBuilder.coloredDuration(
95+
duration: Duration,
96+
good: Duration = Duration.ofMillis(200),
97+
okay: Duration = Duration.ofMillis(1000)
98+
) {
99+
val millis = duration.toMillis()
100+
when {
101+
duration < good -> text(
102+
millis.toString() + "ms",
103+
Colors.GREEN
104+
)
105+
106+
duration < okay -> text(
107+
millis.toString() + "ms",
108+
Colors.YELLOW
109+
)
110+
111+
else -> text(millis.toString() + "ms", Colors.RED)
112+
}
113+
}
114+
115+
fun SurfComponentBuilder.coloredPing(
116+
ping: Long
117+
) = coloredDuration(Duration.ofMillis(ping), Duration.ofMillis(100), Duration.ofMillis(300))
118+
119+
fun Long.coloredComponent(good: Long = 200L, okay: Long = 1000L) =
120+
buildText {
121+
when {
122+
this@coloredComponent < good -> append(
123+
Component.text(
124+
this@coloredComponent.toString() + "ms",
125+
Colors.GREEN
126+
)
127+
)
128+
129+
this@coloredComponent < okay -> append(
130+
Component.text(
131+
this@coloredComponent.toString() + "ms",
132+
Colors.YELLOW
133+
)
134+
)
135+
136+
else -> append(Component.text(this@coloredComponent.toString() + "ms", Colors.RED))
137+
}
138+
}

0 commit comments

Comments
 (0)