mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 07:49:03 +00:00
Rewrite of the Custom item into RecipeItem
and Ingredient with subclasses Implemented adding custom items to Ingredients Added support for plugin-items
This commit is contained in:
@@ -1,18 +1,29 @@
|
||||
package com.dre.brewery.filedata;
|
||||
|
||||
import com.dre.brewery.*;
|
||||
import com.dre.brewery.integration.WGBarrel;
|
||||
import com.dre.brewery.integration.WGBarrel5;
|
||||
import com.dre.brewery.integration.WGBarrel6;
|
||||
import com.dre.brewery.integration.WGBarrel7;
|
||||
import com.dre.brewery.Brew;
|
||||
import com.dre.brewery.DistortChat;
|
||||
import com.dre.brewery.MCBarrel;
|
||||
import com.dre.brewery.P;
|
||||
import com.dre.brewery.integration.barrel.WGBarrel;
|
||||
import com.dre.brewery.integration.barrel.WGBarrel5;
|
||||
import com.dre.brewery.integration.barrel.WGBarrel6;
|
||||
import com.dre.brewery.integration.barrel.WGBarrel7;
|
||||
import com.dre.brewery.integration.item.BreweryPluginItem;
|
||||
import com.dre.brewery.integration.item.MMOItemsPluginItem;
|
||||
import com.dre.brewery.integration.item.SlimefunPluginItem;
|
||||
import com.dre.brewery.recipe.BCauldronRecipe;
|
||||
import com.dre.brewery.recipe.BRecipe;
|
||||
import com.dre.brewery.recipe.PluginItem;
|
||||
import com.dre.brewery.recipe.RecipeItem;
|
||||
import com.dre.brewery.utility.BUtil;
|
||||
import com.dre.brewery.utility.CustomItem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
@@ -38,6 +49,8 @@ public class BConfig {
|
||||
public static boolean useGP; //GriefPrevention
|
||||
public static boolean hasVault; // Vault
|
||||
public static boolean useCitadel; // CivCraft/DevotedMC Citadel
|
||||
public static Boolean hasSlimefun = null; // Slimefun ; Null if not checked
|
||||
public static Boolean hasMMOItems = null; // MMOItems ; Null if not checked
|
||||
|
||||
// Barrel
|
||||
public static boolean openEverywhere;
|
||||
@@ -61,7 +74,7 @@ public class BConfig {
|
||||
public static boolean alwaysShowAlc; // Always show alc%
|
||||
|
||||
//Item
|
||||
public static List<CustomItem> customItems = new ArrayList<>();
|
||||
public static List<RecipeItem> customItems = new ArrayList<>();
|
||||
|
||||
public static P p = P.p;
|
||||
|
||||
@@ -189,12 +202,18 @@ public class BConfig {
|
||||
|
||||
Brew.loadSeed(config, file);
|
||||
|
||||
PluginItem.registerForConfig("brewery", BreweryPluginItem::new);
|
||||
PluginItem.registerForConfig("mmoitems", MMOItemsPluginItem::new);
|
||||
PluginItem.registerForConfig("slimefun", SlimefunPluginItem::new);
|
||||
PluginItem.registerForConfig("exoticgarden", SlimefunPluginItem::new);
|
||||
|
||||
// Loading custom items
|
||||
ConfigurationSection configSection = config.getConfigurationSection("customItems");
|
||||
if (configSection != null) {
|
||||
for (String custId : configSection.getKeys(false)) {
|
||||
CustomItem custom = CustomItem.fromConfig(configSection, custId);
|
||||
RecipeItem custom = RecipeItem.fromConfigCustom(configSection, custId);
|
||||
if (custom != null) {
|
||||
custom.makeImmutable();
|
||||
customItems.add(custom);
|
||||
} else {
|
||||
p.errorLog("Loading the Custom Item with id: '" + custId + "' failed!");
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package com.dre.brewery.filedata;
|
||||
|
||||
import com.dre.brewery.*;
|
||||
import com.dre.brewery.lore.Base91DecoderStream;
|
||||
import com.dre.brewery.recipe.CustomItem;
|
||||
import com.dre.brewery.recipe.Ingredient;
|
||||
import com.dre.brewery.recipe.PluginItem;
|
||||
import com.dre.brewery.recipe.SimpleItem;
|
||||
import com.dre.brewery.utility.BUtil;
|
||||
import com.dre.brewery.utility.BoundingBox;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
@@ -12,14 +17,12 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class BData {
|
||||
|
||||
@@ -47,18 +50,30 @@ public class BData {
|
||||
}
|
||||
}
|
||||
|
||||
// Register Item Loaders
|
||||
CustomItem.registerItemLoader();
|
||||
SimpleItem.registerItemLoader();
|
||||
PluginItem.registerItemLoader();
|
||||
|
||||
// loading Ingredients into ingMap
|
||||
// Only for Legacy Brews
|
||||
Map<String, BIngredients> ingMap = new HashMap<>();
|
||||
ConfigurationSection section = data.getConfigurationSection("Ingredients");
|
||||
if (section != null) {
|
||||
for (String id : section.getKeys(false)) {
|
||||
ConfigurationSection matSection = section.getConfigurationSection(id + ".mats");
|
||||
if (matSection != null) {
|
||||
// matSection has all the materials + amount as Integers
|
||||
ArrayList<ItemStack> ingredients = deserializeIngredients(matSection);
|
||||
ingMap.put(id, new BIngredients(ingredients, section.getInt(id + ".cookedTime", 0), true));
|
||||
if (section.isConfigurationSection(id + ".mats")) {
|
||||
// Old way of saving
|
||||
ConfigurationSection matSection = section.getConfigurationSection(id + ".mats");
|
||||
if (matSection != null) {
|
||||
// matSection has all the materials + amount as Integers
|
||||
List<Ingredient> ingredients = oldDeserializeIngredients(matSection);
|
||||
ingMap.put(id, new BIngredients(ingredients, section.getInt(id + ".cookedTime", 0), true));
|
||||
} else {
|
||||
P.p.errorLog("Ingredient id: '" + id + "' incomplete in data.yml");
|
||||
}
|
||||
} else {
|
||||
P.p.errorLog("Ingredient id: '" + id + "' incomplete in data.yml");
|
||||
// New way of saving ingredients
|
||||
ingMap.put(id, deserializeIngredients(section.getString(id + ".mats")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,9 +125,9 @@ public class BData {
|
||||
|
||||
for (World world : P.p.getServer().getWorlds()) {
|
||||
if (world.getName().startsWith("DXL_")) {
|
||||
loadWorldData(BUtil.getDxlName(world.getName()), world);
|
||||
loadWorldData(BUtil.getDxlName(world.getName()), world, data);
|
||||
} else {
|
||||
loadWorldData(world.getUID().toString(), world);
|
||||
loadWorldData(world.getUID().toString(), world, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,8 +136,19 @@ public class BData {
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<ItemStack> deserializeIngredients(ConfigurationSection matSection) {
|
||||
ArrayList<ItemStack> ingredients = new ArrayList<>();
|
||||
public static BIngredients deserializeIngredients(String mat) {
|
||||
try (DataInputStream in = new DataInputStream(new Base91DecoderStream(new ByteArrayInputStream(mat.getBytes())))) {
|
||||
byte ver = in.readByte();
|
||||
return BIngredients.load(in, ver);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return new BIngredients();
|
||||
}
|
||||
}
|
||||
|
||||
// Loading from the old way of saving ingredients
|
||||
public static List<Ingredient> oldDeserializeIngredients(ConfigurationSection matSection) {
|
||||
List<Ingredient> ingredients = new ArrayList<>();
|
||||
for (String mat : matSection.getKeys(false)) {
|
||||
String[] matSplit = mat.split(",");
|
||||
Material m = Material.getMaterial(matSplit[0]);
|
||||
@@ -135,10 +161,13 @@ public class BData {
|
||||
P.p.debugLog("converting Data Material from " + matSplit[0] + " to " + m);
|
||||
}
|
||||
if (m == null) continue;
|
||||
ItemStack item = new ItemStack(m, matSection.getInt(mat));
|
||||
SimpleItem item;
|
||||
if (matSplit.length == 2) {
|
||||
item.setDurability((short) P.p.parseInt(matSplit[1]));
|
||||
item = new SimpleItem(m, (short) P.p.parseInt(matSplit[1]));
|
||||
} else {
|
||||
item = new SimpleItem(m);
|
||||
}
|
||||
item.setAmount(matSection.getInt(mat));
|
||||
ingredients.add(item);
|
||||
}
|
||||
return ingredients;
|
||||
@@ -156,134 +185,146 @@ public class BData {
|
||||
}
|
||||
|
||||
// loads BIngredients from an ingredient section
|
||||
public static BIngredients loadIngredients(ConfigurationSection section) {
|
||||
if (section != null) {
|
||||
return new BIngredients(deserializeIngredients(section), 0);
|
||||
public static BIngredients loadCauldronIng(ConfigurationSection section, String path) {
|
||||
if (section.isConfigurationSection(path)) {
|
||||
// Old way of saving
|
||||
ConfigurationSection matSection = section.getConfigurationSection(path);
|
||||
if (matSection != null) {
|
||||
// matSection has all the materials + amount as Integers
|
||||
return new BIngredients(oldDeserializeIngredients(section), 0);
|
||||
} else {
|
||||
P.p.errorLog("Cauldron is missing Ingredient Section");
|
||||
return new BIngredients();
|
||||
}
|
||||
} else {
|
||||
P.p.errorLog("Cauldron is missing Ingredient Section");
|
||||
// New way of saving ingredients
|
||||
return deserializeIngredients(section.getString(path));
|
||||
}
|
||||
return new BIngredients();
|
||||
}
|
||||
|
||||
// load Block locations of given world
|
||||
public static void loadWorldData(String uuid, World world) {
|
||||
public static void loadWorldData(String uuid, World world, FileConfiguration data) {
|
||||
|
||||
File file = new File(P.p.getDataFolder(), "data.yml");
|
||||
if (file.exists()) {
|
||||
|
||||
FileConfiguration data = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
// loading BCauldron
|
||||
if (data.contains("BCauldron." + uuid)) {
|
||||
ConfigurationSection section = data.getConfigurationSection("BCauldron." + uuid);
|
||||
for (String cauldron : section.getKeys(false)) {
|
||||
// block is splitted into x/y/z
|
||||
String block = section.getString(cauldron + ".block");
|
||||
if (block != null) {
|
||||
String[] splitted = block.split("/");
|
||||
if (splitted.length == 3) {
|
||||
|
||||
Block worldBlock = world.getBlockAt(P.p.parseInt(splitted[0]), P.p.parseInt(splitted[1]), P.p.parseInt(splitted[2]));
|
||||
BIngredients ingredients = loadIngredients(section.getConfigurationSection(cauldron + ".ingredients"));
|
||||
int state = section.getInt(cauldron + ".state", 1);
|
||||
|
||||
new BCauldron(worldBlock, ingredients, state);
|
||||
} else {
|
||||
P.p.errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + cauldron);
|
||||
}
|
||||
} else {
|
||||
P.p.errorLog("Missing Block-Data in data.yml: " + section.getCurrentPath() + "." + cauldron);
|
||||
}
|
||||
}
|
||||
if (data == null) {
|
||||
File file = new File(P.p.getDataFolder(), "data.yml");
|
||||
if (file.exists()) {
|
||||
data = YamlConfiguration.loadConfiguration(file);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
// loading Barrel
|
||||
if (data.contains("Barrel." + uuid)) {
|
||||
ConfigurationSection section = data.getConfigurationSection("Barrel." + uuid);
|
||||
for (String barrel : section.getKeys(false)) {
|
||||
// block spigot is splitted into x/y/z
|
||||
String spigot = section.getString(barrel + ".spigot");
|
||||
if (spigot != null) {
|
||||
String[] splitted = spigot.split("/");
|
||||
if (splitted.length == 3) {
|
||||
|
||||
// load itemStacks from invSection
|
||||
ConfigurationSection invSection = section.getConfigurationSection(barrel + ".inv");
|
||||
Block block = world.getBlockAt(P.p.parseInt(splitted[0]), P.p.parseInt(splitted[1]), P.p.parseInt(splitted[2]));
|
||||
float time = (float) section.getDouble(barrel + ".time", 0.0);
|
||||
byte sign = (byte) section.getInt(barrel + ".sign", 0);
|
||||
|
||||
BoundingBox box = null;
|
||||
if (section.contains(barrel + ".bounds")) {
|
||||
String[] bds = section.getString(barrel + ".bounds", "").split(",");
|
||||
if (bds.length == 6) {
|
||||
box = new BoundingBox(P.p.parseInt(bds[0]), P.p.parseInt(bds[1]), P.p.parseInt(bds[2]), P.p.parseInt(bds[3]), P.p.parseInt(bds[4]), P.p.parseInt(bds[5]));
|
||||
}
|
||||
} else if (section.contains(barrel + ".st")) {
|
||||
// Convert from Stair and Wood Locations to BoundingBox
|
||||
String[] st = section.getString(barrel + ".st", "").split(",");
|
||||
String[] wo = section.getString(barrel + ".wo", "").split(",");
|
||||
int woLength = wo.length;
|
||||
if (woLength <= 1) {
|
||||
woLength = 0;
|
||||
}
|
||||
String[] points = new String[st.length + woLength];
|
||||
System.arraycopy(st, 0, points, 0, st.length);
|
||||
if (woLength > 1) {
|
||||
System.arraycopy(wo, 0, points, st.length, woLength);
|
||||
}
|
||||
int[] locs = ArrayUtils.toPrimitive(Arrays.stream(points).map(s -> P.p.parseInt(s)).toArray(Integer[]::new));
|
||||
box = BoundingBox.fromPoints(locs);
|
||||
}
|
||||
|
||||
Barrel b;
|
||||
if (invSection != null) {
|
||||
b = new Barrel(block, sign, box, invSection.getValues(true), time);
|
||||
} else {
|
||||
// Barrel has no inventory
|
||||
b = new Barrel(block, sign, box, null, time);
|
||||
}
|
||||
|
||||
// In case Barrel Block locations were missing and could not be recreated: do not add the barrel
|
||||
if (b.getBody().getBounds() != null) {
|
||||
Barrel.barrels.add(b);
|
||||
}
|
||||
|
||||
} else {
|
||||
P.p.errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
|
||||
}
|
||||
} else {
|
||||
P.p.errorLog("Missing Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loading Wakeup
|
||||
if (data.contains("Wakeup." + uuid)) {
|
||||
ConfigurationSection section = data.getConfigurationSection("Wakeup." + uuid);
|
||||
for (String wakeup : section.getKeys(false)) {
|
||||
// loc of wakeup is splitted into x/y/z/pitch/yaw
|
||||
String loc = section.getString(wakeup);
|
||||
if (loc != null) {
|
||||
String[] splitted = loc.split("/");
|
||||
if (splitted.length == 5) {
|
||||
|
||||
double x = NumberUtils.toDouble(splitted[0]);
|
||||
double y = NumberUtils.toDouble(splitted[1]);
|
||||
double z = NumberUtils.toDouble(splitted[2]);
|
||||
float pitch = NumberUtils.toFloat(splitted[3]);
|
||||
float yaw = NumberUtils.toFloat(splitted[4]);
|
||||
Location location = new Location(world, x, y, z, yaw, pitch);
|
||||
|
||||
Wakeup.wakeups.add(new Wakeup(location));
|
||||
|
||||
} else {
|
||||
P.p.errorLog("Incomplete Location-Data in data.yml: " + section.getCurrentPath() + "." + wakeup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// loading BCauldron
|
||||
if (data.contains("BCauldron." + uuid)) {
|
||||
ConfigurationSection section = data.getConfigurationSection("BCauldron." + uuid);
|
||||
for (String cauldron : section.getKeys(false)) {
|
||||
// block is splitted into x/y/z
|
||||
String block = section.getString(cauldron + ".block");
|
||||
if (block != null) {
|
||||
String[] splitted = block.split("/");
|
||||
if (splitted.length == 3) {
|
||||
|
||||
Block worldBlock = world.getBlockAt(P.p.parseInt(splitted[0]), P.p.parseInt(splitted[1]), P.p.parseInt(splitted[2]));
|
||||
BIngredients ingredients = loadCauldronIng(section, cauldron + ".ingredients");
|
||||
int state = section.getInt(cauldron + ".state", 1);
|
||||
|
||||
new BCauldron(worldBlock, ingredients, state);
|
||||
} else {
|
||||
P.p.errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + cauldron);
|
||||
}
|
||||
} else {
|
||||
P.p.errorLog("Missing Block-Data in data.yml: " + section.getCurrentPath() + "." + cauldron);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loading Barrel
|
||||
if (data.contains("Barrel." + uuid)) {
|
||||
ConfigurationSection section = data.getConfigurationSection("Barrel." + uuid);
|
||||
for (String barrel : section.getKeys(false)) {
|
||||
// block spigot is splitted into x/y/z
|
||||
String spigot = section.getString(barrel + ".spigot");
|
||||
if (spigot != null) {
|
||||
String[] splitted = spigot.split("/");
|
||||
if (splitted.length == 3) {
|
||||
|
||||
// load itemStacks from invSection
|
||||
ConfigurationSection invSection = section.getConfigurationSection(barrel + ".inv");
|
||||
Block block = world.getBlockAt(P.p.parseInt(splitted[0]), P.p.parseInt(splitted[1]), P.p.parseInt(splitted[2]));
|
||||
float time = (float) section.getDouble(barrel + ".time", 0.0);
|
||||
byte sign = (byte) section.getInt(barrel + ".sign", 0);
|
||||
|
||||
BoundingBox box = null;
|
||||
if (section.contains(barrel + ".bounds")) {
|
||||
String[] bds = section.getString(barrel + ".bounds", "").split(",");
|
||||
if (bds.length == 6) {
|
||||
box = new BoundingBox(P.p.parseInt(bds[0]), P.p.parseInt(bds[1]), P.p.parseInt(bds[2]), P.p.parseInt(bds[3]), P.p.parseInt(bds[4]), P.p.parseInt(bds[5]));
|
||||
}
|
||||
} else if (section.contains(barrel + ".st")) {
|
||||
// Convert from Stair and Wood Locations to BoundingBox
|
||||
String[] st = section.getString(barrel + ".st", "").split(",");
|
||||
String[] wo = section.getString(barrel + ".wo", "").split(",");
|
||||
int woLength = wo.length;
|
||||
if (woLength <= 1) {
|
||||
woLength = 0;
|
||||
}
|
||||
String[] points = new String[st.length + woLength];
|
||||
System.arraycopy(st, 0, points, 0, st.length);
|
||||
if (woLength > 1) {
|
||||
System.arraycopy(wo, 0, points, st.length, woLength);
|
||||
}
|
||||
int[] locs = ArrayUtils.toPrimitive(Arrays.stream(points).map(s -> P.p.parseInt(s)).toArray(Integer[]::new));
|
||||
box = BoundingBox.fromPoints(locs);
|
||||
}
|
||||
|
||||
Barrel b;
|
||||
if (invSection != null) {
|
||||
b = new Barrel(block, sign, box, invSection.getValues(true), time);
|
||||
} else {
|
||||
// Barrel has no inventory
|
||||
b = new Barrel(block, sign, box, null, time);
|
||||
}
|
||||
|
||||
// In case Barrel Block locations were missing and could not be recreated: do not add the barrel
|
||||
|
||||
if (b.getBody().getBounds() != null) {
|
||||
Barrel.barrels.add(b);
|
||||
}
|
||||
|
||||
} else {
|
||||
P.p.errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
|
||||
}
|
||||
} else {
|
||||
P.p.errorLog("Missing Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loading Wakeup
|
||||
if (data.contains("Wakeup." + uuid)) {
|
||||
ConfigurationSection section = data.getConfigurationSection("Wakeup." + uuid);
|
||||
for (String wakeup : section.getKeys(false)) {
|
||||
// loc of wakeup is splitted into x/y/z/pitch/yaw
|
||||
String loc = section.getString(wakeup);
|
||||
if (loc != null) {
|
||||
String[] splitted = loc.split("/");
|
||||
if (splitted.length == 5) {
|
||||
|
||||
double x = NumberUtils.toDouble(splitted[0]);
|
||||
double y = NumberUtils.toDouble(splitted[1]);
|
||||
double z = NumberUtils.toDouble(splitted[2]);
|
||||
float pitch = NumberUtils.toFloat(splitted[3]);
|
||||
float yaw = NumberUtils.toFloat(splitted[4]);
|
||||
Location location = new Location(world, x, y, z, yaw, pitch);
|
||||
|
||||
Wakeup.wakeups.add(new Wakeup(location));
|
||||
|
||||
} else {
|
||||
P.p.errorLog("Incomplete Location-Data in data.yml: " + section.getCurrentPath() + "." + wakeup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class DataSave extends BukkitRunnable {
|
||||
Brew.writePrevSeeds(configFile);
|
||||
|
||||
if (!Brew.legacyPotions.isEmpty()) {
|
||||
Brew.save(configFile.createSection("Brew"));
|
||||
Brew.saveLegacy(configFile.createSection("Brew"));
|
||||
}
|
||||
|
||||
if (!BCauldron.bcauldrons.isEmpty() || oldData.contains("BCauldron")) {
|
||||
|
||||
Reference in New Issue
Block a user