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;
}
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();
}
}
Aggregations