Gijan Emerie Yap

Make all the sword into hoes

Kodari AI
KodariOct 10 at 10:15 am 1
SwordToHoeTransformer
Transforms all swords into hoes in Minecraft. Listens for item pickup, inventory changes, and crafting events, replacing any sword item with an equivalent hoe. Preserves enchantments, durability, and custom names during transformation. Provides configurable settings to control which sword types convert, whether to affect equipped items, and optional chat notifications. Includes a command to manually convert all swords in a player's inventory. Works seamlessly with both iron, gold, diamond, and netherite sword variants, maintaining the same material tier for the resulting hoe.
  1. Create a Paper plugin that converts each sword type to its matching hoe.

  2. Convert swords in current players’ inventories on join and periodically, so newly acquired swords are handled too.

  3. Add the project’s Gradle and plugin metadata.

Created SwordToHoes: it converts player-inventory swords into the matching hoes when players join and checks inventories every second.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 95
src/main/java/com/kodari/swordtohoes/SwordToHoesPlugin.java
package com.kodari.swordtohoes;

import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Map;

public final class SwordToHoesPlugin extends JavaPlugin implements Listener {
    private static final Map<String, String> SWORD_TO_HOE = Map.of(
            "WOODEN_SWORD", "WOODEN_HOE",
            "STONE_SWORD", "STONE_HOE",
            "IRON_SWORD", "IRON_HOE",
            "GOLDEN_SWORD", "GOLDEN_HOE",
            "DIAMOND_SWORD", "DIAMOND_HOE",
            "NETHERITE_SWORD", "NETHERITE_HOE"
    );

    @Override
    public void onEnable() {
        Bukkit.getPluginManager().registerEvents(this, this);
        Bukkit.getOnlinePlayers().forEach(this::convertInventory);
        Bukkit.getScheduler().runTaskTimer(this,
                () -> Bukkit.getOnlinePlayers().forEach(this::convertInventory), 1L, 20L);
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        convertInventory(event.getPlayer());
    }

    private void convertInventory(Player player) {
        ItemStack[] contents = player.getInventory().getContents();
        boolean changed = false;

        for (ItemStack item : contents) {
            if (item == null) {
                continue;
            }

            String hoeName = SWORD_TO_HOE.get(XMaterial.matchXMaterial(item.getType()).name());
            if (hoeName == null) {
                continue;
            }

            Material hoe = XMaterial.matchXMaterial(hoeName)
                    .map(XMaterial::parseMaterial)
                    .orElse(null);
            if (hoe != null) {
                item.setType(hoe);
                changed = true;
            }
        }

        if (changed) {
            player.getInventory().setContents(contents);
        }
    }
}