mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2025-02-18 12:41:19 +01:00
Improve /ecoadmin output and change default config.
This commit is contained in:
parent
ac956f7a87
commit
55195eb0a2
@ -53,7 +53,7 @@ public class EconomyAdminCommand extends SaneEconomyCommand {
|
|||||||
Player targetPlayer = Bukkit.getServer().getPlayer(sTargetPlayer);
|
Player targetPlayer = Bukkit.getServer().getPlayer(sTargetPlayer);
|
||||||
|
|
||||||
if (targetPlayer == null) {
|
if (targetPlayer == null) {
|
||||||
MessageUtils.sendMessage(sender, "That player is not online!");
|
MessageUtils.sendMessage(sender, "That player is not online.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,12 +61,11 @@ public class EconomyAdminCommand extends SaneEconomyCommand {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
amount = Double.valueOf(sAmount);
|
amount = Double.valueOf(sAmount);
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
MessageUtils.sendMessage(sender, "%s is not a number!", sAmount);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (amount < 0) {
|
if (amount < 0) {
|
||||||
|
throw new NumberFormatException();
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
MessageUtils.sendMessage(sender, "%s is not a positive number.", sAmount);
|
MessageUtils.sendMessage(sender, "%s is not a positive number.", sAmount);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -74,12 +73,20 @@ public class EconomyAdminCommand extends SaneEconomyCommand {
|
|||||||
if (subCommand.equalsIgnoreCase("give")) {
|
if (subCommand.equalsIgnoreCase("give")) {
|
||||||
double newAmount = SaneEconomy.getInstance().getEconomyManager().addBalance(targetPlayer, amount);
|
double newAmount = SaneEconomy.getInstance().getEconomyManager().addBalance(targetPlayer, amount);
|
||||||
|
|
||||||
MessageUtils.sendMessage(sender, "New balance for %s is %s", sTargetPlayer, SaneEconomy.getInstance().getEconomyManager().getCurrency().formatAmount(newAmount));
|
MessageUtils.sendMessage(sender, "Added %s to %s. Their balance is now %s.",
|
||||||
|
SaneEconomy.getInstance().getEconomyManager().getCurrency().formatAmount(amount),
|
||||||
|
sTargetPlayer,
|
||||||
|
SaneEconomy.getInstance().getEconomyManager().getCurrency().formatAmount(newAmount)
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
} else if (subCommand.equalsIgnoreCase("take")) {
|
} else if (subCommand.equalsIgnoreCase("take")) {
|
||||||
double newAmount = SaneEconomy.getInstance().getEconomyManager().subtractBalance(targetPlayer, amount);
|
double newAmount = SaneEconomy.getInstance().getEconomyManager().subtractBalance(targetPlayer, amount);
|
||||||
|
|
||||||
MessageUtils.sendMessage(sender, "New balance for %s is %s", sTargetPlayer, SaneEconomy.getInstance().getEconomyManager().getCurrency().formatAmount(newAmount));
|
MessageUtils.sendMessage(sender, "Took %s from %s. Their balance is now %s.",
|
||||||
|
SaneEconomy.getInstance().getEconomyManager().getCurrency().formatAmount(amount),
|
||||||
|
sTargetPlayer,
|
||||||
|
SaneEconomy.getInstance().getEconomyManager().getCurrency().formatAmount(newAmount)
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
} else if (subCommand.equalsIgnoreCase("set")) {
|
} else if (subCommand.equalsIgnoreCase("set")) {
|
||||||
SaneEconomy.getInstance().getEconomyManager().setBalance(targetPlayer, amount);
|
SaneEconomy.getInstance().getEconomyManager().setBalance(targetPlayer, amount);
|
||||||
|
@ -22,6 +22,7 @@ public class JoinQuitListener implements Listener {
|
|||||||
public void onPlayerJoin(PlayerJoinEvent evt) {
|
public void onPlayerJoin(PlayerJoinEvent evt) {
|
||||||
Player player = evt.getPlayer();
|
Player player = evt.getPlayer();
|
||||||
double startBalance = plugin.getConfig().getDouble("economy.start-balance", 0.0D);
|
double startBalance = plugin.getConfig().getDouble("economy.start-balance", 0.0D);
|
||||||
|
|
||||||
/* A starting balance is configured AND they haven't been given it yet. */
|
/* A starting balance is configured AND they haven't been given it yet. */
|
||||||
if (startBalance > 0 && !plugin.getEconomyManager().accountExists(player)) {
|
if (startBalance > 0 && !plugin.getEconomyManager().accountExists(player)) {
|
||||||
plugin.getEconomyManager().setBalance(player, startBalance);
|
plugin.getEconomyManager().setBalance(player, startBalance);
|
||||||
|
@ -9,8 +9,15 @@ import org.bukkit.command.CommandSender;
|
|||||||
* Blackjack is still best pony.
|
* Blackjack is still best pony.
|
||||||
*/
|
*/
|
||||||
public class MessageUtils {
|
public class MessageUtils {
|
||||||
public static void sendMessage(CommandSender sender, String fmt, String... args) {
|
/**
|
||||||
String prefix = ChatColor.translateAlternateColorCodes('&', SaneEconomy.getInstance().getConfig().getString("chat.prefix", "[SaneEcon] "));;
|
* Send a formatted chat message to the given target.
|
||||||
sender.sendMessage(prefix + String.format(fmt, args));
|
* This message will have the prefix defined in SaneEconomy's config file.
|
||||||
|
* @param target Target CommandSender
|
||||||
|
* @param fmt String#format format
|
||||||
|
* @param args String#format args
|
||||||
|
*/
|
||||||
|
public static void sendMessage(CommandSender target, String fmt, String... args) {
|
||||||
|
String prefix = ChatColor.translateAlternateColorCodes('&', SaneEconomy.getInstance().getConfig().getString("chat.prefix", ""));
|
||||||
|
target.sendMessage(prefix + String.format(fmt, args));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ currency:
|
|||||||
format: '0.00'
|
format: '0.00'
|
||||||
|
|
||||||
chat:
|
chat:
|
||||||
prefix: '&b[&9SaneEcon&b]&r '
|
prefix: '&b[&9Economy&b]&r '
|
||||||
|
|
||||||
economy:
|
economy:
|
||||||
start-balance: 1000.0
|
start-balance: 1000.0
|
Loading…
Reference in New Issue
Block a user