mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2025-02-16 19:51:23 +01:00
Merge branch 'master' of github.com:AppleDash/SaneEconomy
This commit is contained in:
commit
c0bd36b3e0
@ -6,10 +6,10 @@
|
||||
<parent>
|
||||
<groupId>org.appledash</groupId>
|
||||
<artifactId>SaneEconomy</artifactId>
|
||||
<version>0.10.3-SNAPSHOT</version>
|
||||
<version>0.10.4-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>SaneEconomyCore</artifactId>
|
||||
<version>0.10.3-SNAPSHOT</version>
|
||||
<version>0.10.4-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -8,6 +8,7 @@ import org.appledash.saneeconomy.utils.MessageUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import static org.appledash.saneeconomy.utils.I18n._;
|
||||
|
||||
/**
|
||||
* Created by AppleDash on 6/13/2016.
|
||||
@ -36,7 +37,7 @@ public abstract class SaneEconomyCommand implements CommandExecutor {
|
||||
|
||||
|
||||
for (String s : getUsage()) {
|
||||
MessageUtils.sendMessage(sender, "Usage: {1}", s.replace("<command>", label));
|
||||
MessageUtils.sendMessage(sender, _("Usage: {1}"), _(s).replace("<command>", label));
|
||||
}
|
||||
} catch (CommandException e) {
|
||||
MessageUtils.sendMessage(sender, e.getMessage());
|
||||
|
@ -63,6 +63,10 @@ public class BalanceCommand extends SaneEconomyCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
MessageUtils.sendMessage(sender, "Balance for {1} is {2}.", playerName, saneEconomy.getEconomyManager().getFormattedBalance(Economable.wrap(player)));
|
||||
if (sender == player) {
|
||||
MessageUtils.sendMessage(sender, "Your balance is {1}.", saneEconomy.getEconomyManager().getFormattedBalance(Economable.wrap(player)));
|
||||
} else {
|
||||
MessageUtils.sendMessage(sender, "Balance for {1} is {2}.", playerName, saneEconomy.getEconomyManager().getFormattedBalance(Economable.wrap(player)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
package org.appledash.saneeconomy.economy.backend.type;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import org.appledash.saneeconomy.economy.economable.Economable;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Created by appledash on 1/22/17.
|
||||
* Blackjack is best pony.
|
||||
*/
|
||||
public class EconomyStorageBackendJSON extends EconomyStorageBackendCaching {
|
||||
private final Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().create();
|
||||
private File file;
|
||||
|
||||
public EconomyStorageBackendJSON(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBalance(Economable economable, double newBalance) {
|
||||
balances.put(economable.getUniqueIdentifier(), newBalance);
|
||||
saveDatabase();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void reloadDatabase() {
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
balances = new ConcurrentHashMap<>((Map)gson.fromJson(new FileReader(file), new TypeToken<Map<String, Double>>(){}.getType()));
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException("Failed to load database!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitUntilFlushed() {
|
||||
// NOOP - Database is saved on every change.
|
||||
}
|
||||
|
||||
private synchronized void saveDatabase() {
|
||||
try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file, false))) {
|
||||
bufferedWriter.write(gson.toJson(balances));
|
||||
bufferedWriter.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to save database", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -12,12 +12,18 @@ import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Created by AppleDash on 6/14/2016.
|
||||
* Blackjack is still best pony.
|
||||
*/
|
||||
public class EconomyStorageBackendMySQL extends EconomyStorageBackendCaching {
|
||||
private static final Logger LOGGER = Logger.getLogger("EconomyStorageBackendMySQL");
|
||||
static {
|
||||
LOGGER.setLevel(Level.FINEST);
|
||||
}
|
||||
private final MySQLConnection dbConn;
|
||||
|
||||
public EconomyStorageBackendMySQL(DatabaseCredentials dbCredentials) {
|
||||
@ -115,7 +121,7 @@ public class EconomyStorageBackendMySQL extends EconomyStorageBackendCaching {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void setBalance(final Economable economable, final double newBalance) {
|
||||
public void setBalance(final Economable economable, final double newBalance) {
|
||||
final double oldBalance = getBalance(economable);
|
||||
balances.put(economable.getUniqueIdentifier(), newBalance);
|
||||
|
||||
@ -133,7 +139,7 @@ public class EconomyStorageBackendMySQL extends EconomyStorageBackendCaching {
|
||||
});
|
||||
}
|
||||
|
||||
private synchronized void ensureAccountExists(Economable economable, Connection conn) throws SQLException {
|
||||
private void ensureAccountExists(Economable economable, Connection conn) throws SQLException {
|
||||
if (!accountExists(economable, conn)) {
|
||||
PreparedStatement statement = dbConn.prepareStatement(conn, String.format("INSERT INTO `%s` (unique_identifier, balance) VALUES (?, 0.0)", dbConn.getTable("saneeconomy_balances")));
|
||||
statement.setString(1, economable.getUniqueIdentifier());
|
||||
@ -141,7 +147,7 @@ public class EconomyStorageBackendMySQL extends EconomyStorageBackendCaching {
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized boolean accountExists(Economable economable, Connection conn) throws SQLException {
|
||||
private boolean accountExists(Economable economable, Connection conn) throws SQLException {
|
||||
PreparedStatement statement = dbConn.prepareStatement(conn, String.format("SELECT 1 FROM `%s` WHERE `unique_identifier` = ?", dbConn.getTable("saneeconomy_balances")));
|
||||
statement.setString(1, economable.getUniqueIdentifier());
|
||||
|
||||
|
@ -2,6 +2,7 @@ package org.appledash.saneeconomy.utils;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import org.appledash.saneeconomy.SaneEconomy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -23,7 +24,7 @@ public class MessageUtils {
|
||||
* @param fmt String#format format
|
||||
* @param args String#format args
|
||||
*/
|
||||
public static synchronized void sendMessage(CommandSender target, String fmt, Object... args) {
|
||||
public static void sendMessage(CommandSender target, String fmt, Object... args) {
|
||||
fmt = _(fmt);
|
||||
|
||||
String prefix = ChatColor.translateAlternateColorCodes('&', SaneEconomy.getInstance().getConfig().getString("chat.prefix", ""));
|
||||
@ -36,11 +37,11 @@ public class MessageUtils {
|
||||
formatted = indexedFormat(fmt, (Object[]) args);
|
||||
}
|
||||
|
||||
target.sendMessage(prefix + formatted);
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SaneEconomy.getInstance(), () -> target.sendMessage(prefix + formatted));
|
||||
}
|
||||
|
||||
public static synchronized void sendMessage(OfflinePlayer target, String fmt, Object... args) {
|
||||
if (target.isOnline() && (target instanceof CommandSender)) {
|
||||
public static void sendMessage(Object target, String fmt, Object... args) {
|
||||
if ((target instanceof OfflinePlayer) && ((OfflinePlayer) target).isOnline() && (target instanceof CommandSender)) {
|
||||
sendMessage(((CommandSender) target), fmt, (Object[])args);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import org.appledash.saneeconomy.economy.Currency;
|
||||
import org.appledash.saneeconomy.economy.EconomyManager;
|
||||
import org.appledash.saneeconomy.economy.backend.EconomyStorageBackend;
|
||||
import org.appledash.saneeconomy.economy.backend.type.EconomyStorageBackendFlatfile;
|
||||
import org.appledash.saneeconomy.economy.backend.type.EconomyStorageBackendJSON;
|
||||
import org.appledash.saneeconomy.economy.backend.type.EconomyStorageBackendMySQL;
|
||||
import org.appledash.saneeconomy.economy.economable.EconomableGeneric;
|
||||
import org.appledash.saneeconomy.economy.logger.TransactionLogger;
|
||||
@ -81,6 +82,11 @@ public class SaneEconomyConfiguration {
|
||||
File backendFile = new File(saneEconomy.getDataFolder(), backendFileName);
|
||||
backend = new EconomyStorageBackendFlatfile(backendFile);
|
||||
logger.info("Initialized flatfile backend with file " + backendFile.getAbsolutePath());
|
||||
} else if (backendType.equalsIgnoreCase("json")) {
|
||||
String backendFileName = config.getString("file", "economy.json");
|
||||
File backendFile = new File(saneEconomy.getDataFolder(), backendFileName);
|
||||
backend = new EconomyStorageBackendJSON(backendFile);
|
||||
logger.info("Initialized JSON backend with file " + backendFile.getAbsolutePath());
|
||||
} else if (backendType.equalsIgnoreCase("mysql")) {
|
||||
EconomyStorageBackendMySQL mySQLBackend = new EconomyStorageBackendMySQL(loadCredentials(config));
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
backend:
|
||||
type: flatfile
|
||||
type: json
|
||||
|
||||
currency:
|
||||
name:
|
||||
|
@ -7,24 +7,33 @@
|
||||
# IMPORTANT: If your translation has a colon ( : ) character inside of it, you must enclose the entire part after "message: " in single quotes ( ' ).
|
||||
# If this file doesn't work for some reason, check your console for errors with "SnakeYAML" included in them.
|
||||
messages:
|
||||
- message: You don't have permission to check the balance of {1}.
|
||||
- message: That player is not online.
|
||||
- message: You cannot pay yourself.
|
||||
- message: "You don't have permission to check the balance of {1}."
|
||||
- message: "That player is not online."
|
||||
- message: "You cannot pay yourself."
|
||||
- message: "Usage: {1}"
|
||||
- message: That player does not exist.
|
||||
- message: Balance for {1} is {2}.
|
||||
- message: "That player does not exist."
|
||||
- message: "Your balance is {1}."
|
||||
- message: "Balance for {1} is {2}."
|
||||
- message: "Top {1} players on page {2}:"
|
||||
- message: That player does not exist.
|
||||
- message: "That player does not exist."
|
||||
- message: "{1} is not a positive number."
|
||||
- message: Added {1} to {2}. Their balance is now {3}.
|
||||
- message: Took {1} from {2}. Their balance is now {3}.
|
||||
- message: Balance for {1} set to {2}.
|
||||
- message: You do not have enough money to transfer {1} to {2}.
|
||||
- message: You have transferred {1} to {2}.
|
||||
- message: You have received {1} from {2}.
|
||||
- message: Reloading database...
|
||||
- message: Database reloaded.
|
||||
- message: You've been issued a starting balance of {1}!
|
||||
- message: "Added {1} to {2}. Their balance is now {3}."
|
||||
- message: "Took {1} from {2}. Their balance is now {3}."
|
||||
- message: "Balance for {1} set to {2}."
|
||||
- message: "You do not have enough money to transfer {1} to {2}."
|
||||
- message: "You have transferred {1} to {2}."
|
||||
- message: "You have received {1} from {2}."
|
||||
- message: "Reloading database..."
|
||||
- message: "Database reloaded."
|
||||
- message: "You've been issued a starting balance of {1}!"
|
||||
- message: "{1} is not a valid number."
|
||||
- message: "There aren't enough players to display that page."
|
||||
- message: "[{1:02d}] {2} - {3}"
|
||||
- message: "Too few arguments for that command!"
|
||||
- message: "Usage: {1}"
|
||||
- message: "/pay <player> <amount>"
|
||||
- message: "/<command> [player]"
|
||||
- message: "/<command>"
|
||||
- message: "/<command> <page>"
|
||||
- message: "/<command> <give/take/set> [player] <amount>"
|
||||
- message: "/<command> reload-database"
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: SaneEconomy
|
||||
author: AppleDash
|
||||
main: org.appledash.saneeconomy.SaneEconomy
|
||||
version: 0.10.3
|
||||
version: 0.10.4
|
||||
load: STARTUP
|
||||
softdepend: [Vault]
|
||||
commands:
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>SaneEconomy</artifactId>
|
||||
<groupId>org.appledash</groupId>
|
||||
<version>0.10.3-SNAPSHOT</version>
|
||||
<version>0.10.4-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
<dependency>
|
||||
<groupId>org.appledash</groupId>
|
||||
<artifactId>SaneEconomyCore</artifactId>
|
||||
<version>0.10.3-SNAPSHOT</version>
|
||||
<version>0.10.4-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -71,7 +71,7 @@ public class EntityDamageListener implements Listener {
|
||||
}
|
||||
|
||||
Map<UUID, Double> damageDoneToThisEntity = damageDealt.get(entity.getEntityId());
|
||||
double totalDmg = sumValues(damageDoneToThisEntity);
|
||||
double totalDmg = ((LivingEntity) entity).getMaxHealth();//sumValues(damageDoneToThisEntity);
|
||||
|
||||
for (Map.Entry<UUID, Double> entry : damageDoneToThisEntity.entrySet()) {
|
||||
double thisDmg = entry.getValue();
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>SaneEconomy</artifactId>
|
||||
<groupId>org.appledash</groupId>
|
||||
<version>0.10.3-SNAPSHOT</version>
|
||||
<version>0.10.4-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
<dependency>
|
||||
<groupId>org.appledash</groupId>
|
||||
<artifactId>SaneEconomyCore</artifactId>
|
||||
<version>0.10.3-SNAPSHOT</version>
|
||||
<version>0.10.4-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user