Skip to content
Open
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kotlin.code.style=official
kotlin.stdlib.default.dependency=false
org.gradle.parallel=true
version=3.3.7
version=3.3.8
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ object PaperCommandManager {
worldCommand()
pingCommand()
echestCommand()
testSoundCommand()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ object PaperListenerManager {
SpecialItemListener.register()
HungerListener.register()
RestartListener.register()
SpectatorFlyListener.register()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package dev.slne.surf.essentials.command

import dev.jorel.commandapi.kotlindsl.*
import dev.slne.surf.api.core.messages.adventure.playSound
import dev.slne.surf.api.core.messages.adventure.sendText
import dev.slne.surf.api.paper.util.BukkitSound
import dev.slne.surf.essentials.util.permission.EssentialsPermissionRegistry
import org.bukkit.Registry

fun testSoundCommand() = commandTree("testsound") {
withPermission(EssentialsPermissionRegistry.TEST_SOUND_COMMAND)

soundArgument("sound") {
playerExecutor { player, arguments ->
val sound: BukkitSound by arguments

player.playSound(true) {
type(sound)
}

player.sendText {
appendSuccessPrefix()
success("Der Sound ")
variableValue(Registry.SOUNDS.getKey(sound)?.key.toString())
success(" wurde erfolgreich abgespielt.")
}
}
floatArgument("pitch") {
playerExecutor { player, arguments ->
val sound: BukkitSound by arguments
val pitch: Float by arguments

player.playSound(true) {
type(sound)
pitch(pitch)
}

player.sendText {
appendSuccessPrefix()
success("Der Sound ")
variableValue(Registry.SOUNDS.getKey(sound)?.key.toString())
success(" wurde erfolgreich abgespielt.")
}
}

floatArgument("volume") {
playerExecutor { player, arguments ->
val sound: BukkitSound by arguments
val pitch: Float by arguments
val volume: Float? by arguments

player.playSound(true) {
type(sound)
pitch(pitch)
volume?.let {
volume(it)
}
}

player.sendText {
appendSuccessPrefix()
success("Der Sound ")
variableValue(Registry.SOUNDS.getKey(sound)?.key.toString())
success(" wurde erfolgreich abgespielt.")
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package dev.slne.surf.essentials.listener

import dev.slne.surf.essentials.plugin
import org.bukkit.GameMode
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerGameModeChangeEvent
import org.bukkit.event.player.PlayerQuitEvent
import java.util.*
import java.util.concurrent.ConcurrentHashMap

object SpectatorFlyListener : Listener {
private val allowFlightPlayers = ConcurrentHashMap.newKeySet<UUID>()
private val flyingPlayers = ConcurrentHashMap.newKeySet<UUID>()

@EventHandler(ignoreCancelled = true)
fun onGameModeChange(event: PlayerGameModeChangeEvent) {
val player = event.player
val previousGameMode = player.gameMode
val newGameMode = event.newGameMode

val isOldFlightMode =
previousGameMode == GameMode.SPECTATOR || previousGameMode == GameMode.CREATIVE
val isNewFlightMode = newGameMode == GameMode.SPECTATOR || newGameMode == GameMode.CREATIVE

if (!isOldFlightMode && isNewFlightMode) {
if (player.allowFlight) {
allowFlightPlayers.add(player.uniqueId)
if (player.isFlying) {
flyingPlayers.add(player.uniqueId)
}
}
return
}

if (isOldFlightMode && !isNewFlightMode) {
val hadAllowFlight = allowFlightPlayers.remove(player.uniqueId)
val wasFlying = flyingPlayers.remove(player.uniqueId)

player.scheduler.runDelayed(plugin, {
if (player.isOnline) {
player.allowFlight = hadAllowFlight
player.isFlying = wasFlying && hadAllowFlight
}
}, null, 1L)
}
}

@EventHandler
fun onQuit(event: PlayerQuitEvent) {
allowFlightPlayers.remove(event.player.uniqueId)
flyingPlayers.remove(event.player.uniqueId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,6 @@ object EssentialsPermissionRegistry : PermissionRegistry() {
val RENAME_COMMAND = create("$PREFIX.rename.command")
val RENAME_COMMAND_BYPASS = create("$PREFIX.rename.command.bypass")
val RENAME_COMMAND_MINIMESSAGE = create("$PREFIX.rename.command.minimessage")

val TEST_SOUND_COMMAND = create("$PREFIX.testsound.command")
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

@Suppress("SuspendCoroutineLacksCancellationGuarantees")
suspend fun World.unloadCanvasWorld(save: Boolean = true): WorldUnloadResult = suspendCoroutine { cont ->
Bukkit.unloadWorldAsync(this, save) {
cont.resume(it)
}
}
suspend fun World.unloadCanvasWorld(save: Boolean = true): WorldUnloadResult =
suspendCoroutine { cont ->
Bukkit.getServer().unloadWorldAsync(this, save) {
cont.resume(it)
}
}