mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-11-26 20:16:18 +01:00
Clean up some code
This commit is contained in:
parent
21cef3c697
commit
fc0588281f
@ -92,10 +92,10 @@ public class SaneEconomy extends JavaPlugin implements ISaneEconomy {
|
||||
reloadConfig();
|
||||
}
|
||||
|
||||
SaneEconomyConfiguration saneEconomyConfiguration = new SaneEconomyConfiguration(this);
|
||||
SaneEconomyConfiguration config = new SaneEconomyConfiguration(this);
|
||||
|
||||
economyManager = saneEconomyConfiguration.loadEconomyBackend();
|
||||
transactionLogger = saneEconomyConfiguration.loadLogger();
|
||||
economyManager = config.loadEconomyBackend();
|
||||
transactionLogger = config.loadLogger();
|
||||
|
||||
saveConfig();
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.appledash.saneeconomy.economy;
|
||||
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
@ -6,6 +6,7 @@ import org.appledash.saneeconomy.economy.economable.Economable;
|
||||
import org.appledash.saneeconomy.economy.transaction.Transaction;
|
||||
import org.appledash.saneeconomy.economy.transaction.TransactionReason;
|
||||
import org.appledash.saneeconomy.economy.transaction.TransactionResult;
|
||||
import org.appledash.saneeconomy.economy.transaction.TransactionResult.Status;
|
||||
import org.appledash.saneeconomy.utils.NumberUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -92,7 +93,7 @@ public class EconomyManager {
|
||||
* @return Player's new balance
|
||||
* @throws IllegalArgumentException If amount is negative
|
||||
*/
|
||||
private double addBalance(Economable targetPlayer, double amount) {
|
||||
private void addBalance(Economable targetPlayer, double amount) {
|
||||
amount = NumberUtils.filterAmount(currency, amount);
|
||||
|
||||
if (amount < 0) {
|
||||
@ -100,14 +101,12 @@ public class EconomyManager {
|
||||
}
|
||||
|
||||
if (targetPlayer == Economable.CONSOLE) {
|
||||
return Double.MAX_VALUE;
|
||||
return;
|
||||
}
|
||||
|
||||
double newAmount = backend.getBalance(targetPlayer) + amount;
|
||||
|
||||
setBalance(targetPlayer, newAmount);
|
||||
|
||||
return newAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,7 +117,7 @@ public class EconomyManager {
|
||||
* @return Player's new balance
|
||||
* @throws IllegalArgumentException If amount is negative
|
||||
*/
|
||||
private double subtractBalance(Economable targetPlayer, double amount) {
|
||||
private void subtractBalance(Economable targetPlayer, double amount) {
|
||||
amount = NumberUtils.filterAmount(currency, amount);
|
||||
|
||||
if (amount < 0) {
|
||||
@ -126,7 +125,7 @@ public class EconomyManager {
|
||||
}
|
||||
|
||||
if (targetPlayer == Economable.CONSOLE) {
|
||||
return Double.MAX_VALUE;
|
||||
return;
|
||||
}
|
||||
|
||||
double newAmount = backend.getBalance(targetPlayer) - amount;
|
||||
@ -138,8 +137,6 @@ public class EconomyManager {
|
||||
}
|
||||
|
||||
setBalance(targetPlayer, newAmount);
|
||||
|
||||
return newAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -172,8 +169,8 @@ public class EconomyManager {
|
||||
double amount = transaction.getAmount();
|
||||
|
||||
if (!transaction.isFree()) { // If the transaction is occurring because of another plugin or because of an admin.
|
||||
if (!hasBalance(sender, amount) && transaction.getReason() != TransactionReason.TEST) {
|
||||
return new TransactionResult(transaction, TransactionResult.Status.ERR_NOT_ENOUGH_FUNDS);
|
||||
if (!hasBalance(sender, amount) && (transaction.getReason() != TransactionReason.TEST)) {
|
||||
return new TransactionResult(transaction, Status.ERR_NOT_ENOUGH_FUNDS);
|
||||
}
|
||||
|
||||
subtractBalance(sender, amount);
|
||||
|
@ -13,25 +13,25 @@ import java.util.UUID;
|
||||
*/
|
||||
public interface EconomyStorageBackend {
|
||||
/**
|
||||
* Check whether a player has used the economy system before.
|
||||
* @param player Player
|
||||
* Check whether an economable has used the economy system before.
|
||||
* @param economable Economable
|
||||
* @return True if they have, false otherwise.
|
||||
*/
|
||||
boolean accountExists(Economable player);
|
||||
boolean accountExists(Economable economable);
|
||||
|
||||
/**
|
||||
* Get the balance of a player.
|
||||
* @param player Player
|
||||
* @param economable Economable
|
||||
* @return Player's current balance
|
||||
*/
|
||||
double getBalance(Economable player);
|
||||
double getBalance(Economable economable);
|
||||
|
||||
/**
|
||||
* Set the balance of a player, overwriting the old balance.
|
||||
* @param player Player
|
||||
* Set the balance of an Economable, overwriting the old balance.
|
||||
* @param economable Economable
|
||||
* @param newBalance Player's new balance
|
||||
*/
|
||||
void setBalance(Economable player, double newBalance);
|
||||
void setBalance(Economable economable, double newBalance);
|
||||
|
||||
/**
|
||||
* Get the UUIDs of the players who have the most money, along with how much money they have.
|
||||
|
@ -4,15 +4,14 @@ import org.appledash.saneeconomy.SaneEconomy;
|
||||
import org.appledash.saneeconomy.economy.economable.Economable;
|
||||
import org.appledash.saneeconomy.utils.DatabaseCredentials;
|
||||
import org.appledash.saneeconomy.utils.MySQLConnection;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Collections;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Created by AppleDash on 6/14/2016.
|
||||
|
@ -14,7 +14,7 @@ import java.sql.SQLException;
|
||||
* Blackjack is best pony.
|
||||
*/
|
||||
public class TransactionLoggerMySQL implements TransactionLogger {
|
||||
private MySQLConnection dbConn;
|
||||
private final MySQLConnection dbConn;
|
||||
|
||||
public TransactionLoggerMySQL(DatabaseCredentials credentials) {
|
||||
this.dbConn = new MySQLConnection(credentials);
|
||||
|
@ -40,6 +40,6 @@ public class Transaction {
|
||||
}
|
||||
|
||||
public boolean isFree() {
|
||||
return sender == Economable.CONSOLE || sender == Economable.PLUGIN || reason == TransactionReason.ADMIN;
|
||||
return (sender == Economable.CONSOLE) || (sender == Economable.PLUGIN) || (reason == TransactionReason.ADMIN);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package org.appledash.saneeconomy.utils;
|
||||
|
||||
import org.appledash.saneeconomy.SaneEconomy;
|
||||
import org.bukkit.Bukkit;
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
|
@ -128,10 +128,11 @@ public class SaneEconomyConfiguration {
|
||||
|
||||
DatabaseCredentials credentials = loadCredentials(rootConfig.getConfigurationSection("logger-database"));
|
||||
|
||||
TransactionLoggerMySQL transactionLoggerMySQL = new TransactionLoggerMySQL(credentials);
|
||||
if (transactionLoggerMySQL.testConnection()) {
|
||||
TransactionLoggerMySQL transactionLogger = new TransactionLoggerMySQL(credentials);
|
||||
|
||||
if (transactionLogger.testConnection()) {
|
||||
logger.info("Initialized MySQL transaction logger.");
|
||||
return transactionLoggerMySQL;
|
||||
return transactionLogger;
|
||||
}
|
||||
|
||||
logger.severe("Failed to connect to MySQL database for transaction logger!");
|
||||
|
@ -17,7 +17,7 @@ public class MockOfflinePlayer implements OfflinePlayer {
|
||||
private final UUID uuid;
|
||||
private final String name;
|
||||
|
||||
public MockOfflinePlayer(UUID uuid, String name) {
|
||||
private MockOfflinePlayer(UUID uuid, String name) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user