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=3.2.1-SNAPSHOT
version=3.2.2-SNAPSHOT
6 changes: 4 additions & 2 deletions src/main/kotlin/dev/slne/surf/protect/paper/PaperMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Comment thread
TheBjoRedCraft marked this conversation as resolved.
buildLore {
line {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RegionInfo> = initialState("protection")

private val paginationState: State<Pagination> =
buildLazyPaginationState { _ -> EditableProtectionFlags.entries.toMutableList() }
buildLazyPaginationState { _ -> EditableProtectionFlags.entries.chunked(21)[0].toMutableList() }
.elementFactory { context, builder, _, flag ->

builder.renderWith {
Expand All @@ -44,7 +44,7 @@ object ProtectionEditFlagsView : View() {
context.playGeneralClickSound()

context.openForPlayer(
ProtectionEditFlagsView::class.java,
ProtectionEditFlagsViewA::class.java,
mapOf("protection" to protection)
)

Expand All @@ -66,14 +66,13 @@ object ProtectionEditFlagsView : View() {
.titleBuilder {
protectColored("Grundstück - Flags".toSmallCaps(), TextDecoration.BOLD)
}
.size(6)
.size(5)
.layout(
"OOOOOOOOO",
"ORRRRRRRO",
"ORRRRRRRO",
"ORRRRRRRO",
"ORRRRRRRO",
"OOOOBOOOO"
"OOOOBONOO",
)
.cancelInteractions()
}
Expand All @@ -87,6 +86,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(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
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<RegionInfo> = initialState("protection")

private val paginationState: State<Pagination> =
buildLazyPaginationState { _ -> EditableProtectionFlags.entries.chunked(21)[1].toMutableList() }
Comment thread
TheBjoRedCraft marked this conversation as resolved.
.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(5)
.layout(
"OOOOOOOOO",
"ORRRRRRRO",
"ORRRRRRRO",
"ORRRRRRRO",
"OOLOBOOOO",
)
.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())
}
}
}
}