mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-24 00:26:16 +02:00
config mitigation to 1.8.0
This commit is contained in:
parent
2cb053e0ca
commit
4c3d9459b7
8 changed files with 82 additions and 49 deletions
|
|
@ -72,18 +72,6 @@ permission_needed_for_color: true
|
|||
# Valid values include 0 to 1000.
|
||||
use_of_color_cost: 0
|
||||
|
||||
# Work penalty increase the price for every anvil use.
|
||||
# This config allow you to choose the comportment of work penalty.
|
||||
# Vanilla work penalty formula can be represented as 2 * previous_penalty + 1. with start value equal to 0
|
||||
# See https://minecraft.wiki/w/Anvil_mechanics#Anvil_uses for more detail
|
||||
#
|
||||
# Valid work penalty type is:
|
||||
# - default: work penalty added and increased
|
||||
# - increase_only: work penalty increased but not added
|
||||
# - add_only: work penalty added but not increased
|
||||
# - disabled: work penalty disabled
|
||||
work_penalty_type: default
|
||||
|
||||
# Default limit to apply to any enchants missing from enchant_limits
|
||||
#
|
||||
# Valid values include 1 to 1000
|
||||
|
|
@ -294,4 +282,4 @@ debug_log_verbose: false
|
|||
# ProtocoLib may also be used if the server is in an "unsupported" version even if this option is disabled.
|
||||
force_protocolib: false
|
||||
|
||||
configVersion: 1.6.2
|
||||
configVersion: 1.8.0
|
||||
|
|
|
|||
|
|
@ -72,18 +72,6 @@ permission_needed_for_color: true
|
|||
# Valid values include 0 to 1000.
|
||||
use_of_color_cost: 0
|
||||
|
||||
# Work penalty increase the price for every anvil use.
|
||||
# This config allow you to choose the comportment of work penalty.
|
||||
# Vanilla work penalty formula can be represented as 2 * previous_penalty + 1. with start value equal to 0
|
||||
# See https://minecraft.wiki/w/Anvil_mechanics#Anvil_uses for more detail
|
||||
#
|
||||
# Valid work penalty type is:
|
||||
# - default: work penalty added and increased
|
||||
# - increase_only: work penalty increased but not added
|
||||
# - add_only: work penalty added but not increased
|
||||
# - disabled: work penalty disabled
|
||||
work_penalty_type: default
|
||||
|
||||
# Default limit to apply to any enchants missing from enchant_limits
|
||||
#
|
||||
# Valid values include 1 to 1000
|
||||
|
|
@ -294,4 +282,4 @@ debug_log_verbose: false
|
|||
# ProtocoLib may also be used if the server is in an "unsupported" version even if this option is disabled.
|
||||
force_protocolib: false
|
||||
|
||||
configVersion: 1.6.2
|
||||
configVersion: 1.8.0
|
||||
|
|
|
|||
|
|
@ -156,11 +156,15 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
|
|||
|
||||
@Override
|
||||
public boolean onSave() {
|
||||
return saveWorkPenalty(items);
|
||||
}
|
||||
|
||||
public static boolean saveWorkPenalty(Map<AnvilUseType, WorkPenaltyType.WorkPenaltyPart> partEnum) {
|
||||
String path = ConfigOptions.WORK_PENALTY_ROOT;
|
||||
ConfigHolder configHolder = ConfigHolder.DEFAULT_CONFIG;
|
||||
FileConfiguration config = configHolder.getConfig();
|
||||
|
||||
items.forEach((key, value) -> {
|
||||
partEnum.forEach((key, value) -> {
|
||||
String partPath = path + "." + key.getTypeName();
|
||||
|
||||
if (key.getDefaultPenalty().equals(value)) {
|
||||
|
|
@ -172,8 +176,7 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
|
|||
config.set(partPath + '.' + ConfigOptions.WORK_PENALTY_ADDITIVE, value.penaltyAdditive());
|
||||
});
|
||||
|
||||
configHolder.saveToDisk(true);
|
||||
return true;
|
||||
return configHolder.saveToDisk(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ public class PUpdate_1_6_7 {
|
|||
|
||||
toSave.add(ConfigHolder.DEFAULT_CONFIG);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
package xyz.alexcrea.cuanvil.update.plugin;
|
||||
|
||||
import io.delilaheve.util.ConfigOptions;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.config.WorkPenaltyType;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.WorkPenaltyTypeSettingGui;
|
||||
import xyz.alexcrea.cuanvil.util.AnvilUseType;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Set;
|
||||
|
||||
public class PUpdate_1_8_0 {
|
||||
|
||||
private static final String WORK_PENALTY_TYPE = "work_penalty_type";
|
||||
|
||||
public static void handleUpdate(@Nonnull Set<ConfigHolder> toSave) {
|
||||
FileConfiguration config = ConfigHolder.DEFAULT_CONFIG.getConfig();
|
||||
|
||||
// We migrate the work penalty type if it exists
|
||||
String penaltyTypeValue = config.getString(WORK_PENALTY_TYPE);
|
||||
if (penaltyTypeValue == null) return;
|
||||
|
||||
EnumMap<AnvilUseType, WorkPenaltyType.WorkPenaltyPart> partEnum;
|
||||
partEnum = new EnumMap<>(ConfigOptions.INSTANCE.getWorkPenaltyType().getPartMap());
|
||||
|
||||
boolean keepIncrease;
|
||||
boolean keepAdditive;
|
||||
|
||||
switch (penaltyTypeValue.toLowerCase()) {
|
||||
case "add_only":
|
||||
keepIncrease = false;
|
||||
keepAdditive = true;
|
||||
break;
|
||||
case "increase_only":
|
||||
keepIncrease = true;
|
||||
keepAdditive = false;
|
||||
break;
|
||||
case "disabled":
|
||||
keepIncrease = false;
|
||||
keepAdditive = false;
|
||||
break;
|
||||
default:
|
||||
keepIncrease = true;
|
||||
keepAdditive = true;
|
||||
}
|
||||
|
||||
for (AnvilUseType type : partEnum.keySet()) {
|
||||
WorkPenaltyType.WorkPenaltyPart part = partEnum.get(type);
|
||||
part = new WorkPenaltyType.WorkPenaltyPart(
|
||||
keepIncrease & part.penaltyIncrease(),
|
||||
keepAdditive & part.penaltyAdditive());
|
||||
partEnum.replace(type, part);
|
||||
}
|
||||
|
||||
if(WorkPenaltyTypeSettingGui.saveWorkPenalty(partEnum)){
|
||||
config.set(WORK_PENALTY_TYPE, null);
|
||||
}
|
||||
|
||||
toSave.add(ConfigHolder.DEFAULT_CONFIG);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -12,21 +12,26 @@ public class PluginUpdates {
|
|||
|
||||
private static final String CONFIG_VERSION_PATH = "configVersion";
|
||||
|
||||
public static void handlePluginUpdate(){
|
||||
public static void handlePluginUpdate() {
|
||||
String versionString = ConfigHolder.DEFAULT_CONFIG.getConfig().getString(CONFIG_VERSION_PATH);
|
||||
Version current = versionString == null ? new Version(0) : Version.fromString(versionString);
|
||||
|
||||
Set<ConfigHolder> toSave = new HashSet<>();
|
||||
|
||||
if(new Version(1, 6, 2).greaterThan(current)){
|
||||
if (new Version(1, 6, 2).greaterThan(current)) {
|
||||
PUpdate_1_6_2.handleUpdate(toSave);
|
||||
|
||||
// We assume 1.6.7 will run. TODO a better system instead of that I guess
|
||||
}
|
||||
if(new Version(1, 6, 7).greaterThan(current)){
|
||||
if (new Version(1, 6, 7).greaterThan(current)) {
|
||||
PUpdate_1_6_7.handleUpdate(toSave);
|
||||
|
||||
finishConfiguration("1.6.7", toSave);
|
||||
// We assume 1.8.0 will run.
|
||||
}
|
||||
if (new Version(1, 8, 0).greaterThan(current)) {
|
||||
PUpdate_1_8_0.handleUpdate(toSave);
|
||||
|
||||
finishConfiguration("1.8.0", toSave);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ 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" TODO move old value to config migration
|
||||
const val WORK_PENALTY_ROOT = "work_penalty"
|
||||
const val WORK_PENALTY_INCREASE = "increase"
|
||||
const val WORK_PENALTY_ADDITIVE = "additive"
|
||||
|
|
|
|||
|
|
@ -72,18 +72,6 @@ permission_needed_for_color: true
|
|||
# Valid values include 0 to 1000.
|
||||
use_of_color_cost: 0
|
||||
|
||||
# Work penalty increase the price for every anvil use.
|
||||
# This config allow you to choose the comportment of work penalty.
|
||||
# Vanilla work penalty formula can be represented as 2 * previous_penalty + 1. with start value equal to 0
|
||||
# See https://minecraft.wiki/w/Anvil_mechanics#Anvil_uses for more detail
|
||||
#
|
||||
# Valid work penalty type is:
|
||||
# - default: work penalty added and increased
|
||||
# - increase_only: work penalty increased but not added
|
||||
# - add_only: work penalty added but not increased
|
||||
# - disabled: work penalty disabled
|
||||
work_penalty_type: default
|
||||
|
||||
# Default limit to apply to any enchants missing from enchant_limits
|
||||
#
|
||||
# Valid values include 1 to 1000
|
||||
|
|
@ -294,4 +282,4 @@ debug_log_verbose: false
|
|||
# ProtocoLib may also be used if the server is in an "unsupported" version even if this option is disabled.
|
||||
force_protocolib: false
|
||||
|
||||
configVersion: 1.6.7
|
||||
configVersion: 1.8.0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue