Merge pull request #5 from SKBotNL/main
Update DiamondBank-OG API example
This commit was merged in pull request #5.
This commit is contained in:
4 files changed
+34
-50
No files matched your search
+1
-8
@@ -56,9 +56,7 @@ dependencies {
|
||||
compileOnly("io.github.miniplaceholders:miniplaceholders-api:2.2.3") // Import MiniPlaceholders API.
|
||||
compileOnlyApi(project(":libs:Utilities-OG")) // Import TrueOG Network Utilities-OG API.
|
||||
compileOnlyApi(project(":libs:GxUI-OG")) // Import TrueOG Network GxUI-OG API.
|
||||
compileOnlyApi(
|
||||
"net.trueog.diamondbank-og:diamondbank-og:1.19-7957b9127d"
|
||||
) // Import TrueOG Network DiamondBank-OG API.
|
||||
compileOnlyApi(project(":libs:DiamondBank-OG")) // Import TrueOG Network DiamondBank-OG API.
|
||||
}
|
||||
|
||||
tasks.withType<AbstractArchiveTask>().configureEach { // Ensure reproducible .jars
|
||||
@@ -80,16 +78,11 @@ tasks.build {
|
||||
tasks.jar { archiveClassifier.set("part") }
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
dependsOn(":libs:DiamondBank-OG:publishToMavenLocal")
|
||||
options.compilerArgs.addAll(listOf("-parameters", "-Xlint:deprecation")) // Triggers deprecation warning messages.
|
||||
options.encoding = "UTF-8"
|
||||
options.isFork = true
|
||||
}
|
||||
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
|
||||
dependsOn(":libs:DiamondBank-OG:publishToMavenLocal")
|
||||
}
|
||||
|
||||
spotless {
|
||||
java {
|
||||
removeUnusedImports()
|
||||
|
||||
+1
-1
Submodule libs/DiamondBank-OG updated: 677ce502e0...b75844bcf5.
@@ -1,5 +1,7 @@
|
||||
package plugin;
|
||||
|
||||
import net.trueog.diamondbankog.DiamondBankException;
|
||||
import net.trueog.utilitiesog.UtilitiesOG;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@@ -14,50 +16,37 @@ public class Listeners implements Listener {
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
// Make sure to never run any other Bukkit functions in runTaskAsynchronously() (for example accessing players'
|
||||
// inventories)
|
||||
// runTaskAsynchronously() is needed in this case since getPlayerShards().get() calls a database which can be
|
||||
// slow to run on the main thread
|
||||
/*Bukkit.getScheduler().runTaskAsynchronously(TemplateOG.getPlugin(), () -> {
|
||||
CompletableFuture<PlayerShards> completablePlayerShards;
|
||||
// runTaskAsynchronously() is needed in this case since getTotalShards() calls a database which can be
|
||||
// too slow to run on the main thread
|
||||
Bukkit.getScheduler().runTaskAsynchronously(TemplateOG.getPlugin(), () -> {
|
||||
int totalShards;
|
||||
try {
|
||||
completablePlayerShards = TemplateOG.diamondBankAPI()
|
||||
.getPlayerShards(event.getPlayer().getUniqueId(), ShardType.ALL);
|
||||
totalShards = TemplateOG.diamondBankAPI()
|
||||
.getTotalShards(event.getPlayer().getUniqueId());
|
||||
} catch (DiamondBankException.EconomyDisabledException e) {
|
||||
UtilitiesOG.trueogMessage(event.getPlayer(), "<red>The economy is disabled.");
|
||||
return;
|
||||
} catch (DiamondBankException.TransactionsLockedException e) {
|
||||
UtilitiesOG.trueogMessage(event.getPlayer(), "<red>Your transactions are locked.");
|
||||
UtilitiesOG.trueogMessage(event.getPlayer(), "<red>Transactions are currently locked for you.");
|
||||
return;
|
||||
} catch (DiamondBankException.OtherException e) {
|
||||
UtilitiesOG.trueogMessage(event.getPlayer(), "<red>Something went wrong.");
|
||||
} catch (DiamondBankException.DatabaseException e) {
|
||||
UtilitiesOG.trueogMessage(event.getPlayer(), "<red>Something went wrong with the database.");
|
||||
return;
|
||||
}
|
||||
// If you don't care about the specific exceptions you can also do the following:
|
||||
// try {
|
||||
// totalShards = TemplateOG.diamondBankAPI().getTotalShards(event.getPlayer().getUniqueId());
|
||||
// } catch (DiamondBankException e) {
|
||||
// UtilitiesOG.trueogMessage(event.getPlayer(), "<red>Something went wrong.");
|
||||
// }
|
||||
|
||||
try {
|
||||
PlayerShards playerShardsResult = completablePlayerShards.get();
|
||||
if (playerShardsResult.getShardsInBank() == null
|
||||
|| playerShardsResult.getShardsInInventory() == null
|
||||
|| playerShardsResult.getShardsInEnderChest() == null) {
|
||||
UtilitiesOG.trueogMessage(event.getPlayer(), "<red>An error has occurred.");
|
||||
return;
|
||||
}
|
||||
double totalBalance = playerShardsResult.getShardsInBank()
|
||||
+ playerShardsResult.getShardsInInventory()
|
||||
+ playerShardsResult.getShardsInEnderChest();
|
||||
|
||||
// Send a message to the player with their balance.
|
||||
UtilitiesOG.trueogMessage(event.getPlayer(), "&BYour balance is: &e" + totalBalance + "&B Diamonds.");
|
||||
UtilitiesOG.logToConsole(
|
||||
"[Template-OG]",
|
||||
"The player: " + event.getPlayer() + "'s <aqua>balance</aqua> is: " + totalBalance
|
||||
+ "&B Diamonds");
|
||||
|
||||
} catch (InterruptedException | ExecutionException error) {
|
||||
UtilitiesOG.logToConsole(
|
||||
"[Template-OG]",
|
||||
"ERROR: The player: " + event.getPlayer() + "'s balance could not be fetched! ERROR: "
|
||||
+ error.getMessage());
|
||||
}
|
||||
});*/
|
||||
// Send a message to the player with their balance.
|
||||
UtilitiesOG.trueogMessage(event.getPlayer(), "&BYour balance is: &e" + totalShards + "&B Diamond Shards.");
|
||||
UtilitiesOG.logToConsole(
|
||||
"[Template-OG]",
|
||||
"The player: " + event.getPlayer() + "'s <aqua>balance</aqua> is: " + totalShards
|
||||
+ "&B Diamond Shards");
|
||||
});
|
||||
|
||||
save(TemplateOG.config(), Bukkit.getOfflinePlayer("TheMonsterEric"));
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package plugin;
|
||||
|
||||
// import net.trueog.diamondbankog.DiamondBankAPIJava;
|
||||
import net.trueog.diamondbankog.DiamondBankAPIJava;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class TemplateOG extends JavaPlugin {
|
||||
|
||||
private static TemplateOG plugin;
|
||||
// private static DiamondBankAPIJava diamondBankAPI;
|
||||
private static DiamondBankAPIJava diamondBankAPI;
|
||||
private static FileConfiguration config;
|
||||
|
||||
@Override
|
||||
@@ -20,7 +22,7 @@ public class TemplateOG extends JavaPlugin {
|
||||
|
||||
getServer().getPluginManager().registerEvents(new Listeners(), this);
|
||||
|
||||
/*RegisteredServiceProvider<DiamondBankAPIJava> provider =
|
||||
RegisteredServiceProvider<DiamondBankAPIJava> provider =
|
||||
getServer().getServicesManager().getRegistration(DiamondBankAPIJava.class);
|
||||
|
||||
if (provider == null) {
|
||||
@@ -28,16 +30,16 @@ public class TemplateOG extends JavaPlugin {
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
diamondBankAPI = provider.getProvider();*/
|
||||
diamondBankAPI = provider.getProvider();
|
||||
}
|
||||
|
||||
public static TemplateOG getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/*public static DiamondBankAPIJava diamondBankAPI() {
|
||||
public static DiamondBankAPIJava diamondBankAPI() {
|
||||
return diamondBankAPI;
|
||||
}*/
|
||||
}
|
||||
|
||||
public static FileConfiguration config() {
|
||||
return config;
|
||||
|
||||
Reference in new issue
Block a user