Improves config readability, but breaks backwards compatibility

This commit is contained in:
Kristian Knarvik 2021-09-19 17:46:20 +02:00
parent d5e6f1145c
commit 8ff30ed03f
3 changed files with 143 additions and 123 deletions

View File

@ -12,7 +12,6 @@ import net.knarcraft.stargate.listener.PluginEventListener;
import net.knarcraft.stargate.listener.PortalEventListener; import net.knarcraft.stargate.listener.PortalEventListener;
import net.knarcraft.stargate.listener.VehicleEventListener; import net.knarcraft.stargate.listener.VehicleEventListener;
import net.knarcraft.stargate.listener.WorldEventListener; import net.knarcraft.stargate.listener.WorldEventListener;
import net.knarcraft.stargate.portal.Gate;
import net.knarcraft.stargate.portal.GateHandler; import net.knarcraft.stargate.portal.GateHandler;
import net.knarcraft.stargate.portal.Portal; import net.knarcraft.stargate.portal.Portal;
import net.knarcraft.stargate.portal.PortalHandler; import net.knarcraft.stargate.portal.PortalHandler;
@ -34,6 +33,7 @@ import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.java.JavaPluginLoader; import org.bukkit.plugin.java.JavaPluginLoader;
import org.bukkit.plugin.messaging.Messenger;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
@ -41,7 +41,6 @@ import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Map; import java.util.Map;
import java.util.Queue; import java.util.Queue;
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -57,9 +56,9 @@ public class Stargate extends JavaPlugin {
public static Stargate stargate; public static Stargate stargate;
public static LanguageLoader languageLoader; public static LanguageLoader languageLoader;
public static int maxGates = 0; public static int maxGates = 0;
public static boolean destMemory = false; public static boolean rememberDestination = false;
public static boolean handleVehicles = true; public static boolean handleVehicles = true;
public static boolean sortLists = false; public static boolean sortNetworkDestinations = false;
public static boolean protectEntrance = false; public static boolean protectEntrance = false;
public static boolean enableBungee = true; public static boolean enableBungee = true;
public static boolean verifyPortals = true; public static boolean verifyPortals = true;
@ -81,9 +80,9 @@ public class Stargate extends JavaPlugin {
private static String gateFolder; private static String gateFolder;
private static String defaultGateNetwork = "central"; private static String defaultGateNetwork = "central";
private static boolean destroyExplosion = false; private static boolean destroyExplosion = false;
private static String langName = "en"; private static String languageName = "en";
private FileConfiguration newConfig; private FileConfiguration newConfig;
private PluginManager pm; private PluginManager pluginManager;
public Stargate() { public Stargate() {
super(); super();
@ -503,7 +502,7 @@ public class Stargate extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
PluginDescriptionFile pluginDescriptionFile = this.getDescription(); PluginDescriptionFile pluginDescriptionFile = this.getDescription();
pm = getServer().getPluginManager(); pluginManager = getServer().getPluginManager();
newConfig = this.getConfig(); newConfig = this.getConfig();
log = Logger.getLogger("Minecraft"); log = Logger.getLogger("Minecraft");
Stargate.server = getServer(); Stargate.server = getServer();
@ -520,38 +519,31 @@ public class Stargate extends JavaPlugin {
log.info(pluginDescriptionFile.getName() + " v." + pluginDescriptionFile.getVersion() + " is enabled."); log.info(pluginDescriptionFile.getName() + " v." + pluginDescriptionFile.getVersion() + " is enabled.");
// Register events before loading gates to stop weird things happening. // Register events before loading gates to stop weird things happening.
pm.registerEvents(new PlayerEventListener(), this); pluginManager.registerEvents(new PlayerEventListener(), this);
pm.registerEvents(new BlockEventListener(), this); pluginManager.registerEvents(new BlockEventListener(), this);
pm.registerEvents(new VehicleEventListener(), this); pluginManager.registerEvents(new VehicleEventListener(), this);
pm.registerEvents(new EntityEventListener(), this); pluginManager.registerEvents(new EntityEventListener(), this);
pm.registerEvents(new PortalEventListener(), this); pluginManager.registerEvents(new PortalEventListener(), this);
pm.registerEvents(new WorldEventListener(), this); pluginManager.registerEvents(new WorldEventListener(), this);
pm.registerEvents(new PluginEventListener(this), this); pluginManager.registerEvents(new PluginEventListener(this), this);
this.loadConfig(); this.loadConfig();
// Enable the required channels for Bungee support // Enable the required channels for Bungee support
if (enableBungee) { if (enableBungee) {
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); startStopBungeeListener(true);
Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeCordListener());
} }
// It is important to load languages here, as they are used during reloadGates() // It is important to load languages here, as they are used during reloadGates()
languageLoader = new LanguageLoader(languageFolder, Stargate.langName); languageLoader = new LanguageLoader(languageFolder, Stargate.languageName);
this.migrate(); this.migrate();
this.loadGates(); this.loadGates();
this.loadAllPortals(); this.loadAllPortals();
// Check to see if Economy is loaded yet. // Check to see if Economy is loaded yet.
if (EconomyHandler.setupEconomy(pm)) { setupVaultEconomy();
if (EconomyHandler.economy != null) {
String vaultVersion = EconomyHandler.vault.getDescription().getVersion();
log.info(Stargate.getString("prefix") +
replaceVars(Stargate.getString("vaultLoaded"), "%version%", vaultVersion));
}
}
getServer().getScheduler().runTaskTimer(this, new StarGateThread(), 0L, 100L); getServer().getScheduler().runTaskTimer(this, new StarGateThread(), 0L, 100L);
getServer().getScheduler().runTaskTimer(this, new BlockChangeThread(), 0L, 1L); getServer().getScheduler().runTaskTimer(this, new BlockChangeThread(), 0L, 1L);
@ -574,34 +566,34 @@ public class Stargate extends JavaPlugin {
newConfig.options().copyDefaults(true); newConfig.options().copyDefaults(true);
// Load values into variables // Load values into variables
portalFolder = newConfig.getString("portal-folder"); portalFolder = newConfig.getString("folders.portalFolder");
gateFolder = newConfig.getString("gate-folder"); gateFolder = newConfig.getString("folders.gateFolder");
String defaultNetwork = newConfig.getString("default-gate-network"); String defaultNetwork = newConfig.getString("gates.defaultGateNetwork");
defaultGateNetwork = defaultNetwork != null ? defaultNetwork.trim() : null; defaultGateNetwork = defaultNetwork != null ? defaultNetwork.trim() : null;
destroyExplosion = newConfig.getBoolean("destroyexplosion"); destroyExplosion = newConfig.getBoolean("gates.destroyedByExplosion");
maxGates = newConfig.getInt("maxgates"); maxGates = newConfig.getInt("gates.maxGatesEachNetwork");
langName = newConfig.getString("lang"); languageName = newConfig.getString("language");
destMemory = newConfig.getBoolean("destMemory"); rememberDestination = newConfig.getBoolean("gates.cosmetic.rememberDestination");
ignoreEntrance = newConfig.getBoolean("ignoreEntrance"); ignoreEntrance = newConfig.getBoolean("gates.integrity.ignoreEntrance");
handleVehicles = newConfig.getBoolean("handleVehicles"); handleVehicles = newConfig.getBoolean("gates.functionality.handleVehicles");
sortLists = newConfig.getBoolean("sortLists"); sortNetworkDestinations = newConfig.getBoolean("gates.cosmetic.sortNetworkDestinations");
protectEntrance = newConfig.getBoolean("protectEntrance"); protectEntrance = newConfig.getBoolean("gates.integrity.protectEntrance");
enableBungee = newConfig.getBoolean("enableBungee"); enableBungee = newConfig.getBoolean("gates.functionality.enableBungee");
verifyPortals = newConfig.getBoolean("verifyPortals"); verifyPortals = newConfig.getBoolean("gates.integrity.verifyPortals");
// Sign color // Sign color
loadSignColor(newConfig.getString("signColor")); loadSignColor(newConfig.getString("gates.cosmetic.signColor"));
// Debug // Debug
debuggingEnabled = newConfig.getBoolean("debug"); debuggingEnabled = newConfig.getBoolean("debugging.debug");
permissionDebuggingEnabled = newConfig.getBoolean("permdebug"); permissionDebuggingEnabled = newConfig.getBoolean("debugging.permissionDebug");
// Economy // Economy
EconomyHandler.economyEnabled = newConfig.getBoolean("useeconomy"); EconomyHandler.economyEnabled = newConfig.getBoolean("economy.useEconomy");
EconomyHandler.setCreateCost(newConfig.getInt("createcost")); EconomyHandler.setCreateCost(newConfig.getInt("economy.createCost"));
EconomyHandler.setDestroyCost(newConfig.getInt("destroycost")); EconomyHandler.setDestroyCost(newConfig.getInt("economy.destroyCost"));
EconomyHandler.setUseCost(newConfig.getInt("usecost")); EconomyHandler.setUseCost(newConfig.getInt("economy.useCost"));
EconomyHandler.toOwner = newConfig.getBoolean("toowner"); EconomyHandler.toOwner = newConfig.getBoolean("economy.toOwner");
EconomyHandler.chargeFreeDestination = newConfig.getBoolean("chargefreedestination"); EconomyHandler.chargeFreeDestination = newConfig.getBoolean("economy.chargeFreeDestination");
EconomyHandler.freeGatesGreen = newConfig.getBoolean("freegatesgreen"); EconomyHandler.freeGatesGreen = newConfig.getBoolean("economy.freeGatesGreen");
this.saveConfig(); this.saveConfig();
} }
@ -618,8 +610,7 @@ public class Stargate extends JavaPlugin {
} catch (IllegalArgumentException | NullPointerException ignored) { } catch (IllegalArgumentException | NullPointerException ignored) {
} }
} }
log.warning(Stargate.getString("prefix") + "You have specified an invalid color in your config.yml." + log.warning(getString("prefix") + "You have specified an invalid color in your config.yml. Defaulting to BLACK");
" Defaulting to BLACK");
Stargate.signColor = ChatColor.BLACK; Stargate.signColor = ChatColor.BLACK;
} }
@ -664,7 +655,7 @@ public class Stargate extends JavaPlugin {
* Check if a plugin is loaded/enabled already. Returns the plugin if so, null otherwise * Check if a plugin is loaded/enabled already. Returns the plugin if so, null otherwise
*/ */
private Plugin checkPlugin(String p) { private Plugin checkPlugin(String p) {
Plugin plugin = pm.getPlugin(p); Plugin plugin = pluginManager.getPlugin(p);
return checkPlugin(plugin); return checkPlugin(plugin);
} }
@ -683,8 +674,8 @@ public class Stargate extends JavaPlugin {
*/ */
public void reload(CommandSender sender) { public void reload(CommandSender sender) {
// Deactivate portals // Deactivate portals
for (Portal p : activeList) { for (Portal activePortal : activeList) {
p.deactivate(); activePortal.deactivate();
} }
// Close portals // Close portals
closeAllPortals(); closeAllPortals();
@ -701,36 +692,57 @@ public class Stargate extends JavaPlugin {
loadConfig(); loadConfig();
loadGates(); loadGates();
loadAllPortals(); loadAllPortals();
languageLoader.setChosenLanguage(langName); languageLoader.setChosenLanguage(languageName);
languageLoader.reload(); languageLoader.reload();
// Load Economy support if enabled/clear if disabled //Load Economy support if enabled/clear if disabled
if (EconomyHandler.economyEnabled && EconomyHandler.economy == null) { reloadEconomy();
if (EconomyHandler.setupEconomy(pm)) {
if (EconomyHandler.economy != null) {
String vaultVersion = EconomyHandler.vault.getDescription().getVersion();
log.info(Stargate.getString("prefix") + Stargate.replaceVars(
Stargate.getString("vaultLoaded"), "%version%", vaultVersion));
}
}
}
if (!EconomyHandler.economyEnabled) {
EconomyHandler.vault = null;
EconomyHandler.economy = null;
}
// Enable the required channels for Bungee support //Enable or disable the required channels for Bungee support
if (oldEnableBungee != enableBungee) { if (oldEnableBungee != enableBungee) {
if (enableBungee) { startStopBungeeListener(enableBungee);
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeCordListener());
} else {
Bukkit.getMessenger().unregisterIncomingPluginChannel(this, "BungeeCord");
Bukkit.getMessenger().unregisterOutgoingPluginChannel(this, "BungeeCord");
}
} }
sendMessage(sender, "stargate reloaded"); sendMessage(sender, "stargate reloaded");
} }
/**
* Reloads economy by enabling or disabling it as necessary
*/
private void reloadEconomy() {
if (EconomyHandler.economyEnabled && EconomyHandler.economy == null) {
setupVaultEconomy();
} else if (!EconomyHandler.economyEnabled) {
EconomyHandler.vault = null;
EconomyHandler.economy = null;
}
}
/**
* Loads economy from Vault
*/
private void setupVaultEconomy() {
if (EconomyHandler.setupEconomy(pluginManager) && EconomyHandler.economy != null) {
String vaultVersion = EconomyHandler.vault.getDescription().getVersion();
log.info(Stargate.getString("prefix") + Stargate.replaceVars(
Stargate.getString("vaultLoaded"), "%version%", vaultVersion));
}
}
/**
* Starts the listener for listening to BungeeCord messages
*/
private void startStopBungeeListener(boolean start) {
Messenger messenger = Bukkit.getMessenger();
String bungeeChannel = "BungeeCord";
if (start) {
messenger.registerOutgoingPluginChannel(this, bungeeChannel);
messenger.registerIncomingPluginChannel(this, bungeeChannel, new BungeeCordListener());
} else {
messenger.unregisterIncomingPluginChannel(this, bungeeChannel);
messenger.unregisterOutgoingPluginChannel(this, bungeeChannel);
}
}
} }

View File

@ -1029,10 +1029,10 @@ public class Portal {
activePlayer = player; activePlayer = player;
String network = getNetwork(); String network = getNetwork();
destinations = PortalHandler.getDestinations(this, player, network); destinations = PortalHandler.getDestinations(this, player, network);
if (Stargate.sortLists) { if (Stargate.sortNetworkDestinations) {
Collections.sort(destinations); Collections.sort(destinations);
} }
if (Stargate.destMemory && !lastDestination.isEmpty() && destinations.contains(lastDestination)) { if (Stargate.rememberDestination && !lastDestination.isEmpty() && destinations.contains(lastDestination)) {
destination = lastDestination; destination = lastDestination;
} }
@ -1113,7 +1113,7 @@ public class Portal {
return; return;
} }
if (!Stargate.destMemory || !activate || lastDestination.isEmpty()) { if (!Stargate.rememberDestination || !activate || lastDestination.isEmpty()) {
cycleDestination(direction); cycleDestination(direction);
} }
openTime = System.currentTimeMillis() / 1000; openTime = System.currentTimeMillis() / 1000;

View File

@ -1,54 +1,62 @@
# stargate Configuration File # stargate Configuration File
# Main stargate config # Main stargate config
# # I----------I----------I #
# portal-folder - The folder for storing portals # portalFolder - The folder for storing portals
# gate-folder - The folder for storing gate layouts # gateFolder - The folder for storing gate layouts
# default-gate-network - The default gate network # defaultGateNetwork - The default gate network
# destroyexplosion - Whether or not to destroy gates with explosions (Creeper, TNT, etc) # destroyedByExplosion - Whether to destroy gates with explosions (Creeper, TNT, etc.)
# maxgates - The maximum number of gates allowed on a network - 0 for unlimited # maxGatesEachNetwork - The maximum number of gates allowed on a network - 0 for unlimited
# lang - The language file to load for messages # language - The language file to load for messages
# destMemory - Whether to remember the cursor location between uses # rememberDestination - Whether to remember the cursor location between uses
# ignoreEntrance - Ignore the entrance blocks of a gate when checking. Used to work around snowmen # ignoreEntrance - Ignore the entrance blocks of a gate when checking. Used to work around snowmen
# handleVehicles - Whether to allow vehicles through gates # handleVehicles - Whether to allow vehicles through gates
# sortLists - Whether to sort network lists alphabetically # sortNetworkDestinations - Whether to sort network lists alphabetically
# protectEntrance - Whether to protect gate entrance material (More resource intensive. Only enable if using destroyable open/closed material) # protectEntrance - Whether to protect gate entrance material (More resource intensive. Only enable if using destroyable open/closed material)
# signColor - The color used for drawing signs (Default: BLACK). # signColor - The color used for drawing signs (Default: BLACK).
# verifyPortals - Whether or not all the non-sign blocks are checked to match the gate layout when a stargate is loaded. # verifyPortals - Whether all the non-sign blocks are checked to match the gate layout when a stargate is loaded.
############################ # I------------I-------------I #
# stargate economy options # # stargate economy options #
############################ # I------------I-------------I #
# useeconomy - Whether to use an economy plugin # useEconomy - Whether to use an economy plugin
# createcost - The cost to create a gate # createCost - The cost to create a gate
# destroycost - The cost to destroy a gate # destroyCost - The cost to destroy a gate
# usecost - The cost to use a gate # useCost - The cost to use a gate
# toowner - Whether the charge for using a gate goes to the gates owner # toOwner - Whether the charge for using a gate goes to the gate's owner
# chargefreedestination - Whether a gate whose destination is a free gate is still charged # chargeFreeDestination - Whether a gate whose destination is a free gate is still charged
# freegatesgreen - Whether a free gate in the destination list is drawn green # freeGatesGreen - Whether a free gate in the destination list is drawn green
################# # I-------I-------I #
# Debug options # # Debug options #
################# # I-------I-------I #
# debug - Debug -- Only enable if you have issues, massive console output # debug - Debug -- Only enable if you have issues, massive console output
# permdebug - This will output any and all Permissions checks to console, used for permissions debugging (Requires debug: true) # permissionDebug - This will output any and all Permissions checks to console, used for permissions debugging (Requires debug: true)
portal-folder: plugins/stargate/portals/
gate-folder: plugins/stargate/gates/ language: en
default-gate-network: central folders:
destroyexplosion: false portalFolder: plugins/stargate/portals/
maxgates: 0 gateFolder: plugins/stargate/gates/
lang: en gates:
destMemory: false maxGatesEachNetwork: 0
ignoreEntrance: false defaultGateNetwork: central
handleVehicles: true cosmetic:
sortLists: false rememberDestination: false
protectEntrance: false sortNetworkDestinations: false
signColor: BLACK signColor: BLACK
useeconomy: false integrity:
createcost: 0 destroyedByExplosion: false
destroycost: 0 verifyPortals: false
usecost: 0 protectEntrance: false
toowner: false ignoreEntrance: false
chargefreedestination: true functionality:
freegatesgreen: false enableBungee: false
debug: false handleVehicles: true
permdebug: false economy:
enableBungee: false useEconomy: false
verifyPortals: false createCost: 0
destroyCost: 0
useCost: 0
toOwner: false
chargeFreeDestination: true
freeGatesGreen: false
debugging:
debug: false
permissionDebug: false