Implements #42

This commit is contained in:
2024-04-30 15:50:18 +02:00
parent 98b5ea5abe
commit fb68c18fe6
31 changed files with 415 additions and 254 deletions

View File

@@ -3,6 +3,7 @@ package net.knarcraft.minigames.arena;
import net.knarcraft.minigames.arena.reward.Reward;
import net.knarcraft.minigames.arena.reward.RewardCondition;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -13,6 +14,7 @@ import java.util.UUID;
/**
* An interface describing an arena
*/
@SuppressWarnings("unused")
public interface Arena {
/**
@@ -23,6 +25,14 @@ public interface Arena {
@NotNull
String getArenaName();
/**
* Sets the name of this arena
*
* @param arenaName <p>The new name</p>
* @return <p>True if successfully updated</p>
*/
boolean setName(@NotNull String arenaName);
/**
* Gets the data stored for this arena
*
@@ -61,6 +71,24 @@ public interface Arena {
*/
boolean saveData();
/**
* Gets the type of block a player has to hit to win this arena
*
* @return <p>The kind of block players must hit</p>
*/
@NotNull
Material getWinBlockType();
/**
* Sets the material of the win block type
*
* <p>The win block type is the type of block a player must hit to win in this arena</p>
*
* @param material <p>The material to set for the win block type</p>
* @return <p>True if successfully updated</p>
*/
boolean setWinBlockType(@NotNull Material material);
/**
* Gets whether standing on the given block should cause a win
*
@@ -92,6 +120,14 @@ public interface Arena {
@NotNull
Location getSpawnLocation();
/**
* Sets the spawn location for this arena
*
* @param newLocation <p>The new spawn location</p>
* @return <p>True if successfully updated</p>
*/
boolean setSpawnLocation(@Nullable Location newLocation);
/**
* Gets this arena's exit location
*
@@ -100,6 +136,14 @@ public interface Arena {
@Nullable
Location getExitLocation();
/**
* Sets the exit location for this arena
*
* @param newLocation <p>The new exit location</p>
* @return <p>True if successfully updated</p>
*/
boolean setExitLocation(@Nullable Location newLocation);
/**
* Adds a reward to this arena
*
@@ -124,4 +168,18 @@ public interface Arena {
@NotNull
Set<Reward> getRewards(RewardCondition rewardCondition);
/**
* Gets the maximum amount of players that can join this arena at once
*
* @return <p>The maximum amount of players</p>
*/
int getMaxPlayers();
/**
* Sets the maximum amount of players that can join this arena at once
*
* @param newValue <p>The new maximum amount of players</p>
*/
boolean setMaxPlayers(int newValue);
}

View File

@@ -151,7 +151,11 @@ public abstract class ArenaHandler<K extends Arena, S extends ArenaGroup<K, S>>
* @return <p>The arena with the given name, or null if not found</p>
*/
public @Nullable K getArena(@NotNull String arenaName) {
return this.arenas.get(this.arenaNameLookup.get(StringSanitizer.sanitizeArenaName(arenaName)));
try {
return this.arenas.get(UUID.fromString(arenaName));
} catch (IllegalArgumentException exception) {
return this.arenas.get(this.arenaNameLookup.get(StringSanitizer.sanitizeArenaName(arenaName)));
}
}
/**

View File

@@ -45,4 +45,9 @@ public enum EditablePropertyType {
*/
DOUBLE,
/**
* The property is an integer with no particular restrictions
*/
INTEGER,
}

View File

@@ -63,6 +63,11 @@ public class DropperArena implements Arena {
*/
private float playerHorizontalVelocity;
/**
* The maximum amount of players able to join this arena at any time
*/
private int maxPlayers = -1;
/**
* The material of the block players have to hit to win this dropper arena
*/
@@ -89,14 +94,16 @@ public class DropperArena implements Arena {
* @param playerVerticalVelocity <p>The velocity to use for players' vertical velocity</p>
* @param playerHorizontalVelocity <p>The velocity to use for players' horizontal velocity (-1 to 1)</p>
* @param winBlockType <p>The material of the block players have to hit to win this dropper arena</p>
* @param maxPlayers <p>The maximum amount of players able to join this arena at once</p>
* @param rewards <p>The rewards given by this arena</p>
* @param dropperArenaData <p>The arena data keeping track of which players have done what in this arena</p>
* @param arenaHandler <p>The arena handler used for saving any changes</p>
*/
public DropperArena(@NotNull UUID arenaId, @NotNull String arenaName, @NotNull Location spawnLocation,
@Nullable Location exitLocation, double playerVerticalVelocity, float playerHorizontalVelocity,
@NotNull Material winBlockType, @NotNull Map<RewardCondition, Set<Reward>> rewards,
@NotNull DropperArenaData dropperArenaData, @NotNull DropperArenaHandler arenaHandler) {
@NotNull Material winBlockType, int maxPlayers,
@NotNull Map<RewardCondition, Set<Reward>> rewards, @NotNull DropperArenaData dropperArenaData,
@NotNull DropperArenaHandler arenaHandler) {
this.arenaId = arenaId;
this.arenaName = arenaName;
this.spawnLocation = spawnLocation;
@@ -107,6 +114,7 @@ public class DropperArena implements Arena {
this.dropperArenaData = dropperArenaData;
this.dropperArenaHandler = arenaHandler;
this.rewards = rewards;
this.maxPlayers = maxPlayers;
}
/**
@@ -186,44 +194,27 @@ public class DropperArena implements Arena {
}
}
/**
* Gets the vertical velocity for players in this arena
*
* <p>This velocity will be set on the negative y-axis, for all players in this arena.</p>
*
* @return <p>Players' velocity in this arena</p>
*/
public double getPlayerVerticalVelocity() {
return this.playerVerticalVelocity;
@Override
public int getMaxPlayers() {
return this.maxPlayers;
}
/**
* Gets the horizontal for players in this arena
*
* <p>This will be used for players' fly-speed in this arena</p>
*
* @return <p>Players' velocity in this arena</p>
*/
public float getPlayerHorizontalVelocity() {
return this.playerHorizontalVelocity;
@Override
public boolean setMaxPlayers(int newValue) {
this.maxPlayers = newValue;
this.saveArena();
return true;
}
/**
* Gets the type of block a player has to hit to win this arena
*
* @return <p>The kind of block players must hit</p>
*/
public @NotNull Material getWinBlockType() {
@Override
@NotNull
public Material getWinBlockType() {
return this.winBlockType;
}
/**
* Gets this arena's sanitized name
*
* @return <p>This arena's sanitized name</p>
*/
public @NotNull String getArenaNameSanitized() {
@Override
@NotNull
public String getArenaNameSanitized() {
return StringSanitizer.sanitizeArenaName(this.getArenaName());
}
@@ -257,12 +248,7 @@ public class DropperArena implements Arena {
return winBlockType.isSolid();
}
/**
* Sets the spawn location for this arena
*
* @param newLocation <p>The new spawn location</p>
* @return <p>True if successfully updated</p>
*/
@Override
public boolean setSpawnLocation(@Nullable Location newLocation) {
if (isInvalid(newLocation)) {
return false;
@@ -273,12 +259,7 @@ public class DropperArena implements Arena {
}
}
/**
* Sets the exit location for this arena
*
* @param newLocation <p>The new exit location</p>
* @return <p>True if successfully updated</p>
*/
@Override
public boolean setExitLocation(@Nullable Location newLocation) {
if (isInvalid(newLocation)) {
return false;
@@ -289,12 +270,7 @@ public class DropperArena implements Arena {
}
}
/**
* Sets the name of this arena
*
* @param arenaName <p>The new name</p>
* @return <p>True if successfully updated</p>
*/
@Override
public boolean setName(@NotNull String arenaName) {
if (!arenaName.isBlank()) {
String oldName = this.getArenaNameSanitized();
@@ -309,13 +285,29 @@ public class DropperArena implements Arena {
}
/**
* Sets the material of the win block type
* Gets the vertical velocity for players in this arena
*
* <p>The win block type is the type of block a player must hit to win in this arena</p>
* <p>This velocity will be set on the negative y-axis, for all players in this arena.</p>
*
* @param material <p>The material to set for the win block type</p>
* @return <p>True if successfully updated</p>
* @return <p>Players' velocity in this arena</p>
*/
public double getPlayerVerticalVelocity() {
return this.playerVerticalVelocity;
}
/**
* Gets the horizontal for players in this arena
*
* <p>This will be used for players' fly-speed in this arena</p>
*
* @return <p>Players' velocity in this arena</p>
*/
public float getPlayerHorizontalVelocity() {
return this.playerHorizontalVelocity;
}
@Override
public boolean setWinBlockType(@NotNull Material material) {
if (material.isAir() || !material.isBlock()) {
return false;

View File

@@ -45,6 +45,12 @@ public enum DropperArenaEditableProperty {
*/
WIN_BLOCK_TYPE("winBlockType", (arena) -> arena.getWinBlockType().toString(),
EditablePropertyType.BLOCK_TYPE),
/**
* The arena's max players
*/
MAX_PLAYERS("maxPlayers", (arena) -> String.valueOf(arena.getMaxPlayers()),
EditablePropertyType.INTEGER),
;
private final @NotNull String argumentString;

View File

@@ -51,6 +51,11 @@ public enum DropperArenaStorageKey {
* The key for this arena's rewards
*/
REWARDS("rewards"),
/**
* The key for this arena's maximum players
*/
MAX_PLAYERS("maxPlayers"),
;
private final @NotNull String key;

View File

@@ -84,6 +84,11 @@ public class ParkourArena implements Arena {
*/
private @Nullable Set<Material> obstacleBlocks;
/**
* The maximum amount of players able to join this arena at any time
*/
private int maxPlayers;
/**
* The checkpoints for this arena. Entering a checkpoint overrides the player's spawn location.
*/
@@ -110,6 +115,7 @@ public class ParkourArena implements Arena {
* @param killPlaneBlockNames <p>The names of the types of blocks that trigger a loss when stepped on</p>
* @param obstacleBlockNames <p>The names of the types of blocks that trigger a loss when touched</p>
* @param checkpoints <p>The checkpoints set for this arena</p>
* @param maxPlayers <p>The maximum amount of players able to join this arena at once</p>
* @param rewards <p>The rewards given by this arena</p>
* @param parkourArenaData <p>The arena data keeping track of which players have done what in this arena</p>
* @param arenaHandler <p>The arena handler used for saving any changes</p>
@@ -117,7 +123,7 @@ public class ParkourArena implements Arena {
public ParkourArena(@NotNull UUID arenaId, @NotNull String arenaName, @NotNull Location spawnLocation,
@Nullable Location exitLocation, @NotNull Material winBlockType, @Nullable Location winLocation,
@Nullable Set<String> killPlaneBlockNames, @Nullable Set<String> obstacleBlockNames,
@NotNull List<Location> checkpoints,
@NotNull List<Location> checkpoints, int maxPlayers,
@NotNull Map<RewardCondition, Set<Reward>> rewards,
@NotNull ParkourArenaData parkourArenaData, @NotNull ParkourArenaHandler arenaHandler) {
this.arenaId = arenaId;
@@ -136,6 +142,7 @@ public class ParkourArena implements Arena {
this.parkourArenaData = parkourArenaData;
this.parkourArenaHandler = arenaHandler;
this.rewards = rewards;
this.maxPlayers = maxPlayers;
}
/**
@@ -167,6 +174,7 @@ public class ParkourArena implements Arena {
this.obstacleBlocks = null;
this.checkpoints = new ArrayList<>();
this.parkourArenaHandler = arenaHandler;
this.maxPlayers = -1;
}
@Override
@@ -216,12 +224,25 @@ public class ParkourArena implements Arena {
}
}
/**
* Gets the type of block a player has to hit to win this arena
*
* @return <p>The kind of block players must hit</p>
*/
public @NotNull Material getWinBlockType() {
@Override
public int getMaxPlayers() {
return this.maxPlayers;
}
@Override
public boolean setMaxPlayers(int newValue) {
if (newValue < -1) {
return false;
}
this.maxPlayers = newValue;
this.saveArena();
return true;
}
@Override
@NotNull
public Material getWinBlockType() {
return this.winBlockType;
}
@@ -302,12 +323,9 @@ public class ParkourArena implements Arena {
return this.checkpoints.isEmpty();
}
/**
* Gets this arena's sanitized name
*
* @return <p>This arena's sanitized name</p>
*/
public @NotNull String getArenaNameSanitized() {
@Override
@NotNull
public String getArenaNameSanitized() {
return StringSanitizer.sanitizeArenaName(this.getArenaName());
}
@@ -350,12 +368,7 @@ public class ParkourArena implements Arena {
this.winBlockType.isSolid();
}
/**
* Sets the spawn location for this arena
*
* @param newLocation <p>The new spawn location</p>
* @return <p>True if successfully updated</p>
*/
@Override
public boolean setSpawnLocation(@Nullable Location newLocation) {
if (isInvalid(newLocation)) {
return false;
@@ -366,12 +379,7 @@ public class ParkourArena implements Arena {
}
}
/**
* Sets the exit location for this arena
*
* @param newLocation <p>The new exit location</p>
* @return <p>True if successfully updated</p>
*/
@Override
public boolean setExitLocation(@Nullable Location newLocation) {
if (isInvalid(newLocation)) {
return false;
@@ -382,12 +390,7 @@ public class ParkourArena implements Arena {
}
}
/**
* Sets the name of this arena
*
* @param arenaName <p>The new name</p>
* @return <p>True if successfully updated</p>
*/
@Override
public boolean setName(@NotNull String arenaName) {
if (!arenaName.isBlank()) {
String oldName = this.getArenaNameSanitized();
@@ -401,14 +404,7 @@ public class ParkourArena implements Arena {
}
}
/**
* Sets the material of the win block type
*
* <p>The win block type is the type of block a player must hit to win in this arena</p>
*
* @param material <p>The material to set for the win block type</p>
* @return <p>True if successfully updated</p>
*/
@Override
public boolean setWinBlockType(@NotNull Material material) {
if (material.isAir() || !material.isBlock()) {
return false;

View File

@@ -69,6 +69,11 @@ public enum ParkourArenaEditableProperty {
OBSTACLE_BLOCKS("obstacleBlocks", (arena) -> String.valueOf(arena.getObstacleBlockNames()),
EditablePropertyType.MATERIAL_LIST),
/**
* The arena's max players
*/
MAX_PLAYERS("maxPlayers", (arena) -> String.valueOf(arena.getMaxPlayers()),
EditablePropertyType.INTEGER),
;
private final @NotNull String argumentString;

View File

@@ -29,7 +29,7 @@ public enum ParkourArenaGameMode implements ConfigurationSerializable, ArenaGame
* @param gameMode <p>The game-mode string to match</p>
* @return <p>The specified arena game-mode</p>
*/
public static @NotNull ParkourArenaGameMode matchGamemode(@NotNull String gameMode) {
public static @NotNull ParkourArenaGameMode matchGameMode(@NotNull String gameMode) {
try {
return ParkourArenaGameMode.valueOf(gameMode.toUpperCase());
} catch (IllegalArgumentException exception) {

View File

@@ -61,6 +61,11 @@ public enum ParkourArenaStorageKey {
* The key for this arena's rewards
*/
REWARDS("rewards"),
/**
* The key for this arena's maximum players
*/
MAX_PLAYERS("maxPlayers"),
;
private final @NotNull String key;