mirror of
https://github.com/SunNetservers/MiniGames.git
synced 2025-09-17 11:27:55 +02:00
Merge branch 'dev' into rewards
# Conflicts: # src/main/java/net/knarcraft/minigames/config/Message.java
This commit is contained in:
@@ -29,6 +29,11 @@ public abstract class AbstractArenaPlayerRegistry<K extends Arena> implements Ar
|
||||
loadEntryStates();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<UUID> getPlayingPlayers() {
|
||||
return arenaPlayers.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable PlayerEntryState getEntryState(@NotNull UUID playerId) {
|
||||
return this.entryStates.get(playerId);
|
||||
@@ -65,13 +70,15 @@ public abstract class AbstractArenaPlayerRegistry<K extends Arena> implements Ar
|
||||
|
||||
@Override
|
||||
public void removeForArena(K arena, boolean immediately) {
|
||||
Set<UUID> removed = new HashSet<>();
|
||||
for (Map.Entry<UUID, ArenaSession> entry : this.arenaPlayers.entrySet()) {
|
||||
if (entry.getValue().getArena() == arena) {
|
||||
// Kick the player gracefully
|
||||
entry.getValue().triggerQuit(immediately);
|
||||
this.arenaPlayers.remove(entry.getKey());
|
||||
entry.getValue().triggerQuit(immediately, false);
|
||||
removed.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
removed.forEach(this.arenaPlayers::remove);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,7 +1,8 @@
|
||||
package net.knarcraft.minigames.arena;
|
||||
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.container.PlaceholderContainer;
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.property.RecordResult;
|
||||
import net.knarcraft.minigames.util.PlayerTeleporter;
|
||||
import org.bukkit.Location;
|
||||
@@ -14,7 +15,7 @@ public abstract class AbstractArenaSession implements ArenaSession {
|
||||
private final @NotNull ArenaGameMode gameMode;
|
||||
private final @NotNull Player player;
|
||||
protected int deaths;
|
||||
protected final long startTime;
|
||||
protected long startTime;
|
||||
protected PlayerEntryState entryState;
|
||||
|
||||
/**
|
||||
@@ -33,13 +34,25 @@ public abstract class AbstractArenaSession implements ArenaSession {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void triggerQuit(boolean immediately) {
|
||||
public void triggerQuit(boolean immediately, boolean removeSession) {
|
||||
// Stop this session
|
||||
removeSession();
|
||||
if (removeSession) {
|
||||
removeSession();
|
||||
}
|
||||
// Teleport the player out of the arena
|
||||
teleportToExit(immediately);
|
||||
// Make the player visible to everyone
|
||||
MiniGames.getInstance().getPlayerVisibilityManager().showPlayersFor(player);
|
||||
|
||||
player.sendMessage(Message.SUCCESS_ARENA_QUIT.getMessage());
|
||||
MiniGames.getInstance().getStringFormatter().displaySuccessMessage(player, MiniGameMessage.SUCCESS_ARENA_QUIT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
this.deaths = 0;
|
||||
this.startTime = System.currentTimeMillis();
|
||||
PlayerTeleporter.teleportPlayer(this.player, this.arena.getSpawnLocation(), false, false);
|
||||
this.entryState.setArenaState();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,16 +69,17 @@ public abstract class AbstractArenaSession implements ArenaSession {
|
||||
// Gets a string representation of the played game-mode
|
||||
String gameModeString = getGameModeString();
|
||||
|
||||
Message recordInfoMessage = switch (recordResult) {
|
||||
case WORLD_RECORD -> Message.RECORD_ACHIEVED_GLOBAL;
|
||||
case PERSONAL_BEST -> Message.RECORD_ACHIEVED_PERSONAL;
|
||||
MiniGameMessage recordInfoMiniGameMessage = switch (recordResult) {
|
||||
case WORLD_RECORD -> MiniGameMessage.RECORD_ACHIEVED_GLOBAL;
|
||||
case PERSONAL_BEST -> MiniGameMessage.RECORD_ACHIEVED_PERSONAL;
|
||||
default -> throw new IllegalStateException("Unexpected value: " + recordResult);
|
||||
};
|
||||
String recordInfo = recordInfoMessage.getPartialMessage("{recordType}", type);
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
String recordInfo = stringFormatter.replacePlaceholder(recordInfoMiniGameMessage, "{recordType}", type);
|
||||
|
||||
PlaceholderContainer placeholderContainer = new PlaceholderContainer().add("{gameMode}", gameModeString);
|
||||
placeholderContainer.add("{recordInfo}", recordInfo);
|
||||
player.sendMessage(Message.SUCCESS_RECORD_ACHIEVED.getMessage(placeholderContainer));
|
||||
stringFormatter.displaySuccessMessage(player, stringFormatter.replacePlaceholders(
|
||||
MiniGameMessage.SUCCESS_RECORD_ACHIEVED, new String[]{"{gameMode}", "{recordInfo}"},
|
||||
new String[]{gameModeString, recordInfo}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -2,16 +2,22 @@ package net.knarcraft.minigames.arena;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import net.knarcraft.minigames.property.PersistentDataKey;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
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.logging.Level;
|
||||
|
||||
@@ -21,7 +27,6 @@ import java.util.logging.Level;
|
||||
public abstract class AbstractPlayerEntryState implements PlayerEntryState {
|
||||
|
||||
protected final UUID playerId;
|
||||
private final boolean makePlayerInvisible;
|
||||
private final Location entryLocation;
|
||||
private final boolean originalIsFlying;
|
||||
private final GameMode originalGameMode;
|
||||
@@ -33,12 +38,10 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState {
|
||||
/**
|
||||
* Instantiates a new abstract player entry state
|
||||
*
|
||||
* @param player <p>The player whose state this should keep track of</p>
|
||||
* @param makePlayerInvisible <p>Whether players should be made invisible while in the arena</p>
|
||||
* @param player <p>The player whose state this should keep track of</p>
|
||||
*/
|
||||
public AbstractPlayerEntryState(@NotNull Player player, boolean makePlayerInvisible) {
|
||||
public AbstractPlayerEntryState(@NotNull Player player) {
|
||||
this.playerId = player.getUniqueId();
|
||||
this.makePlayerInvisible = makePlayerInvisible;
|
||||
this.entryLocation = player.getLocation().clone();
|
||||
this.originalIsFlying = player.isFlying();
|
||||
this.originalGameMode = player.getGameMode();
|
||||
@@ -52,7 +55,6 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState {
|
||||
* Instantiates a new abstract player entry state
|
||||
*
|
||||
* @param playerId <p>The id of the player whose state this should keep track of</p>
|
||||
* @param makePlayerInvisible <p>Whether players should be made invisible while in the arena</p>
|
||||
* @param entryLocation <p>The location the player entered from</p>
|
||||
* @param originalIsFlying <p>Whether the player was flying before entering the arena</p>
|
||||
* @param originalGameMode <p>The game-mode of the player before entering the arena</p>
|
||||
@@ -61,12 +63,11 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState {
|
||||
* @param originalIsSwimming <p>Whether the player was swimming before entering the arena</p>
|
||||
* @param originalCollideAble <p>Whether the player was collide-able before entering the arena</p>
|
||||
*/
|
||||
public AbstractPlayerEntryState(@NotNull UUID playerId, boolean makePlayerInvisible, Location entryLocation,
|
||||
public AbstractPlayerEntryState(@NotNull UUID playerId, Location entryLocation,
|
||||
boolean originalIsFlying, GameMode originalGameMode, boolean originalAllowFlight,
|
||||
boolean originalInvulnerable, boolean originalIsSwimming,
|
||||
boolean originalCollideAble) {
|
||||
this.playerId = playerId;
|
||||
this.makePlayerInvisible = makePlayerInvisible;
|
||||
this.entryLocation = entryLocation;
|
||||
this.originalIsFlying = originalIsFlying;
|
||||
this.originalGameMode = originalGameMode;
|
||||
@@ -81,18 +82,6 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState {
|
||||
return this.playerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setArenaState() {
|
||||
Player player = getPlayer();
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
if (this.makePlayerInvisible) {
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY,
|
||||
PotionEffect.INFINITE_DURATION, 3));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean restore() {
|
||||
Player player = getPlayer();
|
||||
@@ -105,15 +94,13 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState {
|
||||
|
||||
@Override
|
||||
public void restore(@NotNull Player player) {
|
||||
player.setFlying(this.originalIsFlying);
|
||||
player.setGameMode(this.originalGameMode);
|
||||
player.setCollidable(this.originalCollideAble);
|
||||
player.setAllowFlight(this.originalAllowFlight);
|
||||
player.setFlying(player.getAllowFlight() && this.originalIsFlying);
|
||||
player.setGameMode(this.originalGameMode);
|
||||
player.setInvulnerable(this.originalInvulnerable);
|
||||
player.setSwimming(this.originalIsSwimming);
|
||||
player.setCollidable(this.originalCollideAble);
|
||||
if (this.makePlayerInvisible) {
|
||||
player.removePotionEffect(PotionEffectType.INVISIBILITY);
|
||||
}
|
||||
removeMenuItem(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -140,7 +127,6 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState {
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("playerId", new SerializableUUID(this.playerId));
|
||||
data.put("makePlayerInvisible", this.makePlayerInvisible);
|
||||
data.put("entryLocation", this.entryLocation);
|
||||
data.put("originalIsFlying", this.originalIsFlying);
|
||||
data.put("originalGameMode", this.originalGameMode.name());
|
||||
@@ -151,4 +137,42 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the menu item from the given player's inventory
|
||||
*
|
||||
* @param player <p>The player to remove the menu item from</p>
|
||||
*/
|
||||
private void removeMenuItem(Player player) {
|
||||
Set<ItemStack> itemsToRemove = new HashSet<>();
|
||||
player.getInventory().forEach((item) -> {
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null) {
|
||||
return;
|
||||
}
|
||||
Integer persistentData = meta.getPersistentDataContainer().get(new NamespacedKey(MiniGames.getInstance(),
|
||||
PersistentDataKey.MENU_ITEM.getKeyName()), PersistentDataType.INTEGER);
|
||||
if (persistentData != null && persistentData == PersistentDataKey.MENU_ITEM.getDataValue()) {
|
||||
itemsToRemove.add(item);
|
||||
}
|
||||
});
|
||||
for (ItemStack toRemove : itemsToRemove) {
|
||||
player.getInventory().remove(toRemove);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a boolean value from a serialization map
|
||||
*
|
||||
* @param data <p>The serialization data to look through</p>
|
||||
* @param key <p>The key to get</p>
|
||||
* @return <p>The boolean value of the key</p>
|
||||
*/
|
||||
protected static boolean getBoolean(Map<String, Object> data, String key) {
|
||||
Boolean value = (Boolean) data.get(key);
|
||||
return Objects.requireNonNullElse(value, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package net.knarcraft.minigames.arena;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -12,6 +13,13 @@ import java.util.UUID;
|
||||
*/
|
||||
public interface ArenaPlayerRegistry<K extends Arena> {
|
||||
|
||||
/**
|
||||
* Gets the ids of the players currently playing
|
||||
*
|
||||
* @return <p>The ids of the playing players</p>
|
||||
*/
|
||||
@NotNull Set<UUID> getPlayingPlayers();
|
||||
|
||||
/**
|
||||
* Gets the current entry state for the given player
|
||||
*
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package net.knarcraft.minigames.arena;
|
||||
|
||||
import net.knarcraft.minigames.gui.ArenaGUI;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -27,9 +28,10 @@ public interface ArenaSession {
|
||||
/**
|
||||
* Triggers a quit for the player playing in this session
|
||||
*
|
||||
* @param immediately <p>Whether to to the teleportation immediately, not using any timers</p>
|
||||
* @param immediately <p>Whether to to the teleportation immediately, not using any timers</p>
|
||||
* @param removeSession <p>Whether to also remove the session. Should usually be true.</p>
|
||||
*/
|
||||
void triggerQuit(boolean immediately);
|
||||
void triggerQuit(boolean immediately, boolean removeSession);
|
||||
|
||||
/**
|
||||
* Gets the arena this session is being played in
|
||||
@@ -38,4 +40,16 @@ public interface ArenaSession {
|
||||
*/
|
||||
@NotNull Arena getArena();
|
||||
|
||||
/**
|
||||
* Gets the GUI with this arena's options
|
||||
*
|
||||
* @return <p>This arena's GUI</p>
|
||||
*/
|
||||
@NotNull ArenaGUI getGUI();
|
||||
|
||||
/**
|
||||
* Resets the session to allow a player to try again
|
||||
*/
|
||||
void reset();
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,109 @@
|
||||
package net.knarcraft.minigames.arena;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A manager for keeping track of which players have set other players as hidden
|
||||
*/
|
||||
public class PlayerVisibilityManager {
|
||||
|
||||
private final Set<UUID> displayingEnabledFor = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Toggles whether players should be hidden for the player with the given id
|
||||
*
|
||||
* @param player <p>The the player to update</p>
|
||||
*/
|
||||
public void toggleHidePlayers(@NotNull ArenaPlayerRegistry<?> playerRegistry, @NotNull Player player) {
|
||||
if (displayingEnabledFor.contains(player.getUniqueId())) {
|
||||
displayingEnabledFor.remove(player.getUniqueId());
|
||||
// Make all other players hidden
|
||||
changeVisibilityFor(playerRegistry, player, true);
|
||||
} else {
|
||||
displayingEnabledFor.add(player.getUniqueId());
|
||||
// Make all other players visible again
|
||||
changeVisibilityFor(playerRegistry, player, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the given player is currently hiding other players
|
||||
*
|
||||
* @param player <p>The player to check</p>
|
||||
* @return <p>True if currently hiding other players</p>
|
||||
*/
|
||||
public boolean isHidingPlayers(Player player) {
|
||||
return !this.displayingEnabledFor.contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates which players are seen as hidden
|
||||
*
|
||||
* @param playerRegistry <p>The registry containing all playing players</p>
|
||||
* @param player <p>The player that joined the arena</p>
|
||||
*/
|
||||
public void updateHiddenPlayers(@NotNull ArenaPlayerRegistry<?> playerRegistry, @NotNull Player player) {
|
||||
boolean hideForPlayer = !displayingEnabledFor.contains(player.getUniqueId());
|
||||
for (UUID playerId : playerRegistry.getPlayingPlayers()) {
|
||||
Player otherPlayer = Bukkit.getPlayer(playerId);
|
||||
if (otherPlayer == null) {
|
||||
continue;
|
||||
}
|
||||
// Hide the arena player from the newly joined player
|
||||
if (hideForPlayer) {
|
||||
player.hidePlayer(MiniGames.getInstance(), otherPlayer);
|
||||
}
|
||||
// Hide the newly joined player from this player
|
||||
if (!displayingEnabledFor.contains(playerId)) {
|
||||
otherPlayer.hidePlayer(MiniGames.getInstance(), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes all players visible to the given player
|
||||
*
|
||||
* @param player <p>The player to update visibility for</p>
|
||||
*/
|
||||
public void showPlayersFor(@NotNull Player player) {
|
||||
for (Player otherPlayer : Bukkit.getOnlinePlayers()) {
|
||||
player.showPlayer(MiniGames.getInstance(), otherPlayer);
|
||||
otherPlayer.showPlayer(MiniGames.getInstance(), player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes whether the given player can see the other players in the arena
|
||||
*
|
||||
* @param playerRegistry <p>The player registry containing other players</p>
|
||||
* @param player <p>The player to change the visibility for</p>
|
||||
* @param hide <p>Whether to hide the players or show the players</p>
|
||||
*/
|
||||
private void changeVisibilityFor(@Nullable ArenaPlayerRegistry<?> playerRegistry, @NotNull Player player, boolean hide) {
|
||||
if (playerRegistry == null) {
|
||||
return;
|
||||
}
|
||||
for (UUID playerId : playerRegistry.getPlayingPlayers()) {
|
||||
Player otherPlayer = Bukkit.getPlayer(playerId);
|
||||
if (otherPlayer == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hide) {
|
||||
player.hidePlayer(MiniGames.getInstance(), otherPlayer);
|
||||
} else {
|
||||
player.showPlayer(MiniGames.getInstance(), otherPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -206,7 +206,7 @@ public class DropperArena implements Arena {
|
||||
try {
|
||||
DropperArenaStorageHelper.saveDropperArenaData(getData());
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
} catch (IOException exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ package net.knarcraft.minigames.arena.dropper;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaHandler;
|
||||
import net.knarcraft.minigames.arena.ArenaPlayerRegistry;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.util.DropperArenaStorageHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -32,9 +32,10 @@ public class DropperArenaHandler extends ArenaHandler<DropperArena, DropperArena
|
||||
public void saveGroups() {
|
||||
try {
|
||||
DropperArenaStorageHelper.saveDropperArenaGroups(new HashSet<>(this.arenaGroups.values()));
|
||||
} catch (IOException e) {
|
||||
MiniGames.log(Level.SEVERE, Message.ERROR_CANNOT_SAVE_ARENA_GROUPS.getMessage());
|
||||
MiniGames.log(Level.SEVERE, e.getMessage());
|
||||
} catch (IOException exception) {
|
||||
MiniGames.log(Level.SEVERE, MiniGames.getInstance().getTranslator().getTranslatedMessage(
|
||||
MiniGameMessage.ERROR_CANNOT_SAVE_ARENA_GROUPS));
|
||||
MiniGames.log(Level.SEVERE, exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,10 +55,10 @@ public class DropperArenaHandler extends ArenaHandler<DropperArena, DropperArena
|
||||
public void saveArenas() {
|
||||
try {
|
||||
DropperArenaStorageHelper.saveDropperArenas(this.arenas);
|
||||
} catch (IOException e) {
|
||||
} catch (IOException exception) {
|
||||
MiniGames.log(Level.SEVERE, "Unable to save current arenas! " +
|
||||
"Data loss can occur!");
|
||||
MiniGames.log(Level.SEVERE, e.getMessage());
|
||||
MiniGames.log(Level.SEVERE, exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,12 @@
|
||||
package net.knarcraft.minigames.arena.dropper;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.AbstractArenaSession;
|
||||
import net.knarcraft.minigames.arena.PlayerEntryState;
|
||||
import net.knarcraft.minigames.config.DropperConfiguration;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.gui.ArenaGUI;
|
||||
import net.knarcraft.minigames.gui.DropperGUI;
|
||||
import net.knarcraft.minigames.util.PlayerTeleporter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -19,6 +21,7 @@ public class DropperArenaSession extends AbstractArenaSession {
|
||||
private final @NotNull DropperArena arena;
|
||||
private final @NotNull Player player;
|
||||
private final @NotNull DropperArenaGameMode gameMode;
|
||||
private boolean startedMoving = false;
|
||||
|
||||
/**
|
||||
* Instantiates a new dropper arena session
|
||||
@@ -34,14 +37,26 @@ public class DropperArenaSession extends AbstractArenaSession {
|
||||
this.player = player;
|
||||
this.gameMode = gameMode;
|
||||
|
||||
DropperConfiguration configuration = MiniGames.getInstance().getDropperConfiguration();
|
||||
boolean makeInvisible = configuration.makePlayersInvisible();
|
||||
boolean disableCollision = configuration.disableHitCollision();
|
||||
this.entryState = new DropperPlayerEntryState(player, gameMode, makeInvisible, disableCollision,
|
||||
dropperArena.getPlayerHorizontalVelocity());
|
||||
this.entryState = new DropperPlayerEntryState(player, gameMode, dropperArena.getPlayerHorizontalVelocity());
|
||||
this.entryState.setArenaState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks that this arena's player has started moving
|
||||
*/
|
||||
public void setStartedMoving() {
|
||||
this.startedMoving = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the player of this session has started moving in the arena
|
||||
*
|
||||
* @return <p>True if the player has started moving</p>
|
||||
*/
|
||||
public boolean getStartedMoving() {
|
||||
return this.startedMoving;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player playing in this session
|
||||
*
|
||||
@@ -78,11 +93,13 @@ public class DropperArenaSession extends AbstractArenaSession {
|
||||
registerRecord();
|
||||
}
|
||||
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
|
||||
// Mark the arena as cleared
|
||||
if (this.arena.getData().setCompleted(this.gameMode, this.player)) {
|
||||
this.player.sendMessage(Message.SUCCESS_ARENA_FIRST_CLEAR.getMessage());
|
||||
stringFormatter.displaySuccessMessage(this.player, MiniGameMessage.SUCCESS_ARENA_FIRST_CLEAR);
|
||||
}
|
||||
this.player.sendMessage(Message.SUCCESS_ARENA_WIN.getMessage());
|
||||
stringFormatter.displaySuccessMessage(this.player, MiniGameMessage.SUCCESS_ARENA_WIN);
|
||||
|
||||
// Teleport the player out of the arena
|
||||
teleportToExit(false);
|
||||
@@ -101,6 +118,17 @@ public class DropperArenaSession extends AbstractArenaSession {
|
||||
return this.arena;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ArenaGUI getGUI() {
|
||||
return new DropperGUI(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
this.startedMoving = false;
|
||||
super.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeSession() {
|
||||
// Remove this session for game sessions to stop listeners from fiddling more with the player
|
||||
|
@@ -16,7 +16,6 @@ import java.util.UUID;
|
||||
public class DropperPlayerEntryState extends AbstractPlayerEntryState {
|
||||
|
||||
private final float originalFlySpeed;
|
||||
private final boolean disableHitCollision;
|
||||
private final float horizontalVelocity;
|
||||
private final DropperArenaGameMode arenaGameMode;
|
||||
|
||||
@@ -26,11 +25,10 @@ public class DropperPlayerEntryState extends AbstractPlayerEntryState {
|
||||
* @param player <p>The player whose state should be stored</p>
|
||||
*/
|
||||
public DropperPlayerEntryState(@NotNull Player player, @NotNull DropperArenaGameMode arenaGameMode,
|
||||
boolean makePlayerInvisible, boolean disableHitCollision, float horizontalVelocity) {
|
||||
super(player, makePlayerInvisible);
|
||||
float horizontalVelocity) {
|
||||
super(player);
|
||||
this.originalFlySpeed = player.getFlySpeed();
|
||||
this.arenaGameMode = arenaGameMode;
|
||||
this.disableHitCollision = disableHitCollision;
|
||||
this.horizontalVelocity = horizontalVelocity;
|
||||
}
|
||||
|
||||
@@ -38,31 +36,30 @@ public class DropperPlayerEntryState extends AbstractPlayerEntryState {
|
||||
* Instantiates a new parkour player entry state
|
||||
*
|
||||
* @param playerId <p>The id of the player whose state this should keep track of</p>
|
||||
* @param makePlayerInvisible <p>Whether players should be made invisible while in the arena</p>
|
||||
* @param entryLocation <p>The location the player entered from</p>
|
||||
* @param originalIsFlying <p>Whether the player was flying before entering the arena</p>
|
||||
* @param originalGameMode <p>The game-mode of the player before entering the arena</p>
|
||||
* @param originalAllowFlight <p>Whether the player was allowed flight before entering the arena</p>
|
||||
* @param originalInvulnerable <p>Whether the player was invulnerable before entering the arena</p>
|
||||
* @param originalIsSwimming <p>Whether the player was swimming before entering the arena</p>
|
||||
* @param originalFlySpeed <p>The fly-speed of the player before entering the arena</p>
|
||||
* @param horizontalVelocity <p>The horizontal velocity of the player before entering the arena</p>
|
||||
* @param originalCollideAble <p>Whether the player was collide-able before entering the arena</p>
|
||||
*/
|
||||
public DropperPlayerEntryState(@NotNull UUID playerId, boolean makePlayerInvisible, Location entryLocation,
|
||||
public DropperPlayerEntryState(@NotNull UUID playerId, Location entryLocation,
|
||||
boolean originalIsFlying, GameMode originalGameMode, boolean originalAllowFlight,
|
||||
boolean originalInvulnerable, boolean originalIsSwimming,
|
||||
boolean originalCollideAble, float originalFlySpeed, boolean disableHitCollision,
|
||||
float horizontalVelocity, DropperArenaGameMode arenaGameMode) {
|
||||
super(playerId, makePlayerInvisible, entryLocation, originalIsFlying, originalGameMode, originalAllowFlight,
|
||||
float originalFlySpeed, float horizontalVelocity,
|
||||
DropperArenaGameMode arenaGameMode, boolean originalCollideAble) {
|
||||
super(playerId, entryLocation, originalIsFlying, originalGameMode, originalAllowFlight,
|
||||
originalInvulnerable, originalIsSwimming, originalCollideAble);
|
||||
this.originalFlySpeed = originalFlySpeed;
|
||||
this.disableHitCollision = disableHitCollision;
|
||||
this.horizontalVelocity = horizontalVelocity;
|
||||
this.arenaGameMode = arenaGameMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setArenaState() {
|
||||
super.setArenaState();
|
||||
Player player = getPlayer();
|
||||
if (player == null) {
|
||||
return;
|
||||
@@ -71,9 +68,6 @@ public class DropperPlayerEntryState extends AbstractPlayerEntryState {
|
||||
player.setFlying(true);
|
||||
player.setGameMode(GameMode.ADVENTURE);
|
||||
player.setSwimming(false);
|
||||
if (this.disableHitCollision) {
|
||||
player.setCollidable(false);
|
||||
}
|
||||
|
||||
// If playing on the inverted game-mode, negate the horizontal velocity to swap the controls
|
||||
if (this.arenaGameMode == DropperArenaGameMode.INVERTED) {
|
||||
@@ -104,7 +98,6 @@ public class DropperPlayerEntryState extends AbstractPlayerEntryState {
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> data = super.serialize();
|
||||
data.put("originalFlySpeed", this.originalFlySpeed);
|
||||
data.put("disableHitCollision", this.disableHitCollision);
|
||||
data.put("horizontalVelocity", this.horizontalVelocity);
|
||||
data.put("arenaGameMode", this.arenaGameMode);
|
||||
return data;
|
||||
@@ -118,22 +111,20 @@ public class DropperPlayerEntryState extends AbstractPlayerEntryState {
|
||||
@SuppressWarnings("unused")
|
||||
public static DropperPlayerEntryState deserialize(Map<String, Object> data) {
|
||||
UUID playerId = ((SerializableUUID) data.get("playerId")).getRawValue();
|
||||
boolean makePlayerInvisible = (boolean) data.get("makePlayerInvisible");
|
||||
Location entryLocation = (Location) data.get("entryLocation");
|
||||
boolean originalIsFlying = (boolean) data.get("originalIsFlying");
|
||||
boolean originalIsFlying = getBoolean(data, "originalIsFlying");
|
||||
GameMode originalGameMode = GameMode.valueOf((String) data.get("originalGameMode"));
|
||||
boolean originalAllowFlight = (boolean) data.get("originalAllowFlight");
|
||||
boolean originalInvulnerable = (boolean) data.get("originalInvulnerable");
|
||||
boolean originalIsSwimming = (boolean) data.get("originalIsSwimming");
|
||||
boolean originalCollideAble = (boolean) data.get("originalCollideAble");
|
||||
boolean originalAllowFlight = getBoolean(data, "originalAllowFlight");
|
||||
boolean originalInvulnerable = getBoolean(data, "originalInvulnerable");
|
||||
boolean originalIsSwimming = getBoolean(data, "originalIsSwimming");
|
||||
float originalFlySpeed = ((Number) data.get("originalFlySpeed")).floatValue();
|
||||
boolean disableHitCollision = (boolean) data.get("disableHitCollision");
|
||||
float horizontalVelocity = ((Number) data.get("horizontalVelocity")).floatValue();
|
||||
DropperArenaGameMode arenaGameMode = (DropperArenaGameMode) data.get("arenaGameMode");
|
||||
boolean originalCollideAble = getBoolean(data, "originalCollideAble");
|
||||
|
||||
return new DropperPlayerEntryState(playerId, makePlayerInvisible, entryLocation, originalIsFlying,
|
||||
originalGameMode, originalAllowFlight, originalInvulnerable, originalIsSwimming, originalCollideAble,
|
||||
originalFlySpeed, disableHitCollision, horizontalVelocity, arenaGameMode);
|
||||
return new DropperPlayerEntryState(playerId, entryLocation, originalIsFlying,
|
||||
originalGameMode, originalAllowFlight, originalInvulnerable, originalIsSwimming,
|
||||
originalFlySpeed, horizontalVelocity, arenaGameMode, originalCollideAble);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package net.knarcraft.minigames.arena.parkour;
|
||||
|
||||
import net.knarcraft.knarlib.util.MaterialHelper;
|
||||
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.util.MaterialHelper;
|
||||
import net.knarcraft.minigames.util.ParkourArenaStorageHelper;
|
||||
import net.knarcraft.minigames.util.StringSanitizer;
|
||||
import org.bukkit.Location;
|
||||
@@ -106,7 +106,7 @@ public class ParkourArena implements Arena {
|
||||
this.winLocation = winLocation;
|
||||
this.killPlaneBlockNames = killPlaneBlockNames;
|
||||
this.killPlaneBlocks = this.killPlaneBlockNames == null ? null : MaterialHelper.loadMaterialList(
|
||||
new ArrayList<>(killPlaneBlockNames));
|
||||
new ArrayList<>(killPlaneBlockNames), "+", MiniGames.getInstance().getLogger());
|
||||
this.checkpoints = checkpoints;
|
||||
this.parkourArenaData = parkourArenaData;
|
||||
this.parkourArenaHandler = arenaHandler;
|
||||
@@ -250,7 +250,7 @@ public class ParkourArena implements Arena {
|
||||
try {
|
||||
ParkourArenaStorageHelper.saveParkourArenaData(getData());
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
} catch (IOException exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -366,7 +366,8 @@ public class ParkourArena implements Arena {
|
||||
if (killPlaneBlockNames.isEmpty()) {
|
||||
this.killPlaneBlocks = null;
|
||||
} else {
|
||||
Set<Material> parsed = MaterialHelper.loadMaterialList(new ArrayList<>(killPlaneBlockNames));
|
||||
Set<Material> parsed = MaterialHelper.loadMaterialList(new ArrayList<>(killPlaneBlockNames), "+",
|
||||
MiniGames.getInstance().getLogger());
|
||||
if (parsed.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ package net.knarcraft.minigames.arena.parkour;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaHandler;
|
||||
import net.knarcraft.minigames.arena.ArenaPlayerRegistry;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.util.ParkourArenaStorageHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -32,9 +32,10 @@ public class ParkourArenaHandler extends ArenaHandler<ParkourArena, ParkourArena
|
||||
public void saveGroups() {
|
||||
try {
|
||||
ParkourArenaStorageHelper.saveParkourArenaGroups(new HashSet<>(this.arenaGroups.values()));
|
||||
} catch (IOException e) {
|
||||
MiniGames.log(Level.SEVERE, Message.ERROR_CANNOT_SAVE_ARENA_GROUPS.getMessage());
|
||||
MiniGames.log(Level.SEVERE, e.getMessage());
|
||||
} catch (IOException exception) {
|
||||
MiniGames.log(Level.SEVERE, MiniGames.getInstance().getTranslator().getTranslatedMessage(
|
||||
MiniGameMessage.ERROR_CANNOT_SAVE_ARENA_GROUPS));
|
||||
MiniGames.log(Level.SEVERE, exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,10 +55,10 @@ public class ParkourArenaHandler extends ArenaHandler<ParkourArena, ParkourArena
|
||||
public void saveArenas() {
|
||||
try {
|
||||
ParkourArenaStorageHelper.saveParkourArenas(this.arenas);
|
||||
} catch (IOException e) {
|
||||
} catch (IOException exception) {
|
||||
MiniGames.log(Level.SEVERE, "Unable to save current arenas! " +
|
||||
"Data loss can occur!");
|
||||
MiniGames.log(Level.SEVERE, e.getMessage());
|
||||
MiniGames.log(Level.SEVERE, exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -3,8 +3,9 @@ package net.knarcraft.minigames.arena.parkour;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.AbstractArenaSession;
|
||||
import net.knarcraft.minigames.arena.PlayerEntryState;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.config.ParkourConfiguration;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.gui.ArenaGUI;
|
||||
import net.knarcraft.minigames.gui.ParkourGUI;
|
||||
import net.knarcraft.minigames.util.PlayerTeleporter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -37,9 +38,7 @@ public class ParkourArenaSession extends AbstractArenaSession {
|
||||
this.player = player;
|
||||
this.gameMode = gameMode;
|
||||
|
||||
ParkourConfiguration configuration = MiniGames.getInstance().getParkourConfiguration();
|
||||
boolean makeInvisible = configuration.makePlayersInvisible();
|
||||
this.entryState = new ParkourPlayerEntryState(player, makeInvisible);
|
||||
this.entryState = new ParkourPlayerEntryState(player);
|
||||
this.entryState.setArenaState();
|
||||
}
|
||||
|
||||
@@ -90,9 +89,11 @@ public class ParkourArenaSession extends AbstractArenaSession {
|
||||
|
||||
// Mark the arena as cleared
|
||||
if (this.arena.getData().setCompleted(this.gameMode, this.player)) {
|
||||
this.player.sendMessage(Message.SUCCESS_ARENA_FIRST_CLEAR.getMessage());
|
||||
MiniGames.getInstance().getStringFormatter().displaySuccessMessage(this.player,
|
||||
MiniGameMessage.SUCCESS_ARENA_FIRST_CLEAR);
|
||||
}
|
||||
this.player.sendMessage(Message.SUCCESS_ARENA_WIN.getMessage());
|
||||
MiniGames.getInstance().getStringFormatter().displaySuccessMessage(this.player,
|
||||
MiniGameMessage.SUCCESS_ARENA_WIN);
|
||||
|
||||
// Teleport the player out of the arena
|
||||
teleportToExit(false);
|
||||
@@ -112,6 +113,17 @@ public class ParkourArenaSession extends AbstractArenaSession {
|
||||
return this.arena;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ArenaGUI getGUI() {
|
||||
return new ParkourGUI(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
this.reachedCheckpoint = null;
|
||||
super.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeSession() {
|
||||
// Remove this session for game sessions to stop listeners from fiddling more with the player
|
||||
|
@@ -20,15 +20,14 @@ public class ParkourPlayerEntryState extends AbstractPlayerEntryState {
|
||||
*
|
||||
* @param player <p>The player whose state should be stored</p>
|
||||
*/
|
||||
public ParkourPlayerEntryState(@NotNull Player player, boolean makePlayerInvisible) {
|
||||
super(player, makePlayerInvisible);
|
||||
public ParkourPlayerEntryState(@NotNull Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new parkour player entry state
|
||||
*
|
||||
* @param playerId <p>The id of the player whose state this should keep track of</p>
|
||||
* @param makePlayerInvisible <p>Whether players should be made invisible while in the arena</p>
|
||||
* @param entryLocation <p>The location the player entered from</p>
|
||||
* @param originalIsFlying <p>Whether the player was flying before entering the arena</p>
|
||||
* @param originalGameMode <p>The game-mode of the player before entering the arena</p>
|
||||
@@ -37,17 +36,15 @@ public class ParkourPlayerEntryState extends AbstractPlayerEntryState {
|
||||
* @param originalIsSwimming <p>Whether the player was swimming before entering the arena</p>
|
||||
* @param originalCollideAble <p>Whether the player was collide-able before entering the arena</p>
|
||||
*/
|
||||
public ParkourPlayerEntryState(@NotNull UUID playerId, boolean makePlayerInvisible, Location entryLocation,
|
||||
public ParkourPlayerEntryState(@NotNull UUID playerId, Location entryLocation,
|
||||
boolean originalIsFlying, GameMode originalGameMode, boolean originalAllowFlight,
|
||||
boolean originalInvulnerable, boolean originalIsSwimming,
|
||||
boolean originalCollideAble) {
|
||||
super(playerId, makePlayerInvisible, entryLocation, originalIsFlying, originalGameMode, originalAllowFlight,
|
||||
boolean originalInvulnerable, boolean originalIsSwimming, boolean originalCollideAble) {
|
||||
super(playerId, entryLocation, originalIsFlying, originalGameMode, originalAllowFlight,
|
||||
originalInvulnerable, originalIsSwimming, originalCollideAble);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setArenaState() {
|
||||
super.setArenaState();
|
||||
Player player = getPlayer();
|
||||
if (player == null) {
|
||||
return;
|
||||
@@ -56,7 +53,6 @@ public class ParkourPlayerEntryState extends AbstractPlayerEntryState {
|
||||
player.setFlying(false);
|
||||
player.setGameMode(GameMode.ADVENTURE);
|
||||
player.setSwimming(false);
|
||||
player.setCollidable(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,16 +63,15 @@ public class ParkourPlayerEntryState extends AbstractPlayerEntryState {
|
||||
@SuppressWarnings("unused")
|
||||
public static ParkourPlayerEntryState deserialize(Map<String, Object> data) {
|
||||
UUID playerId = ((SerializableUUID) data.get("playerId")).getRawValue();
|
||||
boolean makePlayerInvisible = (boolean) data.get("makePlayerInvisible");
|
||||
Location entryLocation = (Location) data.get("entryLocation");
|
||||
boolean originalIsFlying = (boolean) data.get("originalIsFlying");
|
||||
boolean originalIsFlying = getBoolean(data, "originalIsFlying");
|
||||
GameMode originalGameMode = GameMode.valueOf((String) data.get("originalGameMode"));
|
||||
boolean originalAllowFlight = (boolean) data.get("originalAllowFlight");
|
||||
boolean originalInvulnerable = (boolean) data.get("originalInvulnerable");
|
||||
boolean originalIsSwimming = (boolean) data.get("originalIsSwimming");
|
||||
boolean originalCollideAble = (boolean) data.get("originalCollideAble");
|
||||
boolean originalAllowFlight = getBoolean(data, "originalAllowFlight");
|
||||
boolean originalInvulnerable = getBoolean(data, "originalInvulnerable");
|
||||
boolean originalIsSwimming = getBoolean(data, "originalIsSwimming");
|
||||
boolean originalCollideAble = getBoolean(data, "originalCollideAble");
|
||||
|
||||
return new ParkourPlayerEntryState(playerId, makePlayerInvisible, entryLocation, originalIsFlying,
|
||||
return new ParkourPlayerEntryState(playerId, entryLocation, originalIsFlying,
|
||||
originalGameMode, originalAllowFlight, originalInvulnerable, originalIsSwimming, originalCollideAble);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user