Moves some config values from StarGate and into the StarGateConfig class

Renames EconomyHandler to EconomyConfig and puts it in the new config package
Moves the LanguageLoader to the config package
Fixes the explanation of chargeFreeDestination in the README
This commit is contained in:
Kristian Knarvik 2021-10-23 03:56:59 +02:00
parent 070e7250df
commit 2196d5b99e
18 changed files with 412 additions and 174 deletions

View File

@ -277,7 +277,7 @@ economy:
destroyCost - The cost to destroy a stargate (Can be negative for a "refund"
useCost - The cost to use a stargate
toOwner - Whether the money from gate-use goes to the owner or nobody
chargeFreeDestination - Enable to allow free travel from any gate to a free gate
chargeFreeDestination - Enable to make players pay for teleportation even if the destination is free
freeGatesGreen - Enable to make gates that won't cost the player money show up as green
debugging:
debug - Whether to show massive debug output

View File

@ -2,6 +2,9 @@ package net.knarcraft.stargate;
import net.knarcraft.stargate.command.CommandStarGate;
import net.knarcraft.stargate.command.StarGateTabCompleter;
import net.knarcraft.stargate.config.EconomyConfig;
import net.knarcraft.stargate.config.LanguageLoader;
import net.knarcraft.stargate.config.StargateGateConfig;
import net.knarcraft.stargate.container.BlockChangeRequest;
import net.knarcraft.stargate.container.ChunkUnloadRequest;
import net.knarcraft.stargate.listener.BlockEventListener;
@ -20,7 +23,6 @@ import net.knarcraft.stargate.portal.PortalRegistry;
import net.knarcraft.stargate.thread.BlockChangeThread;
import net.knarcraft.stargate.thread.ChunkUnloadThread;
import net.knarcraft.stargate.thread.StarGateThread;
import net.knarcraft.stargate.utility.EconomyHandler;
import net.knarcraft.stargate.utility.FileHelper;
import net.knarcraft.stargate.utility.PortalFileHelper;
import org.bukkit.Bukkit;
@ -68,17 +70,10 @@ public class Stargate extends JavaPlugin {
public static Stargate stargate;
public static LanguageLoader languageLoader;
public static int maxGatesEachNetwork = 0;
public static boolean rememberDestination = false;
public static boolean handleVehicles = true;
public static boolean sortNetworkDestinations = false;
public static boolean protectEntrance = false;
public static boolean enableBungee = true;
public static boolean verifyPortals = true;
private static boolean destroyExplosion = false;
private String dataFolderPath;
private static StargateGateConfig stargateGateConfig;
private static EconomyConfig economyConfig;
public static ChatColor signColor;
//Used for debug
public static boolean debuggingEnabled = false;
public static boolean permissionDebuggingEnabled = false;
@ -92,7 +87,6 @@ public class Stargate extends JavaPlugin {
private static String portalFolder;
private static String gateFolder;
private static String defaultGateNetwork = "central";
private static String languageName = "en";
private FileConfiguration newConfig;
@ -117,6 +111,24 @@ public class Stargate extends JavaPlugin {
super(loader, descriptionFile, dataFolder, file);
}
/**
* Gets the object containing gate configuration values
*
* @return <p>The object containing gate configuration values</p>
*/
public static StargateGateConfig getGateConfig() {
return stargateGateConfig;
}
/**
* Gets the object containing economy config values
*
* @return <p>The object containing economy config values</p>
*/
public static EconomyConfig getEconomyConfig() {
return economyConfig;
}
/**
* Gets the version of this plugin
*
@ -132,7 +144,7 @@ public class Stargate extends JavaPlugin {
* @return <p>True if portals should be destroyed</p>
*/
public static boolean destroyedByExplosion() {
return destroyExplosion;
return stargateGateConfig.destroyedByExplosion();
}
/**
@ -215,7 +227,7 @@ public class Stargate extends JavaPlugin {
* @param text <p>The new text on the sign</p>
*/
public static void setLine(Sign sign, int index, String text) {
sign.setLine(index, Stargate.signColor + text);
sign.setLine(index, stargateGateConfig.getSignColor() + text);
}
/**
@ -246,7 +258,7 @@ public class Stargate extends JavaPlugin {
* @return <p>The default network</p>
*/
public static String getDefaultNetwork() {
return defaultGateNetwork;
return stargateGateConfig.getDefaultPortalNetwork();
}
/**
@ -324,7 +336,7 @@ public class Stargate extends JavaPlugin {
this.loadConfig();
//Enable the required channels for Bungee support
if (enableBungee) {
if (stargateGateConfig.enableBungee()) {
startStopBungeeListener(true);
}
@ -411,10 +423,10 @@ public class Stargate extends JavaPlugin {
}
//Gates
loadGateConfig();
stargateGateConfig = new StargateGateConfig(newConfig);
//Economy
loadEconomyConfig();
economyConfig = new EconomyConfig(newConfig);
this.saveConfig();
}
@ -456,59 +468,6 @@ public class Stargate extends JavaPlugin {
}
}
/**
* Loads all config values related to gates
*/
private void loadGateConfig() {
String defaultNetwork = newConfig.getString("gates.defaultGateNetwork");
defaultGateNetwork = defaultNetwork != null ? defaultNetwork.trim() : null;
maxGatesEachNetwork = newConfig.getInt("gates.maxGatesEachNetwork");
//Functionality
handleVehicles = newConfig.getBoolean("gates.functionality.handleVehicles");
enableBungee = newConfig.getBoolean("gates.functionality.enableBungee");
//Integrity
protectEntrance = newConfig.getBoolean("gates.integrity.protectEntrance");
verifyPortals = newConfig.getBoolean("gates.integrity.verifyPortals");
destroyExplosion = newConfig.getBoolean("gates.integrity.destroyedByExplosion");
//Cosmetic
sortNetworkDestinations = newConfig.getBoolean("gates.cosmetic.sortNetworkDestinations");
rememberDestination = newConfig.getBoolean("gates.cosmetic.rememberDestination");
loadSignColor(newConfig.getString("gates.cosmetic.signColor"));
}
/**
* Loads all config values related to economy
*/
private void loadEconomyConfig() {
EconomyHandler.economyEnabled = newConfig.getBoolean("economy.useEconomy");
EconomyHandler.setDefaultCreateCost(newConfig.getInt("economy.createCost"));
EconomyHandler.setDefaultDestroyCost(newConfig.getInt("economy.destroyCost"));
EconomyHandler.setDefaultUseCost(newConfig.getInt("economy.useCost"));
EconomyHandler.toOwner = newConfig.getBoolean("economy.toOwner");
EconomyHandler.chargeFreeDestination = newConfig.getBoolean("economy.chargeFreeDestination");
EconomyHandler.freeGatesGreen = newConfig.getBoolean("economy.freeGatesGreen");
}
/**
* Loads the correct sign color given a sign color string
*
* @param signColor <p>A string representing a sign color</p>
*/
private void loadSignColor(String signColor) {
if (signColor != null) {
try {
Stargate.signColor = ChatColor.valueOf(signColor.toUpperCase());
return;
} catch (IllegalArgumentException | NullPointerException ignored) {
}
}
logger.warning(getString("prefix") + "You have specified an invalid color in your config.yml. Defaulting to BLACK");
Stargate.signColor = ChatColor.BLACK;
}
/**
* Forces all open portals to close
*/
@ -577,7 +536,7 @@ public class Stargate extends JavaPlugin {
GateHandler.clearGates();
// Store the old Bungee enabled value
boolean oldEnableBungee = enableBungee;
boolean oldEnableBungee = stargateGateConfig.enableBungee();
// Reload data
loadConfig();
loadGates();
@ -589,8 +548,8 @@ public class Stargate extends JavaPlugin {
reloadEconomy();
//Enable or disable the required channels for Bungee support
if (oldEnableBungee != enableBungee) {
startStopBungeeListener(enableBungee);
if (oldEnableBungee != stargateGateConfig.enableBungee()) {
startStopBungeeListener(stargateGateConfig.enableBungee());
}
sendErrorMessage(sender, "stargate reloaded");
@ -600,11 +559,11 @@ public class Stargate extends JavaPlugin {
* Reloads economy by enabling or disabling it as necessary
*/
private void reloadEconomy() {
if (EconomyHandler.economyEnabled && EconomyHandler.economy == null) {
EconomyConfig economyConfig = Stargate.getEconomyConfig();
if (economyConfig.isEconomyEnabled() && economyConfig.getEconomy() == null) {
setupVaultEconomy();
} else if (!EconomyHandler.economyEnabled) {
EconomyHandler.vault = null;
EconomyHandler.economy = null;
} else if (!economyConfig.isEconomyEnabled()) {
economyConfig.disableEconomy();
}
}
@ -612,8 +571,9 @@ public class Stargate extends JavaPlugin {
* Loads economy from Vault
*/
private void setupVaultEconomy() {
if (EconomyHandler.setupEconomy(pluginManager) && EconomyHandler.economy != null) {
String vaultVersion = EconomyHandler.vault.getDescription().getVersion();
EconomyConfig economyConfig = Stargate.getEconomyConfig();
if (economyConfig.setupEconomy(pluginManager) && economyConfig.getEconomy() != null) {
String vaultVersion = economyConfig.getVault().getDescription().getVersion();
logger.info(Stargate.getString("prefix") + Stargate.replaceVars(
Stargate.getString("vaultLoaded"), "%version%", vaultVersion));
}

View File

@ -1,41 +1,119 @@
package net.knarcraft.stargate.utility;
package net.knarcraft.stargate.config;
import net.knarcraft.stargate.Stargate;
import net.knarcraft.stargate.portal.Gate;
import net.knarcraft.stargate.portal.Portal;
import net.knarcraft.stargate.utility.PermissionHelper;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicesManager;
import java.util.UUID;
/**
* This handler handles economy actions such as payment for using a gate
* The economy config keeps track of economy config values and performs economy actions such as payment for using a gate
*/
public final class EconomyHandler {
public final class EconomyConfig {
public static boolean economyEnabled = false;
public static Economy economy = null;
public static Plugin vault = null;
private static int useCost = 0;
private static int createCost = 0;
private static int destroyCost = 0;
public static boolean toOwner = false;
public static boolean chargeFreeDestination = true;
public static boolean freeGatesGreen = false;
private boolean economyEnabled = false;
private Economy economy = null;
private Plugin vault = null;
private int useCost = 0;
private int createCost = 0;
private int destroyCost = 0;
private boolean toOwner = false;
private boolean chargeFreeDestination = true;
private boolean freeGatesGreen = false;
/**
* Instantiates a new economy config
*
* @param newConfig <p>The file configuration to read values from</p>
*/
public EconomyConfig(FileConfiguration newConfig) {
loadEconomyConfig(newConfig);
}
/**
* Gets the cost of using a gate without a specified cost
*
* @return <p>The gate use cost</p>
*/
public static int getDefaultUseCost() {
public int getDefaultUseCost() {
return useCost;
}
/**
* Gets whether economy is enabled
*
* @return <p>Whether economy is enabled</p>
*/
public boolean isEconomyEnabled() {
return economyEnabled;
}
/**
* Gets the economy object to use for transactions
*
* @return <p>An economy object, or null if economy is disabled or not initialized</p>
*/
public Economy getEconomy() {
return economy;
}
/**
* Gets an instance of the Vault plugin
*
* @return <p>An instance of the Vault plugin, or null if Vault is not loaded</p>
*/
public Plugin getVault() {
return vault;
}
/**
* Disables economy support by clearing relevant values
*/
public void disableEconomy() {
this.economy = null;
this.vault = null;
}
/**
* Gets whether free portals should be marked with green coloring
*
* @return <p>Whether free portals should be green</p>
*/
public boolean drawFreePortalsGreen() {
return freeGatesGreen;
}
/**
* Whether a gate whose destination is a free gate is still charged
*
* <p>If teleporting from a free portal, it's free regardless of destination. If chargeFreeDestination is disabled,
* it's also free to teleport back to the free portal. If chargeFreeDestination is enabled, it's only free to
* teleport back if teleporting from another free portal.</p>
*
* @return <p>Whether to charge for free destinations</p>
*/
public boolean chargeFreeDestination() {
return chargeFreeDestination;
}
/**
* Gets whether payments should be sent to the owner of the used portal
*
* @return <p>Whether to send payments to the portal owner</p>
*/
public boolean sendPaymentToOwner() {
return toOwner;
}
/**
* Sets the cost of using a gate without a specified cost
*
@ -43,11 +121,11 @@ public final class EconomyHandler {
*
* @param useCost <p>The gate use cost</p>
*/
public static void setDefaultUseCost(int useCost) {
public void setDefaultUseCost(int useCost) {
if (useCost < 0) {
throw new IllegalArgumentException("Using a gate cannot cost a negative amount");
}
EconomyHandler.useCost = useCost;
this.useCost = useCost;
}
/**
@ -55,7 +133,7 @@ public final class EconomyHandler {
*
* @return <p>The gate creation cost</p>
*/
public static int getDefaultCreateCost() {
public int getDefaultCreateCost() {
return createCost;
}
@ -66,8 +144,8 @@ public final class EconomyHandler {
*
* @param createCost <p>The gate creation cost</p>
*/
public static void setDefaultCreateCost(int createCost) {
EconomyHandler.createCost = createCost;
public void setDefaultCreateCost(int createCost) {
this.createCost = createCost;
}
/**
@ -75,7 +153,7 @@ public final class EconomyHandler {
*
* @return <p>The gate destruction cost</p>
*/
public static int getDefaultDestroyCost() {
public int getDefaultDestroyCost() {
return destroyCost;
}
@ -84,8 +162,8 @@ public final class EconomyHandler {
*
* @param destroyCost <p>The gate destruction cost</p>
*/
public static void setDefaultDestroyCost(int destroyCost) {
EconomyHandler.destroyCost = destroyCost;
public void setDefaultDestroyCost(int destroyCost) {
this.destroyCost = destroyCost;
}
/**
@ -95,12 +173,12 @@ public final class EconomyHandler {
* @param cost <p>The cost of the transaction</p>
* @return <p>True if the player was charged successfully</p>
*/
public static boolean chargePlayerIfNecessary(Player player, int cost) {
public boolean chargePlayerIfNecessary(Player player, int cost) {
if (skipPayment(cost)) {
return true;
}
//Charge player
return EconomyHandler.chargePlayer(player, cost);
return chargePlayer(player, cost);
}
/**
@ -110,7 +188,7 @@ public final class EconomyHandler {
* @param cost <p>The fee to pay</p>
* @return <p>True if the player can afford to pay the fee</p>
*/
public static boolean canAffordFee(Player player, int cost) {
public boolean canAffordFee(Player player, int cost) {
return economy.getBalance(player) > cost;
}
@ -122,12 +200,12 @@ public final class EconomyHandler {
* @param cost <p>The cost of the transaction</p>
* @return <p>True if the player was charged successfully</p>
*/
public static boolean chargePlayerIfNecessary(Player player, UUID target, int cost) {
public boolean chargePlayerIfNecessary(Player player, UUID target, int cost) {
if (skipPayment(cost)) {
return true;
}
//Charge player
return EconomyHandler.chargePlayer(player, target, cost);
return chargePlayer(player, target, cost);
}
/**
@ -136,7 +214,7 @@ public final class EconomyHandler {
* @param amount <p>The amount to display</p>
* @return <p>A formatted text string describing the amount</p>
*/
public static String format(int amount) {
public String format(int amount) {
if (economyEnabled) {
return economy.format(amount);
} else {
@ -150,17 +228,18 @@ public final class EconomyHandler {
* @param pluginManager <p>The plugin manager to get plugins from</p>
* @return <p>True if economy was enabled</p>
*/
public static boolean setupEconomy(PluginManager pluginManager) {
public boolean setupEconomy(PluginManager pluginManager) {
if (!economyEnabled) {
return false;
}
//Check if vault is loaded
Plugin vault = pluginManager.getPlugin("Vault");
if (vault != null && vault.isEnabled()) {
RegisteredServiceProvider<Economy> economyProvider = Stargate.server.getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
ServicesManager servicesManager = Stargate.server.getServicesManager();
RegisteredServiceProvider<Economy> economyProvider = servicesManager.getRegistration(Economy.class);
if (economyProvider != null) {
economy = economyProvider.getProvider();
EconomyHandler.vault = vault;
this.vault = vault;
return true;
} else {
Stargate.logger.info(Stargate.getString("prefix") + Stargate.getString("ecoLoadError"));
@ -177,7 +256,7 @@ public final class EconomyHandler {
*
* @return <p>True if the user has turned on economy and economy is available</p>
*/
public static boolean useEconomy() {
public boolean useEconomy() {
return economyEnabled && economy != null;
}
@ -187,8 +266,8 @@ public final class EconomyHandler {
* @param cost <p>The cost of the transaction</p>
* @return <p>True if the transaction should be skipped</p>
*/
private static boolean skipPayment(int cost) {
return cost == 0 || !EconomyHandler.useEconomy();
private boolean skipPayment(int cost) {
return cost == 0 || !useEconomy();
}
/**
@ -199,13 +278,13 @@ public final class EconomyHandler {
* @param destination <p>The destination portal</p>
* @return <p>The cost of using the portal</p>
*/
public static int getUseCost(Player player, Portal source, Portal destination) {
public int getUseCost(Player player, Portal source, Portal destination) {
//No payment required
if (!EconomyHandler.useEconomy() || source.getOptions().isFree()) {
if (!useEconomy() || source.getOptions().isFree()) {
return 0;
}
//Not charging for free destinations
if (destination != null && !EconomyHandler.chargeFreeDestination && destination.getOptions().isFree()) {
if (destination != null && !chargeFreeDestination && destination.getOptions().isFree()) {
return 0;
}
//Cost is 0 if the player owns this gate and funds go to the owner
@ -228,7 +307,7 @@ public final class EconomyHandler {
* @param gate <p>The gate type used</p>
* @return <p>The cost of creating the gate</p>
*/
public static int getCreateCost(Player player, Gate gate) {
public int getCreateCost(Player player, Gate gate) {
if (isFree(player, "create")) {
return 0;
} else {
@ -243,7 +322,7 @@ public final class EconomyHandler {
* @param gate <p>The gate type used</p>
* @return <p>The cost of destroying the gate</p>
*/
public static int getDestroyCost(Player player, Gate gate) {
public int getDestroyCost(Player player, Gate gate) {
if (isFree(player, "destroy")) {
return 0;
} else {
@ -251,6 +330,21 @@ public final class EconomyHandler {
}
}
/**
* Loads all config values related to economy
*
* @param newConfig <p>The configuration containing the values to read</p>
*/
private void loadEconomyConfig(FileConfiguration newConfig) {
economyEnabled = newConfig.getBoolean("economy.useEconomy");
setDefaultCreateCost(newConfig.getInt("economy.createCost"));
setDefaultDestroyCost(newConfig.getInt("economy.destroyCost"));
setDefaultUseCost(newConfig.getInt("economy.useCost"));
toOwner = newConfig.getBoolean("economy.toOwner");
chargeFreeDestination = newConfig.getBoolean("economy.chargeFreeDestination");
freeGatesGreen = newConfig.getBoolean("economy.freeGatesGreen");
}
/**
* Determines if a player can do a gate action for free
*
@ -258,8 +352,8 @@ public final class EconomyHandler {
* @param permissionNode <p>The free.permissionNode necessary to allow free gate {action}</p>
* @return <p></p>
*/
private static boolean isFree(Player player, String permissionNode) {
return !EconomyHandler.useEconomy() || PermissionHelper.hasPermission(player, "stargate.free") ||
private boolean isFree(Player player, String permissionNode) {
return !useEconomy() || PermissionHelper.hasPermission(player, "stargate.free") ||
PermissionHelper.hasPermission(player, "stargate.free." + permissionNode);
}
@ -270,7 +364,7 @@ public final class EconomyHandler {
* @param amount <p>The amount to charge</p>
* @return <p>True if the payment succeeded, or if no payment was necessary</p>
*/
private static boolean chargePlayer(Player player, double amount) {
private boolean chargePlayer(Player player, double amount) {
if (economyEnabled && economy != null) {
if (!economy.has(player, amount)) {
return false;
@ -288,7 +382,7 @@ public final class EconomyHandler {
* @param amount <p>The amount to charge</p>
* @return <p>True if the payment succeeded, or if no payment was necessary</p>
*/
private static boolean chargePlayer(Player player, UUID target, double amount) {
private boolean chargePlayer(Player player, UUID target, double amount) {
if (economyEnabled && player.getUniqueId().compareTo(target) != 0 && economy != null) {
if (!economy.has(player, amount)) {
return false;

View File

@ -1,5 +1,6 @@
package net.knarcraft.stargate;
package net.knarcraft.stargate.config;
import net.knarcraft.stargate.Stargate;
import net.knarcraft.stargate.utility.FileHelper;
import java.io.BufferedReader;
@ -14,7 +15,7 @@ import java.util.Set;
/**
* This class is responsible for loading all strings which are translated into several languages
*/
public class LanguageLoader {
public final class LanguageLoader {
private final String languageFolder;
private final Map<String, String> loadedBackupStrings;

View File

@ -0,0 +1,169 @@
package net.knarcraft.stargate.config;
import net.knarcraft.stargate.Stargate;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import static net.knarcraft.stargate.Stargate.getString;
/**
* The Stargate gate config keeps track of all global config values related to gates
*/
public final class StargateGateConfig {
private int maxGatesEachNetwork = 0;
private boolean rememberDestination = false;
private boolean handleVehicles = true;
private boolean sortNetworkDestinations = false;
private boolean protectEntrance = false;
private boolean enableBungee = true;
private boolean verifyPortals = true;
private boolean destroyExplosion = false;
private ChatColor signColor;
private String defaultGateNetwork = "central";
/**
* Instantiates a new stargate config
*
* @param newConfig <p>The file configuration to read values from</p>
*/
public StargateGateConfig(FileConfiguration newConfig) {
loadGateConfig(newConfig);
}
/**
* Gets the maximum number of gates allowed on each network
*
* @return <p>Maximum number of gates for each network</p>
*/
public int maxGatesEachNetwork() {
return maxGatesEachNetwork;
}
/**
* Gets whether a portal's lastly used destination should be remembered
*
* @return <p>Whether a portal's lastly used destination should be remembered</p>
*/
public boolean rememberDestination() {
return rememberDestination;
}
/**
* Gets whether vehicle teleportation should be handled in addition to player teleportation
*
* @return <p>Whether vehicle teleportation should be handled</p>
*/
public boolean handleVehicles() {
return handleVehicles;
}
/**
* Gets whether the list of destinations within a network should be sorted
*
* @return <p>Whether network destinations should be sorted</p>
*/
public boolean sortNetworkDestinations() {
return sortNetworkDestinations;
}
/**
* Gets whether portal entrances should be protected from block breaking
*
* @return <p>Whether portal entrances should be protected</p>
*/
public boolean protectEntrance() {
return protectEntrance;
}
/**
* Gets whether BungeeCord support is enabled
*
* @return <p>Whether bungee support is enabled</p>
*/
public boolean enableBungee() {
return enableBungee;
}
/**
* Gets whether all portals' integrity has to be verified on startup and reload
*
* @return <p>Whether portals need to be verified</p>
*/
public boolean verifyPortals() {
return verifyPortals;
}
/**
* Gets whether portals should be destroyed by nearby explosions
*
* @return <p>Whether portals should be destroyed by explosions</p>
*/
public boolean destroyedByExplosion() {
return destroyExplosion;
}
/**
* Gets the color to use for drawing signs
*
* <p>Highlighting may use other colors. This is just the base color for portal names and such.</p>
*
* @return <p>The color to use for drawing signs</p>
*/
public ChatColor getSignColor() {
return signColor;
}
/**
* Gets the default portal network to use if no other network is given
*
* @return <p>The default portal network</p>
*/
public String getDefaultPortalNetwork() {
return defaultGateNetwork;
}
/**
* Loads all config values related to gates
*
* @param newConfig <p>The configuration containing the values to read</p>
*/
private void loadGateConfig(FileConfiguration newConfig) {
String defaultNetwork = newConfig.getString("gates.defaultGateNetwork");
defaultGateNetwork = defaultNetwork != null ? defaultNetwork.trim() : null;
maxGatesEachNetwork = newConfig.getInt("gates.maxGatesEachNetwork");
//Functionality
handleVehicles = newConfig.getBoolean("gates.functionality.handleVehicles");
enableBungee = newConfig.getBoolean("gates.functionality.enableBungee");
//Integrity
protectEntrance = newConfig.getBoolean("gates.integrity.protectEntrance");
verifyPortals = newConfig.getBoolean("gates.integrity.verifyPortals");
destroyExplosion = newConfig.getBoolean("gates.integrity.destroyedByExplosion");
//Cosmetic
sortNetworkDestinations = newConfig.getBoolean("gates.cosmetic.sortNetworkDestinations");
rememberDestination = newConfig.getBoolean("gates.cosmetic.rememberDestination");
loadSignColor(newConfig.getString("gates.cosmetic.signColor"));
}
/**
* Loads the correct sign color given a sign color string
*
* @param signColor <p>A string representing a sign color</p>
*/
private void loadSignColor(String signColor) {
if (signColor != null) {
try {
this.signColor = ChatColor.valueOf(signColor.toUpperCase());
return;
} catch (IllegalArgumentException | NullPointerException ignored) {
}
}
Stargate.logger.warning(getString("prefix") +
"You have specified an invalid color in your config.yml. Defaulting to BLACK");
this.signColor = ChatColor.BLACK;
}
}

View File

@ -6,7 +6,6 @@ import net.knarcraft.stargate.portal.Portal;
import net.knarcraft.stargate.portal.PortalCreator;
import net.knarcraft.stargate.portal.PortalHandler;
import net.knarcraft.stargate.portal.PortalRegistry;
import net.knarcraft.stargate.utility.EconomyHandler;
import net.knarcraft.stargate.utility.EconomyHelper;
import net.knarcraft.stargate.utility.MaterialHelper;
import net.knarcraft.stargate.utility.PermissionHelper;
@ -45,7 +44,8 @@ public class BlockEventListener implements Listener {
*/
@EventHandler
public void onBlockFormedByEntity(EntityBlockFormEvent event) {
if (event.isCancelled() || (!Stargate.protectEntrance && !Stargate.verifyPortals)) {
if (event.isCancelled() || (!Stargate.getGateConfig().protectEntrance() &&
!Stargate.getGateConfig().verifyPortals())) {
return;
}
//We are only interested in snowman events
@ -101,7 +101,7 @@ public class BlockEventListener implements Listener {
//Decide if a portal is broken
Portal portal = PortalHandler.getByBlock(block);
if (portal == null && Stargate.protectEntrance) {
if (portal == null && Stargate.getGateConfig().protectEntrance()) {
portal = PortalHandler.getByEntrance(block);
}
if (portal == null) {
@ -118,7 +118,7 @@ public class BlockEventListener implements Listener {
Stargate.logger.info(Stargate.getString("prefix") + player.getName() + " tried to destroy gate");
}
int cost = EconomyHandler.getDestroyCost(player, portal.getGate());
int cost = Stargate.getEconomyConfig().getDestroyCost(player, portal.getGate());
//Create and call a StarGateDestroyEvent
StargateDestroyEvent destroyEvent = new StargateDestroyEvent(portal, player, deny, denyMessage, cost);
@ -159,7 +159,7 @@ public class BlockEventListener implements Listener {
if (cost != 0) {
String portalName = portal.getName();
//Cannot pay
if (!EconomyHandler.chargePlayerIfNecessary(player, cost)) {
if (!Stargate.getEconomyConfig().chargePlayerIfNecessary(player, cost)) {
Stargate.debug("onBlockBreak", "Insufficient Funds");
EconomyHelper.sendInsufficientFundsMessage(portalName, player, cost);
event.setCancelled(true);

View File

@ -42,7 +42,7 @@ public class PlayerEventListener implements Listener {
*/
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if (!Stargate.enableBungee) {
if (!Stargate.getGateConfig().enableBungee()) {
return;
}
@ -84,19 +84,34 @@ public class PlayerEventListener implements Listener {
Portal entrancePortal = PortalHandler.getByEntrance(toLocation);
Portal destination = entrancePortal.getPortalActivator().getDestination(player);
//Teleport the vehicle to the player
Entity playerVehicle = player.getVehicle();
if (playerVehicle != null && !Stargate.handleVehicles) {
return;
//If the player is in a vehicle, but vehicle handling is disabled, just ignore the player
if (playerVehicle == null || Stargate.getGateConfig().handleVehicles()) {
teleportPlayer(playerVehicle, player, entrancePortal, destination, event);
}
}
/**
* Teleports a player, also teleports the player's vehicle if it's a living entity
*
* @param playerVehicle <p>The vehicle the player is currently sitting in</p>
* @param player <p>The player which moved</p>
* @param entrancePortal <p>The entrance the player entered</p>
* @param destination <p>The destination of the entrance portal</p>
* @param event <p>The move event causing the teleportation to trigger</p>
*/
private void teleportPlayer(Entity playerVehicle, Player player, Portal entrancePortal, Portal destination,
PlayerMoveEvent event) {
if (playerVehicle instanceof LivingEntity) {
//Make sure any horses are properly tamed
if (playerVehicle instanceof AbstractHorse horse && !horse.isTamed()) {
horse.setTamed(true);
horse.setOwner(player);
}
//Teleport the player's vehicle
new VehicleTeleporter(destination, (Vehicle) playerVehicle).teleport(entrancePortal);
} else {
//Just teleport the player like normal
new PlayerTeleporter(destination, player).teleport(entrancePortal, event);
}
Stargate.sendSuccessMessage(player, Stargate.getString("teleportMsg"));
@ -302,7 +317,7 @@ public class PlayerEventListener implements Listener {
*/
private boolean bungeeTeleport(Player player, Portal entrancePortal, PlayerMoveEvent event) {
//Check if bungee is actually enabled
if (!Stargate.enableBungee) {
if (!Stargate.getGateConfig().enableBungee()) {
Stargate.sendErrorMessage(player, Stargate.getString("bungeeDisabled"));
entrancePortal.getPortalOpener().closePortal(false);
return false;

View File

@ -1,7 +1,6 @@
package net.knarcraft.stargate.listener;
import net.knarcraft.stargate.Stargate;
import net.knarcraft.stargate.utility.EconomyHandler;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
@ -33,8 +32,8 @@ public class PluginEventListener implements Listener {
*/
@EventHandler
public void onPluginEnable(PluginEnableEvent ignored) {
if (EconomyHandler.setupEconomy(stargate.getServer().getPluginManager())) {
String vaultVersion = EconomyHandler.vault.getDescription().getVersion();
if (Stargate.getEconomyConfig().setupEconomy(stargate.getServer().getPluginManager())) {
String vaultVersion = Stargate.getEconomyConfig().getVault().getDescription().getVersion();
stargate.getLogger().info(Stargate.getString("prefix") +
Stargate.replaceVars(Stargate.getString("vaultLoaded"), "%version%", vaultVersion));
}
@ -47,7 +46,7 @@ public class PluginEventListener implements Listener {
*/
@EventHandler
public void onPluginDisable(PluginDisableEvent event) {
if (event.getPlugin().equals(EconomyHandler.vault)) {
if (event.getPlugin().equals(Stargate.getEconomyConfig().getVault())) {
stargate.getLogger().info(Stargate.getString("prefix") + "Vault plugin lost.");
}
}

View File

@ -4,7 +4,6 @@ import net.knarcraft.stargate.Stargate;
import net.knarcraft.stargate.portal.Portal;
import net.knarcraft.stargate.portal.PortalHandler;
import net.knarcraft.stargate.portal.VehicleTeleporter;
import net.knarcraft.stargate.utility.EconomyHandler;
import net.knarcraft.stargate.utility.EconomyHelper;
import net.knarcraft.stargate.utility.EntityHelper;
import net.knarcraft.stargate.utility.PermissionHelper;
@ -30,7 +29,7 @@ public class VehicleEventListener implements Listener {
*/
@EventHandler
public void onVehicleMove(VehicleMoveEvent event) {
if (!Stargate.handleVehicles) {
if (!Stargate.getGateConfig().handleVehicles()) {
return;
}
List<Entity> passengers = event.getVehicle().getPassengers();
@ -110,7 +109,7 @@ public class VehicleEventListener implements Listener {
//To prevent the case where the first passenger pays and then the second passenger is denied, this has to be
// run after it has been confirmed that all passengers are able to pay
int cost = EconomyHandler.getUseCost(player, entrancePortal, destinationPortal);
int cost = Stargate.getEconomyConfig().getUseCost(player, entrancePortal, destinationPortal);
if (cost > 0) {
if (!takePlayerPayment(passengers, entrancePortal, cost)) {
return;
@ -157,8 +156,8 @@ public class VehicleEventListener implements Listener {
}
//Transfer payment if necessary
int cost = EconomyHandler.getUseCost(player, entrancePortal, destinationPortal);
return cost <= 0 || EconomyHandler.canAffordFee(player, cost);
int cost = Stargate.getEconomyConfig().getUseCost(player, entrancePortal, destinationPortal);
return cost <= 0 || Stargate.getEconomyConfig().canAffordFee(player, cost);
}
}

View File

@ -3,7 +3,6 @@ package net.knarcraft.stargate.portal;
import net.knarcraft.stargate.Stargate;
import net.knarcraft.stargate.container.BlockLocation;
import net.knarcraft.stargate.container.RelativeBlockVector;
import net.knarcraft.stargate.utility.EconomyHandler;
import org.bukkit.Material;
import java.io.BufferedWriter;
@ -122,7 +121,7 @@ public class Gate {
* @return <p>The cost of using a portal with this gate</p>
*/
public int getUseCost() {
return useCost < 0 ? EconomyHandler.getDefaultUseCost() : useCost;
return useCost < 0 ? Stargate.getEconomyConfig().getDefaultUseCost() : useCost;
}
/**
@ -131,7 +130,7 @@ public class Gate {
* @return <p>The cost of creating a portal with this gate</p>
*/
public Integer getCreateCost() {
return createCost < 0 ? EconomyHandler.getDefaultCreateCost() : createCost;
return createCost < 0 ? Stargate.getEconomyConfig().getDefaultCreateCost() : createCost;
}
/**
@ -140,7 +139,7 @@ public class Gate {
* @return <p>The cost of destroying a portal with this gate</p>
*/
public Integer getDestroyCost() {
return destroyCost < 0 ? EconomyHandler.getDefaultDestroyCost() : destroyCost;
return destroyCost < 0 ? Stargate.getEconomyConfig().getDefaultDestroyCost() : destroyCost;
}
/**

View File

@ -1,7 +1,6 @@
package net.knarcraft.stargate.portal;
import net.knarcraft.stargate.Stargate;
import net.knarcraft.stargate.utility.EconomyHandler;
import net.knarcraft.stargate.utility.GateReader;
import net.knarcraft.stargate.utility.MaterialHelper;
import org.bukkit.Material;
@ -170,7 +169,7 @@ public class GateHandler {
int createCost = GateReader.readGateConfig(config, fileName, "createcost");
int destroyCost = GateReader.readGateConfig(config, fileName, "destroycost");
boolean toOwner = (config.containsKey("toowner") ? Boolean.parseBoolean(config.get("toowner")) :
EconomyHandler.toOwner);
Stargate.getEconomyConfig().sendPaymentToOwner());
//Create the new gate
Gate gate = new Gate(fileName, new GateLayout(layout), characterMaterialMap, portalOpenBlock, portalClosedBlock,

View File

@ -140,12 +140,13 @@ public class PortalActivator {
destinations = PortalHandler.getDestinations(portal, player, network);
//Sort destinations if enabled
if (Stargate.sortNetworkDestinations) {
if (Stargate.getGateConfig().sortNetworkDestinations()) {
Collections.sort(destinations);
}
//Select last used destination if remember destination is enabled
if (Stargate.rememberDestination && !lastDestination.isEmpty() && destinations.contains(lastDestination)) {
if (Stargate.getGateConfig().rememberDestination() && !lastDestination.isEmpty() &&
destinations.contains(lastDestination)) {
destination = lastDestination;
}
@ -254,7 +255,7 @@ public class PortalActivator {
}
//Cycle if destination remembering is disabled, if the portal was already active, or it has no last destination
if (!Stargate.rememberDestination || !activate || lastDestination.isEmpty()) {
if (!Stargate.getGateConfig().rememberDestination() || !activate || lastDestination.isEmpty()) {
cycleDestination(direction);
}

View File

@ -5,7 +5,6 @@ import net.knarcraft.stargate.container.BlockLocation;
import net.knarcraft.stargate.container.RelativeBlockVector;
import net.knarcraft.stargate.event.StargateCreateEvent;
import net.knarcraft.stargate.utility.DirectionHelper;
import net.knarcraft.stargate.utility.EconomyHandler;
import net.knarcraft.stargate.utility.EconomyHelper;
import net.knarcraft.stargate.utility.PermissionHelper;
import net.knarcraft.stargate.utility.PortalFileHelper;
@ -173,7 +172,7 @@ public class PortalCreator {
String portalName = portal.getName();
String destinationName = portal.getDestinationName();
int createCost = EconomyHandler.getCreateCost(player, gate);
int createCost = Stargate.getEconomyConfig().getCreateCost(player, gate);
//Call StargateCreateEvent to let other plugins cancel or overwrite denial
StargateCreateEvent stargateCreateEvent = new StargateCreateEvent(player, portal, lines, deny,
@ -247,14 +246,15 @@ public class PortalCreator {
//Check if there are too many gates in this network
List<String> networkList = PortalHandler.getAllPortalNetworks().get(portal.getNetwork().toLowerCase());
if (Stargate.maxGatesEachNetwork > 0 && networkList != null && networkList.size() >= Stargate.maxGatesEachNetwork) {
int maxGates = Stargate.getGateConfig().maxGatesEachNetwork();
if (maxGates > 0 && networkList != null && networkList.size() >= maxGates) {
Stargate.sendErrorMessage(player, Stargate.getString("createFull"));
return false;
}
}
if (cost > 0) {
if (!EconomyHandler.chargePlayerIfNecessary(player, cost)) {
if (!Stargate.getEconomyConfig().chargePlayerIfNecessary(player, cost)) {
EconomyHelper.sendInsufficientFundsMessage(portalName, player, cost);
Stargate.debug("createPortal", "Insufficient Funds");
return false;

View File

@ -123,7 +123,7 @@ public class PortalHandler {
if (!PermissionHelper.hasPermission(player, "stargate.admin.bungee")) {
Stargate.sendErrorMessage(player, Stargate.getString("bungeeDeny"));
return false;
} else if (!Stargate.enableBungee) {
} else if (!Stargate.getGateConfig().enableBungee()) {
Stargate.sendErrorMessage(player, Stargate.getString("bungeeDisabled"));
return false;
} else if (destinationName.isEmpty() || network.isEmpty()) {
@ -394,8 +394,9 @@ public class PortalHandler {
for (Portal portal : PortalRegistry.getAllPortals()) {
//Open the gate if it's set as always open or if it's a bungee gate
if (portal.getOptions().isFixed() && (Stargate.enableBungee && portal.getOptions().isBungee() ||
portal.getPortalActivator().getDestination() != null && portal.getOptions().isAlwaysOn())) {
if (portal.getOptions().isFixed() && (Stargate.getGateConfig().enableBungee() &&
portal.getOptions().isBungee() || portal.getPortalActivator().getDestination() != null &&
portal.getOptions().isAlwaysOn())) {
portal.getPortalOpener().openPortal(true);
alwaysOpenCount++;
}

View File

@ -1,7 +1,6 @@
package net.knarcraft.stargate.portal;
import net.knarcraft.stargate.Stargate;
import net.knarcraft.stargate.utility.EconomyHandler;
import net.knarcraft.stargate.utility.PermissionHelper;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
@ -50,8 +49,8 @@ public class PortalSignDrawer {
for (int index = 0; index <= 3; index++) {
sign.setLine(index, "");
}
Stargate.setLine(sign, 0, ChatColor.WHITE + "-" + Stargate.signColor + portal.getName() +
ChatColor.WHITE + "-");
Stargate.setLine(sign, 0, ChatColor.WHITE + "-" + Stargate.getGateConfig().getSignColor() +
portal.getName() + ChatColor.WHITE + "-");
if (!portal.getPortalActivator().isActive()) {
//Default sign text
@ -82,7 +81,8 @@ public class PortalSignDrawer {
int maxIndex = destinations.getDestinations().size() - 1;
int signLineIndex = 0;
int destinationIndex = destinations.getDestinations().indexOf(portal.getDestinationName());
boolean freeGatesGreen = EconomyHandler.useEconomy() && EconomyHandler.freeGatesGreen;
boolean freeGatesGreen = Stargate.getEconomyConfig().useEconomy() &&
Stargate.getEconomyConfig().drawFreePortalsGreen();
//Last, and not only entry. Draw the entry two back
if ((destinationIndex == maxIndex) && (maxIndex > 1)) {
@ -118,8 +118,8 @@ public class PortalSignDrawer {
Stargate.setLine(sign, signLineIndex, (green ? ChatColor.DARK_GREEN : "") + ">" +
portal.getDestinationName() + (green ? ChatColor.DARK_GREEN : "") + "<");
} else {
Stargate.setLine(sign, signLineIndex, Stargate.signColor + " >" + portal.getDestinationName() +
Stargate.signColor + "< ");
Stargate.setLine(sign, signLineIndex, Stargate.getGateConfig().getSignColor() + " >" +
portal.getDestinationName() + Stargate.getGateConfig().getSignColor() + "< ");
}
}

View File

@ -67,7 +67,7 @@ public class PortalStructure {
*/
public boolean isVerified() {
boolean verified = true;
if (!Stargate.verifyPortals) {
if (!Stargate.getGateConfig().verifyPortals()) {
return true;
}
for (RelativeBlockVector control : gate.getLayout().getControls()) {
@ -83,7 +83,7 @@ public class PortalStructure {
* @return <p>True if this portal was verified</p>
*/
public boolean wasVerified() {
if (!Stargate.verifyPortals) {
if (!Stargate.getGateConfig().verifyPortals()) {
return true;
}
return verified;
@ -95,10 +95,11 @@ public class PortalStructure {
* @return <p>True if all blocks match the gate template</p>
*/
public boolean checkIntegrity() {
if (!Stargate.verifyPortals) {
if (Stargate.getGateConfig().verifyPortals()) {
return gate.matches(portal.getTopLeft(), portal.getYaw());
} else {
return true;
}
return gate.matches(portal.getTopLeft(), portal.getYaw());
}
/**

View File

@ -30,9 +30,9 @@ public final class EconomyHelper {
//Try to charge the player. Paying the portal owner is only possible if a UUID is available
if (entrancePortal.getGate().getToOwner()) {
UUID ownerUUID = entrancePortal.getOwner().getUUID();
success = ownerUUID != null && EconomyHandler.chargePlayerIfNecessary(player, ownerUUID, cost);
success = ownerUUID != null && Stargate.getEconomyConfig().chargePlayerIfNecessary(player, ownerUUID, cost);
} else {
success = EconomyHandler.chargePlayerIfNecessary(player, cost);
success = Stargate.getEconomyConfig().chargePlayerIfNecessary(player, cost);
}
//Send the insufficient funds message
@ -124,7 +124,7 @@ public final class EconomyHelper {
*/
private static String replaceVars(String message, String portalName, int cost) {
return Stargate.replaceVars(message, new String[]{"%cost%", "%portal%"},
new String[]{EconomyHandler.format(cost), portalName});
new String[]{Stargate.getEconomyConfig().format(cost), portalName});
}
}

View File

@ -232,7 +232,7 @@ public final class PermissionHelper {
return true;
}
// Don't charge for free destination gates
return dest != null && !EconomyHandler.chargeFreeDestination && dest.getOptions().isFree();
return dest != null && !Stargate.getEconomyConfig().chargeFreeDestination() && dest.getOptions().isFree();
}
/**
@ -409,7 +409,7 @@ public final class PermissionHelper {
}
//Player cannot pay for teleportation
int cost = EconomyHandler.getUseCost(player, entrancePortal, destination);
int cost = Stargate.getEconomyConfig().getUseCost(player, entrancePortal, destination);
if (cost > 0) {
return EconomyHelper.cannotPayTeleportFee(entrancePortal, player, cost);
}