Added sound node for crafting stations which lets you determine how the station sounds.

Added Crafting Station Layouts. This allows you to edit the gui how you like. See here: https://git.lumine.io/mythiccraft/mmoitems/-/wikis/Layouts
This commit is contained in:
Ethan 2020-09-01 07:25:35 -04:00
parent 6c87b6255a
commit a3443485e4
17 changed files with 324 additions and 125 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.Indyuce</groupId>
<artifactId>MMOItems</artifactId>
<version>6.0.1</version>
<version>6.1.0</version>
<name>MMOItems</name>
<description>A great item solution for your RPG server.</description>

View File

@ -63,6 +63,7 @@ public class MMOItems extends JavaPlugin {
private final TemplateManager templateManager = new TemplateManager();
private final ItemManager itemManager = new ItemManager();
private final RecipeManager recipeManager = new RecipeManager();
private final LayoutManager layoutManager = new LayoutManager();
private DropTableManager dropTableManager;
private WorldGenManager worldGenManager;
@ -146,6 +147,7 @@ public class MMOItems extends JavaPlugin {
}
getLogger().log(Level.INFO, "Loading crafting stations, please wait..");
layoutManager.reload();
stationRecipeManager.reload();
Bukkit.getPluginManager().registerEvents(entityManager, this);
@ -292,6 +294,10 @@ public class MMOItems extends JavaPlugin {
return stationRecipeManager;
}
public LayoutManager getLayouts() {
return layoutManager;
}
public UpdaterManager getUpdater() {
return dynamicUpdater;
}

View File

@ -1,16 +1,5 @@
package net.Indyuce.mmoitems.api.crafting;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.crafting.recipe.CraftingRecipe;
import net.Indyuce.mmoitems.api.crafting.recipe.Recipe;
@ -20,9 +9,18 @@ import net.Indyuce.mmoitems.api.crafting.recipe.UpgradingRecipe;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.util.PostLoadObject;
import net.mmogroup.mmolib.MMOLib;
import org.apache.commons.lang.Validate;
import org.bukkit.Sound;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.*;
import java.util.logging.Level;
public class CraftingStation extends PostLoadObject {
private final String id, name;
private final Layout layout;
private final Sound sound;
private final StationItemOptions itemOptions;
private final int maxQueueSize;
private final Map<String, Recipe> recipes = new LinkedHashMap<>();
@ -34,27 +32,32 @@ public class CraftingStation extends PostLoadObject {
this.id = id.toLowerCase().replace("_", "-").replace(" ", "-");
this.name = MMOLib.plugin.parseColors(config.getString("name"));
this.layout = MMOItems.plugin.getLayouts().getLayout(config.getString("layout", "default"));
this.sound = Sound.valueOf(config.getString("sound", "ENTITY_EXPERIENCE_ORB_PICKUP").toUpperCase());
for (String key : config.getConfigurationSection("recipes").getKeys(false))
try {
registerRecipe(loadRecipe(config.getConfigurationSection("recipes." + key)));
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.INFO,
"An issue occured registering recipe '" + key + "' from crafting station '" + id + "': " + exception.getMessage());
"An issue occurred registering recipe '" + key + "' from crafting station '" + id + "': " + exception.getMessage());
}
itemOptions = new StationItemOptions(config.getConfigurationSection("items"));
maxQueueSize = Math.max(1, Math.min(config.getInt("max-queue-size"), 64));
}
public CraftingStation(String id, String name, StationItemOptions itemOptions, int maxQueueSize, CraftingStation parent) {
public CraftingStation(String id, String name, Layout layout, Sound sound, StationItemOptions itemOptions, int maxQueueSize, CraftingStation parent) {
super(null);
Validate.notNull(id, "Crafting station ID must not be null");
Validate.notNull(name, "Crafting station name must not be null");
Validate.notNull(sound, "Crafting station sound must not be null");
this.id = id.toLowerCase().replace("_", "-").replace(" ", "-");
this.name = MMOLib.plugin.parseColors(name);
this.layout = layout;
this.sound = sound;
this.itemOptions = itemOptions;
this.maxQueueSize = maxQueueSize;
this.parent = parent;
@ -68,6 +71,14 @@ public class CraftingStation extends PostLoadObject {
return name;
}
public Layout getLayout() {
return layout;
}
public Sound getSound() {
return sound;
}
public CraftingStation getParent() {
return parent;
}
@ -121,7 +132,7 @@ public class CraftingStation extends PostLoadObject {
}
public int getMaxPage() {
return Math.max(1, (int) Math.ceil((double) recipes.size() / 14));
return Math.max(1, (int) Math.ceil((double) recipes.size() / getLayout().getRecipeSlots().size()));
}
@Override

View File

@ -0,0 +1,64 @@
package net.Indyuce.mmoitems.api.crafting;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.List;
public class Layout {
private final String id;
private final List<Integer> recipeSlots, queueSlots;
private final int size, recipePreviousSlot, recipeNextSlot, queuePreviousSlot, queueNextSlot;
public Layout(String id, FileConfiguration config) {
this.id = id;
this.size = config.getInt("slots");
ConfigurationSection section = config.getConfigurationSection("layout");
// array slots
this.recipeSlots = section.getIntegerList("recipe-slots");
this.queueSlots = section.getIntegerList("queue-slots");
// singular slots
this.recipePreviousSlot = section.getInt("recipe-previous-slot", 18);
this.recipeNextSlot = section.getInt("recipe-next-slot", 26);
this.queuePreviousSlot = section.getInt("queue-previous-slot", 37);
this.queueNextSlot = section.getInt("queue-next-slot", 43);
}
public String getId() {
return id;
}
public int getSize() {
return size;
}
public List<Integer> getRecipeSlots() {
return recipeSlots;
}
public List<Integer> getQueueSlots() {
return queueSlots;
}
public int getRecipePreviousSlot() {
return recipePreviousSlot;
}
public int getRecipeNextSlot() {
return recipeNextSlot;
}
public int getQueuePreviousSlot() {
return queuePreviousSlot;
}
public int getQueueNextSlot() {
return queueNextSlot;
}
}

View File

@ -1,21 +1,20 @@
package net.Indyuce.mmoitems.api.crafting.recipe;
import net.Indyuce.mmoitems.api.crafting.ConfigMMOItem;
import net.Indyuce.mmoitems.api.crafting.CraftingStation;
import net.Indyuce.mmoitems.api.crafting.CraftingStatus.CraftingQueue;
import net.Indyuce.mmoitems.api.crafting.IngredientInventory;
import net.Indyuce.mmoitems.api.event.PlayerUseCraftingStationEvent;
import net.Indyuce.mmoitems.api.item.util.ConfigItem;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.mmogroup.mmolib.api.util.SmartGive;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.api.crafting.ConfigMMOItem;
import net.Indyuce.mmoitems.api.crafting.CraftingStation;
import net.Indyuce.mmoitems.api.crafting.CraftingStatus.CraftingQueue;
import net.Indyuce.mmoitems.api.event.PlayerUseCraftingStationEvent;
import net.Indyuce.mmoitems.api.crafting.IngredientInventory;
import net.Indyuce.mmoitems.api.item.util.ConfigItem;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.mmogroup.mmolib.api.util.SmartGive;
public class CraftingRecipe extends Recipe {
private final ConfigMMOItem output;
@ -64,7 +63,7 @@ public class CraftingRecipe extends Recipe {
new SmartGive(data.getPlayer()).give(getOutput().generate(data.getRPG()));
recipe.getRecipe().getTriggers().forEach(trigger -> trigger.whenCrafting(data));
if (!hasOption(RecipeOption.SILENT_CRAFT))
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
data.getPlayer().playSound(data.getPlayer().getLocation(), station.getSound(), 1, 1);
/*
* if recipe not instant, add item to crafting queue, either way
* RELOAD inventory data and reopen inventory!
@ -73,7 +72,7 @@ public class CraftingRecipe extends Recipe {
data.getCrafting().getQueue(station).add(this);
if (!isInstant())
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
data.getPlayer().playSound(data.getPlayer().getLocation(), station.getSound(), 1, 1);
}
@Override

View File

@ -1,12 +1,5 @@
package net.Indyuce.mmoitems.api.crafting.recipe;
import java.util.Random;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.crafting.ConfigMMOItem;
import net.Indyuce.mmoitems.api.crafting.CraftingStation;
@ -22,6 +15,12 @@ import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.stat.data.UpgradeData;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.mmogroup.mmolib.MMOLib;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import java.util.Random;
public class UpgradingRecipe extends Recipe {
private final ConfigMMOItem item;
@ -51,7 +50,7 @@ public class UpgradingRecipe extends Recipe {
uncastRecipe.getRecipe().getTriggers().forEach(trigger -> trigger.whenCrafting(data));
Message.UPGRADE_SUCCESS.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(recipe.getUpgraded())).send(data.getPlayer());
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
data.getPlayer().playSound(data.getPlayer().getLocation(), station.getSound(), 1, 1);
}
@Override

View File

@ -33,27 +33,16 @@ public class ConfigItem {
public static final ConfigItem CONFIRM = new ConfigItem("CONFIRM", VersionMaterial.GREEN_STAINED_GLASS_PANE.toMaterial(), "&aConfirm");
public static final ConfigItem FILL = new ConfigItem("FILL", VersionMaterial.GRAY_STAINED_GLASS_PANE.toMaterial(), "&8");
public static final CustomSkull PREVIOUS_PAGE = new CustomSkull("PREVIOUS_PAGE",
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmQ2OWUwNmU1ZGFkZmQ4NGU1ZjNkMWMyMTA2M2YyNTUzYjJmYTk0NWVlMWQ0ZDcxNTJmZGM1NDI1YmMxMmE5In19fQ==",
"&aPrevious Page");
public static final CustomSkull NEXT_PAGE = new CustomSkull("NEXT_PAGE",
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTliZjMyOTJlMTI2YTEwNWI1NGViYTcxM2FhMWIxNTJkNTQxYTFkODkzODgyOWM1NjM2NGQxNzhlZDIyYmYifX19",
"&aNext Page");
public static final CustomSkull PREVIOUS_IN_QUEUE = new CustomSkull("PREVIOUS_IN_QUEUE",
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmQ2OWUwNmU1ZGFkZmQ4NGU1ZjNkMWMyMTA2M2YyNTUzYjJmYTk0NWVlMWQ0ZDcxNTJmZGM1NDI1YmMxMmE5In19fQ==",
"&aPrevious");
public static final CustomSkull NEXT_IN_QUEUE = new CustomSkull("NEXT_IN_QUEUE",
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTliZjMyOTJlMTI2YTEwNWI1NGViYTcxM2FhMWIxNTJkNTQxYTFkODkzODgyOWM1NjM2NGQxNzhlZDIyYmYifX19",
"&aNext");
public static final CustomSkull BACK = new CustomSkull("BACK",
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmQ2OWUwNmU1ZGFkZmQ4NGU1ZjNkMWMyMTA2M2YyNTUzYjJmYTk0NWVlMWQ0ZDcxNTJmZGM1NDI1YmMxMmE5In19fQ==",
"&aBack");
public static final CustomSkull PREVIOUS_PAGE = new CustomSkull("PREVIOUS_PAGE", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmQ2OWUwNmU1ZGFkZmQ4NGU1ZjNkMWMyMTA2M2YyNTUzYjJmYTk0NWVlMWQ0ZDcxNTJmZGM1NDI1YmMxMmE5In19fQ==", "&aPrevious Page");
public static final CustomSkull NEXT_PAGE = new CustomSkull("NEXT_PAGE", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTliZjMyOTJlMTI2YTEwNWI1NGViYTcxM2FhMWIxNTJkNTQxYTFkODkzODgyOWM1NjM2NGQxNzhlZDIyYmYifX19", "&aNext Page");
public static final CustomSkull PREVIOUS_IN_QUEUE = new CustomSkull("PREVIOUS_IN_QUEUE", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmQ2OWUwNmU1ZGFkZmQ4NGU1ZjNkMWMyMTA2M2YyNTUzYjJmYTk0NWVlMWQ0ZDcxNTJmZGM1NDI1YmMxMmE5In19fQ==", "&aPrevious");
public static final CustomSkull NEXT_IN_QUEUE = new CustomSkull("NEXT_IN_QUEUE", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTliZjMyOTJlMTI2YTEwNWI1NGViYTcxM2FhMWIxNTJkNTQxYTFkODkzODgyOWM1NjM2NGQxNzhlZDIyYmYifX19", "&aNext");
public static final CustomSkull BACK = new CustomSkull("BACK", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmQ2OWUwNmU1ZGFkZmQ4NGU1ZjNkMWMyMTA2M2YyNTUzYjJmYTk0NWVlMWQ0ZDcxNTJmZGM1NDI1YmMxMmE5In19fQ==", "&aBack");
public static final CraftingRecipeDisplay CRAFTING_RECIPE_DISPLAY = new CraftingRecipeDisplay();
public static final UpgradingRecipeDisplay UPGRADING_RECIPE_DISPLAY = new UpgradingRecipeDisplay();
public static final QueueItemDisplay QUEUE_ITEM_DISPLAY = new QueueItemDisplay();
public static final ConfigItem[] values = { CONFIRM, FILL, PREVIOUS_PAGE, NEXT_PAGE, PREVIOUS_IN_QUEUE, NEXT_IN_QUEUE, BACK,
CRAFTING_RECIPE_DISPLAY, UPGRADING_RECIPE_DISPLAY, QUEUE_ITEM_DISPLAY };
public static final ConfigItem[] values = { CONFIRM, FILL, PREVIOUS_PAGE, NEXT_PAGE, PREVIOUS_IN_QUEUE, NEXT_IN_QUEUE, BACK, CRAFTING_RECIPE_DISPLAY, UPGRADING_RECIPE_DISPLAY, QUEUE_ITEM_DISPLAY };
public ConfigItem(String id, Material material) {
this(id, material, null);
@ -144,6 +133,10 @@ public class ConfigItem {
return item;
}
public ItemStack getNewItem() {
return item.clone();
}
protected void setName(String name) {
this.name = name;
}

View File

@ -1,23 +1,21 @@
package net.Indyuce.mmoitems.api.item.util;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import net.Indyuce.mmoitems.MMOItems;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.item.ItemTag;
import net.mmogroup.mmolib.version.VersionMaterial;
import org.bukkit.ChatColor;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.meta.ItemMeta;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.meta.ItemMeta;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import net.Indyuce.mmoitems.MMOItems;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.item.ItemTag;
import net.mmogroup.mmolib.version.VersionMaterial;
public class CustomSkull extends ConfigItem {
private String textureValue;

View File

@ -1,10 +1,9 @@
package net.Indyuce.mmoitems.command.mmoitems;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import net.Indyuce.mmoitems.MMOItems;
import net.mmogroup.mmolib.command.api.CommandTreeNode;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
public class ReloadCommandTreeNode extends CommandTreeNode {
public ReloadCommandTreeNode(CommandTreeNode parent) {
@ -25,6 +24,7 @@ public class ReloadCommandTreeNode extends CommandTreeNode {
MMOItems.plugin.getTemplates().reload();
MMOItems.plugin.getWorldGen().reload();
MMOItems.plugin.getCustomBlocks().reload();
MMOItems.plugin.getLayouts().reload();
sender.sendMessage(
MMOItems.plugin.getPrefix() + MMOItems.plugin.getName() + " " + MMOItems.plugin.getDescription().getVersion() + " reloaded.");
sender.sendMessage(
@ -59,6 +59,7 @@ public class ReloadCommandTreeNode extends CommandTreeNode {
@Override
public CommandResult execute(CommandSender sender, String[] args) {
MMOItems.plugin.getLayouts().reload();
MMOItems.plugin.getCrafting().reload();
sender.sendMessage(MMOItems.plugin.getPrefix() + "Successfully reloaded the crafting stations..");
sender.sendMessage(MMOItems.plugin.getPrefix() + "- " + ChatColor.RED + MMOItems.plugin.getCrafting().getAll().size() + ChatColor.GRAY

View File

@ -1,23 +1,12 @@
package net.Indyuce.mmoitems.gui;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.crafting.CraftingStation;
import net.Indyuce.mmoitems.api.crafting.CraftingStatus.CraftingQueue;
import net.Indyuce.mmoitems.api.crafting.CraftingStatus.CraftingQueue.CraftingInfo;
import net.Indyuce.mmoitems.api.crafting.IngredientInventory;
import net.Indyuce.mmoitems.api.crafting.Layout;
import net.Indyuce.mmoitems.api.crafting.ingredient.Ingredient;
import net.Indyuce.mmoitems.api.crafting.recipe.CraftingRecipe;
import net.Indyuce.mmoitems.api.crafting.recipe.Recipe;
@ -30,20 +19,30 @@ import net.Indyuce.mmoitems.listener.CustomSoundListener;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.item.NBTItem;
import net.mmogroup.mmolib.api.util.SmartGive;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.List;
import java.util.UUID;
public class CraftingStationView extends PluginInventory {
private final CraftingStation station;
private final Layout layout;
private final PlayerData data;
private List<RecipeInfo> recipes;
private IngredientInventory ingredients;
private int queueOffset;
private static final int[] slots = { 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 25 }, queueSlots = { 38, 39, 40, 41, 42 };
private static final int[] fill = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 26, 27, 35, 36, 37, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 28, 29,
30, 31, 32, 33, 34 };
public CraftingStationView(Player player, CraftingStation station) {
this(player, station, 1);
}
@ -53,6 +52,7 @@ public class CraftingStationView extends PluginInventory {
this.data = PlayerData.get(player);
this.station = station;
this.layout = station.getLayout();
this.page = page;
updateData();
@ -69,42 +69,37 @@ public class CraftingStationView extends PluginInventory {
@Override
public Inventory getInventory() {
Inventory inv = Bukkit.createInventory(this, 54, station.getName().replace("#page#", "" + page).replace("#max#", "" + station.getMaxPage()));
int min = (page - 1) * slots.length, max = page * slots.length;
Inventory inv = Bukkit.createInventory(this, layout.getSize(), station.getName().replace("#page#", "" + page).replace("#max#", "" + station.getMaxPage()));
int min = (page - 1) * layout.getRecipeSlots().size(), max = page * layout.getRecipeSlots().size();
for (int j = min; j < max; j++) {
if (j >= recipes.size()) {
if (station.getItemOptions().hasNoRecipe())
inv.setItem(slots[j - min], station.getItemOptions().getNoRecipe());
inv.setItem(layout.getRecipeSlots().get(j - min), station.getItemOptions().getNoRecipe());
continue;
}
inv.setItem(slots[j - min], recipes.get(j).display());
inv.setItem(layout.getRecipeSlots().get(j - min), recipes.get(j).display());
}
if (station.getItemOptions().hasFill())
for (int slot : fill)
inv.setItem(slot, station.getItemOptions().getFill());
if (max < recipes.size())
inv.setItem(26, ConfigItem.NEXT_PAGE.getItem());
inv.setItem(layout.getRecipeNextSlot(), ConfigItem.NEXT_PAGE.getItem());
if (page > 1)
inv.setItem(18, ConfigItem.PREVIOUS_PAGE.getItem());
inv.setItem(layout.getRecipePreviousSlot(), ConfigItem.PREVIOUS_PAGE.getItem());
CraftingQueue queue = data.getCrafting().getQueue(station);
for (int j = queueOffset; j < queueOffset + queueSlots.length; j++) {
for (int j = queueOffset; j < queueOffset + layout.getQueueSlots().size(); j++) {
if (j >= queue.getCrafts().size()) {
if (station.getItemOptions().hasNoQueueItem())
inv.setItem(queueSlots[j - queueOffset], station.getItemOptions().getNoQueueItem());
inv.setItem(layout.getQueueSlots().get(j - queueOffset), station.getItemOptions().getNoQueueItem());
continue;
}
inv.setItem(queueSlots[j - queueOffset], ConfigItem.QUEUE_ITEM_DISPLAY.newBuilder(queue.getCrafts().get(j), j + 1).build());
inv.setItem(layout.getQueueSlots().get(j - queueOffset), ConfigItem.QUEUE_ITEM_DISPLAY.newBuilder(queue.getCrafts().get(j), j + 1).build());
}
if (queueOffset + queueSlots.length < queue.getCrafts().size())
inv.setItem(43, ConfigItem.NEXT_IN_QUEUE.getItem());
if (queueOffset + layout.getQueueSlots().size() < queue.getCrafts().size())
inv.setItem(layout.getQueueNextSlot(), ConfigItem.NEXT_IN_QUEUE.getItem());
if (queueOffset > 0)
inv.setItem(37, ConfigItem.PREVIOUS_IN_QUEUE.getItem());
inv.setItem(layout.getQueuePreviousSlot(), ConfigItem.PREVIOUS_IN_QUEUE.getItem());
new BukkitRunnable() {
public void run() {
@ -119,14 +114,18 @@ public class CraftingStationView extends PluginInventory {
return;
}
for (int j = queueOffset; j < queueOffset + queueSlots.length; j++)
for (int j = queueOffset; j < queueOffset + layout.getQueueSlots().size(); j++)
if (j >= queue.getCrafts().size())
inv.setItem(queueSlots[j - queueOffset],
inv.setItem(layout.getQueueSlots().get(j - queueOffset),
station.getItemOptions().hasNoQueueItem() ? station.getItemOptions().getNoQueueItem() : null);
else
inv.setItem(queueSlots[j - queueOffset], ConfigItem.QUEUE_ITEM_DISPLAY.newBuilder(queue.getCrafts().get(j), j + 1).build());
inv.setItem(layout.getQueueSlots().get(j - queueOffset), ConfigItem.QUEUE_ITEM_DISPLAY.newBuilder(queue.getCrafts().get(j), j + 1).build());
}
}.runTaskTimerAsynchronously(MMOItems.plugin, 0, 20);
if (station.getItemOptions().hasFill())
for (int j = 0; j < layout.getSize(); j++)
if (inv.getItem(j) == null || inv.getItem(j).getType() == Material.AIR)
inv.setItem(j, station.getItemOptions().getFill());
return inv;
}
@ -189,12 +188,12 @@ public class CraftingStationView extends PluginInventory {
ItemStack craftedItem = recipe.getOutput().generate(playerData.getRPG());
CustomSoundListener.stationCrafting(craftedItem, data.getPlayer());
if (!recipe.hasOption(Recipe.RecipeOption.SILENT_CRAFT))
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
data.getPlayer().playSound(data.getPlayer().getLocation(), station.getSound(), 1, 1);
if (recipe.hasOption(Recipe.RecipeOption.OUTPUT_ITEM))
new SmartGive(data.getPlayer()).give(craftedItem);
}
} else {
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
data.getPlayer().playSound(data.getPlayer().getLocation(), station.getSound(), 1, 1);
for (Ingredient ingredient : craft.getRecipe().getIngredients())
new SmartGive(data.getPlayer()).give(ingredient.generateItemStack(playerData.getRPG()));
}

View File

@ -1,21 +1,5 @@
package net.Indyuce.mmoitems.manager;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.text.DecimalFormat;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Level;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.potion.PotionEffectType;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.ConfigFile;
@ -28,6 +12,21 @@ import net.Indyuce.mmoitems.stat.LuteAttackEffectStat.LuteAttackEffect;
import net.Indyuce.mmoitems.stat.StaffSpiritStat.StaffSpirit;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.util.AltChar;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.potion.PotionEffectType;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.text.DecimalFormat;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Level;
public class ConfigManager {
@ -47,6 +46,7 @@ public class ConfigManager {
// try to setup non existing languages
public ConfigManager() {
mkdir("layouts");
mkdir("item");
mkdir("dynamic");
mkdir("language");
@ -197,7 +197,7 @@ public class ConfigManager {
} catch (IllegalArgumentException exception) {
defaultItemCapacity = new NumericStatFormula(5, .05, .1, .3);
MMOItems.plugin.getLogger().log(Level.INFO,
"An error occured while trying to load default capacity formula for the item generator, using default: "
"An error occurred while trying to load default capacity formula for the item generator, using default: "
+ exception.getMessage());
}
@ -279,6 +279,9 @@ public class ConfigManager {
LORE_FORMAT("lore-format.yml", "language", "lore-format.yml"),
STATS("stats.yml", "language", "stats.yml"),
// station layouts
DEFAULT_LAYOUT("layouts/default.yml", "layouts", "default.yml"),
// default item config files -> /MMOItems/item
ARMOR("item/armor.yml", "item", "armor.yml"),
AXE("item/axe.yml", "item", "axe.yml"),

View File

@ -0,0 +1,41 @@
package net.Indyuce.mmoitems.manager;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.crafting.Layout;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
public class LayoutManager {
private final Map<String, Layout> layouts = new HashMap<>();
public LayoutManager() {
}
public void reload() {
layouts.clear();
for (File file : new File(MMOItems.plugin.getDataFolder() + "/layouts").listFiles())
try {
Layout layout = new Layout(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file));
layouts.put(layout.getId(), layout);
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load layout '" + file.getName() + "': " + exception.getMessage());
}
}
public boolean hasLayout(String id) {
return layouts.containsKey(id);
}
public Collection<Layout> getLayouts() {
return layouts.values();
}
public Layout getLayout(String id) {
return layouts.getOrDefault(id, layouts.get("default"));
}
}

View File

@ -5,8 +5,20 @@ name: 'Arcane Forge (#page#/#max#)'
# The maximum amount of items in the crafting queue ie. the
# max number of items players are able to craft simultaneously.
# Must be between 1 and 64.
max-queue-size: 10
# The sound that plays whenever an action is
# completed in the crafting station.
# GET SOUND NAMES HERE:
# https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html
sound: ENTITY_EXPERIENCE_ORB_PICKUP
# This is how the gui looks. You can define your own
# in crafting-stations/layouts by creating a new
# file with the name of the file as the id.
layout: default
# Configure GUI items here
items:
fill:

View File

@ -5,8 +5,20 @@ name: 'Mythical Forge (#page#/#max#)'
# The maximum amount of items in the crafting queue ie. the
# max number of items players are able to craft simultaneously.
# Must be between 1 and 64.
max-queue-size: 10
# The sound that plays whenever an action is
# completed in the crafting station.
# GET SOUND NAMES HERE:
# https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html
sound: ENTITY_EXPERIENCE_ORB_PICKUP
# This is how the gui looks. You can define your own
# in crafting-stations/layouts by creating a new
# file with the name of the file as the id.
layout: default
# Crafting station parent. This station will inherit of
# all the recipes of the specified crafting station
parent: arcane-forge

View File

@ -5,8 +5,20 @@ name: 'Steel Crafting Station (#page#/#max#)'
# The maximum amount of items in the crafting queue ie. the
# max number of items players are able to craft simultaneously.
# Must be between 1 and 64.
max-queue-size: 10
# The sound that plays whenever an action is
# completed in the crafting station.
# GET SOUND NAMES HERE:
# https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html
sound: ENTITY_EXPERIENCE_ORB_PICKUP
# This is how the gui looks. You can define your own
# in crafting-stations/layouts by creating a new
# file with the name of the file as the id.
layout: default
# Configure GUI items here
items:
fill:
@ -34,7 +46,7 @@ recipes:
# Recipe options
options:
output-item: true # Set to false to give no item
silent-craft: false # No sound when clicking
silent-craft: false # No sound when item is claimed
hide-when-locked: false # Hide in the GUI when conditions are not met
# Conditions to unlock the recipe
@ -123,8 +135,7 @@ recipes:
type: MATERIAL
id: STEEL_INGOT
amount: 3
conditions:
- level{level=6}
crafting-time: 2
ingredients:
- vanilla{type=IRON_INGOT,amount=4,display="Iron Ingot"}
steel-dagger:

View File

@ -0,0 +1,25 @@
# The size of the gui. Must be
# between 9 and 54 and must be a multiple of 9.
slots: 54
layout:
# The slots that display the station's recipes.
recipe-slots: [10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 25]
# The slots that display the station's queue slots.
queue-slots: [38, 39, 40, 41, 42]
# The slots that display the arrows to navigate
# the station's recipes.
# Only shows when it can be used.
recipe-previous-slot: 18
recipe-next-slot: 26
# The slots that display the arrows to navigate
# the station's queue.
# Only shows when it can be used.
queue-previous-slot: 37
queue-next-slot: 43

View File

@ -0,0 +1,25 @@
# The size of the gui. Must be
# between 9 and 54 and must be a multiple of 9.
slots: 54
layout:
# The slots that display the station's recipes.
recipe-slots: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 21, 22, 23]
# The slots that display the station's queue slots.
queue-slots: [38, 39, 40, 41, 42]
# The slots that display the arrows to navigate
# the station's recipes.
# Only shows when it can be used.
recipe-previous-slot: 20
recipe-next-slot: 24
# The slots that display the arrows to navigate
# the station's queue.
# Only shows when it can be used.
queue-previous-slot: 37
queue-next-slot: 43