Parkour implementation safety save 2

This is just a safety save in case the code gets too broken to fix.
This commit is contained in:
Kristian Knarvik 2023-04-13 20:13:29 +02:00
parent 9a3f9841ab
commit 1acaebb3bc
77 changed files with 1168 additions and 847 deletions

View File

@ -1,4 +0,0 @@
package net.knarcraft.dropper.arena;
public interface ArenaGameMode {
}

View File

@ -1,4 +0,0 @@
package net.knarcraft.dropper.arena;
public interface ArenaRecordsRegistry {
}

View File

@ -1,199 +0,0 @@
package net.knarcraft.dropper.arena.dropper;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.ArenaRecordsRegistry;
import net.knarcraft.dropper.arena.record.ArenaRecord;
import net.knarcraft.dropper.arena.record.IntegerRecord;
import net.knarcraft.dropper.arena.record.LongRecord;
import net.knarcraft.dropper.arena.record.SummableArenaRecord;
import net.knarcraft.dropper.container.SerializableUUID;
import net.knarcraft.dropper.property.RecordResult;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
/**
* A registry keeping track of all records
*/
public class DropperArenaRecordsRegistry implements ConfigurationSerializable, ArenaRecordsRegistry {
private final UUID arenaId;
private final @NotNull Set<IntegerRecord> leastDeaths;
private final @NotNull Set<LongRecord> shortestTimeMilliSeconds;
/**
* Instantiates a new empty records registry
*/
public DropperArenaRecordsRegistry(@NotNull UUID arenaId) {
this.arenaId = arenaId;
this.leastDeaths = new HashSet<>();
this.shortestTimeMilliSeconds = new HashSet<>();
}
/**
* Instantiates a new records registry
*
* @param leastDeaths <p>The existing least death records to use</p>
* @param shortestTimeMilliSeconds <p>The existing leash time records to use</p>
*/
private DropperArenaRecordsRegistry(@NotNull UUID arenaId, @NotNull Set<IntegerRecord> leastDeaths,
@NotNull Set<LongRecord> shortestTimeMilliSeconds) {
this.arenaId = arenaId;
this.leastDeaths = new HashSet<>(leastDeaths);
this.shortestTimeMilliSeconds = new HashSet<>(shortestTimeMilliSeconds);
}
/**
* Gets all existing death records
*
* @return <p>Existing death records</p>
*/
public Set<SummableArenaRecord<Integer>> getLeastDeathsRecords() {
return new HashSet<>(this.leastDeaths);
}
/**
* Gets all existing time records
*
* @return <p>Existing time records</p>
*/
public Set<SummableArenaRecord<Long>> getShortestTimeMilliSecondsRecords() {
return new HashSet<>(this.shortestTimeMilliSeconds);
}
/**
* Registers a new deaths-record
*
* @param playerId <p>The id of the player that performed the records</p>
* @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) {
Consumer<Integer> consumer = (value) -> {
leastDeaths.removeIf((item) -> item.getUserId().equals(playerId));
leastDeaths.add(new IntegerRecord(playerId, value));
};
Set<ArenaRecord<Integer>> asInt = new HashSet<>(leastDeaths);
return registerRecord(asInt, consumer, playerId, deaths);
}
/**
* Registers a new time-record
*
* @param playerId <p>The id of the player that performed the records</p>
* @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) {
Consumer<Long> consumer = (value) -> {
shortestTimeMilliSeconds.removeIf((item) -> item.getUserId().equals(playerId));
shortestTimeMilliSeconds.add(new LongRecord(playerId, value));
};
Set<ArenaRecord<Long>> asLong = new HashSet<>(shortestTimeMilliSeconds);
return registerRecord(asLong, consumer, playerId, milliseconds);
}
/**
* Saves changed records
*/
private void save() {
MiniGames.getInstance().getDropperArenaHandler().saveData(this.arenaId);
}
/**
* Registers a new record if applicable
*
* @param existingRecords <p>The map of existing records to use</p>
* @param recordSetter <p>The consumer used to set a new record</p>
* @param playerId <p>The id of the player that potentially achieved a record</p>
* @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) {
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!
result = RecordResult.WORLD_RECORD;
recordSetter.accept(amount);
save();
return result;
}
ArenaRecord<T> 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;
recordSetter.accept(amount);
save();
} else {
// Make sure to save the record if this is the user's first attempt
if (playerRecord == null) {
recordSetter.accept(amount);
save();
}
result = RecordResult.NONE;
}
return result;
}
/**
* Gets the record stored for the given player
*
* @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>
* @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<>();
existingRecords.forEach((item) -> {
if (item.getUserId().equals(playerId)) {
record.set(item);
}
});
return record.get();
}
@NotNull
@Override
public Map<String, Object> serialize() {
Map<String, Object> data = new HashMap<>();
data.put("arenaId", new SerializableUUID(this.arenaId));
data.put("leastDeaths", this.leastDeaths);
data.put("shortestTime", this.shortestTimeMilliSeconds);
return data;
}
/**
* Deserializes the given data
*
* @param data <p>The data to deserialize</p>
* @return <p>The deserialized records registry</p>
*/
@SuppressWarnings({"unused", "unchecked"})
public static DropperArenaRecordsRegistry deserialize(Map<String, Object> data) {
UUID arenaId = ((SerializableUUID) data.get("arenaId")).uuid();
Set<IntegerRecord> leastDeaths =
(Set<IntegerRecord>) data.getOrDefault("leastDeaths", new HashMap<>());
Set<LongRecord> shortestTimeMilliseconds =
(Set<LongRecord>) data.getOrDefault("shortestTime", new HashMap<>());
leastDeaths.removeIf(Objects::isNull);
shortestTimeMilliseconds.removeIf(Objects::isNull);
return new DropperArenaRecordsRegistry(arenaId, leastDeaths, shortestTimeMilliseconds);
}
}

View File

@ -1,127 +0,0 @@
package net.knarcraft.dropper.arena.parkour;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.container.SerializableUUID;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
/**
* Data stored for an arena
*
* @param arenaId <p>The id of the arena this data belongs to</p>
* @param recordRegistries <p>The records belonging to the arena</p>
* @param playersCompleted <p>A set of all player that have completed this arena</p>
*/
public record ParkourArenaData(@NotNull UUID arenaId,
@NotNull Map<ParkourArenaGameMode, ParkourArenaRecordsRegistry> recordRegistries,
@NotNull Map<ParkourArenaGameMode, Set<UUID>> playersCompleted) implements ConfigurationSerializable {
/**
* Instantiates a new dropper arena data object
*
* @param arenaId <p>The id of the arena this data belongs to</p>
* @param recordRegistries <p>The registry of this arena's records</p>
* @param playersCompleted <p>The set of the players that have cleared this arena</p>
*/
public ParkourArenaData(@NotNull UUID arenaId,
@NotNull Map<ParkourArenaGameMode, ParkourArenaRecordsRegistry> recordRegistries,
@NotNull Map<ParkourArenaGameMode, Set<UUID>> playersCompleted) {
this.arenaId = arenaId;
this.recordRegistries = recordRegistries;
this.playersCompleted = new HashMap<>(playersCompleted);
}
/**
* Gets whether the given player has cleared this arena
*
* @param player <p>The player to check</p>
* @return <p>True if the player has cleared the arena this data belongs to</p>
*/
public boolean hasNotCompleted(@NotNull ParkourArenaGameMode arenaGameMode, @NotNull Player player) {
return !this.playersCompleted.getOrDefault(arenaGameMode, new HashSet<>()).contains(player.getUniqueId());
}
/**
* Registers the given player as having completed this arena
*
* @param arenaGameMode <p>The game-mode the player completed</p>
* @param player <p>The player that completed this data's arena</p>
*/
public boolean addCompleted(@NotNull ParkourArenaGameMode arenaGameMode, @NotNull Player player) {
// Make sure to add an empty set to prevent a NullPointerException
if (!this.playersCompleted.containsKey(arenaGameMode)) {
this.playersCompleted.put(arenaGameMode, new HashSet<>());
}
boolean added = this.playersCompleted.get(arenaGameMode).add(player.getUniqueId());
// Persistently save the completion
if (added) {
MiniGames.getInstance().getDropperArenaHandler().saveData(this.arenaId);
}
return added;
}
@NotNull
@Override
public Map<String, Object> serialize() {
Map<String, Object> data = new HashMap<>();
data.put("arenaId", new SerializableUUID(this.arenaId));
data.put("recordsRegistry", this.recordRegistries);
// Convert normal UUIDs to serializable UUIDs
Map<ParkourArenaGameMode, Set<SerializableUUID>> serializablePlayersCompleted = new HashMap<>();
for (ParkourArenaGameMode arenaGameMode : this.playersCompleted.keySet()) {
Set<SerializableUUID> playersCompleted = new HashSet<>();
for (UUID playerCompleted : this.playersCompleted.get(arenaGameMode)) {
playersCompleted.add(new SerializableUUID(playerCompleted));
}
serializablePlayersCompleted.put(arenaGameMode, playersCompleted);
}
data.put("playersCompleted", serializablePlayersCompleted);
return data;
}
/**
* Deserializes a dropper arena data from the given data
*
* @param data <p>The data to deserialize</p>
* @return <p>The deserialized dropper arena data</p>
*/
@SuppressWarnings({"unused", "unchecked"})
public static @NotNull ParkourArenaData deserialize(@NotNull Map<String, Object> data) {
SerializableUUID serializableUUID = (SerializableUUID) data.get("arenaId");
Map<ParkourArenaGameMode, ParkourArenaRecordsRegistry> recordsRegistry =
(Map<ParkourArenaGameMode, ParkourArenaRecordsRegistry>) data.get("recordsRegistry");
Map<ParkourArenaGameMode, Set<SerializableUUID>> playersCompletedData =
(Map<ParkourArenaGameMode, Set<SerializableUUID>>) data.get("playersCompleted");
if (recordsRegistry == null) {
recordsRegistry = new HashMap<>();
} else if (playersCompletedData == null) {
playersCompletedData = new HashMap<>();
}
// Convert the serializable UUIDs to normal UUIDs
Map<ParkourArenaGameMode, Set<UUID>> allPlayersCompleted = new HashMap<>();
for (ParkourArenaGameMode arenaGameMode : playersCompletedData.keySet()) {
Set<UUID> playersCompleted = new HashSet<>();
for (SerializableUUID completedId : playersCompletedData.get(arenaGameMode)) {
playersCompleted.add(completedId.uuid());
}
allPlayersCompleted.put(arenaGameMode, playersCompleted);
if (!recordsRegistry.containsKey(arenaGameMode) || recordsRegistry.get(arenaGameMode) == null) {
recordsRegistry.put(arenaGameMode, new ParkourArenaRecordsRegistry(serializableUUID.uuid()));
}
}
return new ParkourArenaData(serializableUUID.uuid(), recordsRegistry, allPlayersCompleted);
}
}

View File

@ -1,37 +0,0 @@
package net.knarcraft.dropper.config;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
/**
* A configuration for a mini-game
*/
public abstract class MiniGameConfiguration {
protected FileConfiguration configuration;
/**
* Instantiates a new mini-game configuration
*
* @param configuration <p>The YAML configuration to use internally</p>
*/
public MiniGameConfiguration(@NotNull FileConfiguration configuration) {
this.configuration = configuration;
}
/**
* Loads all configuration values from disk
*
* @param configuration <p>The configuration to load</p>
*/
public void load(FileConfiguration configuration) {
this.configuration = configuration;
this.load();
}
/**
* Loads all configuration values from disk, using the current file configuration
*/
public abstract void load();
}

View File

@ -1,37 +0,0 @@
package net.knarcraft.dropper.container;
import org.bukkit.Material;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
/**
* A material container able to be serialized
*
* @param material <p>The material stored by this record</p>
*/
public record SerializableMaterial(Material material) implements ConfigurationSerializable {
@NotNull
@Override
public Map<String, Object> serialize() {
Map<String, Object> data = new HashMap<>();
data.put("name", material.name());
return data;
}
/**
* Deserializes a serialized material
*
* @param data <p>The serialized data</p>
* @return <p>The deserialized material</p>
*/
@SuppressWarnings("unused")
public static SerializableMaterial deserialize(Map<String, Object> data) {
Material material = Material.matchMaterial((String) data.getOrDefault("name", "AIR"));
return new SerializableMaterial(material);
}
}

View File

@ -1,37 +1,39 @@
package net.knarcraft.dropper;
package net.knarcraft.minigames;
import net.knarcraft.dropper.arena.dropper.DropperArenaData;
import net.knarcraft.dropper.arena.dropper.DropperArenaGameMode;
import net.knarcraft.dropper.arena.dropper.DropperArenaGroup;
import net.knarcraft.dropper.arena.dropper.DropperArenaHandler;
import net.knarcraft.dropper.arena.dropper.DropperArenaPlayerRegistry;
import net.knarcraft.dropper.arena.dropper.DropperArenaRecordsRegistry;
import net.knarcraft.dropper.arena.dropper.DropperArenaSession;
import net.knarcraft.dropper.arena.parkour.ParkourArenaHandler;
import net.knarcraft.dropper.arena.parkour.ParkourArenaPlayerRegistry;
import net.knarcraft.dropper.arena.record.IntegerRecord;
import net.knarcraft.dropper.arena.record.LongRecord;
import net.knarcraft.dropper.command.CreateArenaCommand;
import net.knarcraft.dropper.command.EditArenaCommand;
import net.knarcraft.dropper.command.EditArenaTabCompleter;
import net.knarcraft.dropper.command.GroupListCommand;
import net.knarcraft.dropper.command.GroupSetCommand;
import net.knarcraft.dropper.command.GroupSwapCommand;
import net.knarcraft.dropper.command.JoinArenaCommand;
import net.knarcraft.dropper.command.JoinArenaTabCompleter;
import net.knarcraft.dropper.command.LeaveArenaCommand;
import net.knarcraft.dropper.command.ListArenaCommand;
import net.knarcraft.dropper.command.ReloadCommand;
import net.knarcraft.dropper.command.RemoveArenaCommand;
import net.knarcraft.dropper.command.RemoveArenaTabCompleter;
import net.knarcraft.dropper.config.DropperConfiguration;
import net.knarcraft.dropper.container.SerializableMaterial;
import net.knarcraft.dropper.container.SerializableUUID;
import net.knarcraft.dropper.listener.CommandListener;
import net.knarcraft.dropper.listener.DamageListener;
import net.knarcraft.dropper.listener.MoveListener;
import net.knarcraft.dropper.listener.PlayerLeaveListener;
import net.knarcraft.dropper.placeholder.DropperRecordExpansion;
import net.knarcraft.minigames.arena.dropper.DropperArenaData;
import net.knarcraft.minigames.arena.dropper.DropperArenaGameMode;
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
import net.knarcraft.minigames.arena.dropper.DropperArenaPlayerRegistry;
import net.knarcraft.minigames.arena.dropper.DropperArenaRecordsRegistry;
import net.knarcraft.minigames.arena.dropper.DropperArenaSession;
import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler;
import net.knarcraft.minigames.arena.parkour.ParkourArenaPlayerRegistry;
import net.knarcraft.minigames.arena.record.IntegerRecord;
import net.knarcraft.minigames.arena.record.LongRecord;
import net.knarcraft.minigames.command.CreateArenaCommand;
import net.knarcraft.minigames.command.EditArenaCommand;
import net.knarcraft.minigames.command.EditArenaTabCompleter;
import net.knarcraft.minigames.command.GroupListCommand;
import net.knarcraft.minigames.command.GroupSetCommand;
import net.knarcraft.minigames.command.GroupSwapCommand;
import net.knarcraft.minigames.command.JoinArenaCommand;
import net.knarcraft.minigames.command.JoinArenaTabCompleter;
import net.knarcraft.minigames.command.LeaveArenaCommand;
import net.knarcraft.minigames.command.ListArenaCommand;
import net.knarcraft.minigames.command.ReloadCommand;
import net.knarcraft.minigames.command.RemoveArenaCommand;
import net.knarcraft.minigames.command.RemoveArenaTabCompleter;
import net.knarcraft.minigames.config.DropperConfiguration;
import net.knarcraft.minigames.config.ParkourConfiguration;
import net.knarcraft.minigames.config.SharedConfiguration;
import net.knarcraft.minigames.container.SerializableMaterial;
import net.knarcraft.minigames.container.SerializableUUID;
import net.knarcraft.minigames.listener.CommandListener;
import net.knarcraft.minigames.listener.DamageListener;
import net.knarcraft.minigames.listener.MoveListener;
import net.knarcraft.minigames.listener.PlayerLeaveListener;
import net.knarcraft.minigames.placeholder.DropperRecordExpansion;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
@ -52,7 +54,9 @@ import java.util.logging.Level;
public final class MiniGames extends JavaPlugin {
private static MiniGames instance;
private DropperConfiguration configuration;
private SharedConfiguration sharedConfiguration;
private DropperConfiguration dropperConfiguration;
private ParkourConfiguration parkourConfiguration;
private DropperArenaHandler dropperArenaHandler;
private DropperArenaPlayerRegistry dropperArenaPlayerRegistry;
private DropperRecordExpansion dropperRecordExpansion;
@ -104,13 +108,33 @@ public final class MiniGames extends JavaPlugin {
return this.parkourArenaPlayerRegistry;
}
/**
* Gets the shared configuration
*
* <p>The configuration for options which don't affect specific types of mini-games.</p>
*
* @return <p>The shared configuration</p>
*/
public SharedConfiguration getSharedConfiguration() {
return this.sharedConfiguration;
}
/**
* Gets the dropper configuration
*
* @return <p>The dropper configuration</p>
*/
public DropperConfiguration getDropperConfiguration() {
return this.configuration;
return this.dropperConfiguration;
}
/**
* Gets the parkour configuration
*
* @return <p>The parkour configuration</p>
*/
public ParkourConfiguration getParkourConfiguration() {
return this.parkourConfiguration;
}
/**
@ -133,7 +157,9 @@ public final class MiniGames extends JavaPlugin {
// Reload configuration
this.reloadConfig();
this.configuration.load(this.getConfig());
this.sharedConfiguration.load(this.getConfig());
this.dropperConfiguration.load(this.getConfig());
this.parkourConfiguration.load(this.getConfig());
// Clear record caches
this.dropperRecordExpansion.clearCaches();
@ -161,8 +187,9 @@ public final class MiniGames extends JavaPlugin {
getConfig().options().copyDefaults(true);
saveConfig();
reloadConfig();
this.configuration = new DropperConfiguration(this.getConfig());
this.configuration.load();
this.sharedConfiguration = new SharedConfiguration(this.getConfig());
this.dropperConfiguration = new DropperConfiguration(this.getConfig());
this.parkourConfiguration = new ParkourConfiguration(this.getConfig());
this.dropperArenaPlayerRegistry = new DropperArenaPlayerRegistry();
this.dropperArenaHandler = new DropperArenaHandler();
this.dropperArenaHandler.load();
@ -172,7 +199,7 @@ public final class MiniGames extends JavaPlugin {
PluginManager pluginManager = getServer().getPluginManager();
pluginManager.registerEvents(new DamageListener(), this);
pluginManager.registerEvents(new MoveListener(this.configuration), this);
pluginManager.registerEvents(new MoveListener(this.dropperConfiguration), this);
pluginManager.registerEvents(new PlayerLeaveListener(), this);
pluginManager.registerEvents(new CommandListener(), this);
@ -181,7 +208,7 @@ public final class MiniGames extends JavaPlugin {
registerCommand("dropperList", new ListArenaCommand(), null);
registerCommand("dropperJoin", new JoinArenaCommand(), new JoinArenaTabCompleter());
registerCommand("dropperLeave", new LeaveArenaCommand(), null);
registerCommand("dropperEdit", new EditArenaCommand(this.configuration), new EditArenaTabCompleter());
registerCommand("dropperEdit", new EditArenaCommand(this.dropperConfiguration), new EditArenaTabCompleter());
registerCommand("dropperRemove", new RemoveArenaCommand(), new RemoveArenaTabCompleter());
registerCommand("dropperGroupSet", new GroupSetCommand(), null);
registerCommand("dropperGroupSwap", new GroupSwapCommand(), null);

View File

@ -1,4 +1,4 @@
package net.knarcraft.dropper.arena;
package net.knarcraft.minigames.arena;
import org.jetbrains.annotations.NotNull;

View File

@ -1,6 +1,7 @@
package net.knarcraft.dropper.arena;
package net.knarcraft.minigames.arena;
import net.knarcraft.dropper.container.SerializableUUID;
import net.knarcraft.minigames.container.SerializableContainer;
import net.knarcraft.minigames.container.SerializableUUID;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -11,6 +12,8 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import static net.knarcraft.minigames.util.SerializableConverter.makeSerializable;
/**
* An interface describing generic arena data
*/
@ -43,6 +46,15 @@ public abstract class ArenaData implements ConfigurationSerializable {
return this.arenaId;
}
/**
* Gets all record registries
*
* @return <p>All record registries</p>
*/
public @NotNull Map<ArenaGameMode, ArenaRecordsRegistry> getRecordRegistries() {
return new HashMap<>(this.recordRegistries);
}
/**
* Gets whether the given player has cleared this arena
*
@ -87,14 +99,8 @@ public abstract class ArenaData implements ConfigurationSerializable {
data.put("recordsRegistry", this.recordRegistries);
// Convert normal UUIDs to serializable UUIDs
Map<ArenaGameMode, Set<SerializableUUID>> serializablePlayersCompleted = new HashMap<>();
for (ArenaGameMode arenaGameMode : this.playersCompleted.keySet()) {
Set<SerializableUUID> playersCompleted = new HashSet<>();
for (UUID playerCompleted : this.playersCompleted.get(arenaGameMode)) {
playersCompleted.add(new SerializableUUID(playerCompleted));
}
serializablePlayersCompleted.put(arenaGameMode, playersCompleted);
}
Map<ArenaGameMode, Set<SerializableContainer<UUID>>> serializablePlayersCompleted = new HashMap<>();
makeSerializable(this.playersCompleted, serializablePlayersCompleted, new SerializableUUID(null));
data.put("playersCompleted", serializablePlayersCompleted);
return data;
}

View File

@ -0,0 +1,4 @@
package net.knarcraft.minigames.arena;
public interface ArenaGameMode {
}

View File

@ -1,8 +1,8 @@
package net.knarcraft.dropper.arena;
package net.knarcraft.minigames.arena;
import net.knarcraft.dropper.arena.dropper.DropperArenaGroup;
import net.knarcraft.dropper.container.SerializableUUID;
import net.knarcraft.dropper.util.StringSanitizer;
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
import net.knarcraft.minigames.container.SerializableUUID;
import net.knarcraft.minigames.util.StringSanitizer;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.jetbrains.annotations.NotNull;

View File

@ -1,12 +1,11 @@
package net.knarcraft.dropper.arena.parkour;
package net.knarcraft.minigames.arena;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.record.ArenaRecord;
import net.knarcraft.dropper.arena.record.IntegerRecord;
import net.knarcraft.dropper.arena.record.LongRecord;
import net.knarcraft.dropper.arena.record.SummableArenaRecord;
import net.knarcraft.dropper.container.SerializableUUID;
import net.knarcraft.dropper.property.RecordResult;
import net.knarcraft.minigames.arena.record.ArenaRecord;
import net.knarcraft.minigames.arena.record.IntegerRecord;
import net.knarcraft.minigames.arena.record.LongRecord;
import net.knarcraft.minigames.arena.record.SummableArenaRecord;
import net.knarcraft.minigames.container.SerializableUUID;
import net.knarcraft.minigames.property.RecordResult;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -14,25 +13,24 @@ import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
/**
* A registry keeping track of all records
* A records registry storing records for an arena
*/
public class ParkourArenaRecordsRegistry implements ConfigurationSerializable {
public abstract class ArenaRecordsRegistry implements ConfigurationSerializable {
private final UUID arenaId;
protected final UUID arenaId;
private final @NotNull Set<IntegerRecord> leastDeaths;
private final @NotNull Set<LongRecord> shortestTimeMilliSeconds;
/**
* Instantiates a new empty records registry
*/
public ParkourArenaRecordsRegistry(@NotNull UUID arenaId) {
public ArenaRecordsRegistry(@NotNull UUID arenaId) {
this.arenaId = arenaId;
this.leastDeaths = new HashSet<>();
this.shortestTimeMilliSeconds = new HashSet<>();
@ -44,8 +42,8 @@ public class ParkourArenaRecordsRegistry implements ConfigurationSerializable {
* @param leastDeaths <p>The existing least death records to use</p>
* @param shortestTimeMilliSeconds <p>The existing leash time records to use</p>
*/
private ParkourArenaRecordsRegistry(@NotNull UUID arenaId, @NotNull Set<IntegerRecord> leastDeaths,
@NotNull Set<LongRecord> shortestTimeMilliSeconds) {
protected ArenaRecordsRegistry(@NotNull UUID arenaId, @NotNull Set<IntegerRecord> leastDeaths,
@NotNull Set<LongRecord> shortestTimeMilliSeconds) {
this.arenaId = arenaId;
this.leastDeaths = new HashSet<>(leastDeaths);
this.shortestTimeMilliSeconds = new HashSet<>(shortestTimeMilliSeconds);
@ -81,8 +79,7 @@ public class ParkourArenaRecordsRegistry implements ConfigurationSerializable {
leastDeaths.removeIf((item) -> item.getUserId().equals(playerId));
leastDeaths.add(new IntegerRecord(playerId, value));
};
Set<ArenaRecord<Integer>> asInt = new HashSet<>(leastDeaths);
return registerRecord(asInt, consumer, playerId, deaths);
return registerRecord(new HashSet<>(leastDeaths), consumer, playerId, deaths);
}
/**
@ -97,16 +94,13 @@ public class ParkourArenaRecordsRegistry implements ConfigurationSerializable {
shortestTimeMilliSeconds.removeIf((item) -> item.getUserId().equals(playerId));
shortestTimeMilliSeconds.add(new LongRecord(playerId, value));
};
Set<ArenaRecord<Long>> asLong = new HashSet<>(shortestTimeMilliSeconds);
return registerRecord(asLong, consumer, playerId, milliseconds);
return registerRecord(new HashSet<>(shortestTimeMilliSeconds), consumer, playerId, milliseconds);
}
/**
* Saves changed records
*/
private void save() {
MiniGames.getInstance().getDropperArenaHandler().saveData(this.arenaId);
}
protected abstract void save();
/**
* Registers a new record if applicable
@ -176,23 +170,4 @@ public class ParkourArenaRecordsRegistry implements ConfigurationSerializable {
return data;
}
/**
* Deserializes the given data
*
* @param data <p>The data to deserialize</p>
* @return <p>The deserialized records registry</p>
*/
@SuppressWarnings({"unused", "unchecked"})
public static ParkourArenaRecordsRegistry deserialize(Map<String, Object> data) {
UUID arenaId = ((SerializableUUID) data.get("arenaId")).uuid();
Set<IntegerRecord> leastDeaths =
(Set<IntegerRecord>) data.getOrDefault("leastDeaths", new HashMap<>());
Set<LongRecord> shortestTimeMilliseconds =
(Set<LongRecord>) data.getOrDefault("shortestTime", new HashMap<>());
leastDeaths.removeIf(Objects::isNull);
shortestTimeMilliseconds.removeIf(Objects::isNull);
return new ParkourArenaRecordsRegistry(arenaId, leastDeaths, shortestTimeMilliseconds);
}
}

View File

@ -1,11 +1,11 @@
package net.knarcraft.dropper.arena.dropper;
package net.knarcraft.minigames.arena.dropper;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.Arena;
import net.knarcraft.dropper.arena.ArenaGameMode;
import net.knarcraft.dropper.arena.ArenaRecordsRegistry;
import net.knarcraft.dropper.config.DropperConfiguration;
import net.knarcraft.dropper.util.StringSanitizer;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.Arena;
import net.knarcraft.minigames.arena.ArenaGameMode;
import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
import net.knarcraft.minigames.config.DropperConfiguration;
import net.knarcraft.minigames.util.StringSanitizer;
import org.bukkit.Location;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
@ -15,7 +15,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static net.knarcraft.dropper.util.InputValidationHelper.isInvalid;
import static net.knarcraft.minigames.util.InputValidationHelper.isInvalid;
/**
* A representation of one dropper arena

View File

@ -1,14 +1,15 @@
package net.knarcraft.dropper.arena.dropper;
package net.knarcraft.minigames.arena.dropper;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.ArenaData;
import net.knarcraft.dropper.arena.ArenaGameMode;
import net.knarcraft.dropper.arena.ArenaRecordsRegistry;
import net.knarcraft.dropper.container.SerializableUUID;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaData;
import net.knarcraft.minigames.arena.ArenaGameMode;
import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
import net.knarcraft.minigames.container.SerializableContainer;
import net.knarcraft.minigames.container.SerializableUUID;
import net.knarcraft.minigames.util.SerializableConverter;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
@ -47,8 +48,8 @@ public class DropperArenaData extends ArenaData {
SerializableUUID serializableUUID = (SerializableUUID) data.get("arenaId");
Map<ArenaGameMode, ArenaRecordsRegistry> recordsRegistry =
(Map<ArenaGameMode, ArenaRecordsRegistry>) data.get("recordsRegistry");
Map<ArenaGameMode, Set<SerializableUUID>> playersCompletedData =
(Map<ArenaGameMode, Set<SerializableUUID>>) data.get("playersCompleted");
Map<ArenaGameMode, Set<SerializableContainer<UUID>>> playersCompletedData =
(Map<ArenaGameMode, Set<SerializableContainer<UUID>>>) data.get("playersCompleted");
if (recordsRegistry == null) {
recordsRegistry = new HashMap<>();
@ -58,18 +59,14 @@ public class DropperArenaData extends ArenaData {
// Convert the serializable UUIDs to normal UUIDs
Map<ArenaGameMode, Set<UUID>> allPlayersCompleted = new HashMap<>();
for (ArenaGameMode arenaGameMode : playersCompletedData.keySet()) {
Set<UUID> playersCompleted = new HashSet<>();
for (SerializableUUID completedId : playersCompletedData.get(arenaGameMode)) {
playersCompleted.add(completedId.uuid());
}
allPlayersCompleted.put(arenaGameMode, playersCompleted);
SerializableConverter.getRawValue(playersCompletedData, allPlayersCompleted);
for (ArenaGameMode arenaGameMode : playersCompletedData.keySet()) {
if (!recordsRegistry.containsKey(arenaGameMode) || recordsRegistry.get(arenaGameMode) == null) {
recordsRegistry.put(arenaGameMode, new DropperArenaRecordsRegistry(serializableUUID.uuid()));
recordsRegistry.put(arenaGameMode, new DropperArenaRecordsRegistry(serializableUUID.getRawValue()));
}
}
return new DropperArenaData(serializableUUID.uuid(), recordsRegistry, allPlayersCompleted);
return new DropperArenaData(serializableUUID.getRawValue(), recordsRegistry, allPlayersCompleted);
}
}

View File

@ -1,4 +1,4 @@
package net.knarcraft.dropper.arena.dropper;
package net.knarcraft.minigames.arena.dropper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

View File

@ -1,6 +1,6 @@
package net.knarcraft.dropper.arena.dropper;
package net.knarcraft.minigames.arena.dropper;
import net.knarcraft.dropper.arena.ArenaGameMode;
import net.knarcraft.minigames.arena.ArenaGameMode;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.jetbrains.annotations.NotNull;

View File

@ -1,8 +1,9 @@
package net.knarcraft.dropper.arena.dropper;
package net.knarcraft.minigames.arena.dropper;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.ArenaGroup;
import net.knarcraft.dropper.container.SerializableUUID;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaGroup;
import net.knarcraft.minigames.container.SerializableUUID;
import net.knarcraft.minigames.util.SerializableConverter;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -109,13 +110,12 @@ public class DropperArenaGroup extends ArenaGroup {
*/
@SuppressWarnings({"unused", "unchecked"})
public static @NotNull DropperArenaGroup deserialize(@NotNull Map<String, Object> data) {
UUID id = ((SerializableUUID) data.get("groupId")).uuid();
UUID id = ((SerializableUUID) data.get("groupId")).getRawValue();
String name = (String) data.get("groupName");
List<SerializableUUID> serializableArenas = (List<SerializableUUID>) data.get("arenas");
List<UUID> arenas = new ArrayList<>();
for (SerializableUUID arenaId : serializableArenas) {
arenas.add(arenaId.uuid());
}
SerializableConverter.getRawValue(new ArrayList<>(serializableArenas), arenas);
return new DropperArenaGroup(id, name, arenas);
}

View File

@ -1,8 +1,8 @@
package net.knarcraft.dropper.arena.dropper;
package net.knarcraft.minigames.arena.dropper;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.util.ArenaStorageHelper;
import net.knarcraft.dropper.util.StringSanitizer;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.util.ArenaStorageHelper;
import net.knarcraft.minigames.util.StringSanitizer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

View File

@ -1,4 +1,4 @@
package net.knarcraft.dropper.arena.dropper;
package net.knarcraft.minigames.arena.dropper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

View File

@ -0,0 +1,65 @@
package net.knarcraft.minigames.arena.dropper;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
import net.knarcraft.minigames.arena.record.IntegerRecord;
import net.knarcraft.minigames.arena.record.LongRecord;
import net.knarcraft.minigames.container.SerializableUUID;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
/**
* A registry keeping track of all records
*/
public class DropperArenaRecordsRegistry extends ArenaRecordsRegistry {
/**
* Instantiates a new empty records registry
*/
public DropperArenaRecordsRegistry(@NotNull UUID arenaId) {
super(arenaId);
}
/**
* Instantiates a new records registry
*
* @param leastDeaths <p>The existing least death records to use</p>
* @param shortestTimeMilliSeconds <p>The existing leash time records to use</p>
*/
private DropperArenaRecordsRegistry(@NotNull UUID arenaId, @NotNull Set<IntegerRecord> leastDeaths,
@NotNull Set<LongRecord> shortestTimeMilliSeconds) {
super(arenaId, leastDeaths, shortestTimeMilliSeconds);
}
/**
* Saves changed records
*/
protected void save() {
MiniGames.getInstance().getDropperArenaHandler().saveData(this.arenaId);
}
/**
* Deserializes the given data
*
* @param data <p>The data to deserialize</p>
* @return <p>The deserialized records registry</p>
*/
@SuppressWarnings({"unused", "unchecked"})
public static DropperArenaRecordsRegistry deserialize(Map<String, Object> data) {
UUID arenaId = ((SerializableUUID) data.get("arenaId")).getRawValue();
Set<IntegerRecord> leastDeaths =
(Set<IntegerRecord>) data.getOrDefault("leastDeaths", new HashMap<>());
Set<LongRecord> shortestTimeMilliseconds =
(Set<LongRecord>) data.getOrDefault("shortestTime", new HashMap<>());
leastDeaths.removeIf(Objects::isNull);
shortestTimeMilliseconds.removeIf(Objects::isNull);
return new DropperArenaRecordsRegistry(arenaId, leastDeaths, shortestTimeMilliseconds);
}
}

View File

@ -1,9 +1,10 @@
package net.knarcraft.dropper.arena.dropper;
package net.knarcraft.minigames.arena.dropper;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.config.DropperConfiguration;
import net.knarcraft.dropper.property.RecordResult;
import net.knarcraft.dropper.util.PlayerTeleporter;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
import net.knarcraft.minigames.config.DropperConfiguration;
import net.knarcraft.minigames.property.RecordResult;
import net.knarcraft.minigames.util.PlayerTeleporter;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -118,7 +119,7 @@ public class DropperArenaSession {
* Registers the player's record if necessary, and prints record information to the player
*/
private void registerRecord() {
DropperArenaRecordsRegistry recordsRegistry = this.arena.getData().recordRegistries().get(this.gameMode);
ArenaRecordsRegistry recordsRegistry = this.arena.getData().getRecordRegistries().get(this.gameMode);
long timeElapsed = System.currentTimeMillis() - this.startTime;
announceRecord(recordsRegistry.registerTimeRecord(this.player.getUniqueId(), timeElapsed), "time");
announceRecord(recordsRegistry.registerDeathRecord(this.player.getUniqueId(), this.deaths), "least deaths");

View File

@ -1,4 +1,4 @@
package net.knarcraft.dropper.arena.dropper;
package net.knarcraft.minigames.arena.dropper;
import org.jetbrains.annotations.NotNull;

View File

@ -1,4 +1,4 @@
package net.knarcraft.dropper.arena.dropper;
package net.knarcraft.minigames.arena.dropper;
import org.bukkit.GameMode;
import org.bukkit.Location;

View File

@ -1,20 +1,26 @@
package net.knarcraft.dropper.arena.parkour;
package net.knarcraft.minigames.arena.parkour;
import net.knarcraft.dropper.util.StringSanitizer;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaGameMode;
import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
import net.knarcraft.minigames.util.StringSanitizer;
import org.bukkit.Location;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import static net.knarcraft.dropper.util.InputValidationHelper.isInvalid;
import static net.knarcraft.minigames.util.InputValidationHelper.isInvalid;
/**
* A representation of one dropper arena
* A representation of one parkour arena
*/
public class ParkourArena {
@ -40,7 +46,7 @@ public class ParkourArena {
private @Nullable Location exitLocation;
/**
* The material of the block players have to hit to win this dropper arena
* The material of the block players have to hit to win this parkour arena
*/
private @NotNull Material winBlockType;
@ -49,10 +55,15 @@ public class ParkourArena {
*/
private @Nullable Location winLocation;
/**
* The block types constituting this arena's kill plane
*/
private @Nullable Set<Material> killPlaneBlocks;
/**
* The checkpoints for this arena. Entering a checkpoint overrides the player's spawn location.
*/
private @Nullable List<Location> checkpoints;
private @NotNull List<Location> checkpoints;
/**
* The arena data for this arena
@ -62,32 +73,35 @@ public class ParkourArena {
private final ParkourArenaHandler parkourArenaHandler;
/**
* Instantiates a new dropper arena
* Instantiates a new parkour arena
*
* @param arenaId <p>The id of the arena</p>
* @param arenaName <p>The name of the arena</p>
* @param spawnLocation <p>The location players spawn in when entering the arena</p>
* @param exitLocation <p>The location the players are teleported to when exiting the arena, or null</p>
* @param winBlockType <p>The material of the block players have to hit to win this dropper arena</p>
* @param winBlockType <p>The material of the block players have to hit to win this parkour 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>
*/
public ParkourArena(@NotNull UUID arenaId, @NotNull String arenaName, @NotNull Location spawnLocation,
@Nullable Location exitLocation, @NotNull Material winBlockType,
@Nullable Set<Material> killPlaneBlocks, @NotNull List<Location> checkpoints,
@NotNull ParkourArenaData parkourArenaData, @NotNull ParkourArenaHandler arenaHandler) {
this.arenaId = arenaId;
this.arenaName = arenaName;
this.spawnLocation = spawnLocation;
this.exitLocation = exitLocation;
this.winBlockType = winBlockType;
this.killPlaneBlocks = killPlaneBlocks;
this.checkpoints = checkpoints;
this.parkourArenaData = parkourArenaData;
this.parkourArenaHandler = arenaHandler;
}
/**
* Instantiates a new dropper arena
* Instantiates a new parkour arena
*
* <p>Note that this minimal constructor can be used to quickly create a new dropper arena at the player's given
* <p>Note that this minimal constructor can be used to quickly create a new parkour arena at the player's given
* location, simply by them giving an arena name.</p>
*
* @param arenaName <p>The name of the arena</p>
@ -102,13 +116,15 @@ public class ParkourArena {
this.exitLocation = null;
this.winLocation = null;
Map<ParkourArenaGameMode, ParkourArenaRecordsRegistry> recordRegistries = new HashMap<>();
Map<ArenaGameMode, ArenaRecordsRegistry> recordRegistries = new HashMap<>();
for (ParkourArenaGameMode arenaGameMode : ParkourArenaGameMode.values()) {
recordRegistries.put(arenaGameMode, new ParkourArenaRecordsRegistry(this.arenaId));
}
this.parkourArenaData = new ParkourArenaData(this.arenaId, recordRegistries, new HashMap<>());
this.winBlockType = Material.EMERALD_BLOCK;
this.killPlaneBlocks = null;
this.checkpoints = new ArrayList<>();
this.parkourArenaHandler = arenaHandler;
}
@ -142,7 +158,7 @@ public class ParkourArena {
/**
* Gets this arena's spawn location
*
* <p>The spawn location is the location every player starts from when entering the dropper.</p>
* <p>The spawn location is the location every player starts from when entering the parkour arena.</p>
*
* @return <p>This arena's spawn location.</p>
*/
@ -179,6 +195,32 @@ public class ParkourArena {
return this.winLocation != null ? this.winLocation.clone() : null;
}
/**
* Gets the block types used for this parkour arena's kill plane
*
* @return <p>The types of blocks that cause a loss</p>
*/
public Set<Material> getKillPlaneBlocks() {
if (this.killPlaneBlocks != null) {
return new HashSet<>(this.killPlaneBlocks);
} else {
return MiniGames.getInstance().getParkourConfiguration().getKillPlaneBlocks();
}
}
/**
* Gets all checkpoint locations for this arena
*
* @return <p>All checkpoint locations for this arena</p>
*/
public List<Location> getCheckpoints() {
List<Location> copy = new ArrayList<>(this.checkpoints.size());
for (Location location : this.checkpoints) {
copy.add(location.clone());
}
return copy;
}
/**
* Gets this arena's sanitized name
*
@ -267,12 +309,49 @@ public class ParkourArena {
if (isInvalid(newLocation)) {
return false;
} else {
this.exitLocation = newLocation;
this.exitLocation = newLocation.clone();
parkourArenaHandler.saveArenas();
return true;
}
}
/**
* Sets the type of blocks constituting this arena's kill plane
*
* @param killPlaneBlocks <p>The blocks that will cause players to lose</p>
* @return <p>True if successfully changed</p>
*/
public boolean setKillPlaneBlocks(@NotNull Set<Material> killPlaneBlocks) {
for (Material material : killPlaneBlocks) {
// Make sure no nulls have entered the set
if (material == null) {
return false;
}
}
this.killPlaneBlocks = new HashSet<>(killPlaneBlocks);
return true;
}
/**
* Sets the checkpoints of this arena
*
* @param checkpoints <p>The checkpoints to use</p>
* @return <p>True if successfully changed</p>
*/
public boolean setCheckpoints(@NotNull List<Location> checkpoints) {
List<Location> copy = new ArrayList<>(checkpoints.size());
for (Location location : checkpoints) {
if (isInvalid(location)) {
return false;
}
copy.add(location.clone());
}
this.checkpoints = copy;
return true;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof ParkourArena otherArena)) {

View File

@ -0,0 +1,73 @@
package net.knarcraft.minigames.arena.parkour;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaData;
import net.knarcraft.minigames.arena.ArenaGameMode;
import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
import net.knarcraft.minigames.arena.dropper.DropperArenaRecordsRegistry;
import net.knarcraft.minigames.container.SerializableContainer;
import net.knarcraft.minigames.container.SerializableUUID;
import net.knarcraft.minigames.util.SerializableConverter;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
/**
* Data stored for an arena
*/
public class ParkourArenaData extends ArenaData {
/**
* Instantiates a new parkour arena data object
*
* @param arenaId <p>The id of the arena this data belongs to</p>
* @param recordRegistries <p>The registry of this arena's records</p>
* @param playersCompleted <p>The set of the players that have cleared this arena</p>
*/
public ParkourArenaData(@NotNull UUID arenaId,
@NotNull Map<ArenaGameMode, ArenaRecordsRegistry> recordRegistries,
@NotNull Map<ArenaGameMode, Set<UUID>> playersCompleted) {
super(arenaId, recordRegistries, playersCompleted);
}
@Override
public void saveData() {
MiniGames.getInstance().getParkourArenaHandler().saveData(this.arenaId);
}
/**
* Deserializes a dropper arena data from the given data
*
* @param data <p>The data to deserialize</p>
* @return <p>The deserialized dropper arena data</p>
*/
@SuppressWarnings({"unused", "unchecked"})
public static @NotNull ParkourArenaData deserialize(@NotNull Map<String, Object> data) {
SerializableUUID serializableUUID = (SerializableUUID) data.get("arenaId");
Map<ArenaGameMode, ArenaRecordsRegistry> recordsRegistry =
(Map<ArenaGameMode, ArenaRecordsRegistry>) data.get("recordsRegistry");
Map<ArenaGameMode, Set<SerializableContainer<UUID>>> playersCompletedData =
(Map<ArenaGameMode, Set<SerializableContainer<UUID>>>) data.get("playersCompleted");
if (recordsRegistry == null) {
recordsRegistry = new HashMap<>();
} else if (playersCompletedData == null) {
playersCompletedData = new HashMap<>();
}
// Convert the serializable UUIDs to normal UUIDs
Map<ArenaGameMode, Set<UUID>> allPlayersCompleted = new HashMap<>();
SerializableConverter.getRawValue(playersCompletedData, allPlayersCompleted);
for (ArenaGameMode arenaGameMode : playersCompletedData.keySet()) {
if (!recordsRegistry.containsKey(arenaGameMode) || recordsRegistry.get(arenaGameMode) == null) {
recordsRegistry.put(arenaGameMode, new DropperArenaRecordsRegistry(serializableUUID.getRawValue()));
}
}
return new ParkourArenaData(serializableUUID.getRawValue(), recordsRegistry, allPlayersCompleted);
}
}

View File

@ -1,6 +1,6 @@
package net.knarcraft.dropper.arena.parkour;
package net.knarcraft.minigames.arena.parkour;
import net.knarcraft.dropper.arena.ArenaGameMode;
import net.knarcraft.minigames.arena.ArenaGameMode;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.jetbrains.annotations.NotNull;

View File

@ -1,8 +1,8 @@
package net.knarcraft.dropper.arena.parkour;
package net.knarcraft.minigames.arena.parkour;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.ArenaGroup;
import net.knarcraft.dropper.container.SerializableUUID;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaGroup;
import net.knarcraft.minigames.container.SerializableUUID;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -18,7 +18,7 @@ import java.util.logging.Level;
public class ParkourArenaGroup extends ArenaGroup {
/**
* Instantiates a new dropper arena group
* Instantiates a new parkour arena group
*
* @param groupName <p>The name of this group</p>
*/
@ -27,7 +27,7 @@ public class ParkourArenaGroup extends ArenaGroup {
}
/**
* Instantiates a new dropper arena group
* Instantiates a new parkour arena group
*
* @param groupId <p>The unique id of this group</p>
* @param groupName <p>The name of this group</p>
@ -47,15 +47,15 @@ public class ParkourArenaGroup extends ArenaGroup {
public boolean hasBeatenAll(ParkourArenaGameMode gameMode, Player player) {
ParkourArenaHandler arenaHandler = MiniGames.getInstance().getParkourArenaHandler();
for (UUID anArenaId : this.getArenas()) {
ParkourArena dropperArena = arenaHandler.getArena(anArenaId);
if (dropperArena == null) {
ParkourArena parkourArena = arenaHandler.getArena(anArenaId);
if (parkourArena == null) {
// The arena would only be null if the arena has been deleted, but not removed from this group
MiniGames.log(Level.WARNING, "The dropper group " + this.getGroupName() +
MiniGames.log(Level.WARNING, "The parkour group " + this.getGroupName() +
" contains the arena id " + anArenaId + " which is not a valid arena id!");
continue;
}
if (dropperArena.getData().hasNotCompleted(gameMode, player)) {
if (parkourArena.getData().hasNotCompleted(gameMode, player)) {
return false;
}
}
@ -87,7 +87,7 @@ public class ParkourArenaGroup extends ArenaGroup {
ParkourArena parkourArena = arenaHandler.getArena(anArenaId);
if (parkourArena == null) {
// The arena would only be null if the arena has been deleted, but not removed from this group
MiniGames.log(Level.WARNING, String.format("The dropper group %s contains the" +
MiniGames.log(Level.WARNING, String.format("The parkour group %s contains the" +
" arena id %s which is not a valid arena id!", this.getGroupName(), anArenaId));
continue;
}
@ -109,12 +109,12 @@ public class ParkourArenaGroup extends ArenaGroup {
*/
@SuppressWarnings({"unused", "unchecked"})
public static @NotNull ParkourArenaGroup deserialize(@NotNull Map<String, Object> data) {
UUID id = ((SerializableUUID) data.get("groupId")).uuid();
UUID id = ((SerializableUUID) data.get("groupId")).getRawValue();
String name = (String) data.get("groupName");
List<SerializableUUID> serializableArenas = (List<SerializableUUID>) data.get("arenas");
List<UUID> arenas = new ArrayList<>();
for (SerializableUUID arenaId : serializableArenas) {
arenas.add(arenaId.uuid());
arenas.add(arenaId.getRawValue());
}
return new ParkourArenaGroup(id, name, arenas);
}

View File

@ -1,8 +1,8 @@
package net.knarcraft.dropper.arena.parkour;
package net.knarcraft.minigames.arena.parkour;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.util.ArenaStorageHelper;
import net.knarcraft.dropper.util.StringSanitizer;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.util.ArenaStorageHelper;
import net.knarcraft.minigames.util.StringSanitizer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -15,7 +15,7 @@ import java.util.UUID;
import java.util.logging.Level;
/**
* A handler that keeps track of all dropper arenas
* A handler that keeps track of all parkour arenas
*/
public class ParkourArenaHandler {
@ -37,9 +37,9 @@ public class ParkourArenaHandler {
}
/**
* Gets a copy of all dropper groups
* Gets a copy of all parkour groups
*
* @return <p>All dropper groups</p>
* @return <p>All parkour groups</p>
*/
public Set<ParkourArenaGroup> getAllGroups() {
return new HashSet<>(arenaGroups.values());
@ -84,7 +84,7 @@ public class ParkourArenaHandler {
}
/**
* Gets the dropper arena group with the given name
* Gets the parkour arena group with the given name
*
* @param groupName <p>The name of the group to get</p>
* @return <p>The group, or null if not found</p>
@ -163,8 +163,8 @@ public class ParkourArenaHandler {
this.arenas.remove(arenaId);
this.arenaNameLookup.remove(arena.getArenaNameSanitized());
this.arenaGroups.remove(arenaId);
if (!ArenaStorageHelper.removeDropperArenaData(arenaId)) {
MiniGames.log(Level.WARNING, "Unable to remove dropper arena data file " + arenaId + ".yml. " +
if (!ArenaStorageHelper.removeParkourArenaData(arenaId)) {
MiniGames.log(Level.WARNING, "Unable to remove parkour arena data file " + arenaId + ".yml. " +
"You must remove it manually!");
}
this.saveArenas();
@ -185,7 +185,7 @@ public class ParkourArenaHandler {
}
/**
* Saves all current dropper groups to disk
* Saves all current parkour groups to disk
*/
public void saveGroups() {
try {
@ -206,7 +206,7 @@ public class ParkourArenaHandler {
}
/**
* Loads all dropper groups from disk
* Loads all parkour groups from disk
*/
private void loadGroups() {
Set<ParkourArenaGroup> arenaGroups = ArenaStorageHelper.loadParkourArenaGroups();

View File

@ -1,4 +1,4 @@
package net.knarcraft.dropper.arena.parkour;
package net.knarcraft.minigames.arena.parkour;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

View File

@ -0,0 +1,66 @@
package net.knarcraft.minigames.arena.parkour;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
import net.knarcraft.minigames.arena.record.IntegerRecord;
import net.knarcraft.minigames.arena.record.LongRecord;
import net.knarcraft.minigames.container.SerializableUUID;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
/**
* A registry keeping track of all records
*/
public class ParkourArenaRecordsRegistry extends ArenaRecordsRegistry {
/**
* Instantiates a new empty records registry
*/
public ParkourArenaRecordsRegistry(@NotNull UUID arenaId) {
super(arenaId);
}
/**
* Instantiates a new records registry
*
* @param leastDeaths <p>The existing least death records to use</p>
* @param shortestTimeMilliSeconds <p>The existing leash time records to use</p>
*/
private ParkourArenaRecordsRegistry(@NotNull UUID arenaId, @NotNull Set<IntegerRecord> leastDeaths,
@NotNull Set<LongRecord> shortestTimeMilliSeconds) {
super(arenaId, leastDeaths, shortestTimeMilliSeconds);
}
/**
* Saves changed records
*/
@Override
protected void save() {
MiniGames.getInstance().getParkourArenaHandler().saveData(this.arenaId);
}
/**
* Deserializes the given data
*
* @param data <p>The data to deserialize</p>
* @return <p>The deserialized records registry</p>
*/
@SuppressWarnings({"unused", "unchecked"})
public static ParkourArenaRecordsRegistry deserialize(Map<String, Object> data) {
UUID arenaId = ((SerializableUUID) data.get("arenaId")).getRawValue();
Set<IntegerRecord> leastDeaths =
(Set<IntegerRecord>) data.getOrDefault("leastDeaths", new HashMap<>());
Set<LongRecord> shortestTimeMilliseconds =
(Set<LongRecord>) data.getOrDefault("shortestTime", new HashMap<>());
leastDeaths.removeIf(Objects::isNull);
shortestTimeMilliseconds.removeIf(Objects::isNull);
return new ParkourArenaRecordsRegistry(arenaId, leastDeaths, shortestTimeMilliseconds);
}
}

View File

@ -1,9 +1,10 @@
package net.knarcraft.dropper.arena.parkour;
package net.knarcraft.minigames.arena.parkour;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.config.DropperConfiguration;
import net.knarcraft.dropper.property.RecordResult;
import net.knarcraft.dropper.util.PlayerTeleporter;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
import net.knarcraft.minigames.config.ParkourConfiguration;
import net.knarcraft.minigames.property.RecordResult;
import net.knarcraft.minigames.util.PlayerTeleporter;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -11,7 +12,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.logging.Level;
/**
* A representation of a player's current session in a dropper arena
* A representation of a player's current session in a parkour arena
*/
public class ParkourArenaSession {
@ -25,19 +26,19 @@ public class ParkourArenaSession {
/**
* Instantiates a new parkour arena session
*
* @param dropperArena <p>The arena that's being played in</p>
* @param parkourArena <p>The arena that's being played in</p>
* @param player <p>The player playing the arena</p>
* @param gameMode <p>The game-mode</p>
*/
public ParkourArenaSession(@NotNull ParkourArena dropperArena, @NotNull Player player,
public ParkourArenaSession(@NotNull ParkourArena parkourArena, @NotNull Player player,
@NotNull ParkourArenaGameMode gameMode) {
this.arena = dropperArena;
this.arena = parkourArena;
this.player = player;
this.gameMode = gameMode;
this.deaths = 0;
this.startTime = System.currentTimeMillis();
DropperConfiguration configuration = MiniGames.getInstance().getDropperConfiguration();
ParkourConfiguration configuration = MiniGames.getInstance().getParkourConfiguration();
boolean makeInvisible = configuration.makePlayersInvisible();
this.entryState = new ParkourPlayerEntryState(player, makeInvisible);
// Make the player fly to improve mobility in the air
@ -69,7 +70,7 @@ public class ParkourArenaSession {
}
// Mark the arena as cleared
if (this.arena.getData().addCompleted(this.gameMode, this.player)) {
if (this.arena.getData().setCompleted(this.gameMode, this.player)) {
this.player.sendMessage("You cleared the arena!");
}
this.player.sendMessage("You won!");
@ -108,7 +109,7 @@ public class ParkourArenaSession {
* Registers the player's record if necessary, and prints record information to the player
*/
private void registerRecord() {
ParkourArenaRecordsRegistry recordsRegistry = this.arena.getData().recordRegistries().get(this.gameMode);
ArenaRecordsRegistry recordsRegistry = this.arena.getData().getRecordRegistries().get(this.gameMode);
long timeElapsed = System.currentTimeMillis() - this.startTime;
announceRecord(recordsRegistry.registerTimeRecord(this.player.getUniqueId(), timeElapsed), "time");
announceRecord(recordsRegistry.registerDeathRecord(this.player.getUniqueId(), this.deaths), "least deaths");

View File

@ -0,0 +1,76 @@
package net.knarcraft.minigames.arena.parkour;
import org.jetbrains.annotations.NotNull;
/**
* A representation of each key used for storing arena data
*/
public enum ParkourArenaStorageKey {
/**
* The key for an arena's id
*/
ID("arenaId"),
/**
* The key for an arena's name
*/
NAME("arenaName"),
/**
* The key for an arena's spawn location
*/
SPAWN_LOCATION("arenaSpawnLocation"),
/**
* The key for an arena's exit location
*/
EXIT_LOCATION("arenaExitLocation"),
/**
* The key for the type of this arena's win block
*/
WIN_BLOCK_TYPE("winBlockType"),
/**
* The key for this arena's win location (overrides win block type)
*/
WIN_LOCATION("winLocation"),
/**
* The key for this arena's kill plane blocks (overrides the config)
*/
KILL_PLANE_BLOCKS("killPlaneBlocks"),
/**
* The key for this arena's checkpoint locations
*/
CHECKPOINTS("checkpoints"),
/**
* The hey for this arena's data
*/
DATA("arenaData"),
;
private final @NotNull String key;
/**
* Instantiates a new arena storage key
*
* @param key <p>The string path of the configuration key this value represents.</p>
*/
ParkourArenaStorageKey(@NotNull String key) {
this.key = key;
}
/**
* Gets the configuration key this enum represents
*
* @return <p>The string key representation.</p>
*/
public @NotNull String getKey() {
return this.key;
}
}

View File

@ -1,4 +1,4 @@
package net.knarcraft.dropper.arena.parkour;
package net.knarcraft.minigames.arena.parkour;
import org.bukkit.GameMode;
import org.bukkit.Location;

View File

@ -1,6 +1,6 @@
package net.knarcraft.dropper.arena.record;
package net.knarcraft.minigames.arena.record;
import net.knarcraft.dropper.container.SerializableUUID;
import net.knarcraft.minigames.container.SerializableUUID;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.jetbrains.annotations.NotNull;

View File

@ -1,6 +1,6 @@
package net.knarcraft.dropper.arena.record;
package net.knarcraft.minigames.arena.record;
import net.knarcraft.dropper.container.SerializableUUID;
import net.knarcraft.minigames.container.SerializableUUID;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
@ -37,7 +37,7 @@ public class IntegerRecord extends SummableArenaRecord<Integer> {
*/
@SuppressWarnings("unused")
public static IntegerRecord deserialize(@NotNull Map<String, Object> data) {
return new IntegerRecord(((SerializableUUID) data.get("userId")).uuid(), (Integer) data.get("record"));
return new IntegerRecord(((SerializableUUID) data.get("userId")).getRawValue(), (Integer) data.get("record"));
}
}

View File

@ -1,6 +1,6 @@
package net.knarcraft.dropper.arena.record;
package net.knarcraft.minigames.arena.record;
import net.knarcraft.dropper.container.SerializableUUID;
import net.knarcraft.minigames.container.SerializableUUID;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
@ -37,7 +37,7 @@ public class LongRecord extends SummableArenaRecord<Long> {
*/
@SuppressWarnings("unused")
public static LongRecord deserialize(@NotNull Map<String, Object> data) {
return new LongRecord(((SerializableUUID) data.get("userId")).uuid(), ((Number) data.get("record")).longValue());
return new LongRecord(((SerializableUUID) data.get("userId")).getRawValue(), ((Number) data.get("record")).longValue());
}
}

View File

@ -1,4 +1,4 @@
package net.knarcraft.dropper.arena.record;
package net.knarcraft.minigames.arena.record;
import java.util.UUID;

View File

@ -1,9 +1,9 @@
package net.knarcraft.dropper.command;
package net.knarcraft.minigames.command;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.dropper.DropperArena;
import net.knarcraft.dropper.arena.dropper.DropperArenaHandler;
import net.knarcraft.dropper.util.StringSanitizer;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArena;
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
import net.knarcraft.minigames.util.StringSanitizer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;

View File

@ -1,9 +1,9 @@
package net.knarcraft.dropper.command;
package net.knarcraft.minigames.command;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.dropper.DropperArena;
import net.knarcraft.dropper.arena.dropper.DropperArenaEditableProperty;
import net.knarcraft.dropper.config.DropperConfiguration;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArena;
import net.knarcraft.minigames.arena.dropper.DropperArenaEditableProperty;
import net.knarcraft.minigames.config.DropperConfiguration;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.Command;

View File

@ -1,6 +1,6 @@
package net.knarcraft.dropper.command;
package net.knarcraft.minigames.command;
import net.knarcraft.dropper.util.TabCompleteHelper;
import net.knarcraft.minigames.util.TabCompleteHelper;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;

View File

@ -1,9 +1,9 @@
package net.knarcraft.dropper.command;
package net.knarcraft.minigames.command;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.dropper.DropperArena;
import net.knarcraft.dropper.arena.dropper.DropperArenaGroup;
import net.knarcraft.dropper.arena.dropper.DropperArenaHandler;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArena;
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;

View File

@ -1,11 +1,11 @@
package net.knarcraft.dropper.command;
package net.knarcraft.minigames.command;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.dropper.DropperArena;
import net.knarcraft.dropper.arena.dropper.DropperArenaGroup;
import net.knarcraft.dropper.arena.dropper.DropperArenaHandler;
import net.knarcraft.dropper.util.StringSanitizer;
import net.knarcraft.dropper.util.TabCompleteHelper;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArena;
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
import net.knarcraft.minigames.util.StringSanitizer;
import net.knarcraft.minigames.util.TabCompleteHelper;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;

View File

@ -1,9 +1,9 @@
package net.knarcraft.dropper.command;
package net.knarcraft.minigames.command;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.dropper.DropperArena;
import net.knarcraft.dropper.arena.dropper.DropperArenaGroup;
import net.knarcraft.dropper.arena.dropper.DropperArenaHandler;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArena;
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;

View File

@ -1,13 +1,13 @@
package net.knarcraft.dropper.command;
package net.knarcraft.minigames.command;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.dropper.DropperArena;
import net.knarcraft.dropper.arena.dropper.DropperArenaGameMode;
import net.knarcraft.dropper.arena.dropper.DropperArenaGroup;
import net.knarcraft.dropper.arena.dropper.DropperArenaPlayerRegistry;
import net.knarcraft.dropper.arena.dropper.DropperArenaSession;
import net.knarcraft.dropper.config.DropperConfiguration;
import net.knarcraft.dropper.util.PlayerTeleporter;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArena;
import net.knarcraft.minigames.arena.dropper.DropperArenaGameMode;
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
import net.knarcraft.minigames.arena.dropper.DropperArenaPlayerRegistry;
import net.knarcraft.minigames.arena.dropper.DropperArenaSession;
import net.knarcraft.minigames.config.DropperConfiguration;
import net.knarcraft.minigames.util.PlayerTeleporter;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;

View File

@ -1,6 +1,6 @@
package net.knarcraft.dropper.command;
package net.knarcraft.minigames.command;
import net.knarcraft.dropper.util.TabCompleteHelper;
import net.knarcraft.minigames.util.TabCompleteHelper;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;

View File

@ -1,7 +1,7 @@
package net.knarcraft.dropper.command;
package net.knarcraft.minigames.command;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.dropper.DropperArenaSession;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArenaSession;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;

View File

@ -1,6 +1,6 @@
package net.knarcraft.dropper.command;
package net.knarcraft.minigames.command;
import net.knarcraft.dropper.util.TabCompleteHelper;
import net.knarcraft.minigames.util.TabCompleteHelper;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;

View File

@ -1,6 +1,6 @@
package net.knarcraft.dropper.command;
package net.knarcraft.minigames.command;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.minigames.MiniGames;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;

View File

@ -1,7 +1,7 @@
package net.knarcraft.dropper.command;
package net.knarcraft.minigames.command;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.dropper.DropperArena;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArena;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;

View File

@ -1,6 +1,6 @@
package net.knarcraft.dropper.command;
package net.knarcraft.minigames.command;
import net.knarcraft.dropper.util.TabCompleteHelper;
import net.knarcraft.minigames.util.TabCompleteHelper;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;

View File

@ -1,19 +1,10 @@
package net.knarcraft.dropper.config;
package net.knarcraft.minigames.config;
import net.knarcraft.dropper.MiniGames;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Tag;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* The configuration keeping track of dropper settings
@ -143,7 +134,7 @@ public class DropperConfiguration extends MiniGameConfiguration {
}
@Override
public void load() {
protected void load() {
this.verticalVelocity = configuration.getDouble(rootNode + "verticalVelocity", 1.0);
this.horizontalVelocity = (float) configuration.getDouble(rootNode + "horizontalVelocity", 1.0);
this.randomlyInvertedTimer = configuration.getInt(rootNode + "randomlyInvertedTimer", 7);
@ -154,9 +145,8 @@ public class DropperConfiguration extends MiniGameConfiguration {
this.disableHitCollision = configuration.getBoolean(rootNode + "disableHitCollision", true);
this.blockSprinting = configuration.getBoolean(rootNode + "blockSprinting", true);
this.blockSneaking = configuration.getBoolean(rootNode + "blockSneaking", true);
this.blockWhitelist = loadMaterialList(rootNode + "blockWhitelist");
sanitizeValues();
loadBlockWhitelist();
}
/**
@ -176,55 +166,6 @@ public class DropperConfiguration extends MiniGameConfiguration {
}
}
/**
* Loads the materials specified in the block whitelist
*/
private void loadBlockWhitelist() {
this.blockWhitelist = new HashSet<>();
List<?> blockWhitelist = configuration.getList(rootNode + "blockWhitelist", new ArrayList<>());
for (Object value : blockWhitelist) {
if (!(value instanceof String string)) {
continue;
}
// Try to parse a material tag first
if (parseMaterialTag(string)) {
continue;
}
// Try to parse a material name
Material matched = Material.matchMaterial(string);
if (matched != null) {
this.blockWhitelist.add(matched);
} else {
MiniGames.log(Level.WARNING, "Unable to parse: " + string);
}
}
}
/**
* Tries to parse the material tag in the specified material name
*
* @param materialName <p>The material name that might be a material tag</p>
* @return <p>True if a tag was found</p>
*/
private boolean parseMaterialTag(String materialName) {
Pattern pattern = Pattern.compile("^\\+([a-zA-Z_]+)");
Matcher matcher = pattern.matcher(materialName);
if (matcher.find()) {
// The material is a material tag
Tag<Material> tag = Bukkit.getTag(Tag.REGISTRY_BLOCKS, NamespacedKey.minecraft(
matcher.group(1).toLowerCase()), Material.class);
if (tag != null) {
this.blockWhitelist.addAll(tag.getValues());
} else {
MiniGames.log(Level.WARNING, "Unable to parse: " + materialName);
}
return true;
}
return false;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder(

View File

@ -0,0 +1,102 @@
package net.knarcraft.minigames.config;
import net.knarcraft.minigames.MiniGames;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Tag;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* A configuration for a mini-game
*/
public abstract class MiniGameConfiguration {
protected FileConfiguration configuration;
/**
* Instantiates a new mini-game configuration
*
* @param configuration <p>The YAML configuration to use internally</p>
*/
public MiniGameConfiguration(@NotNull FileConfiguration configuration) {
this.configuration = configuration;
this.load();
}
/**
* Loads all configuration values from disk
*
* @param configuration <p>The configuration to load</p>
*/
public void load(FileConfiguration configuration) {
this.configuration = configuration;
this.load();
}
/**
* Loads all configuration values from disk, using the current file configuration
*/
protected abstract void load();
/**
* Loads the materials specified in the block whitelist
*/
protected @NotNull Set<Material> loadMaterialList(@NotNull String path) {
Set<Material> parsedMaterials = new HashSet<>();
List<?> blockWhitelist = configuration.getList(path, new ArrayList<>());
for (Object value : blockWhitelist) {
if (!(value instanceof String string)) {
continue;
}
// Try to parse a material tag first
if (parseMaterialTag(parsedMaterials, string)) {
continue;
}
// Try to parse a material name
Material matched = Material.matchMaterial(string);
if (matched != null) {
parsedMaterials.add(matched);
} else {
MiniGames.log(Level.WARNING, "Unable to parse: " + string);
}
}
return parsedMaterials;
}
/**
* Tries to parse the material tag in the specified material name
*
* @param targetSet <p>The set all parsed materials should be added to</p>
* @param materialName <p>The material name that might be a material tag</p>
* @return <p>True if a tag was found</p>
*/
protected boolean parseMaterialTag(@NotNull Set<Material> targetSet, @NotNull String materialName) {
Pattern pattern = Pattern.compile("^\\+([a-zA-Z_]+)");
Matcher matcher = pattern.matcher(materialName);
if (matcher.find()) {
// The material is a material tag
Tag<Material> tag = Bukkit.getTag(Tag.REGISTRY_BLOCKS, NamespacedKey.minecraft(
matcher.group(1).toLowerCase()), Material.class);
if (tag != null) {
targetSet.addAll(tag.getValues());
} else {
MiniGames.log(Level.WARNING, "Unable to parse: " + materialName);
}
return true;
}
return false;
}
}

View File

@ -1,7 +1,11 @@
package net.knarcraft.dropper.config;
package net.knarcraft.minigames.config;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.HashSet;
import java.util.Set;
/**
* The configuration keeping track of parkour settings
*/
@ -12,6 +16,7 @@ public class ParkourConfiguration extends MiniGameConfiguration {
private boolean mustDoGroupedInSequence;
private boolean ignoreRecordsUntilGroupBeatenOnce;
private boolean makePlayersInvisible;
private Set<Material> killPlaneBlocks;
/**
* Instantiates a new dropper configuration
@ -49,19 +54,36 @@ public class ParkourConfiguration extends MiniGameConfiguration {
return this.makePlayersInvisible;
}
/**
* Gets all types of blocks constituting parkour arenas' kill planes
*
* @return <p>The types of blocks causing a player to fail a parkour map</p>
*/
public Set<Material> getKillPlaneBlocks() {
return new HashSet<>(this.killPlaneBlocks);
}
@Override
public void load() {
protected void load() {
this.mustDoGroupedInSequence = configuration.getBoolean(rootNode + "mustDoGroupedInSequence", true);
this.ignoreRecordsUntilGroupBeatenOnce = configuration.getBoolean(rootNode + "ignoreRecordsUntilGroupBeatenOnce", false);
this.makePlayersInvisible = configuration.getBoolean(rootNode + "makePlayersInvisible", false);
this.killPlaneBlocks = loadMaterialList(rootNode + "killPlaneBlocks");
}
@Override
public String toString() {
return "Current configuration:" +
"\n" + "Must do groups in sequence: " + mustDoGroupedInSequence +
"\n" + "Ignore records until group beaten once: " + ignoreRecordsUntilGroupBeatenOnce +
"\n" + "Make players invisible: " + makePlayersInvisible;
StringBuilder builder = new StringBuilder(
"Current configuration:" +
"Current configuration:" +
"\n" + "Must do groups in sequence: " + mustDoGroupedInSequence +
"\n" + "Ignore records until group beaten once: " + ignoreRecordsUntilGroupBeatenOnce +
"\n" + "Make players invisible: " + makePlayersInvisible +
"\n" + "Kill plane blocks: ");
for (Material material : killPlaneBlocks) {
builder.append("\n - ").append(material.name());
}
return builder.toString();
}
}

View File

@ -1,4 +1,4 @@
package net.knarcraft.dropper.config;
package net.knarcraft.minigames.config;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
@ -46,7 +46,7 @@ public class SharedConfiguration extends MiniGameConfiguration {
}
@Override
public void load() {
protected void load() {
this.liquidHitBoxDepth = configuration.getDouble(rootNode + "liquidHitBoxDepth", -0.8);
this.solidHitBoxDistance = configuration.getDouble(rootNode + "solidHitBoxDistance", 0.2);

View File

@ -0,0 +1,49 @@
package net.knarcraft.minigames.container;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
/**
* A container that is serializable
*
* @param <K> <p>The type of the contained object</p>
*/
public abstract class SerializableContainer<K> implements ConfigurationSerializable {
private final K value;
/**
* Instantiates a new serializable container
*
* @param value <p>The value to contain</p>
*/
public SerializableContainer(K value) {
this.value = value;
}
/**
* Gets the raw, non-serializable object
*
* @return <p>The raw stored value</p>
*/
public K getRawValue() {
return value;
}
/**
* Gets a serializable container containing the given value
*
* @param value <p>The value to make serializable</p>
* @return <p>The serializable value</p>
*/
public abstract SerializableContainer<K> getSerializable(K value);
@Override
public boolean equals(Object object) {
if (object instanceof SerializableContainer<?>) {
return this.getRawValue().equals(((SerializableContainer<?>) object).getRawValue());
} else {
return false;
}
}
}

View File

@ -0,0 +1,52 @@
package net.knarcraft.minigames.container;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
/**
* A material container able to be serialized
*/
public class SerializableMaterial extends SerializableContainer<Material> {
/**
* Instantiates a new serializable material
*
* @param material <p>The material to contain</p>
*/
public SerializableMaterial(Material material) {
super(material);
}
@Override
public SerializableContainer<Material> getSerializable(Material value) {
return new SerializableMaterial(value);
}
@NotNull
@Override
public Map<String, Object> serialize() {
Map<String, Object> data = new HashMap<>();
data.put("name", getRawValue().name());
return data;
}
/**
* Deserializes a serialized material
*
* @param data <p>The serialized data</p>
* @return <p>The deserialized material</p>
*/
@SuppressWarnings("unused")
public static SerializableMaterial deserialize(Map<String, Object> data) {
Material material = Material.matchMaterial((String) data.get("name"));
if (material == null) {
return null;
} else {
return new SerializableMaterial(material);
}
}
}

View File

@ -1,6 +1,5 @@
package net.knarcraft.dropper.container;
package net.knarcraft.minigames.container;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
@ -9,16 +8,28 @@ import java.util.UUID;
/**
* A UUID container able to be serialized
*
* @param uuid <p>The UUID stored by this record</p>
*/
public record SerializableUUID(UUID uuid) implements ConfigurationSerializable {
public class SerializableUUID extends SerializableContainer<UUID> {
/**
* Instantiates a new serializable uuid
*
* @param value <p>The uuid to contain</p>
*/
public SerializableUUID(UUID value) {
super(value);
}
@Override
public SerializableContainer<UUID> getSerializable(UUID value) {
return new SerializableUUID(value);
}
@NotNull
@Override
public Map<String, Object> serialize() {
Map<String, Object> data = new HashMap<>();
data.put("id", uuid.toString());
data.put("id", getRawValue().toString());
return data;
}
@ -38,13 +49,4 @@ public record SerializableUUID(UUID uuid) implements ConfigurationSerializable {
}
}
@Override
public boolean equals(Object object) {
if (object instanceof SerializableUUID) {
return this.uuid.equals(((SerializableUUID) object).uuid);
} else {
return false;
}
}
}

View File

@ -1,7 +1,7 @@
package net.knarcraft.dropper.listener;
package net.knarcraft.minigames.listener;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.dropper.DropperArenaSession;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArenaSession;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

View File

@ -1,8 +1,8 @@
package net.knarcraft.dropper.listener;
package net.knarcraft.minigames.listener;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.dropper.DropperArenaPlayerRegistry;
import net.knarcraft.dropper.arena.dropper.DropperArenaSession;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArenaPlayerRegistry;
import net.knarcraft.minigames.arena.dropper.DropperArenaSession;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;

View File

@ -1,10 +1,11 @@
package net.knarcraft.dropper.listener;
package net.knarcraft.minigames.listener;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.dropper.DropperArenaGameMode;
import net.knarcraft.dropper.arena.dropper.DropperArenaPlayerRegistry;
import net.knarcraft.dropper.arena.dropper.DropperArenaSession;
import net.knarcraft.dropper.config.DropperConfiguration;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArenaGameMode;
import net.knarcraft.minigames.arena.dropper.DropperArenaPlayerRegistry;
import net.knarcraft.minigames.arena.dropper.DropperArenaSession;
import net.knarcraft.minigames.config.DropperConfiguration;
import net.knarcraft.minigames.config.SharedConfiguration;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -78,8 +79,9 @@ public class MoveListener implements Listener {
* @return <p>True if a special block has been hit</p>
*/
private boolean checkForSpecialBlock(DropperArenaSession arenaSession, Location toLocation) {
double liquidDepth = configuration.getLiquidHitBoxDepth();
double solidDepth = configuration.getSolidHitBoxDistance();
SharedConfiguration sharedConfiguration = MiniGames.getInstance().getSharedConfiguration();
double liquidDepth = sharedConfiguration.getLiquidHitBoxDepth();
double solidDepth = sharedConfiguration.getSolidHitBoxDistance();
// Check if the player enters water
Material winBlockType = arenaSession.getArena().getWinBlockType();

View File

@ -1,7 +1,7 @@
package net.knarcraft.dropper.listener;
package net.knarcraft.minigames.listener;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.dropper.DropperArenaSession;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArenaSession;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;

View File

@ -1,17 +1,19 @@
package net.knarcraft.dropper.placeholder;
package net.knarcraft.minigames.placeholder;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.dropper.DropperArena;
import net.knarcraft.dropper.arena.dropper.DropperArenaGameMode;
import net.knarcraft.dropper.arena.dropper.DropperArenaGroup;
import net.knarcraft.dropper.arena.dropper.DropperArenaHandler;
import net.knarcraft.dropper.arena.dropper.DropperArenaRecordsRegistry;
import net.knarcraft.dropper.arena.record.ArenaRecord;
import net.knarcraft.dropper.placeholder.parsing.InfoType;
import net.knarcraft.dropper.placeholder.parsing.SelectionType;
import net.knarcraft.dropper.property.RecordType;
import net.knarcraft.dropper.util.DropperGroupRecordHelper;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaGameMode;
import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
import net.knarcraft.minigames.arena.dropper.DropperArena;
import net.knarcraft.minigames.arena.dropper.DropperArenaGameMode;
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
import net.knarcraft.minigames.arena.dropper.DropperArenaRecordsRegistry;
import net.knarcraft.minigames.arena.record.ArenaRecord;
import net.knarcraft.minigames.placeholder.parsing.InfoType;
import net.knarcraft.minigames.placeholder.parsing.SelectionType;
import net.knarcraft.minigames.property.RecordType;
import net.knarcraft.minigames.util.DropperGroupRecordHelper;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
@ -245,10 +247,10 @@ public class DropperRecordExpansion extends PlaceholderExpansion {
if (arena == null) {
return null;
}
@NotNull Map<DropperArenaGameMode, DropperArenaRecordsRegistry> registries = arena.getData().recordRegistries();
DropperArenaRecordsRegistry recordsRegistry = registries.get(gameMode);
@NotNull Map<ArenaGameMode, ArenaRecordsRegistry> registries = arena.getData().getRecordRegistries();
ArenaRecordsRegistry recordsRegistry = registries.get(gameMode);
ArenaRecord<?> record = getRecord(recordsRegistry, recordType, recordNumber);
ArenaRecord<?> record = getRecord((DropperArenaRecordsRegistry) recordsRegistry, recordType, recordNumber);
// If a record number is not found, leave it blank, so it looks neat
if (record == null) {

View File

@ -1,8 +1,8 @@
package net.knarcraft.dropper.placeholder;
package net.knarcraft.minigames.placeholder;
import net.knarcraft.dropper.arena.dropper.DropperArenaGameMode;
import net.knarcraft.dropper.arena.record.ArenaRecord;
import net.knarcraft.dropper.property.RecordType;
import net.knarcraft.minigames.arena.dropper.DropperArenaGameMode;
import net.knarcraft.minigames.arena.record.ArenaRecord;
import net.knarcraft.minigames.property.RecordType;
import org.jetbrains.annotations.NotNull;
import java.util.Set;

View File

@ -1,4 +1,4 @@
package net.knarcraft.dropper.placeholder.parsing;
package net.knarcraft.minigames.placeholder.parsing;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

View File

@ -1,4 +1,4 @@
package net.knarcraft.dropper.placeholder.parsing;
package net.knarcraft.minigames.placeholder.parsing;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

View File

@ -1,4 +1,4 @@
package net.knarcraft.dropper.property;
package net.knarcraft.minigames.property;
/**
* A representation of all possible record results

View File

@ -1,4 +1,4 @@
package net.knarcraft.dropper.property;
package net.knarcraft.minigames.property;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

View File

@ -1,16 +1,19 @@
package net.knarcraft.dropper.util;
package net.knarcraft.minigames.util;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.ArenaGameMode;
import net.knarcraft.dropper.arena.ArenaRecordsRegistry;
import net.knarcraft.dropper.arena.dropper.DropperArena;
import net.knarcraft.dropper.arena.dropper.DropperArenaData;
import net.knarcraft.dropper.arena.dropper.DropperArenaGameMode;
import net.knarcraft.dropper.arena.dropper.DropperArenaGroup;
import net.knarcraft.dropper.arena.dropper.DropperArenaRecordsRegistry;
import net.knarcraft.dropper.arena.dropper.DropperArenaStorageKey;
import net.knarcraft.dropper.container.SerializableMaterial;
import net.knarcraft.dropper.container.SerializableUUID;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaGameMode;
import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
import net.knarcraft.minigames.arena.dropper.DropperArena;
import net.knarcraft.minigames.arena.dropper.DropperArenaData;
import net.knarcraft.minigames.arena.dropper.DropperArenaGameMode;
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
import net.knarcraft.minigames.arena.dropper.DropperArenaRecordsRegistry;
import net.knarcraft.minigames.arena.dropper.DropperArenaStorageKey;
import net.knarcraft.minigames.arena.parkour.ParkourArena;
import net.knarcraft.minigames.arena.parkour.ParkourArenaData;
import net.knarcraft.minigames.arena.parkour.ParkourArenaStorageKey;
import net.knarcraft.minigames.container.SerializableMaterial;
import net.knarcraft.minigames.container.SerializableUUID;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
@ -33,8 +36,10 @@ import java.util.logging.Level;
public final class ArenaStorageHelper {
private final static File dataFolder = MiniGames.getInstance().getDataFolder();
private final static String arenasConfigurationSection = "arenas";
private final static String groupsConfigurationSection = "groups";
private final static String dropperArenasConfigurationSection = "dropperArenas";
private final static String dropperGroupsConfigurationSection = "dropperGroups";
private final static String parkourArenasConfigurationSection = "parkourArenas";
private final static String parkourGroupsConfigurationSection = "parkourGroups";
private static final File arenaFile = new File(dataFolder, "arenas.yml");
private static final File groupFile = new File(dataFolder, "groups.yml");
private static final File dropperArenaDataFolder = new File(dataFolder, "dropper_arena_data");
@ -52,7 +57,7 @@ public final class ArenaStorageHelper {
*/
public static void saveDropperArenaGroups(@NotNull Set<DropperArenaGroup> arenaGroups) throws IOException {
YamlConfiguration configuration = new YamlConfiguration();
ConfigurationSection groupSection = configuration.createSection(groupsConfigurationSection);
ConfigurationSection groupSection = configuration.createSection(dropperGroupsConfigurationSection);
for (DropperArenaGroup arenaGroup : arenaGroups) {
groupSection.set(arenaGroup.getGroupId().toString(), arenaGroup);
@ -68,7 +73,7 @@ public final class ArenaStorageHelper {
*/
public static @NotNull Set<DropperArenaGroup> loadDropperArenaGroups() {
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(groupFile);
ConfigurationSection groupSection = configuration.getConfigurationSection(groupsConfigurationSection);
ConfigurationSection groupSection = configuration.getConfigurationSection(dropperGroupsConfigurationSection);
//If no such section exists, it must be the case that there is no data to load
if (groupSection == null) {
return new HashSet<>();
@ -91,7 +96,7 @@ public final class ArenaStorageHelper {
*/
public static void saveDropperArenas(@NotNull Map<UUID, DropperArena> arenas) throws IOException {
YamlConfiguration configuration = new YamlConfiguration();
ConfigurationSection arenaSection = configuration.createSection(arenasConfigurationSection);
ConfigurationSection arenaSection = configuration.createSection(dropperArenasConfigurationSection);
for (DropperArena arena : arenas.values()) {
//Note: While the arena name is used as the key, as the key has to be sanitized, the un-sanitized arena name
// must be stored as well
@ -108,6 +113,32 @@ public final class ArenaStorageHelper {
configuration.save(arenaFile);
}
/**
* Saves the given arenas
*
* @param arenas <p>The arenas to save</p>
* @throws IOException <p>If unable to write to the file</p>
*/
public static void saveParkourArenas(@NotNull Map<UUID, ParkourArena> arenas) throws IOException {
YamlConfiguration configuration = new YamlConfiguration();
ConfigurationSection arenaSection = configuration.createSection(parkourArenasConfigurationSection);
for (ParkourArena arena : arenas.values()) {
//Note: While the arena name is used as the key, as the key has to be sanitized, the un-sanitized arena name
// must be stored as well
@NotNull ConfigurationSection configSection = arenaSection.createSection(arena.getArenaId().toString());
configSection.set(ParkourArenaStorageKey.ID.getKey(), new SerializableUUID(arena.getArenaId()));
configSection.set(ParkourArenaStorageKey.NAME.getKey(), arena.getArenaName());
configSection.set(ParkourArenaStorageKey.SPAWN_LOCATION.getKey(), arena.getSpawnLocation());
configSection.set(ParkourArenaStorageKey.EXIT_LOCATION.getKey(), arena.getExitLocation());
configSection.set(ParkourArenaStorageKey.WIN_BLOCK_TYPE.getKey(), new SerializableMaterial(arena.getWinBlockType()));
configSection.set(ParkourArenaStorageKey.WIN_LOCATION.getKey(), arena.getWinLocation());
configSection.set(ParkourArenaStorageKey.KILL_PLANE_BLOCKS.getKey(), arena.getKillPlaneBlocks());
configSection.set(ParkourArenaStorageKey.CHECKPOINTS.getKey(), arena.getCheckpoints());
saveParkourArenaData(arena.getData());
}
configuration.save(arenaFile);
}
/**
* Loads all arenas
*
@ -115,7 +146,7 @@ public final class ArenaStorageHelper {
*/
public static @NotNull Map<UUID, DropperArena> loadDropperArenas() {
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(arenaFile);
ConfigurationSection arenaSection = configuration.getConfigurationSection(arenasConfigurationSection);
ConfigurationSection arenaSection = configuration.getConfigurationSection(dropperArenasConfigurationSection);
//If no such section exists, it must be the case that there is no data to load
if (arenaSection == null) {
return new HashMap<>();
@ -147,7 +178,7 @@ public final class ArenaStorageHelper {
*/
private static @Nullable DropperArena loadDropperArena(@NotNull ConfigurationSection configurationSection) {
UUID arenaId = ((SerializableUUID) configurationSection.get(DropperArenaStorageKey.ID.getKey(),
new SerializableUUID(UUID.randomUUID()))).uuid();
new SerializableUUID(UUID.randomUUID()))).getRawValue();
String arenaName = configurationSection.getString(DropperArenaStorageKey.NAME.getKey());
Location spawnLocation = (Location) configurationSection.get(DropperArenaStorageKey.SPAWN_LOCATION.getKey());
Location exitLocation = (Location) configurationSection.get(DropperArenaStorageKey.EXIT_LOCATION.getKey());
@ -178,7 +209,19 @@ public final class ArenaStorageHelper {
}
return new DropperArena(arenaId, arenaName, spawnLocation, exitLocation, verticalVelocity, horizontalVelocity,
winBlockType.material(), arenaData, MiniGames.getInstance().getDropperArenaHandler());
winBlockType.getRawValue(), arenaData, MiniGames.getInstance().getDropperArenaHandler());
}
/**
* Stores the given arena data to a file
*
* @param arenaData <p>The arena data to store</p>
*/
public static void saveParkourArenaData(@NotNull ParkourArenaData arenaData) throws IOException {
YamlConfiguration configuration = new YamlConfiguration();
configuration.set(ParkourArenaStorageKey.DATA.getKey(), arenaData);
configuration.save(getParkourArenaDataFile(arenaData.getArenaId()));
}
/**
@ -205,6 +248,18 @@ public final class ArenaStorageHelper {
return (DropperArenaData) configuration.get(DropperArenaStorageKey.DATA.getKey());
}
/**
* Loads arena data for the given arena id
*
* @param arenaId <p>The id of the arena to get data for</p>
* @return <p>The loaded arena data</p>
*/
private static @Nullable ParkourArenaData loadParkourArenaData(@NotNull UUID arenaId) {
File arenaDataFile = getParkourArenaDataFile(arenaId);
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(arenaDataFile);
return (ParkourArenaData) configuration.get(ParkourArenaStorageKey.DATA.getKey());
}
/**
* Removes data for the arena with the given id
*
@ -215,6 +270,16 @@ public final class ArenaStorageHelper {
return getDropperArenaDataFile(arenaId).delete();
}
/**
* Removes data for the arena with the given id
*
* @param arenaId <p>The id of the arena to remove data for</p>
* @return <p>True if the data was successfully removed</p>
*/
public static boolean removeParkourArenaData(@NotNull UUID arenaId) {
return getParkourArenaDataFile(arenaId).delete();
}
/**
* Gets the file used to store the given arena id's data
*
@ -222,8 +287,29 @@ public final class ArenaStorageHelper {
* @return <p>The file the arena's data is/should be stored in</p>
*/
private static @NotNull File getDropperArenaDataFile(@NotNull UUID arenaId) {
File arenaDataFile = new File(parkourArenaDataFolder, arenaId + ".yml");
if (!parkourArenaDataFolder.exists() && !parkourArenaDataFolder.mkdirs()) {
return getArenaDataFile(dropperArenaDataFolder, arenaId);
}
/**
* Gets the file used to store the given arena id's data
*
* @param arenaId <p>The id of the arena to get a data file for</p>
* @return <p>The file the arena's data is/should be stored in</p>
*/
private static @NotNull File getParkourArenaDataFile(@NotNull UUID arenaId) {
return getArenaDataFile(parkourArenaDataFolder, arenaId);
}
/**
* Gets the file used to store the given arena id's data
*
* @param root <p>The root directory for the file</p>
* @param arenaId <p>The id of the arena to get a data file for</p>
* @return <p>The file the arena's data is/should be stored in</p>
*/
private static @NotNull File getArenaDataFile(File root, @NotNull UUID arenaId) {
File arenaDataFile = new File(root, arenaId + ".yml");
if (!root.exists() && !root.mkdirs()) {
MiniGames.log(Level.SEVERE, "Unable to create the arena data directories");
}
return arenaDataFile;

View File

@ -1,12 +1,12 @@
package net.knarcraft.dropper.util;
package net.knarcraft.minigames.util;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.dropper.DropperArena;
import net.knarcraft.dropper.arena.dropper.DropperArenaGameMode;
import net.knarcraft.dropper.arena.dropper.DropperArenaGroup;
import net.knarcraft.dropper.arena.dropper.DropperArenaHandler;
import net.knarcraft.dropper.arena.record.ArenaRecord;
import net.knarcraft.dropper.arena.record.SummableArenaRecord;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArena;
import net.knarcraft.minigames.arena.dropper.DropperArenaGameMode;
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
import net.knarcraft.minigames.arena.record.ArenaRecord;
import net.knarcraft.minigames.arena.record.SummableArenaRecord;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
@ -36,7 +36,7 @@ public final class DropperGroupRecordHelper {
@NotNull DropperArenaGameMode gameMode) {
Map<UUID, SummableArenaRecord<Integer>> records = new HashMap<>();
@NotNull BiFunction<DropperArena, DropperArenaGameMode, Set<SummableArenaRecord<Integer>>> recordSupplier =
(arena, aGameMode) -> arena.getData().recordRegistries().get(gameMode).getLeastDeathsRecords();
(arena, aGameMode) -> arena.getData().getRecordRegistries().get(gameMode).getLeastDeathsRecords();
return getCombined(group, gameMode, records, recordSupplier);
}
@ -52,7 +52,7 @@ public final class DropperGroupRecordHelper {
@NotNull DropperArenaGameMode gameMode) {
Map<UUID, SummableArenaRecord<Long>> records = new HashMap<>();
@NotNull BiFunction<DropperArena, DropperArenaGameMode, Set<SummableArenaRecord<Long>>> recordSupplier =
(arena, aGameMode) -> arena.getData().recordRegistries().get(gameMode).getShortestTimeMilliSecondsRecords();
(arena, aGameMode) -> arena.getData().getRecordRegistries().get(gameMode).getShortestTimeMilliSecondsRecords();
return getCombined(group, gameMode, records, recordSupplier);
}

View File

@ -1,4 +1,4 @@
package net.knarcraft.dropper.util;
package net.knarcraft.minigames.util;
import org.bukkit.Location;
import org.bukkit.World;

View File

@ -1,6 +1,6 @@
package net.knarcraft.dropper.util;
package net.knarcraft.minigames.util;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.minigames.MiniGames;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;

View File

@ -0,0 +1,85 @@
package net.knarcraft.minigames.util;
import net.knarcraft.minigames.container.SerializableContainer;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* A converter for converting between normal and serializable classes
*/
public final class SerializableConverter {
private SerializableConverter() {
}
/**
* Converts the given collection into a collection of serializable objects
*
* @param values <p>The values to make serializable</p>
* @param targetCollection <p>The collection to store the converted objects to</p>
* @param target <p>An instance of the target serializable container</p>
* @param <T> <p>The type of the value to make serializable</p>
*/
public static <T> void makeSerializable(@NotNull Collection<T> values,
@NotNull Collection<SerializableContainer<T>> targetCollection,
@NotNull SerializableContainer<T> target) {
for (T item : values) {
targetCollection.add(target.getSerializable(item));
}
}
/**
* Converts the given collection of serializable containers into a collection of normal objects
*
* @param values <p>The values to convert to normal</p>
* @param targetCollection <p>The collection to store the converted objects to</p>
* @param <T> <p>The type of the value to convert to normal</p>
*/
public static <T> void getRawValue(@NotNull Collection<SerializableContainer<T>> values,
@NotNull Collection<T> targetCollection) {
for (SerializableContainer<T> item : values) {
targetCollection.add(item.getRawValue());
}
}
/**
* Converts the given collection into a collection of serializable objects
*
* @param values <p>The values to make serializable</p>
* @param targetMap <p>The map to store the converted objects to</p>
* @param target <p>An instance of the target serializable container</p>
* @param <T> <p>The type of the value to make serializable</p>
*/
public static <S, T> void makeSerializable(@NotNull Map<S, Set<T>> values,
@NotNull Map<S, Set<SerializableContainer<T>>> targetMap,
@NotNull SerializableContainer<T> target) {
for (Map.Entry<S, Set<T>> item : values.entrySet()) {
Set<SerializableContainer<T>> conversionCollection = new HashSet<>();
makeSerializable(item.getValue(), conversionCollection, target);
targetMap.put(item.getKey(), conversionCollection);
}
}
/**
* Converts the given collection of serializable containers into a collection of normal objects
*
* @param values <p>The values to convert to normal</p>
* @param targetMap <p>The map to store the converted objects to</p>
* @param <S> <p>The type of the map's key</p>
* @param <T> <p>The type of the value to convert to normal</p>
*/
public static <S, T> void getRawValue(@NotNull Map<S, Set<SerializableContainer<T>>> values,
@NotNull Map<S, Set<T>> targetMap) {
for (Map.Entry<S, Set<SerializableContainer<T>>> item : values.entrySet()) {
Set<T> conversionCollection = new HashSet<>();
getRawValue(item.getValue(), conversionCollection);
targetMap.put(item.getKey(), conversionCollection);
}
}
}

View File

@ -1,4 +1,4 @@
package net.knarcraft.dropper.util;
package net.knarcraft.minigames.util;
import org.jetbrains.annotations.NotNull;

View File

@ -1,8 +1,8 @@
package net.knarcraft.dropper.util;
package net.knarcraft.minigames.util;
import net.knarcraft.dropper.MiniGames;
import net.knarcraft.dropper.arena.dropper.DropperArena;
import net.knarcraft.dropper.arena.dropper.DropperArenaEditableProperty;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArena;
import net.knarcraft.minigames.arena.dropper.DropperArenaEditableProperty;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;

View File

@ -1,4 +1,20 @@
# Configuration values for droppers
# Configuration values for mini-games
parkour:
# Whether grouped dropper arenas must be played in the correct sequence
mustDoGroupedInSequence: true
# Whether records won't be registered unless the player has already beaten all arenas in a group. That means players
# are required to do a second play-through to register a record for a grouped arena.
ignoreRecordsUntilGroupBeatenOnce: false
# Whether players should be made invisible while playing in a dropper arena
makePlayersInvisible: false
# The blocks compromising parkour arenas' kill planes. Add any materials you want to use for the "bottom" of your
# parkour arenas.
killPlaneBlocks:
- LAVA
- MAGMA_BLOCK
dropper:
# Whether to block using the shift key to drop faster than the intended drop speed
blockSneaking: true
@ -34,14 +50,6 @@ dropper:
# pushing each-other if in the same arena.
disableHitCollision: true
# This decides how far inside a non-solid block the player must go before detection triggers (-1, 0). The closer to -1
# it is, the more accurate it will seem to the player, but the likelihood of not detecting the hit increases.
liquidHitBoxDepth: -0.8
# This decides the distance the player must be from a block below them before a hit triggers (0, 1). If too low, the
# likelihood of detecting the hit decreases, but it won't look like the player hit the block without being near.
solidHitBoxDistance: 0.2
# A whitelist for which blocks won't trigger a loss when hit/passed through. The win block check happens before the
# loss check, so even blocks on the whitelist can be used as the win-block. "+" denotes a material tag.
blockWhitelist:
@ -56,4 +64,12 @@ dropper:
- +BANNERS
- +BUTTONS
- +CORALS
- +WALL_CORALS
- +WALL_CORALS
shared:
# This decides how far inside a non-solid block the player must go before detection triggers (-1, 0). The closer to -1
# it is, the more accurate it will seem to the player, but the likelihood of not detecting the hit increases.
liquidHitBoxDepth: -0.8
# This decides the distance the player must be from a block below them before a hit triggers (0, 1). If too low, the
# likelihood of detecting the hit decreases, but it won't look like the player hit the block without being near.
solidHitBoxDistance: 0.2

View File

@ -1,6 +1,6 @@
name: Dropper
version: '${project.version}'
main: net.knarcraft.dropper.MiniGames
main: net.knarcraft.minigames.MiniGames
api-version: 1.19
description: A plugin that adds various mini-games
softdepend:

View File

@ -1,6 +1,6 @@
package net.knarcraft.dropper.arena;
package net.knarcraft.minigames.arena;
import net.knarcraft.dropper.arena.dropper.DropperArenaGroup;
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;