Refactored display options
This commit is contained in:
@@ -2,13 +2,11 @@ package com.willfp.ecoenchants.display;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.display.sorting.*;
|
||||
import com.willfp.ecoenchants.display.options.DisplayOptions;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
|
||||
import com.willfp.ecoenchants.util.NumberUtils;
|
||||
import com.willfp.ecoenchants.util.StringUtils;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
@@ -240,81 +238,4 @@ public class EnchantDisplay {
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public static class DisplayOptions {
|
||||
private String descriptionColor;
|
||||
|
||||
private int numbersThreshold;
|
||||
private boolean useNumerals;
|
||||
|
||||
private int describeThreshold;
|
||||
private boolean useDescribe;
|
||||
|
||||
private int shrinkThreshold;
|
||||
private int shrinkPerLine;
|
||||
private boolean useShrink;
|
||||
|
||||
private EnchantmentSorter sorter;
|
||||
|
||||
private DisplayOptions() {
|
||||
update();
|
||||
}
|
||||
|
||||
public String getDescriptionColor() {
|
||||
return descriptionColor;
|
||||
}
|
||||
|
||||
public int getNumbersThreshold() {
|
||||
return numbersThreshold;
|
||||
}
|
||||
|
||||
public boolean isUseNumerals() {
|
||||
return useNumerals;
|
||||
}
|
||||
|
||||
public int getDescribeThreshold() {
|
||||
return describeThreshold;
|
||||
}
|
||||
|
||||
public boolean isUseDescribe() {
|
||||
return useDescribe;
|
||||
}
|
||||
|
||||
public int getShrinkThreshold() {
|
||||
return shrinkThreshold;
|
||||
}
|
||||
|
||||
public int getShrinkPerLine() {
|
||||
return shrinkPerLine;
|
||||
}
|
||||
|
||||
public boolean isUseShrink() {
|
||||
return useShrink;
|
||||
}
|
||||
|
||||
public EnchantmentSorter getSorter() {
|
||||
return sorter;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
descriptionColor = StringUtils.translate(ConfigManager.getLang().getString("description-color"));
|
||||
|
||||
useNumerals = ConfigManager.getConfig().getBool("lore.use-numerals");
|
||||
numbersThreshold = ConfigManager.getConfig().getInt("lore.use-numbers-above-threshold");
|
||||
|
||||
describeThreshold = ConfigManager.getConfig().getInt("lore.describe.before-lines");
|
||||
useDescribe = ConfigManager.getConfig().getBool("lore.describe.enabled");
|
||||
|
||||
shrinkThreshold = ConfigManager.getConfig().getInt("lore.shrink.after-lines");
|
||||
useShrink = ConfigManager.getConfig().getBool("lore.shrink.enabled");
|
||||
shrinkPerLine = ConfigManager.getConfig().getInt("lore.shrink.maximum-per-line");
|
||||
|
||||
boolean byType = ConfigManager.getConfig().getBool("lore.sort-by-type");
|
||||
boolean byLength = ConfigManager.getConfig().getBool("lore.sort-by-length");
|
||||
if(byType && byLength) sorter = new TypeLengthSorter();
|
||||
if(byType && !byLength) sorter = new TypeAlphabeticSorter();
|
||||
if(!byType && byLength) sorter = new LengthSorter();
|
||||
if(!byType && !byLength) sorter = new AlphabeticSorter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.ThresholdedOption;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.ToggleableOption;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.UpdateableOption;
|
||||
import com.willfp.ecoenchants.util.StringUtils;
|
||||
|
||||
public class DescriptionOptions implements ThresholdedOption, ToggleableOption, UpdateableOption {
|
||||
private int threshold;
|
||||
private boolean enabled;
|
||||
private String color;
|
||||
|
||||
@Override
|
||||
public int getThreshold() {
|
||||
return threshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
threshold = ConfigManager.getConfig().getInt("lore.describe.before-lines");
|
||||
enabled = ConfigManager.getConfig().getBool("lore.describe.enabled");
|
||||
color = StringUtils.translate(ConfigManager.getLang().getString("description-color"));
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.display.options.sorting.AlphabeticSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.LengthSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.TypeAlphabeticSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.TypeLengthSorter;
|
||||
|
||||
public class DisplayOptions {
|
||||
private EnchantmentSorter sorter;
|
||||
private final DescriptionOptions descriptionOptions = new DescriptionOptions();
|
||||
private final NumbersOptions numbersOptions = new NumbersOptions();
|
||||
private final ShrinkOptions shrinkOptions = new ShrinkOptions();
|
||||
|
||||
public DisplayOptions() {
|
||||
update();
|
||||
}
|
||||
|
||||
public String getDescriptionColor() {
|
||||
return descriptionOptions.getColor();
|
||||
}
|
||||
|
||||
public int getNumbersThreshold() {
|
||||
return numbersOptions.getThreshold();
|
||||
}
|
||||
|
||||
public boolean isUseNumerals() {
|
||||
return numbersOptions.useNumerals();
|
||||
}
|
||||
|
||||
public int getDescribeThreshold() {
|
||||
return descriptionOptions.getThreshold();
|
||||
}
|
||||
|
||||
public boolean isUseDescribe() {
|
||||
return descriptionOptions.isEnabled();
|
||||
}
|
||||
|
||||
public int getShrinkThreshold() {
|
||||
return shrinkOptions.getThreshold();
|
||||
}
|
||||
|
||||
public int getShrinkPerLine() {
|
||||
return shrinkOptions.getShrinkPerLine();
|
||||
}
|
||||
|
||||
public boolean isUseShrink() {
|
||||
return shrinkOptions.isEnabled();
|
||||
}
|
||||
|
||||
public EnchantmentSorter getSorter() {
|
||||
return sorter;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
descriptionOptions.update();
|
||||
numbersOptions.update();
|
||||
shrinkOptions.update();
|
||||
|
||||
boolean byType = ConfigManager.getConfig().getBool("lore.sort-by-type");
|
||||
boolean byLength = ConfigManager.getConfig().getBool("lore.sort-by-length");
|
||||
if (byType && byLength) sorter = new TypeLengthSorter();
|
||||
if (byType && !byLength) sorter = new TypeAlphabeticSorter();
|
||||
if (!byType && byLength) sorter = new LengthSorter();
|
||||
if (!byType && !byLength) sorter = new AlphabeticSorter();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.ThresholdedOption;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.UpdateableOption;
|
||||
|
||||
public class NumbersOptions implements ThresholdedOption, UpdateableOption {
|
||||
private boolean useNumerals;
|
||||
private int threshold;
|
||||
|
||||
@Override
|
||||
public int getThreshold() {
|
||||
return threshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
useNumerals = ConfigManager.getConfig().getBool("lore.use-numerals");
|
||||
threshold = ConfigManager.getConfig().getInt("lore.use-numbers-above-threshold");
|
||||
}
|
||||
|
||||
public boolean useNumerals() {
|
||||
return useNumerals;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.ThresholdedOption;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.ToggleableOption;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.UpdateableOption;
|
||||
|
||||
public class ShrinkOptions implements ThresholdedOption, ToggleableOption, UpdateableOption {
|
||||
private int threshold;
|
||||
private boolean enabled;
|
||||
private int shrinkPerLine;
|
||||
|
||||
@Override
|
||||
public int getThreshold() {
|
||||
return threshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
threshold = ConfigManager.getConfig().getInt("lore.shrink.after-lines");
|
||||
enabled = ConfigManager.getConfig().getBool("lore.shrink.enabled");
|
||||
shrinkPerLine = ConfigManager.getConfig().getInt("lore.shrink.maximum-per-line");
|
||||
}
|
||||
|
||||
public int getShrinkPerLine() {
|
||||
return shrinkPerLine;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.willfp.ecoenchants.display.options.interfaces;
|
||||
|
||||
public interface ThresholdedOption {
|
||||
int getThreshold();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.willfp.ecoenchants.display.options.interfaces;
|
||||
|
||||
public interface ToggleableOption {
|
||||
boolean isEnabled();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.willfp.ecoenchants.display.options.interfaces;
|
||||
|
||||
public interface UpdateableOption {
|
||||
void update();
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.ecoenchants.display.sorting;
|
||||
package com.willfp.ecoenchants.display.options.sorting;
|
||||
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.ecoenchants.display.sorting;
|
||||
package com.willfp.ecoenchants.display.options.sorting;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.ecoenchants.display.sorting;
|
||||
package com.willfp.ecoenchants.display.options.sorting;
|
||||
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.ecoenchants.display.sorting;
|
||||
package com.willfp.ecoenchants.display.options.sorting;
|
||||
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.ecoenchants.display.sorting;
|
||||
package com.willfp.ecoenchants.display.options.sorting;
|
||||
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
Reference in New Issue
Block a user