mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Finish custom recipe config gui.
This commit is contained in:
parent
c55c1c8c6a
commit
81a965e523
4 changed files with 64 additions and 10 deletions
|
|
@ -2,6 +2,7 @@ package xyz.alexcrea.cuanvil.gui.config.global;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
|
|
@ -41,6 +42,7 @@ public class CustomRecipeConfigGui extends MappedElementListConfigGui<AnvilCusto
|
||||||
ItemMeta meta = displaydItem.getItemMeta();
|
ItemMeta meta = displaydItem.getItemMeta();
|
||||||
|
|
||||||
meta.setDisplayName("\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(recipe.getName()) + " \u00A7fCustom recipe");
|
meta.setDisplayName("\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(recipe.getName()) + " \u00A7fCustom recipe");
|
||||||
|
meta.addItemFlags(ItemFlag.values());
|
||||||
|
|
||||||
boolean shouldWork = recipe.validate();
|
boolean shouldWork = recipe.validate();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ public class ItemSettingGui extends AbstractSettingGui {
|
||||||
|
|
||||||
CustomAnvil.Companion.getChatListener().setListenedCallback(player, (message) ->{
|
CustomAnvil.Companion.getChatListener().setListenedCallback(player, (message) ->{
|
||||||
|
|
||||||
if(message != null) return;
|
if(message == null) return;
|
||||||
show(player);
|
show(player);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
@ -152,7 +152,7 @@ public class ItemSettingGui extends AbstractSettingGui {
|
||||||
|
|
||||||
if(cursor.getType().isAir()) return;
|
if(cursor.getType().isAir()) return;
|
||||||
|
|
||||||
now = cursor;
|
this.now = cursor;
|
||||||
|
|
||||||
updateValueDisplay();
|
updateValueDisplay();
|
||||||
update();
|
update();
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
|
||||||
|
|
||||||
Pattern pattern = new Pattern(
|
Pattern pattern = new Pattern(
|
||||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||||
"01230450D",
|
"01203450D",
|
||||||
"B00000000"
|
"B00000000"
|
||||||
);
|
);
|
||||||
this.pane = new PatternPane(0, 0, 9, 3, pattern);
|
this.pane = new PatternPane(0, 0, 9, 3, pattern);
|
||||||
|
|
@ -85,16 +85,16 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
|
||||||
costRange.getFirst(), costRange.getLast(), AnvilCustomRecipe.Companion.getDEFAULT_XP_COST_CONFIG(), 1, 5, 10);
|
costRange.getFirst(), costRange.getLast(), AnvilCustomRecipe.Companion.getDEFAULT_XP_COST_CONFIG(), 1, 5, 10);
|
||||||
|
|
||||||
|
|
||||||
this.leftItemFactory = ItemSettingGui.itemFactory("\u00A78Recipe \u00A7eLeft \u00A78Item", this,
|
this.leftItemFactory = ItemSettingGui.itemFactory("\u00A7eRecipe Left \u00A78Item", this,
|
||||||
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.LEFT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.LEFT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||||
AnvilCustomRecipe.Companion.getDEFAULT_LEFT_ITEM_CONFIG());
|
AnvilCustomRecipe.Companion.getDEFAULT_LEFT_ITEM_CONFIG());
|
||||||
|
|
||||||
this.rightItemFactory = ItemSettingGui.itemFactory("\u00A78Recipe \u00A7eLeft \u00A78Item", this,
|
this.rightItemFactory = ItemSettingGui.itemFactory("\u00A7eRecipe Right \u00A78Item", this,
|
||||||
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.EXACT_COUNT_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.RIGHT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||||
AnvilCustomRecipe.Companion.getDEFAULT_RIGHT_ITEM_CONFIG());
|
AnvilCustomRecipe.Companion.getDEFAULT_RIGHT_ITEM_CONFIG());
|
||||||
|
|
||||||
this.resultItemFactory = ItemSettingGui.itemFactory("\u00A78Recipe \u00A7aResult \u00A78Item", this,
|
this.resultItemFactory = ItemSettingGui.itemFactory("\u00A7aRecipe Result \u00A78Item", this,
|
||||||
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.EXACT_COUNT_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.RESULT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||||
AnvilCustomRecipe.Companion.getDEFAULT_RESULT_ITEM_CONFIG());
|
AnvilCustomRecipe.Companion.getDEFAULT_RESULT_ITEM_CONFIG());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,12 +142,20 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
|
||||||
if (!this.shouldWork) return;
|
if (!this.shouldWork) return;
|
||||||
|
|
||||||
GuiItem exactCountItem = GuiGlobalItems.boolSettingGuiItem(this.exactCountFactory);
|
GuiItem exactCountItem = GuiGlobalItems.boolSettingGuiItem(this.exactCountFactory);
|
||||||
pane.bindItem('1', exactCountItem);
|
this.pane.bindItem('1', exactCountItem);
|
||||||
|
|
||||||
GuiItem xpCostItem = GuiGlobalItems.intSettingGuiItem(this.xpCostFactory, Material.EXPERIENCE_BOTTLE);
|
GuiItem xpCostItem = GuiGlobalItems.intSettingGuiItem(this.xpCostFactory, Material.EXPERIENCE_BOTTLE);
|
||||||
pane.bindItem('2', xpCostItem);
|
this.pane.bindItem('2', xpCostItem);
|
||||||
|
|
||||||
|
GuiItem leftGuiItem = GuiGlobalItems.itemSettingGuiItem(this.leftItemFactory);
|
||||||
|
this.pane.bindItem('3', leftGuiItem);
|
||||||
|
|
||||||
|
GuiItem rightGuiItem = GuiGlobalItems.itemSettingGuiItem(this.rightItemFactory);
|
||||||
|
this.pane.bindItem('4', rightGuiItem);
|
||||||
|
|
||||||
|
GuiItem resultGuiItem = GuiGlobalItems.itemSettingGuiItem(this.resultItemFactory);
|
||||||
|
this.pane.bindItem('5', resultGuiItem);
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,10 @@ import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.config.settings.ItemSettingGui;
|
||||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
|
|
||||||
|
import java.nio.charset.MalformedInputException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -264,6 +266,48 @@ public class GuiGlobalItems {
|
||||||
return intSettingGuiItem(factory, itemMat, CasedStringUtil.detectToUpperSpacedCase(configPath));
|
return intSettingGuiItem(factory, itemMat, CasedStringUtil.detectToUpperSpacedCase(configPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new item setting GuiItem.
|
||||||
|
* This item will create and open an item setting GUI from the factory.
|
||||||
|
* Item's name will be the factory set title.
|
||||||
|
*
|
||||||
|
* @param factory The setting's GUI factory.
|
||||||
|
* @param name Name of the item.
|
||||||
|
* @return A formatted GuiItem that will create and open a GUI for the item setting.
|
||||||
|
*/
|
||||||
|
public static GuiItem itemSettingGuiItem(
|
||||||
|
@NotNull ItemSettingGui.ItemSettingFactory factory,
|
||||||
|
@NotNull String name
|
||||||
|
) {
|
||||||
|
ItemStack item = factory.getConfiguredValue();
|
||||||
|
if(item == null || item.getType().isAir()){
|
||||||
|
item = new ItemStack(Material.BARRIER);
|
||||||
|
}else{
|
||||||
|
item = item.clone();
|
||||||
|
}
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
meta.setDisplayName("\u00A7a" + name);
|
||||||
|
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
|
||||||
|
return openSettingGuiItem(item, factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new item setting GuiItem.
|
||||||
|
* This item will create and open an item setting GUI from the factory.
|
||||||
|
* Item's name will be the factory set title.
|
||||||
|
*
|
||||||
|
* @param factory The setting's GUI factory.
|
||||||
|
* @return A formatted GuiItem that will create and open a GUI for the item setting.
|
||||||
|
*/
|
||||||
|
public static GuiItem itemSettingGuiItem(
|
||||||
|
@NotNull ItemSettingGui.ItemSettingFactory factory
|
||||||
|
) {
|
||||||
|
String configPath = getConfigNameFromPath(factory.getConfigPath());
|
||||||
|
return itemSettingGuiItem(factory, CasedStringUtil.detectToUpperSpacedCase(configPath));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an arbitrary GuiItem from a unique setting and item's property.
|
* Create an arbitrary GuiItem from a unique setting and item's property.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue