prepare exclusive penalty type

This commit is contained in:
alexcrea 2025-02-12 18:05:01 +01:00
parent c882b7c299
commit da776632f9
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
4 changed files with 94 additions and 25 deletions

View file

@ -10,13 +10,23 @@ public class WorkPenaltyType {
public record WorkPenaltyPart( public record WorkPenaltyPart(
boolean penaltyIncrease, boolean penaltyIncrease,
boolean penaltyAdditive) { boolean penaltyAdditive,
boolean exclusivePenaltyIncrease,
boolean exclusivePenaltyAdditive
) {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if(!(obj instanceof WorkPenaltyPart other)) return false; if(!(obj instanceof WorkPenaltyPart other)) return false;
return other.penaltyIncrease == this.penaltyIncrease && other.penaltyAdditive == this.penaltyAdditive; return other.penaltyIncrease == this.penaltyIncrease &&
other.penaltyAdditive == this.penaltyAdditive &&
other.exclusivePenaltyIncrease == this.exclusivePenaltyIncrease &&
other.exclusivePenaltyAdditive == this.exclusivePenaltyAdditive;
}
public WorkPenaltyPart(boolean penaltyIncrease, boolean penaltyAdditive) {
this(penaltyIncrease, penaltyAdditive, false, false);
} }
} }

View file

@ -27,6 +27,9 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
private static final String INCREASING_EXPLANATION = "§eIncreasing§7: will penalty be increased (in item)"; private static final String INCREASING_EXPLANATION = "§eIncreasing§7: will penalty be increased (in item)";
private static final String ADDING_EXPLANATION = "§eAdditive§7: will penalty be added to the cost"; private static final String ADDING_EXPLANATION = "§eAdditive§7: will penalty be added to the cost";
private static final String SHARED_EXPLANATION = "§eShared§7: Vanilla, shared penalty. it will be kept from before the plugin installation.";
private static final String EXCLUSIVE_EXPLANATION = "§eExclusive§7: Custom, per anvil use type penalty. it will be lost after plugin uninstallation";
private final @NotNull WorkPenaltyType currentType; private final @NotNull WorkPenaltyType currentType;
private final @NotNull Map<AnvilUseType, WorkPenaltyType.WorkPenaltyPart> items; private final @NotNull Map<AnvilUseType, WorkPenaltyType.WorkPenaltyPart> items;
@ -51,14 +54,9 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
displayLore.add(INCREASING_EXPLANATION); displayLore.add(INCREASING_EXPLANATION);
displayLore.add(ADDING_EXPLANATION); displayLore.add(ADDING_EXPLANATION);
displayLore.add(""); displayLore.add("");
displayLore.add("§7About shared/exclusive penalty:");
WorkPenaltyType workPenalty = ConfigOptions.INSTANCE.getWorkPenaltyType(); displayLore.add(SHARED_EXPLANATION);
for (AnvilUseType type : AnvilUseType.getEntries()) { displayLore.add(EXCLUSIVE_EXPLANATION);
String increasing = (workPenalty.isPenaltyIncreasing(type) ? "§a" : "§c") + "Increasing";
String additive = (workPenalty.isPenaltyAdditive(type) ? "§a" : "§c") + "Additive";
displayLore.add("§e" + type.getTypeName() + ": " + additive + " §7| " + increasing);
}
ItemStack item = new ItemStack(itemMat); ItemStack item = new ItemStack(itemMat);
@ -84,11 +82,11 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
@Override @Override
protected Pattern getGuiPattern() { protected Pattern getGuiPattern() {
return new Pattern( return new Pattern( // Yeah that a mess
"00zy0xw00", "00a1z9Z00",
"001203400", "00b2y8Y00",
"00ab0c000", "00c3x7X00",
"B0000000S" "B004w600S"
); );
} }
@ -99,16 +97,21 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
int display = 'z' - ordinal; int display = 'z' - ordinal;
int increment = 'a' + ordinal; int increment = 'a' + ordinal;
int additive = '1' + ordinal; int additive = '1' + ordinal;
int exclusiveIncrement = 'Z' - ordinal;
int exclusiveAdditive = '9' - ordinal;
WorkPenaltyType.WorkPenaltyPart part = items.get(type); WorkPenaltyType.WorkPenaltyPart part = items.get(type);
String increasingStr = (part.penaltyIncrease() ? "§a" : "§c") + "Increasing"; String increasingStr = (part.penaltyIncrease() ? "§a" : "§c") + "Increasing";
String additiveStr = (part.penaltyAdditive() ? "§a" : "§c") + "Additive"; String additiveStr = (part.penaltyAdditive() ? "§a" : "§c") + "Additive";
String exclusiveIncreasingStr = (part.exclusivePenaltyIncrease() ? "§a" : "§c") + "Increasing";
String exclusiveAdditiveStr = (part.exclusivePenaltyAdditive() ? "§a" : "§c") + "Additive";
// Display item // Display item
ItemStack displayItem = new ItemStack(type.getDisplayMat()); ItemStack displayItem = new ItemStack(type.getDisplayMat());
ArrayList<String> displayLore = new ArrayList<>(); ArrayList<String> displayLore = new ArrayList<>();
displayLore.add("§e" + type.getTypeName() + ": " + additiveStr + " §7| " + increasingStr); displayLore.add("§eShared§7: " + additiveStr + " §7| " + increasingStr);
displayLore.add("§eExclusive§7: " + exclusiveAdditiveStr + " §7| " + exclusiveIncreasingStr);
ItemMeta meta = displayItem.getItemMeta(); ItemMeta meta = displayItem.getItemMeta();
meta.setDisplayName("§e" + type.getDisplayName()); meta.setDisplayName("§e" + type.getDisplayName());
@ -119,18 +122,22 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
event.setCancelled(true); event.setCancelled(true);
})); }));
// Can probably put this in a function but this works so
// "Increment" item // "Increment" item
ItemStack incrementItem = new ItemStack(part.penaltyIncrease() ? Material.GREEN_TERRACOTTA : Material.RED_TERRACOTTA); ItemStack incrementItem = new ItemStack(part.penaltyIncrease() ? Material.GREEN_TERRACOTTA : Material.RED_TERRACOTTA);
meta = incrementItem.getItemMeta(); meta = incrementItem.getItemMeta();
meta.setDisplayName(increasingStr); meta.setDisplayName(increasingStr);
meta.setLore(List.of(INCREASING_EXPLANATION)); meta.setLore(List.of(INCREASING_EXPLANATION));
meta.setLore(List.of(SHARED_EXPLANATION));
incrementItem.setItemMeta(meta); incrementItem.setItemMeta(meta);
pane.bindItem(increment, new GuiItem(incrementItem, (event) -> { pane.bindItem(increment, new GuiItem(incrementItem, (event) -> {
event.setCancelled(true); event.setCancelled(true);
WorkPenaltyType.WorkPenaltyPart newPart = new WorkPenaltyType.WorkPenaltyPart(!part.penaltyIncrease(), part.penaltyAdditive()); WorkPenaltyType.WorkPenaltyPart newPart = new WorkPenaltyType.WorkPenaltyPart(
!part.penaltyIncrease(), part.penaltyAdditive(),
part.exclusivePenaltyIncrease(), part.exclusivePenaltyAdditive());
items.replace(type, newPart); items.replace(type, newPart);
updateGuiForType(type); updateGuiForType(type);
update(); update();
@ -142,12 +149,55 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
meta = additiveItem.getItemMeta(); meta = additiveItem.getItemMeta();
meta.setDisplayName(additiveStr); meta.setDisplayName(additiveStr);
meta.setLore(List.of(ADDING_EXPLANATION)); meta.setLore(List.of(ADDING_EXPLANATION));
meta.setLore(List.of(SHARED_EXPLANATION));
additiveItem.setItemMeta(meta); additiveItem.setItemMeta(meta);
pane.bindItem(additive, new GuiItem(additiveItem, (event) -> { pane.bindItem(additive, new GuiItem(additiveItem, (event) -> {
event.setCancelled(true); event.setCancelled(true);
WorkPenaltyType.WorkPenaltyPart newPart = new WorkPenaltyType.WorkPenaltyPart(part.penaltyIncrease(), !part.penaltyAdditive()); WorkPenaltyType.WorkPenaltyPart newPart = new WorkPenaltyType.WorkPenaltyPart(
part.penaltyIncrease(), !part.penaltyAdditive(),
part.exclusivePenaltyIncrease(), part.exclusivePenaltyAdditive());
items.replace(type, newPart);
updateGuiForType(type);
update();
}));
// exclusive "Increment" item
ItemStack exclusiveIncrementItem = new ItemStack(part.exclusivePenaltyIncrease() ? Material.GREEN_TERRACOTTA : Material.RED_TERRACOTTA);
meta = exclusiveIncrementItem.getItemMeta();
meta.setDisplayName(exclusiveIncreasingStr);
meta.setLore(List.of(INCREASING_EXPLANATION));
meta.setLore(List.of(EXCLUSIVE_EXPLANATION));
exclusiveIncrementItem.setItemMeta(meta);
pane.bindItem(exclusiveIncrement, new GuiItem(exclusiveIncrementItem, (event) -> {
event.setCancelled(true);
WorkPenaltyType.WorkPenaltyPart newPart = new WorkPenaltyType.WorkPenaltyPart(
part.penaltyIncrease(), part.penaltyAdditive(),
!part.exclusivePenaltyIncrease(), part.exclusivePenaltyAdditive());
items.replace(type, newPart);
updateGuiForType(type);
update();
}));
// exclusive "Additive" item
ItemStack exclusiveAdditiveItem = new ItemStack(part.exclusivePenaltyAdditive() ? Material.GREEN_TERRACOTTA : Material.RED_TERRACOTTA);
meta = exclusiveAdditiveItem.getItemMeta();
meta.setDisplayName(exclusiveAdditiveStr);
meta.setLore(List.of(ADDING_EXPLANATION));
meta.setLore(List.of(EXCLUSIVE_EXPLANATION));
exclusiveAdditiveItem.setItemMeta(meta);
pane.bindItem(exclusiveAdditive, new GuiItem(exclusiveAdditiveItem, (event) -> {
event.setCancelled(true);
WorkPenaltyType.WorkPenaltyPart newPart = new WorkPenaltyType.WorkPenaltyPart(
part.penaltyIncrease(), part.penaltyAdditive(),
part.exclusivePenaltyIncrease(), !part.exclusivePenaltyAdditive());
items.replace(type, newPart); items.replace(type, newPart);
updateGuiForType(type); updateGuiForType(type);
update(); update();
@ -174,6 +224,8 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
config.set(partPath + '.' + ConfigOptions.WORK_PENALTY_INCREASE, value.penaltyIncrease()); config.set(partPath + '.' + ConfigOptions.WORK_PENALTY_INCREASE, value.penaltyIncrease());
config.set(partPath + '.' + ConfigOptions.WORK_PENALTY_ADDITIVE, value.penaltyAdditive()); config.set(partPath + '.' + ConfigOptions.WORK_PENALTY_ADDITIVE, value.penaltyAdditive());
config.set(partPath + '.' + ConfigOptions.EXCLUSIVE_WORK_PENALTY_INCREASE, value.exclusivePenaltyIncrease());
config.set(partPath + '.' + ConfigOptions.EXCLUSIVE_WORK_PENALTY_ADDITIVE, value.exclusivePenaltyAdditive());
}); });
return configHolder.saveToDisk(true); return configHolder.saveToDisk(true);

View file

@ -50,7 +50,9 @@ public class PUpdate_1_8_0 {
WorkPenaltyType.WorkPenaltyPart part = partEnum.get(type); WorkPenaltyType.WorkPenaltyPart part = partEnum.get(type);
part = new WorkPenaltyType.WorkPenaltyPart( part = new WorkPenaltyType.WorkPenaltyPart(
keepIncrease & part.penaltyIncrease(), keepIncrease & part.penaltyIncrease(),
keepAdditive & part.penaltyAdditive()); keepAdditive & part.penaltyAdditive(),
part.exclusivePenaltyIncrease(),
part.exclusivePenaltyAdditive());
partEnum.replace(type, part); partEnum.replace(type, part);
} }

View file

@ -38,8 +38,10 @@ object ConfigOptions {
const val USE_OF_COLOR_COST = "use_of_color_cost" const val USE_OF_COLOR_COST = "use_of_color_cost"
const val WORK_PENALTY_ROOT = "work_penalty" const val WORK_PENALTY_ROOT = "work_penalty"
const val WORK_PENALTY_INCREASE = "increase" const val WORK_PENALTY_INCREASE = "shared_increase"
const val WORK_PENALTY_ADDITIVE = "additive" const val WORK_PENALTY_ADDITIVE = "shared_additive"
const val EXCLUSIVE_WORK_PENALTY_INCREASE = "exclusive_increase"
const val EXCLUSIVE_WORK_PENALTY_ADDITIVE = "exclusive_additive"
const val DEFAULT_LIMIT_PATH = "default_limit" const val DEFAULT_LIMIT_PATH = "default_limit"
@ -283,12 +285,15 @@ object ConfigOptions {
val path = WORK_PENALTY_ROOT + "." + type.typeName val path = WORK_PENALTY_ROOT + "." + type.typeName
// Find values // Find values
val section = config.getConfigurationSection(path) ?: return type.defaultPenalty val defaultPenalty = type.defaultPenalty
val section = config.getConfigurationSection(path) ?: return defaultPenalty
val penaltyIncrease = section.getBoolean(WORK_PENALTY_INCREASE, true) val penaltyIncrease = section.getBoolean(WORK_PENALTY_INCREASE, defaultPenalty.penaltyIncrease)
val penaltyAdditive = section.getBoolean(WORK_PENALTY_ADDITIVE, true) val penaltyAdditive = section.getBoolean(WORK_PENALTY_ADDITIVE, defaultPenalty.penaltyAdditive)
val exclusivePenaltyIncrease = section.getBoolean(EXCLUSIVE_WORK_PENALTY_INCREASE, defaultPenalty.exclusivePenaltyIncrease)
val exclusivePenaltyAdditive = section.getBoolean(EXCLUSIVE_WORK_PENALTY_ADDITIVE, defaultPenalty.exclusivePenaltyAdditive)
return WorkPenaltyPart(penaltyIncrease, penaltyAdditive) return WorkPenaltyPart(penaltyIncrease, penaltyAdditive, exclusivePenaltyIncrease, exclusivePenaltyAdditive)
} }
/** /**