Makes all messages configurable

This commit is contained in:
Kristian Knarvik 2023-07-09 18:20:31 +02:00
parent 57183b64f5
commit 8ea930a5f3
45 changed files with 563 additions and 598 deletions

View File

@ -259,6 +259,20 @@ Example tags:
- +FENCE_GATES - +FENCE_GATES
- +FENCES - +FENCES
## Language customization
Most or all strings are customizable. If you place a strings.yml file in the plugin folder, it will take
priority over built-in languages. If you want to change strings, look at MiniGames/src/main/resources/strings.yml for
the proper keys. All strings have the format: ENUM: "Displayed string". The enum must be identical as it defines which
string you have changed. All strings belonging to a language are beneath the language code and indented with two spaces.
The easiest way to add a new language is to copy an existing language and paste it into your custom strings.yml and
change strings as necessary. If you don't include all strings, the remaining will use the built-in English translation.
Remember to change the language code to whichever you use for your custom language.
The interval messages are unique in that if several values are separated by comma (option1,option2,option3), a random
message will be chosen each time it's displayed.
## License ## License
MiniGames is licensed under the GNU Public License Version 3.0. This includes every source and resource file. See the MiniGames is licensed under the GNU Public License Version 3.0. This includes every source and resource file. See the

12
pom.xml
View File

@ -41,6 +41,12 @@
<configuration> <configuration>
<createDependencyReducedPom>false</createDependencyReducedPom> <createDependencyReducedPom>false</createDependencyReducedPom>
<filters> <filters>
<filter>
<artifact>net.knarcraft:knarlib</artifact>
<includes>
<include>net/knarcraft/knarlib/**</include>
</includes>
</filter>
<filter> <filter>
<artifact>net.knarcraft:knargui</artifact> <artifact>net.knarcraft:knargui</artifact>
<includes> <includes>
@ -113,5 +119,11 @@
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>net.knarcraft</groupId>
<artifactId>knarlib</artifactId>
<version>1.2.3</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,6 +1,9 @@
package net.knarcraft.minigames; package net.knarcraft.minigames;
import net.knarcraft.knargui.GUIListener; import net.knarcraft.knargui.GUIListener;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.knarlib.formatting.Translator;
import net.knarcraft.knarlib.property.ColorConversion;
import net.knarcraft.minigames.arena.ArenaPlayerRegistry; import net.knarcraft.minigames.arena.ArenaPlayerRegistry;
import net.knarcraft.minigames.arena.ArenaSession; import net.knarcraft.minigames.arena.ArenaSession;
import net.knarcraft.minigames.arena.PlayerVisibilityManager; import net.knarcraft.minigames.arena.PlayerVisibilityManager;
@ -48,6 +51,7 @@ import net.knarcraft.minigames.command.parkour.ParkourGroupSwapCommand;
import net.knarcraft.minigames.command.parkour.RemoveParkourArenaCommand; import net.knarcraft.minigames.command.parkour.RemoveParkourArenaCommand;
import net.knarcraft.minigames.command.parkour.RemoveParkourArenaTabCompleter; import net.knarcraft.minigames.command.parkour.RemoveParkourArenaTabCompleter;
import net.knarcraft.minigames.config.DropperConfiguration; import net.knarcraft.minigames.config.DropperConfiguration;
import net.knarcraft.minigames.config.MiniGameMessage;
import net.knarcraft.minigames.config.ParkourConfiguration; import net.knarcraft.minigames.config.ParkourConfiguration;
import net.knarcraft.minigames.config.SharedConfiguration; import net.knarcraft.minigames.config.SharedConfiguration;
import net.knarcraft.minigames.container.SerializableMaterial; import net.knarcraft.minigames.container.SerializableMaterial;
@ -59,6 +63,7 @@ import net.knarcraft.minigames.listener.MoveListener;
import net.knarcraft.minigames.listener.PlayerStateChangeListener; import net.knarcraft.minigames.listener.PlayerStateChangeListener;
import net.knarcraft.minigames.placeholder.DropperRecordExpansion; import net.knarcraft.minigames.placeholder.DropperRecordExpansion;
import net.knarcraft.minigames.placeholder.ParkourRecordExpansion; import net.knarcraft.minigames.placeholder.ParkourRecordExpansion;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
@ -89,6 +94,8 @@ public final class MiniGames extends JavaPlugin {
private ParkourArenaHandler parkourArenaHandler; private ParkourArenaHandler parkourArenaHandler;
private ArenaPlayerRegistry<ParkourArena> parkourArenaPlayerRegistry; private ArenaPlayerRegistry<ParkourArena> parkourArenaPlayerRegistry;
private PlayerVisibilityManager playerVisibilityManager; private PlayerVisibilityManager playerVisibilityManager;
private Translator translator;
private StringFormatter stringFormatter;
/** /**
* Gets an instance of this plugin * Gets an instance of this plugin
@ -173,6 +180,24 @@ public final class MiniGames extends JavaPlugin {
return this.playerVisibilityManager; return this.playerVisibilityManager;
} }
/**
* Gets the translator to get messages from
*
* @return <p>The translator</p>
*/
public Translator getTranslator() {
return this.translator;
}
/**
* Gets the string formatter to get formatted messages from
*
* @return <p>The string formatter</p>
*/
public StringFormatter getStringFormatter() {
return this.stringFormatter;
}
/** /**
* Gets the current session of the given player * Gets the current session of the given player
* *
@ -208,6 +233,8 @@ public final class MiniGames extends JavaPlugin {
// Reload configuration // Reload configuration
this.reloadConfig(); this.reloadConfig();
translator.loadLanguages(this.getDataFolder(), "en",
getConfig().getString("language", "en"));
this.sharedConfiguration.load(this.getConfig()); this.sharedConfiguration.load(this.getConfig());
this.dropperConfiguration.load(this.getConfig()); this.dropperConfiguration.load(this.getConfig());
this.parkourConfiguration.load(this.getConfig()); this.parkourConfiguration.load(this.getConfig());
@ -290,6 +317,9 @@ public final class MiniGames extends JavaPlugin {
getConfig().options().copyDefaults(true); getConfig().options().copyDefaults(true);
saveConfig(); saveConfig();
reloadConfig(); reloadConfig();
setupStringFormatter();
this.sharedConfiguration = new SharedConfiguration(this.getConfig()); this.sharedConfiguration = new SharedConfiguration(this.getConfig());
this.dropperConfiguration = new DropperConfiguration(this.getConfig()); this.dropperConfiguration = new DropperConfiguration(this.getConfig());
this.parkourConfiguration = new ParkourConfiguration(this.getConfig()); this.parkourConfiguration = new ParkourConfiguration(this.getConfig());
@ -375,4 +405,20 @@ public final class MiniGames extends JavaPlugin {
registerCommand("parkourGroupList", new ParkourGroupListCommand(), null); registerCommand("parkourGroupList", new ParkourGroupListCommand(), null);
} }
/**
* Sets up the translator and the string formatter
*/
private void setupStringFormatter() {
translator = new Translator();
translator.registerMessageCategory(MiniGameMessage.ERROR_PLAYER_ONLY);
translator.loadLanguages(this.getDataFolder(), "en",
getConfig().getString("language", "en"));
stringFormatter = new StringFormatter(this.getDescription().getName(), translator);
stringFormatter.setColorConversion(ColorConversion.RGB);
stringFormatter.setNamePrefix("#546EED[&r&l");
stringFormatter.setNameSuffix("#546EED]");
stringFormatter.setErrorColor(ChatColor.RED);
stringFormatter.setSuccessColor(ChatColor.GREEN);
}
} }

View File

@ -1,8 +1,8 @@
package net.knarcraft.minigames.arena; package net.knarcraft.minigames.arena;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import net.knarcraft.minigames.container.PlaceholderContainer;
import net.knarcraft.minigames.property.RecordResult; import net.knarcraft.minigames.property.RecordResult;
import net.knarcraft.minigames.util.PlayerTeleporter; import net.knarcraft.minigames.util.PlayerTeleporter;
import org.bukkit.Location; import org.bukkit.Location;
@ -44,7 +44,7 @@ public abstract class AbstractArenaSession implements ArenaSession {
// Make the player visible to everyone // Make the player visible to everyone
MiniGames.getInstance().getPlayerVisibilityManager().showPlayersFor(player); MiniGames.getInstance().getPlayerVisibilityManager().showPlayersFor(player);
player.sendMessage(Message.SUCCESS_ARENA_QUIT.getMessage()); MiniGames.getInstance().getStringFormatter().displaySuccessMessage(player, MiniGameMessage.SUCCESS_ARENA_QUIT);
} }
@Override @Override
@ -69,16 +69,17 @@ public abstract class AbstractArenaSession implements ArenaSession {
// Gets a string representation of the played game-mode // Gets a string representation of the played game-mode
String gameModeString = getGameModeString(); String gameModeString = getGameModeString();
Message recordInfoMessage = switch (recordResult) { MiniGameMessage recordInfoMiniGameMessage = switch (recordResult) {
case WORLD_RECORD -> Message.RECORD_ACHIEVED_GLOBAL; case WORLD_RECORD -> MiniGameMessage.RECORD_ACHIEVED_GLOBAL;
case PERSONAL_BEST -> Message.RECORD_ACHIEVED_PERSONAL; case PERSONAL_BEST -> MiniGameMessage.RECORD_ACHIEVED_PERSONAL;
default -> throw new IllegalStateException("Unexpected value: " + recordResult); 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); stringFormatter.displaySuccessMessage(player, stringFormatter.replacePlaceholders(
placeholderContainer.add("{recordInfo}", recordInfo); MiniGameMessage.SUCCESS_RECORD_ACHIEVED, new String[]{"{gameMode}", "{recordInfo}"},
player.sendMessage(Message.SUCCESS_RECORD_ACHIEVED.getMessage(placeholderContainer)); new String[]{gameModeString, recordInfo}));
} }
/** /**

View File

@ -206,7 +206,7 @@ public class DropperArena implements Arena {
try { try {
DropperArenaStorageHelper.saveDropperArenaData(getData()); DropperArenaStorageHelper.saveDropperArenaData(getData());
return true; return true;
} catch (IOException e) { } catch (IOException exception) {
return false; return false;
} }
} }

View File

@ -3,7 +3,7 @@ package net.knarcraft.minigames.arena.dropper;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaHandler; import net.knarcraft.minigames.arena.ArenaHandler;
import net.knarcraft.minigames.arena.ArenaPlayerRegistry; 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 net.knarcraft.minigames.util.DropperArenaStorageHelper;
import java.io.IOException; import java.io.IOException;
@ -32,9 +32,10 @@ public class DropperArenaHandler extends ArenaHandler<DropperArena, DropperArena
public void saveGroups() { public void saveGroups() {
try { try {
DropperArenaStorageHelper.saveDropperArenaGroups(new HashSet<>(this.arenaGroups.values())); DropperArenaStorageHelper.saveDropperArenaGroups(new HashSet<>(this.arenaGroups.values()));
} catch (IOException e) { } catch (IOException exception) {
MiniGames.log(Level.SEVERE, Message.ERROR_CANNOT_SAVE_ARENA_GROUPS.getMessage()); MiniGames.log(Level.SEVERE, MiniGames.getInstance().getTranslator().getTranslatedMessage(
MiniGames.log(Level.SEVERE, e.getMessage()); 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() { public void saveArenas() {
try { try {
DropperArenaStorageHelper.saveDropperArenas(this.arenas); DropperArenaStorageHelper.saveDropperArenas(this.arenas);
} catch (IOException e) { } catch (IOException exception) {
MiniGames.log(Level.SEVERE, "Unable to save current arenas! " + MiniGames.log(Level.SEVERE, "Unable to save current arenas! " +
"Data loss can occur!"); "Data loss can occur!");
MiniGames.log(Level.SEVERE, e.getMessage()); MiniGames.log(Level.SEVERE, exception.getMessage());
} }
} }

View File

@ -1,9 +1,10 @@
package net.knarcraft.minigames.arena.dropper; package net.knarcraft.minigames.arena.dropper;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.AbstractArenaSession; import net.knarcraft.minigames.arena.AbstractArenaSession;
import net.knarcraft.minigames.arena.PlayerEntryState; import net.knarcraft.minigames.arena.PlayerEntryState;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import net.knarcraft.minigames.gui.ArenaGUI; import net.knarcraft.minigames.gui.ArenaGUI;
import net.knarcraft.minigames.gui.DropperGUI; import net.knarcraft.minigames.gui.DropperGUI;
import net.knarcraft.minigames.util.PlayerTeleporter; import net.knarcraft.minigames.util.PlayerTeleporter;
@ -92,11 +93,13 @@ public class DropperArenaSession extends AbstractArenaSession {
registerRecord(); registerRecord();
} }
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
// Mark the arena as cleared // Mark the arena as cleared
if (this.arena.getData().setCompleted(this.gameMode, this.player)) { 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 // Teleport the player out of the arena
teleportToExit(false); teleportToExit(false);

View File

@ -1,10 +1,10 @@
package net.knarcraft.minigames.arena.parkour; package net.knarcraft.minigames.arena.parkour;
import net.knarcraft.knarlib.util.MaterialHelper;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.Arena; import net.knarcraft.minigames.arena.Arena;
import net.knarcraft.minigames.arena.ArenaGameMode; import net.knarcraft.minigames.arena.ArenaGameMode;
import net.knarcraft.minigames.arena.ArenaRecordsRegistry; import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
import net.knarcraft.minigames.util.MaterialHelper;
import net.knarcraft.minigames.util.ParkourArenaStorageHelper; import net.knarcraft.minigames.util.ParkourArenaStorageHelper;
import net.knarcraft.minigames.util.StringSanitizer; import net.knarcraft.minigames.util.StringSanitizer;
import org.bukkit.Location; import org.bukkit.Location;
@ -106,7 +106,7 @@ public class ParkourArena implements Arena {
this.winLocation = winLocation; this.winLocation = winLocation;
this.killPlaneBlockNames = killPlaneBlockNames; this.killPlaneBlockNames = killPlaneBlockNames;
this.killPlaneBlocks = this.killPlaneBlockNames == null ? null : MaterialHelper.loadMaterialList( this.killPlaneBlocks = this.killPlaneBlockNames == null ? null : MaterialHelper.loadMaterialList(
new ArrayList<>(killPlaneBlockNames)); new ArrayList<>(killPlaneBlockNames), "+", MiniGames.getInstance().getLogger());
this.checkpoints = checkpoints; this.checkpoints = checkpoints;
this.parkourArenaData = parkourArenaData; this.parkourArenaData = parkourArenaData;
this.parkourArenaHandler = arenaHandler; this.parkourArenaHandler = arenaHandler;
@ -250,7 +250,7 @@ public class ParkourArena implements Arena {
try { try {
ParkourArenaStorageHelper.saveParkourArenaData(getData()); ParkourArenaStorageHelper.saveParkourArenaData(getData());
return true; return true;
} catch (IOException e) { } catch (IOException exception) {
return false; return false;
} }
} }
@ -366,7 +366,8 @@ public class ParkourArena implements Arena {
if (killPlaneBlockNames.isEmpty()) { if (killPlaneBlockNames.isEmpty()) {
this.killPlaneBlocks = null; this.killPlaneBlocks = null;
} else { } else {
Set<Material> parsed = MaterialHelper.loadMaterialList(new ArrayList<>(killPlaneBlockNames)); Set<Material> parsed = MaterialHelper.loadMaterialList(new ArrayList<>(killPlaneBlockNames), "+",
MiniGames.getInstance().getLogger());
if (parsed.isEmpty()) { if (parsed.isEmpty()) {
return false; return false;
} }

View File

@ -3,7 +3,7 @@ package net.knarcraft.minigames.arena.parkour;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaHandler; import net.knarcraft.minigames.arena.ArenaHandler;
import net.knarcraft.minigames.arena.ArenaPlayerRegistry; 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 net.knarcraft.minigames.util.ParkourArenaStorageHelper;
import java.io.IOException; import java.io.IOException;
@ -32,9 +32,10 @@ public class ParkourArenaHandler extends ArenaHandler<ParkourArena, ParkourArena
public void saveGroups() { public void saveGroups() {
try { try {
ParkourArenaStorageHelper.saveParkourArenaGroups(new HashSet<>(this.arenaGroups.values())); ParkourArenaStorageHelper.saveParkourArenaGroups(new HashSet<>(this.arenaGroups.values()));
} catch (IOException e) { } catch (IOException exception) {
MiniGames.log(Level.SEVERE, Message.ERROR_CANNOT_SAVE_ARENA_GROUPS.getMessage()); MiniGames.log(Level.SEVERE, MiniGames.getInstance().getTranslator().getTranslatedMessage(
MiniGames.log(Level.SEVERE, e.getMessage()); 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() { public void saveArenas() {
try { try {
ParkourArenaStorageHelper.saveParkourArenas(this.arenas); ParkourArenaStorageHelper.saveParkourArenas(this.arenas);
} catch (IOException e) { } catch (IOException exception) {
MiniGames.log(Level.SEVERE, "Unable to save current arenas! " + MiniGames.log(Level.SEVERE, "Unable to save current arenas! " +
"Data loss can occur!"); "Data loss can occur!");
MiniGames.log(Level.SEVERE, e.getMessage()); MiniGames.log(Level.SEVERE, exception.getMessage());
} }
} }

View File

@ -3,7 +3,7 @@ package net.knarcraft.minigames.arena.parkour;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.AbstractArenaSession; import net.knarcraft.minigames.arena.AbstractArenaSession;
import net.knarcraft.minigames.arena.PlayerEntryState; import net.knarcraft.minigames.arena.PlayerEntryState;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import net.knarcraft.minigames.gui.ArenaGUI; import net.knarcraft.minigames.gui.ArenaGUI;
import net.knarcraft.minigames.gui.ParkourGUI; import net.knarcraft.minigames.gui.ParkourGUI;
import net.knarcraft.minigames.util.PlayerTeleporter; import net.knarcraft.minigames.util.PlayerTeleporter;
@ -89,9 +89,11 @@ public class ParkourArenaSession extends AbstractArenaSession {
// Mark the arena as cleared // Mark the arena as cleared
if (this.arena.getData().setCompleted(this.gameMode, this.player)) { 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 // Teleport the player out of the arena
teleportToExit(false); teleportToExit(false);

View File

@ -2,7 +2,7 @@ package net.knarcraft.minigames.command;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaSession; import net.knarcraft.minigames.arena.ArenaSession;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
@ -22,13 +22,15 @@ public class LeaveArenaCommand implements TabExecutor {
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
@NotNull String[] strings) { @NotNull String[] strings) {
if (!(commandSender instanceof Player player)) { if (!(commandSender instanceof Player player)) {
commandSender.sendMessage(Message.ERROR_PLAYER_ONLY.getMessage()); MiniGames.getInstance().getStringFormatter().displayErrorMessage(commandSender,
MiniGameMessage.ERROR_PLAYER_ONLY);
return false; return false;
} }
ArenaSession existingSession = MiniGames.getInstance().getSession(player.getUniqueId()); ArenaSession existingSession = MiniGames.getInstance().getSession(player.getUniqueId());
if (existingSession == null) { if (existingSession == null) {
commandSender.sendMessage(Message.ERROR_NOT_IN_ARENA.getMessage()); MiniGames.getInstance().getStringFormatter().displayErrorMessage(commandSender,
MiniGameMessage.ERROR_NOT_IN_ARENA);
return false; return false;
} }

View File

@ -1,6 +1,7 @@
package net.knarcraft.minigames.command; package net.knarcraft.minigames.command;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.config.MiniGameMessage;
import net.knarcraft.minigames.util.GUIHelper; import net.knarcraft.minigames.util.GUIHelper;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -21,7 +22,8 @@ public class MenuCommand implements TabExecutor {
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
@NotNull String[] arguments) { @NotNull String[] arguments) {
if (!(commandSender instanceof Player player)) { if (!(commandSender instanceof Player player)) {
commandSender.sendMessage(Message.ERROR_PLAYER_ONLY.getMessage()); MiniGames.getInstance().getStringFormatter().displayErrorMessage(commandSender,
MiniGameMessage.ERROR_PLAYER_ONLY);
return false; return false;
} }

View File

@ -1,7 +1,7 @@
package net.knarcraft.minigames.command; package net.knarcraft.minigames.command;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
@ -20,7 +20,8 @@ public class ReloadCommand implements TabExecutor {
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
@NotNull String[] arguments) { @NotNull String[] arguments) {
MiniGames.getInstance().reload(); MiniGames.getInstance().reload();
commandSender.sendMessage(Message.SUCCESS_PLUGIN_RELOADED.getMessage()); MiniGames.getInstance().getStringFormatter().displaySuccessMessage(commandSender,
MiniGameMessage.SUCCESS_PLUGIN_RELOADED);
return true; return true;
} }

View File

@ -3,7 +3,7 @@ package net.knarcraft.minigames.command.dropper;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArena; import net.knarcraft.minigames.arena.dropper.DropperArena;
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler; import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import net.knarcraft.minigames.util.StringSanitizer; import net.knarcraft.minigames.util.StringSanitizer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -20,7 +20,8 @@ public class CreateDropperArenaCommand implements CommandExecutor {
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
@NotNull String[] arguments) { @NotNull String[] arguments) {
if (!(commandSender instanceof Player player)) { if (!(commandSender instanceof Player player)) {
commandSender.sendMessage(Message.ERROR_PLAYER_ONLY.getMessage()); MiniGames.getInstance().getStringFormatter().displayErrorMessage(commandSender,
MiniGameMessage.ERROR_PLAYER_ONLY);
return false; return false;
} }
@ -41,13 +42,15 @@ public class CreateDropperArenaCommand implements CommandExecutor {
DropperArena existingArena = arenaHandler.getArena(arenaName); DropperArena existingArena = arenaHandler.getArena(arenaName);
if (existingArena != null) { if (existingArena != null) {
commandSender.sendMessage(Message.ERROR_ARENA_NAME_COLLISION.getMessage()); MiniGames.getInstance().getStringFormatter().displayErrorMessage(commandSender,
MiniGameMessage.ERROR_ARENA_NAME_COLLISION);
return false; return false;
} }
DropperArena arena = new DropperArena(arenaName, player.getLocation(), arenaHandler); DropperArena arena = new DropperArena(arenaName, player.getLocation(), arenaHandler);
arenaHandler.addArena(arena); arenaHandler.addArena(arena);
commandSender.sendMessage(Message.SUCCESS_ARENA_CREATED.getMessage()); MiniGames.getInstance().getStringFormatter().displaySuccessMessage(commandSender,
MiniGameMessage.SUCCESS_ARENA_CREATED);
return true; return true;
} }

View File

@ -1,10 +1,11 @@
package net.knarcraft.minigames.command.dropper; package net.knarcraft.minigames.command.dropper;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArena; import net.knarcraft.minigames.arena.dropper.DropperArena;
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup; import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler; import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
@ -60,13 +61,15 @@ public class DropperGroupListCommand implements TabExecutor {
private boolean displayOrderedArenaNames(@NotNull DropperArenaHandler arenaHandler, @NotNull CommandSender sender, private boolean displayOrderedArenaNames(@NotNull DropperArenaHandler arenaHandler, @NotNull CommandSender sender,
@NotNull String groupName) { @NotNull String groupName) {
DropperArenaGroup arenaGroup = arenaHandler.getGroup(groupName); DropperArenaGroup arenaGroup = arenaHandler.getGroup(groupName);
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
if (arenaGroup == null) { if (arenaGroup == null) {
sender.sendMessage(Message.ERROR_GROUP_NOT_FOUND.getMessage()); stringFormatter.displayErrorMessage(sender, MiniGameMessage.ERROR_GROUP_NOT_FOUND);
return false; return false;
} }
// Send a list of all stages (arenas in the group) // Send a list of all stages (arenas in the group)
StringBuilder builder = new StringBuilder(Message.SUCCESS_GROUP_STAGES.getMessage("{group}", groupName)); StringBuilder builder = new StringBuilder(stringFormatter.replacePlaceholder(
MiniGameMessage.SUCCESS_GROUP_STAGES, "{group}", groupName));
int counter = 1; int counter = 1;
for (UUID arenaId : arenaGroup.getArenas()) { for (UUID arenaId : arenaGroup.getArenas()) {
DropperArena arena = arenaHandler.getArena(arenaId); DropperArena arena = arenaHandler.getArena(arenaId);
@ -74,7 +77,7 @@ public class DropperGroupListCommand implements TabExecutor {
builder.append(counter++).append(". ").append(arena.getArenaName()).append("\n"); builder.append(counter++).append(". ").append(arena.getArenaName()).append("\n");
} }
} }
sender.sendMessage(builder.toString()); stringFormatter.displaySuccessMessage(sender, builder.toString());
return true; return true;
} }

View File

@ -4,7 +4,7 @@ import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArena; import net.knarcraft.minigames.arena.dropper.DropperArena;
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup; import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler; import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import net.knarcraft.minigames.util.StringSanitizer; import net.knarcraft.minigames.util.StringSanitizer;
import net.knarcraft.minigames.util.TabCompleteHelper; import net.knarcraft.minigames.util.TabCompleteHelper;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -34,7 +34,8 @@ public class DropperGroupSetCommand implements TabExecutor {
DropperArena specifiedArena = arenaHandler.getArena(arguments[0]); DropperArena specifiedArena = arenaHandler.getArena(arguments[0]);
if (specifiedArena == null) { if (specifiedArena == null) {
commandSender.sendMessage(Message.ERROR_ARENA_NOT_FOUND.getMessage()); MiniGames.getInstance().getStringFormatter().displayErrorMessage(commandSender,
MiniGameMessage.ERROR_ARENA_NOT_FOUND);
return false; return false;
} }
@ -56,7 +57,8 @@ public class DropperGroupSetCommand implements TabExecutor {
arenaHandler.setGroup(specifiedArena.getArenaId(), arenaGroup); arenaHandler.setGroup(specifiedArena.getArenaId(), arenaGroup);
commandSender.sendMessage(Message.SUCCESS_ARENA_GROUP_UPDATED.getMessage()); MiniGames.getInstance().getStringFormatter().displaySuccessMessage(commandSender,
MiniGameMessage.SUCCESS_ARENA_GROUP_UPDATED);
return true; return true;
} }

View File

@ -1,10 +1,11 @@
package net.knarcraft.minigames.command.dropper; package net.knarcraft.minigames.command.dropper;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArena; import net.knarcraft.minigames.arena.dropper.DropperArena;
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup; import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler; import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
@ -29,30 +30,31 @@ public class DropperGroupSwapCommand implements TabExecutor {
return false; return false;
} }
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
DropperArenaHandler arenaHandler = MiniGames.getInstance().getDropperArenaHandler(); DropperArenaHandler arenaHandler = MiniGames.getInstance().getDropperArenaHandler();
DropperArena arena1 = arenaHandler.getArena(arguments[0]); DropperArena arena1 = arenaHandler.getArena(arguments[0]);
if (arena1 == null) { if (arena1 == null) {
commandSender.sendMessage(Message.ERROR_ARENA_1_NOT_FOUND.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_1_NOT_FOUND);
return false; return false;
} }
DropperArena arena2 = arenaHandler.getArena(arguments[1]); DropperArena arena2 = arenaHandler.getArena(arguments[1]);
if (arena2 == null) { if (arena2 == null) {
commandSender.sendMessage(Message.ERROR_ARENA_2_NOT_FOUND.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_2_NOT_FOUND);
return false; return false;
} }
DropperArenaGroup arena1Group = arenaHandler.getGroup(arena1.getArenaId()); DropperArenaGroup arena1Group = arenaHandler.getGroup(arena1.getArenaId());
DropperArenaGroup arena2Group = arenaHandler.getGroup(arena2.getArenaId()); DropperArenaGroup arena2Group = arenaHandler.getGroup(arena2.getArenaId());
if (arena1Group == null || !arena1Group.equals(arena2Group)) { if (arena1Group == null || !arena1Group.equals(arena2Group)) {
commandSender.sendMessage(Message.ERROR_SWAP_DIFFERENT_GROUPS.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_SWAP_DIFFERENT_GROUPS);
return false; return false;
} }
arena1Group.swapArenas(arena1Group.getArenas().indexOf(arena1.getArenaId()), arena1Group.swapArenas(arena1Group.getArenas().indexOf(arena1.getArenaId()),
arena1Group.getArenas().indexOf(arena2.getArenaId())); arena1Group.getArenas().indexOf(arena2.getArenaId()));
commandSender.sendMessage(Message.SUCCESS_ARENAS_SWAPPED.getMessage()); stringFormatter.displaySuccessMessage(commandSender, MiniGameMessage.SUCCESS_ARENAS_SWAPPED);
return true; return true;
} }

View File

@ -1,11 +1,11 @@
package net.knarcraft.minigames.command.dropper; package net.knarcraft.minigames.command.dropper;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArena; import net.knarcraft.minigames.arena.dropper.DropperArena;
import net.knarcraft.minigames.arena.dropper.DropperArenaEditableProperty; import net.knarcraft.minigames.arena.dropper.DropperArenaEditableProperty;
import net.knarcraft.minigames.config.DropperConfiguration; import net.knarcraft.minigames.config.DropperConfiguration;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import net.knarcraft.minigames.container.PlaceholderContainer;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -33,8 +33,9 @@ public class EditDropperArenaCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
@NotNull String[] arguments) { @NotNull String[] arguments) {
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
if (!(commandSender instanceof Player player)) { if (!(commandSender instanceof Player player)) {
commandSender.sendMessage(Message.ERROR_PLAYER_ONLY.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_PLAYER_ONLY);
return false; return false;
} }
@ -44,29 +45,31 @@ public class EditDropperArenaCommand implements CommandExecutor {
DropperArena specifiedArena = MiniGames.getInstance().getDropperArenaHandler().getArena(arguments[0]); DropperArena specifiedArena = MiniGames.getInstance().getDropperArenaHandler().getArena(arguments[0]);
if (specifiedArena == null) { if (specifiedArena == null) {
commandSender.sendMessage(Message.ERROR_ARENA_NOT_FOUND.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_NOT_FOUND);
return false; return false;
} }
DropperArenaEditableProperty editableProperty = DropperArenaEditableProperty.getFromArgumentString(arguments[1]); DropperArenaEditableProperty editableProperty = DropperArenaEditableProperty.getFromArgumentString(arguments[1]);
if (editableProperty == null) { if (editableProperty == null) {
commandSender.sendMessage(Message.ERROR_UNKNOWN_PROPERTY.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_UNKNOWN_PROPERTY);
return false; return false;
} }
if (arguments.length < 3) { if (arguments.length < 3) {
// Print the current value of the property // Print the current value of the property
String value = editableProperty.getCurrentValueAsString(specifiedArena); String value = editableProperty.getCurrentValueAsString(specifiedArena);
commandSender.sendMessage(Message.SUCCESS_CURRENT_VALUE.getMessage(new PlaceholderContainer().add( stringFormatter.displaySuccessMessage(commandSender, stringFormatter.replacePlaceholders(
"{property}", editableProperty.getArgumentString()).add("{value}", value))); MiniGameMessage.SUCCESS_CURRENT_VALUE, new String[]{"{property}", "{value}"},
new String[]{editableProperty.getArgumentString(), value}));
return true; return true;
} else { } else {
boolean successful = changeValue(specifiedArena, editableProperty, arguments[2], player); boolean successful = changeValue(specifiedArena, editableProperty, arguments[2], player);
if (successful) { if (successful) {
player.sendMessage(Message.SUCCESS_PROPERTY_CHANGED.getMessage("{property}", stringFormatter.displaySuccessMessage(player, stringFormatter.replacePlaceholder(
MiniGameMessage.SUCCESS_PROPERTY_CHANGED, "{property}",
editableProperty.getArgumentString())); editableProperty.getArgumentString()));
} else { } else {
player.sendMessage(Message.ERROR_PROPERTY_INPUT_INVALID.getMessage()); stringFormatter.displayErrorMessage(player, MiniGameMessage.ERROR_PROPERTY_INPUT_INVALID);
} }
return successful; return successful;
} }

View File

@ -1,5 +1,6 @@
package net.knarcraft.minigames.command.dropper; package net.knarcraft.minigames.command.dropper;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaPlayerRegistry; import net.knarcraft.minigames.arena.ArenaPlayerRegistry;
import net.knarcraft.minigames.arena.dropper.DropperArena; import net.knarcraft.minigames.arena.dropper.DropperArena;
@ -7,7 +8,7 @@ import net.knarcraft.minigames.arena.dropper.DropperArenaGameMode;
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup; import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
import net.knarcraft.minigames.arena.dropper.DropperArenaSession; import net.knarcraft.minigames.arena.dropper.DropperArenaSession;
import net.knarcraft.minigames.config.DropperConfiguration; import net.knarcraft.minigames.config.DropperConfiguration;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import net.knarcraft.minigames.util.GUIHelper; import net.knarcraft.minigames.util.GUIHelper;
import net.knarcraft.minigames.util.PlayerTeleporter; import net.knarcraft.minigames.util.PlayerTeleporter;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -24,8 +25,9 @@ public class JoinDropperArenaCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
@NotNull String[] arguments) { @NotNull String[] arguments) {
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
if (!(commandSender instanceof Player player)) { if (!(commandSender instanceof Player player)) {
commandSender.sendMessage(Message.ERROR_PLAYER_ONLY.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_PLAYER_ONLY);
return false; return false;
} }
@ -35,20 +37,20 @@ public class JoinDropperArenaCommand implements CommandExecutor {
// Disallow joining if the player is already in a mini-game arena // Disallow joining if the player is already in a mini-game arena
if (MiniGames.getInstance().getSession(player.getUniqueId()) != null) { if (MiniGames.getInstance().getSession(player.getUniqueId()) != null) {
commandSender.sendMessage(Message.ERROR_ALREADY_PLAYING.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ALREADY_PLAYING);
return false; return false;
} }
// Make sure the arena exists // Make sure the arena exists
DropperArena specifiedArena = MiniGames.getInstance().getDropperArenaHandler().getArena(arguments[0]); DropperArena specifiedArena = MiniGames.getInstance().getDropperArenaHandler().getArena(arguments[0]);
if (specifiedArena == null) { if (specifiedArena == null) {
commandSender.sendMessage(Message.ERROR_ARENA_NOT_FOUND.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_NOT_FOUND);
return false; return false;
} }
// Deny vehicles as allowing this is tricky, and will cause problems in some cases // Deny vehicles as allowing this is tricky, and will cause problems in some cases
if (player.isInsideVehicle() || !player.getPassengers().isEmpty()) { if (player.isInsideVehicle() || !player.getPassengers().isEmpty()) {
commandSender.sendMessage(Message.ERROR_JOIN_IN_VEHICLE_OR_PASSENGER.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_JOIN_IN_VEHICLE_OR_PASSENGER);
return false; return false;
} }
@ -78,11 +80,13 @@ public class JoinDropperArenaCommand implements CommandExecutor {
return false; return false;
} }
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
// Make sure the player has beaten the arena once in normal mode before playing another mode // Make sure the player has beaten the arena once in normal mode before playing another mode
if (MiniGames.getInstance().getDropperConfiguration().mustDoNormalModeFirst() && if (MiniGames.getInstance().getDropperConfiguration().mustDoNormalModeFirst() &&
gameMode != DropperArenaGameMode.DEFAULT && gameMode != DropperArenaGameMode.DEFAULT &&
specifiedArena.getData().hasNotCompleted(DropperArenaGameMode.DEFAULT, player)) { specifiedArena.getData().hasNotCompleted(DropperArenaGameMode.DEFAULT, player)) {
player.sendMessage(Message.ERROR_NORMAL_MODE_REQUIRED.getMessage()); stringFormatter.displayErrorMessage(player, MiniGameMessage.ERROR_NORMAL_MODE_REQUIRED);
return false; return false;
} }
@ -97,7 +101,7 @@ public class JoinDropperArenaCommand implements CommandExecutor {
// Try to teleport the player to the arena // Try to teleport the player to the arena
boolean teleported = PlayerTeleporter.teleportPlayer(player, specifiedArena.getSpawnLocation(), false, false); boolean teleported = PlayerTeleporter.teleportPlayer(player, specifiedArena.getSpawnLocation(), false, false);
if (!teleported) { if (!teleported) {
player.sendMessage(Message.ERROR_ARENA_TELEPORT_FAILED.getMessage()); stringFormatter.displayErrorMessage(player, MiniGameMessage.ERROR_ARENA_TELEPORT_FAILED);
newSession.triggerQuit(false, true); newSession.triggerQuit(false, true);
return false; return false;
} else { } else {
@ -105,7 +109,7 @@ public class JoinDropperArenaCommand implements CommandExecutor {
newSession.getEntryState().setArenaState(); newSession.getEntryState().setArenaState();
player.getInventory().addItem(GUIHelper.getGUIOpenItem()); player.getInventory().addItem(GUIHelper.getGUIOpenItem());
player.sendMessage(Message.SUCCESS_ARENA_JOINED.getMessage()); stringFormatter.displaySuccessMessage(player, MiniGameMessage.SUCCESS_ARENA_JOINED);
return true; return true;
} }
} }
@ -121,18 +125,19 @@ public class JoinDropperArenaCommand implements CommandExecutor {
*/ */
private boolean doGroupChecks(@NotNull DropperArena dropperArena, @NotNull DropperArenaGroup arenaGroup, private boolean doGroupChecks(@NotNull DropperArena dropperArena, @NotNull DropperArenaGroup arenaGroup,
@NotNull DropperArenaGameMode arenaGameMode, @NotNull Player player) { @NotNull DropperArenaGameMode arenaGameMode, @NotNull Player player) {
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
DropperConfiguration configuration = MiniGames.getInstance().getDropperConfiguration(); DropperConfiguration configuration = MiniGames.getInstance().getDropperConfiguration();
// Require that players beat all arenas in the group in the normal game-mode before trying challenge modes // Require that players beat all arenas in the group in the normal game-mode before trying challenge modes
if (configuration.mustDoNormalModeFirst() && arenaGameMode != DropperArenaGameMode.DEFAULT && if (configuration.mustDoNormalModeFirst() && arenaGameMode != DropperArenaGameMode.DEFAULT &&
!arenaGroup.hasBeatenAll(DropperArenaGameMode.DEFAULT, player)) { !arenaGroup.hasBeatenAll(DropperArenaGameMode.DEFAULT, player)) {
player.sendMessage(Message.ERROR_GROUP_NORMAL_MODE_REQUIRED.getMessage()); stringFormatter.displayErrorMessage(player, MiniGameMessage.ERROR_GROUP_NORMAL_MODE_REQUIRED);
return false; return false;
} }
// Require that the player has beaten the previous arena on the same game-mode before trying this one // Require that the player has beaten the previous arena on the same game-mode before trying this one
if (configuration.mustDoGroupedInSequence() && if (configuration.mustDoGroupedInSequence() &&
arenaGroup.cannotPlay(arenaGameMode, player, dropperArena.getArenaId())) { arenaGroup.cannotPlay(arenaGameMode, player, dropperArena.getArenaId())) {
player.sendMessage(Message.ERROR_PREVIOUS_ARENA_REQUIRED.getMessage()); stringFormatter.displayErrorMessage(player, MiniGameMessage.ERROR_PREVIOUS_ARENA_REQUIRED);
return false; return false;
} }

View File

@ -1,6 +1,7 @@
package net.knarcraft.minigames.command.dropper; package net.knarcraft.minigames.command.dropper;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.config.MiniGameMessage;
import net.knarcraft.minigames.util.TabCompleteHelper; import net.knarcraft.minigames.util.TabCompleteHelper;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -19,11 +20,12 @@ public class ListDropperArenaCommand implements TabExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] arguments) { @NotNull String[] arguments) {
StringBuilder builder = new StringBuilder(Message.SUCCESS_DROPPER_ARENAS_LIST.getMessage()); StringBuilder builder = new StringBuilder(MiniGames.getInstance().getTranslator().getTranslatedMessage(
MiniGameMessage.SUCCESS_DROPPER_ARENAS_LIST));
for (String arenaName : TabCompleteHelper.getDropperArenas()) { for (String arenaName : TabCompleteHelper.getDropperArenas()) {
builder.append("\n").append(arenaName); builder.append("\n").append(arenaName);
} }
sender.sendMessage(builder.toString()); MiniGames.getInstance().getStringFormatter().displaySuccessMessage(sender, builder.toString());
return true; return true;
} }

View File

@ -1,8 +1,9 @@
package net.knarcraft.minigames.command.dropper; package net.knarcraft.minigames.command.dropper;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArena; import net.knarcraft.minigames.arena.dropper.DropperArena;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -21,16 +22,18 @@ public class RemoveDropperArenaCommand implements CommandExecutor {
return false; return false;
} }
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
// Get the specified arena // Get the specified arena
DropperArena targetArena = MiniGames.getInstance().getDropperArenaHandler().getArena(arguments[0]); DropperArena targetArena = MiniGames.getInstance().getDropperArenaHandler().getArena(arguments[0]);
if (targetArena == null) { if (targetArena == null) {
commandSender.sendMessage(Message.ERROR_ARENA_NOT_FOUND.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_NOT_FOUND);
return false; return false;
} }
// Remove the arena // Remove the arena
MiniGames.getInstance().getDropperArenaHandler().removeArena(targetArena); MiniGames.getInstance().getDropperArenaHandler().removeArena(targetArena);
commandSender.sendMessage(Message.SUCCESS_ARENA_REMOVED.getMessage()); stringFormatter.displaySuccessMessage(commandSender, MiniGameMessage.SUCCESS_ARENA_REMOVED);
return true; return true;
} }

View File

@ -1,9 +1,10 @@
package net.knarcraft.minigames.command.parkour; package net.knarcraft.minigames.command.parkour;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.parkour.ParkourArena; import net.knarcraft.minigames.arena.parkour.ParkourArena;
import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler; import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import net.knarcraft.minigames.util.StringSanitizer; import net.knarcraft.minigames.util.StringSanitizer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -19,8 +20,9 @@ public class CreateParkourArenaCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
@NotNull String[] arguments) { @NotNull String[] arguments) {
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
if (!(commandSender instanceof Player player)) { if (!(commandSender instanceof Player player)) {
commandSender.sendMessage(Message.ERROR_PLAYER_ONLY.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_PLAYER_ONLY);
return false; return false;
} }
@ -41,13 +43,13 @@ public class CreateParkourArenaCommand implements CommandExecutor {
ParkourArena existingArena = arenaHandler.getArena(arenaName); ParkourArena existingArena = arenaHandler.getArena(arenaName);
if (existingArena != null) { if (existingArena != null) {
commandSender.sendMessage(Message.ERROR_ARENA_NAME_COLLISION.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_NAME_COLLISION);
return false; return false;
} }
ParkourArena arena = new ParkourArena(arenaName, player.getLocation(), arenaHandler); ParkourArena arena = new ParkourArena(arenaName, player.getLocation(), arenaHandler);
arenaHandler.addArena(arena); arenaHandler.addArena(arena);
commandSender.sendMessage(Message.SUCCESS_ARENA_CREATED.getMessage()); stringFormatter.displaySuccessMessage(commandSender, MiniGameMessage.SUCCESS_ARENA_CREATED);
return true; return true;
} }

View File

@ -1,10 +1,10 @@
package net.knarcraft.minigames.command.parkour; package net.knarcraft.minigames.command.parkour;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.parkour.ParkourArena; import net.knarcraft.minigames.arena.parkour.ParkourArena;
import net.knarcraft.minigames.arena.parkour.ParkourArenaEditableProperty; import net.knarcraft.minigames.arena.parkour.ParkourArenaEditableProperty;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import net.knarcraft.minigames.container.PlaceholderContainer;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -30,8 +30,9 @@ public class EditParkourArenaCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
@NotNull String[] arguments) { @NotNull String[] arguments) {
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
if (!(commandSender instanceof Player player)) { if (!(commandSender instanceof Player player)) {
commandSender.sendMessage(Message.ERROR_PLAYER_ONLY.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_PLAYER_ONLY);
return false; return false;
} }
@ -41,29 +42,31 @@ public class EditParkourArenaCommand implements CommandExecutor {
ParkourArena specifiedArena = MiniGames.getInstance().getParkourArenaHandler().getArena(arguments[0]); ParkourArena specifiedArena = MiniGames.getInstance().getParkourArenaHandler().getArena(arguments[0]);
if (specifiedArena == null) { if (specifiedArena == null) {
commandSender.sendMessage(Message.ERROR_ARENA_NOT_FOUND.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_NOT_FOUND);
return false; return false;
} }
ParkourArenaEditableProperty editableProperty = ParkourArenaEditableProperty.getFromArgumentString(arguments[1]); ParkourArenaEditableProperty editableProperty = ParkourArenaEditableProperty.getFromArgumentString(arguments[1]);
if (editableProperty == null) { if (editableProperty == null) {
commandSender.sendMessage(Message.ERROR_UNKNOWN_PROPERTY.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_UNKNOWN_PROPERTY);
return false; return false;
} }
if (arguments.length < 3) { if (arguments.length < 3) {
// Print the current value of the property // Print the current value of the property
String value = editableProperty.getCurrentValueAsString(specifiedArena); String value = editableProperty.getCurrentValueAsString(specifiedArena);
commandSender.sendMessage(Message.SUCCESS_CURRENT_VALUE.getMessage(new PlaceholderContainer().add( stringFormatter.displaySuccessMessage(commandSender, stringFormatter.replacePlaceholders(
"{property}", editableProperty.getArgumentString()).add("{value}", value))); MiniGameMessage.SUCCESS_CURRENT_VALUE, new String[]{"{property}", "{value}"},
new String[]{editableProperty.getArgumentString(), value}));
return true; return true;
} else { } else {
boolean successful = changeValue(specifiedArena, editableProperty, arguments[2], player); boolean successful = changeValue(specifiedArena, editableProperty, arguments[2], player);
if (successful) { if (successful) {
player.sendMessage(Message.SUCCESS_PROPERTY_CHANGED.getMessage("{property}", stringFormatter.displaySuccessMessage(player, stringFormatter.replacePlaceholder(
MiniGameMessage.SUCCESS_PROPERTY_CHANGED, "{property}",
editableProperty.getArgumentString())); editableProperty.getArgumentString()));
} else { } else {
player.sendMessage(Message.ERROR_PROPERTY_INPUT_INVALID.getMessage()); stringFormatter.displayErrorMessage(player, MiniGameMessage.ERROR_PROPERTY_INPUT_INVALID);
} }
return successful; return successful;
} }

View File

@ -1,12 +1,13 @@
package net.knarcraft.minigames.command.parkour; package net.knarcraft.minigames.command.parkour;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaPlayerRegistry; import net.knarcraft.minigames.arena.ArenaPlayerRegistry;
import net.knarcraft.minigames.arena.parkour.ParkourArena; import net.knarcraft.minigames.arena.parkour.ParkourArena;
import net.knarcraft.minigames.arena.parkour.ParkourArenaGameMode; import net.knarcraft.minigames.arena.parkour.ParkourArenaGameMode;
import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup; import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup;
import net.knarcraft.minigames.arena.parkour.ParkourArenaSession; import net.knarcraft.minigames.arena.parkour.ParkourArenaSession;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import net.knarcraft.minigames.config.ParkourConfiguration; import net.knarcraft.minigames.config.ParkourConfiguration;
import net.knarcraft.minigames.util.GUIHelper; import net.knarcraft.minigames.util.GUIHelper;
import net.knarcraft.minigames.util.PlayerTeleporter; import net.knarcraft.minigames.util.PlayerTeleporter;
@ -24,8 +25,9 @@ public class JoinParkourArenaCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
@NotNull String[] arguments) { @NotNull String[] arguments) {
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
if (!(commandSender instanceof Player player)) { if (!(commandSender instanceof Player player)) {
commandSender.sendMessage(Message.ERROR_PLAYER_ONLY.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_PLAYER_ONLY);
return false; return false;
} }
@ -35,20 +37,20 @@ public class JoinParkourArenaCommand implements CommandExecutor {
// Disallow joining if the player is already in a mini-game arena // Disallow joining if the player is already in a mini-game arena
if (MiniGames.getInstance().getSession(player.getUniqueId()) != null) { if (MiniGames.getInstance().getSession(player.getUniqueId()) != null) {
commandSender.sendMessage(Message.ERROR_ALREADY_PLAYING.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ALREADY_PLAYING);
return false; return false;
} }
// Make sure the arena exists // Make sure the arena exists
ParkourArena specifiedArena = MiniGames.getInstance().getParkourArenaHandler().getArena(arguments[0]); ParkourArena specifiedArena = MiniGames.getInstance().getParkourArenaHandler().getArena(arguments[0]);
if (specifiedArena == null) { if (specifiedArena == null) {
commandSender.sendMessage(Message.ERROR_ARENA_NOT_FOUND.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_NOT_FOUND);
return false; return false;
} }
// Deny vehicles as allowing this is tricky, and will cause problems in some cases // Deny vehicles as allowing this is tricky, and will cause problems in some cases
if (player.isInsideVehicle() || !player.getPassengers().isEmpty()) { if (player.isInsideVehicle() || !player.getPassengers().isEmpty()) {
commandSender.sendMessage(Message.ERROR_JOIN_IN_VEHICLE_OR_PASSENGER.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_JOIN_IN_VEHICLE_OR_PASSENGER);
return false; return false;
} }
@ -74,7 +76,8 @@ public class JoinParkourArenaCommand implements CommandExecutor {
// Don't allow joining the hardcore game-mode if there are no checkpoints to skip // Don't allow joining the hardcore game-mode if there are no checkpoints to skip
if (specifiedArena.hasNoCheckpoints() && gameMode == ParkourArenaGameMode.HARDCORE) { if (specifiedArena.hasNoCheckpoints() && gameMode == ParkourArenaGameMode.HARDCORE) {
player.sendMessage(Message.ERROR_HARDCORE_NO_CHECKPOINTS.getMessage()); MiniGames.getInstance().getStringFormatter().displayErrorMessage(player,
MiniGameMessage.ERROR_HARDCORE_NO_CHECKPOINTS);
return false; return false;
} }
@ -95,7 +98,8 @@ public class JoinParkourArenaCommand implements CommandExecutor {
// Try to teleport the player to the arena // Try to teleport the player to the arena
boolean teleported = PlayerTeleporter.teleportPlayer(player, specifiedArena.getSpawnLocation(), false, false); boolean teleported = PlayerTeleporter.teleportPlayer(player, specifiedArena.getSpawnLocation(), false, false);
if (!teleported) { if (!teleported) {
player.sendMessage(Message.ERROR_ARENA_TELEPORT_FAILED.getMessage()); MiniGames.getInstance().getStringFormatter().displayErrorMessage(player,
MiniGameMessage.ERROR_ARENA_TELEPORT_FAILED);
newSession.triggerQuit(false, true); newSession.triggerQuit(false, true);
return false; return false;
} else { } else {
@ -103,7 +107,8 @@ public class JoinParkourArenaCommand implements CommandExecutor {
newSession.getEntryState().setArenaState(); newSession.getEntryState().setArenaState();
player.getInventory().addItem(GUIHelper.getGUIOpenItem()); player.getInventory().addItem(GUIHelper.getGUIOpenItem());
player.sendMessage(Message.SUCCESS_ARENA_JOINED.getMessage()); MiniGames.getInstance().getStringFormatter().displaySuccessMessage(player,
MiniGameMessage.SUCCESS_ARENA_JOINED);
return true; return true;
} }
} }
@ -124,7 +129,8 @@ public class JoinParkourArenaCommand implements CommandExecutor {
// Require that the player has beaten the previous arena on the same game-mode before trying this one // Require that the player has beaten the previous arena on the same game-mode before trying this one
if (configuration.mustDoGroupedInSequence() && if (configuration.mustDoGroupedInSequence() &&
arenaGroup.cannotPlay(arenaGameMode, player, parkourArena.getArenaId())) { arenaGroup.cannotPlay(arenaGameMode, player, parkourArena.getArenaId())) {
player.sendMessage(Message.ERROR_PREVIOUS_ARENA_REQUIRED.getMessage()); MiniGames.getInstance().getStringFormatter().displayErrorMessage(player,
MiniGameMessage.ERROR_PREVIOUS_ARENA_REQUIRED);
return false; return false;
} }

View File

@ -1,6 +1,7 @@
package net.knarcraft.minigames.command.parkour; package net.knarcraft.minigames.command.parkour;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.config.MiniGameMessage;
import net.knarcraft.minigames.util.TabCompleteHelper; import net.knarcraft.minigames.util.TabCompleteHelper;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -19,11 +20,12 @@ public class ListParkourArenaCommand implements TabExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] arguments) { @NotNull String[] arguments) {
StringBuilder builder = new StringBuilder(Message.SUCCESS_PARKOUR_ARENAS_LIST.getMessage()); StringBuilder builder = new StringBuilder(MiniGames.getInstance().getTranslator().getTranslatedMessage(
MiniGameMessage.SUCCESS_PARKOUR_ARENAS_LIST));
for (String arenaName : TabCompleteHelper.getParkourArenas()) { for (String arenaName : TabCompleteHelper.getParkourArenas()) {
builder.append("\n").append(arenaName); builder.append("\n").append(arenaName);
} }
sender.sendMessage(builder.toString()); MiniGames.getInstance().getStringFormatter().displaySuccessMessage(sender, builder.toString());
return true; return true;
} }

View File

@ -1,10 +1,11 @@
package net.knarcraft.minigames.command.parkour; package net.knarcraft.minigames.command.parkour;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.parkour.ParkourArena; import net.knarcraft.minigames.arena.parkour.ParkourArena;
import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup; import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup;
import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler; import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
@ -60,14 +61,16 @@ public class ParkourGroupListCommand implements TabExecutor {
*/ */
private boolean displayOrderedArenaNames(@NotNull ParkourArenaHandler arenaHandler, @NotNull CommandSender sender, private boolean displayOrderedArenaNames(@NotNull ParkourArenaHandler arenaHandler, @NotNull CommandSender sender,
@NotNull String groupName) { @NotNull String groupName) {
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
ParkourArenaGroup arenaGroup = arenaHandler.getGroup(groupName); ParkourArenaGroup arenaGroup = arenaHandler.getGroup(groupName);
if (arenaGroup == null) { if (arenaGroup == null) {
sender.sendMessage(Message.ERROR_GROUP_NOT_FOUND.getMessage()); stringFormatter.displayErrorMessage(sender, MiniGameMessage.ERROR_GROUP_NOT_FOUND);
return false; return false;
} }
// Send a list of all stages (arenas in the group) // Send a list of all stages (arenas in the group)
StringBuilder builder = new StringBuilder(Message.SUCCESS_GROUP_STAGES.getMessage("{group}", groupName)); StringBuilder builder = new StringBuilder(stringFormatter.replacePlaceholder(
MiniGameMessage.SUCCESS_GROUP_STAGES, "{group}", groupName));
int counter = 1; int counter = 1;
for (UUID arenaId : arenaGroup.getArenas()) { for (UUID arenaId : arenaGroup.getArenas()) {
ParkourArena arena = arenaHandler.getArena(arenaId); ParkourArena arena = arenaHandler.getArena(arenaId);
@ -75,7 +78,7 @@ public class ParkourGroupListCommand implements TabExecutor {
builder.append("\n").append(counter++).append(". ").append(arena.getArenaName()); builder.append("\n").append(counter++).append(". ").append(arena.getArenaName());
} }
} }
sender.sendMessage(builder.toString()); stringFormatter.displaySuccessMessage(sender, builder.toString());
return true; return true;
} }

View File

@ -1,10 +1,11 @@
package net.knarcraft.minigames.command.parkour; package net.knarcraft.minigames.command.parkour;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.parkour.ParkourArena; import net.knarcraft.minigames.arena.parkour.ParkourArena;
import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup; import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup;
import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler; import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import net.knarcraft.minigames.util.StringSanitizer; import net.knarcraft.minigames.util.StringSanitizer;
import net.knarcraft.minigames.util.TabCompleteHelper; import net.knarcraft.minigames.util.TabCompleteHelper;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -30,11 +31,12 @@ public class ParkourGroupSetCommand implements TabExecutor {
return false; return false;
} }
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
ParkourArenaHandler arenaHandler = MiniGames.getInstance().getParkourArenaHandler(); ParkourArenaHandler arenaHandler = MiniGames.getInstance().getParkourArenaHandler();
ParkourArena specifiedArena = arenaHandler.getArena(arguments[0]); ParkourArena specifiedArena = arenaHandler.getArena(arguments[0]);
if (specifiedArena == null) { if (specifiedArena == null) {
commandSender.sendMessage(Message.ERROR_ARENA_NOT_FOUND.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_NOT_FOUND);
return false; return false;
} }
@ -56,7 +58,7 @@ public class ParkourGroupSetCommand implements TabExecutor {
arenaHandler.setGroup(specifiedArena.getArenaId(), arenaGroup); arenaHandler.setGroup(specifiedArena.getArenaId(), arenaGroup);
commandSender.sendMessage(Message.SUCCESS_ARENA_GROUP_UPDATED.getMessage()); stringFormatter.displaySuccessMessage(commandSender, MiniGameMessage.SUCCESS_ARENA_GROUP_UPDATED);
return true; return true;
} }

View File

@ -1,10 +1,11 @@
package net.knarcraft.minigames.command.parkour; package net.knarcraft.minigames.command.parkour;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.parkour.ParkourArena; import net.knarcraft.minigames.arena.parkour.ParkourArena;
import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup; import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup;
import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler; import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
@ -30,29 +31,30 @@ public class ParkourGroupSwapCommand implements TabExecutor {
} }
ParkourArenaHandler arenaHandler = MiniGames.getInstance().getParkourArenaHandler(); ParkourArenaHandler arenaHandler = MiniGames.getInstance().getParkourArenaHandler();
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
ParkourArena arena1 = arenaHandler.getArena(arguments[0]); ParkourArena arena1 = arenaHandler.getArena(arguments[0]);
if (arena1 == null) { if (arena1 == null) {
commandSender.sendMessage(Message.ERROR_ARENA_1_NOT_FOUND.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_1_NOT_FOUND);
return false; return false;
} }
ParkourArena arena2 = arenaHandler.getArena(arguments[1]); ParkourArena arena2 = arenaHandler.getArena(arguments[1]);
if (arena2 == null) { if (arena2 == null) {
commandSender.sendMessage(Message.ERROR_ARENA_2_NOT_FOUND.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_2_NOT_FOUND);
return false; return false;
} }
ParkourArenaGroup arena1Group = arenaHandler.getGroup(arena1.getArenaId()); ParkourArenaGroup arena1Group = arenaHandler.getGroup(arena1.getArenaId());
ParkourArenaGroup arena2Group = arenaHandler.getGroup(arena2.getArenaId()); ParkourArenaGroup arena2Group = arenaHandler.getGroup(arena2.getArenaId());
if (arena1Group == null || !arena1Group.equals(arena2Group)) { if (arena1Group == null || !arena1Group.equals(arena2Group)) {
commandSender.sendMessage(Message.ERROR_SWAP_DIFFERENT_GROUPS.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_SWAP_DIFFERENT_GROUPS);
return false; return false;
} }
arena1Group.swapArenas(arena1Group.getArenas().indexOf(arena1.getArenaId()), arena1Group.swapArenas(arena1Group.getArenas().indexOf(arena1.getArenaId()),
arena1Group.getArenas().indexOf(arena2.getArenaId())); arena1Group.getArenas().indexOf(arena2.getArenaId()));
commandSender.sendMessage(Message.SUCCESS_ARENAS_SWAPPED.getMessage()); stringFormatter.displaySuccessMessage(commandSender, MiniGameMessage.SUCCESS_ARENAS_SWAPPED);
return true; return true;
} }

View File

@ -1,8 +1,9 @@
package net.knarcraft.minigames.command.parkour; package net.knarcraft.minigames.command.parkour;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.parkour.ParkourArena; import net.knarcraft.minigames.arena.parkour.ParkourArena;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -21,16 +22,18 @@ public class RemoveParkourArenaCommand implements CommandExecutor {
return false; return false;
} }
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
// Get the specified arena // Get the specified arena
ParkourArena targetArena = MiniGames.getInstance().getParkourArenaHandler().getArena(arguments[0]); ParkourArena targetArena = MiniGames.getInstance().getParkourArenaHandler().getArena(arguments[0]);
if (targetArena == null) { if (targetArena == null) {
commandSender.sendMessage(Message.ERROR_ARENA_NOT_FOUND.getMessage()); stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_NOT_FOUND);
return false; return false;
} }
// Remove the arena // Remove the arena
MiniGames.getInstance().getParkourArenaHandler().removeArena(targetArena); MiniGames.getInstance().getParkourArenaHandler().removeArena(targetArena);
commandSender.sendMessage(Message.SUCCESS_ARENA_REMOVED.getMessage()); stringFormatter.displaySuccessMessage(commandSender, MiniGameMessage.SUCCESS_ARENA_REMOVED);
return true; return true;
} }

View File

@ -1,305 +0,0 @@
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 messages *
* ************** */
/**
* The message displayed if saving arena groups fails
*/
ERROR_CANNOT_SAVE_ARENA_GROUPS("&cUnable to save current arena groups! Data loss can occur!"),
/**
* The message displayed if an un-parse-able message is given by a user
*/
ERROR_MATERIAL_NOT_PARSE_ABLE("&cUnable to parse material: {material}"),
/**
* The message displayed if a player tries to be teleported to/from an arena with a passenger
*/
ERROR_TELEPORT_WITH_PASSENGER("&cYou cannot be teleported with a passenger!"),
/**
* The message displayed if a player tries to be teleported to/from an arena with a vehicle
*/
ERROR_TELEPORT_IN_VEHICLE("&cYou cannot be teleported while in a vehicle"),
/**
* The message displayed if an arena cannot be loaded
*/
ERROR_ARENA_NOT_LOADED("&cCould not load the arena at configuration section {section}. Please check " +
"the {file} storage file for issues."),
/**
* The message displayed if an arena's data cannot be loaded
*/
ERROR_ARENA_DATA_NOT_LOADED("&cUnable to load arena data for dropper arena: {arena}"),
/**
* The message displayed if the user specifies an unrecognized arena
*/
ERROR_ARENA_NOT_FOUND("&cUnable to find the specified arena."),
/**
* The message displayed if the user specifies an unrecognized group
*/
ERROR_GROUP_NOT_FOUND("&cUnable to find the specified group!"),
/**
* The message displayed if the console tries to execute a player-only command
*/
ERROR_PLAYER_ONLY("&cThis command must be used by a player"),
/**
* The message displayed if the name of an arena is duplicated
*/
ERROR_ARENA_NAME_COLLISION("&cThere already exists an arena with that name!"),
/**
* The message displayed if the player is required to win on the default difficulty first
*/
ERROR_NORMAL_MODE_REQUIRED("&cYou must complete this arena in normal mode first!"),
/**
* The message displayed if the player is required to win on the default difficulty for all arenas in the group first
*/
ERROR_GROUP_NORMAL_MODE_REQUIRED("&cYou have not yet beaten the default game-mode for all arenas in this group!"),
/**
* The message displayed if the player is required to beat the previous arena in the group
*/
ERROR_PREVIOUS_ARENA_REQUIRED("&cYou have not yet beaten the previous arena!"),
/**
* The message displayed if player teleportation failed for some reason
*/
ERROR_ARENA_TELEPORT_FAILED("&cUnable to teleport you to the arena."),
/**
* The message displayed if the player tries to quit the arena while not in an arena
*/
ERROR_NOT_IN_ARENA("&cYou are not in a mini-games arena!"),
/**
* The message displayed if the player tries to join an arena while already playing
*
* <p>This should in theory be impossible, as players cannot use any commands except /miniGamesLeave while playing
* in an arena.</p>
*/
ERROR_ALREADY_PLAYING("&cYou are already playing a mini-game!"),
/**
* The message displayed if a player tries to join an arena with a passenger or riding a vehicle
*/
ERROR_JOIN_IN_VEHICLE_OR_PASSENGER("&cYou cannot join an arena while inside a vehicle or carrying a passenger."),
/**
* The message displayed if the player tries to change an unrecognized arena property
*/
ERROR_UNKNOWN_PROPERTY("&cUnknown property specified."),
/**
* The message displayed if the given input to /dEdit or /pEdit's value is invalid
*/
ERROR_PROPERTY_INPUT_INVALID("&cUnable to change the property. Make sure your input is valid!"),
/**
* The message displayed if the first arena specified in /dgSwap or /pgSwap is invalid
*/
ERROR_ARENA_1_NOT_FOUND("&cUnable to find the first specified arena."),
/**
* The message displayed if the second arena specified in /dgSwap or /pgSwap is invalid
*/
ERROR_ARENA_2_NOT_FOUND("&cUnable to find the second specified dropper arena."),
/**
* The message displayed if the two groups specified for /dgSwap or /pgSwap are in different arenas
*/
ERROR_SWAP_DIFFERENT_GROUPS("&cYou cannot swap arenas in different groups!"),
/**
* The message displayed if a player tries to use any command other than /mLeave while in an arena
*/
ERROR_ILLEGAL_COMMAND("&cYou cannot use that command while in an arena!"),
/**
* The message displayed if the player is trying to join a parkour arena on hardcore which has no checkpoints
*/
ERROR_HARDCORE_NO_CHECKPOINTS("&cThis arena cannot be played in hardcore mode as it has no checkpoints!"),
/* **************** *
* Success messages *
* **************** */
/**
* The message displayed if an arena's group has been changed
*/
SUCCESS_ARENA_GROUP_UPDATED("&aThe arena's group has been updated"),
/**
* The message displayed if the MiniGames plugin is reloaded
*/
SUCCESS_PLUGIN_RELOADED("&aPlugin reloaded!"),
/**
* The message displayed if a new arena has been created
*/
SUCCESS_ARENA_CREATED("&aThe arena was successfully created!"),
/**
* The message displayed if a player clears/wins an arena for the first time
*/
SUCCESS_ARENA_FIRST_CLEAR("&aYou cleared the arena!"),
/**
* The message displayed when a player wins an arena
*/
SUCCESS_ARENA_WIN("&aYou won!"),
/**
* The message displayed when a player quits an arena
*/
SUCCESS_ARENA_QUIT("&aYou quit the arena!"),
/**
* The message used to display the current value of an arena property
*/
SUCCESS_CURRENT_VALUE("&aCurrent value of {property} is: {value}"),
/**
* The message used to announce that an arena property has been changed
*/
SUCCESS_PROPERTY_CHANGED("&aProperty {property} successfully changed"),
/**
* The message displayed when two arenas' order in a group have been swapped
*/
SUCCESS_ARENAS_SWAPPED("&aThe arenas have been swapped!"),
/**
* The message displayed when an arena has been removed
*/
SUCCESS_ARENA_REMOVED("&aThe specified arena has been successfully removed"),
/**
* The header displayed before listing all dropper arenas
*/
SUCCESS_DROPPER_ARENAS_LIST("&aDropper arenas:&r"),
/**
* The header displayed before listing all parkour arenas
*/
SUCCESS_PARKOUR_ARENAS_LIST("&aParkour arenas:&r"),
/**
* The message displayed when a player reaches a new checkpoint in a parkour arena
*/
SUCCESS_CHECKPOINT_REACHED("&aCheckpoint reached!"),
/**
* The header displayed before listing all arenas (stages) in a group
*/
SUCCESS_GROUP_STAGES("&a{group}'s stages:&r"),
/**
* The message displayed when a new record has been achieved
*/
SUCCESS_RECORD_ACHIEVED("&aYou just set a {recordInfo} on the {gameMode} game-mode!"),
/**
* The partial message used to describe that the player achieved a world record
*/
RECORD_ACHIEVED_GLOBAL("new {recordType} record"),
/**
* The partial message used to describe that the player achieved a personal best record
*/
RECORD_ACHIEVED_PERSONAL("personal {recordType} record"),
/**
* The message displayed when a player joins an arena
*/
SUCCESS_ARENA_JOINED("&aYou joined the arena."),
;
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, intended for display within another message
*
* @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 getPartialMessage(@NotNull String placeholder, @NotNull String replacement) {
return ColorHelper.translateAllColorCodes(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);
}
}

View File

@ -1,6 +1,7 @@
package net.knarcraft.minigames.config; package net.knarcraft.minigames.config;
import net.knarcraft.minigames.util.MaterialHelper; import net.knarcraft.knarlib.util.MaterialHelper;
import net.knarcraft.minigames.MiniGames;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -46,7 +47,7 @@ public abstract class MiniGameConfiguration {
*/ */
public @NotNull Set<Material> loadMaterialList(@NotNull String path) { public @NotNull Set<Material> loadMaterialList(@NotNull String path) {
List<?> blockWhitelist = configuration.getList(path, new ArrayList<>()); List<?> blockWhitelist = configuration.getList(path, new ArrayList<>());
return MaterialHelper.loadMaterialList(blockWhitelist); return MaterialHelper.loadMaterialList(blockWhitelist, "+", MiniGames.getInstance().getLogger());
} }
} }

View File

@ -0,0 +1,238 @@
package net.knarcraft.minigames.config;
import net.knarcraft.knarlib.formatting.TranslatableMessage;
import org.jetbrains.annotations.NotNull;
/**
* A message which ca be displayed to the user
*/
public enum MiniGameMessage implements TranslatableMessage {
/* ************** *
* Error messages *
* ************** */
/**
* The message displayed if saving arena groups fails
*/
ERROR_CANNOT_SAVE_ARENA_GROUPS,
/**
* The message displayed if an un-parse-able message is given by a user
*/
ERROR_MATERIAL_NOT_PARSE_ABLE,
/**
* The message displayed if a player tries to be teleported to/from an arena with a passenger
*/
ERROR_TELEPORT_WITH_PASSENGER,
/**
* The message displayed if a player tries to be teleported to/from an arena with a vehicle
*/
ERROR_TELEPORT_IN_VEHICLE,
/**
* The message displayed if an arena cannot be loaded
*/
ERROR_ARENA_NOT_LOADED,
/**
* The message displayed if an arena's data cannot be loaded
*/
ERROR_ARENA_DATA_NOT_LOADED,
/**
* The message displayed if the user specifies an unrecognized arena
*/
ERROR_ARENA_NOT_FOUND,
/**
* The message displayed if the user specifies an unrecognized group
*/
ERROR_GROUP_NOT_FOUND,
/**
* The message displayed if the console tries to execute a player-only command
*/
ERROR_PLAYER_ONLY,
/**
* The message displayed if the name of an arena is duplicated
*/
ERROR_ARENA_NAME_COLLISION,
/**
* The message displayed if the player is required to win on the default difficulty first
*/
ERROR_NORMAL_MODE_REQUIRED,
/**
* The message displayed if the player is required to win on the default difficulty for all arenas in the group first
*/
ERROR_GROUP_NORMAL_MODE_REQUIRED,
/**
* The message displayed if the player is required to beat the previous arena in the group
*/
ERROR_PREVIOUS_ARENA_REQUIRED,
/**
* The message displayed if player teleportation failed for some reason
*/
ERROR_ARENA_TELEPORT_FAILED,
/**
* The message displayed if the player tries to quit the arena while not in an arena
*/
ERROR_NOT_IN_ARENA,
/**
* The message displayed if the player tries to join an arena while already playing
*
* <p>This should in theory be impossible, as players cannot use any commands except /miniGamesLeave while playing
* in an arena.</p>
*/
ERROR_ALREADY_PLAYING,
/**
* The message displayed if a player tries to join an arena with a passenger or riding a vehicle
*/
ERROR_JOIN_IN_VEHICLE_OR_PASSENGER,
/**
* The message displayed if the player tries to change an unrecognized arena property
*/
ERROR_UNKNOWN_PROPERTY,
/**
* The message displayed if the given input to /dEdit or /pEdit's value is invalid
*/
ERROR_PROPERTY_INPUT_INVALID,
/**
* The message displayed if the first arena specified in /dgSwap or /pgSwap is invalid
*/
ERROR_ARENA_1_NOT_FOUND,
/**
* The message displayed if the second arena specified in /dgSwap or /pgSwap is invalid
*/
ERROR_ARENA_2_NOT_FOUND,
/**
* The message displayed if the two groups specified for /dgSwap or /pgSwap are in different arenas
*/
ERROR_SWAP_DIFFERENT_GROUPS,
/**
* The message displayed if a player tries to use any command other than /mLeave while in an arena
*/
ERROR_ILLEGAL_COMMAND,
/**
* The message displayed if the player is trying to join a parkour arena on hardcore which has no checkpoints
*/
ERROR_HARDCORE_NO_CHECKPOINTS,
/* **************** *
* Success messages *
* **************** */
/**
* The message displayed if an arena's group has been changed
*/
SUCCESS_ARENA_GROUP_UPDATED,
/**
* The message displayed if the MiniGames plugin is reloaded
*/
SUCCESS_PLUGIN_RELOADED,
/**
* The message displayed if a new arena has been created
*/
SUCCESS_ARENA_CREATED,
/**
* The message displayed if a player clears/wins an arena for the first time
*/
SUCCESS_ARENA_FIRST_CLEAR,
/**
* The message displayed when a player wins an arena
*/
SUCCESS_ARENA_WIN,
/**
* The message displayed when a player quits an arena
*/
SUCCESS_ARENA_QUIT,
/**
* The message used to display the current value of an arena property
*/
SUCCESS_CURRENT_VALUE,
/**
* The message used to announce that an arena property has been changed
*/
SUCCESS_PROPERTY_CHANGED,
/**
* The message displayed when two arenas' order in a group have been swapped
*/
SUCCESS_ARENAS_SWAPPED,
/**
* The message displayed when an arena has been removed
*/
SUCCESS_ARENA_REMOVED,
/**
* The header displayed before listing all dropper arenas
*/
SUCCESS_DROPPER_ARENAS_LIST,
/**
* The header displayed before listing all parkour arenas
*/
SUCCESS_PARKOUR_ARENAS_LIST,
/**
* The message displayed when a player reaches a new checkpoint in a parkour arena
*/
SUCCESS_CHECKPOINT_REACHED,
/**
* The header displayed before listing all arenas (stages) in a group
*/
SUCCESS_GROUP_STAGES,
/**
* The message displayed when a new record has been achieved
*/
SUCCESS_RECORD_ACHIEVED,
/**
* The partial message used to describe that the player achieved a world record
*/
RECORD_ACHIEVED_GLOBAL,
/**
* The partial message used to describe that the player achieved a personal best record
*/
RECORD_ACHIEVED_PERSONAL,
/**
* The message displayed when a player joins an arena
*/
SUCCESS_ARENA_JOINED,
;
@Override
public @NotNull TranslatableMessage[] getAllMessages() {
return MiniGameMessage.values();
}
}

View File

@ -1,41 +0,0 @@
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;
}
}

View File

@ -2,7 +2,7 @@ package net.knarcraft.minigames.listener;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaSession; import net.knarcraft.minigames.arena.ArenaSession;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -43,7 +43,7 @@ public class CommandListener implements Listener {
} }
} }
player.sendMessage(Message.ERROR_ILLEGAL_COMMAND.getMessage()); MiniGames.getInstance().getStringFormatter().displayErrorMessage(player, MiniGameMessage.ERROR_ILLEGAL_COMMAND);
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -46,8 +46,6 @@ public class InteractListener implements Listener {
ArenaGUI.getLeaveAction().run(event.getPlayer()); ArenaGUI.getLeaveAction().run(event.getPlayer());
} else if (persistentData == PersistentDataKey.GIVE_UP_ITEM.getDataValue()) { } else if (persistentData == PersistentDataKey.GIVE_UP_ITEM.getDataValue()) {
ParkourGUI.getGiveUpAction().run(event.getPlayer()); ParkourGUI.getGiveUpAction().run(event.getPlayer());
} else if (persistentData == PersistentDataKey.TOGGLE_PLAYERS_ITEM.getDataValue()) {
//TODO: Figure out how in the world this should be done, as the existing code cannot be re-used
} }
} }
} }

View File

@ -9,7 +9,7 @@ import net.knarcraft.minigames.arena.parkour.ParkourArena;
import net.knarcraft.minigames.arena.parkour.ParkourArenaGameMode; import net.knarcraft.minigames.arena.parkour.ParkourArenaGameMode;
import net.knarcraft.minigames.arena.parkour.ParkourArenaSession; import net.knarcraft.minigames.arena.parkour.ParkourArenaSession;
import net.knarcraft.minigames.config.DropperConfiguration; import net.knarcraft.minigames.config.DropperConfiguration;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import net.knarcraft.minigames.config.ParkourConfiguration; import net.knarcraft.minigames.config.ParkourConfiguration;
import net.knarcraft.minigames.config.SharedConfiguration; import net.knarcraft.minigames.config.SharedConfiguration;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -121,7 +121,8 @@ public class MoveListener implements Listener {
// Register the checkpoint // Register the checkpoint
arenaSession.registerCheckpoint(checkpoint.clone()); arenaSession.registerCheckpoint(checkpoint.clone());
player.sendMessage(Message.SUCCESS_CHECKPOINT_REACHED.getMessage()); MiniGames.getInstance().getStringFormatter().displaySuccessMessage(player,
MiniGameMessage.SUCCESS_CHECKPOINT_REACHED);
return; return;
} }
} }

View File

@ -8,7 +8,6 @@ public enum PersistentDataKey {
MENU_ITEM("MiniGamesMenu", 1799804), MENU_ITEM("MiniGamesMenu", 1799804),
LEAVE_ITEM("MiniGamesAction", 1799871), LEAVE_ITEM("MiniGamesAction", 1799871),
GIVE_UP_ITEM("MiniGamesAction", 1799872), GIVE_UP_ITEM("MiniGamesAction", 1799872),
TOGGLE_PLAYERS_ITEM("MiniGamesAction", 1799873),
; ;
private final String keyName; private final String keyName;

View File

@ -35,7 +35,7 @@ public final class ArenaStorageHelper {
try { try {
configuration.save(new File(MiniGames.getInstance().getDataFolder(), key + "EntryStates.yml")); configuration.save(new File(MiniGames.getInstance().getDataFolder(), key + "EntryStates.yml"));
} catch (IOException e) { } catch (IOException exception) {
MiniGames.log(Level.SEVERE, "Unable to save entry states to disk"); MiniGames.log(Level.SEVERE, "Unable to save entry states to disk");
} }
} }

View File

@ -1,29 +0,0 @@
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;
}
}

View File

@ -9,8 +9,7 @@ import net.knarcraft.minigames.arena.dropper.DropperArenaGameMode;
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup; import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
import net.knarcraft.minigames.arena.dropper.DropperArenaRecordsRegistry; import net.knarcraft.minigames.arena.dropper.DropperArenaRecordsRegistry;
import net.knarcraft.minigames.arena.dropper.DropperArenaStorageKey; import net.knarcraft.minigames.arena.dropper.DropperArenaStorageKey;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import net.knarcraft.minigames.container.PlaceholderContainer;
import net.knarcraft.minigames.container.SerializableMaterial; import net.knarcraft.minigames.container.SerializableMaterial;
import net.knarcraft.minigames.container.SerializableUUID; import net.knarcraft.minigames.container.SerializableUUID;
import org.bukkit.Location; import org.bukkit.Location;
@ -161,8 +160,9 @@ public final class DropperArenaStorageHelper {
DropperArenaStorageKey.WIN_BLOCK_TYPE.getKey()); DropperArenaStorageKey.WIN_BLOCK_TYPE.getKey());
if (arenaName == null || spawnLocation == null) { if (arenaName == null || spawnLocation == null) {
MiniGames.log(Level.SEVERE, Message.ERROR_ARENA_NOT_LOADED.getMessage(new PlaceholderContainer().add( MiniGames.log(Level.SEVERE, MiniGames.getInstance().getStringFormatter().replacePlaceholders(
"{section}", configurationSection.getName()).add("{file}", "dropper_arenas"))); MiniGameMessage.ERROR_ARENA_NOT_LOADED, new String[]{"{section}", "{file}"},
new String[]{configurationSection.getName(), "dropper_arenas"}));
return null; return null;
} }
if (winBlockType == null) { if (winBlockType == null) {
@ -172,8 +172,8 @@ public final class DropperArenaStorageHelper {
// Generate new, empty arena data if not available // Generate new, empty arena data if not available
DropperArenaData arenaData = loadDropperArenaData(arenaId); DropperArenaData arenaData = loadDropperArenaData(arenaId);
if (arenaData == null) { if (arenaData == null) {
MiniGames.log(Level.SEVERE, Message.ERROR_ARENA_DATA_NOT_LOADED.getMessage("{arena}", MiniGames.log(Level.SEVERE, MiniGames.getInstance().getStringFormatter().replacePlaceholder(
arenaId.toString())); MiniGameMessage.ERROR_ARENA_DATA_NOT_LOADED, "{arena}", arenaId.toString()));
arenaData = getEmptyDropperData(arenaId); arenaData = getEmptyDropperData(arenaId);
} }

View File

@ -1,77 +0,0 @@
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;
import org.bukkit.Tag;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* A helper class for dealing with and parsing materials
*/
public final class MaterialHelper {
private MaterialHelper() {
}
/**
* Loads the materials specified in the block whitelist
*/
public static @NotNull Set<Material> loadMaterialList(@NotNull List<?> materials) {
Set<Material> parsedMaterials = new HashSet<>();
for (Object value : materials) {
if (!(value instanceof String string)) {
continue;
}
// Try to parse a material tag first
if (parseMaterialTag(parsedMaterials, string)) {
continue;
}
// Try to parse a material name
Material matched = Material.matchMaterial(string);
if (matched != null) {
parsedMaterials.add(matched);
} else {
MiniGames.log(Level.WARNING, Message.ERROR_MATERIAL_NOT_PARSE_ABLE.getMessage("{material}", string));
}
}
return parsedMaterials;
}
/**
* Tries to parse the material tag in the specified material name
*
* @param targetSet <p>The set all parsed materials should be added to</p>
* @param materialName <p>The material name that might be a material tag</p>
* @return <p>True if a tag was found</p>
*/
private static boolean parseMaterialTag(@NotNull Set<Material> targetSet, @NotNull String materialName) {
Pattern pattern = Pattern.compile("^\\+([a-zA-Z_]+)");
Matcher matcher = pattern.matcher(materialName);
if (matcher.find()) {
// The material is a material tag
Tag<Material> tag = Bukkit.getTag(Tag.REGISTRY_BLOCKS, NamespacedKey.minecraft(
matcher.group(1).toLowerCase()), Material.class);
if (tag != null) {
targetSet.addAll(tag.getValues());
} else {
MiniGames.log(Level.WARNING, "Unable to parse: " + materialName);
}
return true;
}
return false;
}
}

View File

@ -9,8 +9,7 @@ import net.knarcraft.minigames.arena.parkour.ParkourArenaGameMode;
import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup; import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup;
import net.knarcraft.minigames.arena.parkour.ParkourArenaRecordsRegistry; import net.knarcraft.minigames.arena.parkour.ParkourArenaRecordsRegistry;
import net.knarcraft.minigames.arena.parkour.ParkourArenaStorageKey; import net.knarcraft.minigames.arena.parkour.ParkourArenaStorageKey;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import net.knarcraft.minigames.container.PlaceholderContainer;
import net.knarcraft.minigames.container.SerializableMaterial; import net.knarcraft.minigames.container.SerializableMaterial;
import net.knarcraft.minigames.container.SerializableUUID; import net.knarcraft.minigames.container.SerializableUUID;
import org.bukkit.Location; import org.bukkit.Location;
@ -166,8 +165,9 @@ public final class ParkourArenaStorageHelper {
// The arena name and spawn location must be present // The arena name and spawn location must be present
if (arenaName == null || spawnLocation == null) { if (arenaName == null || spawnLocation == null) {
MiniGames.log(Level.SEVERE, Message.ERROR_ARENA_NOT_LOADED.getMessage(new PlaceholderContainer().add( MiniGames.log(Level.SEVERE, MiniGames.getInstance().getStringFormatter().replacePlaceholders(
"{section}", configurationSection.getName()).add("{file}", "parkour_arena"))); MiniGameMessage.ERROR_ARENA_NOT_LOADED, new String[]{"{section}", "{file}"},
new String[]{configurationSection.getName(), "parkour_arena"}));
return null; return null;
} }
@ -179,8 +179,8 @@ public final class ParkourArenaStorageHelper {
// Generate new, empty arena data if not available // Generate new, empty arena data if not available
ParkourArenaData arenaData = loadParkourArenaData(arenaId); ParkourArenaData arenaData = loadParkourArenaData(arenaId);
if (arenaData == null) { if (arenaData == null) {
MiniGames.log(Level.SEVERE, Message.ERROR_ARENA_DATA_NOT_LOADED.getMessage("{arena}", MiniGames.log(Level.SEVERE, MiniGames.getInstance().getStringFormatter().replacePlaceholder(
arenaId.toString())); MiniGameMessage.ERROR_ARENA_DATA_NOT_LOADED, "{arena}", arenaId.toString()));
arenaData = getEmptyParkourData(arenaId); arenaData = getEmptyParkourData(arenaId);
} }

View File

@ -1,7 +1,7 @@
package net.knarcraft.minigames.util; package net.knarcraft.minigames.util;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.config.Message; import net.knarcraft.minigames.config.MiniGameMessage;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -36,7 +36,8 @@ public final class PlayerTeleporter {
passenger.teleport(location); passenger.teleport(location);
} }
} else { } else {
player.sendMessage(Message.ERROR_TELEPORT_WITH_PASSENGER.getMessage()); MiniGames.getInstance().getStringFormatter().displayErrorMessage(player,
MiniGameMessage.ERROR_TELEPORT_WITH_PASSENGER);
return false; return false;
} }
} }
@ -46,7 +47,8 @@ public final class PlayerTeleporter {
player.eject(); player.eject();
vehicle.teleport(location); vehicle.teleport(location);
} else { } else {
player.sendMessage(Message.ERROR_TELEPORT_IN_VEHICLE.getMessage()); MiniGames.getInstance().getStringFormatter().displayErrorMessage(player,
MiniGameMessage.ERROR_TELEPORT_IN_VEHICLE);
return false; return false;
} }
} }

View File

@ -1,4 +1,7 @@
# Configuration values for mini-games # Configuration values for mini-games
# The chosen language for Launchpad. You can use "en" or any custom language specified in strings.yml
language: en
parkour: parkour:
# Whether to enforce the order in which a player must reach checkpoints. Enabling this ensures that a player cannot # Whether to enforce the order in which a player must reach checkpoints. Enabling this ensures that a player cannot
# trigger a previous checkpoint by accident. It also ensures players cannot skip a checkpoint, even if the arena # trigger a previous checkpoint by accident. It also ensures players cannot skip a checkpoint, even if the arena

View File

@ -0,0 +1,43 @@
en:
ERROR_CANNOT_SAVE_ARENA_GROUPS: "Unable to save current arena groups! Data loss can occur!"
ERROR_MATERIAL_NOT_PARSE_ABLE: "Unable to parse material: {material}"
ERROR_TELEPORT_WITH_PASSENGER: "You cannot be teleported with a passenger!"
ERROR_TELEPORT_IN_VEHICLE: "You cannot be teleported while in a vehicle"
ERROR_ARENA_NOT_LOADED: "Could not load the arena at configuration section {section}. Please check the {file} storage file for issues."
ERROR_ARENA_DATA_NOT_LOADED: "Unable to load arena data for dropper arena: {arena}"
ERROR_ARENA_NOT_FOUND: "Unable to find the specified arena."
ERROR_GROUP_NOT_FOUND: "Unable to find the specified group!"
ERROR_PLAYER_ONLY: "This command must be used by a player"
ERROR_ARENA_NAME_COLLISION: "There already exists an arena with that name!"
ERROR_NORMAL_MODE_REQUIRED: "You must complete this arena in normal mode first!"
ERROR_GROUP_NORMAL_MODE_REQUIRED: "You have not yet beaten the default game-mode for all arenas in this group!"
ERROR_PREVIOUS_ARENA_REQUIRED: "You have not yet beaten the previous arena!"
ERROR_ARENA_TELEPORT_FAILED: "Unable to teleport you to the arena."
ERROR_NOT_IN_ARENA: "You are not in a mini-games arena!"
ERROR_ALREADY_PLAYING: "You are already playing a mini-game!"
ERROR_JOIN_IN_VEHICLE_OR_PASSENGER: "You cannot join an arena while inside a vehicle or carrying a passenger."
ERROR_UNKNOWN_PROPERTY: "Unknown property specified."
ERROR_PROPERTY_INPUT_INVALID: "Unable to change the property. Make sure your input is valid!"
ERROR_ARENA_1_NOT_FOUND: "Unable to find the first specified arena."
ERROR_ARENA_2_NOT_FOUND: "Unable to find the second specified dropper arena."
ERROR_SWAP_DIFFERENT_GROUPS: "You cannot swap arenas in different groups!"
ERROR_ILLEGAL_COMMAND: "You cannot use that command while in an arena!"
ERROR_HARDCORE_NO_CHECKPOINTS: "This arena cannot be played in hardcore mode as it has no checkpoints!"
SUCCESS_ARENA_GROUP_UPDATED: "The arena's group has been updated"
SUCCESS_PLUGIN_RELOADED: "Plugin reloaded!"
SUCCESS_ARENA_CREATED: "The arena was successfully created!"
SUCCESS_ARENA_FIRST_CLEAR: "You cleared the arena!"
SUCCESS_ARENA_WIN: "You won!"
SUCCESS_ARENA_QUIT: "You quit the arena!"
SUCCESS_CURRENT_VALUE: "Current value of {property} is: {value}"
SUCCESS_PROPERTY_CHANGED: "Property {property} successfully changed"
SUCCESS_ARENAS_SWAPPED: "The arenas have been swapped!"
SUCCESS_ARENA_REMOVED: "The specified arena has been successfully removed"
SUCCESS_DROPPER_ARENAS_LIST: "Dropper arenas:&r"
SUCCESS_PARKOUR_ARENAS_LIST: "Parkour arenas:&r"
SUCCESS_CHECKPOINT_REACHED: "Checkpoint reached!"
SUCCESS_GROUP_STAGES: "{group}'s stages:&r"
SUCCESS_RECORD_ACHIEVED: "You just set a {recordInfo} on the {gameMode} game-mode!"
RECORD_ACHIEVED_GLOBAL: "new {recordType} record"
RECORD_ACHIEVED_PERSONAL: "personal {recordType} record"
SUCCESS_ARENA_JOINED: "You joined the arena."