Добавление возможности использования нескольких разрешённых айпи
This commit is contained in:
parent
658780cb3a
commit
73345e0edf
@ -5,13 +5,10 @@ import org.bukkit.event.Listener
|
||||
import org.bukkit.event.player.PlayerLoginEvent
|
||||
import org.bukkit.plugin.java.JavaPlugin
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
|
||||
class VpSecure : JavaPlugin(), Listener {
|
||||
|
||||
public var PROXYIP: String? = "1.1.1.1"
|
||||
private var ALLOWED_PROXY_IPS: List<String> = listOf("127.0.0.1")
|
||||
|
||||
override fun onEnable() {
|
||||
// Load configuration
|
||||
@ -20,7 +17,7 @@ class VpSecure : JavaPlugin(), Listener {
|
||||
// Register event listener
|
||||
server.pluginManager.registerEvents(this, this)
|
||||
|
||||
logger.info("VpSecure has been enabled with proxy IP: $PROXYIP")
|
||||
logger.info("VpSecure has been enabled with allowed proxy IPs: $ALLOWED_PROXY_IPS")
|
||||
}
|
||||
|
||||
override fun onDisable() {
|
||||
@ -42,15 +39,15 @@ class VpSecure : JavaPlugin(), Listener {
|
||||
|
||||
// Load the configuration
|
||||
val config = org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(configFile)
|
||||
PROXYIP = config.getString("proxy_ip", "1.1.1.1")
|
||||
ALLOWED_PROXY_IPS = config.getStringList("allowed_proxy_ips")
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onPlayerLogin(event: PlayerLoginEvent) {
|
||||
val ip = event.realAddress.toString().replace("/", "")
|
||||
|
||||
// Check if player's IP matches the configured proxy IP
|
||||
if (ip != PROXYIP) {
|
||||
// Check if player's IP matches any of the configured proxy IPs
|
||||
if (ip !in ALLOWED_PROXY_IPS) {
|
||||
event.disallow(
|
||||
PlayerLoginEvent.Result.KICK_OTHER,
|
||||
"Подключение с этого айпи запрещено: ${ip}. Если это ошибка - напишите по контактам voidproject.del.pw"
|
||||
|
@ -1,2 +1,2 @@
|
||||
# VpSecure Configuration
|
||||
proxy_ip: "127.0.0.1"
|
||||
allowed_proxy_ips:
|
||||
- "127.0.0.1"
|
Loading…
Reference in New Issue
Block a user