Class PlayerChangeSizeSuper
PlayerChangeSizeSuper provides the core scaling mechanism used by scaling effects like SWELLING and SHRINKING. Scaling is implemented using a multiplier-based system where the new scale is calculated by multiplying the player's current scale by a scaleMultiplier. For example, a multiplier of 2.0 doubles the player's size, while 0.5 halves it.
Effect Lifecycle:
- A subclass creates an instance with a specific scaleMultiplier (set before startEffect() is called)
- The subclass calls startEffect() to schedule the size change via an async BukkitRunnable (5-tick delay)
- changePlayerSize() executes asynchronously: removes any conflicting scale effects, applies the new scale, and kills the effect if the player returns to normal size (1.0)
- checkEffect() ages the effect each tick (only for non-permanent effects)
- When the effect expires, doRemove() resets the player back to normal scale (1.0)
Scale Bounds: The player's scale is clamped to the range [0.25, 4.0] to prevent the game engine from being overwhelmed by extremely large or small players. Values outside this range are automatically adjusted to the nearest boundary.
Stacking Behavior: Multiple scaling effects cannot stack on the same player. When changePlayerSize() executes, it removes any existing SWELLING or SHRINKING effects before applying the new scale. This ensures only one scaling effect is active at a time.
-
Field Summary
Fields inherited from class net.pottercraft.ollivanders2.effect.O2Effect
affectedPlayerText, duration, effectType, informousText, kill, legilimensText, p, permanent, targetID -
Constructor Summary
ConstructorsConstructorDescriptionPlayerChangeSizeSuper(@NotNull Ollivanders2 plugin, int duration, boolean isPermanent, @NotNull UUID pid) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidCheck this effect's behavior each game tick.voiddoRemove()Remove this effect and reset the player to normal size.doubleGet the scale multiplier for this size-changing effect.booleanCheck if this effect has successfully transformed the player's size.protected voidSchedule the size change to occur asynchronously with a 5-tick delay.Methods inherited from class net.pottercraft.ollivanders2.effect.O2Effect
age, getAffectedPlayerText, getInformousText, getLegilimensText, getMaxDuration, getMinDuration, getRemainingDuration, getTargetID, isKilled, isPermanent, kill, setPermanent
-
Constructor Details
-
PlayerChangeSizeSuper
public PlayerChangeSizeSuper(@NotNull @NotNull Ollivanders2 plugin, int duration, boolean isPermanent, @NotNull @NotNull UUID pid) Constructor- Parameters:
plugin- a callback to the MC pluginduration- the duration of the effectisPermanent- is this effect permanent (does not age)pid- the ID of the player this effect acts on
-
-
Method Details
-
startEffect
protected void startEffect()Schedule the size change to occur asynchronously with a 5-tick delay.This method should be called by subclass constructors or initialization methods to apply the size change. The actual size modification is executed asynchronously (5 ticks / 250 milliseconds later) to avoid potential synchronization issues. Child classes must set scaleMultiplier before calling this method.
The 5-tick delay allows the player entity to be fully initialized in the server before scale modifications are applied.
-
checkEffect
public void checkEffect()Check this effect's behavior each game tick.This method is called once per tick by the effects system. For non-permanent scaling effects, it ages the effect by 1 tick. The actual size change was already applied asynchronously when startEffect() was called.
- Specified by:
checkEffectin classO2Effect
-
doRemove
public void doRemove()Remove this effect and reset the player to normal size.Called when the effect is being removed from the player (either due to expiration or explicit removal). This method retrieves the player's scale attribute and resets it to 1.0 (normal size), effectively undoing any size changes applied by this effect.
-
isTransformed
public boolean isTransformed()Check if this effect has successfully transformed the player's size.Returns true after the size change has been applied to the player (i.e., after the asynchronous startEffect() runnable has executed and changePlayerSize() has been called). This flag is used to ensure the size change runs exactly once per effect.
- Returns:
- true if the player has been transformed, false if the transformation is still pending
-
getScaleMultiplier
public double getScaleMultiplier()Get the scale multiplier for this size-changing effect.Returns the multiplier used to calculate the new player scale. Values above 1.0 increase the player's size, while values below 1.0 decrease it. For example:
- 2.0 doubles the player's size (SWELLING)
- 0.5 halves the player's size (SHRINKING)
- Returns:
- the scale multiplier value
-