General code cleanup

This commit is contained in:
AppleDash 2017-06-14 19:38:04 -04:00
parent 1545bcacad
commit 078336db8f
10 changed files with 10 additions and 97 deletions

View File

@ -21,6 +21,7 @@ public class EconomyStorageBackendFlatfile extends EconomyStorageBackendCaching
this.file = file; this.file = file;
} }
@SuppressWarnings("unchecked")
@Override @Override
public synchronized void reloadDatabase() { public synchronized void reloadDatabase() {
if (!file.exists()) { if (!file.exists()) {
@ -46,7 +47,7 @@ public class EconomyStorageBackendFlatfile extends EconomyStorageBackendCaching
balances = (Map<String, Double>) ois.readObject(); balances = (Map<String, Double>) ois.readObject();
ois.close(); ois.close();
} catch (IOException | ClassNotFoundException e) { } catch (IOException | ClassNotFoundException | ClassCastException e) {
SaneEconomy.logger().severe("Failed to load flatfile database!"); SaneEconomy.logger().severe("Failed to load flatfile database!");
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -30,7 +30,7 @@ public class EconomyStorageBackendMySQL extends EconomyStorageBackendCaching {
this.dbConn = new MySQLConnection(dbCredentials); this.dbConn = new MySQLConnection(dbCredentials);
} }
private void createTables() { private void createTables() {
try (Connection conn = dbConn.openConnection()) { try (Connection conn = dbConn.openConnection()) {
int schemaVersion; int schemaVersion;
if (!checkTableExists(dbConn.getTable("saneeconomy_schema"))) { if (!checkTableExists(dbConn.getTable("saneeconomy_schema"))) {

View File

@ -87,13 +87,7 @@ public class I18n {
String convertedValue = convertOldTranslations(String.valueOf(currentTranslation)); String convertedValue = convertOldTranslations(String.valueOf(currentTranslation));
// Remove current key from map of things to go to the disk // Remove current key from map of things to go to the disk
Iterator<Map<?, ?>> iter = finalKeys.iterator(); finalKeys.removeIf(map -> String.valueOf(map.get("message")).equals(currentKey));
while (iter.hasNext()) {
if (String.valueOf(iter.next().get("message")).equals(currentKey)) {
iter.remove();
}
}
// Add the converted one. // Add the converted one.
if (convertedValue.equals("null")) { if (convertedValue.equals("null")) {

View File

@ -111,14 +111,14 @@ public class SaneEconomyConfiguration {
/** /**
* Convert one EconomyStorageBackend to another. * Convert one EconomyStorageBackend to another.
* Right now, this just consists of converting all player balances. Data in the old backend is kept. * Right now, this just consists of converting all player balances. Data in the old backend is kept.
* @param old Old backend * @param oldBackend Old backend
* @param newer New backend * @param newBackend New backend
*/ */
private void convertBackends(EconomyStorageBackend old, EconomyStorageBackend newer) { private void convertBackends(EconomyStorageBackend oldBackend, EconomyStorageBackend newBackend) {
old.getAllBalances().forEach((uniqueId, balance) -> { oldBackend.getAllBalances().forEach((uniqueId, balance) -> {
newer.setBalance(new EconomableGeneric(uniqueId), balance); newBackend.setBalance(new EconomableGeneric(uniqueId), balance);
}); });
newer.waitUntilFlushed(); newBackend.waitUntilFlushed();
} }
public TransactionLogger loadLogger() { public TransactionLogger loadLogger() {

View File

@ -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;
}
}

View File

@ -27,14 +27,6 @@ public class DatabaseCredentials {
queryTimeout = 5000; queryTimeout = 5000;
} }
public String getHostname() {
return hostname;
}
public int getPort() {
return port;
}
public String getUsername() { public String getUsername() {
return username; return username;
} }

View File

@ -47,10 +47,6 @@ public class MySQLConnection {
return preparedStatement; return preparedStatement;
} }
public PreparedStatement prepareStatement(String sql) throws SQLException {
return prepareStatement(openConnection(), sql);
}
public boolean testConnection() { public boolean testConnection() {
try (Connection ignored = openConnection()) { try (Connection ignored = openConnection()) {
return true; return true;

View File

@ -46,11 +46,6 @@ public class MockOfflinePlayer implements OfflinePlayer {
return false; return false;
} }
@Override
public void setBanned(boolean banned) {
}
@Override @Override
public boolean isWhitelisted() { public boolean isWhitelisted() {
return false; return false;

View File

@ -105,14 +105,4 @@ public class EntityDamageListener implements Listener {
return entityType.toString(); return entityType.toString();
} }
private double sumValues(Map<?, Double> map) {
double sum = 0;
for (Map.Entry<?, Double> entry : map.entrySet()) {
sum += entry.getValue();
}
return sum;
}
} }

View File

@ -29,10 +29,6 @@ public class ItemInfo implements Serializable {
return new ItemStack(material, amount, damage); return new ItemStack(material, amount, damage);
} }
public Material getMaterial() {
return material;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (!(o instanceof ItemInfo)) { if (!(o instanceof ItemInfo)) {