# Chest Shops

A player turns a single chest into a shop via **shift+left-click with an item in hand**, the sign is created automatically. All trading happens through the sign; the chest stays locked for everyone except owner/team manager/admin. Every shop is `SELLING` (sells from the chest) or `BUYING` (buys from players) and belongs to a player or a [team](teams.html) (money then flows through the team treasury).

## Commands

| Command | Syntax | Permission | Default | Description |
|---|---|---|---|---|
| `/shop info` | `/shop info` (look at block) | `shop.use` | `true` | Owner, item, price, type, stock, coordinates |
| `/shop remove` | `/shop remove` (look at block) | `shop.use` | `true` | Removes the shop (management right required) |
| `/team shop` | `/team shop` (look at block) | `team.shop` + team right | `true` | Converts the shop into a team shop |
| `/shop list` | `/shop list` | `shop.admin` | `false` | All shops with type, owner, item, price, position |
| `/shop reload` | `/shop reload` | `shop.admin` | `false` | Reloads config and shops |
| `/shopedit` | (internal menu, right-click the sign) | `shop.create` | `true` | Change price, toggle type, remove shop |
| `/shopconfirm` / `/shopcancel` | (internal chat buttons) | `shop.use` | `true` | Confirms/cancels a transaction |

## Additional permissions

| Permission | Default | Description |
|---|---|---|
| `shop.create` | `true` | Create shops via shift+click |
| `shop.bypass.maxshops` | `false` | Bypasses the personal and team shop limits |
| `shop.bypass.selftrade` | `false` | Allows trading at your own shop |
| `shop.limit.<n>` | `false` | Individual shop limit (highest value wins) |
| `shop.limit.unlimited` | `false` | No shop limit |

## How a trade works

1. **Left-click the sign**, an anvil GUI asks for the quantity (for selling limited by player stock, chest space and owner balance).
2. Clickable `[✔ Confirm]`/`[✘ Cancel]` buttons appear in chat (valid 30 seconds, `general.confirmation-timeout`).
3. On confirmation everything is re-checked and booked atomically: if any step fails, money and items are returned automatically. If not everything fits into the inventory, the remaining items drop at your feet (no loss).

> **Note:** If the owner changes price or type in the meantime, the confirmation cancels automatically. Price and quantity inputs use anvil windows (not chat) and understand `k`/`M` suffixes like `1.5k`.

> **Tip:** The optional tax (`tax-percentage`) is credited to nobody, it is a pure money sink against inflation.

**Right-clicking your own sign** opens the edit menu: change price, toggle type (cooldown protected), remove the shop. Switching a team shop to `BUYING` additionally needs the team right `WITHDRAW`, because buying shops spend team money.

**Team shops** (`/team shop`): needs team membership with the team right `EDIT_TEAM_SHOPS` (or `shop.admin`). They do not count against the personal limit but against `max-shops-per-team`.

## Sign

The sign is waxed automatically and redrawn on every change:

| Line | Content | Color |
|---|---|---|
| 1 | `[Shop]` | Pink |
| 2 | Owner (player or `Team <name>`) | Aqua |
| 3 | Item name | Yellow |
| 4 | `Sell <price>` / `Buy <price>` (compact format like `10k`) | Green when available, otherwise red |

## Protections

| Threat | Protection |
|---|---|
| Double chests | Creation rejected; merging afterwards is technically impossible |
| Breaking chest/sign | Only owner/team manager/`shop.admin`, and even they must sneak |
| Explosions | Shop chests and signs are blast proof |
| Pistons | Movements involving shop blocks are cancelled entirely |
| Water/lava/fire/enderman | Cannot replace or destroy shop blocks |
| Hoppers | Can neither drain nor fill shop chests (`hopper-protection`) |
| Unauthorized opening | Chest opens only for managers, trading happens via the sign |
| Team chests | Team-claimed chests cannot become a shop |

## Configuration (modules/shop.yml)

```yaml
# Enables or disables the chest shop module.
enabled: true

shop:
  # Default limit per player. Override per rank via permission:
  # shop.limit.25 allows 25 shops, shop.limit.unlimited removes the limit.
  max-shops-per-player: 10
  # Maximum shops per team (-1 = unlimited). Team shops do not count
  # against the personal limit.
  max-shops-per-team: 10
  # Prevents hoppers from draining or filling shop chests.
  hopper-protection: true
  # Allowed price range per item. max-price is hard capped at 999000000
  # (higher values are clamped on load).
  min-price: 0.01
  max-price: 999000000.0
  # Percentage tax on every completed transaction. The amount is credited
  # to nobody (money sink). 0 = no tax.
  tax-percentage: 0
  # Plays transaction sounds for nearby players too.
  sound-broadcast: false
  integrations:
    coreprotect:
      # Logs transactions to CoreProtect (#shop-buy-<player>).
      transaction-logging: true
    nexo:
      # Resolves Nexo item names on signs/displays.
      enabled: true
    carpentary:
      # Resolves Carpentary item names.
      enabled: true

cooldown:
  commands:
    # Seconds between /shopedit actions (against spam toggling).
    shopedit: 3
```

## Complete example config

```yaml
enabled: true

shop:
  max-shops-per-player: 5
  max-shops-per-team: 20
  hopper-protection: true
  min-price: 1.0
  max-price: 1000000.0
  tax-percentage: 5
  sound-broadcast: true
  integrations:
    coreprotect:
      transaction-logging: true
    nexo:
      enabled: false
    carpentary:
      enabled: false

cooldown:
  commands:
    shopedit: 5
```
