Owen St John

make me a plugin named Swap Rewind - Obros. the plugin brings back all atribute swapping features, fixes any water bugs to normal, fixes tick speeds so cobblestone tnt duping farms dont explode and adds tnt and carpet duping. make sure it adds attribute swapping.

Kodari AI
KodariOct 19 at 11:09 pm 1
SwapRewindObros
Restores attribute swapping for tools and armor via commands. Fixes water physics so flowing water behaves normally, preventing cobblestone generators from overflowing. Adjusts tick speeds to stabilize TNT-based cobblestone duplicators, preventing explosions from rapid block updates. Adds TNT duplication mechanics for classic contraptions and carpet duplication for automation. Integrates all features into a single configurable plugin supporting Bukkit and Spigot servers, with permission nodes and toggleable settings for each module.
  1. Add the plugin scaffold and configuration.

  2. Implement main/offhand attribute-modifier swapping and TNT/carpet piston duping.

  3. Keep vanilla water behavior, normalize random tick speed, and protect farm components from TNT damage.

Created Swap Rewind - Obros with:

  • /swaprewind attributes to swap attribute modifiers between the items in your main and offhand.

  • TNT and carpet duplication when pistons push them into coral fans; duplicated TNT uses the configured fuse.

  • A default randomTickSpeed of 3, plus protection for redstone and piston components from TNT block damage. Farm output blocks remain destructible.

  • No water-flow overrides, so water behavior remains native to the server.

  • Configuration in config.yml; use /swaprewind reload to reload it.

Owen St John

by ticks i ment lag, dont fix hoppers or any settings in server.properties, spigot.yml, world defaults or global. dont touch anything that isnt bringing back attribute swapping. erase everything else

Kodari AI
KodariOct 19 at 11:14 pm 1
  • Keep only main-hand/offhand attribute-modifier swapping.

  • Remove TNT/carpet duplication, tick-speed changes, explosion protection, reload/config behavior.

  • Update the plugin command metadata; leave server and world settings untouched.

Removed everything except attribute swapping via /swaprewind attributes, which swaps the attribute modifiers on the items in your main hand and offhand. Removed the duplication, tick-speed, explosion-protection, reload, and config features; no server or world settings were changed.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 119
src/main/java/com/obros/swaprewind/SwapRewindPlugin.java
package com.obros.swaprewind;

import org.bukkit.ChatColor;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public final class SwapRewindPlugin extends JavaPlugin implements CommandExecutor {
    @Override
    public void onEnable() {
        getCommand("swaprewind").setExecutor(this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (args.length != 1 || !(args[0].equalsIgnoreCase("attributes")
                || args[0].equalsIgnoreCase("swapattributes"))) {
            sender.sendMessage(ChatColor.YELLOW + "Usage: /swaprewind attributes");
            return true;
        }

        if (!(sender instanceof Player player)) {
            sender.sendMessage("This command can only be used by a player.");
            return true;
        }

        ItemStack mainHand = player.getInventory().getItemInMainHand();
        ItemStack offHand = player.getInventory().getItemInOffHand();
        if (mainHand.getType().isAir() || offHand.getType().isAir()) {
            player.sendMessage(ChatColor.RED + "Hold an item in each hand to swap their attributes.");
            return true;
        }

        ItemMeta mainMeta = mainHand.getItemMeta();
        ItemMeta offMeta = offHand.getItemMeta();
        if (mainMeta == null || offMeta == null) {
            player.sendMessage(ChatColor.RED + "Those items do not support attribute modifiers.");
            return true;
        }

        Map<Attribute, List<AttributeModifier>> mainAttributes = readAttributes(mainMeta);
        Map<Attribute, List<AttributeModifier>> offAttributes = readAttributes(offMeta);
        writeAttributes(mainMeta, offAttributes);
        writeAttributes(offMeta, mainAttributes);
        mainHand.setItemMeta(mainMeta);
        offHand.setItemMeta(offMeta);
        player.getInventory().setItemInMainHand(mainHand);
        player.getInventory().setItemInOffHand(offHand);
        player.sendMessage(ChatColor.GREEN + "Swapped attribute modifiers between your main-hand and off-hand items.");
        return true;
    }

    private Map<Attribute, List<AttributeModifier>> readAttributes(ItemMeta meta) {
        Map<Attribute, List<AttributeModifier>> attributes = new LinkedHashMap<>();
        var modifiers = meta.getAttributeModifiers();
        if (modifiers != null) {
            for (var entry : modifiers.entries()) {
                attributes.computeIfAbsent(entry.getKey(), ignored -> new ArrayList<>()).add(entry.getValue());
            }
        }
        return attributes;
    }

    private void writeAttributes(ItemMeta meta, Map<Attribute, List<AttributeModifier>> attributes) {
        meta.setAttributeModifiers(null);
        for (Map.Entry<Attribute, List<AttributeModifier>> entry : attributes.entrySet()) {
            for (AttributeModifier modifier : entry.getValue()) {
                meta.addAttributeModifier(entry.getKey(), modifier);
            }
        }
    }
}