mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
alpha version up & cleanup code.
This commit is contained in:
parent
1b83c8db81
commit
00fba2f4b0
40 changed files with 893 additions and 718 deletions
|
|
@ -19,27 +19,27 @@ public abstract class ConfigHolder {
|
|||
public static ConflictConfigHolder CONFLICT_HOLDER;
|
||||
public static UnitRepairHolder UNIT_REPAIR_HOLDER;
|
||||
|
||||
public static boolean loadConfig(){
|
||||
public static boolean loadConfig() {
|
||||
DEFAULT_CONFIG = new DefaultConfigHolder();
|
||||
ITEM_GROUP_HOLDER = new ItemGroupConfigHolder();
|
||||
CONFLICT_HOLDER = new ConflictConfigHolder();
|
||||
UNIT_REPAIR_HOLDER = new UnitRepairHolder();
|
||||
|
||||
boolean result = reloadAllFromDisk(true);
|
||||
if(result){
|
||||
if (result) {
|
||||
MetricsUtil.INSTANCE.testIfConfigIsDefault();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean reloadAllFromDisk(boolean hardfail){
|
||||
public static boolean reloadAllFromDisk(boolean hardfail) {
|
||||
|
||||
boolean sucess = DEFAULT_CONFIG.reloadFromDisk(hardfail);
|
||||
if(!sucess) return false;
|
||||
if (!sucess) return false;
|
||||
sucess = ITEM_GROUP_HOLDER.reloadFromDisk(hardfail);
|
||||
if(!sucess) return false;
|
||||
if (!sucess) return false;
|
||||
sucess = CONFLICT_HOLDER.reloadFromDisk(hardfail);
|
||||
if(!sucess) return false;
|
||||
if (!sucess) return false;
|
||||
sucess = UNIT_REPAIR_HOLDER.reloadFromDisk(hardfail);
|
||||
return sucess;
|
||||
}
|
||||
|
|
@ -49,43 +49,49 @@ public abstract class ConfigHolder {
|
|||
private static final File BACKUP_FOLDER = new File(CustomAnvil.instance.getDataFolder(), "backup");
|
||||
|
||||
protected FileConfiguration configuration;
|
||||
protected ConfigHolder(){
|
||||
|
||||
protected ConfigHolder() {
|
||||
|
||||
}
|
||||
|
||||
public abstract boolean reloadFromDisk(boolean hardFail);
|
||||
|
||||
public abstract void reload();
|
||||
public FileConfiguration getConfig(){
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
// Config name and files
|
||||
protected abstract String getConfigFileName();
|
||||
|
||||
protected String getConfigFileExtension(){
|
||||
protected String getConfigFileExtension() {
|
||||
return ".yml";
|
||||
}
|
||||
protected File getConfigFile(){
|
||||
return new File(CustomAnvil.instance.getDataFolder(), getConfigFileName()+getConfigFileExtension());
|
||||
|
||||
protected File getConfigFile() {
|
||||
return new File(CustomAnvil.instance.getDataFolder(), getConfigFileName() + getConfigFileExtension());
|
||||
}
|
||||
protected File getFirstBackup(){
|
||||
return new File(BACKUP_FOLDER, getConfigFileName()+"-first"+getConfigFileExtension());
|
||||
|
||||
protected File getFirstBackup() {
|
||||
return new File(BACKUP_FOLDER, getConfigFileName() + "-first" + getConfigFileExtension());
|
||||
}
|
||||
protected File getLastBackup(){
|
||||
return new File(BACKUP_FOLDER, getConfigFileName()+"-latest"+getConfigFileExtension());
|
||||
|
||||
protected File getLastBackup() {
|
||||
return new File(BACKUP_FOLDER, getConfigFileName() + "-latest" + getConfigFileExtension());
|
||||
}
|
||||
|
||||
// Save logic
|
||||
public boolean saveToDisk(boolean doBackup){
|
||||
if(doBackup){
|
||||
if(!saveBackup()){
|
||||
public boolean saveToDisk(boolean doBackup) {
|
||||
if (doBackup) {
|
||||
if (!saveBackup()) {
|
||||
CustomAnvil.instance.getLogger().severe("Could not save backup. see above.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
File base = getConfigFile();
|
||||
// if file exist and can't be deleted the file, then we gave up.
|
||||
if(base.exists() && !base.delete()) {
|
||||
if (base.exists() && !base.delete()) {
|
||||
CustomAnvil.instance.getLogger().severe("Could not save config: can't delete existing file.");
|
||||
return false;
|
||||
}
|
||||
|
|
@ -101,15 +107,15 @@ public abstract class ConfigHolder {
|
|||
return true;
|
||||
}
|
||||
|
||||
protected boolean saveBackup(){
|
||||
protected boolean saveBackup() {
|
||||
File base = getConfigFile();
|
||||
if(!base.exists()) return true; // We did back up everything we had to (nothing in this case)
|
||||
if (!base.exists()) return true; // We did back up everything we had to (nothing in this case)
|
||||
boolean sufficientSuccess = false;
|
||||
|
||||
BACKUP_FOLDER.mkdirs();
|
||||
// save first backup if do not exist
|
||||
File firstBackup = getFirstBackup();
|
||||
if(!firstBackup.exists()){
|
||||
if (!firstBackup.exists()) {
|
||||
try {
|
||||
Files.copy(base, firstBackup);
|
||||
sufficientSuccess = true;
|
||||
|
|
@ -120,7 +126,7 @@ public abstract class ConfigHolder {
|
|||
// save last backup
|
||||
File lastBackup = getLastBackup();
|
||||
// if file exist and can't be deleted the file, then we gave up.
|
||||
if(lastBackup.exists() && !lastBackup.delete()){
|
||||
if (lastBackup.exists() && !lastBackup.delete()) {
|
||||
return sufficientSuccess;
|
||||
}
|
||||
|
||||
|
|
@ -134,7 +140,7 @@ public abstract class ConfigHolder {
|
|||
return sufficientSuccess;
|
||||
}
|
||||
|
||||
public static class DefaultConfigHolder extends ConfigHolder{
|
||||
public static class DefaultConfigHolder extends ConfigHolder {
|
||||
|
||||
@Override
|
||||
protected String getConfigFileName() {
|
||||
|
|
@ -150,15 +156,17 @@ public abstract class ConfigHolder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reload() {}// Nothing to do
|
||||
public void reload() {
|
||||
}// Nothing to do
|
||||
|
||||
}
|
||||
|
||||
// Abstract class for non default config
|
||||
public abstract static class ResourceConfigHolder extends ConfigHolder{
|
||||
public abstract static class ResourceConfigHolder extends ConfigHolder {
|
||||
|
||||
String resourceName;
|
||||
private ResourceConfigHolder(String resourceName){
|
||||
|
||||
private ResourceConfigHolder(String resourceName) {
|
||||
this.resourceName = resourceName;
|
||||
}
|
||||
|
||||
|
|
@ -170,8 +178,8 @@ public abstract class ConfigHolder {
|
|||
@Override
|
||||
public boolean reloadFromDisk(boolean hardFail) {
|
||||
YamlConfiguration configuration = CustomAnvil.instance.reloadResource(
|
||||
getConfigFileName()+getConfigFileExtension(), hardFail);
|
||||
if(configuration == null) return false;
|
||||
getConfigFileName() + getConfigFileExtension(), hardFail);
|
||||
if (configuration == null) return false;
|
||||
this.configuration = configuration;
|
||||
reload();
|
||||
return true;
|
||||
|
|
@ -180,10 +188,11 @@ public abstract class ConfigHolder {
|
|||
}
|
||||
|
||||
// Class for itemGroupsManager config
|
||||
public static class ItemGroupConfigHolder extends ResourceConfigHolder{
|
||||
public static class ItemGroupConfigHolder extends ResourceConfigHolder {
|
||||
private final static String FILE_NAME = "item_groups";
|
||||
|
||||
ItemGroupManager itemGroupsManager;
|
||||
|
||||
private ItemGroupConfigHolder() {
|
||||
super(FILE_NAME);
|
||||
}
|
||||
|
|
@ -198,7 +207,7 @@ public abstract class ConfigHolder {
|
|||
this.itemGroupsManager = new ItemGroupManager();
|
||||
this.itemGroupsManager.prepareGroups(this.configuration);
|
||||
|
||||
if(CONFLICT_HOLDER.getConfig() != null){
|
||||
if (CONFLICT_HOLDER.getConfig() != null) {
|
||||
CONFLICT_HOLDER.reload();
|
||||
}
|
||||
}
|
||||
|
|
@ -206,10 +215,11 @@ public abstract class ConfigHolder {
|
|||
}
|
||||
|
||||
// Class for enchant conflict config
|
||||
public static class ConflictConfigHolder extends ResourceConfigHolder{
|
||||
public static class ConflictConfigHolder extends ResourceConfigHolder {
|
||||
private final static String FILE_NAME = "enchant_conflict";
|
||||
|
||||
EnchantConflictManager conflictManager;
|
||||
|
||||
private ConflictConfigHolder() {
|
||||
super(FILE_NAME);
|
||||
}
|
||||
|
|
@ -229,14 +239,16 @@ public abstract class ConfigHolder {
|
|||
}
|
||||
|
||||
// Class for unit repair config
|
||||
public static class UnitRepairHolder extends ResourceConfigHolder{
|
||||
public static class UnitRepairHolder extends ResourceConfigHolder {
|
||||
private final static String ITEM_GROUP_FILE_NAME = "unit_repair_item";
|
||||
|
||||
private UnitRepairHolder() {
|
||||
super(ITEM_GROUP_FILE_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {} // Do nothing
|
||||
public void reload() {
|
||||
} // Do nothing
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,12 +41,11 @@ public enum EnchantmentProperties {
|
|||
SWEEPING(EnchantmentRarity.RARE),
|
||||
THORNS(EnchantmentRarity.VERY_RARE),
|
||||
UNBREAKING(EnchantmentRarity.UNCOMMON),
|
||||
VANISHING_CURSE(EnchantmentRarity.VERY_RARE)
|
||||
|
||||
;
|
||||
VANISHING_CURSE(EnchantmentRarity.VERY_RARE);
|
||||
|
||||
private final EnchantmentRarity rarity;
|
||||
EnchantmentProperties(EnchantmentRarity rarity){
|
||||
|
||||
EnchantmentProperties(EnchantmentRarity rarity) {
|
||||
this.rarity = rarity;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,19 +7,18 @@ public enum EnchantmentRarity {
|
|||
COMMON(1),
|
||||
UNCOMMON(2),
|
||||
RARE(4),
|
||||
VERY_RARE(8)
|
||||
|
||||
;
|
||||
VERY_RARE(8);
|
||||
|
||||
private final int itemValue;
|
||||
private final int bookValue;
|
||||
|
||||
EnchantmentRarity(int itemValue, int bookValue){
|
||||
EnchantmentRarity(int itemValue, int bookValue) {
|
||||
this.itemValue = itemValue;
|
||||
this.bookValue = bookValue;
|
||||
}
|
||||
EnchantmentRarity(int itemValue){
|
||||
this(itemValue, Math.max(1,itemValue/2));
|
||||
|
||||
EnchantmentRarity(int itemValue) {
|
||||
this(itemValue, Math.max(1, itemValue / 2));
|
||||
}
|
||||
|
||||
public int getBookValue() {
|
||||
|
|
|
|||
|
|
@ -14,15 +14,17 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* Abstract Global Config gui for enchantment setting configuration.
|
||||
*
|
||||
* @param <T> Type of the factory of the type of setting the gui should edit.
|
||||
*/
|
||||
public abstract class AbstractEnchantConfigGui<T extends AbstractSettingGui.SettingGuiFactory> extends ValueUpdatableGui {
|
||||
|
||||
/**
|
||||
* Constructor for a gui displaying available enchantment to edit a enchantment setting.
|
||||
*
|
||||
* @param title Title of the gui.
|
||||
*/
|
||||
protected AbstractEnchantConfigGui(String title){
|
||||
protected AbstractEnchantConfigGui(String title) {
|
||||
super(6, title, CustomAnvil.instance);
|
||||
}
|
||||
|
||||
|
|
@ -30,8 +32,8 @@ public abstract class AbstractEnchantConfigGui<T extends AbstractSettingGui.Sett
|
|||
|
||||
/**
|
||||
* Initialise value updatable gui pattern
|
||||
*/
|
||||
protected void init(){
|
||||
*/
|
||||
protected void init() {
|
||||
// Back item panel
|
||||
addPane(GuiSharedConstant.BACK_TO_MAIN_MENU_BIG_LIST_DISPLAY_BACKGROUND_PANE);
|
||||
|
||||
|
|
@ -50,7 +52,7 @@ public abstract class AbstractEnchantConfigGui<T extends AbstractSettingGui.Sett
|
|||
/**
|
||||
* Prepare enchantment config gui displayed items factory.
|
||||
*/
|
||||
protected void prepareValues(){
|
||||
protected void prepareValues() {
|
||||
bookItemFactoryList = new ArrayList<>();
|
||||
|
||||
for (Enchantment enchant : GuiSharedConstant.SORTED_ENCHANTMENT_LIST) {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ public class ConfirmActionGui extends ChestGui {
|
|||
|
||||
private static final ItemStack CANCEL_ITEM;
|
||||
private static final ItemStack CONFIRM_ITEM;
|
||||
|
||||
static {
|
||||
CANCEL_ITEM = new ItemStack(Material.RED_TERRACOTTA);
|
||||
ItemMeta meta = CANCEL_ITEM.getItemMeta();
|
||||
|
|
@ -58,21 +59,21 @@ public class ConfirmActionGui extends ChestGui {
|
|||
event.setCancelled(true);
|
||||
HumanEntity player = event.getWhoClicked();
|
||||
|
||||
if(!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||
player.closeInventory();
|
||||
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean success;
|
||||
try{
|
||||
try {
|
||||
success = onConfirm.get();
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
CustomAnvil.instance.getLogger().log(Level.WARNING, "Could not process confirmation supplier.", e);
|
||||
success = false;
|
||||
}
|
||||
|
||||
if(!success){
|
||||
if (!success) {
|
||||
event.getWhoClicked().sendMessage("\u00A7cAction could not be completed. ");
|
||||
}
|
||||
backOnConfirm.show(player);
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class BasicConfigGui extends ValueUpdatableGui {
|
|||
/**
|
||||
* Constructor of this Global gui for basic settings.
|
||||
*/
|
||||
private BasicConfigGui(){
|
||||
private BasicConfigGui() {
|
||||
super(3, "\u00A78Basic Config", CustomAnvil.instance);
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ public class BasicConfigGui extends ValueUpdatableGui {
|
|||
/**
|
||||
* Initialise Basic gui
|
||||
*/
|
||||
private void init(){
|
||||
private void init() {
|
||||
Pattern pattern = new Pattern(
|
||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||
"012345670",
|
||||
|
|
@ -70,15 +70,15 @@ public class BasicConfigGui extends ValueUpdatableGui {
|
|||
/**
|
||||
* Prepare basic gui displayed items factory and static items..
|
||||
*/
|
||||
protected void prepareValues(){
|
||||
protected void prepareValues() {
|
||||
// limit repair item
|
||||
this.limitRepairFactory = BoolSettingsGui.boolFactory("\u00A78Limit Repair Cost ?",this,
|
||||
this.limitRepairFactory = BoolSettingsGui.boolFactory("\u00A78Limit Repair Cost ?", this,
|
||||
ConfigOptions.LIMIT_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.DEFAULT_LIMIT_REPAIR);
|
||||
|
||||
// rename cost item
|
||||
IntRange range = ConfigOptions.REPAIR_LIMIT_RANGE;
|
||||
this.repairCostFactory = IntSettingsGui.intFactory("\u00A78Repair Cost Limit", this,
|
||||
ConfigOptions.LIMIT_REPAIR_VALUE, ConfigHolder.DEFAULT_CONFIG, range.getFirst(),range.getLast(),
|
||||
ConfigOptions.LIMIT_REPAIR_VALUE, ConfigHolder.DEFAULT_CONFIG, range.getFirst(), range.getLast(),
|
||||
ConfigOptions.DEFAULT_LIMIT_REPAIR_VALUE,
|
||||
1, 5, 10);
|
||||
|
||||
|
|
@ -92,33 +92,33 @@ public class BasicConfigGui extends ValueUpdatableGui {
|
|||
this.notNeededLimitValueItem = new GuiItem(item, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
||||
|
||||
// remove repair limit item
|
||||
this.removeRepairLimit = BoolSettingsGui.boolFactory("\u00A78Remove Repair Limit ?",this,
|
||||
this.removeRepairLimit = BoolSettingsGui.boolFactory("\u00A78Remove Repair Limit ?", this,
|
||||
ConfigOptions.REMOVE_REPAIR_LIMIT, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.DEFAULT_REMOVE_LIMIT);
|
||||
|
||||
// item repair cost
|
||||
range = ConfigOptions.REPAIR_COST_RANGE;
|
||||
this.itemRepairCost = IntSettingsGui.intFactory("\u00A78Item Repair Cost", this,
|
||||
ConfigOptions.ITEM_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(),range.getLast(),
|
||||
ConfigOptions.ITEM_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(), range.getLast(),
|
||||
ConfigOptions.DEFAULT_ITEM_REPAIR_COST,
|
||||
1, 5, 10, 50, 100);
|
||||
|
||||
// unit repair cost
|
||||
this.unitRepairCost = IntSettingsGui.intFactory("\u00A78Unit Repair Cost", this,
|
||||
ConfigOptions.UNIT_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(),range.getLast(),
|
||||
ConfigOptions.UNIT_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(), range.getLast(),
|
||||
ConfigOptions.DEFAULT_UNIT_REPAIR_COST,
|
||||
1, 5, 10, 50, 100);
|
||||
|
||||
// item rename cost
|
||||
range = ConfigOptions.ITEM_RENAME_COST_RANGE;
|
||||
this.itemRenameCost = IntSettingsGui.intFactory("\u00A78Rename Cost", this,
|
||||
ConfigOptions.ITEM_RENAME_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(),range.getLast(),
|
||||
ConfigOptions.ITEM_RENAME_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(), range.getLast(),
|
||||
ConfigOptions.DEFAULT_ITEM_RENAME_COST,
|
||||
1, 5, 10, 50, 100);
|
||||
|
||||
// sacrifice illegal enchant cost
|
||||
range = ConfigOptions.SACRIFICE_ILLEGAL_COST_RANGE;
|
||||
this.sacrificeIllegalEnchantCost = IntSettingsGui.intFactory("\u00A78Sacrifice Illegal Enchant Cost", this,
|
||||
ConfigOptions.SACRIFICE_ILLEGAL_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(),range.getLast(),
|
||||
ConfigOptions.SACRIFICE_ILLEGAL_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(), range.getLast(),
|
||||
ConfigOptions.DEFAULT_SACRIFICE_ILLEGAL_COST,
|
||||
1, 5, 10, 50, 100);
|
||||
|
||||
|
|
@ -132,9 +132,9 @@ public class BasicConfigGui extends ValueUpdatableGui {
|
|||
|
||||
// rename cost item
|
||||
GuiItem limitRepairValueItem;
|
||||
if(this.limitRepairFactory.getConfiguredValue()){
|
||||
if (this.limitRepairFactory.getConfiguredValue()) {
|
||||
limitRepairValueItem = GuiGlobalItems.intSettingGuiItem(this.repairCostFactory, Material.EXPERIENCE_BOTTLE);
|
||||
}else{
|
||||
} else {
|
||||
limitRepairValueItem = this.notNeededLimitValueItem;
|
||||
}
|
||||
pane.bindItem('2', limitRepairValueItem);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import java.util.function.Consumer;
|
|||
public class EnchantConflictGui extends ChestGui {
|
||||
|
||||
public final static EnchantConflictGui INSTANCE = new EnchantConflictGui();
|
||||
|
||||
static {
|
||||
INSTANCE.init();
|
||||
}
|
||||
|
|
@ -47,7 +48,7 @@ public class EnchantConflictGui extends ChestGui {
|
|||
private HashMap<UUID, Integer> pageMap;
|
||||
private PatternPane backgroundPane;
|
||||
|
||||
private void init(){
|
||||
private void init() {
|
||||
// Back item panel
|
||||
Pattern pattern = new Pattern(
|
||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||
|
|
@ -80,13 +81,14 @@ public class EnchantConflictGui extends ChestGui {
|
|||
|
||||
private GuiItem goLeftItem;
|
||||
private GuiItem goRightItem;
|
||||
|
||||
private void prepareOtherValues() {
|
||||
// Left item creation for consumer & bind
|
||||
this.goLeftItem = new GuiItem(new ItemStack(Material.RED_TERRACOTTA), event -> {
|
||||
HumanEntity viewer = event.getWhoClicked();
|
||||
UUID playerUUID = viewer.getUniqueId();
|
||||
int page = this.pageMap.getOrDefault(playerUUID, 0);
|
||||
this.pageMap.put(playerUUID, page-1);
|
||||
this.pageMap.put(playerUUID, page - 1);
|
||||
|
||||
ItemStack cursor = viewer.getItemOnCursor();
|
||||
viewer.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
|
|
@ -101,7 +103,7 @@ public class EnchantConflictGui extends ChestGui {
|
|||
HumanEntity viewer = event.getWhoClicked();
|
||||
UUID playerUUID = viewer.getUniqueId();
|
||||
int page = pageMap.getOrDefault(playerUUID, 0);
|
||||
this.pageMap.put(playerUUID, page+1);
|
||||
this.pageMap.put(playerUUID, page + 1);
|
||||
|
||||
ItemStack cursor = viewer.getItemOnCursor();
|
||||
viewer.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
|
|
@ -124,12 +126,12 @@ public class EnchantConflictGui extends ChestGui {
|
|||
|
||||
createItem.setItemMeta(createMeta);
|
||||
|
||||
this.backgroundPane.bindItem('C', new GuiItem(createItem, (clickEvent)->{
|
||||
this.backgroundPane.bindItem('C', new GuiItem(createItem, (clickEvent) -> {
|
||||
clickEvent.setCancelled(true);
|
||||
HumanEntity player = clickEvent.getWhoClicked();
|
||||
|
||||
// check permission
|
||||
if(!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||
player.closeInventory();
|
||||
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
|
||||
return;
|
||||
|
|
@ -147,10 +149,10 @@ public class EnchantConflictGui extends ChestGui {
|
|||
private Consumer<String> prepareCreateItemConsumer(HumanEntity player) {
|
||||
AtomicReference<Consumer<String>> selfRef = new AtomicReference<>();
|
||||
Consumer<String> selfCallback = (message) -> {
|
||||
if(message == null) return;
|
||||
if (message == null) return;
|
||||
|
||||
message = message.toLowerCase(Locale.ROOT);
|
||||
if("cancel".equalsIgnoreCase(message)) {
|
||||
if ("cancel".equalsIgnoreCase(message)) {
|
||||
player.sendMessage("conflict creation cancelled...");
|
||||
show(player);
|
||||
return;
|
||||
|
|
@ -161,7 +163,7 @@ public class EnchantConflictGui extends ChestGui {
|
|||
// 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 (EnchantConflictGroup conflict : ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList()) {
|
||||
if(conflict.getName().equalsIgnoreCase(message)){
|
||||
if (conflict.getName().equalsIgnoreCase(message)) {
|
||||
player.sendMessage("\u00A7cPlease enter a conflict name that do not already exist...");
|
||||
// wait next message.
|
||||
CustomAnvil.Companion.getChatListener().setListenedCallback(player, selfRef.get());
|
||||
|
|
@ -182,11 +184,11 @@ public class EnchantConflictGui extends ChestGui {
|
|||
String[] emptyStringArray = new String[0];
|
||||
|
||||
FileConfiguration config = ConfigHolder.CONFLICT_HOLDER.getConfig();
|
||||
config.set(message+".enchantments", emptyStringArray);
|
||||
config.set(message+".notAffectedGroups", emptyStringArray);
|
||||
config.set(message+".maxEnchantmentBeforeConflict", 0);
|
||||
config.set(message + ".enchantments", emptyStringArray);
|
||||
config.set(message + ".notAffectedGroups", emptyStringArray);
|
||||
config.set(message + ".maxEnchantmentBeforeConflict", 0);
|
||||
|
||||
if(GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE){
|
||||
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
||||
ConfigHolder.CONFLICT_HOLDER.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||
}
|
||||
|
||||
|
|
@ -199,7 +201,7 @@ public class EnchantConflictGui extends ChestGui {
|
|||
return selfCallback;
|
||||
}
|
||||
|
||||
private OutlinePane createEmptyPage(){
|
||||
private OutlinePane createEmptyPage() {
|
||||
OutlinePane page = new OutlinePane(0, 0, 9, 5);
|
||||
page.align(OutlinePane.Alignment.BEGIN);
|
||||
page.setOrientation(Orientable.Orientation.HORIZONTAL);
|
||||
|
|
@ -207,7 +209,7 @@ public class EnchantConflictGui extends ChestGui {
|
|||
return page;
|
||||
}
|
||||
|
||||
public void reloadValues(){
|
||||
public void reloadValues() {
|
||||
this.conflictGuiMap.forEach((conflict, gui) -> gui.cleanUnused());
|
||||
this.conflictGuiMap.clear();
|
||||
this.firstPage.clear();
|
||||
|
|
@ -221,28 +223,28 @@ public class EnchantConflictGui extends ChestGui {
|
|||
update();
|
||||
}
|
||||
|
||||
public static ItemStack createItemForConflict(EnchantConflictGroup conflict){
|
||||
public static ItemStack createItemForConflict(EnchantConflictGroup conflict) {
|
||||
ItemStack item = new ItemStack(conflict.getRepresentativeMaterial());
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
meta.setDisplayName("\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(conflict.getName()) + " \u00A7fConflict");
|
||||
meta.setLore(Arrays.asList(
|
||||
"\u00A77Enchantment count: \u00A7e"+conflict.getEnchants().size(),
|
||||
"\u00A77Group count: \u00A7e"+conflict.getCantConflictGroup().getGroups().size(),
|
||||
"\u00A77Min enchantments count: \u00A7e"+conflict.getMinBeforeBlock()
|
||||
"\u00A77Enchantment count: \u00A7e" + conflict.getEnchants().size(),
|
||||
"\u00A77Group count: \u00A7e" + conflict.getCantConflictGroup().getGroups().size(),
|
||||
"\u00A77Min enchantments count: \u00A7e" + conflict.getMinBeforeBlock()
|
||||
));
|
||||
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public void updateValueForConflict(EnchantConflictGroup conflict, boolean shouldUpdate){
|
||||
public void updateValueForConflict(EnchantConflictGroup conflict, boolean shouldUpdate) {
|
||||
EnchantConflictSubSettingGui gui = this.conflictGuiMap.get(conflict);
|
||||
ItemStack item = createItemForConflict(conflict);
|
||||
|
||||
GuiItem guiItem;
|
||||
if(gui == null){
|
||||
if (gui == null) {
|
||||
// Create new sub setting gui
|
||||
guiItem = new GuiItem(item, CustomAnvil.instance);
|
||||
gui = new EnchantConflictSubSettingGui(this, conflict, guiItem);
|
||||
|
|
@ -251,22 +253,22 @@ public class EnchantConflictGui extends ChestGui {
|
|||
|
||||
this.conflictGuiMap.put(conflict, gui);
|
||||
addToPage(guiItem);
|
||||
}else{
|
||||
} else {
|
||||
// Replace item with the updated one
|
||||
guiItem = gui.getParentItemForThisGui();
|
||||
guiItem.setItem(item);
|
||||
}
|
||||
|
||||
gui.updateLocal();
|
||||
if(shouldUpdate){
|
||||
if (shouldUpdate) {
|
||||
update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void removeConflict(EnchantConflictGroup conflict){
|
||||
public void removeConflict(EnchantConflictGroup conflict) {
|
||||
EnchantConflictSubSettingGui gui = this.conflictGuiMap.get(conflict);
|
||||
if(gui == null) return;
|
||||
if (gui == null) return;
|
||||
|
||||
this.conflictGuiMap.remove(conflict);
|
||||
removeFromPage(gui.getParentItemForThisGui());
|
||||
|
|
@ -276,8 +278,8 @@ public class EnchantConflictGui extends ChestGui {
|
|||
|
||||
private void addToPage(GuiItem guiItem) {
|
||||
// Get first available page or create one
|
||||
OutlinePane page = this.pages.get(this.pages.size()-1);
|
||||
if(page.getItems().size() >= 5*9){
|
||||
OutlinePane page = this.pages.get(this.pages.size() - 1);
|
||||
if (page.getItems().size() >= 5 * 9) {
|
||||
page = createEmptyPage();
|
||||
this.pages.add(page);
|
||||
}
|
||||
|
|
@ -289,16 +291,16 @@ public class EnchantConflictGui extends ChestGui {
|
|||
// get item page
|
||||
OutlinePane page = null;
|
||||
int pageID = 0;
|
||||
while(pageID < this.pages.size()){
|
||||
while (pageID < this.pages.size()) {
|
||||
OutlinePane tempPage = this.pages.get(pageID);
|
||||
if(tempPage.getItems().contains(guiItem)){
|
||||
if (tempPage.getItems().contains(guiItem)) {
|
||||
page = tempPage;
|
||||
break;
|
||||
}
|
||||
pageID++;
|
||||
}
|
||||
|
||||
if(page == null){// Why...
|
||||
if (page == null) {// Why...
|
||||
return;
|
||||
}
|
||||
removeFromPage(page, pageID, guiItem);
|
||||
|
|
@ -308,62 +310,62 @@ public class EnchantConflictGui extends ChestGui {
|
|||
page.removeItem(guiItem);
|
||||
|
||||
// There is now a slot available, let fill it if possible
|
||||
if(pageID < (this.pages.size() - 1)){
|
||||
OutlinePane newPage = this.pages.get(pageID+1);
|
||||
if (pageID < (this.pages.size() - 1)) {
|
||||
OutlinePane newPage = this.pages.get(pageID + 1);
|
||||
GuiItem nextPageItem = newPage.getItems().get(0);
|
||||
|
||||
removeFromPage(newPage, pageID+1, nextPageItem);
|
||||
removeFromPage(newPage, pageID + 1, nextPageItem);
|
||||
|
||||
OutlinePane thisPage = this.pages.get(pageID);
|
||||
thisPage.addItem(nextPageItem);
|
||||
}else if(pageID > 0 && page.getItems().isEmpty()){
|
||||
} else if (pageID > 0 && page.getItems().isEmpty()) {
|
||||
this.pages.remove(pageID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getPlayerPageID(UUID uuid){
|
||||
public int getPlayerPageID(UUID uuid) {
|
||||
int pageId = this.pageMap.getOrDefault(uuid, 0);
|
||||
if(pageId >= this.pages.size()){
|
||||
pageId = this.pages.size()-1;
|
||||
if (pageId >= this.pages.size()) {
|
||||
pageId = this.pages.size() - 1;
|
||||
}
|
||||
return pageId;
|
||||
}
|
||||
|
||||
public void placeArrow(int page, boolean customise){
|
||||
public void placeArrow(int page, boolean customise) {
|
||||
|
||||
// Place left arrow
|
||||
addPane(this.backgroundPane);
|
||||
if(page > 0){
|
||||
if(customise){
|
||||
if (page > 0) {
|
||||
if (customise) {
|
||||
ItemStack leftItem = this.goLeftItem.getItem();
|
||||
ItemMeta leftMeta = leftItem.getItemMeta();
|
||||
|
||||
leftMeta.setDisplayName("\u00A7eReturn to page " +(page));
|
||||
leftMeta.setDisplayName("\u00A7eReturn to page " + (page));
|
||||
|
||||
leftItem.setItemMeta(leftMeta);
|
||||
this.goLeftItem.setItem(leftItem);
|
||||
}
|
||||
|
||||
this.backgroundPane.bindItem('L', this.goLeftItem);
|
||||
}else{
|
||||
} else {
|
||||
this.backgroundPane.bindItem('L', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
|
||||
}
|
||||
|
||||
// Place right arrow
|
||||
if(page < pages.size()-1){
|
||||
if(customise){
|
||||
if (page < pages.size() - 1) {
|
||||
if (customise) {
|
||||
ItemStack rightItem = this.goRightItem.getItem();
|
||||
ItemMeta rightMeta = rightItem.getItemMeta();
|
||||
|
||||
rightMeta.setDisplayName("\u00A7eGo to page " +(page+2));
|
||||
rightMeta.setDisplayName("\u00A7eGo to page " + (page + 2));
|
||||
|
||||
rightItem.setItemMeta(rightMeta);
|
||||
this.goRightItem.setItem(rightItem);
|
||||
}
|
||||
|
||||
this.backgroundPane.bindItem('R', this.goRightItem);
|
||||
}else{
|
||||
} else {
|
||||
this.backgroundPane.bindItem('R', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
|
||||
}
|
||||
}
|
||||
|
|
@ -381,7 +383,7 @@ public class EnchantConflictGui extends ChestGui {
|
|||
addPane(page);
|
||||
|
||||
// set title
|
||||
setTitle("Conflict Config ("+(pageID+1)+"/"+(pages.size())+")");
|
||||
setTitle("Conflict Config (" + (pageID + 1) + "/" + (pages.size()) + ")");
|
||||
|
||||
super.show(humanEntity);
|
||||
|
||||
|
|
|
|||
|
|
@ -46,10 +46,11 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSe
|
|||
EnchantmentRarity rarity = EnchantmentRarity.NO_RARITY;
|
||||
try {
|
||||
rarity = EnchantmentProperties.valueOf(key.toUpperCase(Locale.ENGLISH)).getRarity();
|
||||
}catch (IllegalArgumentException ignored){}
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
|
||||
return EnchantCostSettingsGui.enchantCostFactory(prettyKey+" Level Cost", this,
|
||||
SECTION_NAME+'.'+key, ConfigHolder.DEFAULT_CONFIG, 0, 255,
|
||||
return EnchantCostSettingsGui.enchantCostFactory(prettyKey + " Level Cost", this,
|
||||
SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG, 0, 255,
|
||||
rarity.getItemValue(), rarity.getBookValue(),
|
||||
1, 10, 50);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ public class EnchantLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsG
|
|||
String key = enchant.getKey().getKey().toLowerCase(Locale.ROOT);
|
||||
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key);
|
||||
|
||||
return IntSettingsGui.intFactory(prettyKey+" Level Limit", this,
|
||||
SECTION_NAME+'.'+key, ConfigHolder.DEFAULT_CONFIG, 0, 255,
|
||||
return IntSettingsGui.intFactory(prettyKey + " Level Limit", this,
|
||||
SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG, 0, 255,
|
||||
enchant.getMaxLevel(),
|
||||
1, 5, 10, 50, 100);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,12 +20,13 @@ public class MainConfigGui extends ChestGui {
|
|||
static {
|
||||
INSTANCE.init();
|
||||
}
|
||||
|
||||
private MainConfigGui() {
|
||||
super(3, "\u00A78Anvil Config", CustomAnvil.instance);
|
||||
|
||||
}
|
||||
|
||||
private void init(){
|
||||
private void init() {
|
||||
Pattern pattern = new Pattern(
|
||||
"I00000000",
|
||||
"012304560",
|
||||
|
|
@ -101,7 +102,7 @@ public class MainConfigGui extends ChestGui {
|
|||
GuiItem quitItem = new GuiItem(quitItemstack, event -> {
|
||||
event.setCancelled(true);
|
||||
event.getWhoClicked().closeInventory();
|
||||
},CustomAnvil.instance);
|
||||
}, CustomAnvil.instance);
|
||||
pane.bindItem('Q', quitItem);
|
||||
|
||||
// create & bind "info" item
|
||||
|
|
|
|||
|
|
@ -26,8 +26,9 @@ public abstract class AbstractSettingGui extends ChestGui {
|
|||
|
||||
/**
|
||||
* Prepare necessary object for a setting gui.
|
||||
* @param rows Number of row for this gui.
|
||||
* @param title Title of this gui.
|
||||
*
|
||||
* @param rows Number of row for this gui.
|
||||
* @param title Title of this gui.
|
||||
* @param parent Parent gui to go back when completed.
|
||||
*/
|
||||
public AbstractSettingGui(int rows, @NotNull TextHolder title, ValueUpdatableGui parent) {
|
||||
|
|
@ -37,8 +38,9 @@ public abstract class AbstractSettingGui extends ChestGui {
|
|||
|
||||
/**
|
||||
* Prepare necessary object for a setting gui.
|
||||
* @param rows Number of row for this gui.
|
||||
* @param title Title of this gui.
|
||||
*
|
||||
* @param rows Number of row for this gui.
|
||||
* @param title Title of this gui.
|
||||
* @param parent Parent gui to go back when completed.
|
||||
*/
|
||||
public AbstractSettingGui(int rows, @NotNull String title, ValueUpdatableGui parent) {
|
||||
|
|
@ -50,9 +52,10 @@ public abstract class AbstractSettingGui extends ChestGui {
|
|||
|
||||
/**
|
||||
* Initialise and prepare value for this gui.
|
||||
*
|
||||
* @param parent Parent gui to go back when completed.
|
||||
*/
|
||||
private void initBase(ValueUpdatableGui parent){
|
||||
private void initBase(ValueUpdatableGui parent) {
|
||||
Pattern pattern = getGuiPattern();
|
||||
pane = new PatternPane(0, 0, pattern.getLength(), pattern.getHeight(), pattern);
|
||||
addPane(pane);
|
||||
|
|
@ -75,6 +78,7 @@ public abstract class AbstractSettingGui extends ChestGui {
|
|||
|
||||
/**
|
||||
* Get main pane for this setting gui.
|
||||
*
|
||||
* @return Main pattern pain of this gui.
|
||||
*/
|
||||
protected PatternPane getPane() {
|
||||
|
|
@ -89,12 +93,14 @@ public abstract class AbstractSettingGui extends ChestGui {
|
|||
* <li><b>B</b>: "back to previous gui" button.</li>
|
||||
* <li><b>0</b>: default background item.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @return The gui's pattern.
|
||||
*/
|
||||
protected abstract Pattern getGuiPattern();
|
||||
|
||||
/**
|
||||
* Called when the associated setting need to be saved.
|
||||
*
|
||||
* @return true if the save was successful. false otherwise
|
||||
*/
|
||||
public abstract boolean onSave();
|
||||
|
|
@ -102,6 +108,7 @@ public abstract class AbstractSettingGui extends ChestGui {
|
|||
/**
|
||||
* If this function return true
|
||||
* the gui assume the associated setting can be saved.
|
||||
*
|
||||
* @return true if there is a change to the setting. false otherwise
|
||||
*/
|
||||
public abstract boolean hadChange();
|
||||
|
|
@ -111,16 +118,17 @@ public abstract class AbstractSettingGui extends ChestGui {
|
|||
* <p>
|
||||
* It is better to keep a factory that hold setting data than find what parameters to use every time.
|
||||
*/
|
||||
public abstract static class SettingGuiFactory{
|
||||
public abstract static class SettingGuiFactory {
|
||||
protected String configPath;
|
||||
protected ConfigHolder config;
|
||||
|
||||
/**
|
||||
* Constructor for settings gui factory
|
||||
*
|
||||
* @param configPath Configuration path of this setting.
|
||||
* @param config Configuration holder of this setting.
|
||||
* @param config Configuration holder of this setting.
|
||||
*/
|
||||
protected SettingGuiFactory(String configPath, ConfigHolder config){
|
||||
protected SettingGuiFactory(String configPath, ConfigHolder config) {
|
||||
this.configPath = configPath;
|
||||
this.config = config;
|
||||
}
|
||||
|
|
@ -141,6 +149,7 @@ public abstract class AbstractSettingGui extends ChestGui {
|
|||
|
||||
/**
|
||||
* Create a gui using setting parameters and current setting value.
|
||||
*
|
||||
* @return A new instance of the implemented setting gui.
|
||||
*/
|
||||
public abstract AbstractSettingGui create();
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import java.util.function.Consumer;
|
|||
/**
|
||||
* An instance of a gui used to edit a boolean setting.
|
||||
*/
|
||||
public class BoolSettingsGui extends AbstractSettingGui{
|
||||
public class BoolSettingsGui extends AbstractSettingGui {
|
||||
|
||||
private final BoolSettingFactory holder;
|
||||
private final boolean before;
|
||||
|
|
@ -29,8 +29,9 @@ public class BoolSettingsGui extends AbstractSettingGui{
|
|||
|
||||
/**
|
||||
* Create a boolean setting config gui.
|
||||
*
|
||||
* @param holder Configuration factory of this setting.
|
||||
* @param now The defined value of this setting.
|
||||
* @param now The defined value of this setting.
|
||||
*/
|
||||
protected BoolSettingsGui(BoolSettingFactory holder, boolean now) {
|
||||
super(3, holder.getTitle(), holder.parent);
|
||||
|
|
@ -57,12 +58,12 @@ public class BoolSettingsGui extends AbstractSettingGui{
|
|||
/**
|
||||
* Prepare "return to default value" gui item.
|
||||
*/
|
||||
protected void prepareReturnToDefault(){
|
||||
protected void prepareReturnToDefault() {
|
||||
ItemStack item = new ItemStack(Material.COMMAND_BLOCK);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
meta.setDisplayName("\u00A7eReset to default value");
|
||||
meta.setLore(Collections.singletonList("\u00A77Default value is: "+holder.defaultVal));
|
||||
meta.setLore(Collections.singletonList("\u00A77Default value is: " + holder.defaultVal));
|
||||
item.setItemMeta(meta);
|
||||
returnToDefault = new GuiItem(item, event -> {
|
||||
event.setCancelled(true);
|
||||
|
|
@ -75,16 +76,16 @@ public class BoolSettingsGui extends AbstractSettingGui{
|
|||
/**
|
||||
* Update item using the setting value to match the new value
|
||||
*/
|
||||
protected void updateValueDisplay(){
|
||||
protected void updateValueDisplay() {
|
||||
PatternPane pane = getPane();
|
||||
|
||||
// Get displayed value for this config.
|
||||
String displayedName;
|
||||
Material displayedMat;
|
||||
if(now){
|
||||
if (now) {
|
||||
displayedName = "\u00A7aTrue";
|
||||
displayedMat = Material.GREEN_TERRACOTTA;
|
||||
}else{
|
||||
} else {
|
||||
displayedName = "\u00A7cFalse";
|
||||
displayedMat = Material.RED_TERRACOTTA;
|
||||
}
|
||||
|
|
@ -100,9 +101,9 @@ public class BoolSettingsGui extends AbstractSettingGui{
|
|||
|
||||
// reset to default
|
||||
GuiItem returnToDefault;
|
||||
if(now != holder.defaultVal){
|
||||
if (now != holder.defaultVal) {
|
||||
returnToDefault = this.returnToDefault;
|
||||
}else{
|
||||
} else {
|
||||
returnToDefault = GuiGlobalItems.backgroundItem();
|
||||
}
|
||||
pane.bindItem('D', returnToDefault);
|
||||
|
|
@ -112,8 +113,8 @@ public class BoolSettingsGui extends AbstractSettingGui{
|
|||
/**
|
||||
* @return A consumer to update the current setting's value.
|
||||
*/
|
||||
protected Consumer<InventoryClickEvent> inverseNowConsumer(){
|
||||
return event->{
|
||||
protected Consumer<InventoryClickEvent> inverseNowConsumer() {
|
||||
return event -> {
|
||||
event.setCancelled(true);
|
||||
now = !now;
|
||||
updateValueDisplay();
|
||||
|
|
@ -126,7 +127,7 @@ public class BoolSettingsGui extends AbstractSettingGui{
|
|||
holder.config.getConfig().set(holder.configPath, now);
|
||||
|
||||
MetricsUtil.INSTANCE.notifyChange(this.holder.config, this.holder.configPath);
|
||||
if(GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE){
|
||||
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
||||
return holder.config.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||
}
|
||||
return true;
|
||||
|
|
@ -139,18 +140,19 @@ public class BoolSettingsGui extends AbstractSettingGui{
|
|||
|
||||
/**
|
||||
* Create a bool setting factory from setting's parameters.
|
||||
* @param title The title of the gui.
|
||||
* @param parent Parent gui to go back when completed.
|
||||
*
|
||||
* @param title The title of the gui.
|
||||
* @param parent Parent gui to go back when completed.
|
||||
* @param configPath Configuration path of this setting.
|
||||
* @param config Configuration holder of this setting.
|
||||
* @param config Configuration holder of this setting.
|
||||
* @param defaultVal Default value if not found on the config.
|
||||
* @return A factory for a boolean setting gui.
|
||||
*/
|
||||
public static BoolSettingFactory boolFactory(@NotNull String title, ValueUpdatableGui parent,
|
||||
String configPath, ConfigHolder config,
|
||||
boolean defaultVal){
|
||||
boolean defaultVal) {
|
||||
return new BoolSettingFactory(
|
||||
title,parent,
|
||||
title, parent,
|
||||
configPath, config,
|
||||
defaultVal);
|
||||
}
|
||||
|
|
@ -158,22 +160,25 @@ public class BoolSettingsGui extends AbstractSettingGui{
|
|||
/**
|
||||
* A factory for a boolean setting gui that hold setting's information.
|
||||
*/
|
||||
public static class BoolSettingFactory extends SettingGuiFactory{
|
||||
@NotNull String title; ValueUpdatableGui parent;
|
||||
public static class BoolSettingFactory extends SettingGuiFactory {
|
||||
@NotNull
|
||||
String title;
|
||||
ValueUpdatableGui parent;
|
||||
boolean defaultVal;
|
||||
|
||||
/**
|
||||
* Constructor for a boolean setting gui factory.
|
||||
* @param title The title of the gui.
|
||||
* @param parent Parent gui to go back when completed.
|
||||
*
|
||||
* @param title The title of the gui.
|
||||
* @param parent Parent gui to go back when completed.
|
||||
* @param configPath Configuration path of this setting.
|
||||
* @param config Configuration holder of this setting.
|
||||
* @param config Configuration holder of this setting.
|
||||
* @param defaultVal Default value if not found on the config.
|
||||
*/
|
||||
protected BoolSettingFactory(
|
||||
@NotNull String title, ValueUpdatableGui parent,
|
||||
String configPath, ConfigHolder config,
|
||||
boolean defaultVal){
|
||||
boolean defaultVal) {
|
||||
super(configPath, config);
|
||||
this.title = title;
|
||||
this.parent = parent;
|
||||
|
|
@ -192,7 +197,7 @@ public class BoolSettingsGui extends AbstractSettingGui{
|
|||
/**
|
||||
* @return The configured value for the associated setting.
|
||||
*/
|
||||
public boolean getConfiguredValue(){
|
||||
public boolean getConfiguredValue() {
|
||||
return this.config.getConfig().getBoolean(this.configPath, this.defaultVal);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
|||
|
||||
/**
|
||||
* Create an enchantment cost setting config gui.
|
||||
* @param holder Configuration factory of this setting.
|
||||
*
|
||||
* @param holder Configuration factory of this setting.
|
||||
* @param nowItem The defined value of this setting item's value.
|
||||
*/
|
||||
protected EnchantCostSettingsGui(EnchantCostSettingFactory holder, int nowItem) {
|
||||
|
|
@ -54,7 +55,7 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
|||
protected void initStepsValue() {
|
||||
super.initStepsValue();
|
||||
|
||||
int nowBook = ((EnchantCostSettingFactory)this.holder).getConfiguredBookValue();
|
||||
int nowBook = ((EnchantCostSettingFactory) this.holder).getConfiguredBookValue();
|
||||
this.beforeBook = nowBook;
|
||||
this.nowBook = nowBook;
|
||||
}
|
||||
|
|
@ -81,7 +82,8 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
|||
bookMeta.setDisplayName("\u00A7aCost of an Enchantment by Book");
|
||||
bookMeta.setLore(Arrays.asList(
|
||||
"\u00A77Cost per result item level of an sacrifice enchantment",
|
||||
"\u00A77Only apply if sacrificed item \u00A7cis \u00A77a book"));bookItemstack.setItemMeta(bookMeta);
|
||||
"\u00A77Only apply if sacrificed item \u00A7cis \u00A77a book"));
|
||||
bookItemstack.setItemMeta(bookMeta);
|
||||
|
||||
// sword display
|
||||
ItemStack swordItemstack = new ItemStack(Material.WOODEN_SWORD);
|
||||
|
|
@ -95,12 +97,12 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
|||
swordItemstack.setItemMeta(swordMeta);
|
||||
|
||||
pane.bindItem('1', GuiGlobalItems.backgroundItem(Material.BLACK_STAINED_GLASS_PANE));
|
||||
pane.bindItem('2', new GuiItem(bookItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance));
|
||||
pane.bindItem('2', new GuiItem(bookItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance));
|
||||
pane.bindItem('3', new GuiItem(swordItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareReturnToDefault(){
|
||||
protected void prepareReturnToDefault() {
|
||||
ItemStack item = new ItemStack(Material.COMMAND_BLOCK);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
|
|
@ -118,11 +120,11 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
|||
now = holder.defaultVal;
|
||||
updateValueDisplay();
|
||||
update();
|
||||
}, CustomAnvil.instance);
|
||||
}, CustomAnvil.instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateValueDisplay(){
|
||||
protected void updateValueDisplay() {
|
||||
super.updateValueDisplay();
|
||||
PatternPane pane = getPane();
|
||||
|
||||
|
|
@ -133,32 +135,32 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
|||
|
||||
// minus item
|
||||
GuiItem minusItem;
|
||||
if(nowBook > holder.min){
|
||||
if (nowBook > holder.min) {
|
||||
int planned = Math.max(holder.min, nowBook - step);
|
||||
ItemStack item = new ItemStack(Material.RED_TERRACOTTA);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName("\u00A7e"+nowBook+" -> "+planned + " \u00A7r(\u00A7c-"+(nowBook-planned)+"\u00A7r)");
|
||||
meta.setDisplayName("\u00A7e" + nowBook + " -> " + planned + " \u00A7r(\u00A7c-" + (nowBook - planned) + "\u00A7r)");
|
||||
meta.setLore(AbstractSettingGui.CLICK_LORE);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
minusItem = new GuiItem(item, updateNowBookConsumer(planned), CustomAnvil.instance);
|
||||
}else{
|
||||
} else {
|
||||
minusItem = GuiGlobalItems.backgroundItem(Material.BARRIER);
|
||||
}
|
||||
pane.bindItem('M', minusItem);
|
||||
|
||||
//plus item
|
||||
GuiItem plusItem;
|
||||
if(nowBook < holder.max){
|
||||
if (nowBook < holder.max) {
|
||||
int planned = Math.min(holder.max, nowBook + step);
|
||||
ItemStack item = new ItemStack(Material.GREEN_TERRACOTTA);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName("\u00A7e"+nowBook+" -> "+planned + " \u00A7r(\u00A7a+"+(planned-nowBook)+"\u00A7r)");
|
||||
meta.setDisplayName("\u00A7e" + nowBook + " -> " + planned + " \u00A7r(\u00A7a+" + (planned - nowBook) + "\u00A7r)");
|
||||
meta.setLore(AbstractSettingGui.CLICK_LORE);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
plusItem = new GuiItem(item, updateNowBookConsumer(planned), CustomAnvil.instance);
|
||||
}else{
|
||||
} else {
|
||||
plusItem = GuiGlobalItems.backgroundItem(Material.BARRIER);
|
||||
}
|
||||
pane.bindItem('P', plusItem);
|
||||
|
|
@ -166,7 +168,7 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
|||
// "result" display
|
||||
ItemStack resultPaper = new ItemStack(Material.PAPER);
|
||||
ItemMeta resultMeta = resultPaper.getItemMeta();
|
||||
resultMeta.setDisplayName("\u00A7eValue: "+nowBook);
|
||||
resultMeta.setDisplayName("\u00A7eValue: " + nowBook);
|
||||
resultPaper.setItemMeta(resultMeta);
|
||||
GuiItem resultItem = new GuiItem(resultPaper, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
||||
|
||||
|
|
@ -174,9 +176,9 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
|||
|
||||
// reset to default
|
||||
GuiItem returnToDefault;
|
||||
if(now != holder.defaultVal || nowBook != holder.defaultBookVal){
|
||||
if (now != holder.defaultVal || nowBook != holder.defaultBookVal) {
|
||||
returnToDefault = this.returnToDefault;
|
||||
}else{
|
||||
} else {
|
||||
returnToDefault = GuiGlobalItems.backgroundItem();
|
||||
}
|
||||
pane.bindItem('D', returnToDefault);
|
||||
|
|
@ -188,8 +190,8 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
|||
* @param planned Value to change current book cost setting to.
|
||||
* @return A consumer to update the current book cost setting's value.
|
||||
*/
|
||||
protected Consumer<InventoryClickEvent> updateNowBookConsumer(int planned){
|
||||
return event->{
|
||||
protected Consumer<InventoryClickEvent> updateNowBookConsumer(int planned) {
|
||||
return event -> {
|
||||
event.setCancelled(true);
|
||||
nowBook = planned;
|
||||
updateValueDisplay();
|
||||
|
|
@ -204,11 +206,11 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
|||
|
||||
@Override
|
||||
public boolean onSave() {
|
||||
holder.config.getConfig().set(holder.configPath+ITEM_PATH, now);
|
||||
holder.config.getConfig().set(holder.configPath+BOOK_PATH, nowBook);
|
||||
holder.config.getConfig().set(holder.configPath + ITEM_PATH, now);
|
||||
holder.config.getConfig().set(holder.configPath + BOOK_PATH, nowBook);
|
||||
|
||||
MetricsUtil.INSTANCE.notifyChange(this.holder.config, this.holder.configPath);
|
||||
if(GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE){
|
||||
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
||||
return holder.config.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||
}
|
||||
return true;
|
||||
|
|
@ -221,27 +223,28 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
|||
|
||||
/**
|
||||
* Create an int setting factory from setting's parameters.
|
||||
* @param title The title of the gui.
|
||||
* @param parent Parent gui to go back when completed.
|
||||
* @param configPath Configuration path of this setting.
|
||||
* @param config Configuration holder of this setting.
|
||||
* @param min Minimum value of this setting.
|
||||
* @param max Maximum value of this setting.
|
||||
*
|
||||
* @param title The title of the gui.
|
||||
* @param parent Parent gui to go back when completed.
|
||||
* @param configPath Configuration path of this setting.
|
||||
* @param config Configuration holder of this setting.
|
||||
* @param min Minimum value of this setting.
|
||||
* @param max Maximum value of this setting.
|
||||
* @param defaultItemVal Default item value if not found on the config.
|
||||
* @param defaultBookVal Default book value if not found on the config.
|
||||
* @param steps List of step the value can increment/decrement.
|
||||
* List's size should be between 1 (included) and 3 (included).
|
||||
* it is visually preferable to have an odd number of step.
|
||||
* If step only contain 1 value, no step item should be displayed.
|
||||
* @param steps List of step the value can increment/decrement.
|
||||
* List's size should be between 1 (included) and 3 (included).
|
||||
* it is visually preferable to have an odd number of step.
|
||||
* If step only contain 1 value, no step item should be displayed.
|
||||
* @return A factory for an enchant cost setting gui.
|
||||
*/
|
||||
public static EnchantCostSettingFactory enchantCostFactory(
|
||||
@NotNull String title, ValueUpdatableGui parent,
|
||||
String configPath, ConfigHolder config,
|
||||
int min, int max, int defaultItemVal, int defaultBookVal,
|
||||
int... steps){
|
||||
int... steps) {
|
||||
return new EnchantCostSettingFactory(
|
||||
title,parent,
|
||||
title, parent,
|
||||
configPath, config,
|
||||
min, max, defaultItemVal, defaultBookVal, steps);
|
||||
}
|
||||
|
|
@ -255,26 +258,27 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
|||
|
||||
/**
|
||||
* Constructor for an enchantment cost setting gui factory.
|
||||
* @param title The title of the gui.
|
||||
* @param parent Parent gui to go back when completed.
|
||||
* @param configPath Configuration path of this setting.
|
||||
* @param config Configuration holder of this setting.
|
||||
* @param min Minimum value of this setting.
|
||||
* @param max Maximum value of this setting.
|
||||
*
|
||||
* @param title The title of the gui.
|
||||
* @param parent Parent gui to go back when completed.
|
||||
* @param configPath Configuration path of this setting.
|
||||
* @param config Configuration holder of this setting.
|
||||
* @param min Minimum value of this setting.
|
||||
* @param max Maximum value of this setting.
|
||||
* @param defaultItemVal Default item value if not found on the config.
|
||||
* @param defaultBookVal Default book value if not found on the config.
|
||||
* @param steps List of step the value can increment/decrement.
|
||||
* List's size should be between 1 (included) and 3 (included).
|
||||
* it is visually preferable to have an odd number of step.
|
||||
* If step only contain 1 value, no step item should be displayed.
|
||||
* @param steps List of step the value can increment/decrement.
|
||||
* List's size should be between 1 (included) and 3 (included).
|
||||
* it is visually preferable to have an odd number of step.
|
||||
* If step only contain 1 value, no step item should be displayed.
|
||||
*/
|
||||
protected EnchantCostSettingFactory(
|
||||
@NotNull String title, ValueUpdatableGui parent,
|
||||
String configPath, ConfigHolder config,
|
||||
int min, int max, int defaultItemVal, int defaultBookVal,
|
||||
int... steps){
|
||||
int... steps) {
|
||||
|
||||
super(title,parent,
|
||||
super(title, parent,
|
||||
configPath, config,
|
||||
min, max, defaultItemVal, steps);
|
||||
this.defaultBookVal = defaultBookVal;
|
||||
|
|
@ -285,14 +289,14 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
|||
*/
|
||||
@Override
|
||||
public int getConfiguredValue() {
|
||||
return this.config.getConfig().getInt(this.configPath+ITEM_PATH, this.defaultVal);
|
||||
return this.config.getConfig().getInt(this.configPath + ITEM_PATH, this.defaultVal);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The configured value for the enchant setting book value.
|
||||
*/
|
||||
public int getConfiguredBookValue(){
|
||||
return this.config.getConfig().getInt(this.configPath+BOOK_PATH, this.defaultBookVal);
|
||||
public int getConfiguredBookValue() {
|
||||
return this.config.getConfig().getInt(this.configPath + BOOK_PATH, this.defaultBookVal);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class EnchantSelectSettingGui extends AbstractSettingGui{
|
||||
public class EnchantSelectSettingGui extends AbstractSettingGui {
|
||||
|
||||
SelectEnchantmentContainer enchantContainer;
|
||||
int page;
|
||||
|
|
@ -57,7 +57,7 @@ public class EnchantSelectSettingGui extends AbstractSettingGui{
|
|||
);
|
||||
}
|
||||
|
||||
protected void initGroups(){
|
||||
protected void initGroups() {
|
||||
// Add enchantment gui item
|
||||
OutlinePane filledEnchant = new OutlinePane(0, 0, 9, 5);
|
||||
filledEnchant.setPriority(Pane.Priority.HIGH);
|
||||
|
|
@ -66,7 +66,7 @@ public class EnchantSelectSettingGui extends AbstractSettingGui{
|
|||
|
||||
Set<Enchantment> illegalEnchant = this.enchantContainer.illegalEnchantments();
|
||||
for (Enchantment enchant : GuiSharedConstant.SORTED_ENCHANTMENT_LIST) {
|
||||
if(illegalEnchant.contains(enchant)) {
|
||||
if (illegalEnchant.contains(enchant)) {
|
||||
return;
|
||||
}
|
||||
filledEnchant.addItem(getGuiItemFromEnchant(enchant));
|
||||
|
|
@ -76,13 +76,13 @@ public class EnchantSelectSettingGui extends AbstractSettingGui{
|
|||
|
||||
}
|
||||
|
||||
private GuiItem getGuiItemFromEnchant(Enchantment enchantment){
|
||||
private GuiItem getGuiItemFromEnchant(Enchantment enchantment) {
|
||||
boolean isIn = this.selectedEnchant.contains(enchantment);
|
||||
|
||||
Material usedMaterial;
|
||||
if(isIn){
|
||||
if (isIn) {
|
||||
usedMaterial = Material.ENCHANTED_BOOK;
|
||||
}else{
|
||||
} else {
|
||||
usedMaterial = Material.BOOK;
|
||||
}
|
||||
ItemStack item = new ItemStack(usedMaterial);
|
||||
|
|
@ -98,22 +98,22 @@ public class EnchantSelectSettingGui extends AbstractSettingGui{
|
|||
private static final List<String> TRUE_LORE = Collections.singletonList("\u00A77Value: \u00A7aSelected");
|
||||
private static final List<String> FALSE_LORE = Collections.singletonList("\u00A77Value: \u00A7cNot Selected");
|
||||
|
||||
public void setEnchantItemMeta(ItemStack item, String name, boolean isIn){
|
||||
public void setEnchantItemMeta(ItemStack item, String name, boolean isIn) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
if(meta == null){
|
||||
CustomAnvil.instance.getLogger().warning("Could not create item for enchantment: "+name+":\n" +
|
||||
"Item do not gave item meta: "+item+". Using placeholder instead");
|
||||
if (meta == null) {
|
||||
CustomAnvil.instance.getLogger().warning("Could not create item for enchantment: " + name + ":\n" +
|
||||
"Item do not gave item meta: " + item + ". Using placeholder instead");
|
||||
item.setType(Material.PAPER);
|
||||
meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
}
|
||||
|
||||
meta.setDisplayName("\u00A7"+(isIn ? 'a' : 'c')+ CasedStringUtil.snakeToUpperSpacedCase(name));
|
||||
if(isIn){
|
||||
meta.setDisplayName("\u00A7" + (isIn ? 'a' : 'c') + CasedStringUtil.snakeToUpperSpacedCase(name));
|
||||
if (isIn) {
|
||||
meta.addEnchant(Enchantment.DAMAGE_UNDEAD, 1, true);
|
||||
meta.setLore(TRUE_LORE);
|
||||
}else{
|
||||
} else {
|
||||
meta.removeEnchant(Enchantment.DAMAGE_UNDEAD);
|
||||
meta.setLore(FALSE_LORE);
|
||||
}
|
||||
|
|
@ -122,17 +122,17 @@ public class EnchantSelectSettingGui extends AbstractSettingGui{
|
|||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
private Consumer<InventoryClickEvent> getEnchantItemConsumer(Enchantment enchant, GuiItem guiItem){
|
||||
private Consumer<InventoryClickEvent> getEnchantItemConsumer(Enchantment enchant, GuiItem guiItem) {
|
||||
return event -> {
|
||||
event.setCancelled(true);
|
||||
|
||||
ItemStack item = guiItem.getItem();
|
||||
|
||||
boolean isIn = this.selectedEnchant.contains(enchant);
|
||||
if(isIn){
|
||||
if (isIn) {
|
||||
this.selectedEnchant.remove(enchant);
|
||||
item.setType(Material.BOOK);
|
||||
}else{
|
||||
} else {
|
||||
this.selectedEnchant.add(enchant);
|
||||
item.setType(Material.ENCHANTED_BOOK);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,10 +20,13 @@ import xyz.alexcrea.cuanvil.gui.config.SelectGroupContainer;
|
|||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class GroupSelectSettingGui extends AbstractSettingGui{
|
||||
public class GroupSelectSettingGui extends AbstractSettingGui {
|
||||
|
||||
SelectGroupContainer groupContainer;
|
||||
int page;
|
||||
|
|
@ -56,7 +59,7 @@ public class GroupSelectSettingGui extends AbstractSettingGui{
|
|||
);
|
||||
}
|
||||
|
||||
protected void initGroups(){
|
||||
protected void initGroups() {
|
||||
// Add enchantment gui item
|
||||
OutlinePane filledEnchant = new OutlinePane(0, 0, 9, 5);
|
||||
filledEnchant.setPriority(Pane.Priority.HIGH);
|
||||
|
|
@ -65,7 +68,7 @@ public class GroupSelectSettingGui extends AbstractSettingGui{
|
|||
|
||||
Set<AbstractMaterialGroup> illegalGroup = this.groupContainer.illegalGroups();
|
||||
for (AbstractMaterialGroup group : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) {
|
||||
if(illegalGroup.contains(group)) {
|
||||
if (illegalGroup.contains(group)) {
|
||||
return;
|
||||
}
|
||||
filledEnchant.addItem(getGuiItemFromGroup(group));
|
||||
|
|
@ -75,7 +78,7 @@ public class GroupSelectSettingGui extends AbstractSettingGui{
|
|||
|
||||
}
|
||||
|
||||
private GuiItem getGuiItemFromGroup(AbstractMaterialGroup group){
|
||||
private GuiItem getGuiItemFromGroup(AbstractMaterialGroup group) {
|
||||
boolean isIn = this.selectedGroups.contains(group);
|
||||
|
||||
Material usedMaterial = group.getRepresentativeMaterial();
|
||||
|
|
@ -91,22 +94,22 @@ public class GroupSelectSettingGui extends AbstractSettingGui{
|
|||
private static final List<String> TRUE_LORE = Collections.singletonList("\u00A77Value: \u00A7aSelected");
|
||||
private static final List<String> FALSE_LORE = Collections.singletonList("\u00A77Value: \u00A7cNot Selected");
|
||||
|
||||
public void setGroupItemMeta(ItemStack item, String name, boolean isIn){
|
||||
public void setGroupItemMeta(ItemStack item, String name, boolean isIn) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
if(meta == null){
|
||||
CustomAnvil.instance.getLogger().warning("Could not create item for group: "+name+":\n" +
|
||||
"Item do not gave item meta: "+item+". Using placeholder instead");
|
||||
if (meta == null) {
|
||||
CustomAnvil.instance.getLogger().warning("Could not create item for group: " + name + ":\n" +
|
||||
"Item do not gave item meta: " + item + ". Using placeholder instead");
|
||||
item.setType(Material.PAPER);
|
||||
meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
}
|
||||
|
||||
meta.setDisplayName("\u00A7"+(isIn ? 'a' : 'c')+ CasedStringUtil.snakeToUpperSpacedCase(name));
|
||||
if(isIn){
|
||||
meta.setDisplayName("\u00A7" + (isIn ? 'a' : 'c') + CasedStringUtil.snakeToUpperSpacedCase(name));
|
||||
if (isIn) {
|
||||
meta.addEnchant(Enchantment.DAMAGE_UNDEAD, 1, true);
|
||||
meta.setLore(TRUE_LORE);
|
||||
}else{
|
||||
} else {
|
||||
meta.removeEnchant(Enchantment.DAMAGE_UNDEAD);
|
||||
meta.setLore(FALSE_LORE);
|
||||
}
|
||||
|
|
@ -115,14 +118,14 @@ public class GroupSelectSettingGui extends AbstractSettingGui{
|
|||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
private Consumer<InventoryClickEvent> getGroupItemConsumer(AbstractMaterialGroup group, GuiItem guiItem){
|
||||
private Consumer<InventoryClickEvent> getGroupItemConsumer(AbstractMaterialGroup group, GuiItem guiItem) {
|
||||
return event -> {
|
||||
event.setCancelled(true);
|
||||
|
||||
boolean isIn = this.selectedGroups.contains(group);
|
||||
if(isIn){
|
||||
if (isIn) {
|
||||
this.selectedGroups.remove(group);
|
||||
}else{
|
||||
} else {
|
||||
this.selectedGroups.add(group);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import java.util.function.Consumer;
|
|||
/**
|
||||
* An instance of a gui used to edit an int setting.
|
||||
*/
|
||||
public class IntSettingsGui extends AbstractSettingGui{
|
||||
public class IntSettingsGui extends AbstractSettingGui {
|
||||
|
||||
protected final IntSettingFactory holder;
|
||||
protected final int before;
|
||||
|
|
@ -32,8 +32,9 @@ public class IntSettingsGui extends AbstractSettingGui{
|
|||
|
||||
/**
|
||||
* Create an int setting config gui.
|
||||
*
|
||||
* @param holder Configuration factory of this setting.
|
||||
* @param now The defined value of this setting.
|
||||
* @param now The defined value of this setting.
|
||||
*/
|
||||
protected IntSettingsGui(IntSettingFactory holder, int now) {
|
||||
super(3, holder.getTitle(), holder.parent);
|
||||
|
|
@ -59,43 +60,44 @@ public class IntSettingsGui extends AbstractSettingGui{
|
|||
}
|
||||
|
||||
protected GuiItem returnToDefault;
|
||||
|
||||
/**
|
||||
* Prepare "return to default value" gui item.
|
||||
*/
|
||||
protected void prepareReturnToDefault(){
|
||||
protected void prepareReturnToDefault() {
|
||||
ItemStack item = new ItemStack(Material.COMMAND_BLOCK);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
meta.setDisplayName("\u00A7eReset to default value");
|
||||
meta.setLore(Collections.singletonList("\u00A77Default value is: "+holder.defaultVal));
|
||||
meta.setLore(Collections.singletonList("\u00A77Default value is: " + holder.defaultVal));
|
||||
item.setItemMeta(meta);
|
||||
returnToDefault = new GuiItem(item, event -> {
|
||||
event.setCancelled(true);
|
||||
now = holder.defaultVal;
|
||||
updateValueDisplay();
|
||||
update();
|
||||
}, CustomAnvil.instance);
|
||||
}, CustomAnvil.instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update item using the setting value to match the new value.
|
||||
*/
|
||||
protected void updateValueDisplay(){
|
||||
protected void updateValueDisplay() {
|
||||
|
||||
PatternPane pane = getPane();
|
||||
|
||||
// minus item
|
||||
GuiItem minusItem;
|
||||
if(now > holder.min){
|
||||
if (now > holder.min) {
|
||||
int planned = Math.max(holder.min, now - step);
|
||||
ItemStack item = new ItemStack(Material.RED_TERRACOTTA);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName("\u00A7e"+now+" -> "+planned + " \u00A7r(\u00A7c-"+(now-planned)+"\u00A7r)");
|
||||
meta.setDisplayName("\u00A7e" + now + " -> " + planned + " \u00A7r(\u00A7c-" + (now - planned) + "\u00A7r)");
|
||||
meta.setLore(AbstractSettingGui.CLICK_LORE);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
minusItem = new GuiItem(item, updateNowConsumer(planned), CustomAnvil.instance);
|
||||
}else{
|
||||
} else {
|
||||
minusItem = GuiGlobalItems.backgroundItem(Material.BARRIER);
|
||||
}
|
||||
pane.bindItem('-', minusItem);
|
||||
|
|
@ -103,16 +105,16 @@ public class IntSettingsGui extends AbstractSettingGui{
|
|||
//plus item
|
||||
// may do a function to generalise ?
|
||||
GuiItem plusItem;
|
||||
if(now < holder.max){
|
||||
if (now < holder.max) {
|
||||
int planned = Math.min(holder.max, now + step);
|
||||
ItemStack item = new ItemStack(Material.GREEN_TERRACOTTA);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName("\u00A7e"+now+" -> "+planned + " \u00A7r(\u00A7a+"+(planned-now)+"\u00A7r)");
|
||||
meta.setDisplayName("\u00A7e" + now + " -> " + planned + " \u00A7r(\u00A7a+" + (planned - now) + "\u00A7r)");
|
||||
meta.setLore(AbstractSettingGui.CLICK_LORE);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
plusItem = new GuiItem(item, updateNowConsumer(planned), CustomAnvil.instance);
|
||||
}else{
|
||||
} else {
|
||||
plusItem = GuiGlobalItems.backgroundItem(Material.BARRIER);
|
||||
}
|
||||
pane.bindItem('+', plusItem);
|
||||
|
|
@ -120,7 +122,7 @@ public class IntSettingsGui extends AbstractSettingGui{
|
|||
// "result" display
|
||||
ItemStack resultPaper = new ItemStack(Material.PAPER);
|
||||
ItemMeta resultMeta = resultPaper.getItemMeta();
|
||||
resultMeta.setDisplayName("\u00A7eValue: "+now);
|
||||
resultMeta.setDisplayName("\u00A7eValue: " + now);
|
||||
resultPaper.setItemMeta(resultMeta);
|
||||
GuiItem resultItem = new GuiItem(resultPaper, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
||||
|
||||
|
|
@ -128,9 +130,9 @@ public class IntSettingsGui extends AbstractSettingGui{
|
|||
|
||||
// reset to default
|
||||
GuiItem returnToDefault;
|
||||
if(now != holder.defaultVal){
|
||||
if (now != holder.defaultVal) {
|
||||
returnToDefault = this.returnToDefault;
|
||||
}else{
|
||||
} else {
|
||||
returnToDefault = GuiGlobalItems.backgroundItem();
|
||||
}
|
||||
pane.bindItem('D', returnToDefault);
|
||||
|
|
@ -142,8 +144,8 @@ public class IntSettingsGui extends AbstractSettingGui{
|
|||
* @param planned Value to change current setting to.
|
||||
* @return A consumer to update the current setting's value.
|
||||
*/
|
||||
protected Consumer<InventoryClickEvent> updateNowConsumer(int planned){
|
||||
return event->{
|
||||
protected Consumer<InventoryClickEvent> updateNowConsumer(int planned) {
|
||||
return event -> {
|
||||
event.setCancelled(true);
|
||||
now = planned;
|
||||
updateValueDisplay();
|
||||
|
|
@ -154,12 +156,12 @@ public class IntSettingsGui extends AbstractSettingGui{
|
|||
/**
|
||||
* Initialise step items.
|
||||
*/
|
||||
protected void initStepsValue(){
|
||||
protected void initStepsValue() {
|
||||
// Put background glass on the background of 'a' to 'b'
|
||||
GuiItem background = GuiGlobalItems.backgroundItem();
|
||||
PatternPane pane = getPane();
|
||||
|
||||
for (char i = 'a'; i < (getMidStepChar()-'a')*2+1; i++) {
|
||||
for (char i = 'a'; i < (getMidStepChar() - 'a') * 2 + 1; i++) {
|
||||
pane.bindItem(i, background);
|
||||
}
|
||||
// Then update legit step values
|
||||
|
|
@ -169,35 +171,37 @@ public class IntSettingsGui extends AbstractSettingGui{
|
|||
/**
|
||||
* Update steps items value.
|
||||
*/
|
||||
protected void updateStepValue(){
|
||||
if(holder.steps.length <= 1) return;
|
||||
protected void updateStepValue() {
|
||||
if (holder.steps.length <= 1) return;
|
||||
// We assume steps have a length of 2k+1 cause its more pretty
|
||||
char val = getMidStepChar();
|
||||
// Offset to start (not the best way to do it)
|
||||
val -= (char) ((holder.steps.length-1)/2);
|
||||
val -= (char) ((holder.steps.length - 1) / 2);
|
||||
|
||||
// Then place items
|
||||
PatternPane pane = getPane();
|
||||
for (int i = 0; i < holder.steps.length; i++) {
|
||||
pane.bindItem(val+i, stepGuiItem(i));
|
||||
pane.bindItem(val + i, stepGuiItem(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Step use lower case character from 'a' to a certain char.
|
||||
*
|
||||
* @return The middle value of the character set for steps.
|
||||
*/
|
||||
protected char getMidStepChar(){
|
||||
protected char getMidStepChar() {
|
||||
return 'e';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a step item from a step value.
|
||||
*
|
||||
* @param stepIndex the index of the step item.
|
||||
* @return A step item corresponding to its index value.
|
||||
*/
|
||||
protected GuiItem stepGuiItem(int stepIndex){
|
||||
protected GuiItem stepGuiItem(int stepIndex) {
|
||||
int stepValue = holder.steps[stepIndex];
|
||||
|
||||
// Get material properties
|
||||
|
|
@ -205,15 +209,15 @@ public class IntSettingsGui extends AbstractSettingGui{
|
|||
StringBuilder stepName = new StringBuilder("\u00A7");
|
||||
List<String> stepLore;
|
||||
Consumer<InventoryClickEvent> clickEvent;
|
||||
if(stepValue == step){
|
||||
if (stepValue == step) {
|
||||
stepMat = Material.GREEN_STAINED_GLASS_PANE;
|
||||
stepName.append('a');
|
||||
stepLore = Collections.singletonList("\u00A77Value is changing by "+stepValue);
|
||||
stepLore = Collections.singletonList("\u00A77Value is changing by " + stepValue);
|
||||
clickEvent = GuiGlobalActions.stayInPlace;
|
||||
}else{
|
||||
} else {
|
||||
stepMat = Material.RED_STAINED_GLASS_PANE;
|
||||
stepName.append('c');
|
||||
stepLore = Collections.singletonList("\u00A77Click here to change the value by "+stepValue);
|
||||
stepLore = Collections.singletonList("\u00A77Click here to change the value by " + stepValue);
|
||||
clickEvent = updateStepValue(stepValue);
|
||||
}
|
||||
stepName.append("Step of: ").append(stepValue);
|
||||
|
|
@ -233,7 +237,7 @@ public class IntSettingsGui extends AbstractSettingGui{
|
|||
* @param stepValue Value to change current step to.
|
||||
* @return A consumer to update the current step of this setting.
|
||||
*/
|
||||
protected Consumer<InventoryClickEvent> updateStepValue(int stepValue){
|
||||
protected Consumer<InventoryClickEvent> updateStepValue(int stepValue) {
|
||||
return event -> {
|
||||
event.setCancelled(true);
|
||||
this.step = stepValue;
|
||||
|
|
@ -248,7 +252,7 @@ public class IntSettingsGui extends AbstractSettingGui{
|
|||
holder.config.getConfig().set(holder.configPath, now);
|
||||
|
||||
MetricsUtil.INSTANCE.notifyChange(this.holder.config, this.holder.configPath);
|
||||
if(GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE){
|
||||
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
||||
return holder.config.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||
}
|
||||
return true;
|
||||
|
|
@ -261,24 +265,25 @@ public class IntSettingsGui extends AbstractSettingGui{
|
|||
|
||||
/**
|
||||
* Create an int setting factory from setting's parameters.
|
||||
* @param title The title of the gui.
|
||||
* @param parent Parent gui to go back when completed.
|
||||
*
|
||||
* @param title The title of the gui.
|
||||
* @param parent Parent gui to go back when completed.
|
||||
* @param configPath Configuration path of this setting.
|
||||
* @param config Configuration holder of this setting.
|
||||
* @param min Minimum value of this setting.
|
||||
* @param max Maximum value of this setting.
|
||||
* @param config Configuration holder of this setting.
|
||||
* @param min Minimum value of this setting.
|
||||
* @param max Maximum value of this setting.
|
||||
* @param defaultVal Default value if not found on the config.
|
||||
* @param steps List of step the value can increment/decrement.
|
||||
* List's size should be between 1 (included) and 5 (included).
|
||||
* it is visually preferable to have an odd number of step.
|
||||
* If step only contain 1 value, no step item should be displayed.
|
||||
* @param steps List of step the value can increment/decrement.
|
||||
* List's size should be between 1 (included) and 5 (included).
|
||||
* it is visually preferable to have an odd number of step.
|
||||
* If step only contain 1 value, no step item should be displayed.
|
||||
* @return A factory for an int setting gui.
|
||||
*/
|
||||
public static IntSettingFactory intFactory(@NotNull String title, ValueUpdatableGui parent,
|
||||
String configPath, ConfigHolder config,
|
||||
int min, int max, int defaultVal, int... steps){
|
||||
int min, int max, int defaultVal, int... steps) {
|
||||
return new IntSettingFactory(
|
||||
title,parent,
|
||||
title, parent,
|
||||
configPath, config,
|
||||
min, max, defaultVal, steps);
|
||||
}
|
||||
|
|
@ -286,28 +291,34 @@ public class IntSettingsGui extends AbstractSettingGui{
|
|||
/**
|
||||
* A factory for an int setting gui that hold setting's information.
|
||||
*/
|
||||
public static class IntSettingFactory extends SettingGuiFactory{
|
||||
@NotNull String title; ValueUpdatableGui parent;
|
||||
int min; int max; int defaultVal; int[] steps;
|
||||
public static class IntSettingFactory extends SettingGuiFactory {
|
||||
@NotNull
|
||||
String title;
|
||||
ValueUpdatableGui parent;
|
||||
int min;
|
||||
int max;
|
||||
int defaultVal;
|
||||
int[] steps;
|
||||
|
||||
/**
|
||||
* Constructor for an int setting gui factory.
|
||||
* @param title The title of the gui.
|
||||
* @param parent Parent gui to go back when completed.
|
||||
*
|
||||
* @param title The title of the gui.
|
||||
* @param parent Parent gui to go back when completed.
|
||||
* @param configPath Configuration path of this setting.
|
||||
* @param config Configuration holder of this setting.
|
||||
* @param min Minimum value of this setting.
|
||||
* @param max Maximum value of this setting.
|
||||
* @param config Configuration holder of this setting.
|
||||
* @param min Minimum value of this setting.
|
||||
* @param max Maximum value of this setting.
|
||||
* @param defaultVal Default value if not found on the config.
|
||||
* @param steps List of step the value can increment/decrement.
|
||||
* List's size should be between 1 (included) and 5 (included).
|
||||
* it is visually preferable to have an odd number of step.
|
||||
* If step only contain 1 value, no step item should be displayed.
|
||||
* @param steps List of step the value can increment/decrement.
|
||||
* List's size should be between 1 (included) and 5 (included).
|
||||
* it is visually preferable to have an odd number of step.
|
||||
* If step only contain 1 value, no step item should be displayed.
|
||||
*/
|
||||
protected IntSettingFactory(
|
||||
@NotNull String title, ValueUpdatableGui parent,
|
||||
String configPath, ConfigHolder config,
|
||||
int min, int max, int defaultVal, int... steps){
|
||||
int min, int max, int defaultVal, int... steps) {
|
||||
super(configPath, config);
|
||||
this.title = title;
|
||||
this.parent = parent;
|
||||
|
|
@ -328,7 +339,7 @@ public class IntSettingsGui extends AbstractSettingGui{
|
|||
/**
|
||||
* @return The configured value for the associated setting.
|
||||
*/
|
||||
public int getConfiguredValue(){
|
||||
public int getConfiguredValue() {
|
||||
return this.config.getConfig().getInt(this.configPath, this.defaultVal);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
|||
|
||||
// Displayed item will be updated later
|
||||
|
||||
this.enchantSettingItem = new GuiItem(new ItemStack(Material.ENCHANTED_BOOK), (event)->{
|
||||
this.enchantSettingItem = new GuiItem(new ItemStack(Material.ENCHANTED_BOOK), (event) -> {
|
||||
event.setCancelled(true);
|
||||
EnchantSelectSettingGui enchantGui = new EnchantSelectSettingGui(
|
||||
"\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.getName()) + " \u00A75Enchantments",
|
||||
|
|
@ -93,7 +93,7 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
|||
enchantGui.show(event.getWhoClicked());
|
||||
}, CustomAnvil.instance);
|
||||
|
||||
this.groupSettingItem = new GuiItem(new ItemStack(Material.PAPER), (event)->{
|
||||
this.groupSettingItem = new GuiItem(new ItemStack(Material.PAPER), (event) -> {
|
||||
event.setCancelled(true);
|
||||
GroupSelectSettingGui enchantGui = new GroupSelectSettingGui(
|
||||
"\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(this.enchantConflict.getName()) + " \u00A73Groups",
|
||||
|
|
@ -103,9 +103,9 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
|||
|
||||
this.minBeforeActiveSettingFactory = IntSettingsGui.intFactory(
|
||||
"\u00A78Minimum enchantment count",
|
||||
this, this.enchantConflict.getName()+".maxEnchantmentBeforeConflict", ConfigHolder.CONFLICT_HOLDER,
|
||||
this, this.enchantConflict.getName() + ".maxEnchantmentBeforeConflict", ConfigHolder.CONFLICT_HOLDER,
|
||||
0, 255, 0, 1
|
||||
);
|
||||
);
|
||||
|
||||
this.pane.bindItem('E', this.enchantSettingItem);
|
||||
this.pane.bindItem('G', this.groupSettingItem);
|
||||
|
|
@ -116,7 +116,7 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
|||
}
|
||||
|
||||
private ConfirmActionGui createDeleteGui() {
|
||||
Supplier<Boolean> deleteSupplier = () ->{
|
||||
Supplier<Boolean> deleteSupplier = () -> {
|
||||
EnchantConflictManager manager = ConfigHolder.CONFLICT_HOLDER.getConflictManager();
|
||||
|
||||
// Remove from manager
|
||||
|
|
@ -136,17 +136,17 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
|||
|
||||
// Save
|
||||
boolean success = true;
|
||||
if(GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE){
|
||||
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
||||
success = ConfigHolder.CONFLICT_HOLDER.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||
}
|
||||
|
||||
return success;
|
||||
};
|
||||
|
||||
return new ConfirmActionGui("\u00A7cDelete \u00A7e"+CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.getName())+"\u00A7c?",
|
||||
return new ConfirmActionGui("\u00A7cDelete \u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.getName()) + "\u00A7c?",
|
||||
"\u00A77Confirm that you want to delete this conflict.",
|
||||
this, this.parent, deleteSupplier
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -155,16 +155,16 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
|||
// Parent should call updateLocal
|
||||
}
|
||||
|
||||
public void updateLocal(){
|
||||
if(!this.shouldWorld) return;
|
||||
public void updateLocal() {
|
||||
if (!this.shouldWorld) return;
|
||||
|
||||
// Prepare enchantment lore
|
||||
ArrayList<String> enchantLore = new ArrayList<>();
|
||||
enchantLore.add("\u00A77Allow you to select a list of \u00A75Enchantments \u00A77that this conflict should include");
|
||||
Set<Enchantment> enchants = getSelectedEnchantments();
|
||||
if(enchants.isEmpty()){
|
||||
if (enchants.isEmpty()) {
|
||||
enchantLore.add("\u00A77There is no included enchantment for this conflict.");
|
||||
}else{
|
||||
} else {
|
||||
enchantLore.add("\u00A77List of included enchantment for this conflict:");
|
||||
Iterator<Enchantment> enchantIterator = enchants.iterator();
|
||||
|
||||
|
|
@ -175,8 +175,8 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
|||
String formattedName = CasedStringUtil.snakeToUpperSpacedCase(enchantIterator.next().getKey().getKey());
|
||||
enchantLore.add("\u00A77- \u00A75" + formattedName);
|
||||
}
|
||||
if(greaterThanMax){
|
||||
enchantLore.add("\u00A77And "+(enchants.size()-4)+" more...");
|
||||
if (greaterThanMax) {
|
||||
enchantLore.add("\u00A77And " + (enchants.size() - 4) + " more...");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -185,9 +185,9 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
|||
ArrayList<String> groupLore = new ArrayList<>();
|
||||
groupLore.add("\u00A77Allow you to select a list of \u00A73Groups \u00A77that this conflict should include");
|
||||
Set<AbstractMaterialGroup> grouos = getSelectedGroups();
|
||||
if(grouos.isEmpty()){
|
||||
if (grouos.isEmpty()) {
|
||||
groupLore.add("\u00A77There is no excluded groups for this conflict.");
|
||||
}else{
|
||||
} else {
|
||||
groupLore.add("\u00A77List of excluded groups for this conflict:");
|
||||
Iterator<AbstractMaterialGroup> groupIterator = grouos.iterator();
|
||||
|
||||
|
|
@ -199,8 +199,8 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
|||
groupLore.add("\u00A77- \u00A73" + formattedName);
|
||||
|
||||
}
|
||||
if(greaterThanMax){
|
||||
groupLore.add("\u00A77And "+(grouos.size()-4)+" more...");
|
||||
if (greaterThanMax) {
|
||||
groupLore.add("\u00A77And " + (grouos.size() - 4) + " more...");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -231,7 +231,7 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
|||
update();
|
||||
}
|
||||
|
||||
public void cleanUnused(){
|
||||
public void cleanUnused() {
|
||||
for (HumanEntity viewer : getViewers()) {
|
||||
this.parent.show(viewer);
|
||||
}
|
||||
|
|
@ -247,9 +247,9 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
|||
|
||||
@Override
|
||||
public void show(@NotNull HumanEntity humanEntity) {
|
||||
if(this.shouldWorld){
|
||||
if (this.shouldWorld) {
|
||||
super.show(humanEntity);
|
||||
}else{
|
||||
} else {
|
||||
this.parent.show(humanEntity);
|
||||
}
|
||||
}
|
||||
|
|
@ -267,8 +267,8 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
|||
|
||||
@Override
|
||||
public boolean setSelectedEnchantments(Set<Enchantment> enchantments) {
|
||||
if(!this.shouldWorld) {
|
||||
CustomAnvil.instance.getLogger().info("Trying to save "+enchantConflict.getName()+" enchants but sub config is destroyed");
|
||||
if (!this.shouldWorld) {
|
||||
CustomAnvil.instance.getLogger().info("Trying to save " + enchantConflict.getName() + " enchants but sub config is destroyed");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -281,17 +281,17 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
|||
for (Enchantment enchantment : enchantments) {
|
||||
enchantKeys[index++] = enchantment.getKey().getKey();
|
||||
}
|
||||
ConfigHolder.CONFLICT_HOLDER.getConfig().set(enchantConflict.getName()+".enchantments", enchantKeys);
|
||||
ConfigHolder.CONFLICT_HOLDER.getConfig().set(enchantConflict.getName() + ".enchantments", enchantKeys);
|
||||
|
||||
try {
|
||||
updateGuiValues();
|
||||
}catch (Exception e){
|
||||
CustomAnvil.instance.getLogger().log(Level.WARNING, "An error occurred while updating enchants for "+this.enchantConflict.getName(), e);
|
||||
} catch (Exception e) {
|
||||
CustomAnvil.instance.getLogger().log(Level.WARNING, "An error occurred while updating enchants for " + this.enchantConflict.getName(), e);
|
||||
}
|
||||
|
||||
|
||||
// Save file configuration to disk
|
||||
if(GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE){
|
||||
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
||||
return ConfigHolder.CONFLICT_HOLDER.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||
}
|
||||
|
||||
|
|
@ -312,8 +312,8 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
|||
|
||||
@Override
|
||||
public boolean setSelectedGroups(Set<AbstractMaterialGroup> groups) {
|
||||
if(!this.shouldWorld) {
|
||||
CustomAnvil.instance.getLogger().info("Trying to save "+enchantConflict.getName()+" groups but sub config is destroyed");
|
||||
if (!this.shouldWorld) {
|
||||
CustomAnvil.instance.getLogger().info("Trying to save " + enchantConflict.getName() + " groups but sub config is destroyed");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -326,16 +326,16 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
|||
for (AbstractMaterialGroup group : groups) {
|
||||
groupsNames[index++] = group.getName();
|
||||
}
|
||||
ConfigHolder.CONFLICT_HOLDER.getConfig().set(this.enchantConflict.getName()+".notAffectedGroups", groupsNames);
|
||||
ConfigHolder.CONFLICT_HOLDER.getConfig().set(this.enchantConflict.getName() + ".notAffectedGroups", groupsNames);
|
||||
|
||||
try {
|
||||
updateGuiValues();
|
||||
}catch (Exception e){
|
||||
CustomAnvil.instance.getLogger().log(Level.WARNING, "An error occurred while updating group for "+this.enchantConflict.getName(), e);
|
||||
} catch (Exception e) {
|
||||
CustomAnvil.instance.getLogger().log(Level.WARNING, "An error occurred while updating group for " + this.enchantConflict.getName(), e);
|
||||
}
|
||||
|
||||
// Save file configuration to disk
|
||||
if(GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE){
|
||||
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
||||
return ConfigHolder.CONFLICT_HOLDER.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,21 +27,22 @@ public class GuiGlobalActions {
|
|||
/**
|
||||
* Create a consumer to create and open a new GUI.
|
||||
* Used with InventoryClickEvent as the consumer argument as it is planned to be used on click on an GuiItem.
|
||||
* @param clazz The class of the gui to open.
|
||||
* It is assumed this class contain a constructor requiring arguments of argClass in the same order as argClass array.
|
||||
*
|
||||
* @param clazz The class of the gui to open.
|
||||
* It is assumed this class contain a constructor requiring arguments of argClass in the same order as argClass array.
|
||||
* @param argClass Classes of the argument that will be passed to the constructor of the GUI class.
|
||||
* @param args Arguments for the constructor the GUI class.
|
||||
* @param args Arguments for the constructor the GUI class.
|
||||
* @return A consumer to create a new gui and open it.
|
||||
*/
|
||||
public static @NotNull Consumer<InventoryClickEvent> openGuiAction(
|
||||
@NotNull Class<? extends Gui> clazz,
|
||||
@NotNull Class<?>[] argClass,
|
||||
@NotNull Object... args){
|
||||
@NotNull Object... args) {
|
||||
return event -> {
|
||||
event.setCancelled(true);
|
||||
HumanEntity player = event.getWhoClicked();
|
||||
// Do not allow to open inventory if player do not have edit configuration permission
|
||||
if(!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||
player.closeInventory();
|
||||
player.sendMessage(NO_EDIT_PERM);
|
||||
return;
|
||||
|
|
@ -62,22 +63,24 @@ public class GuiGlobalActions {
|
|||
/**
|
||||
* Create a consumer to create and open a new GUI.
|
||||
* Used with InventoryClickEvent as the consumer argument as it is planned to be used on click on an GuiItem.
|
||||
*
|
||||
* @param clazz The class of the gui to open.
|
||||
* It is assumed this class contain a constructor with no argument.
|
||||
* @return A consumer to create a new gui and open it.
|
||||
*/
|
||||
public static @NotNull Consumer<InventoryClickEvent> openGuiAction(
|
||||
@NotNull Class<? extends Gui> clazz){
|
||||
@NotNull Class<? extends Gui> clazz) {
|
||||
return openGuiAction(clazz, new Class<?>[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a consumer to open a setting gui from a setting GUI factory.
|
||||
* Used with InventoryClickEvent as the consumer argument as it is planned to be used on click on an GuiItem.
|
||||
*
|
||||
* @param factory The setting gui factory.
|
||||
* @return A consumer to create and open a new setting GUI.
|
||||
*/
|
||||
public static @NotNull Consumer<InventoryClickEvent> openSettingGuiAction(AbstractSettingGui.SettingGuiFactory factory){
|
||||
public static @NotNull Consumer<InventoryClickEvent> openSettingGuiAction(AbstractSettingGui.SettingGuiFactory factory) {
|
||||
return event -> {
|
||||
event.setCancelled(true);
|
||||
Gui gui = factory.create();
|
||||
|
|
@ -88,6 +91,7 @@ public class GuiGlobalActions {
|
|||
/**
|
||||
* Create a consumer to open a global GUI.
|
||||
* Used with InventoryClickEvent as the consumer argument as it is planned to be used on click on an GuiItem.
|
||||
*
|
||||
* @param goal The gui to open when consumer is run.
|
||||
* @return A consumer to open a global GUI.
|
||||
*/
|
||||
|
|
@ -95,7 +99,7 @@ public class GuiGlobalActions {
|
|||
return event -> {
|
||||
HumanEntity player = event.getWhoClicked();
|
||||
// Do not allow to open inventory if player do not have edit configuration permission
|
||||
if(!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||
player.closeInventory();
|
||||
player.sendMessage(NO_EDIT_PERM);
|
||||
return;
|
||||
|
|
@ -109,8 +113,9 @@ public class GuiGlobalActions {
|
|||
* Create a consumer to update and open an updatable GUI.
|
||||
* Used with InventoryClickEvent as the consumer argument as it is planned to be used on click on an GuiItem.
|
||||
* This consumer check if the player who interacted with the item have the permission to save before saving.
|
||||
*
|
||||
* @param setting The gui that contain the modified setting.
|
||||
* @param goal The gui to update and open when consumer is run.
|
||||
* @param goal The gui to update and open when consumer is run.
|
||||
* @return A consumer to open a global GUI.
|
||||
*/
|
||||
public static @NotNull Consumer<InventoryClickEvent> saveSettingAction(
|
||||
|
|
@ -120,14 +125,14 @@ public class GuiGlobalActions {
|
|||
event.setCancelled(true);
|
||||
HumanEntity player = event.getWhoClicked();
|
||||
// Do not allow to save configuration if player do not have edit configuration permission
|
||||
if(!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||
player.closeInventory();
|
||||
player.sendMessage(NO_EDIT_PERM);
|
||||
return;
|
||||
}
|
||||
|
||||
// Save setting
|
||||
if(!setting.onSave()){
|
||||
if (!setting.onSave()) {
|
||||
player.sendMessage("\u00A7cSomething went wrong while saving the change of value.");
|
||||
}
|
||||
// Update gui for those who have it open.
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ public class GuiGlobalItems {
|
|||
|
||||
// statically create default back itemstack
|
||||
private static final ItemStack BACK_ITEM;
|
||||
|
||||
static {
|
||||
BACK_ITEM = new ItemStack(Material.BARRIER);
|
||||
ItemMeta meta = BACK_ITEM.getItemMeta();
|
||||
|
|
@ -32,32 +33,35 @@ public class GuiGlobalItems {
|
|||
|
||||
/**
|
||||
* Create a GuiItem that open the given GUi.
|
||||
*
|
||||
* @param item The item to display in the GUI.
|
||||
* @param goal The GUI to open on click.
|
||||
* @return An GuiItem that open goal on click.
|
||||
*/
|
||||
public static GuiItem goToGuiItem(@NotNull ItemStack item, @NotNull Gui goal){
|
||||
public static GuiItem goToGuiItem(@NotNull ItemStack item, @NotNull Gui goal) {
|
||||
return new GuiItem(item, GuiGlobalActions.openGuiAction(goal), CustomAnvil.instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create back button item from default back GuiItem.
|
||||
* The back item will open the goal inventory when clicked.
|
||||
*
|
||||
* @param goal The GUI to go back to.
|
||||
* @return An GuiItem that go back to goal on click.
|
||||
*/
|
||||
public static GuiItem backItem(@NotNull Gui goal){
|
||||
public static GuiItem backItem(@NotNull Gui goal) {
|
||||
return goToGuiItem(BACK_ITEM, goal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add default back item to a GUI pattern with the reserved character key <strong>B</strong>.
|
||||
* The back item will open the target inventory when clicked.
|
||||
*
|
||||
* @param target The pattern to add the back item.
|
||||
* @param goal The GUI to go back to.
|
||||
* @param goal The GUI to go back to.
|
||||
*/
|
||||
public static void addBackItem(@NotNull PatternPane target,
|
||||
@NotNull Gui goal){
|
||||
@NotNull Gui goal) {
|
||||
target.bindItem('B', backItem(goal));
|
||||
}
|
||||
|
||||
|
|
@ -66,42 +70,47 @@ public class GuiGlobalItems {
|
|||
/**
|
||||
* Get a background item with backgroundMat as the displayed material.
|
||||
* A background item is a GuiItem that do nothing when interacted with and have an empty name.
|
||||
*
|
||||
* @param backgroundMat The material to which the background item should be made of.
|
||||
* @return A background item with backgroundMat as material.
|
||||
*/
|
||||
public static GuiItem backgroundItem(Material backgroundMat){
|
||||
public static GuiItem backgroundItem(Material backgroundMat) {
|
||||
ItemStack item = new ItemStack(backgroundMat);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName("\u00A7c");
|
||||
item.setItemMeta(meta);
|
||||
return new GuiItem(item, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default background GuiItem.
|
||||
* A background item is a GuiItem that do nothing when interacted with and have an empty name.
|
||||
*
|
||||
* @return A new instance of the default background item.
|
||||
*/
|
||||
public static GuiItem backgroundItem(){
|
||||
public static GuiItem backgroundItem() {
|
||||
return backgroundItem(DEFAULT_BACKGROUND_MAT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add default background item to a GUI pattern with the reserved character key <strong>0</strong>.
|
||||
* A background item is a GuiItem that do nothing when interacted with and have an empty name.
|
||||
* @param target The pattern to add the background item.
|
||||
*
|
||||
* @param target The pattern to add the background item.
|
||||
* @param backgroundMat The material of the background item.
|
||||
*/
|
||||
public static void addBackgroundItem(@NotNull PatternPane target,
|
||||
@NotNull Material backgroundMat){
|
||||
@NotNull Material backgroundMat) {
|
||||
target.bindItem('0', backgroundItem(backgroundMat));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add default background item to a GUI pattern with the reserved character key <strong>0</strong>.
|
||||
* A background item is a GuiItem that do nothing when interacted with and have an empty name.
|
||||
*
|
||||
* @param target The pattern to add the background item.
|
||||
*/
|
||||
public static void addBackgroundItem(@NotNull PatternPane target){
|
||||
public static void addBackgroundItem(@NotNull PatternPane target) {
|
||||
addBackgroundItem(target, DEFAULT_BACKGROUND_MAT);
|
||||
}
|
||||
|
||||
|
|
@ -112,13 +121,14 @@ public class GuiGlobalItems {
|
|||
* Create a new save setting GuiItem.
|
||||
* A save setting item is a GuiItem that save a changed setting when clicked.
|
||||
* This item also check if the player who interacted with the item have the permission to save before saving.
|
||||
*
|
||||
* @param setting The setting to change.
|
||||
* @param goal Parent GUI of this setting GUI. as setting will be change the display of goal GUI will be updated.
|
||||
* @param goal Parent GUI of this setting GUI. as setting will be change the display of goal GUI will be updated.
|
||||
* @return A save setting item.
|
||||
*/
|
||||
public static GuiItem saveItem(
|
||||
@NotNull AbstractSettingGui setting,
|
||||
@NotNull ValueUpdatableGui goal){
|
||||
@NotNull ValueUpdatableGui goal) {
|
||||
|
||||
ItemStack item = new ItemStack(DEFAULT_SAVE_ITEM);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
|
@ -131,34 +141,37 @@ public class GuiGlobalItems {
|
|||
|
||||
// Create static non change item
|
||||
private static final GuiItem NO_CHANGE_ITEM;
|
||||
|
||||
static {
|
||||
ItemStack item = new ItemStack(DEFAULT_NO_CHANGE_ITEM);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName("\u00A77No change. can't save.");
|
||||
item.setItemMeta(meta);
|
||||
NO_CHANGE_ITEM = new GuiItem(item,GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
||||
NO_CHANGE_ITEM = new GuiItem(item, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the global "no change" GuiItem.
|
||||
* The no change item do nothing when interacted, only the title is change to show there is no change.
|
||||
*
|
||||
* @return The global "no change" item.
|
||||
*/
|
||||
public static GuiItem noChangeItem(){
|
||||
public static GuiItem noChangeItem() {
|
||||
return NO_CHANGE_ITEM;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new "create and go to the setting GUI" GuiItem.
|
||||
* This item will create and open a setting GUI from the factory.
|
||||
* @param item The item that will be displayed.
|
||||
*
|
||||
* @param item The item that will be displayed.
|
||||
* @param factory The setting's GUI factory.
|
||||
* @return A formatted GuiItem that will create and open a GUI for the setting.
|
||||
*/
|
||||
public static GuiItem openSettingGuiItem(
|
||||
@NotNull ItemStack item,
|
||||
@NotNull AbstractSettingGui.SettingGuiFactory factory
|
||||
){
|
||||
) {
|
||||
return new GuiItem(item, GuiGlobalActions.openSettingGuiAction(factory), CustomAnvil.instance);
|
||||
}
|
||||
|
||||
|
|
@ -169,23 +182,24 @@ public class GuiGlobalItems {
|
|||
* Create a new Boolean setting GuiItem.
|
||||
* This item will create and open a boolean setting GUI from the factory.
|
||||
* The item will have its value written in the lore part of the item.
|
||||
*
|
||||
* @param factory The setting's GUI factory.
|
||||
* @param name Name of the item.
|
||||
* @param name Name of the item.
|
||||
* @return A formatted GuiItem that will create and open a GUI for the boolean setting.
|
||||
*/
|
||||
public static GuiItem boolSettingGuiItem(
|
||||
@NotNull BoolSettingsGui.BoolSettingFactory factory,
|
||||
@NotNull String name
|
||||
){
|
||||
) {
|
||||
// Get item properties
|
||||
boolean value = factory.getConfiguredValue();
|
||||
|
||||
Material itemMat;
|
||||
StringBuilder itemName = new StringBuilder("\u00A7");
|
||||
if(value){
|
||||
if (value) {
|
||||
itemMat = Material.GREEN_TERRACOTTA;
|
||||
itemName.append("a");
|
||||
}else{
|
||||
} else {
|
||||
itemMat = Material.RED_TERRACOTTA;
|
||||
itemName.append("c");
|
||||
}
|
||||
|
|
@ -199,12 +213,13 @@ public class GuiGlobalItems {
|
|||
* This item will create and open a boolean setting GUI from the factory.
|
||||
* The item will have its value written in the lore part of the item.
|
||||
* 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 boolean setting.
|
||||
*/
|
||||
public static GuiItem boolSettingGuiItem(
|
||||
@NotNull BoolSettingsGui.BoolSettingFactory factory
|
||||
){
|
||||
) {
|
||||
String configPath = getConfigNameFromPath(factory.getConfigPath());
|
||||
return boolSettingGuiItem(factory, CasedStringUtil.snakeToUpperSpacedCase(configPath));
|
||||
}
|
||||
|
|
@ -213,16 +228,17 @@ public class GuiGlobalItems {
|
|||
* Create a new int setting GuiItem.
|
||||
* This item will create and open an int setting GUI from the factory.
|
||||
* The item will have its value written in the lore part of the item.
|
||||
*
|
||||
* @param factory The setting's GUI factory.
|
||||
* @param itemMat Displayed material of the item.
|
||||
* @param name Name of the item.
|
||||
* @param name Name of the item.
|
||||
* @return A formatted GuiItem that will create and open a GUI for the int setting.
|
||||
*/
|
||||
public static GuiItem intSettingGuiItem(
|
||||
@NotNull IntSettingsGui.IntSettingFactory factory,
|
||||
@NotNull Material itemMat,
|
||||
@NotNull String name
|
||||
){
|
||||
) {
|
||||
// Get item properties
|
||||
int value = factory.getConfiguredValue();
|
||||
StringBuilder itemName = new StringBuilder("\u00A7a").append(name);
|
||||
|
|
@ -235,6 +251,7 @@ public class GuiGlobalItems {
|
|||
* This item will create and open an int setting GUI from the factory.
|
||||
* The item will have its value written in the lore part of the item.
|
||||
* Item's name will be the factory set title.
|
||||
*
|
||||
* @param factory The setting's GUI factory.
|
||||
* @param itemMat Displayed material of the item.
|
||||
* @return A formatted GuiItem that will create and open a GUI for the int setting.
|
||||
|
|
@ -242,18 +259,19 @@ public class GuiGlobalItems {
|
|||
public static GuiItem intSettingGuiItem(
|
||||
@NotNull IntSettingsGui.IntSettingFactory factory,
|
||||
@NotNull Material itemMat
|
||||
){
|
||||
) {
|
||||
String configPath = getConfigNameFromPath(factory.getConfigPath());
|
||||
return intSettingGuiItem(factory, itemMat, CasedStringUtil.detectToUpperSpacedCase(configPath));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an arbitrary GuiItem from a unique setting and item's property.
|
||||
* @param factory The setting's GUI factory.
|
||||
* @param itemMat Displayed material of the item.
|
||||
*
|
||||
* @param factory The setting's GUI factory.
|
||||
* @param itemMat Displayed material of the item.
|
||||
* @param itemName Name of the item.
|
||||
* @param value Value of the setting when the item is created.
|
||||
* Will not update automatically, if the setting's value change, the item need to be created again.
|
||||
* @param value Value of the setting when the item is created.
|
||||
* Will not update automatically, if the setting's value change, the item need to be created again.
|
||||
* @return A formatted GuiItem that will create and open a GUI for the setting.
|
||||
*/
|
||||
private static GuiItem createGuiItemFromProperties(
|
||||
|
|
@ -261,13 +279,13 @@ public class GuiGlobalItems {
|
|||
@NotNull Material itemMat,
|
||||
@NotNull StringBuilder itemName,
|
||||
@NotNull Object value
|
||||
){
|
||||
) {
|
||||
// Create & initialise item
|
||||
ItemStack item = new ItemStack(itemMat);
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
|
||||
itemMeta.setDisplayName(itemName.toString());
|
||||
itemMeta.setLore(Collections.singletonList(SETTING_ITEM_LORE_PREFIX+value));
|
||||
itemMeta.setLore(Collections.singletonList(SETTING_ITEM_LORE_PREFIX + value));
|
||||
|
||||
item.setItemMeta(itemMeta);
|
||||
// Create GuiItem
|
||||
|
|
@ -277,14 +295,15 @@ public class GuiGlobalItems {
|
|||
/**
|
||||
* Get the setting name from the setting path.
|
||||
* For example: "gui.command.name" will return "name".
|
||||
*
|
||||
* @param path The setting's path.
|
||||
* @return The setting's name.
|
||||
*/
|
||||
public static String getConfigNameFromPath(String path){
|
||||
public static String getConfigNameFromPath(String path) {
|
||||
// Get index of first dot
|
||||
int indexOfDot = path.indexOf(".");
|
||||
// when indexOfDot == -1 (not fond), it is implied that indexOfDot+1 = 0. substring will keep the full path as expected
|
||||
return path.substring(indexOfDot+1);
|
||||
return path.substring(indexOfDot + 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ public class GuiSharedConstant {
|
|||
public static final boolean TEMPORARY_DO_BACKUP_EVERY_SAVE = true;
|
||||
|
||||
public static final PatternPane BACK_TO_MAIN_MENU_BIG_LIST_DISPLAY_BACKGROUND_PANE;
|
||||
|
||||
static {
|
||||
Pattern pattern = new Pattern(
|
||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||
|
|
|
|||
|
|
@ -9,17 +9,18 @@ public class CasedStringUtil {
|
|||
* Transform a snake cased string to an upper-cased spaced string.
|
||||
* <p>
|
||||
* for example: if we use "hello_world" as an input this function will return "Hello World".
|
||||
*
|
||||
* @param snake_cased_string The input string.
|
||||
* This argument NEED to be a snake cased string, or it will not work
|
||||
* This argument NEED to be a snake cased string, or it will not work
|
||||
* @return The input as an upper-cased string with space separator.
|
||||
*/
|
||||
public static String snakeToUpperSpacedCase(String snake_cased_string){
|
||||
if(snake_cased_string.contentEquals("")) return "";
|
||||
public static String snakeToUpperSpacedCase(String snake_cased_string) {
|
||||
if (snake_cased_string.contentEquals("")) return "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
for (String word : snake_cased_string.split("_")) {
|
||||
result.append(" ");
|
||||
if(word.isEmpty()) continue;
|
||||
if (word.isEmpty()) continue;
|
||||
char firstChar = word.charAt(0);
|
||||
|
||||
result.append(Character.toUpperCase(firstChar));
|
||||
|
|
@ -28,15 +29,15 @@ public class CasedStringUtil {
|
|||
return result.substring(1);
|
||||
}
|
||||
|
||||
public static String camelCaseToUpperSpaceCase(String camelCasedString){
|
||||
if(camelCasedString.isEmpty()) return camelCasedString;
|
||||
public static String camelCaseToUpperSpaceCase(String camelCasedString) {
|
||||
if (camelCasedString.isEmpty()) return camelCasedString;
|
||||
StringBuilder stb = new StringBuilder();
|
||||
|
||||
char[] chars = camelCasedString.toCharArray();
|
||||
stb.append(chars[0]);
|
||||
for (int i = 1; i < chars.length; i++) {
|
||||
char chr = chars[i];
|
||||
if(Character.isUpperCase(chr)){
|
||||
if (Character.isUpperCase(chr)) {
|
||||
stb.append(" ");
|
||||
}
|
||||
stb.append(chr);
|
||||
|
|
@ -45,11 +46,11 @@ public class CasedStringUtil {
|
|||
return stb.toString();
|
||||
}
|
||||
|
||||
public static String detectToUpperSpacedCase(String toDetect){
|
||||
public static String detectToUpperSpacedCase(String toDetect) {
|
||||
//not advanced detection
|
||||
if(toDetect.contains("_")){
|
||||
if (toDetect.contains("_")) {
|
||||
return snakeToUpperSpacedCase(toDetect);
|
||||
}else{
|
||||
} else {
|
||||
return camelCaseToUpperSpaceCase(toDetect);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue