Translates the list command's messages
This commit is contained in:
parent
30bca7b8f1
commit
4602ca71db
@ -3,12 +3,20 @@ package net.knarcraft.paidsigns.command;
|
|||||||
import net.knarcraft.paidsigns.PaidSigns;
|
import net.knarcraft.paidsigns.PaidSigns;
|
||||||
import net.knarcraft.paidsigns.container.PaidSign;
|
import net.knarcraft.paidsigns.container.PaidSign;
|
||||||
import net.knarcraft.paidsigns.container.PaidSignCondition;
|
import net.knarcraft.paidsigns.container.PaidSignCondition;
|
||||||
|
import net.knarcraft.paidsigns.formatting.StringFormatter;
|
||||||
|
import net.knarcraft.paidsigns.formatting.TranslatableMessage;
|
||||||
|
import net.knarcraft.paidsigns.formatting.Translator;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static net.knarcraft.paidsigns.formatting.StringFormatter.getTranslatedErrorMessage;
|
||||||
|
import static net.knarcraft.paidsigns.formatting.StringFormatter.replacePlaceholder;
|
||||||
|
import static net.knarcraft.paidsigns.formatting.StringFormatter.replacePlaceholders;
|
||||||
|
import static net.knarcraft.paidsigns.formatting.StringFormatter.translateBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A representation of the command for listing information about paid signs
|
* A representation of the command for listing information about paid signs
|
||||||
*/
|
*/
|
||||||
@ -19,10 +27,7 @@ public class ListCommand extends TokenizedCommand {
|
|||||||
@NotNull String[] args) {
|
@NotNull String[] args) {
|
||||||
super.onCommand(sender, command, label, args);
|
super.onCommand(sender, command, label, args);
|
||||||
if (argumentSize < 1) {
|
if (argumentSize < 1) {
|
||||||
sender.sendMessage("Paid signs:");
|
displaySigns(sender);
|
||||||
for (String signName : PaidSigns.getInstance().getSignManager().getAllPaidSigns().keySet()) {
|
|
||||||
sender.sendMessage(" | " + signName);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
} else if (argumentSize < 3) {
|
} else if (argumentSize < 3) {
|
||||||
return parsePaidSignSelection(sender);
|
return parsePaidSignSelection(sender);
|
||||||
@ -30,6 +35,21 @@ public class ListCommand extends TokenizedCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays all available signs
|
||||||
|
*
|
||||||
|
* @param sender <p>The command sender to display the signs to</p>
|
||||||
|
*/
|
||||||
|
private void displaySigns(CommandSender sender) {
|
||||||
|
StringBuilder signs = new StringBuilder();
|
||||||
|
for (String signName : PaidSigns.getInstance().getSignManager().getAllPaidSigns().keySet()) {
|
||||||
|
signs.append(StringFormatter.replacePlaceholder(Translator.getTranslatedMessage(
|
||||||
|
TranslatableMessage.PAID_SIGNS_INFO_FORMAT), "{name}", signName));
|
||||||
|
}
|
||||||
|
sender.sendMessage(StringFormatter.replacePlaceholder(Translator.getTranslatedMessage(
|
||||||
|
TranslatableMessage.PAID_SIGNS_INFO), "{signs}", signs.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the given input and displays the wanted paid-sign information
|
* Parses the given input and displays the wanted paid-sign information
|
||||||
*
|
*
|
||||||
@ -39,7 +59,7 @@ public class ListCommand extends TokenizedCommand {
|
|||||||
private boolean parsePaidSignSelection(CommandSender sender) {
|
private boolean parsePaidSignSelection(CommandSender sender) {
|
||||||
PaidSign paidSign = PaidSigns.getInstance().getSignManager().getPaidSign(arguments.get(0));
|
PaidSign paidSign = PaidSigns.getInstance().getSignManager().getPaidSign(arguments.get(0));
|
||||||
if (paidSign == null) {
|
if (paidSign == null) {
|
||||||
sender.sendMessage("No such paid sign");
|
sender.sendMessage(getTranslatedErrorMessage(TranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (argumentSize < 2) {
|
if (argumentSize < 2) {
|
||||||
@ -49,11 +69,12 @@ public class ListCommand extends TokenizedCommand {
|
|||||||
try {
|
try {
|
||||||
signLine = (short) (Short.parseShort(arguments.get(1)) - 1);
|
signLine = (short) (Short.parseShort(arguments.get(1)) - 1);
|
||||||
} catch (NumberFormatException exception) {
|
} catch (NumberFormatException exception) {
|
||||||
sender.sendMessage("Invalid number given");
|
sender.sendMessage(getTranslatedErrorMessage(TranslatableMessage.ERROR_INVALID_NUMBER));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!paidSign.getConditions().containsKey(signLine)) {
|
if (!paidSign.getConditions().containsKey(signLine)) {
|
||||||
sender.sendMessage("The paid sign you specified has no condition for line " + signLine);
|
sender.sendMessage(replacePlaceholder(getTranslatedErrorMessage(
|
||||||
|
TranslatableMessage.ERROR_NO_SUCH_CONDITION), "{line}", String.valueOf(signLine)));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PaidSignCondition condition = paidSign.getConditions().get(signLine);
|
PaidSignCondition condition = paidSign.getConditions().get(signLine);
|
||||||
@ -72,13 +93,11 @@ public class ListCommand extends TokenizedCommand {
|
|||||||
*/
|
*/
|
||||||
private void displayPaidSignCondition(CommandSender sender, String signName, short signLine,
|
private void displayPaidSignCondition(CommandSender sender, String signName, short signLine,
|
||||||
PaidSignCondition condition) {
|
PaidSignCondition condition) {
|
||||||
sender.sendMessage("Paid sign condition info: ");
|
sender.sendMessage(StringFormatter.replacePlaceholders(Translator.getTranslatedMessage(
|
||||||
sender.sendMessage("Paid sign name: " + signName);
|
TranslatableMessage.PAID_SIGN_CONDITION_INFO), new String[]{"{name}", "{line}", "{match}", "{regex}",
|
||||||
sender.sendMessage("Condition line: " + signLine);
|
"{case}", "{color}"}, new String[]{signName, String.valueOf(signLine + 1), condition.getStringToMatch(),
|
||||||
sender.sendMessage("Condition match string: " + condition.getStringToMatch());
|
translateBoolean(condition.executeRegex()), translateBoolean(condition.ignoreCase()),
|
||||||
sender.sendMessage("Execute RegEx: " + condition.executeRegex());
|
translateBoolean(condition.ignoreColor())}));
|
||||||
sender.sendMessage("Ignore case: " + condition.ignoreCase());
|
|
||||||
sender.sendMessage("Ignore color: " + condition.ignoreColor());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,17 +107,19 @@ public class ListCommand extends TokenizedCommand {
|
|||||||
* @param paidSign <p>The paid sign to display information about</p>
|
* @param paidSign <p>The paid sign to display information about</p>
|
||||||
*/
|
*/
|
||||||
private void displayPaidSign(CommandSender sender, PaidSign paidSign) {
|
private void displayPaidSign(CommandSender sender, PaidSign paidSign) {
|
||||||
sender.sendMessage("Paid sign info:");
|
Map<Short, PaidSignCondition> signConditions = paidSign.getConditions();
|
||||||
sender.sendMessage("Name: " + paidSign.getName());
|
StringBuilder conditions = new StringBuilder();
|
||||||
sender.sendMessage("Cost: " + paidSign.getCost());
|
for (short lineIndex : signConditions.keySet()) {
|
||||||
sender.sendMessage("Permission: " + paidSign.getPermission());
|
String format = Translator.getTranslatedMessage(TranslatableMessage.PAID_SIGN_INFO_CONDITION_FORMAT);
|
||||||
sender.sendMessage("Ignore case: " + paidSign.getIgnoreCase());
|
conditions.append(StringFormatter.replacePlaceholders(format, new String[]{"{line}", "{condition}"},
|
||||||
sender.sendMessage("Ignore color: " + paidSign.getIgnoreColor());
|
new String[]{String.valueOf((lineIndex + 1)), signConditions.get(lineIndex).getStringToMatch()}));
|
||||||
sender.sendMessage("Sign conditions: ");
|
|
||||||
Map<Short, PaidSignCondition> conditions = paidSign.getConditions();
|
|
||||||
for (short lineIndex : conditions.keySet()) {
|
|
||||||
sender.sendMessage(" | " + (lineIndex + 1) + ". " + conditions.get(lineIndex).getStringToMatch());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(replacePlaceholders(Translator.getTranslatedMessage(
|
||||||
|
TranslatableMessage.PAID_SIGN_INFO), new String[]{"{name}", "{cost}", "{permission}", "{case}",
|
||||||
|
"{color}", "{conditions}"}, new String[]{paidSign.getName(), String.valueOf(paidSign.getCost()),
|
||||||
|
paidSign.getPermission(), translateBoolean(paidSign.getIgnoreCase()),
|
||||||
|
translateBoolean(paidSign.getIgnoreColor()), conditions.toString()}));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user