mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-11-22 18:16:11 +01:00
Refactor code a little bit.
This commit is contained in:
parent
f940d301b7
commit
7547f75af0
@ -20,7 +20,7 @@ public abstract class SaneEconomyCommand implements CommandExecutor {
|
||||
throw new NoPermissionException();
|
||||
}
|
||||
|
||||
return onCommand(sender, args);
|
||||
onCommand(sender, args);
|
||||
} catch (UsageException e) {
|
||||
/* Invalid usage in some way, print out exactly what went wrong along with the proper usage. */
|
||||
MessageUtils.sendMessage(sender, e.getMessage());
|
||||
@ -28,12 +28,11 @@ public abstract class SaneEconomyCommand implements CommandExecutor {
|
||||
for (String s : getUsage()) {
|
||||
MessageUtils.sendMessage(sender, String.format("Usage: %s", s.replace("<command>", label)));
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (CommandException e) {
|
||||
MessageUtils.sendMessage(sender, e.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,5 +48,5 @@ public abstract class SaneEconomyCommand implements CommandExecutor {
|
||||
*/
|
||||
public abstract String[] getUsage();
|
||||
|
||||
protected abstract boolean onCommand(CommandSender sender, String[] args) throws CommandException;
|
||||
protected abstract void onCommand(CommandSender sender, String[] args) throws CommandException;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class BalanceCommand extends SaneEconomyCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, String[] args) throws CommandException {
|
||||
public void onCommand(CommandSender sender, String[] args) throws CommandException {
|
||||
String playerName;
|
||||
|
||||
if (args.length == 0) {
|
||||
@ -44,11 +44,11 @@ public class BalanceCommand extends SaneEconomyCommand {
|
||||
|
||||
if (player == null) {
|
||||
MessageUtils.sendMessage(sender, "That player is not online.");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
MessageUtils.sendMessage(sender, "Balance of %s is %s.", playerName, SaneEconomy.getInstance().getEconomyManager().getFormattedBalance(player));
|
||||
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public class EconomyAdminCommand extends SaneEconomyCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, String[] args) throws CommandException {
|
||||
public void onCommand(CommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 2) {
|
||||
throw new TooFewArgumentsException();
|
||||
}
|
||||
@ -55,7 +55,7 @@ public class EconomyAdminCommand extends SaneEconomyCommand {
|
||||
|
||||
if (targetPlayer == null) {
|
||||
MessageUtils.sendMessage(sender, "That player is not online.");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
double amount;
|
||||
@ -68,7 +68,7 @@ public class EconomyAdminCommand extends SaneEconomyCommand {
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
MessageUtils.sendMessage(sender, "%s is not a positive number.", sAmount);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
EconomyManager ecoMan = SaneEconomy.getInstance().getEconomyManager();
|
||||
@ -81,7 +81,7 @@ public class EconomyAdminCommand extends SaneEconomyCommand {
|
||||
sTargetPlayer,
|
||||
ecoMan.getCurrency().formatAmount(newAmount)
|
||||
);
|
||||
return true;
|
||||
return;
|
||||
} else if (subCommand.equalsIgnoreCase("take")) {
|
||||
double newAmount = ecoMan.subtractBalance(targetPlayer, amount);
|
||||
|
||||
@ -90,11 +90,11 @@ public class EconomyAdminCommand extends SaneEconomyCommand {
|
||||
sTargetPlayer,
|
||||
ecoMan.getCurrency().formatAmount(newAmount)
|
||||
);
|
||||
return true;
|
||||
return;
|
||||
} else if (subCommand.equalsIgnoreCase("set")) {
|
||||
ecoMan.setBalance(targetPlayer, amount);
|
||||
MessageUtils.sendMessage(sender, "Balance for %s set to %s", sTargetPlayer, ecoMan.getCurrency().formatAmount(amount));
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
throw new InvalidUsageException();
|
||||
|
@ -11,11 +11,11 @@ import java.text.DecimalFormat;
|
||||
* Represents an in-game currency.
|
||||
*/
|
||||
public class Currency {
|
||||
private String nameSingular;
|
||||
private String namePlural;
|
||||
private DecimalFormat format;
|
||||
private final String nameSingular;
|
||||
private final String namePlural;
|
||||
private final DecimalFormat format;
|
||||
|
||||
public Currency(String nameSingular, String namePlural, DecimalFormat format) {
|
||||
private Currency(String nameSingular, String namePlural, DecimalFormat format) {
|
||||
this.nameSingular = nameSingular;
|
||||
this.namePlural = namePlural;
|
||||
this.format = format;
|
||||
|
@ -10,8 +10,8 @@ import org.bukkit.entity.Player;
|
||||
* Represents our EconomyManager, which manages players' balances.
|
||||
*/
|
||||
public class EconomyManager {
|
||||
private Currency currency;
|
||||
private EconomyStorageBackend backend;
|
||||
private final Currency currency;
|
||||
private final EconomyStorageBackend backend;
|
||||
|
||||
public EconomyManager(Currency currency, EconomyStorageBackend backend) {
|
||||
this.currency = currency;
|
||||
|
@ -16,7 +16,7 @@ import java.util.UUID;
|
||||
public class EconomyStorageBackendFlatfile implements EconomyStorageBackend {
|
||||
private static final int SCHEMA_VERSION = 1;
|
||||
|
||||
private File file;
|
||||
private final File file;
|
||||
private Map<UUID, Double> playerBalances = new HashMap<>();
|
||||
|
||||
public EconomyStorageBackendFlatfile(File file) {
|
||||
|
@ -12,7 +12,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
* Blackjack is still best pony.
|
||||
*/
|
||||
public class JoinQuitListener implements Listener {
|
||||
private SaneEconomy plugin;
|
||||
private final SaneEconomy plugin;
|
||||
|
||||
public JoinQuitListener(SaneEconomy plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -22,7 +22,7 @@ public class JoinQuitListener implements Listener {
|
||||
public void onPlayerJoin(PlayerJoinEvent evt) {
|
||||
Player player = evt.getPlayer();
|
||||
double startBalance = plugin.getConfig().getDouble("economy.start-balance", 0.0D);
|
||||
|
||||
|
||||
/* A starting balance is configured AND they haven't been given it yet. */
|
||||
if (startBalance > 0 && !plugin.getEconomyManager().accountExists(player)) {
|
||||
plugin.getEconomyManager().setBalance(player, startBalance);
|
||||
|
@ -18,6 +18,6 @@ public class MessageUtils {
|
||||
*/
|
||||
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));
|
||||
target.sendMessage(prefix + String.format(fmt, (Object[])args));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user