mirror of
https://github.com/SunNetservers/MiniGames.git
synced 2025-04-02 09:46:26 +02:00
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
d7e950c53e | |||
c8fbdec64f |
6
pom.xml
6
pom.xml
@ -105,12 +105,6 @@
|
||||
<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>
|
||||
|
@ -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.size() > 0) {
|
||||
if (!this.entryStates.isEmpty()) {
|
||||
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.");
|
||||
|
@ -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)?")) {
|
||||
} else if (sanitized.matches("rand(om)?_?(inverted)?")) {
|
||||
return DropperArenaGameMode.RANDOM_INVERTED;
|
||||
} else {
|
||||
return DropperArenaGameMode.DEFAULT;
|
||||
|
@ -44,6 +44,13 @@ 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);
|
||||
@ -70,7 +77,7 @@ public abstract class ArenaRecord<K extends Comparable<K>> implements Comparable
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return userId + ": " + record;
|
||||
return userId + ":" + record;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,11 @@ 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);
|
||||
|
@ -7,7 +7,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A record storing a Long
|
||||
* A record storing a Long time
|
||||
*/
|
||||
public class LongRecord extends SummableArenaRecord<Long> {
|
||||
|
||||
@ -29,6 +29,22 @@ 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
|
||||
*
|
||||
|
@ -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 false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Make sure the arena exists
|
||||
@ -51,10 +51,11 @@ 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 false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return joinArena(specifiedArena, player, arguments);
|
||||
joinArena(specifiedArena, player, arguments);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,13 +64,12 @@ 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 boolean joinArena(DropperArena specifiedArena, Player player, String[] arguments) {
|
||||
private void 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 false;
|
||||
return;
|
||||
}
|
||||
|
||||
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 false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Register the player's session
|
||||
@ -103,14 +103,12 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Make sure the arena exists
|
||||
@ -51,10 +51,11 @@ 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 false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return joinArena(specifiedArena, player, arguments);
|
||||
joinArena(specifiedArena, player, arguments);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,9 +64,8 @@ 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 boolean joinArena(ParkourArena specifiedArena, Player player, String[] arguments) {
|
||||
private void 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 false;
|
||||
return;
|
||||
}
|
||||
|
||||
// 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 false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Register the player's session
|
||||
@ -101,7 +101,6 @@ 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();
|
||||
@ -109,7 +108,6 @@ public class JoinParkourArenaCommand implements CommandExecutor {
|
||||
player.getInventory().addItem(GUIHelper.getGUIOpenItem());
|
||||
MiniGames.getInstance().getStringFormatter().displaySuccessMessage(player,
|
||||
MiniGameMessage.SUCCESS_ARENA_JOINED);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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.getRecord().toString();
|
||||
case COMBINED -> getPlayerName(arenaRecord.getUserId()) + ": " + arenaRecord.getRecord().toString();
|
||||
case VALUE -> arenaRecord.getAsString();
|
||||
case COMBINED -> getPlayerName(arenaRecord.getUserId()) + ": " + arenaRecord.getAsString();
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ 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;
|
||||
@ -249,9 +250,14 @@ public final class DropperArenaStorageHelper {
|
||||
* @return <p>The loaded arena data</p>
|
||||
*/
|
||||
private static @Nullable DropperArenaData loadDropperArenaData(@NotNull UUID arenaId) {
|
||||
File arenaDataFile = getDropperArenaDataFile(arenaId);
|
||||
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(arenaDataFile);
|
||||
return (DropperArenaData) configuration.get(DropperArenaStorageKey.DATA.getKey());
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user