mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-11-22 18:16:11 +01:00
Hopefully convert everything over to the new format placeholders.
This commit is contained in:
parent
8bef764622
commit
e3a36ccd22
@ -51,7 +51,7 @@ public class BalanceCommand extends SaneEconomyCommand {
|
||||
playerName = args[0];
|
||||
|
||||
if (!sender.hasPermission("saneeconomy.balance.other")) {
|
||||
MessageUtils.sendMessage(sender, "You don't have permission to check the balance of {0}.", playerIdentifier);
|
||||
MessageUtils.sendMessage(sender, "You don't have permission to check the balance of {1}.", playerIdentifier);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -63,6 +63,6 @@ public class BalanceCommand extends SaneEconomyCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
MessageUtils.sendMessage(sender, "Balance for %s is %s.", playerName, saneEconomy.getEconomyManager().getFormattedBalance(Economable.wrap(player)));
|
||||
MessageUtils.sendMessage(sender, "Balance for {1} is {2}.", playerName, saneEconomy.getEconomyManager().getFormattedBalance(Economable.wrap(player)));
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class BalanceTopCommand extends SaneEconomyCommand {
|
||||
try {
|
||||
page = Math.abs(Integer.parseInt(args[0]));
|
||||
} catch (NumberFormatException e) {
|
||||
MessageUtils.sendMessage(sender, "%s is not a valid number.");
|
||||
MessageUtils.sendMessage(sender, "{1} is not a valid number.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -62,7 +62,7 @@ public class BalanceTopCommand extends SaneEconomyCommand {
|
||||
|
||||
AtomicInteger index = new AtomicInteger(offset + 1); /* I know it's stupid, but you can't do some_int++ from within the lambda. */
|
||||
|
||||
MessageUtils.sendMessage(sender, "Top %d players on page %d:", topBalances.size(), page);
|
||||
topBalances.forEach((player, balance) -> MessageUtils.sendMessage(sender, "[%02d] %s - %s", index.getAndIncrement(), player.getName(), SaneEconomy.getInstance().getEconomyManager().getCurrency().formatAmount(balance)));
|
||||
MessageUtils.sendMessage(sender, "Top {1} players on page {2}:", topBalances.size(), page);
|
||||
topBalances.forEach((player, balance) -> MessageUtils.sendMessage(sender, "[{1:02d}] {2} - {3}", index.getAndIncrement(), player.getName(), SaneEconomy.getInstance().getEconomyManager().getCurrency().formatAmount(balance)));
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,6 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import static org.appledash.saneeconomy.utils.I18n._;
|
||||
|
||||
/**
|
||||
* Created by AppleDash on 6/13/2016.
|
||||
* Blackjack is still best pony.
|
||||
@ -66,7 +64,7 @@ public class EconomyAdminCommand extends SaneEconomyCommand {
|
||||
OfflinePlayer targetPlayer = PlayerUtils.getOfflinePlayer(sTargetPlayer);
|
||||
|
||||
if (targetPlayer == null) {
|
||||
MessageUtils.sendMessage(sender, _("That player does not exist."));
|
||||
MessageUtils.sendMessage(sender, "That player does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -76,7 +74,7 @@ public class EconomyAdminCommand extends SaneEconomyCommand {
|
||||
double amount = NumberUtils.parseAndFilter(ecoMan.getCurrency(), sAmount);
|
||||
|
||||
if (amount <= 0) {
|
||||
MessageUtils.sendMessage(sender, _("%s is not a positive number."), ((amount == -1) ? sAmount : String.valueOf(amount)));
|
||||
MessageUtils.sendMessage(sender, "{1} is not a positive number.", ((amount == -1) ? sAmount : String.valueOf(amount)));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -86,7 +84,7 @@ public class EconomyAdminCommand extends SaneEconomyCommand {
|
||||
|
||||
double newAmount = result.getToBalance();
|
||||
|
||||
MessageUtils.sendMessage(sender, _("Added %s to %s. Their balance is now %s."),
|
||||
MessageUtils.sendMessage(sender, "Added {1} to {2}. Their balance is now {3}.",
|
||||
ecoMan.getCurrency().formatAmount(amount),
|
||||
sTargetPlayer,
|
||||
ecoMan.getCurrency().formatAmount(newAmount)
|
||||
@ -100,7 +98,7 @@ public class EconomyAdminCommand extends SaneEconomyCommand {
|
||||
|
||||
double newAmount = result.getFromBalance();
|
||||
|
||||
MessageUtils.sendMessage(sender, _("Took %s from %s. Their balance is now %s."),
|
||||
MessageUtils.sendMessage(sender, "Took {1} from {2}. Their balance is now {3}.",
|
||||
ecoMan.getCurrency().formatAmount(amount),
|
||||
sTargetPlayer,
|
||||
ecoMan.getCurrency().formatAmount(newAmount)
|
||||
@ -111,7 +109,7 @@ public class EconomyAdminCommand extends SaneEconomyCommand {
|
||||
if (subCommand.equalsIgnoreCase("set")) {
|
||||
double oldBal = ecoMan.getBalance(economable);
|
||||
ecoMan.setBalance(economable, amount);
|
||||
MessageUtils.sendMessage(sender, _("Balance for %s set to %s."), sTargetPlayer, ecoMan.getCurrency().formatAmount(amount));
|
||||
MessageUtils.sendMessage(sender, "Balance for {1} set to {2}.", sTargetPlayer, ecoMan.getCurrency().formatAmount(amount));
|
||||
|
||||
if (saneEconomy.shouldLogTransactions()) {
|
||||
// FIXME: This is a silly hack to get it to log.
|
||||
|
@ -69,7 +69,7 @@ public class PayCommand extends SaneEconomyCommand {
|
||||
double amount = NumberUtils.parseAndFilter(ecoMan.getCurrency(), sAmount);
|
||||
|
||||
if (amount <= 0) {
|
||||
MessageUtils.sendMessage(sender, "%s is not a positive number.", ((amount == -1) ? sAmount : String.valueOf(amount)));
|
||||
MessageUtils.sendMessage(sender, "{1} is not a positive number.", ((amount == -1) ? sAmount : String.valueOf(amount)));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ public class PayCommand extends SaneEconomyCommand {
|
||||
TransactionResult result = ecoMan.transact(transaction);
|
||||
|
||||
if (result.getStatus() != TransactionResult.Status.SUCCESS) {
|
||||
MessageUtils.sendMessage(sender, "You do not have enough money to transfer %s to %s.",
|
||||
MessageUtils.sendMessage(sender, "You do not have enough money to transfer {1} to {2}.",
|
||||
ecoMan.getCurrency().formatAmount(amount),
|
||||
sToPlayer
|
||||
);
|
||||
@ -88,12 +88,12 @@ public class PayCommand extends SaneEconomyCommand {
|
||||
|
||||
/* Inform the relevant parties. */
|
||||
|
||||
MessageUtils.sendMessage(sender, "You have transferred %s to %s.",
|
||||
MessageUtils.sendMessage(sender, "You have transferred {1} to {2}.",
|
||||
ecoMan.getCurrency().formatAmount(amount),
|
||||
sToPlayer
|
||||
);
|
||||
|
||||
MessageUtils.sendMessage(toPlayer, "You have received %s from %s.",
|
||||
MessageUtils.sendMessage(toPlayer, "You have received {1} from {2}.",
|
||||
ecoMan.getCurrency().formatAmount(amount),
|
||||
fromPlayer.getDisplayName()
|
||||
);
|
||||
|
@ -36,13 +36,13 @@ public class JoinQuitListener implements Listener {
|
||||
Economable.CONSOLE, economable, startBalance, TransactionReason.STARTING_BALANCE
|
||||
));
|
||||
if (plugin.getConfig().getBoolean("economy.notify-start-balance", true)) {
|
||||
MessageUtils.sendMessage(player, "You've been issued a starting balance of %s!", plugin.getEconomyManager().getCurrency().formatAmount(startBalance));
|
||||
MessageUtils.sendMessage(player, "You've been issued a starting balance of {1}!", plugin.getEconomyManager().getCurrency().formatAmount(startBalance));
|
||||
}
|
||||
}
|
||||
|
||||
/* Update notification */
|
||||
if (player.hasPermission("saneeconomy.update-notify") && plugin.getVersionChecker().isUpdateAvailable()) {
|
||||
MessageUtils.sendMessage(player, "An update is available! The currently-installed version is %s, but the newest available is %s. Please go to %s to update!", plugin.getDescription().getVersion(), plugin.getVersionChecker().getNewestVersion(), GithubVersionChecker.DOWNLOAD_URL);
|
||||
MessageUtils.sendMessage(player, "An update is available! The currently-installed version is {1}, but the newest available is {2}. Please go to %s to update!", plugin.getDescription().getVersion(), plugin.getVersionChecker().getNewestVersion(), GithubVersionChecker.DOWNLOAD_URL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.appledash.saneeconomy.utils;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import org.appledash.saneeconomy.SaneEconomy;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -38,7 +39,7 @@ public class MessageUtils {
|
||||
}
|
||||
|
||||
public static String indexedFormat(String fmt, Object... arguments) {
|
||||
Matcher m = Pattern.compile("\\{([0-9]+)\\}").matcher(fmt);
|
||||
Matcher m = Pattern.compile("\\{([0-9]+)(:[^}]+)?\\}").matcher(fmt);
|
||||
StringBuffer formatted = new StringBuffer();
|
||||
|
||||
while (m.find()) {
|
||||
@ -48,7 +49,15 @@ public class MessageUtils {
|
||||
throw new IllegalArgumentException("Index must be within the range of the given arguments.");
|
||||
}
|
||||
|
||||
m.appendReplacement(formatted, String.valueOf(arguments[index]));
|
||||
String stringRep;
|
||||
|
||||
if (!Strings.isNullOrEmpty(m.group(2))) {
|
||||
stringRep = String.format(String.format("%%%s", m.group(2).substring(1)), arguments[index]);
|
||||
} else {
|
||||
stringRep = String.valueOf(arguments[index]);
|
||||
}
|
||||
|
||||
m.appendReplacement(formatted, stringRep);
|
||||
}
|
||||
|
||||
m.appendTail(formatted);
|
||||
|
@ -17,6 +17,12 @@ public class MessageUtilsTest {
|
||||
Assert.assertEquals("Hello, world!", MessageUtils.indexedFormat("Hello, world!", "this", "shouldn't", "change"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdvancedIndexFormat() {
|
||||
Assert.assertEquals("Temperature: 20.01 degrees", MessageUtils.indexedFormat("Temperature: {1:.2f} degrees", 20.01f));
|
||||
Assert.assertEquals("Index: 01", MessageUtils.indexedFormat("Index: {1:02d}", 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testBadIndexedFormat() {
|
||||
MessageUtils.indexedFormat("Hello, {3}!", "world", "something");
|
||||
|
@ -85,14 +85,14 @@ public class InteractListener implements Listener {
|
||||
double price = shop.getBuyPrice(quantity);
|
||||
|
||||
if (!ecoMan.hasBalance(Economable.wrap(player), price)) {
|
||||
MessageUtils.sendMessage(player, String.format("You do not have enough money to buy %d %s.", quantity, shop.getItem()));
|
||||
MessageUtils.sendMessage(player, "You do not have enough money to buy {1} {2}.", quantity, shop.getItem());
|
||||
return;
|
||||
}
|
||||
|
||||
TransactionResult result = ecoMan.transact(new Transaction(Economable.wrap(player), Economable.PLUGIN, price, TransactionReason.PLUGIN_TAKE));
|
||||
|
||||
if (result.getStatus() != TransactionResult.Status.SUCCESS) {
|
||||
MessageUtils.sendMessage(player, String.format("An error occurred attempting to perform that transaction: %s", result.getStatus()));
|
||||
MessageUtils.sendMessage(player, "An error occurred attempting to perform that transaction: {1}", result.getStatus());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ public class InteractListener implements Listener {
|
||||
stack.setAmount(quantity);
|
||||
|
||||
player.getInventory().addItem(stack);
|
||||
MessageUtils.sendMessage(player, String.format("You have bought %d %s for %s.", quantity, shop.getItem(), ecoMan.getCurrency().formatAmount(price)));
|
||||
MessageUtils.sendMessage(player, "You have bought {1} {2} for {3}.", quantity, shop.getItem(), ecoMan.getCurrency().formatAmount(price));
|
||||
}
|
||||
|
||||
private void doSell(SignShop shop, Player player) { // TODO: Selling enchanted items
|
||||
@ -109,7 +109,7 @@ public class InteractListener implements Listener {
|
||||
double price = shop.getSellPrice(quantity);
|
||||
|
||||
if (!player.getInventory().containsAtLeast(new ItemStack(shop.getItem()), quantity)) {
|
||||
MessageUtils.sendMessage(player, String.format("You do not have %d %s!", quantity, shop.getItem()));
|
||||
MessageUtils.sendMessage(player, "You do not have {1} {2}!", quantity, shop.getItem());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -118,6 +118,6 @@ public class InteractListener implements Listener {
|
||||
|
||||
player.getInventory().removeItem(stack); // FIXME: This does not remove items with damage values that were detected by contains()
|
||||
ecoMan.transact(new Transaction(Economable.PLUGIN, Economable.wrap(player), price, TransactionReason.PLUGIN_GIVE));
|
||||
MessageUtils.sendMessage(player, String.format("You have sold %d %s for %s.", quantity, shop.getItem(), ecoMan.getCurrency().formatAmount(price)));
|
||||
MessageUtils.sendMessage(player, "You have sold {1} {2} for {3}.", quantity, shop.getItem(), ecoMan.getCurrency().formatAmount(price));
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class SignChangeListener implements Listener {
|
||||
ParsedSignShop pss = parseSignShop(evt);
|
||||
|
||||
if (pss.error != null) {
|
||||
MessageUtils.sendMessage(evt.getPlayer(), String.format("Cannot create shop: %s", pss.error));
|
||||
MessageUtils.sendMessage(evt.getPlayer(), "Cannot create shop: {1}", pss.error);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -50,18 +50,18 @@ public class SignChangeListener implements Listener {
|
||||
plugin.getSignShopManager().addSignShop(signShop);
|
||||
evt.setLine(0, ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("admin-shop-title")));
|
||||
MessageUtils.sendMessage(evt.getPlayer(), "Sign shop created!");
|
||||
MessageUtils.sendMessage(evt.getPlayer(), String.format("Item: %d x %s", signShop.getQuantity(), signShop.getItem()));
|
||||
MessageUtils.sendMessage(evt.getPlayer(), "Item: {1} x {2}", signShop.getQuantity(), signShop.getItem());
|
||||
|
||||
if (signShop.canBuy()) { // The player be buying from the shop, not the other way around.
|
||||
MessageUtils.sendMessage(evt.getPlayer(), String.format("Will sell too players for %s.",
|
||||
MessageUtils.sendMessage(evt.getPlayer(), "Will sell to players for {!}.",
|
||||
plugin.getSaneEconomy().getEconomyManager().getCurrency().formatAmount(signShop.getBuyPrice())
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
if (signShop.canSell()) { // The player be selling to the shop, not the other way around.
|
||||
MessageUtils.sendMessage(evt.getPlayer(), String.format("Will buy from players for %s.",
|
||||
MessageUtils.sendMessage(evt.getPlayer(), "Will buy from players for {1}.",
|
||||
plugin.getSaneEconomy().getEconomyManager().getCurrency().formatAmount(signShop.getSellPrice())
|
||||
));
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,8 +202,4 @@ public class SignChangeListener implements Listener {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user