From a354566686abf471bcebff3a3b92509e6d5adf69 Mon Sep 17 00:00:00 2001 From: TheBjoRedCraft Date: Wed, 13 May 2026 15:35:44 +0200 Subject: [PATCH 1/5] feat: implement dual flag editing views for enhanced protection management --- gradle.properties | 2 +- .../dev/slne/surf/protect/paper/PaperMain.kt | 6 +- .../paper/menu/view/ProtectionInfoView.kt | 4 +- ...agsView.kt => ProtectionEditFlagsViewA.kt} | 23 ++- .../view/flags/ProtectionEditFlagsViewB.kt | 184 ++++++++++++++++++ 5 files changed, 206 insertions(+), 13 deletions(-) rename src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/{ProtectionEditFlagsView.kt => ProtectionEditFlagsViewA.kt} (91%) create mode 100644 src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewB.kt diff --git a/gradle.properties b/gradle.properties index d21c40a..c78c1b3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ kotlin.code.style=official kotlin.stdlib.default.dependency=false org.gradle.parallel=true -version=3.2.1-SNAPSHOT +version=3.2.2-SNAPSHOT diff --git a/src/main/kotlin/dev/slne/surf/protect/paper/PaperMain.kt b/src/main/kotlin/dev/slne/surf/protect/paper/PaperMain.kt index 90b5d9b..22ee2a0 100644 --- a/src/main/kotlin/dev/slne/surf/protect/paper/PaperMain.kt +++ b/src/main/kotlin/dev/slne/surf/protect/paper/PaperMain.kt @@ -12,7 +12,8 @@ import dev.slne.surf.protect.paper.config.ProtectionConfigManager import dev.slne.surf.protect.paper.listener.ListenerManager import dev.slne.surf.protect.paper.menu.view.ProtectionInfoView import dev.slne.surf.protect.paper.menu.view.ProtectionMainView -import dev.slne.surf.protect.paper.menu.view.flags.ProtectionEditFlagsView +import dev.slne.surf.protect.paper.menu.view.flags.ProtectionEditFlagsViewA +import dev.slne.surf.protect.paper.menu.view.flags.ProtectionEditFlagsViewB import dev.slne.surf.protect.paper.menu.view.list.ProtectionListView import dev.slne.surf.protect.paper.menu.view.members.ProtectionMemberListView import dev.slne.surf.protect.paper.menu.view.members.ProtectionMemberRemoveConfirmView @@ -29,7 +30,8 @@ class PaperMain : SuspendingJavaPlugin() { override suspend fun onLoadAsync() { ProtectionFlagsRegistry.registerFlags() - viewFrame.with(ProtectionEditFlagsView) + viewFrame.with(ProtectionEditFlagsViewA) + viewFrame.with(ProtectionEditFlagsViewB) viewFrame.with(ProtectionListView) viewFrame.with(ProtectionMemberListView) viewFrame.with(ProtectionMemberRemoveConfirmView) diff --git a/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/ProtectionInfoView.kt b/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/ProtectionInfoView.kt index 23bd00f..ff1a07c 100644 --- a/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/ProtectionInfoView.kt +++ b/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/ProtectionInfoView.kt @@ -9,7 +9,7 @@ import dev.slne.surf.api.paper.builder.displayName import dev.slne.surf.api.paper.inventory.framework.titleBuilder import dev.slne.surf.protect.paper.menu.dialog.protectionRenameDialog import dev.slne.surf.protect.paper.menu.util.* -import dev.slne.surf.protect.paper.menu.view.flags.ProtectionEditFlagsView +import dev.slne.surf.protect.paper.menu.view.flags.ProtectionEditFlagsViewA import dev.slne.surf.protect.paper.menu.view.list.ProtectionListView import dev.slne.surf.protect.paper.menu.view.members.ProtectionMemberListView import dev.slne.surf.protect.paper.menu.view.sell.ProtectionSellConfirmView @@ -75,7 +75,7 @@ object ProtectionInfoView : View() { render.layoutSlot('F', editFlags).onClick { onClick -> onClick.playGeneralClickSound() onClick.openForPlayer( - ProtectionEditFlagsView::class.java, + ProtectionEditFlagsViewA::class.java, mapOf("protection" to protectionState.get(render)) ) } diff --git a/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsView.kt b/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewA.kt similarity index 91% rename from src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsView.kt rename to src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewA.kt index 930124e..4877a0b 100644 --- a/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsView.kt +++ b/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewA.kt @@ -20,12 +20,12 @@ import me.devnatan.inventoryframework.context.RenderContext import me.devnatan.inventoryframework.state.State import net.kyori.adventure.text.format.TextDecoration -object ProtectionEditFlagsView : View() { +object ProtectionEditFlagsViewA : View() { private val protectionState: State = initialState("protection") private val paginationState: State = - buildLazyPaginationState { _ -> EditableProtectionFlags.entries.toMutableList() } + buildLazyPaginationState { _ -> EditableProtectionFlags.entries.chunked(36)[0].toMutableList() } .elementFactory { context, builder, _, flag -> builder.renderWith { @@ -44,7 +44,7 @@ object ProtectionEditFlagsView : View() { context.playGeneralClickSound() context.openForPlayer( - ProtectionEditFlagsView::class.java, + ProtectionEditFlagsViewA::class.java, mapOf("protection" to protection) ) @@ -68,12 +68,12 @@ object ProtectionEditFlagsView : View() { } .size(6) .layout( + "RRRRRRRRR", + "RRRRRRRRR", + "RRRRRRRRR", + "RRRRRRRRR", "OOOOOOOOO", - "ORRRRRRRO", - "ORRRRRRRO", - "ORRRRRRRO", - "ORRRRRRRO", - "OOOOBOOOO" + " B N " ) .cancelInteractions() } @@ -87,6 +87,13 @@ object ProtectionEditFlagsView : View() { } render.layoutSlot('O', outlineItem) + render.layoutSlot('N', nextItem).onClick { click -> + click.playGeneralClickSound() + click.openForPlayer( + ProtectionEditFlagsViewB::class.java, + mapOf("protection" to protectionState.get(render)) + ) + } } private fun getCurrentState( diff --git a/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewB.kt b/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewB.kt new file mode 100644 index 0000000..ac1e80e --- /dev/null +++ b/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewB.kt @@ -0,0 +1,184 @@ +package dev.slne.surf.protect.paper.menu.view.flags + +import com.sk89q.worldguard.protection.flags.RegionGroup +import com.sk89q.worldguard.protection.flags.StateFlag +import com.sk89q.worldguard.protection.regions.ProtectedRegion +import dev.slne.surf.api.core.font.toSmallCaps +import dev.slne.surf.api.core.messages.adventure.sendText +import dev.slne.surf.api.paper.builder.buildItem +import dev.slne.surf.api.paper.builder.buildLore +import dev.slne.surf.api.paper.builder.displayName +import dev.slne.surf.api.paper.inventory.framework.titleBuilder +import dev.slne.surf.protect.paper.menu.util.* +import dev.slne.surf.protect.paper.menu.view.ProtectionInfoView +import dev.slne.surf.protect.paper.region.flags.EditableProtectionFlags +import dev.slne.surf.protect.paper.region.info.RegionInfo +import me.devnatan.inventoryframework.View +import me.devnatan.inventoryframework.ViewConfigBuilder +import me.devnatan.inventoryframework.component.Pagination +import me.devnatan.inventoryframework.context.RenderContext +import me.devnatan.inventoryframework.state.State +import net.kyori.adventure.text.format.TextDecoration + +object ProtectionEditFlagsViewB : View() { + private val protectionState: State = initialState("protection") + + private val paginationState: State = + buildLazyPaginationState { _ -> EditableProtectionFlags.entries.chunked(36)[1].toMutableList() } + .elementFactory { context, builder, _, flag -> + + builder.renderWith { + val region = protectionState.get(context).region + val state = getCurrentState(region, flag) + createFlagItem(flag, state) + } + + builder.onClick { context -> + val protection = protectionState.get(context) + val region = protection.region + + val newState = toggleState(region, flag) + applyState(region, flag, newState) + + context.playGeneralClickSound() + + context.openForPlayer( + ProtectionEditFlagsViewB::class.java, + mapOf("protection" to protection) + ) + + context.player.sendText { + appendSuccessPrefix() + success("Du hast die Flag ") + protectColored(flag.displayName.toSmallCaps(), TextDecoration.BOLD) + success(" auf ") + variableValue(formatState(flag, newState)) + success(" gesetzt.") + } + } + } + .layoutTarget('R') + .build() + + override fun onInit(config: ViewConfigBuilder) { + config + .titleBuilder { + protectColored("Grundstück - Flags".toSmallCaps(), TextDecoration.BOLD) + } + .size(6) + .layout( + "RRRRRRRRR", + "RRRRRRRRR", + "RRRRRRRRR", + "RRRRRRRRR", + "OOOOOOOOO", + " B N " + ) + .cancelInteractions() + } + + override fun onFirstRender(render: RenderContext) { + render.layoutSlot('B', backItem).onClick { click -> + click.openForPlayer( + ProtectionInfoView::class.java, + mapOf("protection" to protectionState.get(render)) + ) + } + + render.layoutSlot('O', outlineItem) + render.layoutSlot('L', previousItem).onClick { click -> + click.playGeneralClickSound() + click.openForPlayer( + ProtectionEditFlagsViewA::class.java, + mapOf("protection" to protectionState.get(render)) + ) + } + } + + private fun getCurrentState( + region: ProtectedRegion, + flag: EditableProtectionFlags + ): StateFlag.State { + return if (flag.isPlayerRelated) { + val group = region.getFlag(flag.flag.regionGroupFlag) + if (group == RegionGroup.MEMBERS) StateFlag.State.DENY else StateFlag.State.ALLOW + } else { + region.getFlag(flag.flag) ?: flag.initialState ?: StateFlag.State.ALLOW + } + } + + private fun toggleState( + region: ProtectedRegion, + flag: EditableProtectionFlags + ): StateFlag.State { + val current = getCurrentState(region, flag) + return if (current == StateFlag.State.ALLOW) StateFlag.State.DENY else StateFlag.State.ALLOW + } + + private fun applyState( + region: ProtectedRegion, + flag: EditableProtectionFlags, + state: StateFlag.State + ) { + if (flag.isPlayerRelated) { + region.setFlag(flag.flag, StateFlag.State.ALLOW) + if (state == StateFlag.State.ALLOW) { + region.setFlag(flag.flag.regionGroupFlag, null) + } else { + region.setFlag(flag.flag.regionGroupFlag, RegionGroup.MEMBERS) + } + } else { + region.setFlag(flag.flag, state) + } + } + + private fun formatState(flag: EditableProtectionFlags, state: StateFlag.State): String { + return if (flag.isPlayerRelated) { + if (state == StateFlag.State.ALLOW) "Für alle erlaubt" else "Nur für Mitglieder" + } else { + if (state == StateFlag.State.ALLOW) "Erlaubt" else "Verboten" + } + } + + private fun createFlagItem(flag: EditableProtectionFlags, state: StateFlag.State) = + buildItem(flag.icon) { + displayName { + protectColored(flag.displayName.toSmallCaps(), TextDecoration.BOLD) + } + + buildLore { + line { darkSpacer("Flag: ${flag.flag.name}".toSmallCaps()) } + emptyLine() + line { + appendBlob() + appendSpace() + spacer(flag.description) + } + emptyLine() + line { + appendBlob() + appendSpace() + white("Status: ".toSmallCaps()) + + if (flag.isPlayerRelated) { + if (state == StateFlag.State.ALLOW) { + success("Alle".toSmallCaps()) + } else { + variableValue("Mitglieder".toSmallCaps()) + } + } else { + if (state == StateFlag.State.ALLOW) { + success("Erlaubt".toSmallCaps()) + } else { + error("Verboten".toSmallCaps()) + } + } + } + emptyLine() + line { + appendSpace() + variableValue("Klicke zum Umschalten".toSmallCaps()) + } + } + } +} \ No newline at end of file From 19194ec0ef309d04942dae78c4d82c42a76b3965 Mon Sep 17 00:00:00 2001 From: TheBjoRedCraft Date: Wed, 13 May 2026 15:48:59 +0200 Subject: [PATCH 2/5] feat: adjust pagination and layout for flag editing views --- .../slne/surf/protect/paper/menu/util/view-util.kt | 6 +++--- .../menu/view/flags/ProtectionEditFlagsViewA.kt | 13 ++++++------- .../menu/view/flags/ProtectionEditFlagsViewB.kt | 13 ++++++------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/dev/slne/surf/protect/paper/menu/util/view-util.kt b/src/main/kotlin/dev/slne/surf/protect/paper/menu/util/view-util.kt index 17d094a..d6d8a32 100644 --- a/src/main/kotlin/dev/slne/surf/protect/paper/menu/util/view-util.kt +++ b/src/main/kotlin/dev/slne/surf/protect/paper/menu/util/view-util.kt @@ -52,18 +52,18 @@ fun Context.playYesSound() { val previousItem = MenuHeads.ARROW_LEFT.clone().apply { displayName { - protectColored("Vorherige Seite".toSmallCaps(), TextDecoration.BOLD) + protectColored("Vorherige Seite", TextDecoration.BOLD) } buildLore { line { - spacer("Eine Seite zurück") + spacer("Eine Seite zurück".toSmallCaps()) } } } val nextItem = MenuHeads.ARROW_RIGHT.clone().apply { displayName { - protectColored("Nächste Seite".toSmallCaps(), TextDecoration.BOLD) + protectColored("Nächste Seite", TextDecoration.BOLD) } buildLore { line { diff --git a/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewA.kt b/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewA.kt index 4877a0b..9152975 100644 --- a/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewA.kt +++ b/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewA.kt @@ -25,7 +25,7 @@ object ProtectionEditFlagsViewA : View() { private val protectionState: State = initialState("protection") private val paginationState: State = - buildLazyPaginationState { _ -> EditableProtectionFlags.entries.chunked(36)[0].toMutableList() } + buildLazyPaginationState { _ -> EditableProtectionFlags.entries.chunked(27)[0].toMutableList() } .elementFactory { context, builder, _, flag -> builder.renderWith { @@ -66,14 +66,13 @@ object ProtectionEditFlagsViewA : View() { .titleBuilder { protectColored("Grundstück - Flags".toSmallCaps(), TextDecoration.BOLD) } - .size(6) + .size(5) .layout( - "RRRRRRRRR", - "RRRRRRRRR", - "RRRRRRRRR", - "RRRRRRRRR", "OOOOOOOOO", - " B N " + "ORRRRRRRO", + "ORRRRRRRO", + "ORRRRRRRO", + "OOOOBONOO", ) .cancelInteractions() } diff --git a/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewB.kt b/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewB.kt index ac1e80e..e3ca71a 100644 --- a/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewB.kt +++ b/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewB.kt @@ -24,7 +24,7 @@ object ProtectionEditFlagsViewB : View() { private val protectionState: State = initialState("protection") private val paginationState: State = - buildLazyPaginationState { _ -> EditableProtectionFlags.entries.chunked(36)[1].toMutableList() } + buildLazyPaginationState { _ -> EditableProtectionFlags.entries.chunked(27)[1].toMutableList() } .elementFactory { context, builder, _, flag -> builder.renderWith { @@ -65,14 +65,13 @@ object ProtectionEditFlagsViewB : View() { .titleBuilder { protectColored("Grundstück - Flags".toSmallCaps(), TextDecoration.BOLD) } - .size(6) + .size(5) .layout( - "RRRRRRRRR", - "RRRRRRRRR", - "RRRRRRRRR", - "RRRRRRRRR", "OOOOOOOOO", - " B N " + "ORRRRRRRO", + "ORRRRRRRO", + "ORRRRRRRO", + "OOLOBOOOO", ) .cancelInteractions() } From 82a85f95d1962ed6fd3159329a1c9e766f24fad4 Mon Sep 17 00:00:00 2001 From: TheBjoRedCraft Date: Wed, 13 May 2026 15:49:56 +0200 Subject: [PATCH 3/5] feat: adjust pagination chunk size for flag editing views --- .../protect/paper/menu/view/flags/ProtectionEditFlagsViewA.kt | 2 +- .../protect/paper/menu/view/flags/ProtectionEditFlagsViewB.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewA.kt b/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewA.kt index 9152975..12a9cb1 100644 --- a/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewA.kt +++ b/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewA.kt @@ -25,7 +25,7 @@ object ProtectionEditFlagsViewA : View() { private val protectionState: State = initialState("protection") private val paginationState: State = - buildLazyPaginationState { _ -> EditableProtectionFlags.entries.chunked(27)[0].toMutableList() } + buildLazyPaginationState { _ -> EditableProtectionFlags.entries.chunked(21)[0].toMutableList() } .elementFactory { context, builder, _, flag -> builder.renderWith { diff --git a/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewB.kt b/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewB.kt index e3ca71a..90c48e9 100644 --- a/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewB.kt +++ b/src/main/kotlin/dev/slne/surf/protect/paper/menu/view/flags/ProtectionEditFlagsViewB.kt @@ -24,7 +24,7 @@ object ProtectionEditFlagsViewB : View() { private val protectionState: State = initialState("protection") private val paginationState: State = - buildLazyPaginationState { _ -> EditableProtectionFlags.entries.chunked(27)[1].toMutableList() } + buildLazyPaginationState { _ -> EditableProtectionFlags.entries.chunked(21)[1].toMutableList() } .elementFactory { context, builder, _, flag -> builder.renderWith { From a69b3812f7f46e17107f3ca587f2240b69f3327e Mon Sep 17 00:00:00 2001 From: TheBjoRedCraft Date: Wed, 13 May 2026 15:51:33 +0200 Subject: [PATCH 4/5] feat: update close item display name formatting in view-util --- .../kotlin/dev/slne/surf/protect/paper/menu/util/view-util.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/dev/slne/surf/protect/paper/menu/util/view-util.kt b/src/main/kotlin/dev/slne/surf/protect/paper/menu/util/view-util.kt index d6d8a32..e6bab33 100644 --- a/src/main/kotlin/dev/slne/surf/protect/paper/menu/util/view-util.kt +++ b/src/main/kotlin/dev/slne/surf/protect/paper/menu/util/view-util.kt @@ -86,7 +86,7 @@ val backItem = MenuHeads.CROSS.apply { val closeItem = MenuHeads.CROSS.apply { displayName { - protectColored("Schließen".toSmallCaps(), TextDecoration.BOLD) + protectColored("Schließen", TextDecoration.BOLD) } buildLore { From 82265146af5cf247fbf21c165e4201c1e96b6a08 Mon Sep 17 00:00:00 2001 From: TheBjoRedCraft Date: Wed, 13 May 2026 15:53:48 +0200 Subject: [PATCH 5/5] feat: update display name formatting for back item in view-util --- .../kotlin/dev/slne/surf/protect/paper/menu/util/view-util.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/dev/slne/surf/protect/paper/menu/util/view-util.kt b/src/main/kotlin/dev/slne/surf/protect/paper/menu/util/view-util.kt index e6bab33..8046794 100644 --- a/src/main/kotlin/dev/slne/surf/protect/paper/menu/util/view-util.kt +++ b/src/main/kotlin/dev/slne/surf/protect/paper/menu/util/view-util.kt @@ -74,7 +74,7 @@ val nextItem = MenuHeads.ARROW_RIGHT.clone().apply { val backItem = MenuHeads.CROSS.apply { displayName { - protectColored("Zurück".toSmallCaps(), TextDecoration.BOLD) + protectColored("Zurück", TextDecoration.BOLD) } buildLore {