Search in sources :

Example 1 with SoliniaItem

use of com.solinia.solinia.Models.SoliniaItem in project solinia3-core by mixxit.

the class SoliniaItemFactory method CreateItem.

public static ISoliniaItem CreateItem(ItemStack itemStack, boolean operatorCreated) throws SoliniaItemException, CoreStateInitException {
    SoliniaItem item = new SoliniaItem();
    item.setOperatorCreated(operatorCreated);
    item.setId(StateManager.getInstance().getConfigurationManager().getNextItemId());
    item.setBasename(itemStack.getType().name());
    item.setDisplayname(itemStack.getType().name());
    if (itemStack.getData() != null) {
        try {
            item.setColor(itemStack.getData().getData());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (itemStack.getType().name().equals("SKULL_ITEM")) {
        net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(itemStack);
        NBTTagCompound tag = stack.hasTag() ? stack.getTag() : new NBTTagCompound();
        tag.getCompound("SkullOwner").getString("Id");
        String texturevalue = tag.getCompound("SkullOwner").getCompound("Properties").getList("textures", 10).get(0).getString("Value");
        item.setTexturebase64(texturevalue);
    }
    StateManager.getInstance().getConfigurationManager().addItem(item);
    System.out.println("New Item Added: " + item.getId() + " - " + item.getDisplayname());
    return item;
}
Also used : NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) SoliniaItem(com.solinia.solinia.Models.SoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException)

Example 2 with SoliniaItem

use of com.solinia.solinia.Models.SoliniaItem in project solinia3-core by mixxit.

the class JsonItemRepository method commit.

@Override
public void commit() {
    // TODO Auto-generated method stub
    GsonBuilder gsonbuilder = new GsonBuilder();
    // gsonbuilder.setPrettyPrinting();
    Gson gson = gsonbuilder.create();
    String jsonOutput = gson.toJson(items.values(), new TypeToken<List<SoliniaItem>>() {
    }.getType());
    try {
        File file = new File(filePath);
        if (!file.exists())
            file.createNewFile();
        FileOutputStream fileOut = new FileOutputStream(file);
        OutputStreamWriter outWriter = new OutputStreamWriter(fileOut);
        outWriter.append(jsonOutput);
        outWriter.close();
        fileOut.close();
        System.out.println("Commited " + items.size() + " items");
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) TypeToken(com.google.gson.reflect.TypeToken) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) SoliniaItem(com.solinia.solinia.Models.SoliniaItem) File(java.io.File)

Aggregations

ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)2 SoliniaItem (com.solinia.solinia.Models.SoliniaItem)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 TypeToken (com.google.gson.reflect.TypeToken)1 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)1 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)1