Configurable xp orb merge group count (#12503)

This commit is contained in:
Mart
2025-05-03 18:51:19 +00:00
committed by GitHub
parent 6f1f5b67e0
commit 88a3a87015
4 changed files with 34 additions and 4 deletions

View File

@@ -62,7 +62,8 @@ public abstract class Configurations<G, W> {
protected ObjectMapper.Factory.Builder createObjectMapper() {
return ObjectMapper.factoryBuilder()
.addConstraint(Constraint.class, new Constraint.Factory())
.addConstraint(Constraints.Min.class, Number.class, new Constraints.Min.Factory());
.addConstraint(Constraints.Min.class, Number.class, new Constraints.Min.Factory())
.addConstraint(Constraints.Max.class, Number.class, new Constraints.Max.Factory());
}
protected YamlConfigurationLoader.Builder createLoaderBuilder() {

View File

@@ -356,6 +356,9 @@ public class GlobalConfiguration extends ConfigurationPart {
public IntOr.Default compressionLevel = IntOr.Default.USE_DEFAULT;
@Comment("Defines the leniency distance added on the server to the interaction range of a player when validating interact packets.")
public DoubleOr.Default clientInteractionLeniencyDistance = DoubleOr.Default.USE_DEFAULT;
@Comment("Defines how many orbs groups can exist in an area.")
@Constraints.Min(1)
public IntOr.Default xpOrbGroupsPerArea = IntOr.Default.USE_DEFAULT;
}
public BlockUpdates blockUpdates;

View File

@@ -40,4 +40,22 @@ public final class Constraints {
}
}
}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Max {
int value();
final class Factory implements Constraint.Factory<Max, Number> {
@Override
public Constraint<Number> make(Max data, Type type) {
return value -> {
if (value != null && value.intValue() > data.value()) {
throw new SerializationException(value + " is greater than the max " + data.value());
}
};
}
}
}
}