Changes things for the non-static Translator
This commit is contained in:
parent
bb63fb59d1
commit
a9c97f71f9
@ -2,6 +2,7 @@ package net.knarcraft.paidsigns;
|
|||||||
|
|
||||||
import net.knarcraft.knarlib.KnarLib;
|
import net.knarcraft.knarlib.KnarLib;
|
||||||
import net.knarcraft.knarlib.formatting.Translator;
|
import net.knarcraft.knarlib.formatting.Translator;
|
||||||
|
import net.knarcraft.knarlib.util.UpdateChecker;
|
||||||
import net.knarcraft.paidsigns.command.AddCommand;
|
import net.knarcraft.paidsigns.command.AddCommand;
|
||||||
import net.knarcraft.paidsigns.command.AddConditionCommand;
|
import net.knarcraft.paidsigns.command.AddConditionCommand;
|
||||||
import net.knarcraft.paidsigns.command.AddConditionTabCompleter;
|
import net.knarcraft.paidsigns.command.AddConditionTabCompleter;
|
||||||
@ -38,6 +39,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
public final class PaidSigns extends JavaPlugin {
|
public final class PaidSigns extends JavaPlugin {
|
||||||
|
|
||||||
private static PaidSigns paidSigns;
|
private static PaidSigns paidSigns;
|
||||||
|
private static Translator translator;
|
||||||
private PaidSignManager signManager;
|
private PaidSignManager signManager;
|
||||||
private String language;
|
private String language;
|
||||||
private boolean ignoreCase;
|
private boolean ignoreCase;
|
||||||
@ -63,6 +65,15 @@ public final class PaidSigns extends JavaPlugin {
|
|||||||
return paidSigns;
|
return paidSigns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the translator to use for this plugin
|
||||||
|
*
|
||||||
|
* @return <p>The translator to use for this plugin</p>
|
||||||
|
*/
|
||||||
|
public static Translator getTranslator() {
|
||||||
|
return translator;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
KnarLib.setPlugin(this);
|
KnarLib.setPlugin(this);
|
||||||
@ -71,8 +82,9 @@ public final class PaidSigns extends JavaPlugin {
|
|||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
//Initialize translator
|
//Initialize translator
|
||||||
Translator.registerMessageCategory(PaidSignsTranslatableMessage.BOOLEAN_TRUE);
|
translator = new Translator();
|
||||||
Translator.loadLanguages(language);
|
translator.registerMessageCategory(PaidSignsTranslatableMessage.BOOLEAN_TRUE);
|
||||||
|
translator.loadLanguages(language);
|
||||||
|
|
||||||
signManager = new PaidSignManager(PaidSignManager.loadSigns());
|
signManager = new PaidSignManager(PaidSignManager.loadSigns());
|
||||||
TrackedSignManager.loadTrackedSigns();
|
TrackedSignManager.loadTrackedSigns();
|
||||||
@ -82,6 +94,9 @@ public final class PaidSigns extends JavaPlugin {
|
|||||||
pluginManager.registerEvents(new SignBreakListener(), this);
|
pluginManager.registerEvents(new SignBreakListener(), this);
|
||||||
|
|
||||||
registerCommands();
|
registerCommands();
|
||||||
|
|
||||||
|
UpdateChecker.checkForUpdate(this, "https://api.spigotmc.org/legacy/update.php?resource=105842",
|
||||||
|
() -> this.getDescription().getVersion(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -94,7 +109,7 @@ public final class PaidSigns extends JavaPlugin {
|
|||||||
public void reload() {
|
public void reload() {
|
||||||
this.reloadConfig();
|
this.reloadConfig();
|
||||||
loadConfig();
|
loadConfig();
|
||||||
Translator.loadLanguages(language);
|
translator.loadLanguages(language);
|
||||||
signManager = new PaidSignManager(PaidSignManager.loadSigns());
|
signManager = new PaidSignManager(PaidSignManager.loadSigns());
|
||||||
TrackedSignManager.loadTrackedSigns();
|
TrackedSignManager.loadTrackedSigns();
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,8 @@ public class AddCommand extends TokenizedCommand {
|
|||||||
try {
|
try {
|
||||||
cost = Double.parseDouble(arguments.get(1));
|
cost = Double.parseDouble(arguments.get(1));
|
||||||
} catch (NumberFormatException exception) {
|
} catch (NumberFormatException exception) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String permission = "";
|
String permission = "";
|
||||||
@ -71,17 +72,20 @@ public class AddCommand extends TokenizedCommand {
|
|||||||
try {
|
try {
|
||||||
PaidSign sign = new PaidSign(signName, cost, permission, ignoreCase, ignoreColor, matchAnyCondition);
|
PaidSign sign = new PaidSign(signName, cost, permission, ignoreCase, ignoreColor, matchAnyCondition);
|
||||||
if (manager.getPaidSign(signName) != null) {
|
if (manager.getPaidSign(signName) != null) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_NAME_DUPLICATE);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_NAME_DUPLICATE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
manager.addPaidSign(sign);
|
manager.addPaidSign(sign);
|
||||||
StringFormatter.displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_ADDED_PAID_SIGN);
|
StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.SUCCESS_ADDED_PAID_SIGN);
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
|
||||||
return false;
|
return false;
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
StringFormatter.displayErrorMessage(sender, StringFormatter.replacePlaceholder(
|
StringFormatter.displayErrorMessage(sender, StringFormatter.replacePlaceholder(PaidSigns.getTranslator(),
|
||||||
PaidSignsTranslatableMessage.ERROR_INVALID_INPUT, "{input}", e.getMessage()));
|
PaidSignsTranslatableMessage.ERROR_INVALID_INPUT, "{input}", e.getMessage()));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -30,11 +30,13 @@ public class AddConditionCommand extends TokenizedCommand {
|
|||||||
try {
|
try {
|
||||||
lineNumber = (short) (Short.parseShort(arguments.get(1)) - 1);
|
lineNumber = (short) (Short.parseShort(arguments.get(1)) - 1);
|
||||||
if (lineNumber < 0 || lineNumber > 3) {
|
if (lineNumber < 0 || lineNumber > 3) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException exception) {
|
} catch (NumberFormatException exception) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String stringToMatch = arguments.get(2);
|
String stringToMatch = arguments.get(2);
|
||||||
@ -73,17 +75,20 @@ public class AddConditionCommand extends TokenizedCommand {
|
|||||||
PaidSignManager signManager = PaidSigns.getInstance().getSignManager();
|
PaidSignManager signManager = PaidSigns.getInstance().getSignManager();
|
||||||
PaidSign sign = signManager.getPaidSign(name);
|
PaidSign sign = signManager.getPaidSign(name);
|
||||||
if (sign == null) {
|
if (sign == null) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
sign.addCondition(lineNumber, stringToMatch, executeRegEx, ignoreCase, ignoreColor);
|
sign.addCondition(lineNumber, stringToMatch, executeRegEx, ignoreCase, ignoreColor);
|
||||||
try {
|
try {
|
||||||
signManager.saveSigns();
|
signManager.saveSigns();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
StringFormatter.displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_ADDED_PAID_SIGN_CONDITION);
|
StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.SUCCESS_ADDED_PAID_SIGN_CONDITION);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,8 @@ public class EditCommand extends TokenizedCommand {
|
|||||||
|
|
||||||
PaidSign sign = PaidSigns.getInstance().getSignManager().getPaidSign(arguments.get(0));
|
PaidSign sign = PaidSigns.getInstance().getSignManager().getPaidSign(arguments.get(0));
|
||||||
if (sign == null) {
|
if (sign == null) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +45,8 @@ public class EditCommand extends TokenizedCommand {
|
|||||||
return parseGivenProperty(sign, sender);
|
return parseGivenProperty(sign, sender);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,7 +63,8 @@ public class EditCommand extends TokenizedCommand {
|
|||||||
@NotNull CommandSender sender) throws NumberFormatException {
|
@NotNull CommandSender sender) throws NumberFormatException {
|
||||||
short signLine = (short) (Short.parseShort(arguments.get(1)) - 1);
|
short signLine = (short) (Short.parseShort(arguments.get(1)) - 1);
|
||||||
if (signLine < 0 || signLine > 3 || sign.getConditions().get(signLine) == null) {
|
if (signLine < 0 || signLine > 3 || sign.getConditions().get(signLine) == null) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_NO_SUCH_CONDITION);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_NO_SUCH_CONDITION);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (argumentSize < 4) {
|
if (argumentSize < 4) {
|
||||||
@ -70,7 +73,8 @@ public class EditCommand extends TokenizedCommand {
|
|||||||
|
|
||||||
PaidSignConditionProperty conditionProperty = PaidSignConditionProperty.getFromString(arguments.get(2));
|
PaidSignConditionProperty conditionProperty = PaidSignConditionProperty.getFromString(arguments.get(2));
|
||||||
if (conditionProperty == null) {
|
if (conditionProperty == null) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_PROPERTY_NOT_RECOGNIZED);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_PROPERTY_NOT_RECOGNIZED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String value = arguments.get(3);
|
String value = arguments.get(3);
|
||||||
@ -89,7 +93,8 @@ public class EditCommand extends TokenizedCommand {
|
|||||||
@NotNull CommandSender sender) throws IOException {
|
@NotNull CommandSender sender) throws IOException {
|
||||||
PaidSignProperty property = PaidSignProperty.getFromString(arguments.get(1));
|
PaidSignProperty property = PaidSignProperty.getFromString(arguments.get(1));
|
||||||
if (property == null) {
|
if (property == null) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_PROPERTY_NOT_RECOGNIZED);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_PROPERTY_NOT_RECOGNIZED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String value = arguments.get(2);
|
String value = arguments.get(2);
|
||||||
@ -97,7 +102,8 @@ public class EditCommand extends TokenizedCommand {
|
|||||||
updateProperty(sender, sign, property, value);
|
updateProperty(sender, sign, property, value);
|
||||||
return true;
|
return true;
|
||||||
} catch (NumberFormatException exception) {
|
} catch (NumberFormatException exception) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,7 +141,8 @@ public class EditCommand extends TokenizedCommand {
|
|||||||
manager.removePaidSign(sign.getName());
|
manager.removePaidSign(sign.getName());
|
||||||
manager.addPaidSign(updatedSign);
|
manager.addPaidSign(updatedSign);
|
||||||
|
|
||||||
StringFormatter.displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_UPDATED_PAID_SIGN);
|
StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.SUCCESS_UPDATED_PAID_SIGN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -171,11 +178,13 @@ public class EditCommand extends TokenizedCommand {
|
|||||||
try {
|
try {
|
||||||
PaidSigns.getInstance().getSignManager().saveSigns();
|
PaidSigns.getInstance().getSignManager().saveSigns();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringFormatter.displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_UPDATED_PAID_SIGN_CONDITION);
|
StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.SUCCESS_UPDATED_PAID_SIGN_CONDITION);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package net.knarcraft.paidsigns.command;
|
package net.knarcraft.paidsigns.command;
|
||||||
|
|
||||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||||
import net.knarcraft.knarlib.formatting.Translator;
|
|
||||||
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;
|
||||||
@ -55,7 +54,7 @@ public class ListCommand extends TokenizedCommand {
|
|||||||
Set<String> signNames = PaidSigns.getInstance().getSignManager().getAllPaidSigns().keySet();
|
Set<String> signNames = PaidSigns.getInstance().getSignManager().getAllPaidSigns().keySet();
|
||||||
List<String> signNameList = new ArrayList<>(signNames);
|
List<String> signNameList = new ArrayList<>(signNames);
|
||||||
Collections.sort(signNameList);
|
Collections.sort(signNameList);
|
||||||
String infoFormat = Translator.getTranslatedMessage(PaidSignsTranslatableMessage.PAID_SIGNS_INFO_FORMAT);
|
String infoFormat = PaidSigns.getTranslator().getTranslatedMessage(PaidSignsTranslatableMessage.PAID_SIGNS_INFO_FORMAT);
|
||||||
|
|
||||||
//Display up to 10 signs per page
|
//Display up to 10 signs per page
|
||||||
int signsPerPage = 7;
|
int signsPerPage = 7;
|
||||||
@ -72,11 +71,11 @@ public class ListCommand extends TokenizedCommand {
|
|||||||
boolean hasNextPage = alreadyDisplayed + signsPerPage < signNameList.size();
|
boolean hasNextPage = alreadyDisplayed + signsPerPage < signNameList.size();
|
||||||
String nextPagePrompt = "";
|
String nextPagePrompt = "";
|
||||||
if (hasNextPage) {
|
if (hasNextPage) {
|
||||||
nextPagePrompt = replacePlaceholder(Translator.getTranslatedMessage(
|
nextPagePrompt = replacePlaceholder(PaidSigns.getTranslator().getTranslatedMessage(
|
||||||
PaidSignsTranslatableMessage.PAID_SIGNS_NEXT_PROMPT), "{nextPage}", String.valueOf((pageNumber + 2)));
|
PaidSignsTranslatableMessage.PAID_SIGNS_NEXT_PROMPT), "{nextPage}", String.valueOf((pageNumber + 2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(StringFormatter.replacePlaceholders(Translator.getTranslatedMessage(
|
sender.sendMessage(StringFormatter.replacePlaceholders(PaidSigns.getTranslator().getTranslatedMessage(
|
||||||
PaidSignsTranslatableMessage.PAID_SIGNS_INFO), new String[]{"{signs}", "{nextPagePrompt}"},
|
PaidSignsTranslatableMessage.PAID_SIGNS_INFO), new String[]{"{signs}", "{nextPagePrompt}"},
|
||||||
new String[]{signs.toString(), nextPagePrompt}));
|
new String[]{signs.toString(), nextPagePrompt}));
|
||||||
}
|
}
|
||||||
@ -90,7 +89,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) {
|
||||||
displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND);
|
displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (argumentSize < 2) {
|
if (argumentSize < 2) {
|
||||||
@ -100,16 +99,18 @@ public class ListCommand extends TokenizedCommand {
|
|||||||
try {
|
try {
|
||||||
lineNumber = (short) (Short.parseShort(arguments.get(1)) - 1);
|
lineNumber = (short) (Short.parseShort(arguments.get(1)) - 1);
|
||||||
if (lineNumber < 0 || lineNumber > 3) {
|
if (lineNumber < 0 || lineNumber > 3) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException exception) {
|
} catch (NumberFormatException exception) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!paidSign.getConditions().containsKey(lineNumber)) {
|
if (!paidSign.getConditions().containsKey(lineNumber)) {
|
||||||
StringFormatter.displayErrorMessage(sender, replacePlaceholder(PaidSignsTranslatableMessage.ERROR_NO_SUCH_CONDITION,
|
StringFormatter.displayErrorMessage(sender, replacePlaceholder(PaidSigns.getTranslator(),
|
||||||
"{line}", String.valueOf(lineNumber)));
|
PaidSignsTranslatableMessage.ERROR_NO_SUCH_CONDITION, "{line}", String.valueOf(lineNumber)));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PaidSignCondition condition = paidSign.getConditions().get(lineNumber);
|
PaidSignCondition condition = paidSign.getConditions().get(lineNumber);
|
||||||
@ -128,11 +129,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(StringFormatter.replacePlaceholders(PaidSignsTranslatableMessage.PAID_SIGN_CONDITION_INFO,
|
sender.sendMessage(StringFormatter.replacePlaceholders(PaidSigns.getTranslator(),
|
||||||
new String[]{"{name}", "{line}", "{match}", "{regex}", "{case}", "{color}"},
|
PaidSignsTranslatableMessage.PAID_SIGN_CONDITION_INFO, new String[]{"{name}", "{line}", "{match}",
|
||||||
new String[]{signName, String.valueOf(signLine + 1), condition.stringToMatch(),
|
"{regex}", "{case}", "{color}"}, new String[]{signName, String.valueOf(signLine + 1),
|
||||||
translateBoolean(condition.executeRegex()), translateBoolean(condition.ignoreCase()),
|
condition.stringToMatch(), translateBoolean(condition.executeRegex()),
|
||||||
translateBoolean(condition.ignoreColor())}));
|
translateBoolean(condition.ignoreCase()), translateBoolean(condition.ignoreColor())}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -145,12 +146,13 @@ public class ListCommand extends TokenizedCommand {
|
|||||||
Map<Short, PaidSignCondition> signConditions = paidSign.getConditions();
|
Map<Short, PaidSignCondition> signConditions = paidSign.getConditions();
|
||||||
StringBuilder conditions = new StringBuilder();
|
StringBuilder conditions = new StringBuilder();
|
||||||
for (short lineIndex : signConditions.keySet()) {
|
for (short lineIndex : signConditions.keySet()) {
|
||||||
String format = Translator.getTranslatedMessage(PaidSignsTranslatableMessage.PAID_SIGN_INFO_CONDITION_FORMAT);
|
String format = PaidSigns.getTranslator().getTranslatedMessage(
|
||||||
|
PaidSignsTranslatableMessage.PAID_SIGN_INFO_CONDITION_FORMAT);
|
||||||
conditions.append(StringFormatter.replacePlaceholders(format, new String[]{"{line}", "{condition}"},
|
conditions.append(StringFormatter.replacePlaceholders(format, new String[]{"{line}", "{condition}"},
|
||||||
new String[]{String.valueOf((lineIndex + 1)), signConditions.get(lineIndex).stringToMatch()}));
|
new String[]{String.valueOf((lineIndex + 1)), signConditions.get(lineIndex).stringToMatch()}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(replacePlaceholders(Translator.getTranslatedMessage(
|
sender.sendMessage(replacePlaceholders(PaidSigns.getTranslator().getTranslatedMessage(
|
||||||
PaidSignsTranslatableMessage.PAID_SIGN_INFO), new String[]{"{name}", "{cost}", "{permission}", "{case}",
|
PaidSignsTranslatableMessage.PAID_SIGN_INFO), new String[]{"{name}", "{cost}", "{permission}", "{case}",
|
||||||
"{color}", "{any}", "{conditions}"}, new String[]{paidSign.getName(), String.valueOf(paidSign.getCost()),
|
"{color}", "{any}", "{conditions}"}, new String[]{paidSign.getName(), String.valueOf(paidSign.getCost()),
|
||||||
paidSign.getPermission(), translateBoolean(paidSign.getIgnoreCase()),
|
paidSign.getPermission(), translateBoolean(paidSign.getIgnoreCase()),
|
||||||
@ -166,9 +168,9 @@ public class ListCommand extends TokenizedCommand {
|
|||||||
*/
|
*/
|
||||||
public static String translateBoolean(boolean booleanValue) {
|
public static String translateBoolean(boolean booleanValue) {
|
||||||
if (booleanValue) {
|
if (booleanValue) {
|
||||||
return Translator.getTranslatedMessage(PaidSignsTranslatableMessage.BOOLEAN_TRUE);
|
return PaidSigns.getTranslator().getTranslatedMessage(PaidSignsTranslatableMessage.BOOLEAN_TRUE);
|
||||||
} else {
|
} else {
|
||||||
return Translator.getTranslatedMessage(PaidSignsTranslatableMessage.BOOLEAN_FALSE);
|
return PaidSigns.getTranslator().getTranslatedMessage(PaidSignsTranslatableMessage.BOOLEAN_FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,8 @@ public class ReloadTabCommand implements TabExecutor {
|
|||||||
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[] args) {
|
@NotNull String[] args) {
|
||||||
PaidSigns.getInstance().reload();
|
PaidSigns.getInstance().reload();
|
||||||
StringFormatter.displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_RELOADED);
|
StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.SUCCESS_RELOADED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,22 +28,25 @@ public class RemoveConditionCommand extends TokenizedCommand {
|
|||||||
try {
|
try {
|
||||||
lineNumber = (short) (Short.parseShort(arguments.get(1)) - 1);
|
lineNumber = (short) (Short.parseShort(arguments.get(1)) - 1);
|
||||||
if (lineNumber < 0 || lineNumber > 3) {
|
if (lineNumber < 0 || lineNumber > 3) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException exception) {
|
} catch (NumberFormatException exception) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PaidSignManager signManager = PaidSigns.getInstance().getSignManager();
|
PaidSignManager signManager = PaidSigns.getInstance().getSignManager();
|
||||||
PaidSign sign = signManager.getPaidSign(name);
|
PaidSign sign = signManager.getPaidSign(name);
|
||||||
if (sign == null) {
|
if (sign == null) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sign.getConditions().containsKey(lineNumber)) {
|
if (!sign.getConditions().containsKey(lineNumber)) {
|
||||||
StringFormatter.displayErrorMessage(sender, StringFormatter.replacePlaceholder(
|
StringFormatter.displayErrorMessage(sender, StringFormatter.replacePlaceholder(PaidSigns.getTranslator(),
|
||||||
PaidSignsTranslatableMessage.ERROR_NO_SUCH_CONDITION, "{line}",
|
PaidSignsTranslatableMessage.ERROR_NO_SUCH_CONDITION, "{line}",
|
||||||
String.valueOf((lineNumber + 1))));
|
String.valueOf((lineNumber + 1))));
|
||||||
return false;
|
return false;
|
||||||
@ -53,10 +56,12 @@ public class RemoveConditionCommand extends TokenizedCommand {
|
|||||||
try {
|
try {
|
||||||
signManager.saveSigns();
|
signManager.saveSigns();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
StringFormatter.displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_REMOVED_CONDITION);
|
StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.SUCCESS_REMOVED_CONDITION);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,13 +31,16 @@ public class RemoveTabCommand implements TabExecutor {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (PaidSigns.getInstance().getSignManager().removePaidSign(name)) {
|
if (PaidSigns.getInstance().getSignManager().removePaidSign(name)) {
|
||||||
StringFormatter.displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_REMOVED_PAID_SIGN);
|
StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.SUCCESS_REMOVED_PAID_SIGN);
|
||||||
} else {
|
} else {
|
||||||
StringFormatter.displaySuccessMessage(sender, PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND);
|
StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.knarcraft.paidsigns.command;
|
package net.knarcraft.paidsigns.command;
|
||||||
|
|
||||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||||
|
import net.knarcraft.paidsigns.PaidSigns;
|
||||||
import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage;
|
import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage;
|
||||||
import net.knarcraft.paidsigns.utility.Tokenizer;
|
import net.knarcraft.paidsigns.utility.Tokenizer;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -39,7 +40,8 @@ public class TokenizedCommand implements CommandExecutor {
|
|||||||
Pattern.compile(regularExpression);
|
Pattern.compile(regularExpression);
|
||||||
return false;
|
return false;
|
||||||
} catch (PatternSyntaxException exception) {
|
} catch (PatternSyntaxException exception) {
|
||||||
StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_REGULAR_EXPRESSION);
|
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(),
|
||||||
|
PaidSignsTranslatableMessage.ERROR_INVALID_REGULAR_EXPRESSION);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,8 +151,8 @@ public class SignListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
private String replaceCost(double cost, TranslatableMessage message) {
|
private String replaceCost(double cost, TranslatableMessage message) {
|
||||||
String unit = EconomyManager.getCurrency(cost != 1);
|
String unit = EconomyManager.getCurrency(cost != 1);
|
||||||
return String.format(StringFormatter.replacePlaceholders(message, new String[]{"{cost}", "{unit}"},
|
return String.format(StringFormatter.replacePlaceholders(PaidSigns.getTranslator(), message,
|
||||||
new String[]{"%.2f", "%s"}), cost, unit);
|
new String[]{"{cost}", "{unit}"}, new String[]{"%.2f", "%s"}), cost, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -156,8 +156,9 @@ public final class TrackedSignManager {
|
|||||||
EconomyManager.deposit(offlinePlayer, refundSum);
|
EconomyManager.deposit(offlinePlayer, refundSum);
|
||||||
if (offlinePlayer instanceof Player player) {
|
if (offlinePlayer instanceof Player player) {
|
||||||
StringFormatter.displaySuccessMessage(player, String.format(StringFormatter.replacePlaceholders(
|
StringFormatter.displaySuccessMessage(player, String.format(StringFormatter.replacePlaceholders(
|
||||||
PaidSignsTranslatableMessage.SUCCESS_REFUNDED, new String[]{"{cost}", "{unit}"},
|
PaidSigns.getTranslator(), PaidSignsTranslatableMessage.SUCCESS_REFUNDED,
|
||||||
new String[]{"%.2f", "%s"}), refundSum, EconomyManager.getCurrency(refundSum != 1)));
|
new String[]{"{cost}", "{unit}"}, new String[]{"%.2f", "%s"}), refundSum,
|
||||||
|
EconomyManager.getCurrency(refundSum != 1)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user