mirror of
https://github.com/JamesPeters98/ChestsPlusPlus.git
synced 2024-11-14 22:56:27 +01:00
AutoCrafting fixes
Changed Serialization name to stop conflicts with other plugins. And load config can recipes after all other plugins!
This commit is contained in:
parent
0f117e5332
commit
6fe6817340
@ -80,7 +80,6 @@ public class ChestsPlusPlus extends JavaPlugin {
|
||||
Stats.addCharts(metrics);
|
||||
|
||||
Settings.initConfig(this);
|
||||
Crafting.load();
|
||||
PLUGIN = this;
|
||||
|
||||
//API initialisation
|
||||
@ -103,7 +102,6 @@ public class ChestsPlusPlus extends JavaPlugin {
|
||||
|
||||
//Load storage
|
||||
SpigotConfig.load(this);
|
||||
new Config();
|
||||
|
||||
INVENTORY_MANAGER = new InventoryManager(this);
|
||||
INVENTORY_MANAGER.init();
|
||||
@ -139,6 +137,13 @@ public class ChestsPlusPlus extends JavaPlugin {
|
||||
}
|
||||
|
||||
getLogger().info("Chests++ enabled!");
|
||||
|
||||
//Load storages after load.
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () ->{
|
||||
Crafting.load();
|
||||
new Config();
|
||||
getLogger().info("Chests++ Successfully Loaded Config and Recipes");
|
||||
},1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.inventory.ShapelessRecipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@ -30,13 +31,26 @@ public class Crafting {
|
||||
}
|
||||
|
||||
public static Recipe getResult(List<ItemStack> craftingTable){
|
||||
for(ShapelessRecipe shapelessRecipe : shapelessRecipes) {
|
||||
if (matchesShapeless(shapelessRecipe.getChoiceList(), craftingTable)) return shapelessRecipe;
|
||||
Recipe returnRecipe = null;
|
||||
Iterator<Recipe> iterator = Bukkit.recipeIterator();
|
||||
while (iterator.hasNext()){
|
||||
Recipe recipe = iterator.next();
|
||||
if(recipe instanceof ShapedRecipe){
|
||||
ShapedRecipe shapedRecipe = (ShapedRecipe) recipe;
|
||||
if (matchesShaped(shapedRecipe, craftingTable)){
|
||||
returnRecipe = shapedRecipe;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(recipe instanceof ShapelessRecipe){
|
||||
ShapelessRecipe shapelessRecipe = (ShapelessRecipe) recipe;
|
||||
if (matchesShapeless(shapelessRecipe.getChoiceList(), craftingTable)){
|
||||
returnRecipe = shapelessRecipe;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(ShapedRecipe shapedRecipe : shapedRecipes) {
|
||||
if (matchesShaped(shapedRecipe, craftingTable)) return shapedRecipe;
|
||||
}
|
||||
return null;
|
||||
return returnRecipe;
|
||||
}
|
||||
|
||||
private static boolean matchesShapeless(List<RecipeChoice> choice, List<ItemStack> items) {
|
||||
@ -65,11 +79,6 @@ public class Crafting {
|
||||
return userShapedRecipe.matchesRecipe(shape);
|
||||
}
|
||||
|
||||
// public static void craft(Player player){
|
||||
// Inventory craft = new VirtualCraftingHolder().getInventory();
|
||||
// player.openInventory(craft);
|
||||
// }
|
||||
|
||||
public static Recipe getRecipeByKey(NamespacedKey key){
|
||||
Optional<ShapelessRecipe> recipe = shapelessRecipes.stream().filter(s -> s.getKey().equals(key)).findFirst();
|
||||
if(recipe.isPresent()) return recipe.get();
|
||||
|
@ -32,6 +32,7 @@ public class Config {
|
||||
|
||||
public Config() {
|
||||
legacyConverter();
|
||||
configConverter();
|
||||
|
||||
try {
|
||||
config = YamlConfiguration.loadConfiguration(getStorageFile());
|
||||
@ -127,4 +128,15 @@ public class Config {
|
||||
content = content.replaceAll("==: com.jamesdpeters.minecraft.chests.serialize.InventoryStorage", "==: ChestLinkStorage");
|
||||
return content;
|
||||
}
|
||||
|
||||
private void configConverter(){
|
||||
try {
|
||||
Path path = Paths.get(getStorageFile().toURI());
|
||||
String content = new String(Files.readAllBytes(path),Charsets.UTF_8);
|
||||
content = content.replaceAll("==: Recipe", "==: C++Recipe");
|
||||
Files.write(getStorageFile().toPath(), content.getBytes(Charsets.UTF_8));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ import org.bukkit.inventory.ShapelessRecipe;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SerializableAs("Recipe")
|
||||
@SerializableAs("C++Recipe")
|
||||
public class RecipeSerializable implements ConfigurationSerializable {
|
||||
|
||||
private Recipe recipe;
|
||||
|
Loading…
Reference in New Issue
Block a user