S

Create time-limited items via config. The give command "sga give player item-id" will display the item's expiration time in the action bar only while you are holding the item. The warning message in the action bar can be customized via config. Excellentenchants,excellentcrates supported.

Kodari AI
KodariMay 11 at 6:53 pm 13,039 (v2)

I’ll create a time-limited items plugin with action bar expiration warnings and support for ExcellentEnchants/ExcellentCrates.

SGAItems
Time-limited item management system that creates expiring items via configuration. Items display remaining time in the action bar while held, with customizable warning messages. Features include: configurable item durations, automatic expiration tracking using persistent data, prevention of expired item usage, and full integration with ExcellentEnchants and ExcellentCrates. Admins can give timed items using the /sga give command.

Perfect! I’ve created the SGAItems plugin with the following features:

Core Features:

  • ✅ Time-limited items configured in items.yml

  • ✅ /sga give <player> <item-id> command to give items

  • ✅ Action bar shows expiration time only while holding the item

  • ✅ Customizable action bar message in config.yml

  • ✅ ExcellentEnchants and ExcellentCrates support detection

  • ✅ Automatic expiration checking and removal

  • ✅ Prevents use of expired items (interact, break, attack, consume)

Key Components:

  1. ItemManager - Creates items with PDC expiration timestamps, checks expiration

  2. ItemHoldListener - Shows action bar timer only when holding item (task auto-cancels on item switch)

  3. ItemInteractListener - Blocks all interactions with expired items

  4. ConfigManager - Loads items.yml and config.yml

  5. XSeries - Cross-version material/enchantment compatibility

Configuration:

  • config.yml - Action bar message, update interval, expired message

  • items.yml - Define items with material, lore, duration, enchantments, and optional ExcellentEnchants

The action bar updates at configurable intervals (default 0.5s) and automatically stops when the player switches items or logs off.

Kodari can make mistakes. Review important code before using.
Files
src
.gitignore
build.gradle
settings.gradle
Code
14 916
src/main/java/dev/sgaitems/SGAItems.java
package dev.sgaitems;

import dev.sgaitems.commands.SGACommand;
import dev.sgaitems.listeners.ItemHoldListener;
import dev.sgaitems.listeners.ItemInteractListener;
import dev.sgaitems.managers.ConfigManager;
import dev.sgaitems.managers.ItemManager;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

@Getter
public class SGAItems extends JavaPlugin {
    
    private ConfigManager configManager;
    private ItemManager itemManager;
    
    private boolean excellentEnchantsEnabled;
    private boolean excellentCratesEnabled;

    @Override
    public void onEnable() {
        configManager = new ConfigManager(this);
        configManager.loadConfigs();
        
        itemManager = new ItemManager(this);
        
        checkPluginSupport();
        
        registerCommands();
        registerListeners();
        
        startExpirationCheckTask();
        
        getLogger().info("SGAItems has been enabled!");
        if (excellentEnchantsEnabled) {
            getLogger().info("ExcellentEnchants support enabled");
        }
        if (excellentCratesEnabled) {
            getLogger().info("ExcellentCrates support enabled");
        }
    }

    @Override
    public void onDisable() {
        getLogger().info("SGAItems has been disabled!");
    }
    
    private void checkPluginSupport() {
        excellentEnchantsEnabled = getConfig().getBoolean("support.excellent-enchants", true) 
            && Bukkit.getPluginManager().getPlugin("ExcellentEnchants") != null;
        excellentCratesEnabled = getConfig().getBoolean("support.excellent-crates", true) 
            && Bukkit.getPluginManager().getPlugin("ExcellentCrates") != null;
    }
    
    private void registerCommands() {
        getCommand("sga").setExecutor(new SGACommand(this));
    }
    
    private void registerListeners() {
        getServer().getPluginManager().registerEvents(new ItemHoldListener(this), this);
        getServer().getPluginManager().registerEvents(new ItemInteractListener(this), this);
    }
    
    private void startExpirationCheckTask() {
        Bukkit.getScheduler().runTaskTimer(this, () -> {
            Bukkit.getOnlinePlayers().forEach(player -> {
                itemManager.checkAndRemoveExpiredItems(player);
            });
        }, 20L, 20L);
    }
}