Search in sources :

Example 6 with NBTBase

use of net.minecraft.server.v1_13_R2.NBTBase in project MyPet by xXKeyleXx.

the class ConfigItem method load.

public void load(String data) {
    NBTBase nbtBase = null;
    if (data.contains("{")) {
        String tagString = data.substring(data.indexOf("{"));
        data = data.substring(0, data.indexOf("{"));
        try {
            nbtBase = MojangsonParser.parse(tagString);
        } catch (Exception e) {
            MyPetApi.getLogger().warning(ChatColor.RED + "Error" + ChatColor.RESET + " in config: " + ChatColor.YELLOW + e.getLocalizedMessage() + ChatColor.RESET + " caused by:");
            MyPetApi.getLogger().warning(data + tagString);
        }
    }
    String[] splitData = data.split("\\s+");
    if (splitData.length == 0) {
        return;
    }
    Item item = null;
    if (splitData.length >= 1) {
        if (Util.isInt(splitData[0])) {
            int itemId = Integer.parseInt(splitData[0]);
            item = Item.getById(itemId);
        } else {
            item = (Item) Item.REGISTRY.get(splitData[0]);
        }
    }
    if (item != null) {
        int itemDamage = 0;
        if (splitData.length >= 2) {
            if (splitData[1].startsWith("<")) {
                this.durabilityMode = DurabilityMode.Smaller;
                splitData[1] = splitData[1].substring(1);
            } else if (splitData[1].startsWith(">")) {
                this.durabilityMode = DurabilityMode.Bigger;
                splitData[1] = splitData[1].substring(1);
            } else {
                this.durabilityMode = DurabilityMode.Equal;
            }
            if (Util.isInt(splitData[1])) {
                itemDamage = Integer.parseInt(splitData[1]);
            }
        }
        net.minecraft.server.v1_7_R4.ItemStack is = new net.minecraft.server.v1_7_R4.ItemStack(item, 1, itemDamage);
        if (nbtBase != null) {
            is.setTag((NBTTagCompound) nbtBase);
        }
        this.item = CraftItemStack.asBukkitCopy(is);
    }
}
Also used : Item(net.minecraft.server.v1_7_R4.Item) NBTBase(net.minecraft.server.v1_7_R4.NBTBase) CraftItemStack(org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 7 with NBTBase

use of net.minecraft.server.v1_13_R2.NBTBase in project MechanicsMain by WeaponMechanics.

the class NBT_1_14_R1 method visit.

private StringBuilder visit(NBTTagCompound nbt, int indents, int colorOffset) {
    String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length());
    StringBuilder builder = new StringBuilder(braceColor).append('{');
    List<String> keys = new ArrayList<>(nbt.getKeys());
    Collections.sort(keys);
    for (int i = 0; i < keys.size(); i++) {
        String key = keys.get(i);
        NBTBase value = Objects.requireNonNull(nbt.get(key), "This is impossible");
        if (i != 0)
            builder.append('\n');
        builder.append(StringUtil.repeat("  ", indents));
        String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length());
        builder.append(color).append(key).append("&f&l: ").append(color);
        if (value instanceof NBTTagCompound)
            builder.append(visit((NBTTagCompound) value, indents + 1, colorOffset + i));
        else
            builder.append(value);
    }
    return builder.append(braceColor).append("}\n");
}
Also used : NBTBase(net.minecraft.server.v1_14_R1.NBTBase) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.server.v1_14_R1.NBTTagCompound)

Example 8 with NBTBase

use of net.minecraft.server.v1_13_R2.NBTBase in project MechanicsMain by WeaponMechanics.

the class NBT_1_15_R1 method visit.

private StringBuilder visit(NBTTagCompound nbt, int indents, int colorOffset) {
    String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length());
    StringBuilder builder = new StringBuilder(braceColor).append('{');
    List<String> keys = new ArrayList<>(nbt.getKeys());
    Collections.sort(keys);
    for (int i = 0; i < keys.size(); i++) {
        String key = keys.get(i);
        NBTBase value = Objects.requireNonNull(nbt.get(key), "This is impossible");
        if (i != 0)
            builder.append('\n');
        builder.append(StringUtil.repeat("  ", indents));
        String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length());
        builder.append(color).append(key).append("&f&l: ").append(color);
        if (value instanceof NBTTagCompound)
            builder.append(visit((NBTTagCompound) value, indents + 1, colorOffset + i));
        else
            builder.append(value);
    }
    return builder.append(braceColor).append("}\n");
}
Also used : NBTBase(net.minecraft.server.v1_15_R1.NBTBase) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.server.v1_15_R1.NBTTagCompound)

Example 9 with NBTBase

use of net.minecraft.server.v1_13_R2.NBTBase in project MechanicsMain by WeaponMechanics.

the class NBT_1_16_R3 method visit.

private StringBuilder visit(NBTTagCompound nbt, int indents, int colorOffset) {
    String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length());
    StringBuilder builder = new StringBuilder(braceColor).append('{');
    List<String> keys = new ArrayList<>(nbt.getKeys());
    Collections.sort(keys);
    for (int i = 0; i < keys.size(); i++) {
        String key = keys.get(i);
        NBTBase value = Objects.requireNonNull(nbt.get(key), "This is impossible");
        if (i != 0)
            builder.append('\n');
        builder.append(StringUtil.repeat("  ", indents));
        String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length());
        builder.append(color).append(key).append("&f&l: ").append(color);
        if (value instanceof NBTTagCompound)
            builder.append(visit((NBTTagCompound) value, indents + 1, colorOffset + i));
        else
            builder.append(value);
    }
    return builder.append(braceColor).append("}\n");
}
Also used : NBTBase(net.minecraft.server.v1_16_R3.NBTBase) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.server.v1_16_R3.NBTTagCompound)

Example 10 with NBTBase

use of net.minecraft.server.v1_13_R2.NBTBase in project MechanicsMain by WeaponMechanics.

the class NBT_1_13_R2 method visit.

private StringBuilder visit(NBTTagCompound nbt, int indents, int colorOffset) {
    String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length());
    StringBuilder builder = new StringBuilder(braceColor).append('{');
    List<String> keys = new ArrayList<>(nbt.getKeys());
    Collections.sort(keys);
    for (int i = 0; i < keys.size(); i++) {
        String key = keys.get(i);
        NBTBase value = Objects.requireNonNull(nbt.get(key), "This is impossible");
        if (i != 0)
            builder.append('\n');
        builder.append(StringUtil.repeat("  ", indents));
        String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length());
        builder.append(color).append(key).append("&f&l: ").append(color);
        if (value instanceof NBTTagCompound)
            builder.append(visit((NBTTagCompound) value, indents + 1, colorOffset + i));
        else
            builder.append(value);
    }
    return builder.append(braceColor).append("}\n");
}
Also used : NBTBase(net.minecraft.server.v1_13_R2.NBTBase) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.server.v1_13_R2.NBTTagCompound)

Aggregations

ArrayList (java.util.ArrayList)10 NBTBase (net.minecraft.server.v1_16_R3.NBTBase)2 NBTBase (net.minecraft.server.v1_10_R1.NBTBase)1 NBTTagCompound (net.minecraft.server.v1_10_R1.NBTTagCompound)1 NBTBase (net.minecraft.server.v1_11_R1.NBTBase)1 NBTTagCompound (net.minecraft.server.v1_11_R1.NBTTagCompound)1 NBTBase (net.minecraft.server.v1_12_R1.NBTBase)1 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)1 NBTBase (net.minecraft.server.v1_13_R2.NBTBase)1 NBTTagCompound (net.minecraft.server.v1_13_R2.NBTTagCompound)1 NBTBase (net.minecraft.server.v1_14_R1.NBTBase)1 NBTTagCompound (net.minecraft.server.v1_14_R1.NBTTagCompound)1 NBTBase (net.minecraft.server.v1_15_R1.NBTBase)1 NBTTagCompound (net.minecraft.server.v1_15_R1.NBTTagCompound)1 NBTBase (net.minecraft.server.v1_16_R2.NBTBase)1 NBTTagCompound (net.minecraft.server.v1_16_R3.NBTTagCompound)1 Item (net.minecraft.server.v1_7_R4.Item)1 NBTBase (net.minecraft.server.v1_7_R4.NBTBase)1 NBTBase (net.minecraft.server.v1_9_R2.NBTBase)1 NBTTagCompound (net.minecraft.server.v1_9_R2.NBTTagCompound)1