Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/kotlin/dev/znci/rocket/Rocket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@ import org.bukkit.plugin.java.JavaPlugin
import java.io.File

class Rocket : JavaPlugin() {
companion object {
lateinit var instance: Rocket
private set
}

private var defaultLocale: String = "en_GB"

override fun onEnable() {
instance = this

// Create the plugin data folder
saveDefaultConfig()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dev.znci.rocket.scripting.globals.tables.LuaCommands
import dev.znci.rocket.scripting.globals.tables.LuaHTTPClient
import dev.znci.rocket.scripting.globals.tables.LuaLocations
import dev.znci.rocket.scripting.globals.tables.LuaPlayers
import dev.znci.rocket.scripting.globals.tables.LuaServer
import dev.znci.rocket.scripting.globals.values.TestValue
import org.bukkit.plugin.java.JavaPlugin

Expand All @@ -29,6 +30,7 @@ object GlobalInitializer {
ScriptManager.registerGlobal(LuaLocations())
ScriptManager.registerGlobal(LuaHTTPClient())
ScriptManager.registerGlobal(LuaCommands())
ScriptManager.registerGlobal(LuaServer())
//ScriptManager.registerGlobal(GamemodeEnum())

return true
Expand Down
190 changes: 190 additions & 0 deletions src/main/kotlin/dev/znci/rocket/scripting/globals/tables/Server.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
package dev.znci.rocket.scripting.globals.tables

import dev.znci.rocket.Rocket
import dev.znci.rocket.util.MessageFormatter
import dev.znci.twine.TwineError

Check warning on line 5 in src/main/kotlin/dev/znci/rocket/scripting/globals/tables/Server.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import dev.znci.twine.TwineNative
import dev.znci.twine.annotations.TwineNativeFunction
import dev.znci.twine.annotations.TwineNativeProperty
import java.text.MessageFormat

Check warning on line 9 in src/main/kotlin/dev/znci/rocket/scripting/globals/tables/Server.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import java.util.UUID

Check warning on line 10 in src/main/kotlin/dev/znci/rocket/scripting/globals/tables/Server.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive

@Suppress("unused")
class LuaServer : TwineNative("server") {
private val server = Rocket.instance.server

@TwineNativeProperty
val ip
get() = server.ip

@TwineNativeProperty
val port
get() = server.port

@TwineNativeProperty
var maxPlayers
get() = server.maxPlayers
set(value) { server.maxPlayers = value}

@TwineNativeProperty
val maxWorldSize
get() = server.maxWorldSize

@TwineNativeProperty
val minecraftVersion
get() = server.version

@TwineNativeProperty
val operators
get() = server.operators.map { LuaOfflinePlayer(it) }

@TwineNativeProperty
val resourcePack
get() = server.resourcePack

@TwineNativeProperty
val resourcePackHash
get() = server.resourcePackHash

@TwineNativeProperty
val resourcePackPrompt
get() = server.resourcePackPrompt

@TwineNativeProperty
val resourcePackRequired
get() = server.isResourcePackRequired

@TwineNativeProperty
val spawnProtectionRadius
get() = server.spawnRadius

@TwineNativeProperty
val tps
get() = ArrayList(server.tps.toList())

@TwineNativeProperty
val tickTimes
get() = ArrayList(server.tickTimes.toList())

@TwineNativeProperty
val viewDistance
get() = server.viewDistance

@TwineNativeProperty
var whitelisted
get() = server.hasWhitelist()
set(value) { server.setWhitelist(value) }

@TwineNativeProperty
var whitelistEnforced
get() = server.isWhitelistEnforced
set(value) { server.setWhitelistEnforced(value) }

Check notice on line 81 in src/main/kotlin/dev/znci/rocket/scripting/globals/tables/Server.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Accessor call that can be replaced with property access syntax

Use of setter method instead of property access syntax

@TwineNativeProperty
val acceptingTransfers
get() = server.isAcceptingTransfers

@TwineNativeProperty
val enforcingSecureProfiles
get() = server.isEnforcingSecureProfiles

@TwineNativeProperty
val hardcore
get() = server.isHardcore

@TwineNativeProperty
val loggingIPs
get() = server.isLoggingIPs

@TwineNativeProperty
val stopping
get() = server.isStopping

@TwineNativeProperty
val permissionMessage
get() = server.permissionMessage

// TODO: implement set functionality once enums are done
@TwineNativeProperty
val defaultGamemode
get() = server.defaultGameMode.toString()

@TwineNativeProperty
val paused
get() = server.isPaused

@TwineNativeProperty
var pauseWhenEmptyTime
get() = server.pauseWhenEmptyTime
set(value) { server.pauseWhenEmptyTime = value }

@TwineNativeProperty
val allowEnd
get() = server.allowEnd

@TwineNativeProperty
val allowNether
get() = server.allowNether

@TwineNativeProperty
val allowFlight
get() = server.allowFlight

@TwineNativeProperty
val idleTimeout
get() = server.idleTimeout

@TwineNativeFunction
fun allowPausing(value: Boolean): Boolean {
server.allowPausing(Rocket.instance, value)
return true
}

@TwineNativeFunction
fun broadcast(message: String): Boolean {
server.broadcast(MessageFormatter.formatMessage(message))
return true
}

@TwineNativeFunction
fun reload(): Boolean {
server.reload()
return true
}

@TwineNativeFunction
fun reloadMinecraftData(): Boolean {
server.reloadData()
return true
}

@TwineNativeFunction
fun reloadWhitelist(): Boolean {
server.reloadWhitelist()
return true
}

@TwineNativeFunction
fun reloadPermissions(): Boolean {
server.reloadPermissions()
return true
}

@TwineNativeFunction
fun reloadCommandAliases(): Boolean {
server.reloadCommandAliases()
return true
}

@TwineNativeFunction
fun shutdown(): Boolean {
server.shutdown()
return true
}

@TwineNativeFunction
fun restart(): Boolean {
server.restart()
return true
}
}
Loading