mirror of
https://github.com/SunNetservers/MiniGames.git
synced 2024-12-05 00:43:15 +01:00
Improves messages #16
This commit is contained in:
parent
58e25bcb30
commit
e6bb324da1
@ -280,10 +280,10 @@ public final class MiniGames extends JavaPlugin {
|
||||
public void onDisable() {
|
||||
// Kill all sessions before exiting
|
||||
for (DropperArena arena : dropperArenaHandler.getArenas().values()) {
|
||||
dropperArenaPlayerRegistry.removeForArena(arena);
|
||||
dropperArenaPlayerRegistry.removeForArena(arena, true);
|
||||
}
|
||||
for (ParkourArena arena : parkourArenaHandler.getArenas().values()) {
|
||||
parkourArenaPlayerRegistry.removeForArena(arena);
|
||||
parkourArenaPlayerRegistry.removeForArena(arena, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,7 +170,7 @@ public abstract class ArenaHandler<K extends Arena, S extends ArenaGroup<K, S>>
|
||||
*/
|
||||
public void removeArena(@NotNull K arena) {
|
||||
UUID arenaId = arena.getArenaId();
|
||||
this.playerRegistry.removeForArena(arena);
|
||||
this.playerRegistry.removeForArena(arena, false);
|
||||
this.arenas.remove(arenaId);
|
||||
this.arenaNameLookup.remove(arena.getArenaNameSanitized());
|
||||
this.arenaGroups.remove(arenaId);
|
||||
|
@ -10,8 +10,9 @@ public interface ArenaPlayerRegistry<K extends Arena> {
|
||||
/**
|
||||
* Removes all active sessions for the given arena
|
||||
*
|
||||
* @param arena <p>The arena to remove sessions for</p>
|
||||
* @param arena <p>The arena to remove sessions for</p>
|
||||
* @param immediately <p>Whether to immediately teleport the player</p>
|
||||
*/
|
||||
void removeForArena(K arena);
|
||||
void removeForArena(K arena, boolean immediately);
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package net.knarcraft.minigames.arena.dropper;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaHandler;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.util.DropperArenaStorageHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -31,8 +32,7 @@ public class DropperArenaHandler extends ArenaHandler<DropperArena, DropperArena
|
||||
try {
|
||||
DropperArenaStorageHelper.saveDropperArenaGroups(new HashSet<>(this.arenaGroups.values()));
|
||||
} catch (IOException e) {
|
||||
MiniGames.log(Level.SEVERE, "Unable to save current arena groups! " +
|
||||
"Data loss can occur!");
|
||||
MiniGames.log(Level.SEVERE, Message.ERROR_CANNOT_SAVE_ARENA_GROUPS.getMessage());
|
||||
MiniGames.log(Level.SEVERE, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -44,16 +44,12 @@ public class DropperArenaPlayerRegistry implements ArenaPlayerRegistry<DropperAr
|
||||
return this.arenaPlayers.getOrDefault(playerId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all active sessions for the given arena
|
||||
*
|
||||
* @param arena <p>The arena to remove sessions for</p>
|
||||
*/
|
||||
public void removeForArena(DropperArena arena) {
|
||||
@Override
|
||||
public void removeForArena(DropperArena arena, boolean immediately) {
|
||||
for (Map.Entry<UUID, DropperArenaSession> entry : this.arenaPlayers.entrySet()) {
|
||||
if (entry.getValue().getArena() == arena) {
|
||||
// Kick the player gracefully
|
||||
entry.getValue().triggerQuit(false);
|
||||
entry.getValue().triggerQuit(immediately);
|
||||
this.arenaPlayers.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
|
||||
import net.knarcraft.minigames.arena.ArenaSession;
|
||||
import net.knarcraft.minigames.arena.PlayerEntryState;
|
||||
import net.knarcraft.minigames.config.DropperConfiguration;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.property.RecordResult;
|
||||
import net.knarcraft.minigames.util.PlayerTeleporter;
|
||||
import org.bukkit.Location;
|
||||
@ -84,9 +85,9 @@ public class DropperArenaSession implements ArenaSession {
|
||||
|
||||
// Mark the arena as cleared
|
||||
if (this.arena.getData().setCompleted(this.gameMode, this.player)) {
|
||||
this.player.sendMessage("You cleared the arena!");
|
||||
this.player.sendMessage(Message.SUCCESS_ARENA_FIRST_CLEAR.getMessage());
|
||||
}
|
||||
this.player.sendMessage("You won!");
|
||||
this.player.sendMessage(Message.SUCCESS_ARENA_WIN.getMessage());
|
||||
|
||||
// Teleport the player out of the arena
|
||||
teleportToExit(false);
|
||||
@ -178,7 +179,7 @@ public class DropperArenaSession implements ArenaSession {
|
||||
// Teleport the player out of the arena
|
||||
teleportToExit(immediately);
|
||||
|
||||
player.sendMessage("You quit the arena!");
|
||||
player.sendMessage(Message.SUCCESS_ARENA_QUIT.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,7 @@ package net.knarcraft.minigames.arena.parkour;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaHandler;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.util.ParkourArenaStorageHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -31,8 +32,7 @@ public class ParkourArenaHandler extends ArenaHandler<ParkourArena, ParkourArena
|
||||
try {
|
||||
ParkourArenaStorageHelper.saveParkourArenaGroups(new HashSet<>(this.arenaGroups.values()));
|
||||
} catch (IOException e) {
|
||||
MiniGames.log(Level.SEVERE, "Unable to save current arena groups! " +
|
||||
"Data loss can occur!");
|
||||
MiniGames.log(Level.SEVERE, Message.ERROR_CANNOT_SAVE_ARENA_GROUPS.getMessage());
|
||||
MiniGames.log(Level.SEVERE, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -44,16 +44,12 @@ public class ParkourArenaPlayerRegistry implements ArenaPlayerRegistry<ParkourAr
|
||||
return this.arenaPlayers.getOrDefault(playerId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all active sessions for the given arena
|
||||
*
|
||||
* @param arena <p>The arena to remove sessions for</p>
|
||||
*/
|
||||
public void removeForArena(ParkourArena arena) {
|
||||
@Override
|
||||
public void removeForArena(ParkourArena arena, boolean immediately) {
|
||||
for (Map.Entry<UUID, ParkourArenaSession> entry : this.arenaPlayers.entrySet()) {
|
||||
if (entry.getValue().getArena() == arena) {
|
||||
// Kick the player gracefully
|
||||
entry.getValue().triggerQuit(false);
|
||||
entry.getValue().triggerQuit(immediately);
|
||||
this.arenaPlayers.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import net.knarcraft.minigames.arena.ArenaGameMode;
|
||||
import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
|
||||
import net.knarcraft.minigames.arena.ArenaSession;
|
||||
import net.knarcraft.minigames.arena.PlayerEntryState;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.config.ParkourConfiguration;
|
||||
import net.knarcraft.minigames.property.RecordResult;
|
||||
import net.knarcraft.minigames.util.PlayerTeleporter;
|
||||
@ -99,9 +100,9 @@ public class ParkourArenaSession implements ArenaSession {
|
||||
|
||||
// Mark the arena as cleared
|
||||
if (this.arena.getData().setCompleted(this.gameMode, this.player)) {
|
||||
this.player.sendMessage("You cleared the arena!");
|
||||
this.player.sendMessage(Message.SUCCESS_ARENA_FIRST_CLEAR.getMessage());
|
||||
}
|
||||
this.player.sendMessage("You won!");
|
||||
this.player.sendMessage(Message.SUCCESS_ARENA_WIN.getMessage());
|
||||
|
||||
// Teleport the player out of the arena
|
||||
teleportToExit(false);
|
||||
@ -188,7 +189,7 @@ public class ParkourArenaSession implements ArenaSession {
|
||||
// Teleport the player out of the arena
|
||||
teleportToExit(immediately);
|
||||
|
||||
player.sendMessage("You quit the arena!");
|
||||
player.sendMessage(Message.SUCCESS_ARENA_QUIT.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,7 @@ package net.knarcraft.minigames.command;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaSession;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@ -21,13 +22,13 @@ public class LeaveArenaCommand implements TabExecutor {
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] strings) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendMessage("This command must be used by a player");
|
||||
commandSender.sendMessage(Message.ERROR_PLAYER_ONLY.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
ArenaSession existingSession = MiniGames.getInstance().getSession(player.getUniqueId());
|
||||
if (existingSession == null) {
|
||||
commandSender.sendMessage("You are not in a mini-games arena!");
|
||||
commandSender.sendMessage(Message.ERROR_NOT_IN_ARENA.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.knarcraft.minigames.command;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@ -19,7 +20,7 @@ public class ReloadCommand implements TabExecutor {
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
MiniGames.getInstance().reload();
|
||||
commandSender.sendMessage("Plugin reloaded!");
|
||||
commandSender.sendMessage(Message.SUCCESS_PLUGIN_RELOADED.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package net.knarcraft.minigames.command.dropper;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArena;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.util.StringSanitizer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -19,7 +20,7 @@ public class CreateDropperArenaCommand implements CommandExecutor {
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendMessage("This command must be used by a player");
|
||||
commandSender.sendMessage(Message.ERROR_PLAYER_ONLY.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -40,13 +41,13 @@ public class CreateDropperArenaCommand implements CommandExecutor {
|
||||
|
||||
DropperArena existingArena = arenaHandler.getArena(arenaName);
|
||||
if (existingArena != null) {
|
||||
commandSender.sendMessage("There already exists a dropper arena with that name!");
|
||||
commandSender.sendMessage(Message.ERROR_ARENA_NAME_COLLISION.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
DropperArena arena = new DropperArena(arenaName, player.getLocation(), arenaHandler);
|
||||
arenaHandler.addArena(arena);
|
||||
commandSender.sendMessage("The arena was successfully created!");
|
||||
commandSender.sendMessage(Message.SUCCESS_ARENA_CREATED.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ 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.config.Message;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@ -60,12 +61,12 @@ public class DropperGroupListCommand implements TabExecutor {
|
||||
@NotNull String groupName) {
|
||||
DropperArenaGroup arenaGroup = arenaHandler.getGroup(groupName);
|
||||
if (arenaGroup == null) {
|
||||
sender.sendMessage("Unable to find the specified group!");
|
||||
sender.sendMessage(Message.ERROR_GROUP_NOT_FOUND.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send a list of all stages (arenas in the group)
|
||||
StringBuilder builder = new StringBuilder(groupName).append("'s stages:").append("\n");
|
||||
StringBuilder builder = new StringBuilder(Message.SUCCESS_GROUP_STAGES.getMessage("{group}", groupName));
|
||||
int counter = 1;
|
||||
for (UUID arenaId : arenaGroup.getArenas()) {
|
||||
DropperArena arena = arenaHandler.getArena(arenaId);
|
||||
|
@ -4,6 +4,7 @@ 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.config.Message;
|
||||
import net.knarcraft.minigames.util.StringSanitizer;
|
||||
import net.knarcraft.minigames.util.TabCompleteHelper;
|
||||
import org.bukkit.command.Command;
|
||||
@ -33,7 +34,7 @@ public class DropperGroupSetCommand implements TabExecutor {
|
||||
|
||||
DropperArena specifiedArena = arenaHandler.getArena(arguments[0]);
|
||||
if (specifiedArena == null) {
|
||||
commandSender.sendMessage("Unable to find the specified dropper arena.");
|
||||
commandSender.sendMessage(Message.ERROR_ARENA_NOT_FOUND.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -55,7 +56,7 @@ public class DropperGroupSetCommand implements TabExecutor {
|
||||
|
||||
arenaHandler.setGroup(specifiedArena.getArenaId(), arenaGroup);
|
||||
|
||||
commandSender.sendMessage("The arena's group has been updated");
|
||||
commandSender.sendMessage(Message.SUCCESS_ARENA_GROUP_UPDATED.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ 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.config.Message;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@ -32,26 +33,26 @@ public class DropperGroupSwapCommand implements TabExecutor {
|
||||
|
||||
DropperArena arena1 = arenaHandler.getArena(arguments[0]);
|
||||
if (arena1 == null) {
|
||||
commandSender.sendMessage("Unable to find the first specified dropper arena.");
|
||||
commandSender.sendMessage(Message.ERROR_ARENA_1_NOT_FOUND.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
DropperArena arena2 = arenaHandler.getArena(arguments[1]);
|
||||
if (arena2 == null) {
|
||||
commandSender.sendMessage("Unable to find the second specified dropper arena.");
|
||||
commandSender.sendMessage(Message.ERROR_ARENA_2_NOT_FOUND.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
DropperArenaGroup arena1Group = arenaHandler.getGroup(arena1.getArenaId());
|
||||
DropperArenaGroup arena2Group = arenaHandler.getGroup(arena2.getArenaId());
|
||||
if (arena1Group == null || !arena1Group.equals(arena2Group)) {
|
||||
commandSender.sendMessage("You cannot swap arenas in different groups!");
|
||||
commandSender.sendMessage(Message.ERROR_SWAP_DIFFERENT_GROUPS.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
arena1Group.swapArenas(arena1Group.getArenas().indexOf(arena1.getArenaId()),
|
||||
arena1Group.getArenas().indexOf(arena2.getArenaId()));
|
||||
commandSender.sendMessage("The arenas have been swapped!");
|
||||
commandSender.sendMessage(Message.SUCCESS_ARENAS_SWAPPED.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,8 @@ 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 net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.container.PlaceholderContainer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
@ -32,7 +34,7 @@ public class EditDropperArenaCommand implements CommandExecutor {
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendMessage("This command must be used by a player");
|
||||
commandSender.sendMessage(Message.ERROR_PLAYER_ONLY.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -42,29 +44,29 @@ public class EditDropperArenaCommand implements CommandExecutor {
|
||||
|
||||
DropperArena specifiedArena = MiniGames.getInstance().getDropperArenaHandler().getArena(arguments[0]);
|
||||
if (specifiedArena == null) {
|
||||
commandSender.sendMessage("Unable to find the specified dropper arena.");
|
||||
commandSender.sendMessage(Message.ERROR_ARENA_NOT_FOUND.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
DropperArenaEditableProperty editableProperty = DropperArenaEditableProperty.getFromArgumentString(arguments[1]);
|
||||
if (editableProperty == null) {
|
||||
commandSender.sendMessage("Unknown property specified.");
|
||||
commandSender.sendMessage(Message.ERROR_UNKNOWN_PROPERTY.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
String currentValueFormat = "Current value of %s is: %s";
|
||||
|
||||
if (arguments.length < 3) {
|
||||
// Print the current value of the property
|
||||
String value = editableProperty.getCurrentValueAsString(specifiedArena);
|
||||
commandSender.sendMessage(String.format(currentValueFormat, editableProperty.getArgumentString(), value));
|
||||
commandSender.sendMessage(Message.SUCCESS_CURRENT_VALUE.getMessage(new PlaceholderContainer().add(
|
||||
"{property}", editableProperty.getArgumentString()).add("{value}", value)));
|
||||
return true;
|
||||
} else {
|
||||
boolean successful = changeValue(specifiedArena, editableProperty, arguments[2], player);
|
||||
if (successful) {
|
||||
player.sendMessage(String.format("Property %s changed to: %s", editableProperty, arguments[2]));
|
||||
player.sendMessage(Message.SUCCESS_PROPERTY_CHANGED.getMessage("{property}",
|
||||
editableProperty.getArgumentString()));
|
||||
} else {
|
||||
player.sendMessage("Unable to change the property. Make sure your input is valid!");
|
||||
player.sendMessage(Message.ERROR_PROPERTY_INPUT_INVALID.getMessage());
|
||||
}
|
||||
return successful;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ 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.config.Message;
|
||||
import net.knarcraft.minigames.util.PlayerTeleporter;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -23,7 +24,7 @@ public class JoinDropperArenaCommand implements CommandExecutor {
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendMessage("This command must be used by a player");
|
||||
commandSender.sendMessage(Message.ERROR_PLAYER_ONLY.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -33,20 +34,20 @@ public class JoinDropperArenaCommand implements CommandExecutor {
|
||||
|
||||
// Disallow joining if the player is already in a mini-game arena
|
||||
if (MiniGames.getInstance().getSession(player.getUniqueId()) != null) {
|
||||
commandSender.sendMessage("You are already playing a mini-game!");
|
||||
commandSender.sendMessage(Message.ERROR_ALREADY_PLAYING.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure the arena exists
|
||||
DropperArena specifiedArena = MiniGames.getInstance().getDropperArenaHandler().getArena(arguments[0]);
|
||||
if (specifiedArena == null) {
|
||||
commandSender.sendMessage("Unable to find the specified dropper arena.");
|
||||
commandSender.sendMessage(Message.ERROR_ARENA_NOT_FOUND.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Deny vehicles as allowing this is tricky, and will cause problems in some cases
|
||||
if (player.isInsideVehicle() || !player.getPassengers().isEmpty()) {
|
||||
commandSender.sendMessage("You cannot join an arena while inside a vehicle or carrying a passenger.");
|
||||
commandSender.sendMessage(Message.ERROR_JOIN_IN_VEHICLE_OR_PASSENGER.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -80,7 +81,7 @@ public class JoinDropperArenaCommand implements CommandExecutor {
|
||||
if (MiniGames.getInstance().getDropperConfiguration().mustDoNormalModeFirst() &&
|
||||
gameMode != DropperArenaGameMode.DEFAULT &&
|
||||
specifiedArena.getData().hasNotCompleted(DropperArenaGameMode.DEFAULT, player)) {
|
||||
player.sendMessage("You must complete this arena in normal mode first!");
|
||||
player.sendMessage(Message.ERROR_NORMAL_MODE_REQUIRED.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -92,8 +93,7 @@ public class JoinDropperArenaCommand implements CommandExecutor {
|
||||
// Try to teleport the player to the arena
|
||||
boolean teleported = PlayerTeleporter.teleportPlayer(player, specifiedArena.getSpawnLocation(), false, false);
|
||||
if (!teleported) {
|
||||
player.sendMessage("Unable to teleport you to the dropper arena. Make sure you're not in a vehicle," +
|
||||
"and not carrying a passenger!");
|
||||
player.sendMessage(Message.ERROR_ARENA_TELEPORT_FAILED.getMessage());
|
||||
newSession.triggerQuit(false);
|
||||
return false;
|
||||
} else {
|
||||
@ -118,14 +118,14 @@ public class JoinDropperArenaCommand implements CommandExecutor {
|
||||
// Require that players beat all arenas in the group in the normal game-mode before trying challenge modes
|
||||
if (configuration.mustDoNormalModeFirst() && arenaGameMode != DropperArenaGameMode.DEFAULT &&
|
||||
!arenaGroup.hasBeatenAll(DropperArenaGameMode.DEFAULT, player)) {
|
||||
player.sendMessage("You have not yet beaten all arenas in this group!");
|
||||
player.sendMessage(Message.ERROR_GROUP_NORMAL_MODE_REQUIRED.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Require that the player has beaten the previous arena on the same game-mode before trying this one
|
||||
if (configuration.mustDoGroupedInSequence() &&
|
||||
arenaGroup.cannotPlay(arenaGameMode, player, dropperArena.getArenaId())) {
|
||||
player.sendMessage("You have not yet beaten the previous arena!");
|
||||
player.sendMessage(Message.ERROR_PREVIOUS_ARENA_REQUIRED.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.knarcraft.minigames.command.dropper;
|
||||
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.util.TabCompleteHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -18,10 +19,11 @@ public class ListDropperArenaCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] arguments) {
|
||||
sender.sendMessage("Dropper arenas:");
|
||||
StringBuilder builder = new StringBuilder(Message.SUCCESS_DROPPER_ARENAS_LIST.getMessage());
|
||||
for (String arenaName : TabCompleteHelper.getDropperArenas()) {
|
||||
sender.sendMessage(arenaName);
|
||||
builder.append("\n").append(arenaName);
|
||||
}
|
||||
sender.sendMessage(builder.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package net.knarcraft.minigames.command.dropper;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArena;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -23,13 +24,13 @@ public class RemoveDropperArenaCommand implements CommandExecutor {
|
||||
// Get the specified arena
|
||||
DropperArena targetArena = MiniGames.getInstance().getDropperArenaHandler().getArena(arguments[0]);
|
||||
if (targetArena == null) {
|
||||
commandSender.sendMessage("Unable to find the specified arena");
|
||||
commandSender.sendMessage(Message.ERROR_ARENA_NOT_FOUND.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove the arena
|
||||
MiniGames.getInstance().getDropperArenaHandler().removeArena(targetArena);
|
||||
commandSender.sendMessage("The specified arena has been successfully removed");
|
||||
commandSender.sendMessage(Message.SUCCESS_ARENA_REMOVED.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package net.knarcraft.minigames.command.parkour;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.util.StringSanitizer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -19,7 +20,7 @@ public class CreateParkourArenaCommand implements CommandExecutor {
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendMessage("This command must be used by a player");
|
||||
commandSender.sendMessage(Message.ERROR_PLAYER_ONLY.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -40,13 +41,13 @@ public class CreateParkourArenaCommand implements CommandExecutor {
|
||||
|
||||
ParkourArena existingArena = arenaHandler.getArena(arenaName);
|
||||
if (existingArena != null) {
|
||||
commandSender.sendMessage("There already exists a parkour arena with that name!");
|
||||
commandSender.sendMessage(Message.ERROR_ARENA_NAME_COLLISION.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
ParkourArena arena = new ParkourArena(arenaName, player.getLocation(), arenaHandler);
|
||||
arenaHandler.addArena(arena);
|
||||
commandSender.sendMessage("The arena was successfully created!");
|
||||
commandSender.sendMessage(Message.SUCCESS_ARENA_CREATED.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@ package net.knarcraft.minigames.command.parkour;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaEditableProperty;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.container.PlaceholderContainer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
@ -29,7 +31,7 @@ public class EditParkourArenaCommand implements CommandExecutor {
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendMessage("This command must be used by a player");
|
||||
commandSender.sendMessage(Message.ERROR_PLAYER_ONLY.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -39,29 +41,29 @@ public class EditParkourArenaCommand implements CommandExecutor {
|
||||
|
||||
ParkourArena specifiedArena = MiniGames.getInstance().getParkourArenaHandler().getArena(arguments[0]);
|
||||
if (specifiedArena == null) {
|
||||
commandSender.sendMessage("Unable to find the specified dropper arena.");
|
||||
commandSender.sendMessage(Message.ERROR_ARENA_NOT_FOUND.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
ParkourArenaEditableProperty editableProperty = ParkourArenaEditableProperty.getFromArgumentString(arguments[1]);
|
||||
if (editableProperty == null) {
|
||||
commandSender.sendMessage("Unknown property specified.");
|
||||
commandSender.sendMessage(Message.ERROR_UNKNOWN_PROPERTY.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
String currentValueFormat = "Current value of %s is: %s";
|
||||
|
||||
if (arguments.length < 3) {
|
||||
// Print the current value of the property
|
||||
String value = editableProperty.getCurrentValueAsString(specifiedArena);
|
||||
commandSender.sendMessage(String.format(currentValueFormat, editableProperty.getArgumentString(), value));
|
||||
commandSender.sendMessage(Message.SUCCESS_CURRENT_VALUE.getMessage(new PlaceholderContainer().add(
|
||||
"{property}", editableProperty.getArgumentString()).add("{value}", value)));
|
||||
return true;
|
||||
} else {
|
||||
boolean successful = changeValue(specifiedArena, editableProperty, arguments[2], player);
|
||||
if (successful) {
|
||||
player.sendMessage(String.format("Property %s changed to: %s", editableProperty, arguments[2]));
|
||||
player.sendMessage(Message.SUCCESS_PROPERTY_CHANGED.getMessage("{property}",
|
||||
editableProperty.getArgumentString()));
|
||||
} else {
|
||||
player.sendMessage("Unable to change the property. Make sure your input is valid!");
|
||||
player.sendMessage(Message.ERROR_PROPERTY_INPUT_INVALID.getMessage());
|
||||
}
|
||||
return successful;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import net.knarcraft.minigames.arena.parkour.ParkourArenaGameMode;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaPlayerRegistry;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaSession;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.config.ParkourConfiguration;
|
||||
import net.knarcraft.minigames.util.PlayerTeleporter;
|
||||
import org.bukkit.command.Command;
|
||||
@ -23,7 +24,7 @@ public class JoinParkourArenaCommand implements CommandExecutor {
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendMessage("This command must be used by a player");
|
||||
commandSender.sendMessage(Message.ERROR_PLAYER_ONLY.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -33,20 +34,20 @@ public class JoinParkourArenaCommand implements CommandExecutor {
|
||||
|
||||
// Disallow joining if the player is already in a mini-game arena
|
||||
if (MiniGames.getInstance().getSession(player.getUniqueId()) != null) {
|
||||
commandSender.sendMessage("You are already playing a mini-game!");
|
||||
commandSender.sendMessage(Message.ERROR_ALREADY_PLAYING.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure the arena exists
|
||||
ParkourArena specifiedArena = MiniGames.getInstance().getParkourArenaHandler().getArena(arguments[0]);
|
||||
if (specifiedArena == null) {
|
||||
commandSender.sendMessage("Unable to find the specified parkour arena.");
|
||||
commandSender.sendMessage(Message.ERROR_ARENA_NOT_FOUND.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Deny vehicles as allowing this is tricky, and will cause problems in some cases
|
||||
if (player.isInsideVehicle() || !player.getPassengers().isEmpty()) {
|
||||
commandSender.sendMessage("You cannot join an arena while inside a vehicle or carrying a passenger.");
|
||||
commandSender.sendMessage(Message.ERROR_JOIN_IN_VEHICLE_OR_PASSENGER.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -84,8 +85,7 @@ public class JoinParkourArenaCommand implements CommandExecutor {
|
||||
// Try to teleport the player to the arena
|
||||
boolean teleported = PlayerTeleporter.teleportPlayer(player, specifiedArena.getSpawnLocation(), false, false);
|
||||
if (!teleported) {
|
||||
player.sendMessage("Unable to teleport you to the parkour arena. Make sure you're not in a vehicle," +
|
||||
"and not carrying a passenger!");
|
||||
player.sendMessage(Message.ERROR_ARENA_TELEPORT_FAILED.getMessage());
|
||||
newSession.triggerQuit(false);
|
||||
return false;
|
||||
} else {
|
||||
@ -111,7 +111,7 @@ public class JoinParkourArenaCommand implements CommandExecutor {
|
||||
// Require that the player has beaten the previous arena on the same game-mode before trying this one
|
||||
if (configuration.mustDoGroupedInSequence() &&
|
||||
arenaGroup.cannotPlay(arenaGameMode, player, parkourArena.getArenaId())) {
|
||||
player.sendMessage("You have not yet beaten the previous arena!");
|
||||
player.sendMessage(Message.ERROR_PREVIOUS_ARENA_REQUIRED.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.knarcraft.minigames.command.parkour;
|
||||
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.util.TabCompleteHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -18,10 +19,11 @@ public class ListParkourArenaCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] arguments) {
|
||||
sender.sendMessage("Parkour arenas:");
|
||||
StringBuilder builder = new StringBuilder(Message.SUCCESS_PARKOUR_ARENAS_LIST.getMessage());
|
||||
for (String arenaName : TabCompleteHelper.getParkourArenas()) {
|
||||
sender.sendMessage(arenaName);
|
||||
builder.append("\n").append(arenaName);
|
||||
}
|
||||
sender.sendMessage(builder.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@ -61,17 +62,17 @@ public class ParkourGroupListCommand implements TabExecutor {
|
||||
@NotNull String groupName) {
|
||||
ParkourArenaGroup arenaGroup = arenaHandler.getGroup(groupName);
|
||||
if (arenaGroup == null) {
|
||||
sender.sendMessage("Unable to find the specified group!");
|
||||
sender.sendMessage(Message.ERROR_GROUP_NOT_FOUND.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send a list of all stages (arenas in the group)
|
||||
StringBuilder builder = new StringBuilder(groupName).append("'s stages:").append("\n");
|
||||
StringBuilder builder = new StringBuilder(Message.SUCCESS_GROUP_STAGES.getMessage("{group}", groupName));
|
||||
int counter = 1;
|
||||
for (UUID arenaId : arenaGroup.getArenas()) {
|
||||
ParkourArena arena = arenaHandler.getArena(arenaId);
|
||||
if (arena != null) {
|
||||
builder.append(counter++).append(". ").append(arena.getArenaName()).append("\n");
|
||||
builder.append("\n").append(counter++).append(". ").append(arena.getArenaName());
|
||||
}
|
||||
}
|
||||
sender.sendMessage(builder.toString());
|
||||
|
@ -4,6 +4,7 @@ import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.util.StringSanitizer;
|
||||
import net.knarcraft.minigames.util.TabCompleteHelper;
|
||||
import org.bukkit.command.Command;
|
||||
@ -33,7 +34,7 @@ public class ParkourGroupSetCommand implements TabExecutor {
|
||||
|
||||
ParkourArena specifiedArena = arenaHandler.getArena(arguments[0]);
|
||||
if (specifiedArena == null) {
|
||||
commandSender.sendMessage("Unable to find the specified parkour arena.");
|
||||
commandSender.sendMessage(Message.ERROR_ARENA_NOT_FOUND.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -55,7 +56,7 @@ public class ParkourGroupSetCommand implements TabExecutor {
|
||||
|
||||
arenaHandler.setGroup(specifiedArena.getArenaId(), arenaGroup);
|
||||
|
||||
commandSender.sendMessage("The arena's group has been updated");
|
||||
commandSender.sendMessage(Message.SUCCESS_ARENA_GROUP_UPDATED.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@ -32,26 +33,26 @@ public class ParkourGroupSwapCommand implements TabExecutor {
|
||||
|
||||
ParkourArena arena1 = arenaHandler.getArena(arguments[0]);
|
||||
if (arena1 == null) {
|
||||
commandSender.sendMessage("Unable to find the first specified parkour arena.");
|
||||
commandSender.sendMessage(Message.ERROR_ARENA_1_NOT_FOUND.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
ParkourArena arena2 = arenaHandler.getArena(arguments[1]);
|
||||
if (arena2 == null) {
|
||||
commandSender.sendMessage("Unable to find the second specified parkour arena.");
|
||||
commandSender.sendMessage(Message.ERROR_ARENA_2_NOT_FOUND.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
ParkourArenaGroup arena1Group = arenaHandler.getGroup(arena1.getArenaId());
|
||||
ParkourArenaGroup arena2Group = arenaHandler.getGroup(arena2.getArenaId());
|
||||
if (arena1Group == null || !arena1Group.equals(arena2Group)) {
|
||||
commandSender.sendMessage("You cannot swap arenas in different groups!");
|
||||
commandSender.sendMessage(Message.ERROR_SWAP_DIFFERENT_GROUPS.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
arena1Group.swapArenas(arena1Group.getArenas().indexOf(arena1.getArenaId()),
|
||||
arena1Group.getArenas().indexOf(arena2.getArenaId()));
|
||||
commandSender.sendMessage("The arenas have been swapped!");
|
||||
commandSender.sendMessage(Message.SUCCESS_ARENAS_SWAPPED.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package net.knarcraft.minigames.command.parkour;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -23,13 +24,13 @@ public class RemoveParkourArenaCommand implements CommandExecutor {
|
||||
// Get the specified arena
|
||||
ParkourArena targetArena = MiniGames.getInstance().getParkourArenaHandler().getArena(arguments[0]);
|
||||
if (targetArena == null) {
|
||||
commandSender.sendMessage("Unable to find the specified arena");
|
||||
commandSender.sendMessage(Message.ERROR_ARENA_NOT_FOUND.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove the arena
|
||||
MiniGames.getInstance().getParkourArenaHandler().removeArena(targetArena);
|
||||
commandSender.sendMessage("The specified arena has been successfully removed");
|
||||
commandSender.sendMessage(Message.SUCCESS_ARENA_REMOVED.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
111
src/main/java/net/knarcraft/minigames/config/Message.java
Normal file
111
src/main/java/net/knarcraft/minigames/config/Message.java
Normal file
@ -0,0 +1,111 @@
|
||||
package net.knarcraft.minigames.config;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.container.PlaceholderContainer;
|
||||
import net.knarcraft.minigames.util.ColorHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A message which ca be displayed to the user
|
||||
*/
|
||||
public enum Message {
|
||||
|
||||
ERROR_CANNOT_SAVE_ARENA_GROUPS("&cUnable to save current arena groups! Data loss can occur!"),
|
||||
ERROR_MATERIAL_NOT_PARSE_ABLE("&cUnable to parse material: {material}"),
|
||||
ERROR_TELEPORT_WITH_PASSENGER("&cYou cannot be teleported with a passenger!"),
|
||||
ERROR_TELEPORT_IN_VEHICLE("&cYou cannot be teleported while in a vehicle"),
|
||||
ERROR_ARENA_NOT_LOADED("&cCould not load the arena at configuration section {section}. Please check " +
|
||||
"the {file} storage file for issues."),
|
||||
ERROR_ARENA_DATA_NOT_LOADED("&cUnable to load arena data for dropper arena: {arena}"),
|
||||
ERROR_ARENA_NOT_FOUND("&cUnable to find the specified arena."),
|
||||
ERROR_GROUP_NOT_FOUND("&cUnable to find the specified group!"),
|
||||
ERROR_PLAYER_ONLY("&cThis command must be used by a player"),
|
||||
ERROR_ARENA_NAME_COLLISION("&cThere already exists an arena with that name!"),
|
||||
ERROR_NORMAL_MODE_REQUIRED("&cYou must complete this arena in normal mode first!"),
|
||||
ERROR_GROUP_NORMAL_MODE_REQUIRED("&cYou have not yet beaten the default game-mode for all arenas in this group!"),
|
||||
ERROR_PREVIOUS_ARENA_REQUIRED("&cYou have not yet beaten the previous arena!"),
|
||||
ERROR_ARENA_TELEPORT_FAILED("&cUnable to teleport you to the arena."),
|
||||
ERROR_NOT_IN_ARENA("&cYou are not in a mini-games arena!"),
|
||||
ERROR_ALREADY_PLAYING("&cYou are already playing a mini-game!"),
|
||||
ERROR_JOIN_IN_VEHICLE_OR_PASSENGER("&cYou cannot join an arena while inside a vehicle or carrying a passenger."),
|
||||
ERROR_UNKNOWN_PROPERTY("&cUnknown property specified."),
|
||||
ERROR_PROPERTY_INPUT_INVALID("&cUnable to change the property. Make sure your input is valid!"),
|
||||
ERROR_ARENA_1_NOT_FOUND("&cUnable to find the first specified arena."),
|
||||
ERROR_ARENA_2_NOT_FOUND("&cUnable to find the second specified dropper arena."),
|
||||
ERROR_SWAP_DIFFERENT_GROUPS("&cYou cannot swap arenas in different groups!"),
|
||||
ERROR_ILLEGAL_COMMAND("&cYou cannot use that command while in an arena!"),
|
||||
SUCCESS_ARENA_GROUP_UPDATED("&aThe arena's group has been updated"),
|
||||
SUCCESS_PLUGIN_RELOADED("&aPlugin reloaded!"),
|
||||
SUCCESS_ARENA_CREATED("&aThe arena was successfully created!"),
|
||||
SUCCESS_ARENA_FIRST_CLEAR("&aYou cleared the arena!"),
|
||||
SUCCESS_ARENA_WIN("&aYou won!"),
|
||||
SUCCESS_ARENA_QUIT("&aYou quit the arena!"),
|
||||
SUCCESS_CURRENT_VALUE("&aCurrent value of {property} is: {value}"),
|
||||
SUCCESS_PROPERTY_CHANGED("&aProperty {property} successfully changed"),
|
||||
SUCCESS_ARENAS_SWAPPED("&aThe arenas have been swapped!"),
|
||||
SUCCESS_ARENA_REMOVED("&aThe specified arena has been successfully removed"),
|
||||
SUCCESS_DROPPER_ARENAS_LIST("&aDropper arenas:&r"),
|
||||
SUCCESS_PARKOUR_ARENAS_LIST("&aParkour arenas:&r"),
|
||||
SUCCESS_CHECKPOINT_REACHED("&aCheckpoint reached!"),
|
||||
SUCCESS_GROUP_STAGES("&a{group}'s stages:&r"),
|
||||
;
|
||||
|
||||
private final @NotNull String defaultMessage;
|
||||
|
||||
/**
|
||||
* Instantiates a new message
|
||||
*
|
||||
* @param defaultMessage <p>The default value of the message</p>
|
||||
*/
|
||||
Message(@NotNull String defaultMessage) {
|
||||
this.defaultMessage = defaultMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message this enum represents
|
||||
*
|
||||
* @return <p>The formatted message</p>
|
||||
*/
|
||||
public @NotNull String getMessage() {
|
||||
return formatMessage(this.defaultMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message this enum represents
|
||||
*
|
||||
* @param placeholder <p>The placeholder to replace</p>
|
||||
* @param replacement <p>The replacement to use</p>
|
||||
* @return <p>The formatted message</p>
|
||||
*/
|
||||
public @NotNull String getMessage(@NotNull String placeholder, @NotNull String replacement) {
|
||||
return formatMessage(this.defaultMessage.replace(placeholder, replacement));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message this enum represents
|
||||
*
|
||||
* @param placeholders <p>The placeholder -> replacement map specifying necessary replacements</p>
|
||||
* @return <p>The formatted message</p>
|
||||
*/
|
||||
public @NotNull String getMessage(@NotNull PlaceholderContainer placeholders) {
|
||||
String replaced = this.defaultMessage;
|
||||
for (Map.Entry<String, String> entry : placeholders.getPlaceholders().entrySet()) {
|
||||
replaced = replaced.replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return formatMessage(replaced);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the formatted version of the given message
|
||||
*
|
||||
* @param message <p>The message to format</p>
|
||||
* @return <p>The formatted message</p>
|
||||
*/
|
||||
private @NotNull String formatMessage(@NotNull String message) {
|
||||
String prefix = MiniGames.getInstance().getDescription().getPrefix();
|
||||
return ColorHelper.translateAllColorCodes("#546EED[&r&l" + prefix + "#546EED]&r " + message);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package net.knarcraft.minigames.container;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A container for keeping track of several placeholder to value mappings
|
||||
*/
|
||||
public class PlaceholderContainer {
|
||||
|
||||
private final Map<String, String> placeholders;
|
||||
|
||||
/**
|
||||
* Instantiates a new placeholder container
|
||||
*/
|
||||
public PlaceholderContainer() {
|
||||
this.placeholders = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all placeholders
|
||||
*
|
||||
* @return <p>All placeholders</p>
|
||||
*/
|
||||
public Map<String, String> getPlaceholders() {
|
||||
return new HashMap<>(this.placeholders);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new placeholder
|
||||
*
|
||||
* @param placeholder <p>The placeholder to register</p>
|
||||
* @param value <p>The value of the placeholder</p>
|
||||
* @return <p>This object</p>
|
||||
*/
|
||||
public PlaceholderContainer add(String placeholder, String value) {
|
||||
this.placeholders.put(placeholder, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,7 @@ package net.knarcraft.minigames.listener;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaSession;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -40,7 +41,7 @@ public class CommandListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
player.sendMessage("You cannot use that command while in an arena!");
|
||||
player.sendMessage(Message.ERROR_ILLEGAL_COMMAND.getMessage());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import net.knarcraft.minigames.arena.dropper.DropperArenaSession;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaSession;
|
||||
import net.knarcraft.minigames.config.DropperConfiguration;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.config.ParkourConfiguration;
|
||||
import net.knarcraft.minigames.config.SharedConfiguration;
|
||||
import org.bukkit.Location;
|
||||
@ -80,19 +81,30 @@ public class MoveListener implements Listener {
|
||||
List<Location> checkpoints = arena.getCheckpoints();
|
||||
for (Location checkpoint : checkpoints) {
|
||||
Location previousCheckpoint = arenaSession.getRegisteredCheckpoint();
|
||||
if (checkpoint.getBlock().equals(event.getTo().getBlock()) && !checkpoint.equals(previousCheckpoint)) {
|
||||
if (parkourConfiguration.enforceCheckpointOrder()) {
|
||||
int checkpointIndex = checkpoints.indexOf(checkpoint);
|
||||
int previousIndex = previousCheckpoint == null ? -1 : checkpoints.indexOf(previousCheckpoint);
|
||||
if (checkpointIndex - previousIndex != 1) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
arenaSession.registerCheckpoint(checkpoint.clone());
|
||||
event.getPlayer().sendMessage("Checkpoint reached!");
|
||||
// Skip if checkpoint has not been reached
|
||||
if (!checkpoint.getBlock().equals(event.getTo().getBlock())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the checkpoint is the same as the previously reached one, abort
|
||||
if (previousCheckpoint != null && checkpoint.getBlock().equals(previousCheckpoint.getBlock())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If not the correct checkpoint according to the enforced order, abort
|
||||
if (parkourConfiguration.enforceCheckpointOrder()) {
|
||||
int checkpointIndex = checkpoints.indexOf(checkpoint);
|
||||
int previousIndex = previousCheckpoint == null ? -1 : checkpoints.indexOf(previousCheckpoint);
|
||||
if (checkpointIndex - previousIndex != 1) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Register the checkpoint
|
||||
arenaSession.registerCheckpoint(checkpoint.clone());
|
||||
event.getPlayer().sendMessage(Message.SUCCESS_CHECKPOINT_REACHED.getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
29
src/main/java/net/knarcraft/minigames/util/ColorHelper.java
Normal file
29
src/main/java/net/knarcraft/minigames/util/ColorHelper.java
Normal file
@ -0,0 +1,29 @@
|
||||
package net.knarcraft.minigames.util;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* A helper class for converting colors
|
||||
*/
|
||||
public class ColorHelper {
|
||||
|
||||
/**
|
||||
* Translates all found color codes to formatting in a string
|
||||
*
|
||||
* @param message <p>The string to search for color codes</p>
|
||||
* @return <p>The message with color codes translated</p>
|
||||
*/
|
||||
public static String translateAllColorCodes(String message) {
|
||||
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||
Pattern pattern = Pattern.compile("&?(#[a-fA-F0-9]{6})");
|
||||
Matcher matcher = pattern.matcher(message);
|
||||
while (matcher.find()) {
|
||||
message = message.replace(matcher.group(), "" + ChatColor.of(matcher.group(1)));
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
@ -9,6 +9,8 @@ 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.config.Message;
|
||||
import net.knarcraft.minigames.container.PlaceholderContainer;
|
||||
import net.knarcraft.minigames.container.SerializableMaterial;
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import org.bukkit.Location;
|
||||
@ -159,8 +161,8 @@ public final class DropperArenaStorageHelper {
|
||||
DropperArenaStorageKey.WIN_BLOCK_TYPE.getKey());
|
||||
|
||||
if (arenaName == null || spawnLocation == null) {
|
||||
MiniGames.log(Level.SEVERE, "Could not load the arena at configuration " +
|
||||
"section " + configurationSection.getName() + ". Please check the dropper_arenas storage file for issues.");
|
||||
MiniGames.log(Level.SEVERE, Message.ERROR_ARENA_NOT_LOADED.getMessage(new PlaceholderContainer().add(
|
||||
"{section}", configurationSection.getName()).add("{file}", "dropper_arenas")));
|
||||
return null;
|
||||
}
|
||||
if (winBlockType == null) {
|
||||
@ -170,7 +172,8 @@ public final class DropperArenaStorageHelper {
|
||||
// Generate new, empty arena data if not available
|
||||
DropperArenaData arenaData = loadDropperArenaData(arenaId);
|
||||
if (arenaData == null) {
|
||||
MiniGames.log(Level.SEVERE, "Unable to load arena data for dropper arena" + arenaId);
|
||||
MiniGames.log(Level.SEVERE, Message.ERROR_ARENA_DATA_NOT_LOADED.getMessage("{arena}",
|
||||
arenaId.toString()));
|
||||
arenaData = getEmptyDropperData(arenaId);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.knarcraft.minigames.util;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
@ -43,7 +44,7 @@ public final class MaterialHelper {
|
||||
if (matched != null) {
|
||||
parsedMaterials.add(matched);
|
||||
} else {
|
||||
MiniGames.log(Level.WARNING, "Unable to parse: " + string);
|
||||
MiniGames.log(Level.WARNING, Message.ERROR_MATERIAL_NOT_PARSE_ABLE.getMessage("{material}", string));
|
||||
}
|
||||
}
|
||||
return parsedMaterials;
|
||||
|
@ -9,6 +9,8 @@ import net.knarcraft.minigames.arena.parkour.ParkourArenaGameMode;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaRecordsRegistry;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaStorageKey;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import net.knarcraft.minigames.container.PlaceholderContainer;
|
||||
import net.knarcraft.minigames.container.SerializableMaterial;
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import org.bukkit.Location;
|
||||
@ -164,8 +166,8 @@ public final class ParkourArenaStorageHelper {
|
||||
|
||||
// The arena name and spawn location must be present
|
||||
if (arenaName == null || spawnLocation == null) {
|
||||
MiniGames.log(Level.SEVERE, "Could not load the arena at configuration " +
|
||||
"section " + configurationSection.getName() + ". Please check the parkour_arenas storage file for issues.");
|
||||
MiniGames.log(Level.SEVERE, Message.ERROR_ARENA_NOT_LOADED.getMessage(new PlaceholderContainer().add(
|
||||
"{section}", configurationSection.getName()).add("{file}", "parkour_arena")));
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -177,7 +179,8 @@ public final class ParkourArenaStorageHelper {
|
||||
// Generate new, empty arena data if not available
|
||||
ParkourArenaData arenaData = loadParkourArenaData(arenaId);
|
||||
if (arenaData == null) {
|
||||
MiniGames.log(Level.SEVERE, "Unable to load arena data for parkour arena" + arenaId);
|
||||
MiniGames.log(Level.SEVERE, Message.ERROR_ARENA_DATA_NOT_LOADED.getMessage("{arena}",
|
||||
arenaId.toString()));
|
||||
arenaData = getEmptyParkourData(arenaId);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.knarcraft.minigames.util;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -35,7 +36,7 @@ public final class PlayerTeleporter {
|
||||
passenger.teleport(location);
|
||||
}
|
||||
} else {
|
||||
player.sendMessage("You cannot be teleported with a passenger!");
|
||||
player.sendMessage(Message.ERROR_TELEPORT_WITH_PASSENGER.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -45,16 +46,16 @@ public final class PlayerTeleporter {
|
||||
player.eject();
|
||||
vehicle.teleport(location);
|
||||
} else {
|
||||
player.sendMessage("You cannot be teleported while in a vehicle");
|
||||
player.sendMessage(Message.ERROR_TELEPORT_IN_VEHICLE.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//Stop the existing player velocity to prevent unevenness between players
|
||||
// Stop the existing player velocity to prevent unevenness between players
|
||||
player.setVelocity(new Vector(0, 0, 0));
|
||||
player.setInvulnerable(true);
|
||||
player.teleport(location);
|
||||
player.setVelocity(new Vector(0, 0, 0));
|
||||
//When teleporting a player out of the arena, sometimes the move listener is slow to react, giving the player
|
||||
// When teleporting a player out of the arena, sometimes the move listener is slow to react, giving the player
|
||||
// lethal velocity, and causing damage. That's why the player is given 5 ticks of invulnerability
|
||||
if (!immediately) {
|
||||
Bukkit.getScheduler().runTaskLater(MiniGames.getInstance(), () -> player.setInvulnerable(false), 5);
|
||||
|
@ -1,4 +1,5 @@
|
||||
name: MiniGames
|
||||
prefix: MiniGames
|
||||
version: '${project.version}'
|
||||
main: net.knarcraft.minigames.MiniGames
|
||||
api-version: 1.19
|
||||
|
Loading…
Reference in New Issue
Block a user