mirror of
https://github.com/SunNetservers/MiniGames.git
synced 2025-12-04 18:08:48 +01:00
Cleans up some nullability annotations
This commit is contained in:
@@ -15,22 +15,22 @@ import java.util.logging.Level;
|
||||
/**
|
||||
* An interface describing a generic arena handler
|
||||
*
|
||||
* @param <K> <p>The type of arena stored</p>
|
||||
* @param <S> <p>The type of arena group stored</p>
|
||||
* @param <ArenaType> <p>The type of arena stored</p>
|
||||
* @param <GroupType> <p>The type of arena group stored</p>
|
||||
*/
|
||||
public abstract class ArenaHandler<K extends Arena, S extends ArenaGroup<K, S>> {
|
||||
public abstract class ArenaHandler<ArenaType extends Arena, GroupType extends ArenaGroup<ArenaType, GroupType>> {
|
||||
|
||||
protected Map<UUID, K> arenas = new HashMap<>();
|
||||
protected Map<UUID, S> arenaGroups = new HashMap<>();
|
||||
protected Map<UUID, ArenaType> arenas = new HashMap<>();
|
||||
protected Map<UUID, GroupType> arenaGroups = new HashMap<>();
|
||||
protected Map<String, UUID> arenaNameLookup = new HashMap<>();
|
||||
private final ArenaPlayerRegistry<K> playerRegistry;
|
||||
private final ArenaPlayerRegistry<ArenaType> playerRegistry;
|
||||
|
||||
/**
|
||||
* Instantiates a new arena handler
|
||||
*
|
||||
* @param playerRegistry <p>The registry keeping track of player sessions</p>
|
||||
*/
|
||||
public ArenaHandler(ArenaPlayerRegistry<K> playerRegistry) {
|
||||
public ArenaHandler(@NotNull ArenaPlayerRegistry<ArenaType> playerRegistry) {
|
||||
this.playerRegistry = playerRegistry;
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ public abstract class ArenaHandler<K extends Arena, S extends ArenaGroup<K, S>>
|
||||
*
|
||||
* @return <p>All arenas in a group</p>
|
||||
*/
|
||||
public @NotNull Set<K> getArenasInAGroup() {
|
||||
Set<K> arenas = new HashSet<>();
|
||||
public @NotNull Set<ArenaType> getArenasInAGroup() {
|
||||
Set<ArenaType> arenas = new HashSet<>();
|
||||
for (UUID arenaId : arenaGroups.keySet()) {
|
||||
arenas.add(this.arenas.get(arenaId));
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public abstract class ArenaHandler<K extends Arena, S extends ArenaGroup<K, S>>
|
||||
*
|
||||
* @return <p>All arena groups</p>
|
||||
*/
|
||||
public Set<S> getAllGroups() {
|
||||
public Set<GroupType> getAllGroups() {
|
||||
return new HashSet<>(arenaGroups.values());
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public abstract class ArenaHandler<K extends Arena, S extends ArenaGroup<K, S>>
|
||||
* @param arenaId <p>The id of the arena to get the group of</p>
|
||||
* @return <p>The group the arena belongs to, or null if not in a group</p>
|
||||
*/
|
||||
public @Nullable S getGroup(@NotNull UUID arenaId) {
|
||||
public @Nullable GroupType getGroup(@NotNull UUID arenaId) {
|
||||
return this.arenaGroups.get(arenaId);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public abstract class ArenaHandler<K extends Arena, S extends ArenaGroup<K, S>>
|
||||
* @param arenaId <p>The id of the arena to change</p>
|
||||
* @param arenaGroup <p>The group to add the arena to, or null to remove the current group</p>
|
||||
*/
|
||||
public void setGroup(@NotNull UUID arenaId, @Nullable S arenaGroup) {
|
||||
public void setGroup(@NotNull UUID arenaId, @Nullable GroupType arenaGroup) {
|
||||
if (arenaGroup == null) {
|
||||
// No need to remove something non-existing
|
||||
if (!this.arenaGroups.containsKey(arenaId)) {
|
||||
@@ -80,7 +80,7 @@ public abstract class ArenaHandler<K extends Arena, S extends ArenaGroup<K, S>>
|
||||
}
|
||||
|
||||
// Remove the existing group
|
||||
S oldGroup = this.arenaGroups.remove(arenaId);
|
||||
GroupType oldGroup = this.arenaGroups.remove(arenaId);
|
||||
oldGroup.removeArena(arenaId);
|
||||
} else {
|
||||
// Make sure to remove the arena from the old group's internal tracking
|
||||
@@ -100,9 +100,9 @@ public abstract class ArenaHandler<K extends Arena, S extends ArenaGroup<K, S>>
|
||||
* @param groupName <p>The name of the group to get</p>
|
||||
* @return <p>The group, or null if not found</p>
|
||||
*/
|
||||
public @Nullable S getGroup(String groupName) {
|
||||
public @Nullable GroupType getGroup(@NotNull String groupName) {
|
||||
String sanitized = StringSanitizer.sanitizeArenaName(groupName);
|
||||
for (S arenaGroup : this.arenaGroups.values()) {
|
||||
for (GroupType arenaGroup : this.arenaGroups.values()) {
|
||||
if (arenaGroup.getGroupNameSanitized().equals(sanitized)) {
|
||||
return arenaGroup;
|
||||
}
|
||||
@@ -128,7 +128,7 @@ public abstract class ArenaHandler<K extends Arena, S extends ArenaGroup<K, S>>
|
||||
*
|
||||
* @param arena <p>The arena to add</p>
|
||||
*/
|
||||
public void addArena(@NotNull K arena) {
|
||||
public void addArena(@NotNull ArenaType arena) {
|
||||
this.arenas.put(arena.getArenaId(), arena);
|
||||
this.arenaNameLookup.put(arena.getArenaNameSanitized(), arena.getArenaId());
|
||||
this.saveArenas();
|
||||
@@ -140,7 +140,7 @@ public abstract class ArenaHandler<K extends Arena, S extends ArenaGroup<K, S>>
|
||||
* @param arenaId <p>The id of the arena to get</p>
|
||||
* @return <p>The arena, or null if no arena could be found</p>
|
||||
*/
|
||||
public @Nullable K getArena(@NotNull UUID arenaId) {
|
||||
public @Nullable ArenaType getArena(@NotNull UUID arenaId) {
|
||||
return this.arenas.get(arenaId);
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ public abstract class ArenaHandler<K extends Arena, S extends ArenaGroup<K, S>>
|
||||
* @param arenaName <p>The arena to get</p>
|
||||
* @return <p>The arena with the given name, or null if not found</p>
|
||||
*/
|
||||
public @Nullable K getArena(@NotNull String arenaName) {
|
||||
public @Nullable ArenaType getArena(@NotNull String arenaName) {
|
||||
try {
|
||||
return this.arenas.get(UUID.fromString(arenaName));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
@@ -163,7 +163,7 @@ public abstract class ArenaHandler<K extends Arena, S extends ArenaGroup<K, S>>
|
||||
*
|
||||
* @return <p>All known arenas</p>
|
||||
*/
|
||||
public @NotNull Map<UUID, K> getArenas() {
|
||||
public @NotNull Map<UUID, ArenaType> getArenas() {
|
||||
return new HashMap<>(this.arenas);
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ public abstract class ArenaHandler<K extends Arena, S extends ArenaGroup<K, S>>
|
||||
*
|
||||
* @param arena <p>The arena to remove</p>
|
||||
*/
|
||||
public void removeArena(@NotNull K arena) {
|
||||
public void removeArena(@NotNull ArenaType arena) {
|
||||
UUID arenaId = arena.getArenaId();
|
||||
this.playerRegistry.removeForArena(arena, false);
|
||||
this.arenas.remove(arenaId);
|
||||
@@ -190,8 +190,8 @@ public abstract class ArenaHandler<K extends Arena, S extends ArenaGroup<K, S>>
|
||||
*
|
||||
* @param arenaId <p>The id of the arena whose data should be saved</p>
|
||||
*/
|
||||
public void saveData(UUID arenaId) {
|
||||
K arena = getArena(arenaId);
|
||||
public void saveData(@NotNull UUID arenaId) {
|
||||
ArenaType arena = getArena(arenaId);
|
||||
if (arena != null) {
|
||||
if (!arena.saveData()) {
|
||||
MiniGames.log(Level.WARNING, "Unable to save data for arena with id " + arenaId +
|
||||
|
||||
@@ -54,6 +54,7 @@ public abstract class ArenaRecordsRegistry implements ConfigurationSerializable
|
||||
*
|
||||
* @return <p>Existing death records</p>
|
||||
*/
|
||||
@NotNull
|
||||
public Set<SummableArenaRecord<Integer>> getLeastDeathsRecords() {
|
||||
return new HashSet<>(this.leastDeaths);
|
||||
}
|
||||
@@ -63,6 +64,7 @@ public abstract class ArenaRecordsRegistry implements ConfigurationSerializable
|
||||
*
|
||||
* @return <p>Existing time records</p>
|
||||
*/
|
||||
@NotNull
|
||||
public Set<SummableArenaRecord<Long>> getShortestTimeMilliSecondsRecords() {
|
||||
return new HashSet<>(this.shortestTimeMilliSeconds);
|
||||
}
|
||||
@@ -74,7 +76,8 @@ public abstract class ArenaRecordsRegistry implements ConfigurationSerializable
|
||||
* @param deaths <p>The number of deaths suffered before the player finished the arena</p>
|
||||
* @return <p>The result explaining what type of record was achieved</p>
|
||||
*/
|
||||
public @NotNull RecordResult registerDeathRecord(@NotNull UUID playerId, int deaths) {
|
||||
@NotNull
|
||||
public RecordResult registerDeathRecord(@NotNull UUID playerId, int deaths) {
|
||||
Consumer<Integer> consumer = (value) -> {
|
||||
leastDeaths.removeIf((item) -> item.getUserId().equals(playerId));
|
||||
leastDeaths.add(new IntegerRecord(playerId, value));
|
||||
@@ -89,7 +92,8 @@ public abstract class ArenaRecordsRegistry implements ConfigurationSerializable
|
||||
* @param milliseconds <p>The number of milliseconds it took the player to finish the dropper arena</p>
|
||||
* @return <p>The result explaining what type of record was achieved</p>
|
||||
*/
|
||||
public @NotNull RecordResult registerTimeRecord(@NotNull UUID playerId, long milliseconds) {
|
||||
@NotNull
|
||||
public RecordResult registerTimeRecord(@NotNull UUID playerId, long milliseconds) {
|
||||
Consumer<Long> consumer = (value) -> {
|
||||
shortestTimeMilliSeconds.removeIf((item) -> item.getUserId().equals(playerId));
|
||||
shortestTimeMilliSeconds.add(new LongRecord(playerId, value));
|
||||
@@ -111,9 +115,10 @@ public abstract class ArenaRecordsRegistry implements ConfigurationSerializable
|
||||
* @param amount <p>The amount of whatever the player achieved</p>
|
||||
* @return <p>The result of the player's record attempt</p>
|
||||
*/
|
||||
private <T extends Comparable<T>> @NotNull RecordResult registerRecord(@NotNull Set<ArenaRecord<T>> existingRecords,
|
||||
@NotNull Consumer<T> recordSetter,
|
||||
@NotNull UUID playerId, T amount) {
|
||||
@NotNull
|
||||
private <RecordType extends Comparable<RecordType>> RecordResult registerRecord(@NotNull Set<ArenaRecord<RecordType>> existingRecords,
|
||||
@NotNull Consumer<RecordType> recordSetter,
|
||||
@NotNull UUID playerId, RecordType amount) {
|
||||
RecordResult result;
|
||||
if (existingRecords.stream().allMatch((entry) -> amount.compareTo(entry.getRecord()) < 0)) {
|
||||
// If the given value is less than all other values, that's a world record!
|
||||
@@ -123,7 +128,7 @@ public abstract class ArenaRecordsRegistry implements ConfigurationSerializable
|
||||
return result;
|
||||
}
|
||||
|
||||
ArenaRecord<T> playerRecord = getRecord(existingRecords, playerId);
|
||||
ArenaRecord<RecordType> playerRecord = getRecord(existingRecords, playerId);
|
||||
if (playerRecord != null && amount.compareTo(playerRecord.getRecord()) < 0) {
|
||||
// If the given value is less than the player's previous value, that's a personal best!
|
||||
result = RecordResult.PERSONAL_BEST;
|
||||
@@ -146,12 +151,13 @@ public abstract class ArenaRecordsRegistry implements ConfigurationSerializable
|
||||
*
|
||||
* @param existingRecords <p>The existing records to look through</p>
|
||||
* @param playerId <p>The id of the player to look for</p>
|
||||
* @param <T> <p>The type of the stored record</p>
|
||||
* @param <RecordType> <p>The type of the stored record</p>
|
||||
* @return <p>The record, or null if not found</p>
|
||||
*/
|
||||
private <T extends Comparable<T>> @Nullable ArenaRecord<T> getRecord(@NotNull Set<ArenaRecord<T>> existingRecords,
|
||||
@NotNull UUID playerId) {
|
||||
AtomicReference<ArenaRecord<T>> record = new AtomicReference<>();
|
||||
@Nullable
|
||||
private <RecordType extends Comparable<RecordType>> ArenaRecord<RecordType> getRecord(@NotNull Set<ArenaRecord<RecordType>> existingRecords,
|
||||
@NotNull UUID playerId) {
|
||||
AtomicReference<ArenaRecord<RecordType>> record = new AtomicReference<>();
|
||||
existingRecords.forEach((item) -> {
|
||||
if (item.getUserId().equals(playerId)) {
|
||||
record.set(item);
|
||||
|
||||
@@ -35,23 +35,27 @@ public class DropperArena implements Arena {
|
||||
/**
|
||||
* An unique and persistent identifier for this arena
|
||||
*/
|
||||
@NotNull
|
||||
private final UUID arenaId;
|
||||
|
||||
/**
|
||||
* A name used when listing and storing this arena.
|
||||
*/
|
||||
private @NotNull String arenaName;
|
||||
@NotNull
|
||||
private String arenaName;
|
||||
|
||||
/**
|
||||
* The location players are teleported to when joining this arena.
|
||||
*/
|
||||
private @NotNull Location spawnLocation;
|
||||
@NotNull
|
||||
private Location spawnLocation;
|
||||
|
||||
/**
|
||||
* The location players will be sent to when they win or lose the arena. If not set, their entry location should be
|
||||
* used instead.
|
||||
*/
|
||||
private @Nullable Location exitLocation;
|
||||
@Nullable
|
||||
private Location exitLocation;
|
||||
|
||||
/**
|
||||
* The velocity in the y-direction to apply to all players in this arena.
|
||||
@@ -73,27 +77,34 @@ public class DropperArena implements Arena {
|
||||
/**
|
||||
* Types of damage that won't be blocked in this arena
|
||||
*/
|
||||
@NotNull
|
||||
private Set<EntityDamageEvent.DamageCause> allowedDamageCauses;
|
||||
|
||||
/**
|
||||
* Types of damage that will trigger a loss in this arena
|
||||
*/
|
||||
@NotNull
|
||||
private Set<EntityDamageEvent.DamageCause> lossTriggerDamageCauses;
|
||||
|
||||
/**
|
||||
* The material of the block players have to hit to win this dropper arena
|
||||
*/
|
||||
private @NotNull Material winBlockType;
|
||||
@NotNull
|
||||
private Material winBlockType;
|
||||
|
||||
/**
|
||||
* The arena data for this arena
|
||||
*/
|
||||
@NotNull
|
||||
private final DropperArenaData dropperArenaData;
|
||||
|
||||
@NotNull
|
||||
private final DropperArenaHandler dropperArenaHandler;
|
||||
|
||||
@NotNull
|
||||
private Map<RewardCondition, Set<Reward>> rewards = new HashMap<>();
|
||||
|
||||
@NotNull
|
||||
private static final DropperConfiguration dropperConfiguration = MiniGames.getInstance().getDropperConfiguration();
|
||||
|
||||
/**
|
||||
@@ -168,27 +179,32 @@ public class DropperArena implements Arena {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull DropperArenaData getData() {
|
||||
@NotNull
|
||||
public DropperArenaData getData() {
|
||||
return this.dropperArenaData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull UUID getArenaId() {
|
||||
@NotNull
|
||||
public UUID getArenaId() {
|
||||
return this.arenaId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getArenaName() {
|
||||
@NotNull
|
||||
public String getArenaName() {
|
||||
return this.arenaName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Location getSpawnLocation() {
|
||||
@NotNull
|
||||
public Location getSpawnLocation() {
|
||||
return this.spawnLocation.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Location getExitLocation() {
|
||||
@Nullable
|
||||
public Location getExitLocation() {
|
||||
return this.exitLocation != null ? this.exitLocation.clone() : null;
|
||||
}
|
||||
|
||||
@@ -206,7 +222,8 @@ public class DropperArena implements Arena {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<Reward> getRewards(RewardCondition rewardCondition) {
|
||||
@NotNull
|
||||
public Set<Reward> getRewards(@NotNull RewardCondition rewardCondition) {
|
||||
if (this.rewards.containsKey(rewardCondition) && this.rewards.get(rewardCondition) != null) {
|
||||
return this.rewards.get(rewardCondition);
|
||||
} else {
|
||||
@@ -231,12 +248,14 @@ public class DropperArena implements Arena {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<EntityDamageEvent.DamageCause> getAllowedDamageCauses() {
|
||||
@NotNull
|
||||
public Set<EntityDamageEvent.DamageCause> getAllowedDamageCauses() {
|
||||
return this.allowedDamageCauses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<EntityDamageEvent.DamageCause> getLossTriggerDamageCauses() {
|
||||
@NotNull
|
||||
public Set<EntityDamageEvent.DamageCause> getLossTriggerDamageCauses() {
|
||||
return this.lossTriggerDamageCauses;
|
||||
}
|
||||
|
||||
@@ -414,11 +433,8 @@ public class DropperArena implements Arena {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof DropperArena otherArena)) {
|
||||
return false;
|
||||
}
|
||||
return this.getArenaNameSanitized().equals(otherArena.getArenaNameSanitized());
|
||||
public boolean equals(@Nullable Object other) {
|
||||
return other instanceof DropperArena otherArena && this.getArenaNameSanitized().equals(otherArena.getArenaNameSanitized());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@ public class DropperArenaData extends ArenaData {
|
||||
* @return <p>The deserialized dropper arena data</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public static @NotNull DropperArenaData deserialize(@NotNull Map<String, Object> data) {
|
||||
@NotNull
|
||||
public static DropperArenaData deserialize(@NotNull Map<String, Object> data) {
|
||||
SerializableUUID serializableUUID = (SerializableUUID) data.get("arenaId");
|
||||
Map<ArenaGameMode, ArenaRecordsRegistry> recordsRegistry =
|
||||
(Map<ArenaGameMode, ArenaRecordsRegistry>) data.get("recordsRegistry");
|
||||
|
||||
@@ -77,8 +77,9 @@ public enum DropperArenaEditableProperty {
|
||||
*
|
||||
* @param argumentString <p>The argument string used to specify this property</p>
|
||||
*/
|
||||
DropperArenaEditableProperty(@NotNull String argumentString, Function<DropperArena, String> currentValueProvider,
|
||||
EditablePropertyType propertyType) {
|
||||
DropperArenaEditableProperty(@NotNull String argumentString,
|
||||
@NotNull Function<DropperArena, String> currentValueProvider,
|
||||
@NotNull EditablePropertyType propertyType) {
|
||||
this.argumentString = argumentString;
|
||||
this.currentValueProvider = currentValueProvider;
|
||||
this.propertyType = propertyType;
|
||||
@@ -89,6 +90,7 @@ public enum DropperArenaEditableProperty {
|
||||
*
|
||||
* @return <p>The type of this property</p>
|
||||
*/
|
||||
@NotNull
|
||||
public EditablePropertyType getPropertyType() {
|
||||
return this.propertyType;
|
||||
}
|
||||
@@ -99,7 +101,8 @@ public enum DropperArenaEditableProperty {
|
||||
* @param arena <p>The arena to check the value for</p>
|
||||
* @return <p>The current value as a string</p>
|
||||
*/
|
||||
public String getCurrentValueAsString(DropperArena arena) {
|
||||
@NotNull
|
||||
public String getCurrentValueAsString(@NotNull DropperArena arena) {
|
||||
return this.currentValueProvider.apply(arena);
|
||||
}
|
||||
|
||||
@@ -108,7 +111,8 @@ public enum DropperArenaEditableProperty {
|
||||
*
|
||||
* @return <p>The argument string</p>
|
||||
*/
|
||||
public @NotNull String getArgumentString() {
|
||||
@NotNull
|
||||
public String getArgumentString() {
|
||||
return this.argumentString;
|
||||
}
|
||||
|
||||
@@ -118,7 +122,8 @@ public enum DropperArenaEditableProperty {
|
||||
* @param argumentString <p>The argument string used to specify an editable property</p>
|
||||
* @return <p>The corresponding editable property, or null if not found</p>
|
||||
*/
|
||||
public static @Nullable DropperArenaEditableProperty getFromArgumentString(String argumentString) {
|
||||
@Nullable
|
||||
public static DropperArenaEditableProperty getFromArgumentString(@NotNull String argumentString) {
|
||||
for (DropperArenaEditableProperty property : DropperArenaEditableProperty.values()) {
|
||||
if (property.argumentString.equalsIgnoreCase(argumentString)) {
|
||||
return property;
|
||||
|
||||
@@ -34,7 +34,8 @@ public enum DropperArenaGameMode implements ConfigurationSerializable, ArenaGame
|
||||
* @param gameMode <p>The game-mode string to match</p>
|
||||
* @return <p>The specified arena game-mode</p>
|
||||
*/
|
||||
public static @NotNull DropperArenaGameMode matchGameMode(@NotNull String gameMode) {
|
||||
@NotNull
|
||||
public static DropperArenaGameMode matchGameMode(@NotNull String gameMode) {
|
||||
String sanitized = gameMode.trim().toLowerCase();
|
||||
if (sanitized.matches("(invert(ed)?|inverse)")) {
|
||||
return DropperArenaGameMode.INVERTED;
|
||||
@@ -60,12 +61,14 @@ public enum DropperArenaGameMode implements ConfigurationSerializable, ArenaGame
|
||||
* @return <p>The deserialized arena game-mode</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static DropperArenaGameMode deserialize(Map<String, Object> data) {
|
||||
@NotNull
|
||||
public static DropperArenaGameMode deserialize(@NotNull Map<String, Object> data) {
|
||||
return DropperArenaGameMode.valueOf((String) data.get("name"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull DropperArenaGameMode[] getValues() {
|
||||
@NotNull
|
||||
public DropperArenaGameMode[] getValues() {
|
||||
return DropperArenaGameMode.values();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,8 @@ public class DropperArenaGroup extends ArenaGroup<DropperArena, DropperArenaGrou
|
||||
* @return <p>The deserialized arena group</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public static @NotNull DropperArenaGroup deserialize(@NotNull Map<String, Object> data) {
|
||||
@NotNull
|
||||
public static DropperArenaGroup deserialize(@NotNull Map<String, Object> data) {
|
||||
UUID id = ((SerializableUUID) data.get("groupId")).getRawValue();
|
||||
String name = (String) data.get("groupName");
|
||||
List<SerializableUUID> serializableArenas = (List<SerializableUUID>) data.get("arenas");
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.knarcraft.minigames.arena.ArenaHandler;
|
||||
import net.knarcraft.minigames.arena.ArenaPlayerRegistry;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.util.DropperArenaStorageHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
@@ -24,7 +25,7 @@ public class DropperArenaHandler extends ArenaHandler<DropperArena, DropperArena
|
||||
*
|
||||
* @param playerRegistry <p>The registry keeping track of player sessions</p>
|
||||
*/
|
||||
public DropperArenaHandler(ArenaPlayerRegistry<DropperArena> playerRegistry) {
|
||||
public DropperArenaHandler(@NotNull ArenaPlayerRegistry<DropperArena> playerRegistry) {
|
||||
super(playerRegistry);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.knarcraft.minigames.arena.dropper;
|
||||
|
||||
import net.knarcraft.minigames.arena.AbstractArenaPlayerRegistry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A registry to keep track of which players are playing in which arenas
|
||||
@@ -8,6 +9,7 @@ import net.knarcraft.minigames.arena.AbstractArenaPlayerRegistry;
|
||||
public class DropperArenaPlayerRegistry extends AbstractArenaPlayerRegistry<DropperArena> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String getEntryStateStorageKey() {
|
||||
return "dropper";
|
||||
}
|
||||
|
||||
@@ -50,7 +50,8 @@ public class DropperArenaRecordsRegistry extends ArenaRecordsRegistry {
|
||||
* @return <p>The deserialized records registry</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public static DropperArenaRecordsRegistry deserialize(Map<String, Object> data) {
|
||||
@NotNull
|
||||
public static DropperArenaRecordsRegistry deserialize(@NotNull Map<String, Object> data) {
|
||||
UUID arenaId = ((SerializableUUID) data.get("arenaId")).getRawValue();
|
||||
Set<IntegerRecord> leastDeaths =
|
||||
(Set<IntegerRecord>) data.getOrDefault("leastDeaths", new HashMap<>());
|
||||
|
||||
@@ -23,9 +23,12 @@ import java.util.logging.Level;
|
||||
*/
|
||||
public class DropperArenaSession extends AbstractArenaSession {
|
||||
|
||||
private final @NotNull DropperArena arena;
|
||||
private final @NotNull Player player;
|
||||
private final @NotNull DropperArenaGameMode gameMode;
|
||||
@NotNull
|
||||
private final DropperArena arena;
|
||||
@NotNull
|
||||
private final Player player;
|
||||
@NotNull
|
||||
private final DropperArenaGameMode gameMode;
|
||||
private boolean startedMoving = false;
|
||||
|
||||
/**
|
||||
@@ -67,7 +70,8 @@ public class DropperArenaSession extends AbstractArenaSession {
|
||||
*
|
||||
* @return <p>This session's player</p>
|
||||
*/
|
||||
public @NotNull Player getPlayer() {
|
||||
@NotNull
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
@@ -76,12 +80,14 @@ public class DropperArenaSession extends AbstractArenaSession {
|
||||
*
|
||||
* @return <p>The game-mode for this session</p>
|
||||
*/
|
||||
public @NotNull DropperArenaGameMode getGameMode() {
|
||||
@NotNull
|
||||
public DropperArenaGameMode getGameMode() {
|
||||
return this.gameMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PlayerEntryState getEntryState() {
|
||||
@NotNull
|
||||
public PlayerEntryState getEntryState() {
|
||||
return this.entryState;
|
||||
}
|
||||
|
||||
@@ -120,12 +126,14 @@ public class DropperArenaSession extends AbstractArenaSession {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull DropperArena getArena() {
|
||||
@NotNull
|
||||
public DropperArena getArena() {
|
||||
return this.arena;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ArenaGUI getGUI() {
|
||||
@NotNull
|
||||
public ArenaGUI getGUI() {
|
||||
if (GeyserHelper.isGeyserPlayer(this.player)) {
|
||||
return new DropperGUIBedrock(this.player);
|
||||
} else {
|
||||
@@ -151,6 +159,7 @@ public class DropperArenaSession extends AbstractArenaSession {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String getGameModeString() {
|
||||
return switch (this.gameMode) {
|
||||
case DEFAULT -> "default";
|
||||
|
||||
@@ -69,7 +69,8 @@ public enum DropperArenaStorageKey implements StorageKey {
|
||||
LOSS_TRIGGER_DAMAGE_CAUSES("lossTriggerDamageCauses"),
|
||||
;
|
||||
|
||||
private final @NotNull String key;
|
||||
@NotNull
|
||||
private final String key;
|
||||
|
||||
/**
|
||||
* Instantiates a new arena storage key
|
||||
@@ -81,7 +82,8 @@ public enum DropperArenaStorageKey implements StorageKey {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getKey() {
|
||||
@NotNull
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ public class DropperPlayerEntryState extends AbstractPlayerEntryState {
|
||||
|
||||
private final float originalFlySpeed;
|
||||
private final float horizontalVelocity;
|
||||
@NotNull
|
||||
private final DropperArenaGameMode arenaGameMode;
|
||||
|
||||
/**
|
||||
@@ -118,7 +119,8 @@ public class DropperPlayerEntryState extends AbstractPlayerEntryState {
|
||||
* @return <p>The data to deserialize</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public static DropperPlayerEntryState deserialize(Map<String, Object> data) {
|
||||
@NotNull
|
||||
public static DropperPlayerEntryState deserialize(@NotNull Map<String, Object> data) {
|
||||
UUID playerId = ((SerializableUUID) data.get("playerId")).getRawValue();
|
||||
Location entryLocation = (Location) data.get("entryLocation");
|
||||
boolean originalIsFlying = getBoolean(data, "originalIsFlying");
|
||||
|
||||
@@ -38,53 +38,63 @@ public class ParkourArena implements Arena {
|
||||
/**
|
||||
* An unique and persistent identifier for this arena
|
||||
*/
|
||||
private final @NotNull UUID arenaId;
|
||||
@NotNull
|
||||
private final UUID arenaId;
|
||||
|
||||
/**
|
||||
* A name used when listing and storing this arena.
|
||||
*/
|
||||
private @NotNull String arenaName;
|
||||
@NotNull
|
||||
private String arenaName;
|
||||
|
||||
/**
|
||||
* The location players are teleported to when joining this arena.
|
||||
*/
|
||||
private @NotNull Location spawnLocation;
|
||||
@NotNull
|
||||
private Location spawnLocation;
|
||||
|
||||
/**
|
||||
* The location players will be sent to when they win or lose the arena. If not set, their entry location should be
|
||||
* used instead.
|
||||
*/
|
||||
private @Nullable Location exitLocation;
|
||||
@Nullable
|
||||
private Location exitLocation;
|
||||
|
||||
/**
|
||||
* The material of the block players have to hit to win this parkour arena
|
||||
*/
|
||||
private @NotNull Material winBlockType;
|
||||
@NotNull
|
||||
private Material winBlockType;
|
||||
|
||||
/**
|
||||
* The location the player has to reach to win. If not set, winBlockType is used instead
|
||||
*/
|
||||
private @Nullable Location winLocation;
|
||||
@Nullable
|
||||
private Location winLocation;
|
||||
|
||||
/**
|
||||
* The names of the block types constituting this arena's kill plane
|
||||
*/
|
||||
private @Nullable Set<String> killPlaneBlockNames;
|
||||
@Nullable
|
||||
private Set<String> killPlaneBlockNames;
|
||||
|
||||
/**
|
||||
* The block types constituting this arena's kill plane
|
||||
*/
|
||||
private @Nullable Set<Material> killPlaneBlocks;
|
||||
@Nullable
|
||||
private Set<Material> killPlaneBlocks;
|
||||
|
||||
/**
|
||||
* The names of the block types serving as obstacles for this arena
|
||||
*/
|
||||
private @Nullable Set<String> obstacleBlockNames;
|
||||
@Nullable
|
||||
private Set<String> obstacleBlockNames;
|
||||
|
||||
/**
|
||||
* The block types serving as obstacles for this arena
|
||||
*/
|
||||
private @Nullable Set<Material> obstacleBlocks;
|
||||
@Nullable
|
||||
private Set<Material> obstacleBlocks;
|
||||
|
||||
/**
|
||||
* The maximum amount of players able to join this arena at any time
|
||||
@@ -94,25 +104,31 @@ public class ParkourArena implements Arena {
|
||||
/**
|
||||
* Types of damage that won't be blocked in this arena
|
||||
*/
|
||||
@NotNull
|
||||
private Set<EntityDamageEvent.DamageCause> allowedDamageCauses;
|
||||
|
||||
/**
|
||||
* Types of damage that will trigger a loss in this arena
|
||||
*/
|
||||
@NotNull
|
||||
private Set<EntityDamageEvent.DamageCause> lossTriggerDamageCauses;
|
||||
|
||||
/**
|
||||
* The checkpoints for this arena. Entering a checkpoint overrides the player's spawn location.
|
||||
*/
|
||||
private final @NotNull List<Location> checkpoints;
|
||||
@NotNull
|
||||
private final List<Location> checkpoints;
|
||||
|
||||
/**
|
||||
* The arena data for this arena
|
||||
*/
|
||||
private final @NotNull ParkourArenaData parkourArenaData;
|
||||
@NotNull
|
||||
private final ParkourArenaData parkourArenaData;
|
||||
|
||||
private final @NotNull ParkourArenaHandler parkourArenaHandler;
|
||||
@NotNull
|
||||
private final ParkourArenaHandler parkourArenaHandler;
|
||||
|
||||
@NotNull
|
||||
private Map<RewardCondition, Set<Reward>> rewards = new HashMap<>();
|
||||
|
||||
/**
|
||||
@@ -198,27 +214,32 @@ public class ParkourArena implements Arena {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ParkourArenaData getData() {
|
||||
@NotNull
|
||||
public ParkourArenaData getData() {
|
||||
return this.parkourArenaData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull UUID getArenaId() {
|
||||
@NotNull
|
||||
public UUID getArenaId() {
|
||||
return this.arenaId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getArenaName() {
|
||||
@NotNull
|
||||
public String getArenaName() {
|
||||
return this.arenaName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Location getSpawnLocation() {
|
||||
@NotNull
|
||||
public Location getSpawnLocation() {
|
||||
return this.spawnLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Location getExitLocation() {
|
||||
@Nullable
|
||||
public Location getExitLocation() {
|
||||
return this.exitLocation;
|
||||
}
|
||||
|
||||
@@ -236,7 +257,8 @@ public class ParkourArena implements Arena {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<Reward> getRewards(RewardCondition rewardCondition) {
|
||||
@NotNull
|
||||
public Set<Reward> getRewards(@NotNull RewardCondition rewardCondition) {
|
||||
if (this.rewards.containsKey(rewardCondition)) {
|
||||
return this.rewards.get(rewardCondition);
|
||||
} else {
|
||||
@@ -261,12 +283,14 @@ public class ParkourArena implements Arena {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<EntityDamageEvent.DamageCause> getAllowedDamageCauses() {
|
||||
@NotNull
|
||||
public Set<EntityDamageEvent.DamageCause> getAllowedDamageCauses() {
|
||||
return this.allowedDamageCauses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<EntityDamageEvent.DamageCause> getLossTriggerDamageCauses() {
|
||||
@NotNull
|
||||
public Set<EntityDamageEvent.DamageCause> getLossTriggerDamageCauses() {
|
||||
return this.lossTriggerDamageCauses;
|
||||
}
|
||||
|
||||
@@ -297,7 +321,8 @@ public class ParkourArena implements Arena {
|
||||
*
|
||||
* @return <p>The win trigger's location</p>
|
||||
*/
|
||||
public @Nullable Location getWinLocation() {
|
||||
@Nullable
|
||||
public Location getWinLocation() {
|
||||
return this.winLocation != null ? this.winLocation.clone() : null;
|
||||
}
|
||||
|
||||
@@ -306,7 +331,8 @@ public class ParkourArena implements Arena {
|
||||
*
|
||||
* @return <p>The types of blocks that cause a loss</p>
|
||||
*/
|
||||
public @NotNull Set<Material> getKillPlaneBlocks() {
|
||||
@NotNull
|
||||
public Set<Material> getKillPlaneBlocks() {
|
||||
if (this.killPlaneBlocks != null) {
|
||||
return new HashSet<>(this.killPlaneBlocks);
|
||||
} else {
|
||||
@@ -319,7 +345,8 @@ public class ParkourArena implements Arena {
|
||||
*
|
||||
* @return <p>The names of the types of blocks that cause a loss</p>
|
||||
*/
|
||||
public @Nullable Set<String> getKillPlaneBlockNames() {
|
||||
@Nullable
|
||||
public Set<String> getKillPlaneBlockNames() {
|
||||
return this.killPlaneBlockNames;
|
||||
}
|
||||
|
||||
@@ -328,7 +355,8 @@ public class ParkourArena implements Arena {
|
||||
*
|
||||
* @return <p>The types of blocks used as obstacles</p>
|
||||
*/
|
||||
public @NotNull Set<Material> getObstacleBlocks() {
|
||||
@NotNull
|
||||
public Set<Material> getObstacleBlocks() {
|
||||
if (this.obstacleBlocks != null) {
|
||||
return new HashSet<>(this.obstacleBlocks);
|
||||
} else {
|
||||
@@ -341,7 +369,8 @@ public class ParkourArena implements Arena {
|
||||
*
|
||||
* @return <p>The names of the blocks used as this arena's obstacle blocks</p>
|
||||
*/
|
||||
public @Nullable Set<String> getObstacleBlockNames() {
|
||||
@Nullable
|
||||
public Set<String> getObstacleBlockNames() {
|
||||
return this.obstacleBlockNames;
|
||||
}
|
||||
|
||||
@@ -350,6 +379,7 @@ public class ParkourArena implements Arena {
|
||||
*
|
||||
* @return <p>All checkpoint locations for this arena</p>
|
||||
*/
|
||||
@NotNull
|
||||
public List<Location> getCheckpoints() {
|
||||
List<Location> copy = new ArrayList<>(this.checkpoints.size());
|
||||
for (Location location : this.checkpoints) {
|
||||
@@ -569,11 +599,8 @@ public class ParkourArena implements Arena {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof ParkourArena otherArena)) {
|
||||
return false;
|
||||
}
|
||||
return this.getArenaNameSanitized().equals(otherArena.getArenaNameSanitized());
|
||||
public boolean equals(@Nullable Object other) {
|
||||
return other instanceof ParkourArena otherArena && this.getArenaNameSanitized().equals(otherArena.getArenaNameSanitized());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@ public class ParkourArenaData extends ArenaData {
|
||||
* @return <p>The deserialized parkour arena data</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public static @NotNull ParkourArenaData deserialize(@NotNull Map<String, Object> data) {
|
||||
@NotNull
|
||||
public static ParkourArenaData deserialize(@NotNull Map<String, Object> data) {
|
||||
SerializableUUID serializableUUID = (SerializableUUID) data.get("arenaId");
|
||||
Map<ArenaGameMode, ArenaRecordsRegistry> recordsRegistry =
|
||||
(Map<ArenaGameMode, ArenaRecordsRegistry>) data.get("recordsRegistry");
|
||||
|
||||
@@ -91,8 +91,11 @@ public enum ParkourArenaEditableProperty {
|
||||
EditablePropertyType.DAMAGE_CAUSE_LIST),
|
||||
;
|
||||
|
||||
private final @NotNull String argumentString;
|
||||
@NotNull
|
||||
private final String argumentString;
|
||||
@NotNull
|
||||
private final Function<ParkourArena, String> currentValueProvider;
|
||||
@NotNull
|
||||
private final EditablePropertyType propertyType;
|
||||
|
||||
/**
|
||||
@@ -100,8 +103,8 @@ public enum ParkourArenaEditableProperty {
|
||||
*
|
||||
* @param argumentString <p>The argument string used to specify this property</p>
|
||||
*/
|
||||
ParkourArenaEditableProperty(@NotNull String argumentString, Function<ParkourArena, String> currentValueProvider,
|
||||
EditablePropertyType propertyType) {
|
||||
ParkourArenaEditableProperty(@NotNull String argumentString, @NotNull Function<ParkourArena, String> currentValueProvider,
|
||||
@NotNull EditablePropertyType propertyType) {
|
||||
this.argumentString = argumentString;
|
||||
this.currentValueProvider = currentValueProvider;
|
||||
this.propertyType = propertyType;
|
||||
@@ -112,6 +115,7 @@ public enum ParkourArenaEditableProperty {
|
||||
*
|
||||
* @return <p>The type of this property</p>
|
||||
*/
|
||||
@NotNull
|
||||
public EditablePropertyType getPropertyType() {
|
||||
return this.propertyType;
|
||||
}
|
||||
@@ -122,7 +126,8 @@ public enum ParkourArenaEditableProperty {
|
||||
* @param arena <p>The arena to check the value for</p>
|
||||
* @return <p>The current value as a string</p>
|
||||
*/
|
||||
public String getCurrentValueAsString(ParkourArena arena) {
|
||||
@NotNull
|
||||
public String getCurrentValueAsString(@NotNull ParkourArena arena) {
|
||||
return this.currentValueProvider.apply(arena);
|
||||
}
|
||||
|
||||
@@ -141,7 +146,8 @@ public enum ParkourArenaEditableProperty {
|
||||
* @param argumentString <p>The argument string used to specify an editable property</p>
|
||||
* @return <p>The corresponding editable property, or null if not found</p>
|
||||
*/
|
||||
public static @Nullable ParkourArenaEditableProperty getFromArgumentString(String argumentString) {
|
||||
@Nullable
|
||||
public static ParkourArenaEditableProperty getFromArgumentString(@NotNull String argumentString) {
|
||||
for (ParkourArenaEditableProperty property : ParkourArenaEditableProperty.values()) {
|
||||
if (property.argumentString.equalsIgnoreCase(argumentString)) {
|
||||
return property;
|
||||
|
||||
@@ -29,7 +29,8 @@ 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) {
|
||||
@NotNull
|
||||
public static ParkourArenaGameMode matchGameMode(@NotNull String gameMode) {
|
||||
try {
|
||||
return ParkourArenaGameMode.valueOf(gameMode.toUpperCase());
|
||||
} catch (IllegalArgumentException exception) {
|
||||
@@ -52,12 +53,14 @@ public enum ParkourArenaGameMode implements ConfigurationSerializable, ArenaGame
|
||||
* @return <p>The deserialized arena game-mode</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static ParkourArenaGameMode deserialize(Map<String, Object> data) {
|
||||
@NotNull
|
||||
public static ParkourArenaGameMode deserialize(@NotNull Map<String, Object> data) {
|
||||
return ParkourArenaGameMode.valueOf((String) data.get("name"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ParkourArenaGameMode[] getValues() {
|
||||
@NotNull
|
||||
public ParkourArenaGameMode[] getValues() {
|
||||
return ParkourArenaGameMode.values();
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,8 @@ public class ParkourArenaGroup extends ArenaGroup<ParkourArena, ParkourArenaGrou
|
||||
* @return <p>The deserialized arena group</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public static @NotNull ParkourArenaGroup deserialize(@NotNull Map<String, Object> data) {
|
||||
@NotNull
|
||||
public static ParkourArenaGroup deserialize(@NotNull Map<String, Object> data) {
|
||||
UUID id = ((SerializableUUID) data.get("groupId")).getRawValue();
|
||||
String name = (String) data.get("groupName");
|
||||
List<SerializableUUID> serializableArenas = (List<SerializableUUID>) data.get("arenas");
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.knarcraft.minigames.arena.ArenaHandler;
|
||||
import net.knarcraft.minigames.arena.ArenaPlayerRegistry;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.util.ParkourArenaStorageHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
@@ -24,7 +25,7 @@ public class ParkourArenaHandler extends ArenaHandler<ParkourArena, ParkourArena
|
||||
*
|
||||
* @param playerRegistry <p>The registry keeping track of player sessions</p>
|
||||
*/
|
||||
public ParkourArenaHandler(ArenaPlayerRegistry<ParkourArena> playerRegistry) {
|
||||
public ParkourArenaHandler(@NotNull ArenaPlayerRegistry<ParkourArena> playerRegistry) {
|
||||
super(playerRegistry);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.knarcraft.minigames.arena.parkour;
|
||||
|
||||
import net.knarcraft.minigames.arena.AbstractArenaPlayerRegistry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A registry to keep track of which players are playing in which arenas
|
||||
@@ -8,6 +9,7 @@ import net.knarcraft.minigames.arena.AbstractArenaPlayerRegistry;
|
||||
public class ParkourArenaPlayerRegistry extends AbstractArenaPlayerRegistry<ParkourArena> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String getEntryStateStorageKey() {
|
||||
return "parkour";
|
||||
}
|
||||
|
||||
@@ -51,7 +51,8 @@ public class ParkourArenaRecordsRegistry extends ArenaRecordsRegistry {
|
||||
* @return <p>The deserialized records registry</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public static ParkourArenaRecordsRegistry deserialize(Map<String, Object> data) {
|
||||
@NotNull
|
||||
public static ParkourArenaRecordsRegistry deserialize(@NotNull Map<String, Object> data) {
|
||||
UUID arenaId = ((SerializableUUID) data.get("arenaId")).getRawValue();
|
||||
Set<IntegerRecord> leastDeaths =
|
||||
(Set<IntegerRecord>) data.getOrDefault("leastDeaths", new HashMap<>());
|
||||
|
||||
@@ -33,11 +33,16 @@ import java.util.logging.Level;
|
||||
*/
|
||||
public class ParkourArenaSession extends AbstractArenaSession {
|
||||
|
||||
private static final @NotNull Map<Arena, Set<Block>> changedLevers = new HashMap<>();
|
||||
private final @NotNull ParkourArena arena;
|
||||
private final @NotNull Player player;
|
||||
private final @NotNull ParkourArenaGameMode gameMode;
|
||||
private @Nullable Location reachedCheckpoint = null;
|
||||
@NotNull
|
||||
private static final Map<Arena, Set<Block>> changedLevers = new HashMap<>();
|
||||
@NotNull
|
||||
private final ParkourArena arena;
|
||||
@NotNull
|
||||
private final Player player;
|
||||
@NotNull
|
||||
private final ParkourArenaGameMode gameMode;
|
||||
@Nullable
|
||||
private Location reachedCheckpoint = null;
|
||||
|
||||
/**
|
||||
* Instantiates a new parkour arena session
|
||||
@@ -62,7 +67,8 @@ public class ParkourArenaSession extends AbstractArenaSession {
|
||||
*
|
||||
* @return <p>The game-mode for this session</p>
|
||||
*/
|
||||
public @NotNull ParkourArenaGameMode getGameMode() {
|
||||
@NotNull
|
||||
public ParkourArenaGameMode getGameMode() {
|
||||
return this.gameMode;
|
||||
}
|
||||
|
||||
@@ -90,12 +96,14 @@ public class ParkourArenaSession extends AbstractArenaSession {
|
||||
*
|
||||
* @return <p>The registered checkpoint, or null if not set</p>
|
||||
*/
|
||||
public @Nullable Location getRegisteredCheckpoint() {
|
||||
@Nullable
|
||||
public Location getRegisteredCheckpoint() {
|
||||
return this.reachedCheckpoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PlayerEntryState getEntryState() {
|
||||
@NotNull
|
||||
public PlayerEntryState getEntryState() {
|
||||
return this.entryState;
|
||||
}
|
||||
|
||||
@@ -139,12 +147,14 @@ public class ParkourArenaSession extends AbstractArenaSession {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ParkourArena getArena() {
|
||||
@NotNull
|
||||
public ParkourArena getArena() {
|
||||
return this.arena;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ArenaGUI getGUI() {
|
||||
@NotNull
|
||||
public ArenaGUI getGUI() {
|
||||
if (GeyserHelper.isGeyserPlayer(this.player)) {
|
||||
return new ParkourGUIBedrock(this.player);
|
||||
} else {
|
||||
@@ -173,6 +183,7 @@ public class ParkourArenaSession extends AbstractArenaSession {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String getGameModeString() {
|
||||
return switch (this.gameMode) {
|
||||
case DEFAULT -> "default";
|
||||
|
||||
@@ -91,7 +91,8 @@ public enum ParkourArenaStorageKey implements StorageKey {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getKey() {
|
||||
@NotNull
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,10 +42,10 @@ public class ParkourPlayerEntryState extends AbstractPlayerEntryState {
|
||||
* @param originalHealth <p>The health of the player when joining the arena</p>
|
||||
* @param originalSaturation <p>The saturation of the player when joining the arena</p>
|
||||
*/
|
||||
public ParkourPlayerEntryState(@NotNull UUID playerId, Location entryLocation,
|
||||
boolean originalIsFlying, GameMode originalGameMode, boolean originalAllowFlight,
|
||||
public ParkourPlayerEntryState(@NotNull UUID playerId, @NotNull Location entryLocation,
|
||||
boolean originalIsFlying, @NotNull GameMode originalGameMode, boolean originalAllowFlight,
|
||||
boolean originalInvulnerable, boolean originalIsSwimming,
|
||||
boolean originalCollideAble, Collection<PotionEffect> originalPotionEffects,
|
||||
boolean originalCollideAble, @NotNull Collection<PotionEffect> originalPotionEffects,
|
||||
double originalHealth, float originalSaturation) {
|
||||
super(playerId, entryLocation, originalIsFlying, originalGameMode, originalAllowFlight,
|
||||
originalInvulnerable, originalIsSwimming, originalCollideAble, originalPotionEffects, originalHealth,
|
||||
@@ -70,7 +70,8 @@ public class ParkourPlayerEntryState extends AbstractPlayerEntryState {
|
||||
* @return <p>The data to deserialize</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public static ParkourPlayerEntryState deserialize(Map<String, Object> data) {
|
||||
@NotNull
|
||||
public static ParkourPlayerEntryState deserialize(@NotNull Map<String, Object> data) {
|
||||
UUID playerId = ((SerializableUUID) data.get("playerId")).getRawValue();
|
||||
Location entryLocation = (Location) data.get("entryLocation");
|
||||
boolean originalIsFlying = getBoolean(data, "originalIsFlying");
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.knarcraft.minigames.arena.record;
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -12,16 +13,16 @@ import java.util.UUID;
|
||||
/**
|
||||
* A record stored for an arena
|
||||
*/
|
||||
public abstract class ArenaRecord<K extends Comparable<K>> implements Comparable<ArenaRecord<K>>, ConfigurationSerializable {
|
||||
public abstract class ArenaRecord<RecordType extends Comparable<RecordType>> implements Comparable<ArenaRecord<RecordType>>, ConfigurationSerializable {
|
||||
|
||||
private final UUID userId;
|
||||
private final K record;
|
||||
private final RecordType record;
|
||||
|
||||
/**
|
||||
* @param userId <p>The id of the player that achieved the record</p>
|
||||
* @param record <p>The record achieved</p>
|
||||
*/
|
||||
public ArenaRecord(UUID userId, K record) {
|
||||
public ArenaRecord(@NotNull UUID userId, @NotNull RecordType record) {
|
||||
this.userId = userId;
|
||||
this.record = record;
|
||||
}
|
||||
@@ -31,6 +32,7 @@ public abstract class ArenaRecord<K extends Comparable<K>> implements Comparable
|
||||
*
|
||||
* @return <p>The record's achiever</p>
|
||||
*/
|
||||
@NotNull
|
||||
public UUID getUserId() {
|
||||
return userId;
|
||||
}
|
||||
@@ -40,7 +42,8 @@ public abstract class ArenaRecord<K extends Comparable<K>> implements Comparable
|
||||
*
|
||||
* @return <p>The record value</p>
|
||||
*/
|
||||
public K getRecord() {
|
||||
@NotNull
|
||||
public RecordType getRecord() {
|
||||
return record;
|
||||
}
|
||||
|
||||
@@ -52,12 +55,12 @@ public abstract class ArenaRecord<K extends Comparable<K>> implements Comparable
|
||||
public abstract String getAsString();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
public boolean equals(@Nullable Object other) {
|
||||
return other instanceof ArenaRecord<?> && userId.equals(((ArenaRecord<?>) other).userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull ArenaRecord<K> other) {
|
||||
public int compareTo(@NotNull ArenaRecord<RecordType> other) {
|
||||
return record.compareTo(other.record);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.knarcraft.minigames.arena.record;
|
||||
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -12,25 +13,29 @@ import java.util.UUID;
|
||||
public class IntegerRecord extends SummableArenaRecord<Integer> {
|
||||
|
||||
/**
|
||||
* Instantiates a new integer record
|
||||
*
|
||||
* @param userId <p>The id of the player that achieved the record</p>
|
||||
* @param record <p>The record achieved</p>
|
||||
*/
|
||||
public IntegerRecord(UUID userId, Integer record) {
|
||||
public IntegerRecord(@NotNull UUID userId, @NotNull Integer record) {
|
||||
super(userId, record);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getAsString() {
|
||||
return String.valueOf(this.getRecord());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SummableArenaRecord<Integer> sum(Integer value) {
|
||||
@NotNull
|
||||
public SummableArenaRecord<Integer> sum(@NotNull Integer value) {
|
||||
return new IntegerRecord(this.getUserId(), this.getRecord() + value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
public boolean equals(@Nullable Object other) {
|
||||
return other instanceof IntegerRecord && this.getUserId().equals(((IntegerRecord) other).getUserId());
|
||||
}
|
||||
|
||||
@@ -41,6 +46,7 @@ public class IntegerRecord extends SummableArenaRecord<Integer> {
|
||||
* @return <p>The deserialized data</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@NotNull
|
||||
public static IntegerRecord deserialize(@NotNull Map<String, Object> data) {
|
||||
return new IntegerRecord(((SerializableUUID) data.get("userId")).getRawValue(), (Integer) data.get("record"));
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.knarcraft.minigames.arena.record;
|
||||
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -12,24 +13,28 @@ import java.util.UUID;
|
||||
public class LongRecord extends SummableArenaRecord<Long> {
|
||||
|
||||
/**
|
||||
* Instantiates a new long record
|
||||
*
|
||||
* @param userId <p>The id of the player that achieved the record</p>
|
||||
* @param record <p>The record achieved</p>
|
||||
*/
|
||||
public LongRecord(UUID userId, Long record) {
|
||||
public LongRecord(@NotNull UUID userId, @NotNull Long record) {
|
||||
super(userId, record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
public boolean equals(@Nullable Object other) {
|
||||
return other instanceof LongRecord && this.getUserId().equals(((LongRecord) other).getUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SummableArenaRecord<Long> sum(Long value) {
|
||||
@NotNull
|
||||
public SummableArenaRecord<Long> sum(@NotNull Long value) {
|
||||
return new LongRecord(this.getUserId(), this.getRecord() + value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getAsString() {
|
||||
double seconds = getRecord() / 1000.0;
|
||||
double minutes = 0;
|
||||
@@ -52,6 +57,7 @@ public class LongRecord extends SummableArenaRecord<Long> {
|
||||
* @return <p>The deserialized data</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@NotNull
|
||||
public static LongRecord deserialize(@NotNull Map<String, Object> data) {
|
||||
return new LongRecord(((SerializableUUID) data.get("userId")).getRawValue(),
|
||||
((Number) data.get("record")).longValue());
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
package net.knarcraft.minigames.arena.record;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A type of arena record which can be summed together
|
||||
*
|
||||
* @param <K> <p>The type of the stored value</p>
|
||||
* @param <RecordType> <p>The type of the stored value</p>
|
||||
*/
|
||||
public abstract class SummableArenaRecord<K extends Comparable<K>> extends ArenaRecord<K> {
|
||||
public abstract class SummableArenaRecord<RecordType extends Comparable<RecordType>> extends ArenaRecord<RecordType> {
|
||||
|
||||
/**
|
||||
* @param userId <p>The id of the player that achieved the record</p>
|
||||
* @param record <p>The record achieved</p>
|
||||
*/
|
||||
public SummableArenaRecord(UUID userId, K record) {
|
||||
public SummableArenaRecord(@NotNull UUID userId, @NotNull RecordType record) {
|
||||
super(userId, record);
|
||||
}
|
||||
|
||||
@@ -23,6 +25,7 @@ public abstract class SummableArenaRecord<K extends Comparable<K>> extends Arena
|
||||
* @param value <p>The value to add to the existing value</p>
|
||||
* @return <p>A record with the sum of this record and the given value</p>
|
||||
*/
|
||||
public abstract SummableArenaRecord<K> sum(K value);
|
||||
@NotNull
|
||||
public abstract SummableArenaRecord<RecordType> sum(@NotNull RecordType value);
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,8 @@ public class CommandReward implements Reward {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull FormatBuilder getGrantMessage() {
|
||||
@NotNull
|
||||
public FormatBuilder getGrantMessage() {
|
||||
return new FormatBuilder(MiniGameMessage.SUCCESS_COMMAND_REWARDED).replace("{command}", command);
|
||||
}
|
||||
|
||||
@@ -50,6 +51,7 @@ public class CommandReward implements Reward {
|
||||
* @param input <p>The input containing a name placeholder</p>
|
||||
* @return <p>The input with the placeholder replaced</p>
|
||||
*/
|
||||
@NotNull
|
||||
private String replaceNamePlaceholder(@NotNull Player player, @NotNull String input) {
|
||||
return input.replaceAll("[<%(\\[{]player[_\\-]?(name)?[>%)\\]}]", player.getName());
|
||||
}
|
||||
@@ -61,7 +63,8 @@ public class CommandReward implements Reward {
|
||||
* @return <p>The deserialized data</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static CommandReward deserialize(Map<String, Object> data) {
|
||||
@NotNull
|
||||
public static CommandReward deserialize(@NotNull Map<String, Object> data) {
|
||||
return new CommandReward((String) data.get("command"));
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,8 @@ public class EconomyReward implements Reward {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull FormatBuilder getGrantMessage() {
|
||||
@NotNull
|
||||
public FormatBuilder getGrantMessage() {
|
||||
return new FormatBuilder(MiniGameMessage.SUCCESS_ECONOMY_REWARDED).replace("{currency}",
|
||||
EconomyManager.format(amount));
|
||||
}
|
||||
@@ -59,7 +60,8 @@ public class EconomyReward implements Reward {
|
||||
* @return <p>The deserialized data</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static EconomyReward deserialize(Map<String, Object> data) {
|
||||
@NotNull
|
||||
public static EconomyReward deserialize(@NotNull Map<String, Object> data) {
|
||||
return new EconomyReward((Double) data.get("amount"));
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,8 @@ public class ItemReward implements Reward {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull FormatBuilder getGrantMessage() {
|
||||
@NotNull
|
||||
public FormatBuilder getGrantMessage() {
|
||||
NamespacedKey key = item.getType().getKeyOrNull();
|
||||
String name = key == null ? "Unnamed item" : key.getKey().replace("_", " ");
|
||||
return new FormatBuilder(MiniGameMessage.SUCCESS_ITEM_REWARDED).
|
||||
@@ -65,7 +66,8 @@ public class ItemReward implements Reward {
|
||||
* @return <p>The deserialized data</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static ItemReward deserialize(Map<String, Object> data) {
|
||||
@NotNull
|
||||
public static ItemReward deserialize(@NotNull Map<String, Object> data) {
|
||||
return new ItemReward((ItemStack) data.get("item"));
|
||||
}
|
||||
|
||||
@@ -75,7 +77,7 @@ public class ItemReward implements Reward {
|
||||
* @param inventory <p>The inventory to check</p>
|
||||
* @return <p>True if the inventory can fit the item</p>
|
||||
*/
|
||||
private boolean canFitItem(Inventory inventory) {
|
||||
private boolean canFitItem(@NotNull Inventory inventory) {
|
||||
// If a slot is available, there is no problem
|
||||
if (inventory.firstEmpty() != -1) {
|
||||
return true;
|
||||
|
||||
@@ -48,7 +48,8 @@ public class PermissionReward implements Reward {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull FormatBuilder getGrantMessage() {
|
||||
@NotNull
|
||||
public FormatBuilder getGrantMessage() {
|
||||
if (world == null) {
|
||||
return new FormatBuilder(MiniGameMessage.SUCCESS_PERMISSION_REWARDED).replace("{permission}",
|
||||
permission);
|
||||
@@ -76,7 +77,8 @@ public class PermissionReward implements Reward {
|
||||
* @return <p>The deserialized data</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static PermissionReward deserialize(Map<String, Object> data) {
|
||||
@NotNull
|
||||
public static PermissionReward deserialize(@NotNull Map<String, Object> data) {
|
||||
World world = (World) data.getOrDefault("world", null);
|
||||
String permission = (String) data.get("permission");
|
||||
return new PermissionReward(world, permission);
|
||||
|
||||
@@ -50,7 +50,8 @@ public enum RewardCondition implements ConfigurationSerializable {
|
||||
* @param condition <p>The string specifying a reward condition</p>
|
||||
* @return <p>The matching reward condition, or null if not found</p>
|
||||
*/
|
||||
public static @Nullable RewardCondition getFromString(@NotNull String condition) {
|
||||
@Nullable
|
||||
public static RewardCondition getFromString(@NotNull String condition) {
|
||||
for (RewardCondition rewardCondition : RewardCondition.values()) {
|
||||
if (rewardCondition.name().equalsIgnoreCase(condition.replace("-", "_"))) {
|
||||
return rewardCondition;
|
||||
@@ -75,7 +76,8 @@ public enum RewardCondition implements ConfigurationSerializable {
|
||||
* @return <p>The deserialized reward condition</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused"})
|
||||
public static @NotNull RewardCondition deserialize(@NotNull Map<String, Object> data) {
|
||||
@NotNull
|
||||
public static RewardCondition deserialize(@NotNull Map<String, Object> data) {
|
||||
RewardCondition rewardCondition = getFromString(String.valueOf(data.get("condition")));
|
||||
return Objects.requireNonNullElse(rewardCondition, RewardCondition.FIRST_WIN);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.knarcraft.minigames.arena.reward;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* The type of a specific reward
|
||||
@@ -34,6 +35,7 @@ public enum RewardType {
|
||||
* @param condition <p>The string specifying a reward type</p>
|
||||
* @return <p>The matching reward type, or null if not found</p>
|
||||
*/
|
||||
@Nullable
|
||||
public static RewardType getFromString(@NotNull String condition) {
|
||||
for (RewardType rewardType : RewardType.values()) {
|
||||
if (rewardType.name().equalsIgnoreCase(condition.replace("-", "_"))) {
|
||||
|
||||
Reference in New Issue
Block a user