-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add first-party support for Minestom servers (#634)
* feat(shulker-server-agent): create agent library for Minestom * feat(shulker-crds): add Minestom in version channels * feat(shulker-operator): mimic Paper server when channel is Minestom * fix(shulker-server-agent): add support for BungeeCord proxy * feat(shulker-operator): validate MinecraftServerSpec on reconciling
- Loading branch information
1 parent
c41c2e2
commit 3874320
Showing
15 changed files
with
305 additions
and
16 deletions.
There are no files selected for viewing
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
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
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
89 changes: 89 additions & 0 deletions
89
...erver-agent/src/minestom/kotlin/io/shulkermc/serveragent/paper/ServerInterfaceMinestom.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,89 @@ | ||
package io.shulkermc.serveragent.paper | ||
|
||
import io.shulkermc.serveragent.ServerInterface | ||
import io.shulkermc.serveragent.platform.HookPostOrder | ||
import io.shulkermc.serveragent.platform.PlayerDisconnectHook | ||
import io.shulkermc.serveragent.platform.PlayerLoginHook | ||
import net.minestom.server.MinecraftServer | ||
import net.minestom.server.event.EventNode | ||
import net.minestom.server.event.player.PlayerDisconnectEvent | ||
import net.minestom.server.event.player.PlayerSpawnEvent | ||
import net.minestom.server.permission.Permission | ||
import net.minestom.server.timer.Task | ||
import net.minestom.server.timer.TaskSchedule | ||
import java.time.Duration | ||
import java.util.UUID | ||
import java.util.concurrent.TimeUnit | ||
|
||
class ServerInterfaceMinestom : ServerInterface { | ||
companion object { | ||
private const val ADMIN_PERMISSION_LEVEL = 4 | ||
} | ||
|
||
private val eventNode = EventNode.all("shulker-server-agent-minestom") | ||
|
||
override fun prepareNetworkAdminsPermissions(playerIds: List<UUID>) { | ||
this.eventNode.addListener(PlayerSpawnEvent::class.java) { event: PlayerSpawnEvent -> | ||
if (playerIds.contains(event.player.uuid)) { | ||
event.player.permissionLevel = ADMIN_PERMISSION_LEVEL | ||
event.player.addPermission(Permission("*")) | ||
} | ||
} | ||
} | ||
|
||
override fun addPlayerJoinHook( | ||
hook: PlayerLoginHook, | ||
postOrder: HookPostOrder, | ||
) { | ||
this.eventNode.addListener(PlayerSpawnEvent::class.java) { _ -> hook() } | ||
} | ||
|
||
override fun addPlayerQuitHook( | ||
hook: PlayerDisconnectHook, | ||
postOrder: HookPostOrder, | ||
) { | ||
this.eventNode.addListener(PlayerDisconnectEvent::class.java) { _ -> hook() } | ||
} | ||
|
||
override fun getPlayerCount(): Int = MinecraftServer.getConnectionManager().onlinePlayers.size | ||
|
||
override fun scheduleDelayedTask( | ||
delay: Long, | ||
timeUnit: TimeUnit, | ||
runnable: Runnable, | ||
): ServerInterface.ScheduledTask { | ||
val duration = Duration.ofNanos(timeUnit.toNanos(delay)) | ||
val task = | ||
MinecraftServer.getSchedulerManager().scheduleTask( | ||
runnable, | ||
TaskSchedule.duration(duration), | ||
TaskSchedule.stop(), | ||
) | ||
|
||
return MinestomScheduledTask(task) | ||
} | ||
|
||
override fun scheduleRepeatingTask( | ||
delay: Long, | ||
interval: Long, | ||
timeUnit: TimeUnit, | ||
runnable: Runnable, | ||
): ServerInterface.ScheduledTask { | ||
val delayDuration = Duration.ofNanos(timeUnit.toNanos(delay)) | ||
val intervalDuration = Duration.ofNanos(timeUnit.toNanos(interval)) | ||
val task = | ||
MinecraftServer.getSchedulerManager().scheduleTask( | ||
runnable, | ||
TaskSchedule.duration(delayDuration), | ||
TaskSchedule.duration(intervalDuration), | ||
) | ||
|
||
return MinestomScheduledTask(task) | ||
} | ||
|
||
private class MinestomScheduledTask(private val minestomTask: Task) : ServerInterface.ScheduledTask { | ||
override fun cancel() { | ||
this.minestomTask.cancel() | ||
} | ||
} | ||
} |
Oops, something went wrong.