Fixes some problems related to the changed economy class

This commit is contained in:
2025-08-07 20:33:54 +02:00
parent aa02f5ca2b
commit e23e861e32
9 changed files with 11 additions and 21 deletions

View File

@@ -184,7 +184,7 @@ public class BooksWithoutBorders extends JavaPlugin {
String pluginVersion = pluginDescriptionFile.getVersion(); String pluginVersion = pluginDescriptionFile.getVersion();
Translator translator = new Translator(); Translator translator = new Translator();
translator.registerMessageCategory(Translatable.PREFIX); translator.registerMessageCategory(Translatable.SUCCESS_COPY);
stringFormatter = new StringFormatter(this.getDescription().getName(), translator); stringFormatter = new StringFormatter(this.getDescription().getName(), translator);
stringFormatter.setColorConversion(ColorConversion.RGB); stringFormatter.setColorConversion(ColorConversion.RGB);
stringFormatter.setSuccessColor(ChatColor.of("#A9FF84")); stringFormatter.setSuccessColor(ChatColor.of("#A9FF84"));
@@ -290,11 +290,6 @@ public class BooksWithoutBorders extends JavaPlugin {
return false; return false;
} }
//Load config
if (!getConfiguration().loadConfig()) {
return false;
}
//Save config with loaded values to fix invalid config values //Save config with loaded values to fix invalid config values
getConfiguration().saveConfigValues(); getConfiguration().saveConfigValues();

View File

@@ -73,7 +73,7 @@ public class CommandBooksWithoutBorders implements TabExecutor {
} else { } else {
EconomyManager economyManager = BooksWithoutBorders.getConfiguration().getEconomyManager(); EconomyManager economyManager = BooksWithoutBorders.getConfiguration().getEconomyManager();
if (economyManager.getEconomy() == null) { if (economyManager.getEconomy() == null) {
return BooksWithoutBorders.getStringFormatter().getUnFormattedColoredMessage(Translatable.ERROR_VAULT_COST_BUT_UNAVAILABLE); return BooksWithoutBorders.getStringFormatter().getUnFormattedColoredMessage(Translatable.ERROR_VAULT_COST_BUT_UNAVAILABLE) + "\n";
} else { } else {
return stringFormatter.replacePlaceholder(Translatable.NEUTRAL_COMMANDS_BOOK_PRICE_ECO, return stringFormatter.replacePlaceholder(Translatable.NEUTRAL_COMMANDS_BOOK_PRICE_ECO,
"{price}", economyManager.getEconomy().format(bookPriceQuantity)); "{price}", economyManager.getEconomy().format(bookPriceQuantity));

View File

@@ -31,7 +31,7 @@ public class CommandDecrypt implements TabExecutor {
StringFormatter stringFormatter = BooksWithoutBorders.getStringFormatter(); StringFormatter stringFormatter = BooksWithoutBorders.getStringFormatter();
if (!(sender instanceof Player player)) { if (!(sender instanceof Player player)) {
BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!"); BooksWithoutBorders.getStringFormatter().displayErrorMessage(sender, Translatable.ERROR_PLAYER_ONLY);
return false; return false;
} }

View File

@@ -136,7 +136,7 @@ public class CommandSetBookPrice implements TabExecutor {
economyManager.getEconomy().format(newPriceQuantity) + "!"); economyManager.getEconomy().format(newPriceQuantity) + "!");
return true; return true;
} else { } else {
BooksWithoutBorders.sendErrorMessage(sender, StaticMessage.EXCEPTION_VAULT_NOT_AVAILABLE.toString()); BooksWithoutBorders.sendErrorMessage(sender, StaticMessage.EXCEPTION_VAULT_PRICE_NOT_CHANGED.toString());
return false; return false;
} }
} }

View File

@@ -398,7 +398,8 @@ public class BooksWithoutBordersConfig {
this.titleAuthorSeparator = ","; this.titleAuthorSeparator = ",";
config.set("Options.Title-Author_Separator", this.titleAuthorSeparator); config.set("Options.Title-Author_Separator", this.titleAuthorSeparator);
} }
} catch (Exception e) { } catch (Exception exception) {
logger.log(Level.SEVERE, exception.getMessage());
logger.log(Level.SEVERE, "Warning! Config.yml failed to load!\n" + logger.log(Level.SEVERE, "Warning! Config.yml failed to load!\n" +
"Try Looking for settings that are missing values!"); "Try Looking for settings that are missing values!");
return false; return false;

View File

@@ -10,8 +10,8 @@ public enum StaticMessage {
BOOK_SAVING_FAILED("Saving failed! Aborting..."), BOOK_SAVING_FAILED("Saving failed! Aborting..."),
BOOK_FOLDER_CREATE_FAILED("Unable to create necessary folders"), BOOK_FOLDER_CREATE_FAILED("Unable to create necessary folders"),
COMMAND_NOT_REGISTERED("Command {command} has not been registered!"), COMMAND_NOT_REGISTERED("Command {command} has not been registered!"),
EXCEPTION_VAULT_NOT_AVAILABLE("BooksWithoutBorders failed to hook into Vault! Book price not set!"), EXCEPTION_VAULT_NOT_AVAILABLE("Vault is unavailable, but book price is set to economy. Unsetting book cost!"),
; EXCEPTION_VAULT_PRICE_NOT_CHANGED("BooksWithoutBorders failed to hook into Vault! Book price not set!");
private final @NotNull String messageString; private final @NotNull String messageString;

View File

@@ -8,11 +8,6 @@ import org.jetbrains.annotations.NotNull;
*/ */
public enum Translatable implements TranslatableMessage { public enum Translatable implements TranslatableMessage {
/**
* The prefix to display in messages
*/
PREFIX,
/** /**
* The success message displayed when the copy command succeeds * The success message displayed when the copy command succeeds
*/ */

View File

@@ -2,7 +2,6 @@ package net.knarcraft.bookswithoutborders.manager;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.config.BooksWithoutBordersConfig; import net.knarcraft.bookswithoutborders.config.BooksWithoutBordersConfig;
import net.knarcraft.bookswithoutborders.config.StaticMessage;
import net.knarcraft.bookswithoutborders.config.Translatable; import net.knarcraft.bookswithoutborders.config.Translatable;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import org.bukkit.Material; import org.bukkit.Material;
@@ -31,13 +30,13 @@ public class EconomyManager {
/** /**
* Instantiates the economy manager * Instantiates the economy manager
*/ */
public EconomyManager() throws IllegalStateException { public EconomyManager() {
Server server = BooksWithoutBorders.getInstance().getServer(); Server server = BooksWithoutBorders.getInstance().getServer();
Plugin plugin = server.getPluginManager().getPlugin("Vault"); Plugin plugin = server.getPluginManager().getPlugin("Vault");
ServicesManager servicesManager = server.getServicesManager(); ServicesManager servicesManager = server.getServicesManager();
if (plugin == null) { if (plugin == null) {
throw new IllegalStateException(StaticMessage.EXCEPTION_VAULT_NOT_AVAILABLE.toString()); return;
} }
RegisteredServiceProvider<Economy> economyProvider = servicesManager.getRegistration(Economy.class); RegisteredServiceProvider<Economy> economyProvider = servicesManager.getRegistration(Economy.class);

View File

@@ -14,7 +14,7 @@ en:
ERROR_BOOK_COPIED_TOO_FAR: "You cannot copy this book any further. You must have the original or a direct copy." ERROR_BOOK_COPIED_TOO_FAR: "You cannot copy this book any further. You must have the original or a direct copy."
ERROR_INVENTORY_FULL: "You need an available slot in your inventory." ERROR_INVENTORY_FULL: "You need an available slot in your inventory."
ERROR_METADATA_MISSING: "Unable to get metadata for the held book!" ERROR_METADATA_MISSING: "Unable to get metadata for the held book!"
ERROR_VAULT_COST_BUT_UNAVAILABLE: "The cost was set to economy, but Vault is unavailable!" ERROR_VAULT_COST_BUT_UNAVAILABLE: "&4The cost was set to economy, but Vault is unavailable!"
NEUTRAL_COMMANDS_HEADER: | NEUTRAL_COMMANDS_HEADER: |
&e[] denote optional parameters &e[] denote optional parameters
<> denote required parameters <> denote required parameters