Skip to content

Commit

Permalink
feat: move exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ybw0014 committed Aug 5, 2024
1 parent a5d040a commit a862461
Show file tree
Hide file tree
Showing 20 changed files with 24 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.guizhanss.fastmachines.items.machines.infinityexpansion;

import java.util.List;
import java.util.logging.Level;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
Expand All @@ -25,13 +24,8 @@ public FastInfinityWorkbench(SlimefunItemStack item, RecipeType recipeType, Item

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
try {
List<RawRecipe> rawRecipes = RecipeUtils.getInfinityMachineRecipes(InfinityWorkbench.class);
RecipeUtils.registerRecipes(recipes, rawRecipes, false);
} catch (Exception ex) {
FastMachines.log(Level.SEVERE, ex, "An error has occurred while registering recipes for {0}", getClass().getSimpleName());
}
List<RawRecipe> rawRecipes = RecipeUtils.getInfinityMachineRecipes(InfinityWorkbench.class);
RecipeUtils.registerRecipes(recipes, rawRecipes, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.guizhanss.fastmachines.items.machines.infinityexpansion;

import java.util.List;
import java.util.logging.Level;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
Expand All @@ -25,13 +24,8 @@ public FastMobDataInfuser(SlimefunItemStack item, RecipeType recipeType, ItemSta

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
try {
List<RawRecipe> rawRecipes = RecipeUtils.getInfinityMachineRecipes(MobDataInfuser.class);
RecipeUtils.registerRecipes(recipes, rawRecipes, false);
} catch (Exception ex) {
FastMachines.log(Level.SEVERE, ex, "An error has occurred while registering recipes for {0}", getClass().getSimpleName());
}
List<RawRecipe> rawRecipes = RecipeUtils.getInfinityMachineRecipes(MobDataInfuser.class);
RecipeUtils.registerRecipes(recipes, rawRecipes, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public FastSlimeFrameFoundry(SlimefunItemStack item, RecipeType recipeType, Item

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
RecipeUtils.registerMultiblockMachineRecipes(recipes, SFrameStacks.FOUNDRY.getItemId(), false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
Expand All @@ -28,23 +27,18 @@ public FastAncientAltar(SlimefunItemStack item, RecipeType recipeType, ItemStack

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
try {
var altar = (AncientAltar) SlimefunItems.ANCIENT_ALTAR.getItem();
List<RawRecipe> rawRecipes = new ArrayList<>();
for (var recipe : altar.getRecipes()) {
if (recipe.getOutput().getType() == Material.SPAWNER) {
continue;
}
var input = new ArrayList<>(recipe.getInput());
input.add(recipe.getCatalyst());
RawRecipe rawRecipe = new RawRecipe(input.toArray(new ItemStack[9]), new ItemStack[] {recipe.getOutput()});
rawRecipes.add(rawRecipe);
var altar = (AncientAltar) SlimefunItems.ANCIENT_ALTAR.getItem();
List<RawRecipe> rawRecipes = new ArrayList<>();
for (var recipe : altar.getRecipes()) {
if (recipe.getOutput().getType() == Material.SPAWNER) {
continue;
}
RecipeUtils.registerRecipes(recipes, rawRecipes, false);
} catch (Exception ex) {
FastMachines.log(Level.SEVERE, ex, "An error has occurred while registering recipes for {0}", getClass().getSimpleName());
var input = new ArrayList<>(recipe.getInput());
input.add(recipe.getCatalyst());
RawRecipe rawRecipe = new RawRecipe(input.toArray(new ItemStack[9]), new ItemStack[] {recipe.getOutput()});
rawRecipes.add(rawRecipe);
}
RecipeUtils.registerRecipes(recipes, rawRecipes, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public FastArmorForge(SlimefunItemStack item, RecipeType recipeType, ItemStack[]

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
RecipeUtils.registerMultiblockMachineRecipes(recipes, SlimefunItems.ARMOR_FORGE.getItemId(), false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public FastComposter(SlimefunItemStack item, RecipeType recipeType, ItemStack[]

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
RecipeUtils.registerDisplayRecipes(recipes, SlimefunItems.COMPOSTER.getItemId(), false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public FastCompressor(SlimefunItemStack item, RecipeType recipeType, ItemStack[]

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
RecipeUtils.registerMultiblockMachineRecipes(recipes, SlimefunItems.COMPRESSOR.getItemId(), false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public FastEnhancedCraftingTable(SlimefunItemStack item, RecipeType recipeType,

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
RecipeUtils.registerMultiblockMachineRecipes(recipes, SlimefunItems.ENHANCED_CRAFTING_TABLE.getItemId(), false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public FastGrindStone(SlimefunItemStack item, RecipeType recipeType, ItemStack[]

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
RecipeUtils.registerMultiblockMachineRecipes(recipes, SlimefunItems.GRIND_STONE.getItemId(), false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public FastJuicer(SlimefunItemStack item, RecipeType recipeType, ItemStack[] rec

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
RecipeUtils.registerMultiblockMachineRecipes(recipes, SlimefunItems.JUICER.getItemId(), false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public FastMagicWorkbench(SlimefunItemStack item, RecipeType recipeType, ItemSta

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
RecipeUtils.registerMultiblockMachineRecipes(recipes, SlimefunItems.MAGIC_WORKBENCH.getItemId(), false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public FastOreCrusher(SlimefunItemStack item, RecipeType recipeType, ItemStack[]

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
RecipeUtils.registerMultiblockMachineRecipes(recipes, SlimefunItems.ORE_CRUSHER.getItemId(), true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public FastOreWasher(SlimefunItemStack item, RecipeType recipeType, ItemStack[]

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
RecipeUtils.registerMultiblockMachineRecipes(recipes, SlimefunItems.ORE_WASHER.getItemId(), true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public FastPanningMachine(SlimefunItemStack item, RecipeType recipeType, ItemSta

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
RecipeUtils.registerDisplayRecipes(recipes, SlimefunItems.AUTOMATED_PANNING_MACHINE.getItemId(), true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public FastPressureChamber(SlimefunItemStack item, RecipeType recipeType, ItemSt

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
RecipeUtils.registerMultiblockMachineRecipes(recipes, SlimefunItems.PRESSURE_CHAMBER.getItemId(), false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public FastSmeltery(SlimefunItemStack item, RecipeType recipeType, ItemStack[] r

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
RecipeUtils.registerMultiblockMachineRecipes(recipes, SlimefunItems.SMELTERY.getItemId(), false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public FastTableSaw(SlimefunItemStack item, RecipeType recipeType, ItemStack[] r

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
RecipeUtils.registerDisplayRecipes(recipes, SlimefunItems.TABLE_SAW.getItemId(), false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public FastCraftingTable(SlimefunItemStack item, RecipeType recipeType, ItemStac

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
RecipeUtils.registerVanillaRecipes(recipes, ShapedRecipe.class);
RecipeUtils.registerVanillaRecipes(recipes, ShapelessRecipe.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public FastFurnace(SlimefunItemStack item, RecipeType recipeType, ItemStack[] re

@Override
public void registerRecipes() {
FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName());
RecipeUtils.registerVanillaRecipes(recipes, FurnaceRecipe.class);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.guizhanss.fastmachines.listeners;

import java.util.logging.Level;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;

Expand All @@ -9,7 +11,6 @@
import io.github.thebusybiscuit.slimefun4.api.events.SlimefunItemRegistryFinalizedEvent;

import net.guizhanss.fastmachines.FastMachines;
import net.guizhanss.fastmachines.items.machines.generic.AbstractFastMachine;

public class SlimefunRegistryLoadedListener implements Listener {

Expand All @@ -20,6 +21,13 @@ public SlimefunRegistryLoadedListener(@Nonnull FastMachines plugin) {

@EventHandler
public void onRegistryLoaded(@Nonnull SlimefunItemRegistryFinalizedEvent e) {
FastMachines.getRegistry().getAllEnabledFastMachines().forEach(AbstractFastMachine::registerRecipes);
FastMachines.getRegistry().getAllEnabledFastMachines().forEach(machine -> {
FastMachines.debug("Registering recipes for {0}", machine.getClass().getSimpleName());
try {
machine.registerRecipes();
} catch (Exception ex) {
FastMachines.log(Level.SEVERE, ex, "An error has occurred while registering recipes for {0}", machine.getClass().getSimpleName());
}
});
}
}

0 comments on commit a862461

Please sign in to comment.