mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 08:25:56 +02:00
add unit repair to item config
This commit is contained in:
parent
d3cc101bed
commit
f4e07247e2
3 changed files with 22 additions and 9 deletions
|
|
@ -9,8 +9,10 @@ import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
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.gui.util.GuiGlobalActions;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
|
import xyz.alexcrea.cuanvil.util.UnitRepairUtil;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
|
@ -40,7 +42,7 @@ public class ItemConfigGui extends ChestGui {
|
||||||
|
|
||||||
displayMeta.setDisplayName("§aConfiguring " + material);
|
displayMeta.setDisplayName("§aConfiguring " + material);
|
||||||
displayItemstack.setItemMeta(displayMeta);
|
displayItemstack.setItemMeta(displayMeta);
|
||||||
pane.bindItem('D', new GuiItem(displayItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance));
|
pane.bindItem('D', new GuiItem(displayItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance));
|
||||||
|
|
||||||
// Enchantment Conflicts item
|
// Enchantment Conflicts item
|
||||||
ItemStack enchantConflictItemstack = new ItemStack(Material.OAK_FENCE);
|
ItemStack enchantConflictItemstack = new ItemStack(Material.OAK_FENCE);
|
||||||
|
|
@ -76,8 +78,7 @@ public class ItemConfigGui extends ChestGui {
|
||||||
unitRepairMeta.setLore(Collections.singletonList("§7Click here to open anvil unit repair menu"));
|
unitRepairMeta.setLore(Collections.singletonList("§7Click here to open anvil unit repair menu"));
|
||||||
unirRepairItemstack.setItemMeta(unitRepairMeta);
|
unirRepairItemstack.setItemMeta(unitRepairMeta);
|
||||||
|
|
||||||
//TODO
|
GuiItem unitRepairItem = GuiGlobalItems.goToGuiItem(unirRepairItemstack, getUnitRepairConfigGui(material));
|
||||||
GuiItem unitRepairItem = GuiGlobalItems.goToGuiItem(unirRepairItemstack, UnitRepairConfigGui.getInstance());
|
|
||||||
pane.bindItem('7', unitRepairItem);
|
pane.bindItem('7', unitRepairItem);
|
||||||
|
|
||||||
// Custom recipe item
|
// Custom recipe item
|
||||||
|
|
@ -118,16 +119,17 @@ public class ItemConfigGui extends ChestGui {
|
||||||
return groupConfigGui;
|
return groupConfigGui;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private UnitRepairConfigGui getUnitRepairConfigGui(NamespacedKey material) {
|
private UnitRepairConfigGui getUnitRepairConfigGui(NamespacedKey material) {
|
||||||
if (unitRepairConfigGui == null) {
|
if (unitRepairConfigGui == null) {
|
||||||
unitRepairConfigGui = new UnitRepairConfigGui(this);
|
unitRepairConfigGui = new UnitRepairConfigGui(this);
|
||||||
unitRepairConfigGui.setFilter(otherMat ->
|
unitRepairConfigGui.setFilter(otherMat ->
|
||||||
group.contain(material) //TODO check material & what inside
|
otherMat.equals(material) || UnitRepairUtil.INSTANCE.findRawRepairValue(
|
||||||
|
material, otherMat, ConfigHolder.UNIT_REPAIR_HOLDER.getConfig()) != null
|
||||||
);
|
);
|
||||||
unitRepairConfigGui.init();
|
unitRepairConfigGui.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
return unitRepairConfigGui;
|
return unitRepairConfigGui;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ public class UnitRepairConfigGui extends
|
||||||
protected ItemStack createItemForGeneric(@NotNull NamespacedKey material) {
|
protected ItemStack createItemForGeneric(@NotNull NamespacedKey material) {
|
||||||
var unitConfig = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig();
|
var unitConfig = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig();
|
||||||
var section = unitConfig.getConfigurationSection(material.toString().toLowerCase());
|
var section = unitConfig.getConfigurationSection(material.toString().toLowerCase());
|
||||||
var legacySection = unitConfig.getConfigurationSection(material.toString().toLowerCase());
|
var legacySection = unitConfig.getConfigurationSection(material.getKey().toLowerCase());
|
||||||
|
|
||||||
String materialName = CasedStringUtil.snakeToUpperSpacedCase(material.getKey().toLowerCase());
|
String materialName = CasedStringUtil.snakeToUpperSpacedCase(material.getKey().toLowerCase());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ object UnitRepairUtil {
|
||||||
if (other == null) return null
|
if (other == null) return null
|
||||||
val config = ConfigHolder.UNIT_REPAIR_HOLDER.config
|
val config = ConfigHolder.UNIT_REPAIR_HOLDER.config
|
||||||
|
|
||||||
val result = findRepairValue(this, other, config) ?: return null
|
val result = findRawRepairValue(this, other, config) ?: return null
|
||||||
|
|
||||||
if(result > 0) return result
|
if(result > 0) return result
|
||||||
|
|
||||||
|
|
@ -36,7 +36,7 @@ object UnitRepairUtil {
|
||||||
return userDefault
|
return userDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findRepairValue(
|
private fun findRawRepairValue(
|
||||||
self: ItemStack,
|
self: ItemStack,
|
||||||
other: ItemStack,
|
other: ItemStack,
|
||||||
config: FileConfiguration
|
config: FileConfiguration
|
||||||
|
|
@ -50,6 +50,17 @@ object UnitRepairUtil {
|
||||||
return checkSection(config, material.key, selfType)
|
return checkSection(config, material.key, selfType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun findRawRepairValue(
|
||||||
|
self: NamespacedKey,
|
||||||
|
other: NamespacedKey,
|
||||||
|
config: FileConfiguration
|
||||||
|
): Double? {
|
||||||
|
val result = checkSection(config, other.toString(), self)
|
||||||
|
if (result != null) return result
|
||||||
|
|
||||||
|
return checkSection(config, other.key, self)
|
||||||
|
}
|
||||||
|
|
||||||
fun checkSection(
|
fun checkSection(
|
||||||
config: FileConfiguration,
|
config: FileConfiguration,
|
||||||
path: String,
|
path: String,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue