mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
new work penalty
also removed old penalty config gui
This commit is contained in:
parent
ea19ffc4a1
commit
b6d2c63b86
7 changed files with 66 additions and 128 deletions
|
|
@ -1,114 +1,35 @@
|
|||
package xyz.alexcrea.cuanvil.config;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.EnumSettingGui;
|
||||
import xyz.alexcrea.cuanvil.util.AnvilUseType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.EnumMap;
|
||||
|
||||
public enum WorkPenaltyType implements EnumSettingGui.ConfigurableEnum {
|
||||
DEFAULT("default", true, true, "§aDefault", Material.LIME_TERRACOTTA),
|
||||
ADDITIVE("add_only", false, true, "§eAdd Only", Material.YELLOW_TERRACOTTA),
|
||||
INCREASE("increase_only", true, false, "§eIncrease Only", Material.YELLOW_TERRACOTTA),
|
||||
DISABLED("disabled", false, false, "§cDisabled", Material.RED_TERRACOTTA),
|
||||
;
|
||||
public class WorkPenaltyType {
|
||||
|
||||
private final String name;
|
||||
private final boolean penaltyIncrease;
|
||||
private final boolean penaltyAdditive;
|
||||
public record WorkPenaltyPart(
|
||||
boolean penaltyIncrease,
|
||||
boolean penaltyAdditive) {
|
||||
|
||||
private final String configName;
|
||||
private final Material configMaterial;
|
||||
|
||||
WorkPenaltyType(String name, boolean penaltyIncrease, boolean penaltyAdditive, String configName, Material configMaterial) {
|
||||
this.name = name;
|
||||
this.penaltyIncrease = penaltyIncrease;
|
||||
this.penaltyAdditive = penaltyAdditive;
|
||||
this.configName = configName;
|
||||
this.configMaterial = configMaterial;
|
||||
public static WorkPenaltyPart ONLY_TRUE_PART = new WorkPenaltyPart(true, true);
|
||||
}
|
||||
|
||||
public boolean isPenaltyIncreasing() {
|
||||
return penaltyIncrease;
|
||||
private final EnumMap<AnvilUseType, WorkPenaltyPart> partMap;
|
||||
|
||||
public WorkPenaltyType(@Nullable EnumMap<AnvilUseType, WorkPenaltyPart> partMap) {
|
||||
this.partMap = new EnumMap<>(partMap != null ? partMap : new EnumMap<>(AnvilUseType.class));
|
||||
}
|
||||
|
||||
public boolean isPenaltyAdditive() {
|
||||
return penaltyAdditive;
|
||||
public WorkPenaltyPart getPenaltyInfo(AnvilUseType type) {
|
||||
return partMap.getOrDefault(type, WorkPenaltyPart.ONLY_TRUE_PART);
|
||||
}
|
||||
|
||||
private boolean doRepresentThisType(String toTest){
|
||||
return name.equalsIgnoreCase(toTest);
|
||||
public boolean isPenaltyIncreasing(AnvilUseType type) {
|
||||
return partMap.getOrDefault(type, WorkPenaltyPart.ONLY_TRUE_PART).penaltyIncrease;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static WorkPenaltyType fromString(@Nullable String toTest){
|
||||
if(toTest == null) return DEFAULT;
|
||||
|
||||
// Test if it matches any of values
|
||||
for (WorkPenaltyType value : values()) {
|
||||
if(value.doRepresentThisType(toTest)){
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
// Use default if not found
|
||||
return DEFAULT;
|
||||
public boolean isPenaltyAdditive(AnvilUseType type) {
|
||||
return partMap.getOrDefault(type, WorkPenaltyPart.ONLY_TRUE_PART).penaltyAdditive;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static WorkPenaltyType next(@NotNull WorkPenaltyType now){
|
||||
return switch (now){
|
||||
case DEFAULT -> ADDITIVE;
|
||||
case ADDITIVE -> INCREASE;
|
||||
case INCREASE -> DISABLED;
|
||||
case DISABLED -> DEFAULT;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack configurationGuiItem() {
|
||||
ItemStack displayedItem = new ItemStack(this.configMaterial);
|
||||
ItemMeta valueMeta = displayedItem.getItemMeta();
|
||||
assert valueMeta != null;
|
||||
|
||||
valueMeta.setDisplayName(this.configName);
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
lore.add(configDisplayForAdd());
|
||||
lore.add(configDisplayForIncrease());
|
||||
lore.add("");
|
||||
|
||||
lore.add(AbstractSettingGui.CLICK_LORE);
|
||||
valueMeta.setLore(lore);
|
||||
|
||||
displayedItem.setItemMeta(valueMeta);
|
||||
|
||||
return displayedItem;
|
||||
}
|
||||
|
||||
public String configDisplayForAdd(){
|
||||
return ("§7Add penalty: " + (penaltyAdditive ? "§aYes" : "§cNo"));
|
||||
}
|
||||
|
||||
public String configDisplayForIncrease(){
|
||||
return ("§7Increase penalty: " + (penaltyIncrease ? "§aYes" : "§cNo"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String configName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String configurationGuiName() {
|
||||
return this.configName;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,12 +14,10 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.config.WorkPenaltyType;
|
||||
import xyz.alexcrea.cuanvil.dependency.packet.PacketManager;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.EnumSettingGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
|
|
@ -28,7 +26,6 @@ import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Global config to edit basic basic settings.
|
||||
|
|
@ -89,7 +86,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui {
|
|||
private IntSettingsGui.IntSettingFactory itemRenameCost; // r character
|
||||
private IntSettingsGui.IntSettingFactory sacrificeIllegalEnchantCost; // S character
|
||||
|
||||
private EnumSettingGui.EnumSettingFactory<WorkPenaltyType> workPenaltyType; // W character
|
||||
//TODO private EnumSettingGui.EnumSettingFactory<WorkPenaltyType> workPenaltyType; // W character
|
||||
|
||||
private BoolSettingsGui.BoolSettingFactory allowColorCode; // c character
|
||||
private BoolSettingsGui.BoolSettingFactory allowHexColor; // h character
|
||||
|
|
@ -215,7 +212,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui {
|
|||
// Work Penalty
|
||||
// -------------
|
||||
|
||||
this.workPenaltyType = new EnumSettingGui.EnumSettingFactory<>("§8Work Penalty Type", this,
|
||||
/*TODO this.workPenaltyType = new EnumSettingGui.EnumSettingFactory<>("§8Work Penalty Type", this,
|
||||
ConfigOptions.WORK_PENALTY_TYPE, ConfigHolder.DEFAULT_CONFIG
|
||||
) {
|
||||
@NotNull
|
||||
|
|
@ -237,8 +234,8 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui {
|
|||
"§7Work penalty increase the price for every anvil use.",
|
||||
"§7This config allow you to choose the comportment of work penalty.",
|
||||
"",
|
||||
value.configDisplayForAdd(),
|
||||
value.configDisplayForIncrease()
|
||||
"IN PROGRESS",
|
||||
"IN PROGRESS"
|
||||
|
||||
);
|
||||
}
|
||||
|
|
@ -249,7 +246,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui {
|
|||
return WorkPenaltyType.next(now);
|
||||
}
|
||||
|
||||
};
|
||||
};*/
|
||||
|
||||
// -------------
|
||||
// Color config
|
||||
|
|
@ -377,8 +374,8 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui {
|
|||
pane.bindItem('S', illegalCostItem);
|
||||
|
||||
// work penalty type
|
||||
GuiItem workPenaltyType = this.workPenaltyType.getItem(Material.DAMAGED_ANVIL, "§aWork Penalty Type");
|
||||
pane.bindItem('W', workPenaltyType);
|
||||
//TODO GuiItem workPenaltyType = this.workPenaltyType.getItem(Material.DAMAGED_ANVIL, "§aWork Penalty Type");
|
||||
//TODO pane.bindItem('W', workPenaltyType);
|
||||
|
||||
// allow color code
|
||||
GuiItem allowColorCodeItem = this.allowColorCode.getItem();
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import io.delilaheve.util.ConfigOptions;
|
|||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.config.WorkPenaltyType;
|
||||
|
||||
public class PluginSetDefault {
|
||||
|
||||
|
|
@ -26,7 +25,6 @@ public class PluginSetDefault {
|
|||
nbSet+= trySetDefault(config, ConfigOptions.ALLOW_HEXADECIMAL_COLOR, ConfigOptions.DEFAULT_ALLOW_HEXADECIMAL_COLOR);
|
||||
nbSet+= trySetDefault(config, ConfigOptions.PERMISSION_NEEDED_FOR_COLOR, ConfigOptions.DEFAULT_PERMISSION_NEEDED_FOR_COLOR);
|
||||
nbSet+= trySetDefault(config, ConfigOptions.USE_OF_COLOR_COST, ConfigOptions.DEFAULT_USE_OF_COLOR_COST);
|
||||
nbSet+= trySetDefault(config, ConfigOptions.WORK_PENALTY_TYPE, WorkPenaltyType.DEFAULT.configName());
|
||||
nbSet+= trySetDefault(config, ConfigOptions.DEFAULT_LIMIT_PATH, ConfigOptions.DEFAULT_ENCHANT_LIMIT);
|
||||
|
||||
if(nbSet > 0){
|
||||
|
|
|
|||
|
|
@ -4,7 +4,10 @@ import io.delilaheve.CustomAnvil
|
|||
import io.delilaheve.util.EnchantmentUtil.enchantmentName
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
import xyz.alexcrea.cuanvil.config.WorkPenaltyType
|
||||
import xyz.alexcrea.cuanvil.config.WorkPenaltyType.WorkPenaltyPart
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||
import xyz.alexcrea.cuanvil.util.AnvilUseType
|
||||
import java.util.EnumMap
|
||||
|
||||
/**
|
||||
* Config option accessors
|
||||
|
|
@ -34,7 +37,8 @@ object ConfigOptions {
|
|||
const val PERMISSION_NEEDED_FOR_COLOR = "permission_needed_for_color"
|
||||
const val USE_OF_COLOR_COST = "use_of_color_cost"
|
||||
|
||||
const val WORK_PENALTY_TYPE = "work_penalty_type"
|
||||
//const val WORK_PENALTY_TYPE = "work_penalty_type" TODO move old value to config migration
|
||||
const val WORK_PENALTY = "work_penalty"
|
||||
|
||||
const val DEFAULT_LIMIT_PATH = "default_limit"
|
||||
|
||||
|
|
@ -113,7 +117,7 @@ object ConfigOptions {
|
|||
private const val DEFAULT_ENCHANT_VALUE = 0
|
||||
|
||||
// Default max before merge disabled (negative mean enabled)
|
||||
const val DEFAULT_MAX_BEFORE_MERGE_DISABLED = -1;
|
||||
const val DEFAULT_MAX_BEFORE_MERGE_DISABLED = -1
|
||||
|
||||
// -------------
|
||||
// Get methods
|
||||
|
|
@ -257,16 +261,35 @@ object ConfigOptions {
|
|||
}
|
||||
|
||||
/**
|
||||
* How many xp should use of color should cost
|
||||
* How work penalties should work
|
||||
*/
|
||||
val workPenaltyType: WorkPenaltyType
|
||||
get() {
|
||||
return WorkPenaltyType.fromString(
|
||||
ConfigHolder.DEFAULT_CONFIG
|
||||
.config
|
||||
.getString(WORK_PENALTY_TYPE));
|
||||
val penaltyMap = EnumMap<AnvilUseType, WorkPenaltyPart>(AnvilUseType::class.java)
|
||||
|
||||
for (type in AnvilUseType.entries) {
|
||||
penaltyMap[type] = workPenaltyPart(type)
|
||||
}
|
||||
|
||||
return WorkPenaltyType(penaltyMap)
|
||||
}
|
||||
|
||||
/**
|
||||
* How work penalty should work
|
||||
*/
|
||||
fun workPenaltyPart(type: AnvilUseType): WorkPenaltyPart {
|
||||
val config = ConfigHolder.CONFLICT_HOLDER.config
|
||||
val path = WORK_PENALTY + "." + type.typeName
|
||||
|
||||
// Find values
|
||||
val section = config.getConfigurationSection(path) ?: return WorkPenaltyPart.ONLY_TRUE_PART
|
||||
|
||||
val penaltyIncrease = section.getBoolean("penalty_increase", true)
|
||||
val penaltyAdditive = section.getBoolean("penalty_additive", true)
|
||||
|
||||
return WorkPenaltyPart(penaltyIncrease, penaltyAdditive)
|
||||
}
|
||||
|
||||
/**
|
||||
* Default enchantment limit
|
||||
*/
|
||||
|
|
@ -303,11 +326,11 @@ object ConfigOptions {
|
|||
fun enchantLimit(enchantment: CAEnchantment): Int {
|
||||
// Test namespace
|
||||
var limit = enchantLimit(enchantment.key.toString())
|
||||
if(limit != null) return limit;
|
||||
if(limit != null) return limit
|
||||
|
||||
// Test legacy (name only)
|
||||
limit = enchantLimit(enchantment.enchantmentName)
|
||||
if(limit != null) return limit;
|
||||
if(limit != null) return limit
|
||||
|
||||
// get default (and test old legacy if present)
|
||||
return getDefaultLevel(enchantment.enchantmentName)
|
||||
|
|
@ -348,11 +371,11 @@ object ConfigOptions {
|
|||
): Int {
|
||||
// Test namespace
|
||||
var limit = enchantmentValue(enchantment.key.toString(), isFromBook)
|
||||
if(limit != null) return limit;
|
||||
if(limit != null) return limit
|
||||
|
||||
// Test legacy (name only)
|
||||
limit = enchantmentValue(enchantment.enchantmentName, isFromBook)
|
||||
if(limit != null) return limit;
|
||||
if(limit != null) return limit
|
||||
|
||||
// get default (and test old legacy if present)
|
||||
return getDefaultValue(enchantment, isFromBook)
|
||||
|
|
|
|||
|
|
@ -23,8 +23,6 @@ import xyz.alexcrea.cuanvil.util.AnvilUseType
|
|||
import xyz.alexcrea.cuanvil.util.AnvilXpUtil
|
||||
import xyz.alexcrea.cuanvil.util.CustomRecipeUtil
|
||||
import xyz.alexcrea.cuanvil.util.UnitRepairUtil.getRepair
|
||||
import java.util.logging.Level
|
||||
|
||||
/**
|
||||
* Listener for anvil events
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
package xyz.alexcrea.cuanvil.util
|
||||
|
||||
enum class AnvilUseType {
|
||||
enum class AnvilUseType(val typeName: String) {
|
||||
|
||||
RENAME_ONLY,
|
||||
MERGE,
|
||||
UNIT_REPAIR
|
||||
RENAME_ONLY("rename_only"),
|
||||
MERGE("merge"),
|
||||
UNIT_REPAIR("unit_repair"),
|
||||
;
|
||||
|
||||
}
|
||||
|
|
@ -77,7 +77,7 @@ object AnvilXpUtil {
|
|||
fun calculatePenalty(left: ItemStack, right: ItemStack?, result: ItemStack, useType: AnvilUseType): Int {
|
||||
// Extracted From https://minecraft.fandom.com/wiki/Anvil_mechanics#Enchantment_equation
|
||||
// Calculate work penalty
|
||||
val penaltyType = ConfigOptions.workPenaltyType
|
||||
val penaltyType = ConfigOptions.workPenaltyPart(useType)
|
||||
val leftPenalty = (left.itemMeta as? Repairable)?.repairCost ?: 0
|
||||
|
||||
val rightPenalty =
|
||||
|
|
@ -86,7 +86,7 @@ object AnvilXpUtil {
|
|||
|
||||
|
||||
// Increase penalty on fusing or unit repair
|
||||
if(penaltyType.isPenaltyIncreasing && (right != null || AnvilUseType.UNIT_REPAIR == useType)){
|
||||
if(penaltyType.penaltyIncrease && (right != null || AnvilUseType.UNIT_REPAIR == useType)){
|
||||
result.itemMeta?.let {
|
||||
(it as? Repairable)?.repairCost = leftPenalty * 2 + 1
|
||||
result.itemMeta = it
|
||||
|
|
@ -101,7 +101,7 @@ object AnvilXpUtil {
|
|||
"result penalty: ${(result.itemMeta as? Repairable)?.repairCost ?: "none"}"
|
||||
)
|
||||
|
||||
if(!penaltyType.isPenaltyAdditive) return 0
|
||||
if(!penaltyType.penaltyAdditive) return 0
|
||||
|
||||
return leftPenalty + rightPenalty
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue