Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,25 @@ run/

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Gradle
.gradle/
build/
*/build/

# IDE files
.idea/
*.iml
*.ipr
*.iws
out/
local.properties

# Build outputs
output/
*.jar
*.log

# OS generated files
*~
*.swp
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Original Mod Made by jblemee

https://github.com/jblemee/RealEconomy


# RealEconomy

Expand Down
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
plugins {
id 'dev.architectury.loom' version '1.10-SNAPSHOT' apply false
id 'dev.architectury.loom' version '1.7-SNAPSHOT' apply false
id 'architectury-plugin' version '3.4-SNAPSHOT'
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
}

architectury {
minecraft = rootProject.minecraft_version
minecraft = project.minecraft_version
}

allprojects {
Expand Down Expand Up @@ -33,7 +33,6 @@ subprojects {
dependencies {
minecraft "net.minecraft:minecraft:$rootProject.minecraft_version"
mappings loom.officialMojangMappings()
// mappings "net.fabricmc:yarn:${yarnVersion}:v2"
}

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ public abstract class AccountManager {
* @return true if the player has an account.
*/
public static boolean hasAccount(String username) {
for (String name : accounts.keySet()) {
if (name.equalsIgnoreCase(username)) {
return true;
}
}
return false;
return accounts.containsKey(username.toLowerCase());
}

/**
Expand All @@ -61,12 +56,7 @@ public static boolean hasAccount(UUID uuid) {
* @return the account of the player requested.
*/
public static Account getAccount(String username) {
for (String name : accounts.keySet()) {
if (name.equalsIgnoreCase(username)) {
return accounts.get(name);
}
}
return null;
return accounts.get(username.toLowerCase());
}

/**
Expand Down Expand Up @@ -96,15 +86,34 @@ public static ArrayList<Account> getAllAccounts() {
* @return true if the account was successfully updated.
*/
public static boolean updateAccount(Account account) {
Account oldAccount = accounts.get(account.getUsername());
accounts.remove(account.getUsername());
accounts.put(account.getUsername(), account);
// Find the existing key case-insensitively for removal
String oldKey = null;
for (String key : accounts.keySet()) {
if (key.equalsIgnoreCase(account.getUsername())) {
oldKey = key;
break;
}
}

Account oldAccount = null;
if (oldKey != null) {
oldAccount = accounts.remove(oldKey);
}

// If oldAccount is null and we are trying to update, it might be a new account or a name change scenario.
// For a name change, the UUID would match. Let's assume 'account' has the new username.
// We'll put the account with the new username, lowercased.

accounts.put(account.getUsername().toLowerCase(), account);
Gson gson = Utils.newGson();
boolean success = Utils.writeFileAsync("accounts/", account.getUUID().toString() + ".json",
gson.toJson(new AccountFile(account)));
if (!success) {
accounts.remove(account.getUsername());
accounts.put(account.getUsername(), oldAccount);
// Rollback
accounts.remove(account.getUsername().toLowerCase());
if (oldAccount != null && oldKey != null) { // If we successfully removed an old entry
accounts.put(oldKey, oldAccount);
}
ErrorManager.addError("Failed to write account to storage for account: " + account.getUsername());
RealEconomy.LOGGER.error("Failed to write account to storage for account: " + account.getUsername());
return false;
Expand All @@ -120,11 +129,14 @@ public static boolean updateAccount(Account account) {
* @return the create account.
*/
public static boolean createAccount(UUID uuid, String username) {
accounts.put(username, new Account(uuid, username));
String lowerCaseUsername = username.toLowerCase();
accounts.put(lowerCaseUsername, new Account(uuid, username)); // Store original case username in Account object
Gson gson = Utils.newGson();
boolean success = Utils.writeFileAsync("accounts/", getAccount(username).getUUID().toString() + ".json",
gson.toJson(new AccountFile(accounts.get(username))));
// Use the username from the account object for AccountFile, which might have original casing
boolean success = Utils.writeFileAsync("accounts/", getAccount(lowerCaseUsername).getUUID().toString() + ".json",
gson.toJson(new AccountFile(accounts.get(lowerCaseUsername))));
if (!success) {
accounts.remove(lowerCaseUsername);
ErrorManager.addError("Failed to write account to storage for account: " + username);
RealEconomy.LOGGER.error("Failed to write account to storage for account: " + username);
return false;
Expand Down Expand Up @@ -158,7 +170,7 @@ public static void initialise() {
String[] list = dir.list();

// If no files, return.
if (list.length == 0) {
if (list == null || list.length == 0) { // Added null check for list
return;
}

Expand All @@ -168,11 +180,13 @@ public static void initialise() {
Gson gson = Utils.newGson();
AccountFile accountFile = gson.fromJson(el, AccountFile.class);
// Add the account to accounts hashmap.
accounts.put(accountFile.getUsername(), new Account(accountFile));
// Use toLowerCase for the key, but Account object stores original username from file
accounts.put(accountFile.getUsername().toLowerCase(), new Account(accountFile));
}));
}
} catch (Exception e) {
e.printStackTrace();
// It's good practice to log the exception or handle it more gracefully
RealEconomy.LOGGER.error("Error during AccountManager initialisation: ", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public LiteralCommandNode<CommandSourceStack> build() {
// for (String name : ctx.getSource().getOnlinePlayerNames()) {
// builder.suggest(name);
// }
// return builder.buildFuture();
// return builder.buildFuture();
// })
.executes(this::showUsage)
.then(Commands.argument("currency", StringArgumentType.string())
Expand Down Expand Up @@ -93,9 +93,9 @@ public int run(CommandContext<CommandSourceStack> context) {
List<ServerPlayer> playerArguments;
try {
playerArguments = EntityArgument.getPlayers(context, "player").stream().toList();
playerArguments.forEach(player -> pay(context, playerSource, isPlayer, player.getDisplayName().getString()));
playerArguments.forEach(player -> pay(context, playerSource, isPlayer, player.getGameProfile().getName())); // Changed from getDisplayName().getString()
} catch (CommandSyntaxException ex) {
String playerArg = context.getInput().split(" ")[1];
String playerArg = context.getInput().split(" ")[2]; // Changed from 1 to 2
pay(context, playerSource, isPlayer, playerArg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public LiteralCommandNode<CommandSourceStack> build() {
// for (String name : ctx.getSource().getOnlinePlayerNames()) {
// builder.suggest(name);
// }
// return builder.buildFuture();
// return builder.buildFuture();
// })
.executes(this::showUsage)
.then(Commands.argument("currency", StringArgumentType.string())
Expand Down Expand Up @@ -83,9 +83,9 @@ public int run(CommandContext<CommandSourceStack> context) {
List<ServerPlayer> playerArguments;
try {
playerArguments = EntityArgument.getPlayers(context, "player").stream().toList();
playerArguments.forEach(player -> pay(context, playerSource, isPlayer, player.getDisplayName().getString()));
playerArguments.forEach(player -> pay(context, playerSource, isPlayer, player.getGameProfile().getName())); // Changed to getGameProfile().getName()
} catch (CommandSyntaxException ex) {
String playerArg = context.getInput().split(" ")[1];
String playerArg = context.getInput().split(" ")[2]; // Changed index from 1 to 2
pay(context, playerSource, isPlayer, playerArg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public LiteralCommandNode<CommandSourceStack> build() {
// for (String name : ctx.getSource().getOnlinePlayerNames()) {
// builder.suggest(name);
// }
// return builder.buildFuture();
// return builder.buildFuture();
// })
.executes(this::showUsage)
.then(Commands.argument("currency", StringArgumentType.string())
Expand Down Expand Up @@ -93,9 +93,9 @@ public int run(CommandContext<CommandSourceStack> context) {
List<ServerPlayer> playerArguments;
try {
playerArguments = EntityArgument.getPlayers(context, "player").stream().toList();
playerArguments.forEach(player -> pay(context, playerSource, isPlayer, player.getDisplayName().getString()));
playerArguments.forEach(player -> pay(context, playerSource, isPlayer, player.getGameProfile().getName())); // Changed to getGameProfile().getName()
} catch (CommandSyntaxException ex) {
String playerArg = context.getInput().split(" ")[1];
String playerArg = context.getInput().split(" ")[2]; // Changed index from 1 to 2
pay(context, playerSource, isPlayer, playerArg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public LiteralCommandNode<CommandSourceStack> build() {
// for (String name : ctx.getSource().getOnlinePlayerNames()) {
// builder.suggest(name);
// }
// return builder.buildFuture();
// return builder.buildFuture();
// })
.executes(this::showUsage)
.then(Commands.argument("currency", StringArgumentType.string())
Expand Down Expand Up @@ -93,9 +93,9 @@ public int run(CommandContext<CommandSourceStack> context) {
List<ServerPlayer> playerArguments;
try {
playerArguments = EntityArgument.getPlayers(context, "player").stream().toList();
playerArguments.forEach(player -> pay(context, playerSource, isPlayer, player.getDisplayName().getString()));
playerArguments.forEach(player -> pay(context, playerSource, isPlayer, player.getGameProfile().getName())); // Changed to getGameProfile().getName()
} catch (CommandSyntaxException ex) {
String playerArg = context.getInput().split(" ")[1];
String playerArg = context.getInput().split(" ")[2]; // Changed index from 1 to 2
pay(context, playerSource, isPlayer, playerArg);
}
return -1;
Expand Down
19 changes: 14 additions & 5 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,37 @@ architectury {
}

configurations {
common
shadowBundle
common {
canBeResolved = true
canBeConsumed = false
}
compileClasspath.extendsFrom common
runtimeClasspath.extendsFrom common
developmentFabric.extendsFrom common

// Files in this configuration will be bundled into your mod using the Shadow plugin.
// Don't use the `shadow` configuration from the plugin itself as it's meant for excluding files.
shadowBundle {
canBeResolved = true
canBeConsumed = false
}
}

repositories {
mavenCentral()
maven { url 'https://maven.fabricmc.net/' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://maven.nucleoid.xyz/' }
}

dependencies {
modImplementation "net.fabricmc:fabric-loader:$rootProject.fabric_loader_version"
modApi "net.fabricmc.fabric-api:fabric-api:$rootProject.fabric_api_version+$rootProject.minecraft_version"
modImplementation "net.fabricmc.fabric-api:fabric-api:$rootProject.fabric_api_version+$rootProject.minecraft_version"
include(modImplementation("me.lucko:fabric-permissions-api:0.3.1")) { transitive = false }

common(project(path: ':common', configuration: 'namedElements')) { transitive false }
shadowBundle project(path: ':common', configuration: 'transformProductionFabric')

modImplementation include("eu.pb4:placeholder-api:2.4.2+1.21")
modImplementation include("eu.pb4:placeholder-api:2.5.2+1.21.3")
}

processResources {
Expand Down
2 changes: 1 addition & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
},
"depends": {
"fabricloader": ">=0.16.9",
"minecraft": ">=1.21.3"
"minecraft": ">=1.21"
}
}
4 changes: 2 additions & 2 deletions forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ A Minecraft Forge and Fabric economy plugin that supports multiple currencies.
# Does this dependency have to exist - if not, ordering below must be specified
mandatory=true #mandatory
# The version range of the dependency
versionRange="[53,)" #mandatory
versionRange="[52,)" #mandatory
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
ordering="NONE"
# Side this dependency is applied on - BOTH, CLIENT or SERVER
Expand All @@ -61,6 +61,6 @@ A Minecraft Forge and Fabric economy plugin that supports multiple currencies.
modId="minecraft"
mandatory=true
# This version range declares a minimum of the current minecraft version up to but not including the next major version
versionRange="[1.21.3,1.21.4]"
versionRange="[1.21,1.22]"
ordering="NONE"
side="BOTH"
17 changes: 7 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ org.gradle.daemon=false

enabled_platforms=fabric,neoforge,forge

# Mod Properties
archives_name=realeconomy
mod_version=0.1.1
mod_version=1.1.0
maven_group=co.lemee

# Fabric Properties
minecraft_version=1.21.4
yarnVersion=1.21.4+build.4
fabric_loader_version=0.16.14
fabric_api_version=0.119.2
minecraft_version=1.21.1

# Dependencies
forge_version=54.1.3
neoforge_version=21.4.136
fabric_loader_version=0.16.9
fabric_api_version=0.114.0

forge_version=52.1.0
neoforge_version=21.1.170
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 2 additions & 4 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
Empty file modified gradlew
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion neoforge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ description="Create central bank, bank, currency and use it ingame"
[[dependencies.realeconomy]]
modId="minecraft"
type="required"
versionRange="[1.21.3,1.21.5)"
versionRange="[1.21,)"
ordering="NONE"
side="BOTH"