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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ build/
!**/src/main/**/build/
!**/src/test/**/build/

run/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
Expand Down
9 changes: 9 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import dev.slne.surf.api.gradle.util.registerRequired
import dev.slne.surf.api.gradle.util.withSurfApiBukkit

plugins {
id("dev.slne.surf.api.gradle.paper-plugin")
Expand All @@ -19,6 +20,14 @@ surfPaperPluginApi {
}

authors.addAll("twisti", "red", "mikey")

runServer {
withSurfApiBukkit()
}
}

runPaper {
folia.registerTask()
}

dependencies {
Expand Down
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.1
version=3.3.2
32 changes: 32 additions & 0 deletions src/main/kotlin/dev/slne/surf/essentials/command/HatCommand.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
package dev.slne.surf.essentials.command

import dev.jorel.commandapi.CommandAPIPaper
import dev.jorel.commandapi.kotlindsl.commandTree
import dev.jorel.commandapi.kotlindsl.entitySelectorArgumentOnePlayer
import dev.jorel.commandapi.kotlindsl.getValue
import dev.jorel.commandapi.kotlindsl.playerExecutor
import dev.slne.surf.api.core.messages.adventure.buildText
import dev.slne.surf.api.core.messages.adventure.sendText
import dev.slne.surf.essentials.util.permission.EssentialsPermissionRegistry
import io.papermc.paper.datacomponent.DataComponentTypes
import org.bukkit.enchantments.Enchantment
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack

fun hatCommand() = commandTree("hat") {
withPermission(EssentialsPermissionRegistry.HAT_COMMAND)
playerExecutor { player, _ ->
val itemInHand = player.inventory.itemInMainHand
val helmet = player.inventory.helmet

if (!player.hasPermission(EssentialsPermissionRegistry.HAT_COMMAND_BYPASS)) {
if (helmet.isPreventArmorChange()) {
Comment thread
twisti-dev marked this conversation as resolved.
throw CommandAPIPaper.failWithAdventureComponent(buildText {
appendErrorPrefix()
error("Du kannst deinen Hut nicht verändern!")
})
}
}

player.inventory.setHelmet(itemInHand)
player.inventory.setItemInMainHand(helmet)

Expand All @@ -34,6 +49,17 @@ fun hatCommand() = commandTree("hat") {
val player: Player by args
val itemInHand = executor.inventory.itemInMainHand
val helmet = player.inventory.helmet

if (!executor.hasPermission(EssentialsPermissionRegistry.HAT_COMMAND_BYPASS)) {
if (helmet.isPreventArmorChange()) {
Comment thread
twisti-dev marked this conversation as resolved.
throw CommandAPIPaper.failWithAdventureComponent(buildText {
appendErrorPrefix()
variableValue(player.name)
error("s Hut kann nicht verändert werden!")
})
}
}

player.inventory.setHelmet(itemInHand)
player.inventory.setItemInMainHand(helmet)

Expand All @@ -60,4 +86,10 @@ fun hatCommand() = commandTree("hat") {
}
}
}
}

@Suppress("UnstableApiUsage")
private fun ItemStack.isPreventArmorChange(): Boolean {
Comment thread
twisti-dev marked this conversation as resolved.
val enchantments = getData(DataComponentTypes.ENCHANTMENTS) ?: return false
return enchantments.enchantments().keys.any { it.key() == Enchantment.BINDING_CURSE.key() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ object EssentialsPermissionRegistry : PermissionRegistry() {
val HEAL_COMMAND_OTHERS = create("$PREFIX.heal.command.others")
val HAT_COMMAND = create("$PREFIX.hat.command")
val HAT_COMMAND_OTHERS = create("$PREFIX.hat.command.others")
val HAT_COMMAND_BYPASS = create("$PREFIX.hat.command.bypass")
val LIST_COMMAND = create("$PREFIX.list.command")
val LIST_COMMAND_WORLD = create("$PREFIX.list.command.world")
val TRASH_COMMAND = create("$PREFIX.trash.command")
Expand Down