95 lines
3.3 KiB
Java
95 lines
3.3 KiB
Java
package com.librewiki.coalgov.service;
|
|
|
|
import com.librewiki.coalgov.CoalGovPlugin;
|
|
import com.librewiki.coalgov.storage.SuperFurnaceRepository;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.NamespacedKey;
|
|
import org.bukkit.block.Block;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.ShapedRecipe;
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
|
import org.bukkit.persistence.PersistentDataType;
|
|
|
|
import java.sql.SQLException;
|
|
import java.util.List;
|
|
|
|
public final class SuperFurnaceService {
|
|
private static final int SPEED_MULTIPLIER = 5;
|
|
private static final int FUEL_MULTIPLIER = 4;
|
|
|
|
private final CoalGovPlugin plugin;
|
|
private final SuperFurnaceRepository repository;
|
|
private final NamespacedKey itemKey;
|
|
private final NamespacedKey recipeKey;
|
|
|
|
public SuperFurnaceService(CoalGovPlugin plugin, SuperFurnaceRepository repository) {
|
|
this.plugin = plugin;
|
|
this.repository = repository;
|
|
this.itemKey = new NamespacedKey(plugin, "super_furnace");
|
|
this.recipeKey = new NamespacedKey(plugin, "super_furnace_recipe");
|
|
}
|
|
|
|
public void registerRecipe() {
|
|
Bukkit.removeRecipe(recipeKey);
|
|
if (!plugin.getConfig().getBoolean("super_furnace.recipe_enabled", false)) {
|
|
return;
|
|
}
|
|
ShapedRecipe recipe = new ShapedRecipe(recipeKey, item());
|
|
recipe.shape("SSS", "SFS", "SSS");
|
|
recipe.setIngredient('S', Material.STONE);
|
|
recipe.setIngredient('F', Material.FURNACE);
|
|
Bukkit.addRecipe(recipe);
|
|
}
|
|
|
|
public ItemStack item() {
|
|
ItemStack item = new ItemStack(Material.FURNACE);
|
|
ItemMeta meta = item.getItemMeta();
|
|
meta.setDisplayName(plugin.messages().raw("&6CoalGov Super Furnace"));
|
|
meta.setLore(List.of(
|
|
plugin.messages().raw("&75x smelting speed."),
|
|
plugin.messages().raw("&7Burns fuel 4x faster."),
|
|
plugin.messages().raw("&7Crafted with stone around a furnace.")
|
|
));
|
|
meta.getPersistentDataContainer().set(itemKey, PersistentDataType.BYTE, (byte) 1);
|
|
item.setItemMeta(meta);
|
|
return item;
|
|
}
|
|
|
|
public boolean syntheticDiamondsEnabled() {
|
|
return plugin.getConfig().getBoolean("synthetic_diamonds.enabled", true);
|
|
}
|
|
|
|
public int syntheticDiamondCoalInput() {
|
|
return Math.max(2, plugin.getConfig().getInt("synthetic_diamonds.coal_input", 40));
|
|
}
|
|
|
|
public boolean isItem(ItemStack item) {
|
|
if (item == null || item.getType() != Material.FURNACE || !item.hasItemMeta()) {
|
|
return false;
|
|
}
|
|
return item.getItemMeta().getPersistentDataContainer().has(itemKey, PersistentDataType.BYTE);
|
|
}
|
|
|
|
public void add(Block block) throws SQLException {
|
|
repository.add(block.getLocation());
|
|
}
|
|
|
|
public void remove(Block block) throws SQLException {
|
|
repository.remove(block.getLocation());
|
|
}
|
|
|
|
public boolean isSuperFurnace(Block block) throws SQLException {
|
|
return block.getType() == Material.FURNACE && repository.exists(block.getLocation());
|
|
}
|
|
|
|
public int fasterCookTime(int cookTime) {
|
|
return Math.max(1, (int) Math.ceil(cookTime / (double) SPEED_MULTIPLIER));
|
|
}
|
|
|
|
public int shorterBurnTime(int burnTime) {
|
|
return Math.max(1, (int) Math.floor(burnTime / (double) FUEL_MULTIPLIER));
|
|
}
|
|
}
|