Created
December 13, 2025 23:32
-
-
Save Grabsky/67b243a1a6ff93f0e476fb92da717884 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /* | |
| * Copyright (C) Grabsky (michal.czopek.foss@proton.me) | |
| * | |
| * This program is free software: you can redistribute it and/or modify | |
| * it under the terms of the GNU General Public License v3 as published by | |
| * the Free Software Foundation. | |
| * | |
| * This program is distributed in the hope that it will be useful, | |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| * GNU General Public License v3 for more details. | |
| */ | |
| import net.luckperms.api.event.user.UserDataRecalculateEvent | |
| import net.luckperms.api.event.EventSubscription | |
| import net.luckperms.api.LuckPermsProvider | |
| lateinit var listener: EventSubscription<UserDataRecalculateEvent> | |
| on<PlayerJoinEvent> { event -> | |
| LuckPermsProvider.get().userManager.getUser(event.player.uniqueId)?.let { user -> | |
| // Getting view distance from LuckPerms' meta. | |
| val metaValue = (user.cachedData.metaData.getMetaValue("view_distance")?.toInt() ?: 12).coerceIn(2, 32); | |
| // Setting view distance. | |
| event.player.viewDistance = metaValue | |
| } | |
| } | |
| onLoad { | |
| listener = LuckPermsProvider.get().eventBus.subscribe(plugin, UserDataRecalculateEvent::class.java) { event -> | |
| Bukkit.getPlayer(event.user.uniqueId)?.let { player -> | |
| // Getting view distance from LuckPerms' meta. | |
| val metaValue = (event.data.metaData.getMetaValue("view_distance")?.toInt() ?: 12).coerceIn(2, 32) | |
| // Updating view distance if changed. | |
| if (player.viewDistance != metaValue) | |
| logger.info("Changing view distance for ${player.name} from ${player.viewDistance} to $metaValue.") | |
| player.viewDistance = metaValue | |
| } | |
| } | |
| } | |
| onUnload { | |
| listener.close() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment