# CommunityMarket

A professional, production-ready GUI-only marketplace plugin for Minecraft Paper 1.21.11.

Players can create fixed-price listings and auctions, browse, buy, bid, claim items, and withdraw earnings — all through intuitive GUIs. No complex commands to learn!

## Features

### 🛒 Fixed-Price Market
- Create listings with custom prices and durations
- Browse paginated listings with categories and sorting
- Safe atomic purchases to prevent double-buying
- Configurable taxes on sales

### 🔨 Auction System
- Start auctions with minimum bid and optional buyout
- Anti-snipe protection extends auction when bids arrive near the end
- Bid history and automatic outbid notifications
- Safe handling of auction endings and payouts

### 📦 Claim Storage
- Items from expired listings go to claim storage
- Won auction items are safely delivered
- Handles full inventories gracefully

### 💰 Earnings Management
- Pending earnings from sales
- Withdraw all at once
- Complete transaction history

### 🔐 Admin Features (GUI-based)
- View all listings and auctions
- Remove any listing
- Cancel/force-end auctions
- Reload configuration

### 🎮 Intuitive GUI Flow
The creation flow for listings and auctions:
1. **Main Menu** - Central hub for all actions
2. **Select Item** - Click an item from your inventory to select it
3. **Select Quantity** - Choose how many to sell (for stackable items with quantity > 1)
   - Step buttons: -32, -16, -8, -1 and +1, +8, +16, +32
   - MIN and MAX preset buttons for quick selection
   - Items are matched by exact metadata (material, name, lore, enchants, custom model data)
4. **Settings** - Set price and duration with merged, clickable elements
   - Single-item interface: each setting is one clickable item showing all info
   - No redundant info/action item pairs
5. **Confirm** - Review and confirm your listing/auction
   - Final validation ensures items still exist before creating

## Requirements

- **Server**: Paper 1.21.11 (or compatible)
- **Java**: Java 21
- **Economy**: One of the following:
  - Vault + any Vault-compatible economy (Essentials, CMI, etc.)
  - EssentialsX (fallback if Vault is not present)

## Installation

1. Download `CommunityMarket-1.0.0.jar`
2. Place it in your server's `plugins/` folder
3. Ensure you have an economy plugin installed (Vault recommended)
4. Start/restart your server
5. Edit `plugins/CommunityMarket/config.yml` as needed
6. Use `/market` to open the marketplace!

## Commands

| Command | Alias | Description | Permission |
|---------|-------|-------------|------------|
| `/market` | `/cmarket` | Opens the main market GUI | `communitymarket.use` |

**That's it!** Everything else is done through GUIs.

## Permissions

| Permission | Description | Default |
|------------|-------------|---------|
| `communitymarket.*` | All permissions | op |
| `communitymarket.use` | Access the market GUI | true |
| `communitymarket.sell` | Create fixed-price listings | true |
| `communitymarket.auction` | Create auctions | true |
| `communitymarket.buy` | Purchase from the market | true |
| `communitymarket.bid` | Bid on auctions | true |
| `communitymarket.claim` | Claim items from storage | true |
| `communitymarket.withdraw` | Withdraw earnings | true |
| `communitymarket.admin` | Access admin functions | op |
| `communitymarket.admin.viewall` | View all listings/auctions | op |
| `communitymarket.admin.remove` | Remove any listing/auction | op |
| `communitymarket.admin.reload` | Reload configuration | op |

## Configuration

### config.yml

```yaml
# Language setting (available: en_US, pt_PT)
language: en_US

# Database Configuration
database:
  type: sqlite  # or "mysql"
  sqlite:
    file: database.db
  mysql:
    host: localhost
    port: 3306
    database: communitymarket
    username: root
    password: ""

# Economy Settings
economy:
  currency-format: "$#,##0.00"
  currency-symbol: "$"
  taxes:
    market-tax: 5.0      # 5% tax on listings
    auction-tax: 7.5     # 7.5% tax on auctions

# Market Settings
market:
  max-listings-per-player: 20
  listing-cooldown: 0    # seconds between listings
  default-duration-hours: 168  # 7 days
  min-price: 1.0
  max-price: 1000000000.0

# Auction Settings
auction:
  max-auctions-per-player: 10
  min-duration-hours: 1
  max-duration-hours: 168
  anti-snipe:
    enabled: true
    trigger-seconds: 30
    extension-seconds: 30
    max-extensions: 10

# GUI Settings
gui:
  items-per-page: 45
  show-help-button: true  # Set to false to hide help button in main menu
```

See the full `config.yml` for all options.

### Languages

CommunityMarket ships with two languages:
- **English (US)**: `en_US`
- **Portuguese (Portugal)**: `pt_PT`

Change the language in `config.yml`:
```yaml
language: pt_PT
```

You can create custom language files by copying an existing one in `plugins/CommunityMarket/lang/`.

## Building from Source

```bash
git clone https://github.com/henrique/CommunityMarket.git
cd CommunityMarket
mvn clean package
```

The compiled JAR will be in `target/CommunityMarket-1.0.0.jar`.

## FAQ

### Q: The plugin says "No economy plugin found!"
**A:** Install Vault + an economy plugin (like EssentialsX) or just EssentialsX.

### Q: Can I use MySQL instead of SQLite?
**A:** Yes! Change `database.type` to `mysql` in config.yml and fill in your credentials.

### Q: How do I change the GUI titles?
**A:** Edit the language file in `plugins/CommunityMarket/lang/`.

### Q: Items aren't being removed when creating listings?
**A:** This is a known issue with some inventory plugins. Make sure you're running Paper 1.21.11.

### Q: How do taxes work?
**A:** When an item sells, the tax percentage is deducted from the seller's earnings. Buyers pay the listed price.

## Support

- **Issues**: [GitHub Issues](https://github.com/henrique/CommunityMarket/issues)
- **Discord**: Coming soon

## License

MIT License - See LICENSE file for details.

---

Made with ❤️ for the Minecraft community

