package net.knarcraft.minigames.arena.dropper; import net.knarcraft.minigames.arena.EditablePropertyType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.function.Function; /** * All editable properties of a dropper arena */ public enum DropperArenaEditableProperty { /** * The name of the arena */ NAME("name", DropperArena::getArenaName, EditablePropertyType.ARENA_NAME), /** * The arena's spawn location */ SPAWN_LOCATION("spawnLocation", (arena) -> String.valueOf(arena.getSpawnLocation()), EditablePropertyType.LOCATION), /** * The arena's exit location */ EXIT_LOCATION("exitLocation", (arena) -> String.valueOf(arena.getExitLocation()), EditablePropertyType.LOCATION), /** * The arena's vertical velocity */ VERTICAL_VELOCITY("verticalVelocity", (arena) -> String.valueOf(arena.getPlayerVerticalVelocity()), EditablePropertyType.VERTICAL_VELOCITY), /** * The arena's horizontal velocity */ HORIZONTAL_VELOCITY("horizontalVelocity", (arena) -> String.valueOf(arena.getPlayerHorizontalVelocity()), EditablePropertyType.HORIZONTAL_VELOCITY), /** * The arena's win block type */ WIN_BLOCK_TYPE("winBlockType", (arena) -> arena.getWinBlockType().toString(), EditablePropertyType.BLOCK_TYPE), ; private final @NotNull String argumentString; private final Function currentValueProvider; private final EditablePropertyType propertyType; /** * Instantiates a new arena editable property * * @param argumentString

The argument string used to specify this property

*/ DropperArenaEditableProperty(@NotNull String argumentString, Function currentValueProvider, EditablePropertyType propertyType) { this.argumentString = argumentString; this.currentValueProvider = currentValueProvider; this.propertyType = propertyType; } /** * Gets the type of property this editable property represents * * @return

The type of this property

*/ public EditablePropertyType getPropertyType() { return this.propertyType; } /** * Gets the string representation of this property's current value * * @param arena

The arena to check the value for

* @return

The current value as a string

*/ public String getCurrentValueAsString(DropperArena arena) { return this.currentValueProvider.apply(arena); } /** * Gets the argument string used to specify this property * * @return

The argument string

*/ public @NotNull String getArgumentString() { return this.argumentString; } /** * Gets the editable property corresponding to the given argument string * * @param argumentString

The argument string used to specify an editable property

* @return

The corresponding editable property, or null if not found

*/ public static @Nullable DropperArenaEditableProperty getFromArgumentString(String argumentString) { for (DropperArenaEditableProperty property : DropperArenaEditableProperty.values()) { if (property.argumentString.equalsIgnoreCase(argumentString)) { return property; } } return null; } }