witeku

Napisz plugin który będzie blokował podane w configu wymiany z villagerami. Po wpisaniu komendy /wiesniaki lista, pokażą się wszystkie przedmioty których nie da się kupić od villagerów

Kodari AI
KodariApr 25 at 11:34 pm 4,878 (v2)

I’ll create a plugin that blocks configured villager trades and provides a command to list blocked items.

VillagerTradeBlocker
A Minecraft plugin that prevents players from trading specific items with villagers. Server admins can configure which items should be blocked through the config file. Players attempting blocked trades will be denied. The plugin includes a command to display all currently blocked items, making it easy to inform players about trade restrictions. Perfect for balancing economy on survival servers.

Plugin created! This is a complete villager trade blocking system.

Features:

  • Blocks villagers from acquiring trades that offer configured items

  • Command /wiesniaki lista (or list) shows all blocked items

  • Tab completion support

  • Cross-version compatibility via XSeries

  • Configurable messages with color codes

How it works:

  • Listens to VillagerAcquireTradeEvent and cancels trades before villagers even offer them

  • Players won’t see blocked trades in villager trading interfaces

  • Default blocked items: diamonds, emerald blocks, netherite ingots, enchanted golden apples, totems

The command supports both Polish (lista) and English (list) for broader usability.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
6 223
src/main/java/com/villagerblock/plugin/VillagerTradeBlocker.java
package com.villagerblock.plugin;

import com.cryptomorin.xseries.XMaterial;
import lombok.Getter;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
import java.util.List;

public class VillagerTradeBlocker extends JavaPlugin {

    @Getter
    private List<XMaterial> blockedMaterials;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        loadBlockedItems();
        
        getServer().getPluginManager().registerEvents(new TradeListener(this), this);
        getCommand("wiesniaki").setExecutor(new WiesniakyCommand(this));
        
        getLogger().info("VillagerTradeBlocker enabled with " + blockedMaterials.size() + " blocked items.");
    }

    @Override
    public void onDisable() {
        getLogger().info("VillagerTradeBlocker disabled.");
    }

    private void loadBlockedItems() {
        blockedMaterials = new ArrayList<>();
        List<String> configItems = getConfig().getStringList("blocked-items");
        
        for (String itemName : configItems) {
            XMaterial.matchXMaterial(itemName).ifPresent(blockedMaterials::add);
        }
    }

    public void reloadBlockedItems() {
        reloadConfig();
        loadBlockedItems();
    }

    public String getMessage(String key) {
        return getConfig().getString("messages." + key, "&cMessage not found: " + key)
                .replace("&", "§");
    }
}