mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-11-24 19:15:54 +01:00
Format code
This commit is contained in:
parent
c269fc1065
commit
fe4fc5018d
@ -36,13 +36,15 @@ public class SaneEconomy extends SanePlugin implements ISaneEconomy {
|
||||
private TransactionLogger transactionLogger;
|
||||
private GithubVersionChecker versionChecker;
|
||||
|
||||
private final Map<String, SaneCommand> COMMANDS = new HashMap<String, SaneCommand>() {{
|
||||
put("balance", new BalanceCommand(SaneEconomy.this));
|
||||
put("ecoadmin", new EconomyAdminCommand(SaneEconomy.this));
|
||||
put("pay", new PayCommand(SaneEconomy.this));
|
||||
put("saneeconomy", new SaneEcoCommand(SaneEconomy.this));
|
||||
put("balancetop", new BalanceTopCommand(SaneEconomy.this));
|
||||
}};
|
||||
private final Map<String, SaneCommand> COMMANDS = new HashMap<String, SaneCommand>() {
|
||||
{
|
||||
put("balance", new BalanceCommand(SaneEconomy.this));
|
||||
put("ecoadmin", new EconomyAdminCommand(SaneEconomy.this));
|
||||
put("pay", new PayCommand(SaneEconomy.this));
|
||||
put("saneeconomy", new SaneEcoCommand(SaneEconomy.this));
|
||||
put("balancetop", new BalanceTopCommand(SaneEconomy.this));
|
||||
}
|
||||
};
|
||||
|
||||
public SaneEconomy() {
|
||||
instance = this;
|
||||
@ -190,7 +192,7 @@ public class SaneEconomy extends SanePlugin implements ISaneEconomy {
|
||||
getLogger().info("Initialized listeners.");
|
||||
}
|
||||
|
||||
private void shutdown(){
|
||||
private void shutdown() {
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
|
||||
@ -229,7 +231,7 @@ public class SaneEconomy extends SanePlugin implements ISaneEconomy {
|
||||
* Get the logger for the plugin.
|
||||
* @return Plugin logger.
|
||||
*/
|
||||
public static Logger logger(){
|
||||
public static Logger logger() {
|
||||
return instance.getLogger();
|
||||
}
|
||||
|
||||
|
@ -30,8 +30,8 @@ public class BalanceCommand extends SaneCommand {
|
||||
@Override
|
||||
public String[] getUsage() {
|
||||
return new String[] {
|
||||
"/<command> [player]"
|
||||
};
|
||||
"/<command> [player]"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,9 +31,9 @@ public class BalanceTopCommand extends SaneCommand {
|
||||
@Override
|
||||
public String[] getUsage() {
|
||||
return new String[] {
|
||||
"/<command>",
|
||||
"/<command> <page>"
|
||||
};
|
||||
"/<command>",
|
||||
"/<command> <page>"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,8 +39,8 @@ public class EconomyAdminCommand extends SaneCommand {
|
||||
@Override
|
||||
public String[] getUsage() {
|
||||
return new String[] {
|
||||
"/<command> <give/take/set> [player] <amount>"
|
||||
};
|
||||
"/<command> <give/take/set> [player] <amount>"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -92,7 +92,7 @@ public class EconomyAdminCommand extends SaneCommand {
|
||||
ecoMan.getCurrency().formatAmount(amount),
|
||||
sTargetPlayer,
|
||||
ecoMan.getCurrency().formatAmount(newAmount)
|
||||
);
|
||||
);
|
||||
|
||||
if (this.saneEconomy.getConfig().getBoolean("economy.notify-admin-give") && targetPlayer.isOnline()) {
|
||||
this.saneEconomy.getMessenger().sendMessage((Player) targetPlayer, "{1} has given you {2}. Your balance is now {3}.",
|
||||
@ -100,7 +100,7 @@ public class EconomyAdminCommand extends SaneCommand {
|
||||
ecoMan.getCurrency().formatAmount(amount),
|
||||
ecoMan.getCurrency().formatAmount(newAmount)
|
||||
|
||||
);
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -115,7 +115,7 @@ public class EconomyAdminCommand extends SaneCommand {
|
||||
ecoMan.getCurrency().formatAmount(amount),
|
||||
sTargetPlayer,
|
||||
ecoMan.getCurrency().formatAmount(newAmount)
|
||||
);
|
||||
);
|
||||
|
||||
if (this.saneEconomy.getConfig().getBoolean("economy.notify-admin-take") && targetPlayer.isOnline()) {
|
||||
this.saneEconomy.getMessenger().sendMessage((Player) targetPlayer, "{1} has taken {2} from you. Your balance is now {3}.",
|
||||
@ -123,7 +123,7 @@ public class EconomyAdminCommand extends SaneCommand {
|
||||
ecoMan.getCurrency().formatAmount(amount),
|
||||
ecoMan.getCurrency().formatAmount(newAmount)
|
||||
|
||||
);
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -137,13 +137,13 @@ public class EconomyAdminCommand extends SaneCommand {
|
||||
// FIXME: This is a silly hack to get it to log.
|
||||
if (oldBal.compareTo(BigDecimal.ZERO) > 0) {
|
||||
logger.logTransaction(new Transaction(
|
||||
ecoMan.getCurrency(), economable, Economable.CONSOLE, oldBal, TransactionReason.ADMIN_TAKE
|
||||
));
|
||||
ecoMan.getCurrency(), economable, Economable.CONSOLE, oldBal, TransactionReason.ADMIN_TAKE
|
||||
));
|
||||
}
|
||||
|
||||
logger.logTransaction(new Transaction(
|
||||
ecoMan.getCurrency(), Economable.CONSOLE, economable, amount, TransactionReason.ADMIN_GIVE
|
||||
));
|
||||
ecoMan.getCurrency(), Economable.CONSOLE, economable, amount, TransactionReason.ADMIN_GIVE
|
||||
));
|
||||
});
|
||||
|
||||
if (this.saneEconomy.getConfig().getBoolean("economy.notify-admin-set") && targetPlayer.isOnline()) {
|
||||
@ -151,7 +151,7 @@ public class EconomyAdminCommand extends SaneCommand {
|
||||
sender.getName(),
|
||||
ecoMan.getCurrency().formatAmount(amount)
|
||||
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -37,8 +37,8 @@ public class PayCommand extends SaneCommand {
|
||||
@Override
|
||||
public String[] getUsage() {
|
||||
return new String[] {
|
||||
"/pay <player> <amount>"
|
||||
};
|
||||
"/pay <player> <amount>"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -84,7 +84,7 @@ public class PayCommand extends SaneCommand {
|
||||
this.saneEconomy.getMessenger().sendMessage(sender, "You do not have enough money to transfer {1} to {2}.",
|
||||
ecoMan.getCurrency().formatAmount(amount),
|
||||
sToPlayer
|
||||
);
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -94,13 +94,13 @@ public class PayCommand extends SaneCommand {
|
||||
this.saneEconomy.getMessenger().sendMessage(sender, "You have transferred {1} to {2}.",
|
||||
ecoMan.getCurrency().formatAmount(amount),
|
||||
sToPlayer
|
||||
);
|
||||
);
|
||||
|
||||
if (toPlayer.isOnline()) {
|
||||
this.saneEconomy.getMessenger().sendMessage(((CommandSender) toPlayer), "You have received {1} from {2}.",
|
||||
ecoMan.getCurrency().formatAmount(amount),
|
||||
fromPlayer.getDisplayName()
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,10 +26,10 @@ public class SaneEcoCommand extends SaneCommand {
|
||||
@Override
|
||||
public String[] getUsage() {
|
||||
return new String[] {
|
||||
"/<command> reload - Reload everything.",
|
||||
"/<command> reload-database - Reload the database.",
|
||||
"/<command> reload-config - Reload the configuration."
|
||||
};
|
||||
"/<command> reload - Reload everything.",
|
||||
"/<command> reload-database - Reload the database.",
|
||||
"/<command> reload-config - Reload the configuration."
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,11 +63,11 @@ public class Currency {
|
||||
}
|
||||
|
||||
return new Currency(
|
||||
config.getString("name.singular", "dollar"),
|
||||
config.getString("name.plural", "dollars"),
|
||||
format,
|
||||
config.getString("balance-format", "{1} {2}")
|
||||
);
|
||||
config.getString("name.singular", "dollar"),
|
||||
config.getString("name.plural", "dollars"),
|
||||
format,
|
||||
config.getString("balance-format", "{1} {2}")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,13 +40,13 @@ public class EconomyStorageBackendJSON extends EconomyStorageBackendCaching {
|
||||
try {
|
||||
// try to load the old format and convert it
|
||||
// if that fails, load the new format
|
||||
DataHolderOld dataHolder = gson.fromJson(new FileReader(file), DataHolderOld.class);
|
||||
this.balances = new ConcurrentHashMap<>();
|
||||
this.uuidToName = new ConcurrentHashMap<>(dataHolder.uuidToName);
|
||||
DataHolderOld dataHolder = gson.fromJson(new FileReader(file), DataHolderOld.class);
|
||||
this.balances = new ConcurrentHashMap<>();
|
||||
this.uuidToName = new ConcurrentHashMap<>(dataHolder.uuidToName);
|
||||
|
||||
dataHolder.balances.forEach((s, bal) -> {
|
||||
this.balances.put(s, new BigDecimal(bal));
|
||||
});
|
||||
dataHolder.balances.forEach((s, bal) -> {
|
||||
this.balances.put(s, new BigDecimal(bal));
|
||||
});
|
||||
|
||||
this.saveDatabase();
|
||||
} catch (FileNotFoundException e) {
|
||||
|
@ -36,8 +36,8 @@ public class JoinQuitListener implements Listener {
|
||||
/* A starting balance is configured AND they haven't been given it yet. */
|
||||
if ((startBalance.compareTo(BigDecimal.ZERO) > 0) && !plugin.getEconomyManager().accountExists(economable)) {
|
||||
plugin.getEconomyManager().transact(new Transaction(
|
||||
plugin.getEconomyManager().getCurrency(), Economable.CONSOLE, economable, startBalance, TransactionReason.STARTING_BALANCE
|
||||
));
|
||||
plugin.getEconomyManager().getCurrency(), Economable.CONSOLE, economable, startBalance, TransactionReason.STARTING_BALANCE
|
||||
));
|
||||
if (plugin.getConfig().getBoolean("economy.notify-start-balance", true)) {
|
||||
this.plugin.getMessenger().sendMessage(player, "You've been issued a starting balance of {1}!", plugin.getEconomyManager().getCurrency().formatAmount(startBalance));
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ public class MapUtil {
|
||||
/* Originally found on StackOverflow: http://stackoverflow.com/a/2581754/1849152 */
|
||||
public static <K, V extends Comparable<? super V>> LinkedHashMap<K, V> sortByValue(Map<K, V> map) {
|
||||
List<Map.Entry<K, V>> list =
|
||||
new LinkedList<>(map.entrySet());
|
||||
new LinkedList<>(map.entrySet());
|
||||
|
||||
list.sort((o1, o2) -> -((o1.getValue()).compareTo(o2.getValue())));
|
||||
|
||||
|
@ -156,7 +156,7 @@ public class SaneEconomyConfiguration {
|
||||
boolean useSsl = config.getBoolean("use_ssl", false);
|
||||
|
||||
return new DatabaseCredentials(
|
||||
databaseType, backendHost, backendPort, backendUser, backendPass, backendDb, tablePrefix, useSsl
|
||||
);
|
||||
databaseType, backendHost, backendPort, backendUser, backendPass, backendDb, tablePrefix, useSsl
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -121,8 +121,8 @@ public class EconomySaneEconomy implements Economy {
|
||||
}
|
||||
|
||||
return transact(new Transaction(
|
||||
SaneEconomy.getInstance().getEconomyManager().getCurrency(), makeEconomable(target), Economable.PLUGIN, new BigDecimal(amount), TransactionReason.PLUGIN_TAKE
|
||||
));
|
||||
SaneEconomy.getInstance().getEconomyManager().getCurrency(), makeEconomable(target), Economable.PLUGIN, new BigDecimal(amount), TransactionReason.PLUGIN_TAKE
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -136,8 +136,8 @@ public class EconomySaneEconomy implements Economy {
|
||||
}
|
||||
|
||||
return transact(new Transaction(
|
||||
SaneEconomy.getInstance().getEconomyManager().getCurrency(), Economable.wrap(offlinePlayer), Economable.PLUGIN, new BigDecimal(amount), TransactionReason.PLUGIN_TAKE
|
||||
));
|
||||
SaneEconomy.getInstance().getEconomyManager().getCurrency(), Economable.wrap(offlinePlayer), Economable.PLUGIN, new BigDecimal(amount), TransactionReason.PLUGIN_TAKE
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -157,8 +157,8 @@ public class EconomySaneEconomy implements Economy {
|
||||
}
|
||||
|
||||
return transact(new Transaction(
|
||||
SaneEconomy.getInstance().getEconomyManager().getCurrency(), Economable.PLUGIN, makeEconomable(target), new BigDecimal(amount), TransactionReason.PLUGIN_GIVE
|
||||
));
|
||||
SaneEconomy.getInstance().getEconomyManager().getCurrency(), Economable.PLUGIN, makeEconomable(target), new BigDecimal(amount), TransactionReason.PLUGIN_GIVE
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -168,8 +168,8 @@ public class EconomySaneEconomy implements Economy {
|
||||
}
|
||||
|
||||
return transact(new Transaction(
|
||||
SaneEconomy.getInstance().getEconomyManager().getCurrency(), Economable.PLUGIN, Economable.wrap(offlinePlayer), new BigDecimal(v), TransactionReason.PLUGIN_GIVE
|
||||
));
|
||||
SaneEconomy.getInstance().getEconomyManager().getCurrency(), Economable.PLUGIN, Economable.wrap(offlinePlayer), new BigDecimal(v), TransactionReason.PLUGIN_GIVE
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -29,8 +29,8 @@ public class EconomyManagerTest {
|
||||
@Before
|
||||
public void setupEconomyManager() {
|
||||
economyManager = new EconomyManager(new MockSaneEconomy(),
|
||||
new Currency("test dollar", "test dollars", new DecimalFormat("0.00")),
|
||||
new MockEconomyStorageBackend(), null);
|
||||
new Currency("test dollar", "test dollars", new DecimalFormat("0.00")),
|
||||
new MockEconomyStorageBackend(), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -63,16 +63,16 @@ public class EconomyManagerTest {
|
||||
|
||||
// Ensure that balance addition and subtraction works...
|
||||
Assert.assertEquals(new BigDecimal("25.00"), economyManager.transact(
|
||||
new Transaction(economyManager.getCurrency(), playerOne, Economable.CONSOLE, new BigDecimal("25.00"), TransactionReason.TEST_TAKE)
|
||||
).getFromBalance());
|
||||
new Transaction(economyManager.getCurrency(), playerOne, Economable.CONSOLE, new BigDecimal("25.00"), TransactionReason.TEST_TAKE)
|
||||
).getFromBalance());
|
||||
|
||||
Assert.assertEquals(new BigDecimal("50.00"), economyManager.transact(
|
||||
new Transaction(economyManager.getCurrency(), Economable.CONSOLE, playerOne, new BigDecimal("25.00"), TransactionReason.TEST_GIVE)
|
||||
).getToBalance());
|
||||
new Transaction(economyManager.getCurrency(), Economable.CONSOLE, playerOne, new BigDecimal("25.00"), TransactionReason.TEST_GIVE)
|
||||
).getToBalance());
|
||||
|
||||
Assert.assertEquals(TransactionResult.Status.ERR_NOT_ENOUGH_FUNDS, economyManager.transact(
|
||||
new Transaction(economyManager.getCurrency(), playerTwo, Economable.CONSOLE, new BigDecimal(Double.MAX_VALUE), TransactionReason.TEST_TAKE)
|
||||
).getStatus());
|
||||
new Transaction(economyManager.getCurrency(), playerTwo, Economable.CONSOLE, new BigDecimal(Double.MAX_VALUE), TransactionReason.TEST_TAKE)
|
||||
).getStatus());
|
||||
|
||||
// Ensure that hasBalance works
|
||||
Assert.assertTrue(economyManager.hasBalance(playerOne, new BigDecimal("50.00")));
|
||||
|
@ -87,10 +87,10 @@ public class EntityDamageListener implements Listener {
|
||||
}
|
||||
|
||||
plugin.getSaneEconomy().getEconomyManager().transact(new Transaction(
|
||||
this.plugin.getSaneEconomy().getEconomyManager().getCurrency(), Economable.PLUGIN, Economable.wrap(offlinePlayer), thisAmount, TransactionReason.PLUGIN_GIVE
|
||||
));
|
||||
this.plugin.getSaneEconomy().getEconomyManager().getCurrency(), Economable.PLUGIN, Economable.wrap(offlinePlayer), thisAmount, TransactionReason.PLUGIN_GIVE
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
damageDealt.remove(evt.getEntity().getEntityId());
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ public class SaneEconomyOnlineTime extends SanePlugin implements Listener {
|
||||
}
|
||||
|
||||
}
|
||||
},0, 20);
|
||||
}, 0, 20);
|
||||
|
||||
this.getServer().getPluginManager().registerEvents(this, this);
|
||||
}
|
||||
|
@ -52,14 +52,14 @@ public class SignChangeListener implements Listener {
|
||||
|
||||
if (signShop.canBuy()) { // The player be buying from the shop, not the other way around.
|
||||
this.plugin.getMessenger().sendMessage(evt.getPlayer(), "Will sell to players for {1}.",
|
||||
plugin.getSaneEconomy().getEconomyManager().getCurrency().formatAmount(signShop.getBuyPrice())
|
||||
);
|
||||
plugin.getSaneEconomy().getEconomyManager().getCurrency().formatAmount(signShop.getBuyPrice())
|
||||
);
|
||||
}
|
||||
|
||||
if (signShop.canSell()) { // The player be selling to the shop, not the other way around.
|
||||
this.plugin.getMessenger().sendMessage(evt.getPlayer(), "Will buy from players for {1}.",
|
||||
plugin.getSaneEconomy().getEconomyManager().getCurrency().formatAmount(signShop.getSellPrice())
|
||||
);
|
||||
plugin.getSaneEconomy().getEconomyManager().getCurrency().formatAmount(signShop.getSellPrice())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class SignShopStorageJSON implements SignShopStorage {
|
||||
}
|
||||
|
||||
try {
|
||||
List<SignShop> tempShops = gson.fromJson(new FileReader(storageFile), new TypeToken<List<SignShop>>(){}.getType());
|
||||
List<SignShop> tempShops = gson.fromJson(new FileReader(storageFile), new TypeToken<List<SignShop>>() {} .getType());
|
||||
tempShops.forEach((shop) -> cachedSignShops.put(shop.getLocation(), shop));
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new IllegalStateException("This shouldn't happen - the file " + storageFile.getAbsolutePath() + " disappeared while we were trying to read it!", e);
|
||||
|
@ -60,15 +60,15 @@ public class LimitManager {
|
||||
|
||||
public void incrementLimitsHourly() {
|
||||
// For every limit type
|
||||
// For every player
|
||||
// For every limit
|
||||
// Increment limit by the limit for the specific direction and item.
|
||||
// For every player
|
||||
// For every limit
|
||||
// Increment limit by the limit for the specific direction and item.
|
||||
|
||||
sellPlayerLimits.forEach((playerUuid, itemToLimit) -> {
|
||||
Map<ItemInfo, Integer> newLimits = new HashMap<>();
|
||||
|
||||
itemToLimit.forEach((itemInfo, currentLimit) ->
|
||||
newLimits.put(itemInfo, currentLimit + (sellItemLimits.get(itemInfo).getHourlyGain())));
|
||||
newLimits.put(itemInfo, currentLimit + (sellItemLimits.get(itemInfo).getHourlyGain())));
|
||||
|
||||
itemToLimit.putAll(newLimits);
|
||||
});
|
||||
|
@ -24,4 +24,4 @@ public class Pair<K, V> {
|
||||
public static <K, V> Pair<K, V> of(K k, V v) {
|
||||
return new Pair<>(k, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
9
astyle.conf
Normal file
9
astyle.conf
Normal file
@ -0,0 +1,9 @@
|
||||
--mode=java
|
||||
--style=java # Bracket formatting
|
||||
--indent=spaces=4
|
||||
--indent-switches
|
||||
--pad-oper
|
||||
--pad-header
|
||||
--add-brackets
|
||||
--suffix=none # Do not backup original file
|
||||
--lineend=linux
|
Loading…
Reference in New Issue
Block a user