diff --git a/.gitignore b/.gitignore
index 9c787fd..6c5cdb2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,18 +1,84 @@
-### Maven template
-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
-
-# IntelliJ project files
-.idea
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+# User-specific stuff
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/**/usage.statistics.xml
+.idea/**/dictionaries
+.idea/**/shelf
+
+# AWS User-specific
+.idea/**/aws.xml
+
+# Generated files
+.idea/**/contentModel.xml
+
+# Sensitive or high-churn files
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+.idea/**/dbnavigator.xml
+
+# Gradle
+.idea/**/gradle.xml
+.idea/**/libraries
+
+# Gradle and Maven with auto-import
+# When using Gradle or Maven with auto-import, you should exclude module files,
+# since they will be recreated, and may cause churn. Uncomment if using
+# auto-import.
+.idea/artifacts
+.idea/compiler.xml
+.idea/jarRepositories.xml
+.idea/modules.xml
+.idea/*.iml
+.idea/modules
*.iml
-out
-gen
+*.ipr
+
+# CMake
+cmake-build-*/
+
+# Mongo Explorer plugin
+.idea/**/mongoSettings.xml
+
+# File-based project format
+*.iws
+
+# IntelliJ
+out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Cursive Clojure plugin
+.idea/replstate.xml
+
+# SonarLint plugin
+.idea/sonarlint/
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+# Editor-based Rest Client
+.idea/httpRequests
+
+# Android studio 3.1+ serialized cache file
+.idea/caches/build_file_checksums.ser
+.gradle/
+
+.idea/
+
+build/
+
+libs/
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..d4b7664
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,33 @@
+plugins {
+ id 'java'
+}
+
+
+allprojects {
+ apply plugin: "java"
+ apply plugin: "idea"
+ apply plugin: "maven-publish"
+
+ archivesBaseName = rootProject.archives_base_name
+ version = rootProject.mod_version
+ group = rootProject.maven_group
+
+ repositories {
+ mavenLocal()
+ mavenCentral()
+ maven { url 'https://jitpack.io' }
+ maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
+ }
+
+ tasks.withType(JavaCompile) {
+ options.encoding = "UTF-8"
+ options.release.set(17)
+ }
+
+
+ java {
+ withSourcesJar()
+ }
+}
+
+
diff --git a/bukkit/pom.xml b/bukkit/pom.xml
index 41764a0..076babe 100644
--- a/bukkit/pom.xml
+++ b/bukkit/pom.xml
@@ -82,7 +82,7 @@
com.github.cryptomorin
XSeries
- 8.6.1
+ 9.4.0
com.github.MilkBowl
diff --git a/core/build.gradle b/core/build.gradle
new file mode 100644
index 0000000..3ea97fc
--- /dev/null
+++ b/core/build.gradle
@@ -0,0 +1,46 @@
+plugins {
+ id "org.jetbrains.kotlin.jvm" version "1.7.10"
+ id "com.github.johnrengelman.shadow" version "7.1.2"
+}
+configurations {
+ shadowCommon
+}
+
+dependencies {
+ compileOnly 'com.google.code.gson:gson:2.8.9'
+ compileOnly 'com.github.thijsa:socket.io-client-java:1.0.3'
+ compileOnly 'org.apache.httpcomponents:httpclient:4.5.13'
+ compileOnly 'org.apache.commons:commons-lang3:3.12.0'
+ compileOnly 'commons-logging:commons-logging:1.2'
+ compileOnly 'org.apache.commons:commons-text:1.10.0'
+ compileOnly 'net.luckperms:api:5.4'
+ compileOnly 'com.github.cryptomorin:XSeries:9.8.1'
+ // log4j wrapper
+ compileOnly 'org.apache.logging.log4j:log4j-api:2.8.1'
+ // slf4j wrapper
+ compileOnly 'org.slf4j:slf4j-api:1.8.0-beta4'
+
+ shadowCommon 'org.apache.httpcomponents:httpclient:4.5.13'
+ shadowCommon 'org.apache.commons:commons-lang3:3.12.0'
+ shadowCommon 'org.apache.commons:commons-text:1.10.0'
+ shadowCommon 'com.github.thijsa:socket.io-client-java:1.0.3'
+ shadowCommon 'com.github.cryptomorin:XSeries:9.8.1'
+}
+
+shadowJar {
+ configurations = [project.configurations.shadowCommon]
+
+ relocate 'org.apache.http', 'net.craftingstore.libraries.apache.http'
+ relocate 'org.apache.commons.lang3', 'net.craftingstore.libraries.apache.commons.lang3'
+ relocate 'org.apache.commons.logging', 'net.craftingstore.libraries.apache.commons.logging'
+ relocate 'org.apache.commons.codec', 'net.craftingstore.libraries.apache.commons.codec'
+ relocate 'org.apache.commons.text', 'net.craftingstore.libraries.apache.commons.text'
+ relocate 'org.json', 'net.craftingstore.libraries.json'
+ relocate 'io.socket', 'net.craftingstore.libraries.socket'
+ relocate 'okhttp3', 'net.craftingstore.libraries.okhttp3'
+ relocate 'okio', 'net.craftingstore.libraries.okio'
+ relocate 'com.cryptomorin.xseries', 'net.craftingstore.libraries.xseries'
+}
+
+
+jar.finalizedBy('shadowJar')
diff --git a/core/pom.xml b/core/pom.xml
index d03a415..c74e910 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -36,7 +36,7 @@
com.google.code.gson
gson
- 2.8.0
+ 2.8.9
provided
@@ -62,7 +62,7 @@
org.apache.commons
commons-text
- 1.9
+ 1.10.0
\ No newline at end of file
diff --git a/core/src/main/java/net/craftingstore/core/logging/CraftingStoreLogger.java b/core/src/main/java/net/craftingstore/core/logging/CraftingStoreLogger.java
index 74f056b..13cd496 100644
--- a/core/src/main/java/net/craftingstore/core/logging/CraftingStoreLogger.java
+++ b/core/src/main/java/net/craftingstore/core/logging/CraftingStoreLogger.java
@@ -5,8 +5,10 @@ public abstract class CraftingStoreLogger {
private boolean debugging;
public abstract void info(String message);
+ public abstract void info(String message, Throwable throwable);
public abstract void error(String message);
+ public abstract void error(String message, Throwable throwable);
public void debug(String message) {
if (this.debugging) {
@@ -14,6 +16,12 @@ public void debug(String message) {
}
}
+ public void debug(String message, Throwable throwable) {
+ if (this.debugging) {
+ this.info(message, throwable);
+ }
+ }
+
public void setDebugging(boolean debugging) {
this.debugging = debugging;
if (debugging) {
diff --git a/core/src/main/java/net/craftingstore/core/logging/impl/JavaLogger.java b/core/src/main/java/net/craftingstore/core/logging/impl/JavaLogger.java
index e973a4f..07e1a84 100644
--- a/core/src/main/java/net/craftingstore/core/logging/impl/JavaLogger.java
+++ b/core/src/main/java/net/craftingstore/core/logging/impl/JavaLogger.java
@@ -2,22 +2,28 @@
import net.craftingstore.core.logging.CraftingStoreLogger;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class JavaLogger extends CraftingStoreLogger {
- private Logger logger;
+ public Logger LOGGER = LoggerFactory.getLogger("CraftingStore");
public JavaLogger(Logger logger) {
- this.logger = logger;
+ this.LOGGER = logger;
}
public void info(String message) {
- logger.info(message);
+ LOGGER.info(message);
}
-
- public void error(String message) {
- logger.log(Level.SEVERE, message);
+ public void info(String message, Throwable throwable) {
+ LOGGER.info(message, throwable);
}
+
+ public void warn(String message) {LOGGER.warn(message);}
+
+ public void warn(String message, Throwable throwable) {LOGGER.warn(message, throwable);}
+
+ public void error(String message) { LOGGER.error(message); }
+ public void error(String message, Throwable throwable) { LOGGER.error(message, throwable); }
}
diff --git a/fabric/.gitignore b/fabric/.gitignore
new file mode 100644
index 0000000..12f4d9c
--- /dev/null
+++ b/fabric/.gitignore
@@ -0,0 +1,81 @@
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+# User-specific stuff
+.idea/
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/**/usage.statistics.xml
+.idea/**/dictionaries
+.idea/**/shelf
+
+# AWS User-specific
+.idea/**/aws.xml
+
+# Generated files
+.idea/**/contentModel.xml
+
+# Sensitive or high-churn files
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+.idea/**/dbnavigator.xml
+
+# Gradle
+.idea/**/gradle.xml
+.idea/**/libraries
+
+# Gradle and Maven with auto-import
+# When using Gradle or Maven with auto-import, you should exclude module files,
+# since they will be recreated, and may cause churn. Uncomment if using
+# auto-import.
+.idea/artifacts
+.idea/compiler.xml
+.idea/jarRepositories.xml
+.idea/modules.xml
+.idea/*.iml
+.idea/modules
+*.iml
+*.ipr
+
+# CMake
+cmake-build-*/
+
+# Mongo Explorer plugin
+.idea/**/mongoSettings.xml
+
+# File-based project format
+*.iws
+
+# IntelliJ
+out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Cursive Clojure plugin
+.idea/replstate.xml
+
+# SonarLint plugin
+.idea/sonarlint/
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+# Editor-based Rest Client
+.idea/httpRequests
+
+# Android studio 3.1+ serialized cache file
+.idea/caches/build_file_checksums.ser
+.gradle/
+
+build/
diff --git a/fabric/LICENSE b/fabric/LICENSE
new file mode 100644
index 0000000..a6c495b
--- /dev/null
+++ b/fabric/LICENSE
@@ -0,0 +1,2 @@
+Copyright (c) 2023
+All rights reserved.
diff --git a/fabric/build.gradle b/fabric/build.gradle
new file mode 100644
index 0000000..26d3500
--- /dev/null
+++ b/fabric/build.gradle
@@ -0,0 +1,110 @@
+plugins {
+ id 'fabric-loom' version '1.5-SNAPSHOT'
+ id 'maven-publish'
+ id "org.jetbrains.kotlin.jvm" version "1.7.10"
+ id "com.github.johnrengelman.shadow" version "7.1.2"
+}
+
+configurations {
+ common
+ shadowCommon // Don't use shadow from the shadow plugin since it *excludes* files.
+ compileClasspath.extendsFrom core
+ runtimeClasspath.extendsFrom core
+ developmentFabric.extendsFrom core
+}
+
+dependencies {
+ minecraft "com.mojang:minecraft:${project.minecraft_version}"
+ mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
+ modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
+ modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}"
+
+ //common(project(path: ":core", configuration: "namedElements")) { transitive false }
+ shadowCommon(project(path: ":core", configuration: "shadow")) { transitive false }
+ compileOnly(project(path: ":core"))
+ compileOnly 'net.luckperms:api:5.4'
+}
+
+processResources {
+ inputs.property "version", project.version
+ inputs.property "minecraft_version", project.minecraft_version
+ inputs.property "loader_version", project.fabric_loader_version
+ filteringCharset "UTF-8"
+
+ filesMatching("fabric.mod.json") {
+ expand "version": project.version,
+ "minecraft_version": project.minecraft_version,
+ "loader_version": project.fabric_loader_version
+ }
+}
+
+def targetJavaVersion = 17
+tasks.withType(JavaCompile).configureEach {
+ // ensure that the encoding is set to UTF-8, no matter what the system default is
+ // this fixes some edge cases with special characters not displaying correctly
+ // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
+ // If Javadoc is generated, this must be specified in that task too.
+ it.options.encoding = "UTF-8"
+ if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
+ it.options.release.set(targetJavaVersion)
+ }
+}
+
+java {
+ def javaVersion = JavaVersion.toVersion(targetJavaVersion)
+ if (JavaVersion.current() < javaVersion) {
+ toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
+ }
+ // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
+ // if it is present.
+ // If you remove this line, sources will not be generated.
+ withSourcesJar()
+}
+
+shadowJar {
+ configurations = [project.configurations.shadowCommon]
+ archiveClassifier = "dev-shadow"
+}
+
+remapJar {
+ //injectAccessWidener = true
+ inputFile.set(shadowJar.archiveFile)
+ dependsOn shadowJar
+ archiveClassifier.set("fabric")
+ archiveFileName.set("${project.archivesBaseName}-fabric-${project.version}-${project.minecraft_version}.jar")
+}
+
+jar {
+ from("LICENSE") {
+ rename { "${it}_${project.archivesBaseName}"}
+ }
+}
+
+sourcesJar {
+ def commonSources = project(":core").sourcesJar
+ dependsOn commonSources
+ from commonSources.archiveFile.map { zipTree(it) }
+}
+
+components.java {
+ withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
+ skip()
+ }
+}
+
+// configure the maven publication
+publishing {
+ publications {
+ mavenJava(MavenPublication) {
+ from components.java
+ }
+ }
+
+ // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
+ repositories {
+ // Add repositories to publish to here.
+ // Notice: This block does NOT have the same function as the block in the top level.
+ // The repositories here will be used for publishing your artifact, not for
+ // retrieving dependencies.
+ }
+}
\ No newline at end of file
diff --git a/fabric/src/main/java/network/roanoke/craftingstore/CraftingStoreFabric.java b/fabric/src/main/java/network/roanoke/craftingstore/CraftingStoreFabric.java
new file mode 100644
index 0000000..1b023c0
--- /dev/null
+++ b/fabric/src/main/java/network/roanoke/craftingstore/CraftingStoreFabric.java
@@ -0,0 +1,37 @@
+package network.roanoke.craftingstore;
+
+import net.craftingstore.core.CraftingStore;
+import network.roanoke.craftingstore.commands.CraftingStoreCommand;
+import net.fabricmc.api.ModInitializer;
+import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
+import net.minecraft.server.MinecraftServer;
+import network.roanoke.craftingstore.utils.Config;
+
+public class CraftingStoreFabric implements ModInitializer {
+
+ private CraftingStore craftingStore;
+ private MinecraftServer server;
+ public Config config = new Config();
+
+ @Override
+ public void onInitialize() {
+ this.craftingStore = new CraftingStore(new CraftingStoreFabricImpl(this));
+ new CraftingStoreCommand(this);
+
+ ServerLifecycleEvents.SERVER_STARTED.register(server -> {
+ this.server = server;
+ });
+ }
+
+ public MinecraftServer getServer() {
+ return this.server;
+ }
+
+ public CraftingStore getCraftingStore() {
+ return this.craftingStore;
+ }
+
+ public void setApiKey(String apiKey) {
+ this.config.setApiKey(apiKey);
+ }
+}
diff --git a/fabric/src/main/java/network/roanoke/craftingstore/CraftingStoreFabricImpl.java b/fabric/src/main/java/network/roanoke/craftingstore/CraftingStoreFabricImpl.java
new file mode 100644
index 0000000..92c8e28
--- /dev/null
+++ b/fabric/src/main/java/network/roanoke/craftingstore/CraftingStoreFabricImpl.java
@@ -0,0 +1,112 @@
+package network.roanoke.craftingstore;
+
+import com.mojang.brigadier.CommandDispatcher;
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
+import net.craftingstore.core.CraftingStorePlugin;
+import net.craftingstore.core.PluginConfiguration;
+import net.craftingstore.core.logging.CraftingStoreLogger;
+import net.craftingstore.core.logging.impl.JavaLogger;
+import net.craftingstore.core.models.donation.Donation;
+import net.minecraft.server.command.ServerCommandSource;
+import net.minecraft.server.network.ServerPlayerEntity;
+import network.roanoke.craftingstore.utils.MultiThreading;
+import org.slf4j.LoggerFactory;
+
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+public class CraftingStoreFabricImpl implements CraftingStorePlugin {
+
+ private final CraftingStoreFabric fabricPlugin;
+ private final JavaLogger logger;
+ private final PluginConfiguration pluginConfiguration;
+
+ CraftingStoreFabricImpl(CraftingStoreFabric fabricPlugin) {
+ this.fabricPlugin = fabricPlugin;
+ this.logger = new JavaLogger(LoggerFactory.getLogger("CraftingStore"));
+ this.pluginConfiguration = new FabricPluginConfiguration(fabricPlugin);
+ }
+
+ @Override
+ public boolean executeDonation(Donation donation) {
+ final var id = String.format("%s/%s", donation.getPaymentId(), donation.getCommandId());
+
+ UUID userUUID;
+ if (donation.getPlayer().getUsername() != null && donation.getPlayer().getUUID() == null) {
+
+ ServerPlayerEntity serverPlayer = fabricPlugin.getServer()
+ .getPlayerManager()
+ .getPlayer(donation.getPlayer().getUsername());
+
+ if (serverPlayer != null) {
+ userUUID = serverPlayer.getUuid();
+ } else {
+ userUUID = donation.getPlayer().getUUID();
+ }
+
+ } else {
+ userUUID = donation.getPlayer().getUUID();
+ }
+
+ this.getLogger().info(String.format("Donation (%s) > Package: %s, PlayerName: %s, PlayerUUID: %s",
+ id, donation.getPackage().getName(), donation.getPlayer().getUsername(), userUUID));
+ this.getLogger().info(String.format("Donation (%s) > Command: %s", id, donation.getCommand()));
+
+ if (donation.getPlayer().isRequiredOnline()) {
+ if (fabricPlugin.getServer().getPlayerManager().getPlayerList().stream().noneMatch(player -> player.getUuid().equals(userUUID))) {
+ this.getLogger().info(String.format("Donation (%s) > Player not online!!", id));
+ return false;
+ }
+ }
+
+ var success = new AtomicBoolean(false);
+ var finished = new AtomicBoolean(false);
+
+ fabricPlugin.getServer().execute(() -> {
+ CommandDispatcher dispatcher = fabricPlugin.getServer().getCommandManager().getDispatcher();
+ try {
+ dispatcher.execute(donation.getCommand(), fabricPlugin.getServer().getCommandSource());
+ success.set(true);
+ } catch (CommandSyntaxException e) {
+ this.getLogger().error(String.format("Donation (%s) > Running command for Package: %s, Player: %s, Command: %s",
+ id, donation.getPackage().getName(), donation.getPlayer().getUsername(), donation.getCommand()), e);
+ success.set(false);
+ } finally {
+ finished.set(true);
+ }
+ });
+
+ while (!finished.get()) {
+ Thread.onSpinWait();
+ }
+
+ this.getLogger().info(String.format("Donation (%s) > Result: %s", id, success.get()));
+ return success.get();
+ }
+
+ @Override
+ public CraftingStoreLogger getLogger() {
+ return this.logger;
+ }
+
+ @Override
+ public void registerRunnable(Runnable runnable, int i, int i1) {
+ MultiThreading.schedule(runnable, i, i1, TimeUnit.SECONDS);
+ }
+
+ @Override
+ public void runAsyncTask(Runnable runnable) {
+ MultiThreading.runAsync(runnable);
+ }
+
+ @Override
+ public String getToken() {
+ return fabricPlugin.config.getApiKey();
+ }
+
+ @Override
+ public PluginConfiguration getConfiguration() {
+ return this.pluginConfiguration;
+ }
+}
diff --git a/fabric/src/main/java/network/roanoke/craftingstore/FabricPluginConfiguration.java b/fabric/src/main/java/network/roanoke/craftingstore/FabricPluginConfiguration.java
new file mode 100644
index 0000000..7701fa1
--- /dev/null
+++ b/fabric/src/main/java/network/roanoke/craftingstore/FabricPluginConfiguration.java
@@ -0,0 +1,52 @@
+package network.roanoke.craftingstore;
+
+import net.craftingstore.core.PluginConfiguration;
+
+public class FabricPluginConfiguration implements PluginConfiguration {
+
+ private CraftingStoreFabric plugin;
+
+ FabricPluginConfiguration(CraftingStoreFabric plugin) {
+ this.plugin = plugin;
+ }
+
+ @Override
+ public String getName() {
+ return "Fabric";
+ }
+
+ @Override
+ public String[] getMainCommands() {
+ return new String[]{"craftingstore", "cs"};
+ }
+
+ @Override
+ public String getVersion() {
+ return "2.9.3";
+ }
+
+ @Override
+ public String getPlatform() {
+ return "Fabric";
+ }
+
+ @Override
+ public boolean isBuyCommandEnabled() {
+ return false;
+ }
+
+ @Override
+ public int getTimeBetweenCommands() {
+ return 0;
+ }
+
+ @Override
+ public String getNotEnoughBalanceMessage() {
+ return "Not enough balance.";
+ }
+
+ @Override
+ public boolean isUsingAlternativeApi() {
+ return false;
+ }
+}
diff --git a/fabric/src/main/java/network/roanoke/craftingstore/commands/CraftingStoreCommand.java b/fabric/src/main/java/network/roanoke/craftingstore/commands/CraftingStoreCommand.java
new file mode 100644
index 0000000..7a2a8ff
--- /dev/null
+++ b/fabric/src/main/java/network/roanoke/craftingstore/commands/CraftingStoreCommand.java
@@ -0,0 +1,63 @@
+package network.roanoke.craftingstore.commands;
+
+import com.mojang.brigadier.arguments.StringArgumentType;
+import com.mojang.brigadier.context.CommandContext;
+import network.roanoke.craftingstore.CraftingStoreFabric;
+import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
+import net.minecraft.server.command.ServerCommandSource;
+import net.minecraft.text.Text;
+import network.roanoke.craftingstore.utils.Permissions;
+
+import java.util.concurrent.ExecutionException;
+
+import static net.minecraft.server.command.CommandManager.argument;
+import static net.minecraft.server.command.CommandManager.literal;
+
+public class CraftingStoreCommand {
+
+ private CraftingStoreFabric instance;
+ public CraftingStoreCommand(CraftingStoreFabric instance) {
+
+ this.instance = instance;
+
+ CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
+ dispatcher.register(
+ literal("craftingstore")
+ .requires(Permissions.require("craftingstore.admin"))
+ .then(
+ literal("api")
+ .then(argument("api-key", StringArgumentType.string())
+ .executes(this::setApiKey)
+ )
+ )
+ .then(
+ literal("reload")
+ .executes(this::reloadConfig)
+ )
+ );
+ });
+ }
+
+ private int reloadConfig(CommandContext ctx) {
+ instance.getCraftingStore().reload();
+ ctx.getSource().sendMessage(Text.literal("CraftingStore is reloading..."));
+ return 1;
+ }
+
+
+ private int setApiKey(CommandContext ctx) {
+ String apiKey = StringArgumentType.getString(ctx, "api-key");
+ instance.setApiKey(apiKey);
+ instance.config.save();
+ try {
+ if (instance.getCraftingStore().reload().get()) {
+ ctx.getSource().sendMessage(Text.literal("The new API key has been set in the config, and the plugin has been reloaded."));
+ } else {
+ ctx.getSource().sendMessage(Text.literal("The API key is invalid. The plugin will not work until you set a valid API key."));
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ e.printStackTrace();
+ }
+ return 1;
+ }
+}
\ No newline at end of file
diff --git a/fabric/src/main/java/network/roanoke/craftingstore/utils/Config.java b/fabric/src/main/java/network/roanoke/craftingstore/utils/Config.java
new file mode 100644
index 0000000..5745c84
--- /dev/null
+++ b/fabric/src/main/java/network/roanoke/craftingstore/utils/Config.java
@@ -0,0 +1,59 @@
+package network.roanoke.craftingstore.utils;
+
+import net.fabricmc.loader.api.FabricLoader;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Properties;
+
+
+public class Config {
+ private static final Path CONFIG_FILE_PATH = FabricLoader.getInstance().getConfigDir().resolve("CraftingStore/config.properties");
+ private final Properties properties;
+
+ public Config() {
+ properties = new Properties();
+ try {
+ if (Files.exists(CONFIG_FILE_PATH)) {
+ FileInputStream file = new FileInputStream(CONFIG_FILE_PATH.toFile());
+ properties.load(file);
+ file.close();
+ } else {
+ // If the file doesn't exist, create it with default values
+ setApiKey("api-key-here");
+ save();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public String getApiKey() {
+ return properties.getProperty("apiKey");
+ }
+
+ public void setApiKey(String apiKey) {
+ properties.setProperty("apiKey", String.valueOf(apiKey));
+ save();
+ }
+
+ public void save() {
+ try {
+ Files.createDirectories(CONFIG_FILE_PATH.getParent());
+
+ if (!CONFIG_FILE_PATH.toFile().exists()) {
+ Files.createFile(CONFIG_FILE_PATH);
+ }
+
+ try (FileOutputStream file = new FileOutputStream(CONFIG_FILE_PATH.toFile())) {
+ properties.store(file, null);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/fabric/src/main/java/network/roanoke/craftingstore/utils/MultiThreading.java b/fabric/src/main/java/network/roanoke/craftingstore/utils/MultiThreading.java
new file mode 100644
index 0000000..40c275c
--- /dev/null
+++ b/fabric/src/main/java/network/roanoke/craftingstore/utils/MultiThreading.java
@@ -0,0 +1,36 @@
+package network.roanoke.craftingstore.utils;
+
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class MultiThreading {
+ private static final AtomicInteger counter = new AtomicInteger(0);
+
+ private static final ScheduledExecutorService RUNNABLE_POOL = Executors.newScheduledThreadPool(10, r ->
+ new Thread(r, "CraftingStore Thread " + counter.incrementAndGet()));
+
+ public static ThreadPoolExecutor POOL = new ThreadPoolExecutor(10, 30,
+ 0L, TimeUnit.SECONDS,
+ new LinkedBlockingQueue<>(),
+ r -> new Thread(r, String.format("Thread %s", counter.incrementAndGet())));
+
+ public static ScheduledFuture> schedule(Runnable r, long initialDelay, long delay, TimeUnit unit) {
+ return RUNNABLE_POOL.scheduleAtFixedRate(r, initialDelay, delay, unit);
+ }
+
+ public static ScheduledFuture> schedule(Runnable r, long delay, TimeUnit unit) {
+ return RUNNABLE_POOL.schedule(r, delay, unit);
+ }
+
+ public static Executor delayedExecutor(long delay, TimeUnit unit) {
+ return task -> schedule(task, delay, unit);
+ }
+
+ public static void runAsync(Runnable runnable) {
+ POOL.execute(runnable);
+ }
+
+ public static Future> submit(Runnable runnable) {
+ return POOL.submit(runnable);
+ }
+}
diff --git a/fabric/src/main/java/network/roanoke/craftingstore/utils/Permissions.java b/fabric/src/main/java/network/roanoke/craftingstore/utils/Permissions.java
new file mode 100644
index 0000000..9b8ebaa
--- /dev/null
+++ b/fabric/src/main/java/network/roanoke/craftingstore/utils/Permissions.java
@@ -0,0 +1,22 @@
+package network.roanoke.craftingstore.utils;
+
+import net.luckperms.api.LuckPermsProvider;
+import net.luckperms.api.model.user.User;
+import net.minecraft.server.command.ServerCommandSource;
+
+import java.util.Objects;
+import java.util.function.Predicate;
+
+public class Permissions {
+ public static Predicate require(String permission) {
+ Objects.requireNonNull(permission, "permission");
+ return source -> {
+ Objects.requireNonNull(source.getEntity());
+ User playerLP = LuckPermsProvider.get().getUserManager().getUser(source.getEntity().getUuid());
+ if (playerLP == null) {
+ return false;
+ }
+ return playerLP.getCachedData().getPermissionData().checkPermission(permission).asBoolean();
+ };
+ }
+}
diff --git a/fabric/src/main/resources/craftingstore.mixins.json b/fabric/src/main/resources/craftingstore.mixins.json
new file mode 100644
index 0000000..df445c8
--- /dev/null
+++ b/fabric/src/main/resources/craftingstore.mixins.json
@@ -0,0 +1,13 @@
+{
+ "required": true,
+ "minVersion": "0.8",
+ "package": "net.craftingstore.craftingstore.fabric.mixin",
+ "compatibilityLevel": "JAVA_17",
+ "mixins": [
+ ],
+ "client": [
+ ],
+ "injectors": {
+ "defaultRequire": 1
+ }
+}
diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json
new file mode 100644
index 0000000..1cc08a2
--- /dev/null
+++ b/fabric/src/main/resources/fabric.mod.json
@@ -0,0 +1,29 @@
+{
+ "schemaVersion": 1,
+ "id": "craftingstore",
+ "version": "${version}",
+
+ "name": "craftingstore",
+ "description": "",
+ "authors": [],
+ "contact": {
+ "repo": "https://github.com/RoanokeNetwork/CraftingStore-Fabric"
+ },
+
+ "license": "All-Rights-Reserved",
+
+ "environment": "server",
+ "entrypoints": {
+ "main": [
+ "network.roanoke.craftingstore.CraftingStoreFabric"
+ ]
+ },
+ "mixins": [
+ "craftingstore.mixins.json"
+ ],
+ "depends": {
+ "fabricloader": ">=0.14.22",
+ "fabric": "*",
+ "minecraft": "1.20.1"
+ }
+}
\ No newline at end of file
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 0000000..1a83e67
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,23 @@
+# The Gradle daemon aims to improve the startup and execution time of Gradle.
+# When set to true the Gradle daemon is to run the build.
+org.gradle.daemon=false
+
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+# Default value: -Xmx10248m -XX:MaxPermSize=256m
+org.gradle.jvmargs=-Xmx1G -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+
+minecraft_version=1.20.1
+yarn_mappings=1.20.1+build.10
+enabled_platforms=fabric,forge
+
+archives_base_name=craftingstore
+mod_version=2.9.3
+maven_group=network.roanoke
+
+architectury_version=9.1.12
+
+fabric_loader_version=0.15.6
+fabric_api_version=0.91.0+1.20.1
+
+forge_version=1.20.1-47.2.20
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..7f93135
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..2bbac7d
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
\ No newline at end of file
diff --git a/gradlew b/gradlew
new file mode 100644
index 0000000..1aa94a4
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,249 @@
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
+##############################################################################
+
+# Attempt to set APP_HOME
+
+# Resolve links: $0 may be a link
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
+done
+
+# This is normally unused
+# shellcheck disable=SC2034
+APP_BASE_NAME=${0##*/}
+# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
+APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD=maximum
+
+warn () {
+ echo "$*"
+} >&2
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+} >&2
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD=$JAVA_HOME/jre/sh/java
+ else
+ JAVACMD=$JAVA_HOME/bin/java
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD=java
+ if ! command -v java >/dev/null 2>&1
+ then
+ die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+fi
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
+fi
+
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
+ fi
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
+ done
+fi
+
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Collect all arguments for the java command:
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
+# and any embedded shellness will be escaped.
+# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
+# treated as '${Hostname}' itself on the command line.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
+fi
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..6689b85
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,92 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%"=="" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if %ERRORLEVEL% equ 0 goto execute
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if %ERRORLEVEL% equ 0 goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/pom.xml b/pom.xml
index cd8f6ce..f1056ea 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
${craftingstore-version}-RELEASE
- 2.9.0
+ 2.9.1
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..a0b4361
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1,12 @@
+pluginManagement {
+ repositories {
+ maven { url "https://maven.fabricmc.net/" }
+ maven { url "https://maven.architectury.dev/" }
+ maven { url "https://maven.minecraftforge.net/" }
+ gradlePluginPortal()
+ }
+}
+
+include("core")
+include("fabric")
+include("assembly")
\ No newline at end of file