Compare commits

..

No commits in common. "master" and "v1.2" have entirely different histories.
master ... v1.2

11 changed files with 36 additions and 60 deletions

View File

@ -105,6 +105,12 @@
<version>24.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>

View File

@ -104,7 +104,7 @@ public abstract class AbstractArenaPlayerRegistry<K extends Arena> implements Ar
for (PlayerEntryState entryState : entryStates) {
this.entryStates.put(entryState.getPlayerId(), entryState);
}
if (!this.entryStates.isEmpty()) {
if (this.entryStates.size() > 0) {
MiniGames.log(Level.WARNING, entryStates.size() + " un-exited sessions found. This happens if " +
"players leave in the middle of a game, or if the server crashes. MiniGames will do its best " +
"to fix the players' states.");

View File

@ -34,11 +34,11 @@ public enum DropperArenaGameMode implements ConfigurationSerializable, ArenaGame
* @param gameMode <p>The game-mode string to match</p>
* @return <p>The specified arena game-mode</p>
*/
public static @NotNull DropperArenaGameMode matchGameMode(@NotNull String gameMode) {
public static @NotNull DropperArenaGameMode matchGamemode(@NotNull String gameMode) {
String sanitized = gameMode.trim().toLowerCase();
if (sanitized.matches("(invert(ed)?|inverse)")) {
return DropperArenaGameMode.INVERTED;
} else if (sanitized.matches("rand(om)?_?(inverted)?")) {
} else if (sanitized.matches("rand(om)?")) {
return DropperArenaGameMode.RANDOM_INVERTED;
} else {
return DropperArenaGameMode.DEFAULT;

View File

@ -44,13 +44,6 @@ public abstract class ArenaRecord<K extends Comparable<K>> implements Comparable
return record;
}
/**
* Gets this as a string that should be printed on a sign
*
* @return <p>This as a string</p>
*/
public abstract String getAsString();
@Override
public boolean equals(Object other) {
return other instanceof ArenaRecord<?> && userId.equals(((ArenaRecord<?>) other).userId);
@ -77,7 +70,7 @@ public abstract class ArenaRecord<K extends Comparable<K>> implements Comparable
@Override
public String toString() {
return userId + ":" + record;
return userId + ": " + record;
}
}

View File

@ -19,11 +19,6 @@ public class IntegerRecord extends SummableArenaRecord<Integer> {
super(userId, record);
}
@Override
public String getAsString() {
return String.valueOf(this.getRecord());
}
@Override
public SummableArenaRecord<Integer> sum(Integer value) {
return new IntegerRecord(this.getUserId(), this.getRecord() + value);

View File

@ -7,7 +7,7 @@ import java.util.Map;
import java.util.UUID;
/**
* A record storing a Long time
* A record storing a Long
*/
public class LongRecord extends SummableArenaRecord<Long> {
@ -29,22 +29,6 @@ public class LongRecord extends SummableArenaRecord<Long> {
return new LongRecord(this.getUserId(), this.getRecord() + value);
}
@Override
public String getAsString() {
int seconds = (int) Math.floor(getRecord() / 1000.0);
int minutes = 0;
if (seconds > 60) {
minutes = (int) Math.floor(seconds / 60.0);
seconds = seconds % 60;
}
if (minutes > 0) {
return minutes + "m" + seconds + "s";
} else {
return seconds + "s";
}
}
/**
* Deserializes the saved arena record
*

View File

@ -38,7 +38,7 @@ public class JoinDropperArenaCommand implements CommandExecutor {
// Disallow joining if the player is already in a mini-game arena
if (MiniGames.getInstance().getSession(player.getUniqueId()) != null) {
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ALREADY_PLAYING);
return true;
return false;
}
// Make sure the arena exists
@ -51,11 +51,10 @@ public class JoinDropperArenaCommand implements CommandExecutor {
// Deny vehicles as allowing this is tricky, and will cause problems in some cases
if (player.isInsideVehicle() || !player.getPassengers().isEmpty()) {
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_JOIN_IN_VEHICLE_OR_PASSENGER);
return true;
return false;
}
joinArena(specifiedArena, player, arguments);
return true;
return joinArena(specifiedArena, player, arguments);
}
/**
@ -64,12 +63,13 @@ public class JoinDropperArenaCommand implements CommandExecutor {
* @param specifiedArena <p>The arena the player wants to join</p>
* @param player <p>The player joining the arena</p>
* @param arguments <p>The arguments given</p>
* @return <p>Whether the arena was joined successfully</p>
*/
private void joinArena(DropperArena specifiedArena, Player player, String[] arguments) {
private boolean joinArena(DropperArena specifiedArena, Player player, String[] arguments) {
// Find the specified game-mode
DropperArenaGameMode gameMode;
if (arguments.length > 1) {
gameMode = DropperArenaGameMode.matchGameMode(arguments[1]);
gameMode = DropperArenaGameMode.matchGamemode(arguments[1]);
} else {
gameMode = DropperArenaGameMode.DEFAULT;
}
@ -77,7 +77,7 @@ public class JoinDropperArenaCommand implements CommandExecutor {
// Make sure the player has beaten the necessary levels
DropperArenaGroup arenaGroup = MiniGames.getInstance().getDropperArenaHandler().getGroup(specifiedArena.getArenaId());
if (arenaGroup != null && !doGroupChecks(specifiedArena, arenaGroup, gameMode, player)) {
return;
return false;
}
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
@ -87,7 +87,7 @@ public class JoinDropperArenaCommand implements CommandExecutor {
gameMode != DropperArenaGameMode.DEFAULT &&
specifiedArena.getData().hasNotCompleted(DropperArenaGameMode.DEFAULT, player)) {
stringFormatter.displayErrorMessage(player, MiniGameMessage.ERROR_NORMAL_MODE_REQUIRED);
return;
return false;
}
// Register the player's session
@ -103,12 +103,14 @@ public class JoinDropperArenaCommand implements CommandExecutor {
if (!teleported) {
stringFormatter.displayErrorMessage(player, MiniGameMessage.ERROR_ARENA_TELEPORT_FAILED);
newSession.triggerQuit(false, true);
return false;
} else {
// Update the player's state to follow the arena's rules
newSession.getEntryState().setArenaState();
player.getInventory().addItem(GUIHelper.getGUIOpenItem());
stringFormatter.displaySuccessMessage(player, MiniGameMessage.SUCCESS_ARENA_JOINED);
return true;
}
}

View File

@ -38,7 +38,7 @@ public class JoinParkourArenaCommand implements CommandExecutor {
// Disallow joining if the player is already in a mini-game arena
if (MiniGames.getInstance().getSession(player.getUniqueId()) != null) {
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ALREADY_PLAYING);
return true;
return false;
}
// Make sure the arena exists
@ -51,11 +51,10 @@ public class JoinParkourArenaCommand implements CommandExecutor {
// Deny vehicles as allowing this is tricky, and will cause problems in some cases
if (player.isInsideVehicle() || !player.getPassengers().isEmpty()) {
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_JOIN_IN_VEHICLE_OR_PASSENGER);
return true;
return false;
}
joinArena(specifiedArena, player, arguments);
return true;
return joinArena(specifiedArena, player, arguments);
}
/**
@ -64,8 +63,9 @@ public class JoinParkourArenaCommand implements CommandExecutor {
* @param specifiedArena <p>The arena the player wants to join</p>
* @param player <p>The player joining the arena</p>
* @param arguments <p>The arguments given</p>
* @return <p>Whether the arena was joined successfully</p>
*/
private void joinArena(ParkourArena specifiedArena, Player player, String[] arguments) {
private boolean joinArena(ParkourArena specifiedArena, Player player, String[] arguments) {
// Find the specified game-mode
ParkourArenaGameMode gameMode;
if (arguments.length > 1) {
@ -78,13 +78,13 @@ public class JoinParkourArenaCommand implements CommandExecutor {
if (specifiedArena.hasNoCheckpoints() && gameMode == ParkourArenaGameMode.HARDCORE) {
MiniGames.getInstance().getStringFormatter().displayErrorMessage(player,
MiniGameMessage.ERROR_HARDCORE_NO_CHECKPOINTS);
return;
return false;
}
// Make sure the player has beaten the necessary levels
ParkourArenaGroup arenaGroup = MiniGames.getInstance().getParkourArenaHandler().getGroup(specifiedArena.getArenaId());
if (arenaGroup != null && !doGroupChecks(specifiedArena, arenaGroup, gameMode, player)) {
return;
return false;
}
// Register the player's session
@ -101,6 +101,7 @@ public class JoinParkourArenaCommand implements CommandExecutor {
MiniGames.getInstance().getStringFormatter().displayErrorMessage(player,
MiniGameMessage.ERROR_ARENA_TELEPORT_FAILED);
newSession.triggerQuit(false, true);
return false;
} else {
// Update the player's state to follow the arena's rules
newSession.getEntryState().setArenaState();
@ -108,6 +109,7 @@ public class JoinParkourArenaCommand implements CommandExecutor {
player.getInventory().addItem(GUIHelper.getGUIOpenItem());
MiniGames.getInstance().getStringFormatter().displaySuccessMessage(player,
MiniGameMessage.SUCCESS_ARENA_JOINED);
return true;
}
}

View File

@ -26,7 +26,7 @@ public class DropperRecordExpansion extends RecordExpansion {
@Override
protected @NotNull ArenaGameMode parseGameMode(@NotNull String gameMode) {
return DropperArenaGameMode.matchGameMode(gameMode);
return DropperArenaGameMode.matchGamemode(gameMode);
}
}

View File

@ -313,8 +313,8 @@ public abstract class RecordExpansion extends PlaceholderExpansion {
private String getRecordData(@NotNull InfoType infoType, @NotNull ArenaRecord<?> arenaRecord) {
return switch (infoType) {
case PLAYER -> getPlayerName(arenaRecord.getUserId());
case VALUE -> arenaRecord.getAsString();
case COMBINED -> getPlayerName(arenaRecord.getUserId()) + ": " + arenaRecord.getAsString();
case VALUE -> arenaRecord.getRecord().toString();
case COMBINED -> getPlayerName(arenaRecord.getUserId()) + ": " + arenaRecord.getRecord().toString();
};
}

View File

@ -20,7 +20,6 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.yaml.snakeyaml.error.YAMLException;
import java.io.File;
import java.io.IOException;
@ -250,14 +249,9 @@ public final class DropperArenaStorageHelper {
* @return <p>The loaded arena data</p>
*/
private static @Nullable DropperArenaData loadDropperArenaData(@NotNull UUID arenaId) {
try {
File arenaDataFile = getDropperArenaDataFile(arenaId);
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(arenaDataFile);
return (DropperArenaData) configuration.get(DropperArenaStorageKey.DATA.getKey());
} catch (YAMLException exception) {
MiniGames.log(Level.SEVERE, "Unable to load arena data from arena " + arenaId);
return null;
}
}
/**