mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-11-05 01:59:35 +01:00
General code cleanup
This commit is contained in:
parent
1545bcacad
commit
078336db8f
@ -21,6 +21,7 @@ public class EconomyStorageBackendFlatfile extends EconomyStorageBackendCaching
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public synchronized void reloadDatabase() {
|
||||
if (!file.exists()) {
|
||||
@ -46,7 +47,7 @@ public class EconomyStorageBackendFlatfile extends EconomyStorageBackendCaching
|
||||
balances = (Map<String, Double>) ois.readObject();
|
||||
|
||||
ois.close();
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
} catch (IOException | ClassNotFoundException | ClassCastException e) {
|
||||
SaneEconomy.logger().severe("Failed to load flatfile database!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public class EconomyStorageBackendMySQL extends EconomyStorageBackendCaching {
|
||||
this.dbConn = new MySQLConnection(dbCredentials);
|
||||
}
|
||||
|
||||
private void createTables() {
|
||||
private void createTables() {
|
||||
try (Connection conn = dbConn.openConnection()) {
|
||||
int schemaVersion;
|
||||
if (!checkTableExists(dbConn.getTable("saneeconomy_schema"))) {
|
||||
|
@ -87,13 +87,7 @@ public class I18n {
|
||||
String convertedValue = convertOldTranslations(String.valueOf(currentTranslation));
|
||||
|
||||
// Remove current key from map of things to go to the disk
|
||||
Iterator<Map<?, ?>> iter = finalKeys.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
if (String.valueOf(iter.next().get("message")).equals(currentKey)) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
finalKeys.removeIf(map -> String.valueOf(map.get("message")).equals(currentKey));
|
||||
|
||||
// Add the converted one.
|
||||
if (convertedValue.equals("null")) {
|
||||
|
@ -111,14 +111,14 @@ public class SaneEconomyConfiguration {
|
||||
/**
|
||||
* Convert one EconomyStorageBackend to another.
|
||||
* Right now, this just consists of converting all player balances. Data in the old backend is kept.
|
||||
* @param old Old backend
|
||||
* @param newer New backend
|
||||
* @param oldBackend Old backend
|
||||
* @param newBackend New backend
|
||||
*/
|
||||
private void convertBackends(EconomyStorageBackend old, EconomyStorageBackend newer) {
|
||||
old.getAllBalances().forEach((uniqueId, balance) -> {
|
||||
newer.setBalance(new EconomableGeneric(uniqueId), balance);
|
||||
private void convertBackends(EconomyStorageBackend oldBackend, EconomyStorageBackend newBackend) {
|
||||
oldBackend.getAllBalances().forEach((uniqueId, balance) -> {
|
||||
newBackend.setBalance(new EconomableGeneric(uniqueId), balance);
|
||||
});
|
||||
newer.waitUntilFlushed();
|
||||
newBackend.waitUntilFlushed();
|
||||
}
|
||||
|
||||
public TransactionLogger loadLogger() {
|
||||
|
@ -1,51 +0,0 @@
|
||||
package org.appledash.saneeconomy.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
/**
|
||||
* Created by appledash on 9/21/16.
|
||||
* Blackjack is best pony.
|
||||
*/
|
||||
public class StackTraceUtils {
|
||||
public static void what() {
|
||||
for (StackTraceElement elem : Thread.currentThread().getStackTrace()) {
|
||||
String className = elem.getClassName();
|
||||
|
||||
Plugin plugin = getPlugin(className);
|
||||
|
||||
if (plugin != null) {
|
||||
System.out.printf("Calling plugin seems to be %s (%s)\n", plugin.getName(), className);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Class classFromName(String className) {
|
||||
try {
|
||||
return Class.forName(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Plugin getPlugin(String className) {
|
||||
Class clazz = classFromName(className);
|
||||
|
||||
if (clazz == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!JavaPlugin.class.isAssignableFrom(clazz)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (Plugin plugin : Bukkit.getServer().getPluginManager().getPlugins()) {
|
||||
if (clazz.isInstance(plugin)) {
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -27,14 +27,6 @@ public class DatabaseCredentials {
|
||||
queryTimeout = 5000;
|
||||
}
|
||||
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
@ -47,10 +47,6 @@ public class MySQLConnection {
|
||||
return preparedStatement;
|
||||
}
|
||||
|
||||
public PreparedStatement prepareStatement(String sql) throws SQLException {
|
||||
return prepareStatement(openConnection(), sql);
|
||||
}
|
||||
|
||||
public boolean testConnection() {
|
||||
try (Connection ignored = openConnection()) {
|
||||
return true;
|
||||
|
@ -46,11 +46,6 @@ public class MockOfflinePlayer implements OfflinePlayer {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBanned(boolean banned) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWhitelisted() {
|
||||
return false;
|
||||
|
@ -105,14 +105,4 @@ public class EntityDamageListener implements Listener {
|
||||
|
||||
return entityType.toString();
|
||||
}
|
||||
|
||||
private double sumValues(Map<?, Double> map) {
|
||||
double sum = 0;
|
||||
|
||||
for (Map.Entry<?, Double> entry : map.entrySet()) {
|
||||
sum += entry.getValue();
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
|
@ -29,10 +29,6 @@ public class ItemInfo implements Serializable {
|
||||
return new ItemStack(material, amount, damage);
|
||||
}
|
||||
|
||||
public Material getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof ItemInfo)) {
|
||||
|
Loading…
Reference in New Issue
Block a user