greatestbanana13

ItemLimiter Per Chunk

Author: Dexer

ItemLimiter Per Chunk is a Minecraft plugin that allows server owners to control how many specific items can be dropped within each chunk. Using a simple configuration file, you can whitelist items by their official Minecraft item IDs (such as BONE, SEA_PICKLE, etc.) and set a maximum drop limit per chunk.

Once the limit is reached, no additional items of that type can be dropped in the same chunk, helping to reduce lag and prevent item farming abuse.

Configuration Example LIMITED-ITEMS:

BONE: 1000

This example limits BONE drops to 1,000 per chunk.

When the player picks up the items or the items disappear in the chunk the entity limiter also goes down too so it doesnt bug out and add a messages.yml file where you can edit everything what it says when you reach the limit and the /itemlimiter check command and add a /itemlimiter reload command

Kodari AI
KodariJan 1 at 4:48 pm 6,129 (v2)

Iโ€™ll create an item limiter plugin that tracks and limits item drops per chunk with configurable messages and admin commands.

ItemLimiterPerChunk
A chunk-based item drop limiter that prevents excessive item farming and reduces server lag. Configure maximum drop limits for specific items per chunk, with automatic counter reduction when items are picked up or despawn. Includes customizable messages and admin commands for monitoring and management. Helps maintain server performance by controlling item entity spawning in high-activity areas.

Plugin created with all requested features:

Core Features:

  • Tracks item drops per chunk per material type

  • Prevents drops when limit is reached

  • Auto-decrements counters when items are picked up or despawn

  • XSeries for cross-version material compatibility

Commands:

  • /itemlimiter check - Shows current chunkโ€™s item counts and limits

  • /itemlimiter reload - Reloads both config.yml and messages.yml

Permissions:

  • itemlimiter.admin - Access to all commands

  • itemlimiter.bypass - Bypass drop limits (wonโ€™t see limit messages)

Configuration:

  • config.yml - Define limited items and their max counts

  • messages.yml - Fully customizable messages with placeholders

The tracker uses concurrent data structures for thread safety and automatically cleans up empty entries to prevent memory leaks.

greatestbanana13

The compilation failed with this error:

code
Validation failed for compilation: Compilation failed with 9 error(s):

ERROR in src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java at line 32: incompatible types: XMaterial cannot be converted to Optional<XMaterial>
        Optional<XMaterial> materialOpt = XMaterial.matchXMaterial(itemStack);
                                                                  ^

ERROR in src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java at line 72: incompatible types: XMaterial cannot be converted to Optional<XMaterial>
        Optional<XMaterial> materialOpt = XMaterial.matchXMaterial(itemStack);
                                                                  ^

ERROR in src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java at line 93: incompatible types: XMaterial cannot be converted to Optional<XMaterial>
        Optional<XMaterial> materialOpt = XMaterial.matchXMaterial(itemStack);
                                                                  ^

ERROR in   src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java at line 32: incompatible types: XMaterial cannot be converted to Optional<XMaterial>
          Optional<XMaterial> materialOpt = XMaterial.matchXMaterial(itemStack);
                                                                    ^

ERROR in   src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java at line 72: incompatible types: XMaterial cannot be converted to Optional<XMaterial>
          Optional<XMaterial> materialOpt = XMaterial.matchXMaterial(itemStack);
                                                                    ^

ERROR in   src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java at line 93: incompatible types: XMaterial cannot be converted to Optional<XMaterial>
          Optional<XMaterial> materialOpt = XMaterial.matchXMaterial(itemStack);
                                                                    ^

ERROR in src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java at line 32: incompatible types: XMaterial cannot be converted to Optional<XMaterial>
        Optional<XMaterial> materialOpt = XMaterial.matchXMaterial(itemStack);
                                                                  ^

ERROR in src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java at line 72: incompatible types: XMaterial cannot be converted to Optional<XMaterial>
        Optional<XMaterial> materialOpt = XMaterial.matchXMaterial(itemStack);
                                                                  ^

ERROR in src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java at line 93: incompatible types: XMaterial cannot be converted to Optional<XMaterial>
        Optional<XMaterial> materialOpt = XMaterial.matchXMaterial(itemStack);
                                                                  ^


=== COMPILATION ERROR ANALYSIS ===

TYPE MISMATCHES:
  - incompatible types: XMaterial cannot be converted to Optional<XMaterial>
  - incompatible types: XMaterial cannot be converted to Optional<XMaterial>
  - incompatible types: XMaterial cannot be converted to Optional<XMaterial>
  - incompatible types: XMaterial cannot be converted to Optional<XMaterial>
  - incompatible types: XMaterial cannot be converted to Optional<XMaterial>
  - incompatible types: XMaterial cannot be converted to Optional<XMaterial>
  - incompatible types: XMaterial cannot be converted to Optional<XMaterial>
  - incompatible types: XMaterial cannot be converted to Optional<XMaterial>
  - incompatible types: XMaterial cannot be converted to Optional<XMaterial>
ACTION: Fix variable types or casting

FILES TO INVESTIGATE:
  - src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java
  -   src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java
 exceeds maximum 

Please fix this error by creating a new artifact with the corrected code.

Kodari AI
KodariJan 1 at 4:49 pm 4,937 (v2)

I need to read the ItemEventListener.java file to see the exact issue with the XMaterial usage.

The issue is clear: XMaterial.matchXMaterial(itemStack) expects a String or Material, not an ItemStack. I need to get the Material from the ItemStack first.

Fixed: Changed XMaterial.matchXMaterial(itemStack) to XMaterial.matchXMaterial(itemStack.getType()) on lines 32, 72, and 93. XMaterial.matchXMaterial expects a Material or String, not an ItemStack.

greatestbanana13

The compilation failed with this error:

code
Validation failed for compilation: Compilation failed with 51 error(s):

ERROR in src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java at line 12: class ItemLimiterPlugin is public, should be declared in a file named ItemLimiterPlugin.java
public class ItemLimiterPlugin extends JavaPlugin {
       ^

ERROR in src/main/java/com/dexer/itemlimiter/ItemLimiterPlugin.java at line 5: package com.dexer.itemlimiter.listener does not exist
import com.dexer.itemlimiter.listener.ItemEventListener;
                                     ^

ERROR in src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java at line 5: package com.dexer.itemlimiter.listener does not exist
import com.dexer.itemlimiter.listener.ItemEventListener;
                                     ^

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 24: cannot find symbol
            sender.sendMessage(plugin.getConfigManager().getMessage("no-permission"));
                                     ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 52: cannot find symbol
            sender.sendMessage(plugin.getConfigManager().getMessage("prefix") + "&cOnly players can use this command!");
                                     ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 59: cannot find symbol
        Map<XMaterial, Integer> chunkData = plugin.getChunkItemTracker().getChunkData(chunk);
                                                  ^
  symbol: method getChunkItemTracker()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 61: cannot find symbol
        sender.sendMessage(plugin.getConfigManager().getMessageRaw("check-header"));
                                 ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 64: cannot find symbol
            sender.sendMessage(plugin.getConfigManager().getMessageRaw("check-no-limits"));
                                     ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 69: cannot find symbol
                Integer maxLimit = plugin.getConfigManager().getLimit(material);
                                         ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 77: cannot find symbol
                String message = plugin.getConfigManager().getMessageRaw("check-item")
                                       ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 87: cannot find symbol
        sender.sendMessage(plugin.getConfigManager().getMessageRaw("check-footer"));
                                 ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 91: cannot find symbol
        plugin.getConfigManager().loadConfigs();
              ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 92: cannot find symbol
        sender.sendMessage(plugin.getConfigManager().getMessage("reload-success"));
                                 ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 96: cannot find symbol
        sender.sendMessage(plugin.getConfigManager().getMessage("prefix") + "&eItemLimiter Commands:");
                                 ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/ItemLimiterPlugin.java at line 24: cannot find symbol
        ItemEventListener itemListener = new ItemEventListener(this);
        ^
  symbol: class ItemEventListener
  location: class ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/ItemLimiterPlugin.java at line 24: cannot find symbol
        ItemEventListener itemListener = new ItemEventListener(this);
                                             ^
  symbol: class ItemEventListener
  location: class ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/tracker/ChunkItemTracker.java at line 70: cannot find symbol
        Integer limit = plugin.getConfigManager().getLimit(material);
                              ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in   src/main/java/com/dexer/itemlimiter/ItemLimiterPlugin.java at line 24: cannot find symbol
          ItemEventListener itemListener = new ItemEventListener(this);
          ^
  symbol: class ItemEventListener
  location: class ItemLimiterPlugin

ERROR in   src/main/java/com/dexer/itemlimiter/ItemLimiterPlugin.java at line 24: cannot find symbol
          ItemEventListener itemListener = new ItemEventListener(this);
                                               ^
  symbol: class ItemEventListener
  location: class ItemLimiterPlugin

ERROR in   src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 24: cannot find symbol
              sender.sendMessage(plugin.getConfigManager().getMessage("no-permission"));
                                       ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in   src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 52: cannot find symbol
              sender.sendMessage(plugin.getConfigManager().getMessage("prefix") + "&cOnly players can use this command!");
                                       ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in   src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 59: cannot find symbol
          Map<XMaterial, Integer> chunkData = plugin.getChunkItemTracker().getChunkData(chunk);
                                                    ^
  symbol: method getChunkItemTracker()
  location: variable plugin of type ItemLimiterPlugin

ERROR in   src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 61: cannot find symbol
          sender.sendMessage(plugin.getConfigManager().getMessageRaw("check-header"));
                                   ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in   src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 64: cannot find symbol
              sender.sendMessage(plugin.getConfigManager().getMessageRaw("check-no-limits"));
                                       ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in   src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 69: cannot find symbol
                  Integer maxLimit = plugin.getConfigManager().getLimit(material);
                                           ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in   src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 77: cannot find symbol
                  String message = plugin.getConfigManager().getMessageRaw("check-item")
                                         ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in   src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 87: cannot find symbol
          sender.sendMessage(plugin.getConfigManager().getMessageRaw("check-footer"));
                                   ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in   src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 91: cannot find symbol
          plugin.getConfigManager().loadConfigs();
                ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in   src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 92: cannot find symbol
          sender.sendMessage(plugin.getConfigManager().getMessage("reload-success"));
                                   ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in   src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 96: cannot find symbol
          sender.sendMessage(plugin.getConfigManager().getMessage("prefix") + "&eItemLimiter Commands:");
                                   ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in   src/main/java/com/dexer/itemlimiter/tracker/ChunkItemTracker.java at line 70: cannot find symbol
          Integer limit = plugin.getConfigManager().getLimit(material);
                                ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in   src/main/java/com/dexer/itemlimiter/ItemLimiterPlugin.java at line 5: package com.dexer.itemlimiter.listener does not exist
  import com.dexer.itemlimiter.listener.ItemEventListener;
                                       ^

ERROR in   src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java at line 5: package com.dexer.itemlimiter.listener does not exist
  import com.dexer.itemlimiter.listener.ItemEventListener;
                                       ^

ERROR in   src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java at line 12: class ItemLimiterPlugin is public, should be declared in a file named ItemLimiterPlugin.java
  public class ItemLimiterPlugin extends JavaPlugin {
         ^

ERROR in src/main/java/com/dexer/itemlimiter/ItemLimiterPlugin.java at line 24: cannot find symbol
        ItemEventListener itemListener = new ItemEventListener(this);
        ^
  symbol: class ItemEventListener
  location: class ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/ItemLimiterPlugin.java at line 24: cannot find symbol
        ItemEventListener itemListener = new ItemEventListener(this);
                                             ^
  symbol: class ItemEventListener
  location: class ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 24: cannot find symbol
            sender.sendMessage(plugin.getConfigManager().getMessage("no-permission"));
                                     ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 52: cannot find symbol
            sender.sendMessage(plugin.getConfigManager().getMessage("prefix") + "&cOnly players can use this command!");
                                     ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 59: cannot find symbol
        Map<XMaterial, Integer> chunkData = plugin.getChunkItemTracker().getChunkData(chunk);
                                                  ^
  symbol: method getChunkItemTracker()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 61: cannot find symbol
        sender.sendMessage(plugin.getConfigManager().getMessageRaw("check-header"));
                                 ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 64: cannot find symbol
            sender.sendMessage(plugin.getConfigManager().getMessageRaw("check-no-limits"));
                                     ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 69: cannot find symbol
                Integer maxLimit = plugin.getConfigManager().getLimit(material);
                                         ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 77: cannot find symbol
                String message = plugin.getConfigManager().getMessageRaw("check-item")
                                       ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 87: cannot find symbol
        sender.sendMessage(plugin.getConfigManager().getMessageRaw("check-footer"));
                                 ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 91: cannot find symbol
        plugin.getConfigManager().loadConfigs();
              ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 92: cannot find symbol
        sender.sendMessage(plugin.getConfigManager().getMessage("reload-success"));
                                 ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java at line 96: cannot find symbol
        sender.sendMessage(plugin.getConfigManager().getMessage("prefix") + "&eItemLimiter Commands:");
                                 ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/tracker/ChunkItemTracker.java at line 70: cannot find symbol
        Integer limit = plugin.getConfigManager().getLimit(material);
                              ^
  symbol: method getConfigManager()
  location: variable plugin of type ItemLimiterPlugin

ERROR in src/main/java/com/dexer/itemlimiter/ItemLimiterPlugin.java at line 5: package com.dexer.itemlimiter.listener does not exist
import com.dexer.itemlimiter.listener.ItemEventListener;
                                     ^

ERROR in src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java at line 5: package com.dexer.itemlimiter.listener does not exist
import com.dexer.itemlimiter.listener.ItemEventListener;
                                     ^

ERROR in src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java at line 12: class ItemLimiterPlugin is public, should be declared in a file named ItemLimiterPlugin.java
public class ItemLimiterPlugin extends JavaPlugin {
       ^


=== COMPILATION ERROR ANALYSIS ===

MISSING CLASSES:
  - ItemEventListener
ACTION: Create these classes or check imports

MISSING METHODS:
  - getConfigManager()
  - getChunkItemTracker()
ACTION: Check method names and signatures

FILES TO INVESTIGATE:
  - src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java
  - src/main/java/com/dexer/itemlimiter/ItemLimiterPlugin.java
  - src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java
  - src/main/java/com/dexer/itemlimiter/tracker/ChunkItemTracker.java
  -   src/main/java/com/dexer/itemlimiter/ItemLimiterPlugin.java
  -   src/main/java/com/dexer/itemlimiter/command/ItemLimiterCommand.java
  -   src/main/java/com/dexer/itemlimiter/tracker/ChunkItemTracker.java
  -   src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java
 exceeds maximum 

Please fix this error by creating a new artifact with the corrected code.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
9 396
src/main/java/com/dexer/itemlimiter/listener/ItemEventListener.java
package com.dexer.itemlimiter;

import com.dexer.itemlimiter.command.ItemLimiterCommand;
import com.dexer.itemlimiter.config.ConfigManager;
import com.dexer.itemlimiter.listener.ItemEventListener;
import com.dexer.itemlimiter.tracker.ChunkItemTracker;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

@Getter
public class ItemLimiterPlugin extends JavaPlugin {
    
    private ConfigManager configManager;
    private ChunkItemTracker chunkItemTracker;
    
    @Override
    public void onEnable() {
        this.configManager = new ConfigManager(this);
        this.configManager.loadConfigs();
        
        this.chunkItemTracker = new ChunkItemTracker(this);
        
        ItemEventListener itemListener = new ItemEventListener(this);
        Bukkit.getPluginManager().registerEvents(itemListener, this);
        
        ItemLimiterCommand command = new ItemLimiterCommand(this);
        getCommand("itemlimiter").setExecutor(command);
        
        getLogger().info("ItemLimiterPerChunk has been enabled!");
    }
    
    @Override
    public void onDisable() {
        getLogger().info("ItemLimiterPerChunk has been disabled!");
    }
}