[factions-banking] Necessary change to introduce MY SQL into the mod!
Some checks failed
build / build (21) (push) Has been cancelled
Some checks failed
build / build (21) (push) Has been cancelled
This commit is contained in:
parent
ef49519368
commit
cde06d56c0
@ -26,7 +26,7 @@ repositories {
|
||||
// includeGroup("cc.tweaked")
|
||||
// }
|
||||
// }
|
||||
maven {url = "https://maven.kyrptonaught.dev"}
|
||||
maven { url = "https://maven.kyrptonaught.dev" }
|
||||
maven { url = 'https://maven.minecraftforge.net/' } // for Terrablender
|
||||
}
|
||||
|
||||
@ -47,6 +47,9 @@ dependencies {
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
|
||||
// modImplementation "mysql:mysql-connector-java:9.1.0"
|
||||
include(implementation("mysql:mysql-connector-java:8.0.27"))
|
||||
|
||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
//modCompileOnly "cc.tweaked:cc-tweaked-1.20-fabric-api:1.105.0"
|
||||
|
BIN
mysql-connector-java-8.0.27.jar
Normal file
BIN
mysql-connector-java-8.0.27.jar
Normal file
Binary file not shown.
@ -88,7 +88,7 @@ public class IndividualBank {
|
||||
// TODO: REPLACE WITH SQL SERVER. DIRTY ITERATE OVER ALL FILES IN DIRECTORY TO LOAD STRUCTURE
|
||||
File dir = new File(accountsListDir);
|
||||
File[] allFiles = dir.listFiles();
|
||||
if (allFiles != null) {
|
||||
if (accounts != null && allFiles != null) {
|
||||
for (File file : allFiles ) {
|
||||
// First grab file identifier as KEY
|
||||
String accountIdentifier = file.getName();
|
||||
@ -123,6 +123,7 @@ public class IndividualBank {
|
||||
// 'accountsListFromName' structure. This makes it no worse than O(n) to fill these two structures in.
|
||||
// NOTE: This is an *EXPENSIVE* operation! Future us might need to update this. Also note a method is needed for everytime a player opens a new account
|
||||
// or gets put on one to update the map every time
|
||||
if (accounts != null) {
|
||||
for (Entry<String, IndividualAccount> account : accounts.accountsList.entrySet()) {
|
||||
// We must loop over the string of holders for each account as well to make the flattened accountsListFromName map
|
||||
List<String> accountHolders = account.getValue().GetAccountHolders();
|
||||
@ -139,6 +140,10 @@ public class IndividualBank {
|
||||
}
|
||||
}
|
||||
numberOfAccounts = accounts.accountsList.size();
|
||||
} else {
|
||||
accounts = new Accounts();
|
||||
numberOfAccounts = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
package jesse.keeblarcraft.Commands;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
|
||||
|
@ -31,7 +31,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import jesse.keeblarcraft.Keeblarcraft;
|
||||
import jesse.keeblarcraft.ChatStuff.ChatMsg;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
@ -45,6 +44,7 @@ public class ConfigManager {
|
||||
// Get a File reference to a file that is created on disk
|
||||
private File GetFile(String confFile) {
|
||||
File file = null;
|
||||
System.out.println("Get file called for " + GLOBAL_CONFIG + confFile);
|
||||
try {
|
||||
file = new File(GLOBAL_CONFIG + confFile);
|
||||
} catch (Exception e) {}
|
||||
@ -284,7 +284,6 @@ public class ConfigManager {
|
||||
public <T> T GetJsonObjectFromFile(String fileName, Class<T> classToConvertTo) throws JsonSyntaxException {
|
||||
Gson gson = new Gson();
|
||||
String ret = "";
|
||||
fileName = "config/keeblarcraft/" + fileName;
|
||||
|
||||
// hot fix: Not sure how to return "false" for invalid conversion when I'm forced to convert or just catch... Look into a better
|
||||
// return value in the future - but for now throw JsonSyntaxException no matter what exception is caught
|
||||
|
@ -45,7 +45,6 @@ public class GeneralConfig {
|
||||
try {
|
||||
config = cfgMgr.GetJsonObjectFromFile("general.json", ImplementedConfig.class);
|
||||
|
||||
System.out.println("Read in config. Random value: " + config.global_spawn.x);
|
||||
existingFile = true;
|
||||
} catch(Exception e) {
|
||||
System.out.println("FAILED TO READ IN GENERALCONFIG");
|
||||
@ -87,6 +86,15 @@ public class GeneralConfig {
|
||||
FlashConfig();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// @fn GetSQLPassword
|
||||
///
|
||||
/// @brief Returns the SQL password set in the text config
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public String GetSQLPassword() {
|
||||
return config.sqlPassword;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// @fn IsNewPlayer
|
||||
///
|
||||
@ -125,6 +133,7 @@ public class GeneralConfig {
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
private class ImplementedConfig {
|
||||
public String MOTD = "Welcome to the server! Have fun!";
|
||||
public String sqlPassword = "PUT SQL PASSWORD HERE";
|
||||
|
||||
// This is lazy, but this will fill with every unique UUID that has joined the server. This is how I am checking
|
||||
// to see if a player has just joined the server for a first time or not
|
||||
|
47
src/main/java/jesse/keeblarcraft/ConfigMgr/SQLConfig.java
Normal file
47
src/main/java/jesse/keeblarcraft/ConfigMgr/SQLConfig.java
Normal file
@ -0,0 +1,47 @@
|
||||
package jesse.keeblarcraft.ConfigMgr;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class SQLConfig {
|
||||
private static SQLConfig static_inst;
|
||||
|
||||
public static SQLConfig GetInstance() {
|
||||
if (static_inst == null) {
|
||||
static_inst = new SQLConfig();
|
||||
}
|
||||
|
||||
return static_inst;
|
||||
}
|
||||
|
||||
Connection conn = null;
|
||||
|
||||
public SQLConfig() {
|
||||
Boolean canConnect = false;
|
||||
try {
|
||||
// According to some random online tutorial; this loads the driver!
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
canConnect = true;
|
||||
} catch (Exception e) {
|
||||
System.out.println("Could not find the proper SQL JDBC Drivers. Cannot connect to SQL Config");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (canConnect) {
|
||||
try {
|
||||
conn = DriverManager.getConnection("jdbc:mysql://localhost/keeblarcraft", "keeblarcraft", GeneralConfig.GetInstance().GetSQLPassword());
|
||||
Statement stmnt = conn.createStatement();
|
||||
String testSql = "SELECT * FROM test_table";
|
||||
ResultSet rs = stmnt.executeQuery(testSql);
|
||||
|
||||
System.out.println("Printing out result set from test query");
|
||||
while (rs.next()) {
|
||||
System.out.println("[RS]: " + rs.getString("test_name"));
|
||||
}
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
}
|
||||
}
|
@ -40,6 +40,7 @@ import jesse.keeblarcraft.AttributeMgr.AttributeMgr;
|
||||
import jesse.keeblarcraft.AttributeMgr.AttributeTree;
|
||||
import jesse.keeblarcraft.BankMgr.BankManager;
|
||||
import jesse.keeblarcraft.Commands.CustomCommandManager;
|
||||
import jesse.keeblarcraft.ConfigMgr.SQLConfig;
|
||||
import jesse.keeblarcraft.CustomBlocks.BlockList;
|
||||
import jesse.keeblarcraft.CustomBlocks.BlockEntities.BlockEntityRegistration;
|
||||
import jesse.keeblarcraft.CustomItems.ItemManager;
|
||||
@ -118,6 +119,9 @@ public class Keeblarcraft implements ModInitializer {
|
||||
// Register the banking system
|
||||
BankManager.GetInstance().InitializeBanks();
|
||||
|
||||
System.out.println("Attempting SQL Registration call");
|
||||
SQLConfig.GetInstance();
|
||||
|
||||
|
||||
/// THE BELOW ITEMS MUST BE DONE LAST IN THE STEPS
|
||||
// Register items
|
||||
|
Loading…
Reference in New Issue
Block a user