use of org.bukkit.inventory.FurnaceRecipe in project Denizen-For-Bukkit by DenizenScript.
the class ItemScriptHelper method scriptReload.
@EventHandler
public void scriptReload(ScriptReloadEvent event) {
for (Map.Entry<ItemScriptContainer, List<String>> entry : recipes_to_register.entrySet()) {
ItemScriptContainer container = entry.getKey();
List<String> recipeList = entry.getValue();
// Process all tags in list
for (int n = 0; n < recipeList.size(); n++) {
recipeList.set(n, TagManager.tag(recipeList.get(n), new BukkitTagContext(container.player, container.npc, false, null, dB.shouldDebug(container), new dScript(container))));
}
// Store every ingredient in a List
List<dItem> ingredients = new ArrayList<dItem>();
boolean shouldRegister = true;
recipeLoop: for (String recipeRow : recipeList) {
String[] elements = recipeRow.split("\\|", 3);
for (String element : elements) {
dItem ingredient = dItem.valueOf(element.replaceAll("[iImM]@", ""));
if (ingredient == null) {
dB.echoError("Invalid dItem ingredient, recipe will not be registered for item script '" + container.getName() + "': " + element);
shouldRegister = false;
break recipeLoop;
}
ingredients.add(ingredient);
}
}
// will be checked manually inside ItemScriptHelper
if (shouldRegister) {
ItemScriptContainer.specialrecipesMap.put(container, ingredients);
}
}
for (Map.Entry<ItemScriptContainer, String> entry : shapeless_to_register.entrySet()) {
ItemScriptContainer container = entry.getKey();
String string = entry.getValue();
String list = TagManager.tag(string, new BukkitTagContext(container.player, container.npc, false, null, dB.shouldDebug(container), new dScript(container)));
List<dItem> ingredients = new ArrayList<dItem>();
boolean shouldRegister = true;
for (String element : dList.valueOf(list)) {
dItem ingredient = dItem.valueOf(element.replaceAll("[iImM]@", ""));
if (ingredient == null) {
dB.echoError("Invalid dItem ingredient, shapeless recipe will not be registered for item script '" + container.getName() + "': " + element);
shouldRegister = false;
break;
}
ingredients.add(ingredient);
}
if (shouldRegister) {
ItemScriptContainer.shapelessRecipesMap.put(container, ingredients);
}
}
for (Map.Entry<ItemScriptContainer, String> entry : furnace_to_register.entrySet()) {
dItem furnace_item = dItem.valueOf(entry.getValue());
if (furnace_item == null) {
dB.echoError("Invalid item '" + entry.getValue() + "'");
continue;
}
FurnaceRecipe recipe = new FurnaceRecipe(entry.getKey().getItemFrom().getItemStack(), furnace_item.getMaterial().getMaterial(), furnace_item.getItemStack().getDurability());
Bukkit.getServer().addRecipe(recipe);
}
recipes_to_register.clear();
shapeless_to_register.clear();
furnace_to_register.clear();
}
use of org.bukkit.inventory.FurnaceRecipe in project Dragonet-Legacy by DragonetMC.
the class CraftingDataPacket method encode.
@Override
public void encode() {
enchants = 0;
try {
setChannel(NetworkChannel.CHANNEL_WORLD_EVENTS);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PEBinaryWriter writer = new PEBinaryWriter(bos);
writer.writeByte((byte) (this.pid() & 0xFF));
for (Object o : recipies) {
if (Recipe.class.isAssignableFrom(o.getClass())) {
Recipe r = (Recipe) o;
if (ShapelessRecipe.class.isInstance(r)) {
writer.writeInt(ENTRY_SHAPELESS);
ByteArrayOutputStream ebos = new ByteArrayOutputStream();
PEBinaryWriter ewriter = new PEBinaryWriter(ebos);
/* Write data */
{
ewriter.writeInt(((ShapelessRecipe) r).getIngredientList().size());
for (ItemStack stack : ((ShapelessRecipe) r).getIngredientList()) {
PEInventorySlot.writeSlot(ewriter, PEInventorySlot.fromItemStack(stack));
}
ewriter.writeInt(1);
PEInventorySlot.writeSlot(ewriter, PEInventorySlot.fromItemStack(r.getResult()));
}
writer.writeInt(ebos.toByteArray().length);
writer.write(ebos.toByteArray());
} else if (FurnaceRecipe.class.isInstance(r)) {
FurnaceRecipe f = (FurnaceRecipe) r;
if (f.getResult().getDurability() != 0) {
writer.writeInt(ENTRY_FURNACE_DATA);
ByteArrayOutputStream ebos = new ByteArrayOutputStream();
PEBinaryWriter ewriter = new PEBinaryWriter(ebos);
/* Write data */
{
ewriter.writeInt(f.getInput().getTypeId() << 16 | f.getInput().getDurability());
PEInventorySlot.writeSlot(ewriter, PEInventorySlot.fromItemStack(f.getResult()));
}
writer.writeInt(ebos.toByteArray().length);
writer.write(ebos.toByteArray());
} else {
writer.writeInt(ENTRY_FURNACE);
ByteArrayOutputStream ebos = new ByteArrayOutputStream();
PEBinaryWriter ewriter = new PEBinaryWriter(ebos);
/* Write data */
{
ewriter.writeInt(f.getInput().getTypeId());
PEInventorySlot.writeSlot(ewriter, PEInventorySlot.fromItemStack(f.getResult()));
}
writer.writeInt(ebos.toByteArray().length);
writer.write(ebos.toByteArray());
}
} else if (ShapedRecipe.class.isInstance(r)) {
ShapedRecipe sr = (ShapedRecipe) r;
writer.writeInt(ENTRY_SHAPED);
ByteArrayOutputStream ebos = new ByteArrayOutputStream();
PEBinaryWriter ewriter = new PEBinaryWriter(ebos);
/* Write data */
{
ewriter.writeInt(sr.getShape()[0].length());
ewriter.writeInt(sr.getShape().length);
for (int pos = 0; pos > sr.getShape()[0].length(); pos++) {
for (String line : sr.getShape()) {
ItemStack stack = sr.getIngredientMap().get(line.charAt(pos));
PEInventorySlot.writeSlot(ewriter, PEInventorySlot.fromItemStack(stack));
}
}
ewriter.writeInt(1);
PEInventorySlot.writeSlot(ewriter, PEInventorySlot.fromItemStack(sr.getResult()));
long mostUUID = sr.getResult().getTypeId() << 32 | sr.getResult().getDurability() << 16 | (sr.getResult().getAmount() & 0xFFFF);
UUID uid = new UUID(mostUUID, mostUUID);
ewriter.writeUUID(uid);
}
writer.writeInt(ebos.toByteArray().length);
writer.write(ebos.toByteArray());
} else {
writer.writeInt(-1);
writer.writeInt(0);
}
} else if (Enchantment.class.isAssignableFrom(o.getClass())) {
Enchantment e = (Enchantment) o;
writer.writeInt(ENTRY_ENCHANT);
ByteArrayOutputStream ebos = new ByteArrayOutputStream();
PEBinaryWriter ewriter = new PEBinaryWriter(ebos);
/* Write data */
{
ewriter.writeInt(enchants);
enchants++;
ewriter.writeInt(e.getId());
// HACK: Always return this.
ewriter.writeInt(e.getMaxLevel());
// HACK: Always 1 for now. TO BE FIXED!
ewriter.writeInt(1);
ewriter.writeString(e.getName());
}
writer.writeInt(ebos.toByteArray().length);
writer.write(ebos.toByteArray());
}
}
writer.writeInt(recipies.size());
this.setData(bos.toByteArray());
} catch (IOException e) {
}
}
Aggregations