feat(potions): add restoration potion for default player size
Release / release (push) Successful in 2m11s
CI / build (push) Successful in 54s

This commit is contained in:
dmg
2026-09-06 19:42:17 -04:00
parent a06d6480fe
commit fd601961eb
13 changed files with 155 additions and 9 deletions
@@ -27,7 +27,8 @@ public final class HeightMath {
if (stored == null || !Double.isFinite(stored)) {
return clamp(1.0, settings);
}
return clamp(stored, settings);
// Restoration is an explicit escape from configured stature limits.
return stored == 1.0 ? 1.0 : clamp(stored, settings);
}
public static double clamp(double value, HeightSettings settings) {
@@ -17,6 +17,7 @@ public final class PotionRecipes {
static final String[] SHIFTING_SHAPE = {"ACA", "AWA", "ACA"};
static final String[] GROWTH_SHAPE = {"GAG", "ASA", "GRG"};
static final String[] DIMINUTION_SHAPE = {"GAG", "ASA", "GFG"};
static final String[] RESTORATION_SHAPE = {"GAG", "ASA", "GUG"};
private final JavaPlugin plugin;
private final NamespacedKey potionKindKey;
@@ -30,6 +31,7 @@ public final class PotionRecipes {
registerShifting();
registerGrowth();
registerDiminution();
registerRestoration();
}
public ItemStack create(StaturePotion kind) {
@@ -96,11 +98,23 @@ public final class PotionRecipes {
plugin.getServer().addRecipe(recipe);
}
private void registerRestoration() {
ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(plugin, "restoration"),
create(StaturePotion.RESTORATION));
recipe.shape(RESTORATION_SHAPE);
recipe.setIngredient('G', Material.GOLD_INGOT);
recipe.setIngredient('A', Material.AMETHYST_SHARD);
recipe.setIngredient('S', new RecipeChoice.ExactChoice(create(StaturePotion.SHIFTING)));
recipe.setIngredient('U', Material.SUGAR);
plugin.getServer().addRecipe(recipe);
}
private static Color color(StaturePotion kind) {
return switch (kind) {
case SHIFTING -> Color.PURPLE;
case GROWTH -> Color.LIME;
case DIMINUTION -> Color.FUCHSIA;
case RESTORATION -> Color.WHITE;
};
}
}
@@ -50,12 +50,8 @@ public final class StatureListener implements Listener {
}
Player player = event.getPlayer();
double current = currentScale(player);
double scale = switch (kind) {
case SHIFTING -> HeightMath.randomScale(settings,
bound -> ThreadLocalRandom.current().nextInt(bound));
case GROWTH -> HeightMath.grow(current, settings);
case DIMINUTION -> HeightMath.shrink(current, settings);
};
double scale = kind.scaleAfterDrinking(current, settings,
bound -> ThreadLocalRandom.current().nextInt(bound));
applyAndSave(player, scale);
player.sendMessage("Your scale is now " + scale + ".");
}
@@ -1,9 +1,12 @@
package games.dmg.spigotheights;
import java.util.function.IntUnaryOperator;
public enum StaturePotion {
SHIFTING("Potion of Shifting Stature"),
GROWTH("Potion of Growth"),
DIMINUTION("Potion of Diminution");
DIMINUTION("Potion of Diminution"),
RESTORATION("Potion of Restoration");
private final String displayName;
@@ -11,6 +14,15 @@ public enum StaturePotion {
this.displayName = displayName;
}
public double scaleAfterDrinking(double current, HeightSettings settings, IntUnaryOperator randomIndex) {
return switch (this) {
case SHIFTING -> HeightMath.randomScale(settings, randomIndex);
case GROWTH -> HeightMath.grow(current, settings);
case DIMINUTION -> HeightMath.shrink(current, settings);
case RESTORATION -> 1.0;
};
}
public String displayName() {
return displayName;
}