Skip to content

Commit

Permalink
Fixes stupid SQL error
Browse files Browse the repository at this point in the history
  • Loading branch information
ImNotStable committed Mar 28, 2024
1 parent fe4cb8a commit 375c3ef
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 28 deletions.
117 changes: 113 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,113 @@
# Project exclude paths
/.idea/
/target/
/QualityEconomy.iml
# User-specific stuff
.idea/

*.iml
*.ipr
*.iws

# IntelliJ
out/

# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

target/

pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next

release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
.flattened-pom.xml

# Common working directory
run/
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ public static void sendParsedMessage(CommandSender sender, MessageType id, Strin
}

public static Component getParsedMessage(MessageType id, String... tags) {
String message = QualityEconomy.getQualityMessages().MESSAGES.get(id.getValue());
if (tags.length == 0)
return MiniMessage.miniMessage().deserialize(QualityEconomy.getQualityMessages().MESSAGES.get(id.getValue()));
return MiniMessage.miniMessage().deserialize(message);
if (tags.length % 2 != 0)
throw new IllegalArgumentException("Invalid number of tags, found odd length when even is required");
TagResolver[] tagResolvers = new TagResolver[tags.length / 2];
for (int i = 0; i < tags.length; i += 2)
tagResolvers[i / 2] = TagResolver.resolver(tags[i], Tag.selfClosingInserting(Component.text(tags[i + 1])));
return MiniMessage.miniMessage().deserialize(QualityEconomy.getQualityMessages().MESSAGES.get(id.getValue()), tagResolvers);
return MiniMessage.miniMessage().deserialize(message, tagResolvers);
}

public void load() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import com.imnotstable.qualityeconomy.util.Misc;
import com.imnotstable.qualityeconomy.util.Number;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
Expand All @@ -21,12 +19,7 @@ public class PlaceholderHook {
public static boolean load() {
if (!Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI"))
return false;

if (new HookProvider().register()) {
Debug.Logger.log(Component.text("Successfully registered expansion with PlaceholderAPI", NamedTextColor.GREEN));
return true;
}
return false;
return new HookProvider().register();
}

private static class HookProvider extends PlaceholderExpansion {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.imnotstable.qualityeconomy.util.Debug;
import com.imnotstable.qualityeconomy.util.Number;
import com.imnotstable.qualityeconomy.util.QualityException;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -40,7 +38,6 @@ public static boolean load() {

economyProvider = registeredServiceProvider.getProvider();

Debug.Logger.log(Component.text("Successfully registered economy with Vault", NamedTextColor.GREEN));
return true;
} catch (QualityException exception) {
new Debug.QualityError("Failed to register QualityEconomy with Vault", exception).log();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public boolean initStorageProcesses() {
createPlayerDataTable(connection);
toggleCurrencyTable(connection);
toggleColumns(connection);
columns = getColumns(connection);
generateStatements();
} catch (SQLException exception) {
new Debug.QualityError("Error while initiating storage processes", exception).log();
return false;
Expand Down Expand Up @@ -76,10 +78,10 @@ public synchronized void createAccount(@NotNull Account account) {
int affectedRows = preparedStatement.executeUpdate();

if (affectedRows == 0) {
new Debug.QualityError("Failed to create account (" + account.getUniqueId().toString() + ")").log();
new Debug.QualityError("Failed to create account (" + account.getUniqueId() + ")").log();
}
} catch (SQLException exception) {
new Debug.QualityError("Failed to create account (" + account.getUniqueId().toString() + ")", exception).log();
new Debug.QualityError("Failed to create account (" + account.getUniqueId() + ")", exception).log();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.Getter;
import org.apache.logging.log4j.util.Strings;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
Expand Down Expand Up @@ -54,13 +55,6 @@ protected Connection getConnection() throws SQLException {

protected void open() {
openDataSource();
try (Connection connection = getConnection()) {
columns = getColumns(connection);
} catch (SQLException exception) {
new Debug.QualityError("Failed to start database", exception).log();
return;
}
generateStatements();
}

protected void close() {
Expand Down Expand Up @@ -173,16 +167,20 @@ protected void createAccountSetter(PreparedStatement preparedStatement, Account
preparedStatement.setString(1, uuid.toString());
preparedStatement.setString(2, account.getUsername());
preparedStatement.setDouble(3, account.getBalance());
if (QualityEconomy.getQualityConfig().COMMANDS_PAY)
Debug.Logger.log(Strings.join(columns, ','));
Debug.Logger.log(uuid + "," + account.getUsername() + "," + account.getBalance());
if (QualityEconomy.getQualityConfig().COMMANDS_PAY) {
Debug.Logger.log("isPayable: " + account.isPayable());
preparedStatement.setBoolean(columns.indexOf("PAYABLE") + 1, account.isPayable());
}
if (QualityEconomy.getQualityConfig().COMMANDS_REQUEST)
preparedStatement.setBoolean(columns.indexOf("REQUESTABLE") + 1, account.isRequestable());
if (QualityEconomy.getQualityConfig().CUSTOM_CURRENCIES)
for (String currency : currencies)
preparedStatement.setDouble(columns.indexOf(currency) + 1, account.getCustomBalance(currency));
}

private void generateStatements() {
protected void generateStatements() {
//Create Account
StringBuilder insert1 = new StringBuilder("UUID,USERNAME,BALANCE");
StringBuilder insert2 = new StringBuilder("?,?,?");
Expand Down

0 comments on commit 375c3ef

Please sign in to comment.