package cat.nyaa.nyaautils.signedit;

import org.bukkit.block.Sign;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta;

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

public class SignContent {
    private List<String> content = new ArrayList<>();

    public SignContent() {

    }

    public static SignContent fromItemStack(ItemStack item) {
        SignContent content = new SignContent();
        if (item.hasItemMeta() && item.getItemMeta() instanceof BlockStateMeta) {
            BlockStateMeta blockStateMeta = (BlockStateMeta) item.getItemMeta();
            if (blockStateMeta.hasBlockState() && blockStateMeta.getBlockState() instanceof Sign) {
                Sign sign = ((Sign) blockStateMeta.getBlockState());
                for (int i = 0; i < 4; i++) {
                    content.setLine(i, sign.getLine(i));
                }
            }
        }
        return content;
    }

    public void setLine(int line, String text) {
        if (line >= content.size()) {
            content.add(text);
            return;
        }
        content.set(line, text);
    }

    public String getLine(int line) {
        if (line >= content.size()) {
            return "";
        }
        return content.get(line);
    }

    public List<String> getContent() {
        return content;
    }

    public ItemStack toItemStack(ItemStack item) {
        if (item.getItemMeta() instanceof BlockStateMeta) {
            BlockStateMeta blockStateMeta = (BlockStateMeta) item.getItemMeta();
            if (blockStateMeta.getBlockState() instanceof Sign) {
                Sign sign = ((Sign) blockStateMeta.getBlockState());
                for (int i = 0; i < 4; i++) {
                    sign.setLine(i, getLine(i));
                }
                blockStateMeta.setBlockState(sign);
            }
            item.setItemMeta(blockStateMeta);
        }
        return item;
    }
}

@@ -178,16 +178,41 @@
 ayList;%0A
+import java.util.Arrays;%0A
 import j
@@ -305,16 +305,45 @@
 yList%3C%3E(
+Arrays.asList(%22%22, %22%22, %22%22, %22%22)
 );%0A%0A    

fix SignEdit