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
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=1.21.11-2.0.11-SNAPSHOT
version=1.21.11-2.0.12-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ object PaperListenerManager {
UnknownCommandListener.register()
WorldListener.register()
SpecialItemListener.register()
CommandExecutionListener.register()
}
Comment thread
TheBjoRedCraft marked this conversation as resolved.
Comment thread
TheBjoRedCraft marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,54 @@ import dev.jorel.commandapi.arguments.Argument
import dev.jorel.commandapi.arguments.ArgumentSuggestions
import dev.jorel.commandapi.arguments.CustomArgument
import dev.jorel.commandapi.arguments.StringArgument
import dev.slne.surf.essentials.util.permission.EssentialsPermissionRegistry
import dev.slne.surf.surfapi.core.api.messages.adventure.buildText
import org.bukkit.GameMode
import org.bukkit.command.CommandSender

class GameModeArgument(nodeName: String) :
CustomArgument<GameMode, String>(StringArgument(nodeName), { info ->
val gameMode = getGameMode(info.input.lowercase())
val input = info.input.lowercase()
val gameMode = getGameMode(input)
?: throw CustomArgumentException.fromAdventureComponent {
buildText {
appendErrorPrefix()
error("Der Spielmodus wurde nicht gefunden.")
}
}

val permission = "surf.essentials.gameMode.${gameMode.name.lowercase()}"
val sender = info.sender
if (sender != null) {
val base = EssentialsPermissionRegistry.GAME_MODE_COMMAND
val specific = "$base.${gameMode.name.lowercase()}"
val wildcard = "$base.*"

if (!sender.hasPermission(permission)) {
throw CustomArgumentException.fromAdventureComponent {
buildText {
appendErrorPrefix()
error("Dazu hast du keine Berechtigung.")
if (!sender.hasPermission(specific) &&
!sender.hasPermission(wildcard)
) {
Comment on lines +26 to +32
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hier wird für die Gamemode-Auswahl die Permission ${EssentialsPermissionRegistry.GAME_MODE_COMMAND}.<mode> bzw. ${...}.* verlangt. Das passt nicht zu den aktuell registrierten Nodes in EssentialsPermissionRegistry (z.B. surf.essentials.gameMode.creative, nicht surf.essentials.gameMode.command.creative). Ergebnis: Nutzer mit den bisherigen Rechten können den Gamemode nicht mehr über /gamemode wählen. Bitte die Permission-Checks an die bestehenden GAME_MODE_CREATIVE|SURVIVAL|...-Nodes anpassen oder die neuen Nodes im Registry hinzufügen.

Copilot uses AI. Check for mistakes.
throw CustomArgumentException.fromAdventureComponent {
buildText {
appendErrorPrefix()
error("Du hast keine Berechtigung für diesen Spielmodus.")
}
}
}
}

gameMode
}) {

init {
this.replaceSuggestions(
replaceSuggestions(
ArgumentSuggestions.stringCollection<CommandSender> { sender ->
val base = EssentialsPermissionRegistry.GAME_MODE_COMMAND
val wildcard = "$base.*"

GameMode.entries
.filter { sender.sender.hasPermission("surf.essentials.gameMode.${it.name.lowercase()}") }
.filter {
sender.sender.hasPermission(wildcard) ||
sender.sender.hasPermission("$base.${it.name.lowercase()}")
}
Comment on lines +46 to +55
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auch die Suggestions filtern über ${EssentialsPermissionRegistry.GAME_MODE_COMMAND}.<mode>/.*. Wenn diese Permission-Nodes nicht wirklich vergeben/registriert werden (aktuell gibt es im Registry surf.essentials.gameMode.<mode>), fehlen die Gamemode-Suggestions trotz vorhandener Rechte. Bitte die Suggestions auf die tatsächlich verwendeten Permission-Nodes umstellen (oder die neuen Nodes konsistent einführen).

Copilot uses AI. Check for mistakes.
.map { it.name.lowercase() }
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.slne.surf.essentials.command.minecraft

import dev.jorel.commandapi.kotlindsl.*
import dev.slne.surf.essentials.util.permission.EssentialsPermissionRegistry
import dev.slne.surf.essentials.util.util.translatable
import dev.slne.surf.surfapi.core.api.messages.adventure.sendText
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
Expand All @@ -19,9 +20,7 @@ fun giveCommand() = commandTree("give") {
executor.sendText {
appendSuccessPrefix()
success("Du hast ")
variableValue(itemStack.amount.toString())
success("x ")
variableValue(itemStack.type.name)
translatable(itemStack.type.translationKey())
success(" an ")
variableValue(players.size.toString())
success(" Spieler vergeben.")
Expand All @@ -31,13 +30,44 @@ fun giveCommand() = commandTree("give") {
player.sendText {
appendSuccessPrefix()
success("Du hast ")
variableValue(itemStack.amount.toString())
success("x ")
variableValue(itemStack.type.name)
translatable(itemStack.type.translationKey())
success(" erhalten.")
}
}
}

integerArgument("amount") {
anyExecutor { executor, args ->
val itemStack: ItemStack by args
val amount: Int by args
val players: Collection<Player> by args

itemStack.amount = amount
players.forEach { it.inventory.addItem(itemStack) }

executor.sendText {
appendSuccessPrefix()
success("Du hast ")
variableValue(amount.toString())
success("x ")
translatable(itemStack.type.translationKey())
success(" an ")
variableValue(players.size.toString())
success(" Spieler vergeben.")
}

players.forEach { player ->
player.sendText {
appendSuccessPrefix()
success("Du hast ")
variableValue(amount.toString())
success("x ")
translatable(itemStack.type.translationKey())
success(" erhalten.")
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ package dev.slne.surf.essentials.command.minecraft
import dev.jorel.commandapi.kotlindsl.*
import dev.slne.surf.essentials.util.permission.EssentialsPermissionRegistry
import dev.slne.surf.essentials.util.util.translatable
import dev.slne.surf.surfapi.bukkit.api.command.args.adventureCompoundBinaryTagArgument
import dev.slne.surf.surfapi.bukkit.api.nms.NmsUseWithCaution
import dev.slne.surf.surfapi.bukkit.api.nms.bridges.entityBridge
import dev.slne.surf.surfapi.core.api.messages.Colors
import dev.slne.surf.surfapi.core.api.messages.adventure.sendText
import net.kyori.adventure.nbt.CompoundBinaryTag
import org.bukkit.Location
import org.bukkit.entity.EntityType

@Suppress("UnstableApiUsage")
@NmsUseWithCaution
fun summonCommand() = commandTree("summon") {
withPermission(EssentialsPermissionRegistry.SUMMON_COMMAND)
entityTypeArgument("entityType") {
Expand All @@ -23,30 +29,64 @@ fun summonCommand() = commandTree("summon") {
}
}

integerArgument("amount") {
locationArgument("location") {
playerExecutor { player, args ->
val entityType: EntityType by args
val amount: Int by args
val location: Location by args

repeat(amount) {
player.location.world.spawnEntity(player.location, entityType)
}
location.world.spawnEntity(location, entityType)
Comment thread
TheBjoRedCraft marked this conversation as resolved.
Comment thread
TheBjoRedCraft marked this conversation as resolved.

player.sendText {
appendSuccessPrefix()
success("Du hast ")
variableValue(amount)
success(" ")
translatable(entityType.translationKey()).color(Colors.VARIABLE_VALUE)
success(" beschworen.")
}
Comment thread
TheBjoRedCraft marked this conversation as resolved.
}

locationArgument("location") {
adventureCompoundBinaryTagArgument("nbt") {
playerExecutor { player, args ->
val entityType: EntityType by args
val location: Location by args
val nbt: CompoundBinaryTag by args

entityBridge.createEntityByNbt(player.world, entityType, location, nbt)
Comment thread
TheBjoRedCraft marked this conversation as resolved.

Comment thread
TheBjoRedCraft marked this conversation as resolved.
player.sendText {
appendSuccessPrefix()
success("Du hast ")
translatable(entityType.translationKey()).color(Colors.VARIABLE_VALUE)
success(" beschworen.")
}
}

integerArgument("amount") {
playerExecutor { player, args ->
val entityType: EntityType by args
val location: Location by args
val nbt: CompoundBinaryTag by args
val amount: Int by args

repeat(amount) {
entityBridge.createEntityByNbt(player.world, entityType, location, nbt)
}
Comment thread
TheBjoRedCraft marked this conversation as resolved.

player.sendText {
appendSuccessPrefix()
success("Du hast ")
success("$amount ")
translatable(entityType.translationKey()).color(Colors.VARIABLE_VALUE)
Comment thread
TheBjoRedCraft marked this conversation as resolved.
success(" beschworen.")
Comment thread
TheBjoRedCraft marked this conversation as resolved.
}
}
}
}

integerArgument("amount") {
playerExecutor { player, args ->
val entityType: EntityType by args
val amount: Int by args
val location: Location by args
val amount: Int by args

repeat(amount) {
location.world.spawnEntity(location, entityType)
Expand All @@ -55,13 +95,12 @@ fun summonCommand() = commandTree("summon") {
player.sendText {
appendSuccessPrefix()
success("Du hast ")
variableValue(amount)
success(" ")
success("$amount ")
translatable(entityType.translationKey()).color(Colors.VARIABLE_VALUE)
success(" beschworen.")
Comment thread
TheBjoRedCraft marked this conversation as resolved.
}
}
}
}
}//TODO: add NBT Support
}
Comment thread
TheBjoRedCraft marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import dev.jorel.commandapi.kotlindsl.*
import dev.slne.surf.essentials.util.permission.EssentialsPermissionRegistry
import dev.slne.surf.surfapi.core.api.messages.adventure.sendText
import org.bukkit.Location
import org.bukkit.entity.Entity
import org.bukkit.entity.Player

fun teleportCommand() = commandTree("teleport") {
withPermission(EssentialsPermissionRegistry.TELEPORT_COMMAND)
withAliases("tp")
entitySelectorArgumentOnePlayer("target") {
entitySelectorArgumentOneEntity("target") {
playerExecutor { player, args ->
val target: Player by args
val target: Entity by args

player.teleportAsync(target.location)

Expand Down Expand Up @@ -39,10 +40,10 @@ fun teleportCommand() = commandTree("teleport") {
}
entitySelectorArgumentManyPlayers("players") {
withPermission(EssentialsPermissionRegistry.TELEPORT_COMMAND_OTHERS)
entitySelectorArgumentOnePlayer("target") {
entitySelectorArgumentOneEntity("target") {
anyExecutor { executor, args ->
val players: Collection<Player> by args
val target: Player by args
val target: Entity by args
Comment thread
TheBjoRedCraft marked this conversation as resolved.

players.forEach { it.teleportAsync(target.location) }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.slne.surf.essentials.command.minecraft

import com.github.shynixn.mccoroutine.folia.globalRegionDispatcher
import com.github.shynixn.mccoroutine.folia.launch
import dev.jorel.commandapi.kotlindsl.*
import dev.slne.surf.essentials.command.argument.namedTimeArgument
Expand Down Expand Up @@ -102,7 +103,9 @@ fun timeCommand() = commandTree("time") {
val time: Int by args

Bukkit.getWorlds().forEach {
it.fullTime = time.toLong()
plugin.launch(plugin.globalRegionDispatcher) {
it.fullTime = time.toLong()
}
}
Comment thread
TheBjoRedCraft marked this conversation as resolved.

executor.sendText {
Expand Down Expand Up @@ -130,7 +133,9 @@ fun timeCommand() = commandTree("time") {
(24000 - current) + target
}

world.fullTime += diff
plugin.launch(plugin.globalRegionDispatcher) {
world.fullTime += diff
}
Comment thread
TheBjoRedCraft marked this conversation as resolved.
}


Expand All @@ -152,10 +157,10 @@ fun timeCommand() = commandTree("time") {
val time: Int by args

Bukkit.getWorlds().forEach {
if (time !in 100..24000) {
it.fullTime += time
} else {
plugin.launch {
plugin.launch(plugin.globalRegionDispatcher) {
if (time !in 100..24000) {
it.fullTime += time
} else {
surfBukkitApi.skipTimeSmoothly(it, time.toLong())
}
}
Expand Down
Loading