1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Reduced technical debt

This commit is contained in:
TheBusyBiscuit 2020-08-22 00:57:44 +02:00
parent e1b619c89a
commit e839ece670
29 changed files with 191 additions and 292 deletions

View File

@ -48,6 +48,7 @@
* Small performance improvements for Holograms
* Small performance improvements for Tree Growth Accelerators
* Small performance improvements for Reactors
* Electric machines now show their tier in the Inventory name too
#### Fixes
* Fixed Programmable Androids rotating in the wrong direction

View File

@ -19,6 +19,7 @@ import org.bukkit.plugin.Plugin;
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetProvider;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
@ -34,71 +35,23 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
* @author TheBusyBiscuit
*
*/
public class ErrorReport {
public class ErrorReport<T extends Throwable> {
private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm", Locale.ROOT);
private static int count;
private SlimefunAddon addon;
private T throwable;
private File file;
public ErrorReport(Throwable throwable, SlimefunAddon addon, Consumer<PrintStream> printer) {
Slimefun.runSync(() -> {
file = getNewFile();
public ErrorReport(T throwable, SlimefunAddon addon, Consumer<PrintStream> printer) {
this.throwable = throwable;
this.addon = addon;
try (PrintStream stream = new PrintStream(file, StandardCharsets.UTF_8.name())) {
stream.println();
stream.println("Java Environment:");
stream.println(" Operating System: " + System.getProperty("os.name"));
stream.println(" Java Version: " + System.getProperty("java.version"));
stream.println();
stream.println("Server Software: " + Bukkit.getName());
stream.println(" Build: " + Bukkit.getVersion());
stream.println(" Minecraft: " + Bukkit.getBukkitVersion());
stream.println();
stream.println("Slimefun Environment:");
stream.println(" CS-CoreLib v" + SlimefunPlugin.getCSCoreLibVersion());
stream.println(" Slimefun v" + SlimefunPlugin.getVersion());
stream.println(" Caused by: " + addon.getName() + " v" + addon.getPluginVersion());
stream.println();
List<String> plugins = new ArrayList<>();
List<String> addons = new ArrayList<>();
scanPlugins(plugins, addons);
stream.println("Installed Addons (" + addons.size() + ")");
addons.forEach(stream::println);
stream.println();
stream.println("Installed Plugins (" + plugins.size() + "):");
plugins.forEach(stream::println);
stream.println();
printer.accept(stream);
stream.println("Stacktrace:");
stream.println();
throwable.printStackTrace(stream);
addon.getLogger().log(Level.WARNING, "");
addon.getLogger().log(Level.WARNING, "An Error occurred! It has been saved as: ");
addon.getLogger().log(Level.WARNING, "/plugins/Slimefun/error-reports/{0}", file.getName());
addon.getLogger().log(Level.WARNING, "Please put this file on https://pastebin.com/ and report this to the developer(s).");
if (addon.getBugTrackerURL() != null) {
addon.getLogger().log(Level.WARNING, "Bug Tracker: {0}", addon.getBugTrackerURL());
}
addon.getLogger().log(Level.WARNING, "");
}
catch (Exception x) {
addon.getLogger().log(Level.SEVERE, x, () -> "An Error occurred while saving an Error-Report for Slimefun " + SlimefunPlugin.getVersion());
}
});
Slimefun.runSync(() -> print(printer));
}
public ErrorReport(Throwable throwable, Location l, SlimefunItem item) {
public ErrorReport(T throwable, Location l, SlimefunItem item) {
this(throwable, item.getAddon(), stream -> {
stream.println("Block Info:");
stream.println(" World: " + l.getWorld().getName());
@ -130,7 +83,7 @@ public class ErrorReport {
});
}
public ErrorReport(Throwable throwable, SlimefunItem item) {
public ErrorReport(T throwable, SlimefunItem item) {
this(throwable, item.getAddon(), stream -> {
stream.println("SlimefunItem:");
stream.println(" ID: " + item.getID());
@ -139,6 +92,94 @@ public class ErrorReport {
});
}
/**
* This method returns the {@link File} this {@link ErrorReport} has been written to.
*
* @return The {@link File} for this {@link ErrorReport}
*/
public File getFile() {
return file;
}
/**
* This returns the {@link Throwable} that was thrown.
*
* @return The {@link Throwable}
*/
public T getThrown() {
return throwable;
}
/**
* This method returns the amount of {@link ErrorReport ErrorReports} created in this session.
*
* @return The amount of {@link ErrorReport ErrorReports} created.
*/
public static int count() {
return count;
}
private void print(Consumer<PrintStream> printer) {
this.file = getNewFile();
count++;
try (PrintStream stream = new PrintStream(file, StandardCharsets.UTF_8.name())) {
stream.println();
stream.println("Java Environment:");
stream.println(" Operating System: " + System.getProperty("os.name"));
stream.println(" Java Version: " + System.getProperty("java.version"));
stream.println();
String serverSoftware = PaperLib.isSpigot() && !PaperLib.isPaper() ? "Spigot" : Bukkit.getName();
stream.println("Server Software: " + serverSoftware);
stream.println(" Build: " + Bukkit.getVersion());
stream.println(" Minecraft v" + Bukkit.getBukkitVersion());
stream.println();
stream.println("Slimefun Environment:");
stream.println(" CS-CoreLib v" + SlimefunPlugin.getCSCoreLibVersion());
stream.println(" Slimefun v" + SlimefunPlugin.getVersion());
stream.println(" Caused by: " + addon.getName() + " v" + addon.getPluginVersion());
stream.println();
List<String> plugins = new ArrayList<>();
List<String> addons = new ArrayList<>();
scanPlugins(plugins, addons);
stream.println("Installed Addons (" + addons.size() + ")");
addons.forEach(stream::println);
stream.println();
stream.println("Installed Plugins (" + plugins.size() + "):");
plugins.forEach(stream::println);
stream.println();
printer.accept(stream);
stream.println("Stacktrace:");
stream.println();
throwable.printStackTrace(stream);
addon.getLogger().log(Level.WARNING, "");
addon.getLogger().log(Level.WARNING, "An Error occurred! It has been saved as: ");
addon.getLogger().log(Level.WARNING, "/plugins/Slimefun/error-reports/{0}", file.getName());
addon.getLogger().log(Level.WARNING, "Please put this file on https://pastebin.com/ and report this to the developer(s).");
if (addon.getBugTrackerURL() != null) {
addon.getLogger().log(Level.WARNING, "Bug Tracker: {0}", addon.getBugTrackerURL());
}
addon.getLogger().log(Level.WARNING, "");
}
catch (Exception x) {
addon.getLogger().log(Level.SEVERE, x, () -> "An Error occurred while saving an Error-Report for Slimefun " + SlimefunPlugin.getVersion());
}
}
private static void scanPlugins(List<String> plugins, List<String> addons) {
String dependency = "Slimefun";
@ -174,11 +215,7 @@ public class ErrorReport {
return newFile;
}
public File getFile() {
return file;
}
public static void tryCatch(Function<Exception, ErrorReport> function, Runnable runnable) {
public static void tryCatch(Function<Exception, ErrorReport<Exception>> function, Runnable runnable) {
try {
runnable.run();
}

View File

@ -834,14 +834,14 @@ public final class SlimefunItems {
if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14)) {
TABLE_SAW = new SlimefunItemStack("TABLE_SAW", Material.STONECUTTER, "&6Table Saw", "", "&aAllows you to get 8 planks from 1 Log", "&a(Works with all log types)");
MAKESHIFT_SMELTERY = new SlimefunItemStack("MAKESHIFT_SMELTERY", Material.BLAST_FURNACE, "&eMakeshift Smeltery", "", "&fImprovised version of the Smeltery", "&fthat only allows you to", "&fsmelt dusts into ingots");
AUTO_DRIER = new SlimefunItemStack("AUTO_DRIER", Material.SMOKER, "&eAuto Drier", "", LoreBuilder.machine(MachineTier.MEDIUM, MachineType.MACHINE), LoreBuilder.speed(1), LoreBuilder.powerPerSecond(10));
AUTO_BREWER = new SlimefunItemStack("AUTO_BREWER", Material.SMOKER, "&eAuto Brewer", "", LoreBuilder.machine(MachineTier.MEDIUM, MachineType.MACHINE), LoreBuilder.speed(1), LoreBuilder.powerPerSecond(12));
AUTO_DRIER = new SlimefunItemStack("AUTO_DRIER", Material.SMOKER, "&6Auto Drier", "", LoreBuilder.machine(MachineTier.MEDIUM, MachineType.MACHINE), LoreBuilder.speed(1), LoreBuilder.powerPerSecond(10));
AUTO_BREWER = new SlimefunItemStack("AUTO_BREWER", Material.SMOKER, "&6Auto Brewer", "", LoreBuilder.machine(MachineTier.MEDIUM, MachineType.MACHINE), LoreBuilder.speed(1), LoreBuilder.powerPerSecond(12));
}
else {
TABLE_SAW = null;
MAKESHIFT_SMELTERY = new SlimefunItemStack("MAKESHIFT_SMELTERY", Material.FURNACE, "&eMakeshift Smeltery", "", "&fImprovised version of the Smeltery", "&fthat only allows you to", "&fsmelt dusts into ingots");
AUTO_DRIER = new SlimefunItemStack("AUTO_DRIER", Material.FURNACE, "&eAuto Drier", "", LoreBuilder.machine(MachineTier.MEDIUM, MachineType.MACHINE), LoreBuilder.speed(1), LoreBuilder.powerPerSecond(10));
AUTO_BREWER = new SlimefunItemStack("AUTO_BREWER", Material.BREWING_STAND, "&eAuto Brewer", LoreBuilder.machine(MachineTier.MEDIUM, MachineType.MACHINE), LoreBuilder.speed(1), LoreBuilder.powerPerSecond(12));
AUTO_DRIER = new SlimefunItemStack("AUTO_DRIER", Material.FURNACE, "&6Auto Drier", "", LoreBuilder.machine(MachineTier.MEDIUM, MachineType.MACHINE), LoreBuilder.speed(1), LoreBuilder.powerPerSecond(10));
AUTO_BREWER = new SlimefunItemStack("AUTO_BREWER", Material.BREWING_STAND, "&6Auto Brewer", LoreBuilder.machine(MachineTier.MEDIUM, MachineType.MACHINE), LoreBuilder.speed(1), LoreBuilder.powerPerSecond(12));
}
}
}

View File

@ -6,11 +6,9 @@ import java.util.List;
import java.util.Locale;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.cscorelib2.chat.ChatInput;
@ -29,6 +27,7 @@ import io.github.thebusybiscuit.slimefun4.core.researching.Research;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.itemstack.SlimefunGuideItem;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.Slimefun;
@ -39,20 +38,7 @@ public class BookSlimefunGuide implements SlimefunGuideImplementation {
private final ItemStack item;
public BookSlimefunGuide() {
item = new ItemStack(Material.ENCHANTED_BOOK);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColors.color("&aSlimefun Guide &7(Book GUI)"));
List<String> lore = new LinkedList<>();
lore.add("");
lore.add(ChatColors.color("&eRight Click &8\u21E8 &7Browse Items"));
lore.add(ChatColors.color("&eShift + Right Click &8\u21E8 &7Open Settings / Credits"));
meta.setLore(lore);
SlimefunPlugin.getItemTextureService().setTexture(meta, "SLIMEFUN_GUIDE");
item.setItemMeta(meta);
item = new SlimefunGuideItem(this, "&aSlimefun Guide &7(Book GUI)");
}
@Override

View File

@ -1,18 +1,12 @@
package io.github.thebusybiscuit.slimefun4.implementation.guide;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.itemstack.SlimefunGuideItem;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
public class CheatSheetSlimefunGuide extends ChestSlimefunGuide {
@ -22,20 +16,7 @@ public class CheatSheetSlimefunGuide extends ChestSlimefunGuide {
public CheatSheetSlimefunGuide() {
super(false);
item = new ItemStack(Material.ENCHANTED_BOOK);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColors.color("&cSlimefun Guide &4(Cheat Sheet)"));
List<String> lore = new LinkedList<>();
lore.add(ChatColors.color("&4&lOnly openable by Admins"));
lore.add(ChatColors.color("&eRight Click &8\u21E8 &7Browse Items"));
lore.add(ChatColors.color("&eShift + Right Click &8\u21E8 &7Open Settings / Credits"));
meta.setLore(lore);
SlimefunPlugin.getItemTextureService().setTexture(meta, "SLIMEFUN_GUIDE");
item.setItemMeta(meta);
item = new SlimefunGuideItem(this, "&cSlimefun Guide &4(Cheat Sheet)");
}
@Override

View File

@ -18,9 +18,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.RecipeChoice.MaterialChoice;
import org.bukkit.inventory.meta.ItemMeta;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.cscorelib2.chat.ChatInput;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
@ -41,6 +39,7 @@ import io.github.thebusybiscuit.slimefun4.core.researching.Research;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.itemstack.SlimefunGuideItem;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.MenuClickHandler;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
@ -59,6 +58,7 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
public ChestSlimefunGuide(boolean vanillaRecipes) {
showVanillaRecipes = vanillaRecipes;
item = new SlimefunGuideItem(this, "&aSlimefun Guide &7(Chest GUI)");
if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14)) {
sound = Sound.ITEM_BOOK_PAGE_TURN;
@ -66,21 +66,6 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
else {
sound = Sound.ENTITY_BAT_TAKEOFF;
}
item = new ItemStack(Material.ENCHANTED_BOOK);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColors.color("&aSlimefun Guide &7(Chest GUI)"));
List<String> lore = new LinkedList<>();
lore.add("");
lore.add(ChatColors.color("&eRight Click &8\u21E8 &7Browse Items"));
lore.add(ChatColors.color("&eShift + Right Click &8\u21E8 &7Open Settings / Credits"));
meta.setLore(lore);
SlimefunPlugin.getItemTextureService().setTexture(meta, "SLIMEFUN_GUIDE");
item.setItemMeta(meta);
}
@Override

View File

@ -4,22 +4,17 @@ import java.util.EnumMap;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionType;
import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
/**
@ -59,52 +54,7 @@ public abstract class AutoBrewer extends AContainer {
}
@Override
protected void tick(Block b) {
BlockMenu menu = BlockStorage.getInventory(b.getLocation());
if (isProcessing(b)) {
int timeleft = progress.get(b);
if (timeleft > 0) {
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
return;
}
ChargableBlock.addCharge(b, -getEnergyConsumption());
progress.put(b, timeleft - 1);
}
else {
menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
for (ItemStack item : processing.get(b).getOutput()) {
menu.pushItem(item, getOutputSlots());
}
progress.remove(b);
processing.remove(b);
}
}
else {
MachineRecipe recipe = findRecipe(menu);
if (recipe != null) {
if (!InvUtils.fitAll(menu.toInventory(), recipe.getOutput(), getOutputSlots())) {
return;
}
for (int slot : getInputSlots()) {
menu.consumeItem(slot);
}
processing.put(b, recipe);
progress.put(b, recipe.getTicks());
}
}
}
private MachineRecipe findRecipe(BlockMenu menu) {
protected MachineRecipe findNextRecipe(BlockMenu menu) {
ItemStack input1 = menu.getItemInSlot(getInputSlots()[0]);
ItemStack input2 = menu.getItemInSlot(getInputSlots()[1]);
@ -113,15 +63,15 @@ public abstract class AutoBrewer extends AContainer {
}
if (isPotion(input1.getType()) || isPotion(input2.getType())) {
boolean slot = isPotion(input1.getType());
ItemStack ingredient = slot ? input2 : input1;
boolean isPotionInFirstSlot = isPotion(input1.getType());
ItemStack ingredient = isPotionInFirstSlot ? input2 : input1;
// Reject any named items
if (ingredient.hasItemMeta()) {
return null;
}
ItemStack potionItem = slot ? input1 : input2;
ItemStack potionItem = isPotionInFirstSlot ? input1 : input2;
PotionMeta potion = (PotionMeta) potionItem.getItemMeta();
ItemStack output = brew(ingredient.getType(), potionItem.getType(), potion);
@ -130,6 +80,15 @@ public abstract class AutoBrewer extends AContainer {
}
output.setItemMeta(potion);
if (!InvUtils.fits(menu.toInventory(), output, getOutputSlots())) {
return null;
}
for (int slot : getInputSlots()) {
menu.consumeItem(slot);
}
return new MachineRecipe(30, new ItemStack[] { input1, input2 }, new ItemStack[] { output });
}
else {
@ -193,14 +152,9 @@ public abstract class AutoBrewer extends AContainer {
return mat == Material.POTION || mat == Material.SPLASH_POTION || mat == Material.LINGERING_POTION;
}
@Override
public String getInventoryTitle() {
return "&6Auto-Brewer";
}
@Override
public ItemStack getProgressBar() {
return new ItemStack(Material.CARROT_ON_A_STICK);
return new ItemStack(Material.FISHING_ROD);
}
@Override

View File

@ -49,11 +49,6 @@ public class AutoDisenchanter extends AContainer {
super(category, item, recipeType, recipe);
}
@Override
public String getInventoryTitle() {
return "&5Auto-Disenchanter";
}
@Override
public ItemStack getProgressBar() {
return new ItemStack(Material.DIAMOND_CHESTPLATE);

View File

@ -91,11 +91,6 @@ public class AutoDrier extends AContainer implements RecipeDisplayItem {
}
}
@Override
public String getInventoryTitle() {
return "&eAuto Drier";
}
@Override
public ItemStack getProgressBar() {
return new ItemStack(Material.FLINT_AND_STEEL);

View File

@ -37,11 +37,6 @@ public class AutoEnchanter extends AContainer {
emeraldEnchantsLimit = SlimefunPlugin.getCfg().getInt("options.emerald-enchantment-limit");
}
@Override
public String getInventoryTitle() {
return "&5Auto-Enchanter";
}
@Override
public ItemStack getProgressBar() {
return new ItemStack(Material.GOLDEN_CHESTPLATE);

View File

@ -37,9 +37,4 @@ public abstract class CarbonPress extends AContainer implements RecipeDisplayIte
return new ItemStack(Material.DIAMOND_PICKAXE);
}
@Override
public String getInventoryTitle() {
return "&cCarbon Press";
}
}

View File

@ -14,17 +14,20 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
/**
* The {@link ChargingBench} is a powered machine that can be used to charge any {@link Rechargeable} item.
*
* @author TheBusyBiscuit
*
* @see Rechargeable
*
*/
public class ChargingBench extends AContainer {
public ChargingBench(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
}
@Override
public String getInventoryTitle() {
return "&3Charging Bench";
}
@Override
public ItemStack getProgressBar() {
return new ItemStack(Material.GOLDEN_PICKAXE);

View File

@ -37,11 +37,6 @@ public abstract class ElectricDustWasher extends AContainer {
oreWasher = (OreWasher) SlimefunItems.ORE_WASHER.getItem();
}
@Override
public String getInventoryTitle() {
return "&bElectric Dust Washer";
}
@Override
public ItemStack getProgressBar() {
return new ItemStack(Material.GOLDEN_SHOVEL);

View File

@ -43,9 +43,4 @@ public abstract class ElectricFurnace extends AContainer {
return new ItemStack(Material.FLINT_AND_STEEL);
}
@Override
public String getInventoryTitle() {
return "&bElectric Furnace";
}
}

View File

@ -41,11 +41,6 @@ public abstract class ElectricGoldPan extends AContainer implements RecipeDispla
return recipes;
}
@Override
public String getInventoryTitle() {
return "&6Electric Gold Pan";
}
@Override
public ItemStack getProgressBar() {
return new ItemStack(Material.DIAMOND_SHOVEL);

View File

@ -25,9 +25,4 @@ public abstract class ElectricIngotFactory extends AContainer implements RecipeD
return new ItemStack(Material.FLINT_AND_STEEL);
}
@Override
public String getInventoryTitle() {
return "&cElectric Ingot Factory";
}
}

View File

@ -29,11 +29,6 @@ public class ElectricIngotPulverizer extends AContainer implements RecipeDisplay
super(category, item, recipeType, recipe);
}
@Override
public String getInventoryTitle() {
return "&bElectric Ingot Pulverizer";
}
@Override
public ItemStack getProgressBar() {
return new ItemStack(Material.IRON_PICKAXE);

View File

@ -25,9 +25,4 @@ public abstract class ElectricOreGrinder extends AContainer implements RecipeDis
return new ItemStack(Material.IRON_PICKAXE);
}
@Override
public String getInventoryTitle() {
return "&bElectric Ore Grinder";
}
}

View File

@ -50,7 +50,7 @@ public abstract class ElectricPress extends AContainer implements RecipeDisplayI
addRecipe(4, new ItemStack(Material.COAL, 9), new ItemStack(Material.COAL_BLOCK));
addRecipe(4, new ItemStack(Material.SAND, 4), new ItemStack(Material.SANDSTONE));
addRecipe(4, new ItemStack(Material.RED_SAND, 4), new ItemStack(Material.RED_SANDSTONE));
addRecipe(5, new ItemStack(Material.IRON_INGOT, 9), new ItemStack(Material.IRON_BLOCK));
addRecipe(5, new ItemStack(Material.GOLD_INGOT, 9), new ItemStack(Material.GOLD_BLOCK));
@ -65,12 +65,6 @@ public abstract class ElectricPress extends AContainer implements RecipeDisplayI
registerRecipe(seconds, new ItemStack[] { input }, new ItemStack[] { output });
}
@Override
public String getInventoryTitle() {
return "&eElectric Press";
}
@Override
public ItemStack getProgressBar() {
return new ItemStack(Material.IRON_HOE);

View File

@ -44,7 +44,7 @@ public abstract class ElectricSmeltery extends AContainer {
public ElectricSmeltery(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
new BlockMenuPreset(getID(), getInventoryTitle()) {
new BlockMenuPreset(getID(), getItemName()) {
@Override
public void init() {
@ -153,11 +153,6 @@ public abstract class ElectricSmeltery extends AContainer {
}
}
@Override
public String getInventoryTitle() {
return "&cElectric Smeltery";
}
@Override
public ItemStack getProgressBar() {
return new ItemStack(Material.FLINT_AND_STEEL);

View File

@ -41,9 +41,4 @@ public abstract class ElectrifiedCrucible extends AContainer {
return new ItemStack(Material.FLINT_AND_STEEL);
}
@Override
public String getInventoryTitle() {
return "&4Electrified Crucible";
}
}

View File

@ -46,9 +46,4 @@ public abstract class FoodComposter extends AContainer implements RecipeDisplayI
return new ItemStack(Material.GOLDEN_HOE);
}
@Override
public String getInventoryTitle() {
return "&cFood Composter";
}
}

View File

@ -45,9 +45,4 @@ public abstract class FoodFabricator extends AContainer {
return new ItemStack(Material.GOLDEN_HOE);
}
@Override
public String getInventoryTitle() {
return "&cFood Fabricator";
}
}

View File

@ -47,11 +47,6 @@ public abstract class Freezer extends AContainer implements RecipeDisplayItem {
return new ItemStack(Material.GOLDEN_PICKAXE);
}
@Override
public String getInventoryTitle() {
return "&bFreezer";
}
@Override
public String getMachineIdentifier() {
return "FREEZER";

View File

@ -38,7 +38,7 @@ public abstract class HeatedPressureChamber extends AContainer {
public HeatedPressureChamber(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
new BlockMenuPreset(getID(), getInventoryTitle()) {
new BlockMenuPreset(getID(), getItemName()) {
@Override
public void init() {
@ -102,11 +102,6 @@ public abstract class HeatedPressureChamber extends AContainer {
registerRecipe(8, new ItemStack[] { SlimefunItems.MAGNESIUM_DUST, SlimefunItems.SALT }, new ItemStack[] { SlimefunItems.MAGNESIUM_SALT });
}
@Override
public String getInventoryTitle() {
return "&cHeated Pressure Chamber";
}
@Override
public ItemStack getProgressBar() {
return new ItemStack(Material.FLINT_AND_STEEL);

View File

@ -21,11 +21,6 @@ public abstract class Refinery extends AContainer implements RecipeDisplayItem {
registerRecipe(40, SlimefunItems.OIL_BUCKET, SlimefunItems.FUEL_BUCKET);
}
@Override
public String getInventoryTitle() {
return "&cRefinery";
}
@Override
public ItemStack getProgressBar() {
return new ItemStack(Material.FLINT_AND_STEEL);

View File

@ -67,11 +67,6 @@ public abstract class GEOMiner extends AContainer implements RecipeDisplayItem {
};
}
@Override
public String getInventoryTitle() {
return "&6GEO-Miner";
}
@Override
public String getMachineIdentifier() {
return "GEO_MINER";
@ -113,14 +108,14 @@ public abstract class GEOMiner extends AContainer implements RecipeDisplayItem {
@Override
protected void constructMenu(BlockMenuPreset preset) {
for (int i : BORDER) {
preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
preset.addItem(i, new CustomItem(Material.GRAY_STAINED_GLASS_PANE, " "), (p, slot, item, action) -> false);
}
for (int i : OUTPUT_BORDER) {
preset.addItem(i, new CustomItem(new ItemStack(Material.ORANGE_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
preset.addItem(i, new CustomItem(Material.ORANGE_STAINED_GLASS_PANE, " "), (p, slot, item, action) -> false);
}
preset.addItem(4, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
preset.addItem(4, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " "), (p, slot, item, action) -> false);
for (int i : getOutputSlots()) {
preset.addMenuClickHandler(i, new AdvancedMenuClickHandler() {
@ -157,7 +152,7 @@ public abstract class GEOMiner extends AContainer implements RecipeDisplayItem {
progress.put(b, timeleft - 1);
}
else {
inv.replaceExistingItem(4, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
inv.replaceExistingItem(4, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " "));
inv.pushItem(processing.get(b).getOutput()[0], getOutputSlots());
progress.remove(b);

View File

@ -0,0 +1,46 @@
package io.github.thebusybiscuit.slimefun4.utils.itemstack;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.guide.CheatSheetSlimefunGuide;
/**
* This is just a helper {@link ItemStack} class for the {@link SlimefunGuide} {@link ItemStack}.
*
* @author TheBusyBiscuit
*
* @see SlimefunGuide
* @see SlimefunGuideImplementation
*
*/
public class SlimefunGuideItem extends ItemStack {
public SlimefunGuideItem(SlimefunGuideImplementation implementation, String name) {
super(Material.ENCHANTED_BOOK);
ItemMeta meta = getItemMeta();
meta.setDisplayName(ChatColors.color(name));
List<String> lore = new LinkedList<>();
lore.add(implementation instanceof CheatSheetSlimefunGuide ? "&4&lOnly openable by Admins" : "");
lore.add(ChatColors.color("&eRight Click &8\u21E8 &7Browse Items"));
lore.add(ChatColors.color("&eShift + Right Click &8\u21E8 &7Open Settings / Credits"));
meta.setLore(lore);
SlimefunPlugin.getItemTextureService().setTexture(meta, "SLIMEFUN_GUIDE");
setItemMeta(meta);
}
}

View File

@ -109,7 +109,9 @@ public abstract class AContainer extends SlimefunItem implements InventoryBlock,
*
* @return The title of the {@link Inventory} of this {@link AContainer}
*/
public abstract String getInventoryTitle();
public String getInventoryTitle() {
return getItemName();
}
/**
* This method returns the {@link ItemStack} that this {@link AContainer} will
@ -258,7 +260,7 @@ public abstract class AContainer extends SlimefunItem implements InventoryBlock,
}
}
else {
MachineRecipe next = nextRecipe(inv);
MachineRecipe next = findNextRecipe(inv);
if (next != null) {
processing.put(b, next);
@ -267,7 +269,7 @@ public abstract class AContainer extends SlimefunItem implements InventoryBlock,
}
}
private MachineRecipe nextRecipe(BlockMenu inv) {
protected MachineRecipe findNextRecipe(BlockMenu inv) {
Map<Integer, ItemStack> inventory = new HashMap<>();
for (int slot : getInputSlots()) {