# API

## Get Plugin Instance

```kotlin
val protect = Bukkit.getPluginManager()
    .getPlugin("CakeProtect") as? CakeProtect
```

## Query Regions

```kotlin
// ดู region ที่ตำแหน่ง
val region = protect.protectionManager.getRegionAt("world", x, z)

// ดู region ของผู้เล่น
val regions = protect.protectionManager.getRegionsOf(player.uniqueId)

// ดู region ทั้งหมด
val all = protect.protectionManager.getAllRegions()

// เช็ค overlap
val hasOverlap = protect.protectionManager.hasOverlap(region)

// หา region by ID
val region = protect.protectionManager.getRegionById("ps_abc123_1234567890")
```

## Manage Members

```kotlin
// เพิ่มสมาชิก
protect.protectionManager.addMember(regionId, uuid)

// ลบสมาชิก
protect.protectionManager.removeMember(regionId, uuid)
```

## Manage Flags

```kotlin
// Toggle flag (cycle: unset → allow → deny → unset)
protect.protectionManager.toggleFlag(regionId, "pvp")

// Change group (cycle: ALL → OWNER → MEMBERS → ...)
protect.protectionManager.cycleGroup(regionId, "pvp")

// Get all flags
val flags = protect.protectionManager.getFlags(regionId)
```

## Tier Management

```kotlin
// Get tier
val tier = protect.protectionManager.getTier("10x10")

// Toggle enabled
tier?.enabled = false
protect.protectionManager.saveTierSettings("10x10")

// Toggle shop visibility
tier?.showInShop = false
protect.protectionManager.saveTierSettings("10x10")
```

## Give Protection Stone

```kotlin
val tier = protect.protectionManager.getTier("50x50") ?: return
val item = PSShopGui.createPSItem(protect, tier)
player.inventory.addItem(item)
```

## Transfer Owner

```kotlin
protect.protectionManager.transferOwner(regionId, newOwnerUuid, newOwnerName)
```

## Create/Remove Region

```kotlin
// สร้าง region
val region = ProtectionRegion(
    id = "custom_id",
    ownerUuid = player.uniqueId,
    ownerName = player.name,
    world = "world",
    x = 100, z = 200,
    xRadius = 10, zRadius = 10,
    tier = "10x10"
)
protect.protectionManager.createRegion(region)

// ลบ region
protect.protectionManager.removeRegion(regionId)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.niendsitekungz.com/developer/api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
