mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 08:25:56 +02:00
Compare commits
No commits in common. "c062684a3cea5a5b98b5113ce8fc49685f126281" and "f6f68d19714a70bfa35b44f2990ccf2f5afd885c" have entirely different histories.
c062684a3c
...
f6f68d1971
29 changed files with 341 additions and 1043 deletions
|
|
@ -3,16 +3,18 @@ package xyz.alexcrea.cuanvil.api;
|
|||
import io.delilaheve.CustomAnvil;
|
||||
import kotlin.Triple;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.dependency.DependencyManager;
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.UnitRepairConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.list.MappedGuiListConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.list.UnitRepairElementListGui;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Custom Anvil api for unit repair.
|
||||
|
|
@ -20,8 +22,7 @@ import java.util.*;
|
|||
@SuppressWarnings("unused")
|
||||
public class UnitRepairApi {
|
||||
|
||||
private UnitRepairApi() {
|
||||
}
|
||||
private UnitRepairApi(){}
|
||||
|
||||
private static Object saveChangeTask = null;
|
||||
|
||||
|
|
@ -38,19 +39,6 @@ public class UnitRepairApi {
|
|||
return addUnitRepair(unit, repairable, 0.25, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write and add a custom anvil unit repair recipe.
|
||||
* Will not write the recipe if it already exists or was deleted.
|
||||
* Set the value to minecraft default value (0.25 = 25%)
|
||||
*
|
||||
* @param unit The unit material used to repair the bellow item.
|
||||
* @param repairable The item to be repaired.
|
||||
* @return true if successful.
|
||||
*/
|
||||
public static boolean addUnitRepair(@NotNull NamespacedKey unit, @NotNull NamespacedKey repairable) {
|
||||
return addUnitRepair(unit, repairable, 0.25, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write and add a custom anvil unit repair recipe.
|
||||
* Will not write the recipe if it already exists or was deleted.
|
||||
|
|
@ -75,22 +63,8 @@ public class UnitRepairApi {
|
|||
* @return true if successful.
|
||||
*/
|
||||
public static boolean addUnitRepair(@NotNull Material unit, @NotNull Material repairable, double value, boolean overrideDeleted){
|
||||
return addUnitRepair(unit.getKey(), repairable.getKey(), value, overrideDeleted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write and add a custom anvil unit repair recipe.
|
||||
* Will not write the recipe if it already exists.
|
||||
*
|
||||
* @param unit The unit material used to repair the bellow item.
|
||||
* @param repairable The item to be repaired.
|
||||
* @param value The amount to be repaired by every unit. (1% = 0.01)
|
||||
* @param overrideDeleted If we should write even if the recipe was previously deleted.
|
||||
* @return true if successful.
|
||||
*/
|
||||
public static boolean addUnitRepair(@NotNull NamespacedKey unit, @NotNull NamespacedKey repairable, double value, boolean overrideDeleted) {
|
||||
FileConfiguration config = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig();
|
||||
String path = unit.toString().toLowerCase() + "." + repairable.toString().toLowerCase();
|
||||
String path = unit.name().toLowerCase() + "." + repairable.name().toLowerCase();
|
||||
|
||||
if(!overrideDeleted && ConfigHolder.UNIT_REPAIR_HOLDER.isDeleted(path)) return false;
|
||||
if(config.contains(path)) return false;
|
||||
|
|
@ -109,23 +83,10 @@ public class UnitRepairApi {
|
|||
* @return true if successful.
|
||||
*/
|
||||
public static boolean setUnitRepair(@NotNull Material unit, @NotNull Material repairable, double value){
|
||||
return setUnitRepair(unit.getKey(), repairable.getKey(), value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write and add a custom anvil unit repair recipe.
|
||||
* Do not check if it previously existed or exist.
|
||||
*
|
||||
* @param unit The unit material used to repair the bellow item.
|
||||
* @param repairable The item to be repaired.
|
||||
* @param value The amount to be repaired by every unit. (1% = 0.01)
|
||||
* @return true if successful.
|
||||
*/
|
||||
public static boolean setUnitRepair(@NotNull NamespacedKey unit, @NotNull NamespacedKey repairable, double value) {
|
||||
FileConfiguration config = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig();
|
||||
|
||||
String repairableName = repairable.toString().toLowerCase();
|
||||
String path = unit.toString().toLowerCase() + "." + repairableName;
|
||||
String repairableName = repairable.name().toLowerCase();
|
||||
String path = unit.name().toLowerCase() + "." + repairableName;
|
||||
|
||||
// Add to config then prepare save
|
||||
config.set(path, value);
|
||||
|
|
@ -136,7 +97,7 @@ public class UnitRepairApi {
|
|||
if(repairConfigGui != null) {
|
||||
UnitRepairElementListGui elementGui = repairConfigGui.getInstanceOrCreate(unit).getStored();
|
||||
|
||||
if (elementGui != null) elementGui.updateValueForGeneric(repairable, true);
|
||||
if(elementGui != null) elementGui.updateValueForGeneric(repairableName, true);
|
||||
repairConfigGui.updateValueForGeneric(unit, true);
|
||||
}
|
||||
|
||||
|
|
@ -151,46 +112,38 @@ public class UnitRepairApi {
|
|||
* @return true if successful.
|
||||
*/
|
||||
public static boolean removeUnitRepair(@NotNull Material unit, @NotNull Material repairable){
|
||||
return removeUnitRepair(unit.getKey(), repairable.getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a custom anvil unit repair recipe.
|
||||
*
|
||||
* @param unit The unit material used to repair the bellow item.
|
||||
* @param repairable The item used to be repaired.
|
||||
* @return true if successful.
|
||||
*/
|
||||
public static boolean removeUnitRepair(@NotNull NamespacedKey unit, @NotNull NamespacedKey repairable) {
|
||||
// Delete every possible variation and save to file
|
||||
String unitName = unit.name();
|
||||
String repairableName = repairable.name();
|
||||
|
||||
FileConfiguration config = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig();
|
||||
config.set(unit.getKey() + "." + repairable.getKey(), null);
|
||||
config.set(unit.getKey() + "." + repairable, null);
|
||||
config.set(unit + "." + repairable.getKey(), null);
|
||||
config.set(unit + "." + repairable, null);
|
||||
config.set(unitName.toLowerCase() + "." + repairableName.toUpperCase(), null);
|
||||
config.set(unitName.toUpperCase() + "." + repairableName.toLowerCase(), null);
|
||||
config.set(unitName.toUpperCase() + "." + repairableName.toUpperCase(), null);
|
||||
config.set(unitName.toLowerCase() + "." + repairableName.toLowerCase(), null);
|
||||
|
||||
// Test if it was the last value of this section
|
||||
boolean lastValue = false;
|
||||
if (config.isConfigurationSection(unit.toString())) {
|
||||
ConfigurationSection section = config.getConfigurationSection(unit.toString());
|
||||
if(config.isConfigurationSection(unitName.toLowerCase())) {
|
||||
ConfigurationSection section = config.getConfigurationSection(unitName.toLowerCase());
|
||||
|
||||
if(section != null && section.getKeys(false).isEmpty()) {
|
||||
lastValue = true;
|
||||
config.set(unit.toString(), null);
|
||||
config.set(unitName.toLowerCase(), null);
|
||||
}
|
||||
|
||||
} else if (config.isConfigurationSection(unit.getKey())) {
|
||||
ConfigurationSection section = config.getConfigurationSection(unit.getKey());
|
||||
} else if (config.isConfigurationSection(unitName.toUpperCase())) {
|
||||
ConfigurationSection section = config.getConfigurationSection(unitName.toUpperCase());
|
||||
if(section != null && section.getKeys(false).isEmpty()) {
|
||||
lastValue = true;
|
||||
config.set(unit.getKey(), null);
|
||||
config.set(unitName.toUpperCase(), null);
|
||||
}
|
||||
|
||||
} else lastValue = true;
|
||||
|
||||
|
||||
ConfigHolder.UNIT_REPAIR_HOLDER.delete(unit.toString().toLowerCase() + "." + repairable.toString().toLowerCase());
|
||||
// We only need to "delete" as the lower case to be counted as deleted
|
||||
ConfigHolder.UNIT_REPAIR_HOLDER.delete(unitName.toLowerCase() + "." + repairableName.toLowerCase());
|
||||
prepareSaveTask();
|
||||
|
||||
// Remove from gui
|
||||
|
|
@ -198,7 +151,7 @@ public class UnitRepairApi {
|
|||
if(repairConfigGui != null) {
|
||||
UnitRepairElementListGui elementGui = repairConfigGui.getInstanceOrCreate(unit).getStored();
|
||||
|
||||
if (elementGui != null) elementGui.removeGeneric(repairable);
|
||||
if(elementGui != null) elementGui.removeGeneric(repairableName);
|
||||
if(lastValue){
|
||||
repairConfigGui.removeGeneric(unit);
|
||||
}
|
||||
|
|
@ -221,7 +174,6 @@ public class UnitRepairApi {
|
|||
|
||||
/**
|
||||
* Get every unit repair recipes.
|
||||
*
|
||||
* @return An immutable collection of unit repair recipes.
|
||||
* <p>
|
||||
* Each element of the provided triple represent a part of the recipe
|
||||
|
|
@ -230,10 +182,7 @@ public class UnitRepairApi {
|
|||
* <li>Second object is the item to be repaired.
|
||||
* <li>Last object is the amount to be repaired by every unit. (1% = 0.01)
|
||||
* </ul>
|
||||
* @deprecated some may be missing. use {@link #getModernUnitRepairs()}
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public static List<Triple<Material, Material, Double>> getUnitRepairs(){
|
||||
List<Triple<Material, Material, Double>> mutableList = new ArrayList<>();
|
||||
|
|
@ -266,53 +215,4 @@ public class UnitRepairApi {
|
|||
return Collections.unmodifiableList(mutableList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get every unit repair recipes.
|
||||
*
|
||||
* @return An immutable collection of unit repair recipes.
|
||||
* <p>
|
||||
* <li>First map contain a key the unit material used to repair the bellow item and value the second map
|
||||
* <li>Second map contain as key the item to be repaired and as value the amount to be repaired by every unit. (1% = 0.01)
|
||||
* </ul>
|
||||
*/
|
||||
@NotNull
|
||||
public static Map<NamespacedKey, Map<NamespacedKey, Double>> getModernUnitRepairs() {
|
||||
Map<NamespacedKey, Map<NamespacedKey, Double>> mutableList = new HashMap<>();
|
||||
|
||||
FileConfiguration config = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig();
|
||||
for (String unitKey : config.getKeys(false)) {
|
||||
// Test if config section exist
|
||||
if (!config.isConfigurationSection(unitKey)) continue;
|
||||
|
||||
// Test if unit is a material
|
||||
NamespacedKey unit = NamespacedKey.fromString(unitKey.toLowerCase());
|
||||
if (unit == null) continue;
|
||||
|
||||
Map<NamespacedKey, Double> map;
|
||||
if (!mutableList.containsKey(unit)) {
|
||||
map = new HashMap<>();
|
||||
mutableList.put(unit, map);
|
||||
} else {
|
||||
map = mutableList.get(unit);
|
||||
}
|
||||
|
||||
// Iterate over reparable items
|
||||
ConfigurationSection section = config.getConfigurationSection(unitKey);
|
||||
for (String repairableKey : section.getKeys(false)) {
|
||||
// Test if value section exist
|
||||
if (!section.isDouble(repairableKey)) continue;
|
||||
|
||||
// Test if repairable is valid a material
|
||||
NamespacedKey repairable = NamespacedKey.fromString(repairableKey.toLowerCase());
|
||||
if (repairable == null) continue;
|
||||
|
||||
// Add the values
|
||||
map.put(repairable, section.getDouble(repairableKey));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return mutableList;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import org.jetbrains.annotations.Nullable;
|
|||
import xyz.alexcrea.cuanvil.enchant.bulk.BulkCleanEnchantOperation;
|
||||
import xyz.alexcrea.cuanvil.enchant.bulk.BulkGetEnchantOperation;
|
||||
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -46,14 +45,6 @@ public interface CAEnchantment {
|
|||
@NotNull
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Get the enchantment name prettified (upper spaced case)
|
||||
* @return Prettier enchantment name
|
||||
*/
|
||||
default String getPrettyName() {
|
||||
return CasedStringUtil.snakeToUpperSpacedCase(getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default maximum level of this enchantment.
|
||||
* @return The default maximum level of this enchantment.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package xyz.alexcrea.cuanvil.gui.config;
|
|||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
|
||||
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
|
|
@ -40,142 +39,116 @@ public class MainConfigGui extends ChestGui {
|
|||
GuiGlobalItems.addBackgroundItem(pane);
|
||||
|
||||
// Basic config item
|
||||
var basicConfigItem = basicConfigItem(new BasicConfigGui(packetManager));
|
||||
ItemStack basicConfigItemstack = new ItemStack(Material.COMMAND_BLOCK);
|
||||
ItemMeta basicConfigMeta = basicConfigItemstack.getItemMeta();
|
||||
assert basicConfigMeta != null;
|
||||
|
||||
basicConfigMeta.setDisplayName("§aBasic Config Menu");
|
||||
basicConfigMeta.setLore(Collections.singletonList("§7Click here to open basic config menu"));
|
||||
basicConfigItemstack.setItemMeta(basicConfigMeta);
|
||||
|
||||
GuiItem basicConfigItem = GuiGlobalItems.goToGuiItem(basicConfigItemstack, new BasicConfigGui(packetManager));
|
||||
pane.bindItem('1', basicConfigItem);
|
||||
|
||||
// enchant level limit item
|
||||
var enchantLimitItem = enchantLimitItem(new EnchantLimitConfigGui());
|
||||
ItemStack enchantLimitItemstack = new ItemStack(Material.ENCHANTED_BOOK);
|
||||
ItemMeta enchantLimitMeta = enchantLimitItemstack.getItemMeta();
|
||||
assert enchantLimitMeta != null;
|
||||
|
||||
enchantLimitMeta.setDisplayName("§aEnchantment Level Limit");
|
||||
enchantLimitMeta.setLore(Collections.singletonList("§7Click here to open enchantment level limit menu"));
|
||||
enchantLimitItemstack.setItemMeta(enchantLimitMeta);
|
||||
|
||||
GuiItem enchantLimitItem = GuiGlobalItems.goToGuiItem(enchantLimitItemstack, new EnchantLimitConfigGui());
|
||||
pane.bindItem('2', enchantLimitItem);
|
||||
|
||||
// enchant level limit item
|
||||
var enchantMergeLimitItem = enchantMergeLimitItem(new EnchantMergeLimitConfigGui());
|
||||
ItemStack enchantMergeLimitItemstack = new ItemStack(Material.ENCHANTED_BOOK);
|
||||
ItemMeta enchantMergeLimitMeta = enchantMergeLimitItemstack.getItemMeta();
|
||||
assert enchantMergeLimitMeta != null;
|
||||
|
||||
enchantMergeLimitMeta.setDisplayName("§aEnchantment Merge Limit");
|
||||
enchantMergeLimitMeta.setLore(Collections.singletonList("§7Click here to open enchantment merge limit menu"));
|
||||
enchantMergeLimitItemstack.setItemMeta(enchantMergeLimitMeta);
|
||||
|
||||
GuiItem enchantMergeLimitItem = GuiGlobalItems.goToGuiItem(enchantMergeLimitItemstack, new EnchantMergeLimitConfigGui());
|
||||
pane.bindItem('3', enchantMergeLimitItem);
|
||||
|
||||
// enchant cost item
|
||||
var enchantCostItem = enchantCostItem(new EnchantCostConfigGui());
|
||||
ItemStack enchantCostItemstack = new ItemStack(Material.EXPERIENCE_BOTTLE);
|
||||
ItemMeta enchantCostMeta = enchantCostItemstack.getItemMeta();
|
||||
assert enchantCostMeta != null;
|
||||
|
||||
enchantCostMeta.setDisplayName("§aEnchantment Cost");
|
||||
enchantCostMeta.setLore(Collections.singletonList("§7Click here to open enchantment costs menu"));
|
||||
enchantCostItemstack.setItemMeta(enchantCostMeta);
|
||||
|
||||
GuiItem enchantCostItem = GuiGlobalItems.goToGuiItem(enchantCostItemstack, new EnchantCostConfigGui());
|
||||
pane.bindItem('4', enchantCostItem);
|
||||
|
||||
// Enchantment Conflicts item
|
||||
var enchantConflictItem = enchantConflictItem(EnchantConflictGui.getInstance());
|
||||
ItemStack enchantConflictItemstack = new ItemStack(Material.OAK_FENCE);
|
||||
ItemMeta enchantConflictMeta = enchantConflictItemstack.getItemMeta();
|
||||
assert enchantConflictMeta != null;
|
||||
|
||||
enchantConflictMeta.setDisplayName("§aEnchantment Conflict");
|
||||
enchantConflictMeta.setLore(Collections.singletonList("§7Click here to open enchantment conflict menu"));
|
||||
enchantConflictItemstack.setItemMeta(enchantConflictMeta);
|
||||
|
||||
GuiItem enchantConflictItem = GuiGlobalItems.goToGuiItem(enchantConflictItemstack, EnchantConflictGui.getInstance());
|
||||
pane.bindItem('5', enchantConflictItem);
|
||||
|
||||
// Group config items
|
||||
var groupConfigItem = groupConfigItem(GroupConfigGui.getInstance());
|
||||
ItemStack groupItemstack = new ItemStack(Material.CHEST);
|
||||
ItemMeta groupMeta = groupItemstack.getItemMeta();
|
||||
assert groupMeta != null;
|
||||
|
||||
groupMeta.setDisplayName("§aItem Groups");
|
||||
groupMeta.setLore(Collections.singletonList("§7Click here to open item group menu"));
|
||||
groupItemstack.setItemMeta(groupMeta);
|
||||
|
||||
GuiItem groupConfigItem = GuiGlobalItems.goToGuiItem(groupItemstack, GroupConfigGui.getInstance());
|
||||
|
||||
pane.bindItem('6', groupConfigItem);
|
||||
|
||||
// Unit repair item
|
||||
var unitRepairItem = unitRepairItem(UnitRepairConfigGui.getInstance());
|
||||
ItemStack unirRepairItemstack = new ItemStack(Material.DIAMOND);
|
||||
ItemMeta unitRepairMeta = unirRepairItemstack.getItemMeta();
|
||||
assert unitRepairMeta != null;
|
||||
|
||||
unitRepairMeta.setDisplayName("§aUnit Repair");
|
||||
unitRepairMeta.setLore(Collections.singletonList("§7Click here to open anvil unit repair menu"));
|
||||
unirRepairItemstack.setItemMeta(unitRepairMeta);
|
||||
|
||||
GuiItem unitRepairItem = GuiGlobalItems.goToGuiItem(unirRepairItemstack, UnitRepairConfigGui.getInstance());
|
||||
pane.bindItem('7', unitRepairItem);
|
||||
|
||||
// Custom recipe item
|
||||
var customRecipeItem = customRecipeItem(CustomRecipeConfigGui.getInstance());
|
||||
ItemStack customRecipeItemstack = new ItemStack(Material.CRAFTING_TABLE);
|
||||
ItemMeta customRecipeMeta = customRecipeItemstack.getItemMeta();
|
||||
assert customRecipeMeta != null;
|
||||
|
||||
customRecipeMeta.setDisplayName("§aCustom recipes");
|
||||
customRecipeMeta.setLore(Collections.singletonList("§7Click here to open anvil custom recipe menu"));
|
||||
customRecipeItemstack.setItemMeta(customRecipeMeta);
|
||||
|
||||
GuiItem customRecipeItem = GuiGlobalItems.goToGuiItem(customRecipeItemstack, CustomRecipeConfigGui.getInstance());
|
||||
pane.bindItem('8', customRecipeItem);
|
||||
|
||||
// quit item
|
||||
pane.bindItem('Q', quitItem());
|
||||
}
|
||||
ItemStack quitItemstack = new ItemStack(Material.BARRIER);
|
||||
ItemMeta quitMeta = quitItemstack.getItemMeta();
|
||||
assert quitMeta != null;
|
||||
|
||||
public static GuiItem basicConfigItem(Gui target) {
|
||||
var item = new ItemStack(Material.COMMAND_BLOCK);
|
||||
var meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
quitMeta.setDisplayName("§cQuit");
|
||||
quitItemstack.setItemMeta(quitMeta);
|
||||
|
||||
meta.setDisplayName("§aBasic Config Menu");
|
||||
meta.setLore(Collections.singletonList("§7Click here to open basic config menu"));
|
||||
item.setItemMeta(meta);
|
||||
return GuiGlobalItems.goToGuiItem(item, target);
|
||||
}
|
||||
|
||||
public static GuiItem enchantLimitItem(Gui target) {
|
||||
var item = new ItemStack(Material.ENCHANTED_BOOK);
|
||||
var meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
|
||||
meta.setDisplayName("§aEnchantment Level Limit");
|
||||
meta.setLore(Collections.singletonList("§7Click here to open enchantment level limit menu"));
|
||||
item.setItemMeta(meta);
|
||||
return GuiGlobalItems.goToGuiItem(item, target);
|
||||
}
|
||||
|
||||
public static GuiItem enchantMergeLimitItem(Gui target) {
|
||||
ItemStack item = new ItemStack(Material.ENCHANTED_BOOK);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
|
||||
meta.setDisplayName("§aEnchantment Merge Limit");
|
||||
meta.setLore(Collections.singletonList("§7Click here to open enchantment merge limit menu"));
|
||||
item.setItemMeta(meta);
|
||||
return GuiGlobalItems.goToGuiItem(item, target);
|
||||
}
|
||||
|
||||
public static GuiItem enchantCostItem(Gui target) {
|
||||
ItemStack item = new ItemStack(Material.EXPERIENCE_BOTTLE);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
|
||||
meta.setDisplayName("§aEnchantment Cost");
|
||||
meta.setLore(Collections.singletonList("§7Click here to open enchantment costs menu"));
|
||||
item.setItemMeta(meta);
|
||||
return GuiGlobalItems.goToGuiItem(item, target);
|
||||
}
|
||||
|
||||
public static GuiItem enchantConflictItem(Gui target) {
|
||||
var item = new ItemStack(Material.OAK_FENCE);
|
||||
var meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
|
||||
meta.setDisplayName("§aEnchantment Conflict");
|
||||
meta.setLore(Collections.singletonList("§7Click here to open enchantment conflict menu"));
|
||||
item.setItemMeta(meta);
|
||||
return GuiGlobalItems.goToGuiItem(item, target);
|
||||
}
|
||||
|
||||
public static GuiItem groupConfigItem(Gui target) {
|
||||
var item = new ItemStack(Material.CHEST);
|
||||
var meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
|
||||
meta.setDisplayName("§aItem Groups");
|
||||
meta.setLore(Collections.singletonList("§7Click here to open item group menu"));
|
||||
item.setItemMeta(meta);
|
||||
return GuiGlobalItems.goToGuiItem(item, target);
|
||||
}
|
||||
|
||||
public static GuiItem unitRepairItem(Gui target) {
|
||||
var item = new ItemStack(Material.DIAMOND);
|
||||
var meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
|
||||
meta.setDisplayName("§aUnit Repair");
|
||||
meta.setLore(Collections.singletonList("§7Click here to open anvil unit repair menu"));
|
||||
item.setItemMeta(meta);
|
||||
|
||||
return GuiGlobalItems.goToGuiItem(item, target);
|
||||
}
|
||||
|
||||
public static GuiItem customRecipeItem(Gui target) {
|
||||
var item = new ItemStack(Material.CRAFTING_TABLE);
|
||||
var meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
|
||||
meta.setDisplayName("§aCustom recipes");
|
||||
meta.setLore(Collections.singletonList("§7Click here to open anvil custom recipe menu"));
|
||||
item.setItemMeta(meta);
|
||||
return GuiGlobalItems.goToGuiItem(item, target);
|
||||
}
|
||||
|
||||
public static GuiItem quitItem() {
|
||||
var item = new ItemStack(Material.BARRIER);
|
||||
var meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
|
||||
meta.setDisplayName("§cQuit");
|
||||
item.setItemMeta(meta);
|
||||
|
||||
return new GuiItem(item, event -> {
|
||||
GuiItem quitItem = new GuiItem(quitItemstack, event -> {
|
||||
event.setCancelled(true);
|
||||
event.getWhoClicked().closeInventory();
|
||||
}, CustomAnvil.instance);
|
||||
pane.bindItem('Q', quitItem);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.list.SettingGuiListConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.SettingGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||
|
|
@ -31,17 +31,13 @@ public abstract class AbstractEnchantConfigGui<T extends SettingGui.SettingGuiFa
|
|||
super(title);
|
||||
}
|
||||
|
||||
protected AbstractEnchantConfigGui(String title, Gui parent) {
|
||||
super(title, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateGuiValues() { //TODO maybe optimise it.
|
||||
reloadValues();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<CAEnchantment> getEveryInstanceOfGeneric() {
|
||||
protected Collection<CAEnchantment> getEveryDisplayableInstanceOfGeneric() {
|
||||
return CAEnchantmentRegistry.getInstance().getNameSortedEnchantments();
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +73,7 @@ public abstract class AbstractEnchantConfigGui<T extends SettingGui.SettingGuiFa
|
|||
this.pages.clear();
|
||||
this.pages.add(this.firstPage);
|
||||
|
||||
for (CAEnchantment enchantment : getDisplayableInstanceOfGeneric()) {
|
||||
for (CAEnchantment enchantment : getEveryDisplayableInstanceOfGeneric()) {
|
||||
GuiItem item = this.guiItemMap.get(enchantment);
|
||||
|
||||
if(item == null) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
|
@ -41,10 +40,6 @@ public class CustomRecipeConfigGui extends MappedGuiListConfigGui<AnvilCustomRec
|
|||
init();
|
||||
}
|
||||
|
||||
public CustomRecipeConfigGui(Gui parent) {
|
||||
super("Custom Recipe Config", parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack createItemForGeneric(AnvilCustomRecipe recipe) {
|
||||
// Get base item to display
|
||||
|
|
@ -118,7 +113,7 @@ public class CustomRecipeConfigGui extends MappedGuiListConfigGui<AnvilCustomRec
|
|||
|
||||
|
||||
@Override
|
||||
protected Collection<AnvilCustomRecipe> getEveryInstanceOfGeneric() {
|
||||
protected Collection<AnvilCustomRecipe> getEveryDisplayableInstanceOfGeneric() {
|
||||
return ConfigHolder.CUSTOM_RECIPE_HOLDER.getRecipeManager().getRecipeList();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,196 +0,0 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
|
||||
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.alexcrea.cuanvil.api.EnchantmentApi;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EnchantConfigGui extends ChestGui implements ValueUpdatableGui {
|
||||
|
||||
private final Set<CAEnchantment> enchantments;
|
||||
private final PatternPane pane;
|
||||
|
||||
private EnchantLimitConfigGui enchantLimitConfigGui;
|
||||
private EnchantMergeLimitConfigGui enchantMergeLimitConfigGui;
|
||||
private EnchantCostConfigGui enchantCostConfigGui;
|
||||
|
||||
private EnchantConflictGui enchantConflictGui;
|
||||
private GroupConfigGui groupConfigGui;
|
||||
|
||||
public EnchantConfigGui(@NotNull Set<CAEnchantment> enchantments) {
|
||||
super(3,
|
||||
"Configuring Enchantments",
|
||||
CustomAnvil.instance);
|
||||
this.enchantments = enchantments;
|
||||
|
||||
Pattern pattern = new Pattern(
|
||||
"0000D0000",
|
||||
"023405600",
|
||||
"Q00000000"
|
||||
);
|
||||
pane = new PatternPane(0, 0, 9, 3, pattern);
|
||||
addPane(pane);
|
||||
|
||||
GuiGlobalItems.addBackgroundItem(pane);
|
||||
|
||||
ItemStack displayItemstack = new ItemStack(Material.ENCHANTED_BOOK);
|
||||
ItemMeta displayMeta = displayItemstack.getItemMeta();
|
||||
assert displayMeta != null;
|
||||
|
||||
displayMeta.setDisplayName("§aConfiguring Enchantments:");
|
||||
displayItemstack.setItemMeta(displayMeta);
|
||||
|
||||
// Set enchantments
|
||||
HashMap<CAEnchantment, Integer> enchantmentMap = new HashMap<>();
|
||||
for (CAEnchantment enchantment : enchantments) {
|
||||
enchantmentMap.put(enchantment, 1);
|
||||
}
|
||||
EnchantmentApi.setEnchantments(displayItemstack, enchantmentMap);
|
||||
|
||||
pane.bindItem('D', new GuiItem(displayItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance));
|
||||
|
||||
updateGuiValues();
|
||||
|
||||
// Enchantment Conflicts item
|
||||
var enchantConflictItem = MainConfigGui.enchantConflictItem(getEnchantConflictGui());
|
||||
pane.bindItem('5', enchantConflictItem);
|
||||
|
||||
// Group config items
|
||||
var groupConfigItem = MainConfigGui.groupConfigItem(getGroupConfigGui());
|
||||
pane.bindItem('6', groupConfigItem);
|
||||
|
||||
// quit item
|
||||
pane.bindItem('Q', MainConfigGui.quitItem());
|
||||
}
|
||||
|
||||
private GuiItem enchantLimitConfigGui() {
|
||||
if (enchantLimitConfigGui == null) {
|
||||
enchantLimitConfigGui = new EnchantLimitConfigGui(this);
|
||||
enchantLimitConfigGui.setFilter(enchantments::contains);
|
||||
enchantLimitConfigGui.init();
|
||||
}
|
||||
|
||||
// Bypass
|
||||
if(enchantments.size() == 1) {
|
||||
var enchant = enchantments.iterator().next();
|
||||
var factory = EnchantLimitConfigGui.createFactory(enchant, this);
|
||||
|
||||
return enchantLimitConfigGui.itemFromFactory(enchant, factory);
|
||||
}
|
||||
|
||||
return MainConfigGui.enchantLimitItem(enchantLimitConfigGui);
|
||||
}
|
||||
|
||||
private GuiItem enchantMergeLimitConfigGui() {
|
||||
if (enchantMergeLimitConfigGui == null) {
|
||||
enchantMergeLimitConfigGui = new EnchantMergeLimitConfigGui(this);
|
||||
enchantMergeLimitConfigGui.setFilter(enchantments::contains);
|
||||
enchantMergeLimitConfigGui.init();
|
||||
}
|
||||
|
||||
// Bypass
|
||||
if(enchantments.size() == 1) {
|
||||
var enchant = enchantments.iterator().next();
|
||||
var factory = EnchantMergeLimitConfigGui.createFactory(enchant, this);
|
||||
|
||||
return enchantMergeLimitConfigGui.itemFromFactory(enchant, factory);
|
||||
}
|
||||
|
||||
return MainConfigGui.enchantMergeLimitItem(enchantMergeLimitConfigGui);
|
||||
}
|
||||
|
||||
private GuiItem enchantCostConfigGui() {
|
||||
if (enchantCostConfigGui == null) {
|
||||
enchantCostConfigGui = new EnchantCostConfigGui(this);
|
||||
enchantCostConfigGui.setFilter(enchantments::contains);
|
||||
enchantCostConfigGui.init();
|
||||
}
|
||||
|
||||
// Bypass
|
||||
if(enchantments.size() == 1) {
|
||||
var enchant = enchantments.iterator().next();
|
||||
var factory = EnchantCostConfigGui.createFactory(enchant, this);
|
||||
|
||||
return enchantCostConfigGui.itemFromFactory(enchant, factory);
|
||||
}
|
||||
|
||||
return MainConfigGui.enchantCostItem(enchantCostConfigGui);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Contract(pure = true)
|
||||
private Predicate<EnchantConflictGroup> getGroupFilter() {
|
||||
return group -> group.getEnchants()
|
||||
.stream()
|
||||
.anyMatch(enchantments::contains);
|
||||
}
|
||||
|
||||
private EnchantConflictGui getEnchantConflictGui() {
|
||||
if (enchantConflictGui == null) {
|
||||
enchantConflictGui = new EnchantConflictGui(this);
|
||||
enchantConflictGui.setFilter(getGroupFilter());
|
||||
enchantConflictGui.init();
|
||||
}
|
||||
|
||||
return enchantConflictGui;
|
||||
}
|
||||
|
||||
private GroupConfigGui getGroupConfigGui() {
|
||||
if (groupConfigGui == null) {
|
||||
groupConfigGui = new GroupConfigGui(this);
|
||||
|
||||
// Get all the conflict related to this enchantment
|
||||
var groups = ConfigHolder.CONFLICT_HOLDER
|
||||
.getConflictManager()
|
||||
.getConflictList()
|
||||
.stream()
|
||||
.filter(getGroupFilter())
|
||||
.map(EnchantConflictGroup::getCantConflictGroup)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
groupConfigGui.setFilter(group ->
|
||||
groups.stream().anyMatch(other -> other.isReferencing(group))
|
||||
);
|
||||
groupConfigGui.init();
|
||||
}
|
||||
|
||||
return groupConfigGui;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateGuiValues() {
|
||||
// enchant level limit item
|
||||
pane.bindItem('2', enchantLimitConfigGui());
|
||||
|
||||
// enchant level limit item
|
||||
pane.bindItem('3', enchantMergeLimitConfigGui());
|
||||
|
||||
// enchant cost item
|
||||
pane.bindItem('4', enchantCostConfigGui());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Gui getConnectedGui() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
|
@ -36,10 +35,6 @@ public class EnchantConflictGui extends MappedGuiListConfigGui<EnchantConflictGr
|
|||
return INSTANCE;
|
||||
}
|
||||
|
||||
// Need to init myself
|
||||
public EnchantConflictGui(Gui parent) {
|
||||
super("Conflict Config", parent);
|
||||
}
|
||||
|
||||
private EnchantConflictGui() {
|
||||
super( "Conflict Config");
|
||||
|
|
@ -102,7 +97,7 @@ public class EnchantConflictGui extends MappedGuiListConfigGui<EnchantConflictGr
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Collection<EnchantConflictGroup> getEveryInstanceOfGeneric() {
|
||||
protected Collection<EnchantConflictGroup> getEveryDisplayableInstanceOfGeneric() {
|
||||
return ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.enchant.EnchantmentProperties;
|
||||
import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.EnchantCostSettingsGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
|
|
@ -18,13 +18,13 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static io.delilaheve.util.ConfigOptions.ENCHANT_VALUES_ROOT;
|
||||
|
||||
/**
|
||||
* Global Config gui for enchantment cost settings.
|
||||
*/
|
||||
public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSettingsGui.EnchantCostSettingFactory> {
|
||||
|
||||
private static final String SECTION_NAME = "enchant_values";
|
||||
|
||||
private static EnchantCostConfigGui INSTANCE = null;
|
||||
|
||||
@Nullable
|
||||
|
|
@ -42,24 +42,13 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSe
|
|||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of this Global gui for enchantment cost settings.
|
||||
*/
|
||||
public EnchantCostConfigGui(Gui parent) {
|
||||
super("§8Enchantment Level Cost", parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnchantCostSettingsGui.EnchantCostSettingFactory createFactory(CAEnchantment enchant) {
|
||||
return createFactory(enchant, this);
|
||||
}
|
||||
|
||||
public static EnchantCostSettingsGui.EnchantCostSettingFactory createFactory(CAEnchantment enchant, ValueUpdatableGui parent) {
|
||||
String key = enchant.getKey().toString().toLowerCase(Locale.ENGLISH);
|
||||
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key.replace(":", "_"));
|
||||
|
||||
return new EnchantCostSettingsGui.EnchantCostSettingFactory(prettyKey + " Cost", parent,
|
||||
ENCHANT_VALUES_ROOT + '.' + key, ConfigHolder.DEFAULT_CONFIG,
|
||||
return new EnchantCostSettingsGui.EnchantCostSettingFactory(prettyKey + " Cost", this,
|
||||
SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG,
|
||||
Arrays.asList(
|
||||
"§7How many level should " + prettyKey,
|
||||
"§7cost when applied by book or by another item."
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import io.delilaheve.util.ConfigOptions;
|
||||
import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
|
||||
|
|
@ -38,22 +36,14 @@ public class EnchantLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsG
|
|||
init();
|
||||
}
|
||||
|
||||
public EnchantLimitConfigGui(Gui parent) {
|
||||
super("§8Enchantment Level Limit", parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntSettingsGui.IntSettingFactory createFactory(CAEnchantment enchant) {
|
||||
return createFactory(enchant, this);
|
||||
}
|
||||
|
||||
public static IntSettingsGui.IntSettingFactory createFactory(CAEnchantment enchant, ValueUpdatableGui parent) {
|
||||
String key = enchant.getKey().toString().toLowerCase(Locale.ROOT);
|
||||
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key.replace(":", "_"));
|
||||
|
||||
var defaultValue = enchant.defaultMaxLevel();
|
||||
|
||||
return new IntSettingsGui.IntSettingFactory(prettyKey + " Limit", parent,
|
||||
return new IntSettingsGui.IntSettingFactory(prettyKey + " Limit", this,
|
||||
SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG,
|
||||
Collections.singletonList(
|
||||
"§7Maximum applied level of " + prettyKey
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import io.delilaheve.util.ConfigOptions;
|
||||
import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
|
||||
|
|
@ -35,24 +33,12 @@ public class EnchantMergeLimitConfigGui extends AbstractEnchantConfigGui<IntSett
|
|||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of this Global gui for enchantment level limit settings.
|
||||
*/
|
||||
public EnchantMergeLimitConfigGui(Gui parent) {
|
||||
super("§8Enchantment Maximum Merge Level", parent);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IntSettingsGui.IntSettingFactory createFactory(CAEnchantment enchant) {
|
||||
return createFactory(enchant, this);
|
||||
}
|
||||
|
||||
public static IntSettingsGui.IntSettingFactory createFactory(CAEnchantment enchant, ValueUpdatableGui parent) {
|
||||
String key = enchant.getKey().toString().toLowerCase(Locale.ROOT);
|
||||
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key.replace(":", "_"));
|
||||
|
||||
return new IntSettingsGui.IntSettingFactory(prettyKey + " Merge Limit", parent,
|
||||
return new IntSettingsGui.IntSettingFactory(prettyKey + " Merge Limit", this,
|
||||
SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG,
|
||||
Arrays.asList(
|
||||
"§7Maximum merge level for for " + prettyKey,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
|
@ -44,10 +43,6 @@ public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedG
|
|||
init();
|
||||
}
|
||||
|
||||
public GroupConfigGui(Gui parent) {
|
||||
super("Group Config", parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack createItemForGeneric(IncludeGroup group) {
|
||||
ItemStack item = new ItemStack(group.getRepresentativeMaterial());
|
||||
|
|
@ -67,7 +62,7 @@ public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedG
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Collection<IncludeGroup> getEveryInstanceOfGeneric() {
|
||||
protected Collection<IncludeGroup> getEveryDisplayableInstanceOfGeneric() {
|
||||
ArrayList<IncludeGroup> includeGroups = new ArrayList<>();
|
||||
|
||||
for (AbstractMaterialGroup group : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) {
|
||||
|
|
|
|||
|
|
@ -1,132 +0,0 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
|
||||
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
|
||||
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
import xyz.alexcrea.cuanvil.util.MaterialUtil;
|
||||
import xyz.alexcrea.cuanvil.util.UnitRepairUtil;
|
||||
|
||||
public class ItemConfigGui extends ChestGui {
|
||||
|
||||
private EnchantConflictGui enchantConflictGui;
|
||||
private GroupConfigGui groupConfigGui;
|
||||
private UnitRepairConfigGui unitRepairConfigGui;
|
||||
private CustomRecipeConfigGui customRecipeConfigGui;
|
||||
|
||||
public ItemConfigGui(@NotNull Material display, @NotNull NamespacedKey material) {
|
||||
super(3,
|
||||
CasedStringUtil.snakeToUpperSpacedCase(
|
||||
material.getKey().toLowerCase()
|
||||
) + " Config",
|
||||
CustomAnvil.instance);
|
||||
|
||||
Pattern pattern = new Pattern(
|
||||
"0000D0000",
|
||||
"056000780",
|
||||
"Q00000000"
|
||||
);
|
||||
PatternPane pane = new PatternPane(0, 0, 9, 3, pattern);
|
||||
addPane(pane);
|
||||
|
||||
GuiGlobalItems.addBackgroundItem(pane);
|
||||
|
||||
ItemStack displayItemstack = new ItemStack(display);
|
||||
ItemMeta displayMeta = displayItemstack.getItemMeta();
|
||||
assert displayMeta != null;
|
||||
|
||||
displayMeta.setDisplayName("§aConfiguring " + material);
|
||||
displayItemstack.setItemMeta(displayMeta);
|
||||
pane.bindItem('D', new GuiItem(displayItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance));
|
||||
|
||||
// Enchantment Conflicts item
|
||||
GuiItem enchantConflictItem = MainConfigGui.enchantConflictItem(getEnchantConflictGui(material));
|
||||
pane.bindItem('5', enchantConflictItem);
|
||||
|
||||
// Group config items
|
||||
GuiItem groupConfigItem = MainConfigGui.groupConfigItem(getGroupConfigGui(material));
|
||||
pane.bindItem('6', groupConfigItem);
|
||||
|
||||
// Unit repair item
|
||||
GuiItem unitRepairItem = MainConfigGui.unitRepairItem(getUnitRepairConfigGui(material));
|
||||
pane.bindItem('7', unitRepairItem);
|
||||
|
||||
// Custom recipe item
|
||||
GuiItem customRecipeItem = MainConfigGui.customRecipeItem(getCustomRecipeConfigGui(material));
|
||||
pane.bindItem('8', customRecipeItem);
|
||||
|
||||
// quit item
|
||||
pane.bindItem('Q', MainConfigGui.quitItem());
|
||||
}
|
||||
|
||||
private EnchantConflictGui getEnchantConflictGui(@NotNull NamespacedKey material) {
|
||||
if (enchantConflictGui == null) {
|
||||
enchantConflictGui = new EnchantConflictGui(this);
|
||||
enchantConflictGui.setFilter(group ->
|
||||
group.getCantConflictGroup().contain(material)
|
||||
);
|
||||
enchantConflictGui.init();
|
||||
}
|
||||
|
||||
return enchantConflictGui;
|
||||
}
|
||||
|
||||
private GroupConfigGui getGroupConfigGui(@NotNull NamespacedKey material) {
|
||||
if (groupConfigGui == null) {
|
||||
groupConfigGui = new GroupConfigGui(this);
|
||||
groupConfigGui.setFilter(group ->
|
||||
group.contain(material)
|
||||
);
|
||||
groupConfigGui.init();
|
||||
}
|
||||
|
||||
return groupConfigGui;
|
||||
}
|
||||
|
||||
private UnitRepairConfigGui getUnitRepairConfigGui(@NotNull NamespacedKey material) {
|
||||
if (unitRepairConfigGui == null) {
|
||||
unitRepairConfigGui = new UnitRepairConfigGui(this);
|
||||
unitRepairConfigGui.setFilter(otherMat ->
|
||||
otherMat.equals(material) || UnitRepairUtil.INSTANCE.findRawRepairValue(
|
||||
material, otherMat, ConfigHolder.UNIT_REPAIR_HOLDER.getConfig()) != null
|
||||
);
|
||||
unitRepairConfigGui.init();
|
||||
}
|
||||
|
||||
return unitRepairConfigGui;
|
||||
}
|
||||
|
||||
private CustomRecipeConfigGui getCustomRecipeConfigGui(@NotNull NamespacedKey material) {
|
||||
if (customRecipeConfigGui == null) {
|
||||
customRecipeConfigGui = new CustomRecipeConfigGui(this);
|
||||
customRecipeConfigGui.setFilter(recipe -> {
|
||||
if (isMaterial(recipe.getLeftItem(), material)) return true;
|
||||
if (isMaterial(recipe.getRightItem(), material)) return true;
|
||||
return isMaterial(recipe.getResultItem(), material);
|
||||
}
|
||||
);
|
||||
customRecipeConfigGui.init();
|
||||
}
|
||||
|
||||
return customRecipeConfigGui;
|
||||
}
|
||||
|
||||
private boolean isMaterial(@Nullable ItemStack item, @NotNull NamespacedKey material) {
|
||||
if (item == null) return false;
|
||||
|
||||
return material.equals(MaterialUtil.INSTANCE.getCustomType(item));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
@ -14,14 +13,13 @@ import xyz.alexcrea.cuanvil.gui.config.ask.SelectItemTypeGui;
|
|||
import xyz.alexcrea.cuanvil.gui.config.list.MappedGuiListConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.list.UnitRepairElementListGui;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
import xyz.alexcrea.cuanvil.util.MaterialUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class UnitRepairConfigGui extends
|
||||
MappedGuiListConfigGui<NamespacedKey, MappedGuiListConfigGui.LazyElement<UnitRepairElementListGui>> {
|
||||
MappedGuiListConfigGui<Material, MappedGuiListConfigGui.LazyElement<UnitRepairElementListGui>> {
|
||||
|
||||
private static UnitRepairConfigGui INSTANCE;
|
||||
|
||||
|
|
@ -43,12 +41,8 @@ public class UnitRepairConfigGui extends
|
|||
init();
|
||||
}
|
||||
|
||||
public UnitRepairConfigGui(Gui parent) {
|
||||
super("Unit Repair Config", parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LazyElement<UnitRepairElementListGui> newInstanceOfGui(NamespacedKey material, GuiItem item) {
|
||||
protected LazyElement<UnitRepairElementListGui> newInstanceOfGui(Material material, GuiItem item) {
|
||||
return new LazyElement<>(item, () -> {
|
||||
UnitRepairElementListGui element = new UnitRepairElementListGui(material, this);
|
||||
element.init();
|
||||
|
|
@ -57,28 +51,17 @@ public class UnitRepairConfigGui extends
|
|||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack createItemForGeneric(@NotNull NamespacedKey material) {
|
||||
var unitConfig = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig();
|
||||
var section = unitConfig.getConfigurationSection(material.toString().toLowerCase());
|
||||
var legacySection = unitConfig.getConfigurationSection(material.getKey().toLowerCase());
|
||||
protected ItemStack createItemForGeneric(Material material) {
|
||||
ConfigurationSection materialSection = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().getConfigurationSection(material.name().toLowerCase());
|
||||
String materialName = CasedStringUtil.snakeToUpperSpacedCase(material.name().toLowerCase());
|
||||
|
||||
String materialName = CasedStringUtil.snakeToUpperSpacedCase(material.getKey().toLowerCase());
|
||||
|
||||
var display = MaterialUtil.INSTANCE.getMatFromKey(material);
|
||||
|
||||
if (display == null || display.isAir()) {
|
||||
display = Material.BARRIER;
|
||||
if(material.isAir()){
|
||||
material = Material.BARRIER;
|
||||
}
|
||||
|
||||
var reparable = new HashSet<String>();
|
||||
if (section != null)
|
||||
reparable.addAll(section.getKeys(false));
|
||||
if (legacySection != null)
|
||||
reparable.addAll(legacySection.getKeys(false));
|
||||
int reparableItemCount = materialSection == null ? 0 : materialSection.getKeys(false).size(); // Probably an expensive call but... why not
|
||||
|
||||
var reparableItemCount = reparable.size();
|
||||
|
||||
ItemStack item = new ItemStack(display);
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
|
||||
|
|
@ -94,16 +77,13 @@ public class UnitRepairConfigGui extends
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Collection<NamespacedKey> getEveryInstanceOfGeneric() {
|
||||
var materials = new HashSet<NamespacedKey>();
|
||||
var config = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig();
|
||||
protected Collection<Material> getEveryDisplayableInstanceOfGeneric() {
|
||||
ArrayList<Material> materials = new ArrayList<>();
|
||||
|
||||
for (String matName : config.getKeys(false)) {
|
||||
if(!config.isConfigurationSection(matName)) continue;
|
||||
|
||||
NamespacedKey material = NamespacedKey.fromString(matName.toLowerCase());
|
||||
if (material != null) {
|
||||
materials.add(material);
|
||||
for (String matName : ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().getKeys(false)) {
|
||||
Material mat = Material.getMaterial(matName.toUpperCase());
|
||||
if(mat != null){
|
||||
materials.add(mat);
|
||||
}
|
||||
}
|
||||
return materials;
|
||||
|
|
@ -133,7 +113,7 @@ public class UnitRepairConfigGui extends
|
|||
"§7You like to be an unit repair item",
|
||||
this,
|
||||
(itemStack, player) -> {
|
||||
NamespacedKey type = MaterialUtil.INSTANCE.getCustomType(itemStack);
|
||||
Material type = itemStack.getType();
|
||||
// Add new material
|
||||
updateValueForGeneric(type, true);
|
||||
|
||||
|
|
@ -146,7 +126,7 @@ public class UnitRepairConfigGui extends
|
|||
}
|
||||
|
||||
@NotNull
|
||||
public LazyElement<UnitRepairElementListGui> getInstanceOrCreate(NamespacedKey mat) {
|
||||
public LazyElement<UnitRepairElementListGui> getInstanceOrCreate(Material mat){
|
||||
LazyElement<UnitRepairElementListGui> element = this.elementGuiMap.get(mat);
|
||||
if(element == null){
|
||||
updateValueForGeneric(mat, false);
|
||||
|
|
@ -161,10 +141,8 @@ public class UnitRepairConfigGui extends
|
|||
protected String genericDisplayedName() {
|
||||
return "this function Should not be used.";
|
||||
}
|
||||
|
||||
@Override // Not used in this implementation.
|
||||
protected NamespacedKey createAndSaveNewEmptyGeneric(String name) {
|
||||
protected Material createAndSaveNewEmptyGeneric(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,21 +23,17 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public abstract class ElementListConfigGui< T > extends ChestGui implements ValueUpdatableGui {
|
||||
|
||||
public static final int LIST_FILLER_START_X = 1;
|
||||
public static final int LIST_FILLER_START_Y = 1;
|
||||
public static final int LIST_FILLER_LENGTH = 7;
|
||||
public static final int LIST_FILLER_HEIGHT = 4;
|
||||
|
||||
private final String namePrefix;
|
||||
|
||||
protected PatternPane backgroundPane;
|
||||
|
||||
private Predicate<T> filter = (t) -> true;
|
||||
private boolean hasDefaultFilter = true;
|
||||
public static final int LIST_FILLER_START_X = 1;
|
||||
public static final int LIST_FILLER_START_Y = 1;
|
||||
public static final int LIST_FILLER_LENGTH = 7;
|
||||
public static final int LIST_FILLER_HEIGHT = 4;
|
||||
|
||||
protected ElementListConfigGui(@NotNull String title, Gui parent) {
|
||||
super(6, title, CustomAnvil.instance);
|
||||
|
|
@ -50,11 +46,6 @@ public abstract class ElementListConfigGui<T> extends ChestGui implements ValueU
|
|||
|
||||
}
|
||||
|
||||
public void setFilter(Predicate<T> filter) {
|
||||
this.filter = filter;
|
||||
this.hasDefaultFilter = false;
|
||||
}
|
||||
|
||||
protected Pattern getBackgroundPattern(){
|
||||
return new Pattern(
|
||||
GuiSharedConstant.UPPER_FILLER_FULL_PLANE,
|
||||
|
|
@ -70,7 +61,7 @@ public abstract class ElementListConfigGui<T> extends ChestGui implements ValueU
|
|||
protected ArrayList<OutlinePane> pages;
|
||||
protected HashMap<UUID, Integer> pageMap;
|
||||
|
||||
public void init() {
|
||||
public void init() { // Why I'm using an init function ? //TODO determine why is it using a init function and not used on constructor.
|
||||
GuiGlobalItems.addBackgroundItem(this.backgroundPane);
|
||||
this.backgroundPane.bindItem('1', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
|
||||
addPane(this.backgroundPane);
|
||||
|
|
@ -121,23 +112,17 @@ public abstract class ElementListConfigGui<T> extends ChestGui implements ValueU
|
|||
viewer.setItemOnCursor(cursor);
|
||||
}, CustomAnvil.instance);
|
||||
|
||||
GuiItem createNew;
|
||||
if(hasDefaultFilter)
|
||||
createNew = prepareCreateNewItem();
|
||||
else
|
||||
createNew = GuiSharedConstant.SECONDARY_BACKGROUND_ITEM;
|
||||
|
||||
GuiItem createNew = prepareCreateNewItem();
|
||||
if(createNew != null){
|
||||
this.backgroundPane.bindItem('C', createNew);
|
||||
}
|
||||
}
|
||||
|
||||
protected void reloadValues(){
|
||||
this.firstPage.clear();
|
||||
this.pages.clear();
|
||||
this.pages.add(this.firstPage);
|
||||
|
||||
for (T generic : getDisplayableInstanceOfGeneric()) {
|
||||
for (T generic : getEveryDisplayableInstanceOfGeneric()) {
|
||||
updateValueForGeneric(generic, false);
|
||||
}
|
||||
|
||||
|
|
@ -315,11 +300,7 @@ public abstract class ElementListConfigGui<T> extends ChestGui implements ValueU
|
|||
|
||||
protected abstract void updateGeneric(T generic, ItemStack usedItem);
|
||||
|
||||
protected abstract Collection<T> getEveryInstanceOfGeneric();
|
||||
|
||||
protected Collection<T> getDisplayableInstanceOfGeneric() {
|
||||
return getEveryInstanceOfGeneric().stream().filter(filter).toList();
|
||||
}
|
||||
protected abstract Collection<T> getEveryDisplayableInstanceOfGeneric();
|
||||
|
||||
@Override
|
||||
public void updateGuiValues() {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.list;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
|
|
@ -18,17 +17,12 @@ import java.util.function.Consumer;
|
|||
public abstract class MappedElementListConfigGui< T, S > extends ElementListConfigGui< T > {
|
||||
|
||||
protected final HashMap<T, S> elementGuiMap;
|
||||
|
||||
protected MappedElementListConfigGui(@NotNull String title, @NotNull Gui parent) {
|
||||
super(title, parent);
|
||||
protected MappedElementListConfigGui(@NotNull String title) {
|
||||
super(title, MainConfigGui.getInstance());
|
||||
this.elementGuiMap = new HashMap<>();
|
||||
|
||||
}
|
||||
|
||||
protected MappedElementListConfigGui(@NotNull String title) {
|
||||
this(title, MainConfigGui.getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiItem prepareCreateNewItem(){
|
||||
// Create new conflict item
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.list;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
|
@ -20,10 +19,7 @@ public abstract class MappedGuiListConfigGui<T, S extends MappedGuiListConfigGui
|
|||
|
||||
protected MappedGuiListConfigGui(@NotNull String title) {
|
||||
super(title);
|
||||
}
|
||||
|
||||
protected MappedGuiListConfigGui(@NotNull String title, @NotNull Gui parent) {
|
||||
super(title, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -84,7 +80,7 @@ public abstract class MappedGuiListConfigGui<T, S extends MappedGuiListConfigGui
|
|||
|
||||
// Try to find if it already exists in a for loop
|
||||
// Not the most efficient on large number of conflict, but it should not run often.
|
||||
for (T generic : getDisplayableInstanceOfGeneric()) {
|
||||
for (T generic : getEveryDisplayableInstanceOfGeneric()) {
|
||||
if (generic.toString().equalsIgnoreCase(message)) {
|
||||
player.sendMessage("§cPlease enter a "+genericDisplayedName()+" name that do not already exist...");
|
||||
// wait next message.
|
||||
|
|
@ -121,7 +117,6 @@ public abstract class MappedGuiListConfigGui<T, S extends MappedGuiListConfigGui
|
|||
|
||||
private final GuiItem parentItem;
|
||||
private final LazyValue<Consumer<InventoryClickEvent>> lazyOpenConsumer;
|
||||
|
||||
public LazyElement(GuiItem parentItem, Supplier<T> valueSupplier) {
|
||||
super(valueSupplier);
|
||||
this.parentItem = parentItem;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ public abstract class SettingGuiListConfigGui<T, S extends SettingGui.SettingGui
|
|||
|
||||
protected HashMap<T, GuiItem> guiItemMap;
|
||||
protected HashMap<T, S> factoryMap;
|
||||
|
||||
protected SettingGuiListConfigGui(@NotNull String title, Gui parent) {
|
||||
super(title, parent);
|
||||
this.guiItemMap = new HashMap<>();
|
||||
|
|
@ -87,22 +86,17 @@ public abstract class SettingGuiListConfigGui<T, S extends SettingGui.SettingGui
|
|||
}
|
||||
|
||||
@Override // Not used
|
||||
protected void updateGeneric(T generic, ItemStack usedItem) {
|
||||
}
|
||||
|
||||
protected void updateGeneric(T generic, ItemStack usedItem) {}
|
||||
@Override // Not used
|
||||
protected ItemStack createItemForGeneric(T generic) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected abstract List<String> getCreateItemLore();
|
||||
|
||||
protected abstract Consumer<InventoryClickEvent> getCreateClickConsumer();
|
||||
|
||||
protected abstract String createItemName();
|
||||
|
||||
protected abstract S createFactory(T generic);
|
||||
|
||||
protected abstract GuiItem itemFromFactory(T generic, S factory);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,14 +3,12 @@ package xyz.alexcrea.cuanvil.gui.config.list;
|
|||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.gui.config.ask.SelectItemTypeGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.UnitRepairConfigGui;
|
||||
|
|
@ -19,25 +17,26 @@ import xyz.alexcrea.cuanvil.gui.config.settings.DoubleSettingGui;
|
|||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
import xyz.alexcrea.cuanvil.util.MaterialUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class UnitRepairElementListGui extends SettingGuiListConfigGui<NamespacedKey, DoubleSettingGui.DoubleSettingFactory> implements ElementMappedToListGui {
|
||||
public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, DoubleSettingGui.DoubleSettingFactory> implements ElementMappedToListGui {
|
||||
|
||||
private final NamespacedKey parentMaterial;
|
||||
private final Material parentMaterial;
|
||||
private final UnitRepairConfigGui parentGui;
|
||||
private final String materialName;
|
||||
|
||||
private boolean shouldWork = true;
|
||||
|
||||
public UnitRepairElementListGui(@NotNull NamespacedKey parentMaterial,
|
||||
public UnitRepairElementListGui(@NotNull Material parentMaterial,
|
||||
@NotNull UnitRepairConfigGui parentGui) {
|
||||
super("§e" + CasedStringUtil.snakeToUpperSpacedCase(parentMaterial.getKey().toLowerCase()) + " §rUnit repair");
|
||||
super("§e" + CasedStringUtil.snakeToUpperSpacedCase(parentMaterial.name().toLowerCase()) + " §rUnit repair");
|
||||
this.parentMaterial = parentMaterial;
|
||||
this.parentGui = parentGui;
|
||||
this.materialName = CasedStringUtil.snakeToUpperSpacedCase(parentMaterial.getKey().toLowerCase());
|
||||
this.materialName = CasedStringUtil.snakeToUpperSpacedCase(parentMaterial.name().toLowerCase());
|
||||
|
||||
GuiGlobalItems.addBackItem(this.backgroundPane, parentGui);
|
||||
}
|
||||
|
|
@ -67,28 +66,28 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<Namespaced
|
|||
this,
|
||||
(itemStack, player) -> {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
NamespacedKey type = MaterialUtil.INSTANCE.getCustomType(itemStack);
|
||||
Material type = itemStack.getType();
|
||||
|
||||
if (!(meta instanceof Damageable)) {
|
||||
if(!(meta instanceof Damageable) || (type.getMaxDurability() <= 0)) {
|
||||
player.sendMessage("§cThis item can't be damaged, so it can't be repaired.");
|
||||
return;
|
||||
}
|
||||
if (type.equals(this.parentMaterial)) {
|
||||
if(type == this.parentMaterial){
|
||||
player.sendMessage("§cItem can't repair something of the same type.");
|
||||
return;
|
||||
}
|
||||
|
||||
String materialName = type.toString();
|
||||
String materialName = type.name().toLowerCase();
|
||||
|
||||
// Add new material
|
||||
ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().set(parentMaterial.toString().toLowerCase() + "." + materialName, 0.25);
|
||||
ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().set(parentMaterial.name().toLowerCase() + "." + materialName,0.25);
|
||||
|
||||
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
||||
ConfigHolder.UNIT_REPAIR_HOLDER.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||
}
|
||||
|
||||
// Update gui
|
||||
updateValueForGeneric(type, true);
|
||||
updateValueForGeneric(materialName, true);
|
||||
this.parentGui.updateValueForGeneric(this.parentMaterial, true);
|
||||
|
||||
|
||||
|
|
@ -107,14 +106,14 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<Namespaced
|
|||
}
|
||||
|
||||
@Override
|
||||
protected DoubleSettingGui.DoubleSettingFactory createFactory(NamespacedKey materialName) {
|
||||
String materialDisplayName = CasedStringUtil.snakeToUpperSpacedCase(materialName.getKey());
|
||||
protected DoubleSettingGui.DoubleSettingFactory createFactory(String materialName) {
|
||||
String materialDisplayName = CasedStringUtil.snakeToUpperSpacedCase(materialName);
|
||||
|
||||
return new DoubleSettingGui.DoubleSettingFactory(
|
||||
"§0%§8" + materialDisplayName +" Repair",
|
||||
this,
|
||||
ConfigHolder.UNIT_REPAIR_HOLDER,
|
||||
this.parentMaterial.toString().toLowerCase() + "." + materialName,
|
||||
this.parentMaterial.name().toLowerCase()+"."+materialName,
|
||||
Arrays.asList(
|
||||
"§7Click here to change how many §e% §7of §a" + materialDisplayName,
|
||||
"§7Should get repaired by §e"+this.materialName
|
||||
|
|
@ -129,39 +128,28 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<Namespaced
|
|||
}
|
||||
|
||||
@Override
|
||||
protected GuiItem itemFromFactory(NamespacedKey materialName, DoubleSettingGui.DoubleSettingFactory factory) {
|
||||
protected GuiItem itemFromFactory(String materialName, DoubleSettingGui.DoubleSettingFactory factory) {
|
||||
return factory.getItem(materialFromName(materialName),
|
||||
"§7%§a" + CasedStringUtil.snakeToUpperSpacedCase(materialName.getKey()) + " §erepaired by §a" + this.materialName);
|
||||
"§7%§a" + CasedStringUtil.snakeToUpperSpacedCase(materialName)+ " §erepaired by §a" + this.materialName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<NamespacedKey> getEveryInstanceOfGeneric() {
|
||||
Set<NamespacedKey> keys = new HashSet<>();
|
||||
protected Collection<String> getEveryDisplayableInstanceOfGeneric() {
|
||||
ArrayList<String> keys = new ArrayList<>();
|
||||
if(!this.shouldWork){
|
||||
return keys;
|
||||
}
|
||||
|
||||
ConfigurationSection legacySection = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().getConfigurationSection(parentMaterial.getKey().toLowerCase());
|
||||
ConfigurationSection materialSection = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().getConfigurationSection(parentMaterial.toString().toLowerCase());
|
||||
|
||||
addAllKeys(legacySection, keys);
|
||||
addAllKeys(materialSection, keys);
|
||||
|
||||
ConfigurationSection materialSection = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().getConfigurationSection(parentMaterial.name().toLowerCase());
|
||||
if(materialSection == null){
|
||||
return keys;
|
||||
}
|
||||
keys.addAll(materialSection.getKeys(false));
|
||||
return keys;
|
||||
}
|
||||
|
||||
private void addAllKeys(@Nullable ConfigurationSection section, @NotNull Set<NamespacedKey> keys) {
|
||||
if (section == null) return;
|
||||
for (var key : section.getKeys(false)) {
|
||||
var material = NamespacedKey.fromString(key);
|
||||
if (material == null) continue;
|
||||
|
||||
keys.add(material);
|
||||
}
|
||||
}
|
||||
|
||||
private Material materialFromName(NamespacedKey material) {
|
||||
Material mat = MaterialUtil.INSTANCE.getMatFromKey(material);
|
||||
private Material materialFromName(String materialName){
|
||||
Material mat = Material.getMaterial(materialName.toUpperCase());
|
||||
if(mat == null || mat.isAir()) return Material.BARRIER;
|
||||
return mat;
|
||||
}
|
||||
|
|
@ -175,8 +163,7 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<Namespaced
|
|||
// ElementMappedToListGui methods
|
||||
|
||||
@Override // Not used in this implementation
|
||||
public void updateLocal() {
|
||||
}
|
||||
public void updateLocal() {}
|
||||
|
||||
@Override
|
||||
public void cleanAndBeUnusable() {
|
||||
|
|
|
|||
|
|
@ -202,6 +202,7 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
|||
}
|
||||
pane.bindItem('D', returnToDefault);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class EnchantSelectSettingGui extends SettingGuiListConfigGui<CAEnchantme
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Collection<CAEnchantment> getEveryInstanceOfGeneric() {
|
||||
protected Collection<CAEnchantment> getEveryDisplayableInstanceOfGeneric() {
|
||||
Stream<CAEnchantment> toDisplayStream;
|
||||
if(this.displayUnselected){
|
||||
toDisplayStream = CAEnchantmentRegistry.getInstance().getNameSortedEnchantments().stream();
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Namespa
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Collection<NamespacedKey> getEveryInstanceOfGeneric() {
|
||||
protected Collection<NamespacedKey> getEveryDisplayableInstanceOfGeneric() {
|
||||
return this.defaultMaterials;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package xyz.alexcrea.cuanvil.update.minecraft;
|
||||
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.update.UpdateUtils;
|
||||
import xyz.alexcrea.cuanvil.update.Version;
|
||||
|
|
|
|||
|
|
@ -38,26 +38,26 @@ public class Update_1_21_11 extends MCUpdate{
|
|||
addAbsentToList(conflictConfig, "restriction_fire_aspect.notAffectedGroups", "spears");
|
||||
|
||||
// Unit repair for spears
|
||||
unitConfig.set("minecraft:gold_ingot.minecraft:golden_spear", 0.25);
|
||||
unitConfig.set("minecraft:copper_ingot.minecraft:copper_spear", 0.25);
|
||||
unitConfig.set("minecraft:iron_ingot.minecraft:iron_spear", 0.25);
|
||||
unitConfig.set("minecraft:diamond.minecraft:diamond_spear", 0.25);
|
||||
unitConfig.set("minecraft:netherite_ingot.minecraft:netherite_spear", 0.25);
|
||||
unitConfig.set("gold_ingot.golden_spear", 0.25);
|
||||
unitConfig.set("copper_ingot.copper_spear", 0.25);
|
||||
unitConfig.set("iron_ingot.iron_spear", 0.25);
|
||||
unitConfig.set("diamond.diamond_spear", 0.25);
|
||||
unitConfig.set("netherite_ingot.netherite_spear", 0.25);
|
||||
|
||||
unitConfig.set("minecraft:cobblestone.stone_spear", 0.25);
|
||||
unitConfig.set("minecraft:cobbled_deepslate.stone_spear", 0.25);
|
||||
unitConfig.set("cobblestone.stone_spear", 0.25);
|
||||
unitConfig.set("cobbled_deepslate.stone_spear", 0.25);
|
||||
|
||||
unitConfig.set("minecraft:oak_planks.minecraft:wooden_spear", 0.25);
|
||||
unitConfig.set("minecraft:spruce_planks.minecraft:wooden_spear", 0.25);
|
||||
unitConfig.set("minecraft:birch_planks.minecraft:wooden_spear", 0.25);
|
||||
unitConfig.set("minecraft:jungle_planks.minecraft:wooden_spear", 0.25);
|
||||
unitConfig.set("minecraft:acacia_planks.minecraft:wooden_spear", 0.25);
|
||||
unitConfig.set("minecraft:dark_oak_planks.minecraft:wooden_spear", 0.25);
|
||||
unitConfig.set("minecraft:mangrove_planks.minecraft:wooden_spear", 0.25);
|
||||
unitConfig.set("minecraft:cherry_planks.minecraft:wooden_spear", 0.25);
|
||||
unitConfig.set("minecraft:bamboo_planks.minecraft:wooden_spear", 0.25);
|
||||
unitConfig.set("minecraft:crimson_planks.minecraft:wooden_spear", 0.25);
|
||||
unitConfig.set("minecraft:warped_planks.minecraft:wooden_spear", 0.25);
|
||||
unitConfig.set("oak_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("spruce_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("birch_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("jungle_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("acacia_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("dark_oak_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("mangrove_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("cherry_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("bamboo_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("crimson_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("warped_planks.wooden_spear", 0.25);
|
||||
|
||||
// Create lunge enchant value and group
|
||||
baseConfig.set("enchant_limits.minecraft:lunge", 3);
|
||||
|
|
|
|||
|
|
@ -49,16 +49,16 @@ public class Update_1_21_9 extends MCUpdate{
|
|||
|
||||
public static void addCopperUnitRepair(FileConfiguration unitConfig) {
|
||||
// Add unit repair
|
||||
unitConfig.set("minecraft:copper_ingot.minecraft:copper_helmet", 0.25);
|
||||
unitConfig.set("minecraft:copper_ingot.minecraft:copper_chestplate", 0.25);
|
||||
unitConfig.set("minecraft:copper_ingot.minecraft:copper_leggings", 0.25);
|
||||
unitConfig.set("minecraft:copper_ingot.minecraft:copper_boots", 0.25);
|
||||
unitConfig.set("copper_ingot.copper_helmet", 0.25);
|
||||
unitConfig.set("copper_ingot.copper_chestplate", 0.25);
|
||||
unitConfig.set("copper_ingot.copper_leggings", 0.25);
|
||||
unitConfig.set("copper_ingot.copper_boots", 0.25);
|
||||
|
||||
unitConfig.set("minecraft:copper_ingot.minecraft:copper_pickaxe", 0.25);
|
||||
unitConfig.set("minecraft:copper_ingot.minecraft:copper_shovel", 0.25);
|
||||
unitConfig.set("minecraft:copper_ingot.minecraft:copper_hoe", 0.25);
|
||||
unitConfig.set("minecraft:copper_ingot.minecraft:copper_axe", 0.25);
|
||||
unitConfig.set("minecraft:copper_ingot.minecraft:copper_sword", 0.25);
|
||||
unitConfig.set("copper_ingot.copper_pickaxe", 0.25);
|
||||
unitConfig.set("copper_ingot.copper_shovel", 0.25);
|
||||
unitConfig.set("copper_ingot.copper_hoe", 0.25);
|
||||
unitConfig.set("copper_ingot.copper_axe", 0.25);
|
||||
unitConfig.set("copper_ingot.copper_sword", 0.25);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
|||
private val helpCommand = HelpExecutor()
|
||||
private val commands = ImmutableMap.of(
|
||||
"gui", editConfigCommand,
|
||||
"config", editConfigCommand,
|
||||
"reload", ReloadExecutor(),
|
||||
"diagnostic", DiagnosticExecutor(),
|
||||
"debug", DebugToggleExecutor(),
|
||||
|
|
@ -43,16 +42,12 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
|||
): Boolean {
|
||||
// Find sub command to execute based on the provided command name
|
||||
val subcmd: CASubCommand?
|
||||
val subcmdStr: String
|
||||
|
||||
val newargs: Array<out String>
|
||||
if(args.isEmpty()) {
|
||||
subcmdStr = "config"
|
||||
subcmd = editConfigCommand
|
||||
newargs = args
|
||||
}else {
|
||||
subcmdStr = args[0].lowercase()
|
||||
subcmd = commands[subcmdStr]
|
||||
subcmd = commands[args[0].lowercase()]
|
||||
newargs = args.copyOfRange(1, args.size)
|
||||
}
|
||||
|
||||
|
|
@ -62,7 +57,7 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
|||
}
|
||||
|
||||
try {
|
||||
return subcmd.executeCommand(sender, cmd, subcmdStr, newargs)
|
||||
return subcmd.executeCommand(sender, cmd, cmdstr, newargs)
|
||||
} catch (e: Throwable) {
|
||||
MetricsUtil.trackError(e)
|
||||
sender.sendMessage("§cError running this command")
|
||||
|
|
@ -80,7 +75,6 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
|||
if(args.size < 2) {
|
||||
for ((key, cmd) in commands) {
|
||||
if(!cmd.allowed(sender)) continue
|
||||
if("gui".contentEquals(key)) continue
|
||||
result.add(key)
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -4,33 +4,16 @@ import io.delilaheve.CustomAnvil
|
|||
import org.bukkit.command.Command
|
||||
import org.bukkit.command.CommandSender
|
||||
import org.bukkit.entity.HumanEntity
|
||||
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
||||
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
||||
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.EnchantConfigGui
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.ItemConfigGui
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions
|
||||
import xyz.alexcrea.cuanvil.util.MaterialUtil.customType
|
||||
import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir
|
||||
|
||||
class EditConfigExecutor: CASubCommand() {
|
||||
|
||||
override fun allowed(sender: CommandSender): Boolean {
|
||||
return sender.hasPermission(CustomAnvil.editConfigPermission)
|
||||
}
|
||||
|
||||
override fun description(): String {
|
||||
return "Gui to edit the plugin's config"
|
||||
}
|
||||
|
||||
override fun executeCommand(
|
||||
sender: CommandSender,
|
||||
override fun executeCommand(sender: CommandSender,
|
||||
cmd: Command,
|
||||
cmdstr: String,
|
||||
args: Array<out String>
|
||||
): Boolean {
|
||||
args: Array<out String>): Boolean {
|
||||
if (sender !is HumanEntity) return false
|
||||
|
||||
if (!allowed(sender)) {
|
||||
|
|
@ -46,88 +29,17 @@ class EditConfigExecutor : CASubCommand() {
|
|||
return false
|
||||
}
|
||||
|
||||
if ("gui".equals(cmdstr, ignoreCase = true)) {
|
||||
sender.sendMessage("§c/ca gui has been moved to /ca config")
|
||||
}
|
||||
|
||||
if (args.isEmpty())
|
||||
processOpen(sender)
|
||||
else when (args[0].lowercase()) {
|
||||
"open" -> processOpen(sender)
|
||||
"enchant" -> processEnchant(sender, args)
|
||||
"item" -> processItem(sender)
|
||||
else -> sender.sendMessage("Unknown subcommand \"${args[0]}\"")
|
||||
}
|
||||
MainConfigGui.getInstance().show(sender)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private fun processEnchant(sender: HumanEntity, args: Array<out String>) {
|
||||
val enchantToFilter: Set<CAEnchantment>
|
||||
if (args.size <= 1) {
|
||||
val item = sender.inventory.itemInMainHand
|
||||
|
||||
enchantToFilter = EnchantmentApi.getEnchantments(item).keys
|
||||
if (enchantToFilter.isEmpty()) {
|
||||
sender.sendMessage("No enchantment found in the item you are holding")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
enchantToFilter = HashSet(EnchantmentApi.getListByName(args[1].lowercase()))
|
||||
|
||||
if (enchantToFilter.isEmpty()) {
|
||||
sender.sendMessage("No enchantment found with the name \"${args[1]}\"")
|
||||
return
|
||||
}
|
||||
override fun allowed(sender: CommandSender): Boolean {
|
||||
return sender.hasPermission(CustomAnvil.editConfigPermission)
|
||||
}
|
||||
|
||||
EnchantConfigGui(enchantToFilter).show(sender)
|
||||
|
||||
}
|
||||
|
||||
private fun processItem(sender: HumanEntity) {
|
||||
val item = sender.inventory.itemInMainHand
|
||||
if (item.isAir) {
|
||||
sender.sendMessage("Cannot configure the item in hand")
|
||||
return
|
||||
}
|
||||
|
||||
ItemConfigGui(item.type, item.customType).show(sender)
|
||||
}
|
||||
|
||||
private fun processOpen(sender: HumanEntity) {
|
||||
MainConfigGui.getInstance().show(sender)
|
||||
}
|
||||
|
||||
// ---------------
|
||||
// Tab completer
|
||||
// ---------------
|
||||
|
||||
private fun allEnchantmentsByName(): Collection<String> {
|
||||
val names = mutableSetOf<String>()
|
||||
for (enchantment in CAEnchantmentRegistry.getInstance().values()) {
|
||||
names.add(enchantment.name)
|
||||
names.add(enchantment.key.toString())
|
||||
}
|
||||
|
||||
return names
|
||||
}
|
||||
|
||||
override fun tabCompleter(sender: CommandSender, args: Array<out String>, list: MutableList<String>) {
|
||||
list.addAll(
|
||||
when (args.size) {
|
||||
1 -> listOf("item", "enchant", "open")
|
||||
2 -> {
|
||||
when (args[0].lowercase()) {
|
||||
"enchant" -> allEnchantmentsByName()
|
||||
else -> listOf()
|
||||
}
|
||||
}
|
||||
|
||||
else -> listOf()
|
||||
}
|
||||
)
|
||||
|
||||
override fun description(): String {
|
||||
return "Gui to edit the plugin's config"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import org.bukkit.NamespacedKey
|
|||
import org.bukkit.inventory.ItemStack
|
||||
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
||||
import xyz.alexcrea.cuanvil.dependency.plugins.EcoItemDependencyUtil
|
||||
import javax.annotation.Nullable
|
||||
|
||||
object MaterialUtil {
|
||||
|
||||
|
|
@ -36,13 +35,11 @@ object MaterialUtil {
|
|||
return this.type.key
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private fun bukkitMaterialFromKey(key: NamespacedKey): Material? {
|
||||
//TODO on paper only transition Registry.MATERIAL.get(key)
|
||||
return Material.matchMaterial(key.toString())
|
||||
}
|
||||
|
||||
@Nullable
|
||||
fun getMatFromKey(key: NamespacedKey): Material? {
|
||||
if(DependencyManager.ecoEnchantCompatibility != null) {
|
||||
val result = EcoItemDependencyUtil.ecoItemMaterialFromKey(key)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package xyz.alexcrea.cuanvil.util
|
||||
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.configuration.ConfigurationSection
|
||||
import org.bukkit.configuration.file.FileConfiguration
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
import xyz.alexcrea.cuanvil.util.MaterialUtil.customType
|
||||
|
|
@ -13,7 +11,7 @@ object UnitRepairUtil {
|
|||
private const val DEFAULT_DEFAULT_UNIT_REPAIR = 0.25
|
||||
|
||||
// Path to user default unit repair value
|
||||
public const val UNIT_REPAIR_DEFAULT_PATH = "default_repair_amount"
|
||||
private const val UNIT_REPAIR_DEFAULT_PATH = "default_repair_amount"
|
||||
|
||||
/**
|
||||
* Get the % of repair by unit [other] will do to this [ItemStack].
|
||||
|
|
@ -24,56 +22,40 @@ object UnitRepairUtil {
|
|||
): Double? {
|
||||
if (other == null) return null
|
||||
val config = ConfigHolder.UNIT_REPAIR_HOLDER.config
|
||||
// Get configuration section if exist
|
||||
val otherName = other.customType.key.lowercase()
|
||||
var section = config.getConfigurationSection(otherName)
|
||||
if (section == null) {
|
||||
section = config.getConfigurationSection(otherName.uppercase())
|
||||
if (section == null) return null
|
||||
|
||||
val result = findRawRepairValue(this, other, config) ?: return null
|
||||
|
||||
if(result > 0) return result
|
||||
|
||||
// Get default
|
||||
val userDefault = config.getDouble(UNIT_REPAIR_DEFAULT_PATH, DEFAULT_DEFAULT_UNIT_REPAIR)
|
||||
if (userDefault <= 0)
|
||||
return DEFAULT_DEFAULT_UNIT_REPAIR
|
||||
return userDefault
|
||||
}
|
||||
// Get repair amount
|
||||
var userDefault = config.getDouble(UNIT_REPAIR_DEFAULT_PATH, DEFAULT_DEFAULT_UNIT_REPAIR)
|
||||
if (userDefault <= 0) {
|
||||
userDefault = DEFAULT_DEFAULT_UNIT_REPAIR
|
||||
}
|
||||
|
||||
private fun findRawRepairValue(
|
||||
self: ItemStack,
|
||||
other: ItemStack,
|
||||
config: FileConfiguration
|
||||
): Double? {
|
||||
val material = other.customType
|
||||
val selfType = self.customType
|
||||
|
||||
val result = checkSection(config, material.toString(), selfType)
|
||||
if (result != null) return result
|
||||
|
||||
return checkSection(config, material.key, selfType)
|
||||
return getRepairAmount(this, section, userDefault)
|
||||
}
|
||||
|
||||
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(
|
||||
config: FileConfiguration,
|
||||
path: String,
|
||||
material: NamespacedKey
|
||||
): Double? {
|
||||
val section = config.getConfigurationSection(path) ?: return null
|
||||
|
||||
if (section.isDouble(material.toString()))
|
||||
return section.getDouble(material.toString())
|
||||
if (section.isDouble(material.key))
|
||||
return section.getDouble(material.key)
|
||||
|
||||
/**
|
||||
* Get the item % repaired by this configuration section of a unit repair.
|
||||
* null if not found.
|
||||
* If value is set to less than or equal to 0 then it will be set to default
|
||||
*/
|
||||
private fun getRepairAmount(item: ItemStack, section: ConfigurationSection, default: Double): Double? {
|
||||
val itemName = item.customType.key.lowercase()
|
||||
val repairValue = if (section.isDouble(itemName)) {
|
||||
section.getDouble(itemName)
|
||||
} else if (section.isDouble(itemName.uppercase())) {
|
||||
section.getDouble(itemName.uppercase())
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
if (repairValue <= 0)
|
||||
return default
|
||||
return repairValue
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue