forked from jeremylvln/Shulker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2831814
commit 1e1add3
Showing
10 changed files
with
190 additions
and
7 deletions.
There are no files selected for viewing
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
17 changes: 17 additions & 0 deletions
17
...er-server-agent/src/common/kotlin/io/shulkermc/serveragent/logger/AgentLoggerInterface.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,17 @@ | ||
package io.shulkermc.serveragent.logger | ||
|
||
interface AgentLoggerInterface { | ||
|
||
fun info(message: String) | ||
|
||
fun warning(message: String) | ||
|
||
fun severe(message: String) | ||
|
||
fun severe(message: String, exception: Throwable) | ||
|
||
fun debug(message: String) | ||
|
||
|
||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...shulker-server-agent/src/common/kotlin/io/shulkermc/serveragent/logger/JavaAgentLogger.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,26 @@ | ||
package io.shulkermc.serveragent.logger | ||
|
||
import java.util.logging.Level | ||
import java.util.logging.Logger | ||
|
||
class JavaAgentLogger(private val logger: Logger): AgentLoggerInterface { | ||
override fun info(message: String) { | ||
logger.info(message) | ||
} | ||
|
||
override fun warning(message: String) { | ||
logger.warning(message) | ||
} | ||
|
||
override fun severe(message: String) { | ||
logger.severe(message) | ||
} | ||
|
||
override fun severe(message: String, exception: Throwable) { | ||
logger.log(Level.SEVERE, message, exception) | ||
} | ||
|
||
override fun debug(message: String) { | ||
logger.fine(message) | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...er-agent/src/minestom/kotlin/io/shulkermc/serveragent/minestom/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,76 @@ | ||
package io.shulkermc.serveragent.minestom | ||
|
||
import io.shulkermc.serveragent.ServerInterface | ||
import io.shulkermc.serveragent.minestom.scheduler.MinestomTask | ||
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.Event | ||
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.TaskSchedule | ||
import java.time.Duration | ||
import java.util.UUID | ||
import java.util.concurrent.TimeUnit | ||
|
||
class ServerInterfaceMinestom(private val plugin: ShulkerServerAgentMinestom): ServerInterface { | ||
|
||
private val eventNode: EventNode<Event> = EventNode.all("shulker-server-agent-minestom") | ||
|
||
|
||
override fun prepareNetworkAdminsPermissions(playerIds: List<UUID>) { | ||
eventNode.addListener(PlayerSpawnEvent::class.java) { event -> | ||
if (event.player.uuid in playerIds) { | ||
event.player.permissionLevel = 4 | ||
event.player.addPermission(Permission("*")); | ||
} | ||
} | ||
} | ||
|
||
override fun addPlayerJoinHook(hook: PlayerLoginHook, postOrder: HookPostOrder) { | ||
eventNode.addListener(PlayerSpawnEvent::class.java) { _ -> | ||
hook() | ||
} | ||
} | ||
|
||
override fun addPlayerQuitHook(hook: PlayerDisconnectHook, postOrder: HookPostOrder) { | ||
eventNode.addListener(PlayerDisconnectEvent::class.java) { _ -> | ||
hook() | ||
} | ||
} | ||
|
||
override fun getPlayerCount(): Int { | ||
return 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 MinestomTask(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 MinestomTask(task) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...agent/src/minestom/kotlin/io/shulkermc/serveragent/minestom/ShulkerServerAgentMinestom.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 @@ | ||
package io.shulkermc.serveragent.minestom | ||
|
||
import io.shulkermc.serveragent.ShulkerServerAgentCommon | ||
import io.shulkermc.serveragent.minestom.logger.SLF4JAgentLogger | ||
import net.minestom.server.extensions.Extension | ||
import org.slf4j.LoggerFactory | ||
|
||
class ShulkerServerAgentMinestom: Extension() { | ||
|
||
companion object{ | ||
private val logger = LoggerFactory.getLogger(ShulkerServerAgentMinestom::class.java) | ||
} | ||
private val agent = ShulkerServerAgentCommon(ServerInterfaceMinestom(this), SLF4JAgentLogger(ShulkerServerAgentMinestom.logger)) | ||
|
||
override fun initialize() { | ||
agent.onServerInitialization() | ||
} | ||
|
||
override fun terminate() { | ||
agent.onServerShutdown() | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...er-agent/src/minestom/kotlin/io/shulkermc/serveragent/minestom/logger/SLF4JAgentLogger.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 @@ | ||
package io.shulkermc.serveragent.minestom.logger | ||
|
||
import io.shulkermc.serveragent.logger.AgentLoggerInterface | ||
import org.slf4j.Logger | ||
|
||
class SLF4JAgentLogger(private val logger: Logger): AgentLoggerInterface { | ||
|
||
|
||
override fun info(message: String) { | ||
logger.info(message) | ||
} | ||
|
||
override fun warning(message: String) { | ||
logger.warn(message) | ||
} | ||
|
||
override fun severe(message: String) { | ||
logger.error(message) | ||
} | ||
|
||
override fun severe(message: String, exception: Throwable) { | ||
logger.error(message, exception) | ||
} | ||
|
||
override fun debug(message: String) { | ||
logger.debug(message) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ver-agent/src/minestom/kotlin/io/shulkermc/serveragent/minestom/scheduler/MinestomTask.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,11 @@ | ||
package io.shulkermc.serveragent.minestom.scheduler | ||
|
||
import io.shulkermc.serveragent.ServerInterface | ||
import net.minestom.server.timer.Task | ||
|
||
class MinestomTask(private val task: Task): ServerInterface.ScheduledTask { | ||
|
||
override fun cancel() { | ||
task.cancel() | ||
} | ||
} |
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