mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
prepare exclusive penalty type
This commit is contained in:
parent
c882b7c299
commit
da776632f9
4 changed files with 94 additions and 25 deletions
|
|
@ -10,13 +10,23 @@ public class WorkPenaltyType {
|
|||
|
||||
public record WorkPenaltyPart(
|
||||
boolean penaltyIncrease,
|
||||
boolean penaltyAdditive) {
|
||||
boolean penaltyAdditive,
|
||||
boolean exclusivePenaltyIncrease,
|
||||
boolean exclusivePenaltyAdditive
|
||||
) {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 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 Map<AnvilUseType, WorkPenaltyType.WorkPenaltyPart> items;
|
||||
|
||||
|
|
@ -51,14 +54,9 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
|
|||
displayLore.add(INCREASING_EXPLANATION);
|
||||
displayLore.add(ADDING_EXPLANATION);
|
||||
displayLore.add("");
|
||||
|
||||
WorkPenaltyType workPenalty = ConfigOptions.INSTANCE.getWorkPenaltyType();
|
||||
for (AnvilUseType type : AnvilUseType.getEntries()) {
|
||||
String increasing = (workPenalty.isPenaltyIncreasing(type) ? "§a" : "§c") + "Increasing";
|
||||
String additive = (workPenalty.isPenaltyAdditive(type) ? "§a" : "§c") + "Additive";
|
||||
|
||||
displayLore.add("§e" + type.getTypeName() + ": " + additive + " §7| " + increasing);
|
||||
}
|
||||
displayLore.add("§7About shared/exclusive penalty:");
|
||||
displayLore.add(SHARED_EXPLANATION);
|
||||
displayLore.add(EXCLUSIVE_EXPLANATION);
|
||||
|
||||
ItemStack item = new ItemStack(itemMat);
|
||||
|
||||
|
|
@ -84,11 +82,11 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
|
|||
|
||||
@Override
|
||||
protected Pattern getGuiPattern() {
|
||||
return new Pattern(
|
||||
"00zy0xw00",
|
||||
"001203400",
|
||||
"00ab0c000",
|
||||
"B0000000S"
|
||||
return new Pattern( // Yeah that a mess
|
||||
"00a1z9Z00",
|
||||
"00b2y8Y00",
|
||||
"00c3x7X00",
|
||||
"B004w600S"
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -99,16 +97,21 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
|
|||
int display = 'z' - ordinal;
|
||||
int increment = 'a' + ordinal;
|
||||
int additive = '1' + ordinal;
|
||||
int exclusiveIncrement = 'Z' - ordinal;
|
||||
int exclusiveAdditive = '9' - ordinal;
|
||||
|
||||
WorkPenaltyType.WorkPenaltyPart part = items.get(type);
|
||||
String increasingStr = (part.penaltyIncrease() ? "§a" : "§c") + "Increasing";
|
||||
String additiveStr = (part.penaltyAdditive() ? "§a" : "§c") + "Additive";
|
||||
String exclusiveIncreasingStr = (part.exclusivePenaltyIncrease() ? "§a" : "§c") + "Increasing";
|
||||
String exclusiveAdditiveStr = (part.exclusivePenaltyAdditive() ? "§a" : "§c") + "Additive";
|
||||
|
||||
// Display item
|
||||
ItemStack displayItem = new ItemStack(type.getDisplayMat());
|
||||
|
||||
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();
|
||||
meta.setDisplayName("§e" + type.getDisplayName());
|
||||
|
|
@ -119,18 +122,22 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
|
|||
event.setCancelled(true);
|
||||
}));
|
||||
|
||||
// Can probably put this in a function but this works so
|
||||
// "Increment" item
|
||||
ItemStack incrementItem = new ItemStack(part.penaltyIncrease() ? Material.GREEN_TERRACOTTA : Material.RED_TERRACOTTA);
|
||||
|
||||
meta = incrementItem.getItemMeta();
|
||||
meta.setDisplayName(increasingStr);
|
||||
meta.setLore(List.of(INCREASING_EXPLANATION));
|
||||
meta.setLore(List.of(SHARED_EXPLANATION));
|
||||
incrementItem.setItemMeta(meta);
|
||||
|
||||
pane.bindItem(increment, new GuiItem(incrementItem, (event) -> {
|
||||
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();
|
||||
|
|
@ -142,12 +149,55 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
|
|||
meta = additiveItem.getItemMeta();
|
||||
meta.setDisplayName(additiveStr);
|
||||
meta.setLore(List.of(ADDING_EXPLANATION));
|
||||
meta.setLore(List.of(SHARED_EXPLANATION));
|
||||
additiveItem.setItemMeta(meta);
|
||||
|
||||
pane.bindItem(additive, new GuiItem(additiveItem, (event) -> {
|
||||
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);
|
||||
updateGuiForType(type);
|
||||
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_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);
|
||||
|
|
|
|||
|
|
@ -50,7 +50,9 @@ public class PUpdate_1_8_0 {
|
|||
WorkPenaltyType.WorkPenaltyPart part = partEnum.get(type);
|
||||
part = new WorkPenaltyType.WorkPenaltyPart(
|
||||
keepIncrease & part.penaltyIncrease(),
|
||||
keepAdditive & part.penaltyAdditive());
|
||||
keepAdditive & part.penaltyAdditive(),
|
||||
part.exclusivePenaltyIncrease(),
|
||||
part.exclusivePenaltyAdditive());
|
||||
partEnum.replace(type, part);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,8 +38,10 @@ object ConfigOptions {
|
|||
const val USE_OF_COLOR_COST = "use_of_color_cost"
|
||||
|
||||
const val WORK_PENALTY_ROOT = "work_penalty"
|
||||
const val WORK_PENALTY_INCREASE = "increase"
|
||||
const val WORK_PENALTY_ADDITIVE = "additive"
|
||||
const val WORK_PENALTY_INCREASE = "shared_increase"
|
||||
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"
|
||||
|
||||
|
|
@ -283,12 +285,15 @@ object ConfigOptions {
|
|||
val path = WORK_PENALTY_ROOT + "." + type.typeName
|
||||
|
||||
// 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 penaltyAdditive = section.getBoolean(WORK_PENALTY_ADDITIVE, true)
|
||||
val penaltyIncrease = section.getBoolean(WORK_PENALTY_INCREASE, defaultPenalty.penaltyIncrease)
|
||||
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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue