Moves all config related code from Stargate to StargateConfig
This commit is contained in:
parent
b7998023f5
commit
2541391d3e
@ -3,13 +3,12 @@ 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.MessageSender;
|
||||
import net.knarcraft.stargate.config.StargateConfig;
|
||||
import net.knarcraft.stargate.config.StargateGateConfig;
|
||||
import net.knarcraft.stargate.container.BlockChangeRequest;
|
||||
import net.knarcraft.stargate.container.ChunkUnloadRequest;
|
||||
import net.knarcraft.stargate.listener.BlockEventListener;
|
||||
import net.knarcraft.stargate.listener.BungeeCordListener;
|
||||
import net.knarcraft.stargate.listener.EntityEventListener;
|
||||
import net.knarcraft.stargate.listener.PlayerEventListener;
|
||||
import net.knarcraft.stargate.listener.PluginEventListener;
|
||||
@ -17,34 +16,23 @@ import net.knarcraft.stargate.listener.PortalEventListener;
|
||||
import net.knarcraft.stargate.listener.TeleportEventListener;
|
||||
import net.knarcraft.stargate.listener.VehicleEventListener;
|
||||
import net.knarcraft.stargate.listener.WorldEventListener;
|
||||
import net.knarcraft.stargate.portal.GateHandler;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
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.FileHelper;
|
||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||
import org.bukkit.plugin.messaging.Messenger;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.PriorityQueue;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
@ -63,28 +51,11 @@ public class Stargate extends JavaPlugin {
|
||||
private static Logger logger;
|
||||
public static Server server;
|
||||
public static Stargate stargate;
|
||||
public static LanguageLoader languageLoader;
|
||||
|
||||
private String dataFolderPath;
|
||||
private static StargateGateConfig stargateGateConfig;
|
||||
private static EconomyConfig economyConfig;
|
||||
|
||||
//Used for debug
|
||||
public static boolean debuggingEnabled = false;
|
||||
public static boolean permissionDebuggingEnabled = false;
|
||||
|
||||
//World names that contain stargates
|
||||
public static final HashSet<String> managedWorlds = new HashSet<>();
|
||||
|
||||
private static String pluginVersion;
|
||||
private static String portalFolder;
|
||||
private static String gateFolder;
|
||||
|
||||
private static String languageName = "en";
|
||||
|
||||
private FileConfiguration newConfig;
|
||||
private PluginManager pluginManager;
|
||||
private static MessageSender messageSender;
|
||||
private static PluginManager pluginManager;
|
||||
private static StargateConfig stargateConfig;
|
||||
|
||||
/**
|
||||
* Empty constructor necessary for Spigot
|
||||
@ -111,7 +82,7 @@ public class Stargate extends JavaPlugin {
|
||||
* @return <p>The sender for sending messages to players</p>
|
||||
*/
|
||||
public static MessageSender getMessageSender() {
|
||||
return messageSender;
|
||||
return stargateConfig.getMessageSender();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -120,16 +91,7 @@ public class Stargate extends JavaPlugin {
|
||||
* @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;
|
||||
return stargateConfig.getStargateGateConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -141,15 +103,6 @@ public class Stargate extends JavaPlugin {
|
||||
return pluginVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether portals should be destroyed by explosions
|
||||
*
|
||||
* @return <p>True if portals should be destroyed</p>
|
||||
*/
|
||||
public static boolean destroyedByExplosion() {
|
||||
return stargateGateConfig.destroyedByExplosion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the logger used for logging to the console
|
||||
*
|
||||
@ -166,24 +119,13 @@ public class Stargate extends JavaPlugin {
|
||||
* @param message <p>A message describing what happened</p>
|
||||
*/
|
||||
public static void debug(String route, String message) {
|
||||
if (Stargate.debuggingEnabled) {
|
||||
if (Stargate.stargateConfig.isDebuggingEnabled()) {
|
||||
logger.info("[stargate::" + route + "] " + message);
|
||||
} else {
|
||||
logger.log(Level.FINEST, "[stargate::" + route + "] " + message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a line on a sign, adding the chosen sign color
|
||||
*
|
||||
* @param sign <p>The sign to update</p>
|
||||
* @param index <p>The index of the sign line to change</p>
|
||||
* @param text <p>The new text on the sign</p>
|
||||
*/
|
||||
public static void setLine(Sign sign, int index, String text) {
|
||||
sign.setLine(index, stargateGateConfig.getSignColor() + text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the folder for saving created portals
|
||||
*
|
||||
@ -191,8 +133,8 @@ public class Stargate extends JavaPlugin {
|
||||
*
|
||||
* @return <p>The folder for storing the portal database</p>
|
||||
*/
|
||||
public static String getSaveLocation() {
|
||||
return portalFolder;
|
||||
public static String getPortalFolder() {
|
||||
return stargateConfig.getPortalFolder();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -203,7 +145,7 @@ public class Stargate extends JavaPlugin {
|
||||
* @return <p>The folder storing gate files</p>
|
||||
*/
|
||||
public static String getGateFolder() {
|
||||
return gateFolder;
|
||||
return stargateConfig.getGateFolder();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -212,7 +154,7 @@ public class Stargate extends JavaPlugin {
|
||||
* @return <p>The default network</p>
|
||||
*/
|
||||
public static String getDefaultNetwork() {
|
||||
return stargateGateConfig.getDefaultPortalNetwork();
|
||||
return stargateConfig.getStargateGateConfig().getDefaultPortalNetwork();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -224,7 +166,7 @@ public class Stargate extends JavaPlugin {
|
||||
* @return <p>The full translated string</p>
|
||||
*/
|
||||
public static String getString(String name) {
|
||||
return languageLoader.getString(name);
|
||||
return stargateConfig.getLanguageLoader().getString(name);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -257,11 +199,29 @@ public class Stargate extends JavaPlugin {
|
||||
return input.replace(search, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets this plugin's plugin manager
|
||||
*
|
||||
* @return <p>A plugin manager</p>
|
||||
*/
|
||||
public static PluginManager getPluginManager() {
|
||||
return pluginManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the object containing economy config values
|
||||
*
|
||||
* @return <p>The object containing economy config values</p>
|
||||
*/
|
||||
public static EconomyConfig getEconomyConfig() {
|
||||
return stargateConfig.getEconomyConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
PortalHandler.closeAllPortals();
|
||||
PortalRegistry.clearPortals();
|
||||
managedWorlds.clear();
|
||||
stargateConfig.clearManagedWorlds();
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
}
|
||||
|
||||
@ -269,52 +229,35 @@ public class Stargate extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
PluginDescriptionFile pluginDescriptionFile = this.getDescription();
|
||||
pluginManager = getServer().getPluginManager();
|
||||
newConfig = this.getConfig();
|
||||
FileConfiguration newConfig = this.getConfig();
|
||||
logger = Logger.getLogger("Minecraft");
|
||||
Stargate.server = getServer();
|
||||
Stargate.stargate = this;
|
||||
|
||||
// Set portalFile and gateFolder to the plugin folder as defaults.
|
||||
dataFolderPath = getDataFolder().getPath().replaceAll("\\\\", "/");
|
||||
portalFolder = dataFolderPath + "/portals/";
|
||||
gateFolder = dataFolderPath + "/gates/";
|
||||
String languageFolder = dataFolderPath + "/lang/";
|
||||
stargateConfig = new StargateConfig(logger);
|
||||
stargateConfig.finishSetup();
|
||||
|
||||
pluginVersion = pluginDescriptionFile.getVersion();
|
||||
|
||||
logger.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 from happening.
|
||||
registerEventListeners();
|
||||
|
||||
this.loadConfig();
|
||||
|
||||
//Enable the required channels for Bungee support
|
||||
if (stargateGateConfig.enableBungee()) {
|
||||
startStopBungeeListener(true);
|
||||
}
|
||||
|
||||
// It is important to load languages here, as they are used during reloadGates()
|
||||
languageLoader = new LanguageLoader(languageFolder, Stargate.languageName);
|
||||
messageSender = new MessageSender(languageLoader);
|
||||
if (debuggingEnabled) {
|
||||
languageLoader.debug();
|
||||
}
|
||||
|
||||
this.createMissingFolders();
|
||||
this.loadGates();
|
||||
this.loadAllPortals();
|
||||
|
||||
//Check to see if Economy is loaded yet.
|
||||
setupVaultEconomy();
|
||||
|
||||
//Run necessary threads
|
||||
runThreads();
|
||||
|
||||
this.registerCommands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts threads using the bukkit scheduler
|
||||
*/
|
||||
private void runThreads() {
|
||||
BukkitScheduler scheduler = getServer().getScheduler();
|
||||
scheduler.runTaskTimer(this, new StarGateThread(), 0L, 100L);
|
||||
scheduler.runTaskTimer(this, new BlockChangeThread(), 0L, 1L);
|
||||
scheduler.runTaskTimer(this, new ChunkUnloadThread(), 0L, 100L);
|
||||
|
||||
this.registerCommands();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -338,218 +281,11 @@ public class Stargate extends JavaPlugin {
|
||||
private void registerCommands() {
|
||||
PluginCommand stargateCommand = this.getCommand("stargate");
|
||||
if (stargateCommand != null) {
|
||||
stargateCommand.setExecutor(new CommandStarGate(this));
|
||||
stargateCommand.setExecutor(new CommandStarGate());
|
||||
stargateCommand.setTabCompleter(new StarGateTabCompleter());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all config values
|
||||
*/
|
||||
public void loadConfig() {
|
||||
this.reloadConfig();
|
||||
newConfig = this.getConfig();
|
||||
|
||||
boolean isMigrating = false;
|
||||
if (newConfig.getString("lang") != null ||
|
||||
newConfig.getString("gates.integrity.ignoreEntrance") != null ||
|
||||
newConfig.getString("ignoreEntrance") != null) {
|
||||
migrateConfig(newConfig);
|
||||
isMigrating = true;
|
||||
}
|
||||
|
||||
// Copy default values if required
|
||||
newConfig.options().copyDefaults(true);
|
||||
|
||||
//Language
|
||||
languageName = newConfig.getString("language");
|
||||
|
||||
//Folders
|
||||
portalFolder = newConfig.getString("folders.portalFolder");
|
||||
gateFolder = newConfig.getString("folders.gateFolder");
|
||||
|
||||
//Debug
|
||||
debuggingEnabled = newConfig.getBoolean("debugging.debug");
|
||||
permissionDebuggingEnabled = newConfig.getBoolean("debugging.permissionDebug");
|
||||
|
||||
//If users have an outdated config, assume they also need to update their default gates
|
||||
if (isMigrating) {
|
||||
GateHandler.writeDefaultGatesToFolder(gateFolder);
|
||||
}
|
||||
|
||||
//Gates
|
||||
stargateGateConfig = new StargateGateConfig(newConfig);
|
||||
|
||||
//Economy
|
||||
economyConfig = new EconomyConfig(newConfig);
|
||||
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes all configuration values from the old name to the new name
|
||||
*
|
||||
* @param newConfig <p>The config to read from and write to</p>
|
||||
*/
|
||||
private void migrateConfig(FileConfiguration newConfig) {
|
||||
try {
|
||||
newConfig.save(dataFolderPath + "/config.old");
|
||||
} catch (IOException e) {
|
||||
Stargate.debug("Stargate::migrateConfig", "Unable to save old backup and do migration");
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, String> migrationFields;
|
||||
try {
|
||||
migrationFields = FileHelper.readKeyValuePairs(FileHelper.getBufferedReaderFromInputStream(
|
||||
FileHelper.getInputStreamForInternalFile("/config-migrations.txt")));
|
||||
} catch (IOException e) {
|
||||
Stargate.debug("Stargate::migrateConfig", "Unable to load config migration file");
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
//Replace old config names with the new ones
|
||||
for (String key : migrationFields.keySet()) {
|
||||
if (newConfig.contains(key)) {
|
||||
String newPath = migrationFields.get(key);
|
||||
Object oldValue = newConfig.get(key);
|
||||
if (!newPath.trim().isEmpty()) {
|
||||
newConfig.set(newPath, oldValue);
|
||||
}
|
||||
newConfig.set(key, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces all open portals to close
|
||||
*/
|
||||
public void closeAllPortals() {
|
||||
// Close all gates prior to reloading
|
||||
for (Portal openPortal : openPortalsQueue) {
|
||||
openPortal.getPortalOpener().closePortal(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all available gates
|
||||
*/
|
||||
public void loadGates() {
|
||||
GateHandler.loadGates(gateFolder);
|
||||
logger.info(Stargate.getString("prefix") + "Loaded " + GateHandler.getGateCount() + " gate layouts");
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all portals in all un-managed worlds
|
||||
*/
|
||||
public void loadAllPortals() {
|
||||
for (World world : getServer().getWorlds()) {
|
||||
if (!managedWorlds.contains(world.getName())) {
|
||||
PortalFileHelper.loadAllPortals(world);
|
||||
managedWorlds.add(world.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates missing folders
|
||||
*/
|
||||
private void createMissingFolders() {
|
||||
File newPortalDir = new File(portalFolder);
|
||||
if (!newPortalDir.exists()) {
|
||||
if (!newPortalDir.mkdirs()) {
|
||||
logger.severe("Unable to create portal directory");
|
||||
}
|
||||
}
|
||||
File newFile = new File(portalFolder, getServer().getWorlds().get(0).getName() + ".db");
|
||||
if (!newFile.exists() && !newFile.getParentFile().exists()) {
|
||||
if (!newFile.getParentFile().mkdirs()) {
|
||||
logger.severe("Unable to create portal database folder: " + newFile.getParentFile().getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads all portals and files
|
||||
*
|
||||
* @param sender <p>The sender of the reload request</p>
|
||||
*/
|
||||
public void reload(CommandSender sender) {
|
||||
// Deactivate portals
|
||||
for (Portal activePortal : activePortalsQueue) {
|
||||
activePortal.getPortalActivator().deactivate();
|
||||
}
|
||||
// Close portals
|
||||
closeAllPortals();
|
||||
// Clear all lists
|
||||
activePortalsQueue.clear();
|
||||
openPortalsQueue.clear();
|
||||
managedWorlds.clear();
|
||||
PortalRegistry.clearPortals();
|
||||
GateHandler.clearGates();
|
||||
|
||||
// Store the old Bungee enabled value
|
||||
boolean oldEnableBungee = stargateGateConfig.enableBungee();
|
||||
// Reload data
|
||||
loadConfig();
|
||||
loadGates();
|
||||
loadAllPortals();
|
||||
languageLoader.setChosenLanguage(languageName);
|
||||
languageLoader.reload();
|
||||
|
||||
//Load Economy support if enabled/clear if disabled
|
||||
reloadEconomy();
|
||||
|
||||
//Enable or disable the required channels for Bungee support
|
||||
if (oldEnableBungee != stargateGateConfig.enableBungee()) {
|
||||
startStopBungeeListener(stargateGateConfig.enableBungee());
|
||||
}
|
||||
|
||||
messageSender.sendErrorMessage(sender, "stargate reloaded");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads economy by enabling or disabling it as necessary
|
||||
*/
|
||||
private void reloadEconomy() {
|
||||
EconomyConfig economyConfig = Stargate.getEconomyConfig();
|
||||
if (economyConfig.isEconomyEnabled() && economyConfig.getEconomy() == null) {
|
||||
setupVaultEconomy();
|
||||
} else if (!economyConfig.isEconomyEnabled()) {
|
||||
economyConfig.disableEconomy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads economy from Vault
|
||||
*/
|
||||
private void setupVaultEconomy() {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the chunk unload queue containing chunks to unload
|
||||
*
|
||||
@ -569,4 +305,12 @@ public class Stargate extends JavaPlugin {
|
||||
chunkUnloadQueue.add(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the stargate configuration
|
||||
*
|
||||
* @return <p>The stargate configuration</p>
|
||||
*/
|
||||
public static StargateConfig getStargateConfig() {
|
||||
return stargateConfig;
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public class CommandAbout implements CommandExecutor {
|
||||
"Drakia" + textColor + ", and revived by " + highlightColor + "EpicKnarvik97");
|
||||
commandSender.sendMessage(textColor + "Go to " + highlightColor +
|
||||
"https://git.knarcraft.net/EpicKnarvik97/Stargate " + textColor + "for the official repository");
|
||||
String author = Stargate.languageLoader.getString("author");
|
||||
String author = Stargate.getStargateConfig().getLanguageLoader().getString("author");
|
||||
if (!author.isEmpty())
|
||||
commandSender.sendMessage(textColor + "Language created by " + highlightColor + author);
|
||||
return true;
|
||||
|
@ -12,17 +12,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public class CommandReload implements CommandExecutor {
|
||||
|
||||
private final Stargate plugin;
|
||||
|
||||
/**
|
||||
* Instantiates the reload command
|
||||
*
|
||||
* @param plugin <p>A reference to the calling plugin object</p>
|
||||
*/
|
||||
public CommandReload(Stargate plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] args) {
|
||||
@ -32,7 +21,7 @@ public class CommandReload implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
plugin.reload(commandSender);
|
||||
Stargate.getStargateConfig().reload(commandSender);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -15,17 +15,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public class CommandStarGate implements CommandExecutor {
|
||||
|
||||
private final Stargate plugin;
|
||||
|
||||
/**
|
||||
* Instantiates the stargate command
|
||||
*
|
||||
* @param plugin <p>A reference to the calling plugin object</p>
|
||||
*/
|
||||
public CommandStarGate(Stargate plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] args) {
|
||||
@ -33,7 +22,7 @@ public class CommandStarGate implements CommandExecutor {
|
||||
if (args[0].equalsIgnoreCase("about")) {
|
||||
return new CommandAbout().onCommand(commandSender, command, s, args);
|
||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||
return new CommandReload(plugin).onCommand(commandSender, command, s, args);
|
||||
return new CommandReload().onCommand(commandSender, command, s, args);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
|
@ -34,7 +34,7 @@ public final class LanguageLoader {
|
||||
|
||||
File tmp = new File(languageFolder, chosenLanguage + ".txt");
|
||||
if (!tmp.exists()) {
|
||||
if (tmp.getParentFile().mkdirs() && Stargate.debuggingEnabled) {
|
||||
if (tmp.getParentFile().mkdirs() && Stargate.getStargateConfig().isDebuggingEnabled()) {
|
||||
Stargate.getConsoleLogger().info("[stargate] Created language folder");
|
||||
}
|
||||
}
|
||||
@ -104,7 +104,7 @@ public final class LanguageLoader {
|
||||
if (inputStream == null) {
|
||||
Stargate.getConsoleLogger().info("[stargate] The language " + language + " is not available. Falling " +
|
||||
"back to english, You can add a custom language by creating a new text file in the lang directory.");
|
||||
if (Stargate.debuggingEnabled) {
|
||||
if (Stargate.getStargateConfig().isDebuggingEnabled()) {
|
||||
Stargate.getConsoleLogger().info("[stargate] Unable to load /lang/" + language + ".txt");
|
||||
}
|
||||
return;
|
||||
@ -217,7 +217,7 @@ public final class LanguageLoader {
|
||||
}
|
||||
strings = FileHelper.readKeyValuePairs(bufferedReader);
|
||||
} catch (Exception e) {
|
||||
if (Stargate.debuggingEnabled) {
|
||||
if (Stargate.getStargateConfig().isDebuggingEnabled()) {
|
||||
Stargate.getConsoleLogger().info("[stargate] Unable to load language " + lang);
|
||||
}
|
||||
return null;
|
||||
@ -226,7 +226,7 @@ public final class LanguageLoader {
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints debug output to the console for checking of loading language strings/translations
|
||||
* Prints debug output to the console for checking loaded language strings/translations
|
||||
*/
|
||||
public void debug() {
|
||||
Set<String> keys = loadedStringTranslations.keySet();
|
||||
|
433
src/main/java/net/knarcraft/stargate/config/StargateConfig.java
Normal file
433
src/main/java/net/knarcraft/stargate/config/StargateConfig.java
Normal file
@ -0,0 +1,433 @@
|
||||
package net.knarcraft.stargate.config;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.listener.BungeeCordListener;
|
||||
import net.knarcraft.stargate.portal.GateHandler;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.utility.FileHelper;
|
||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.messaging.Messenger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* The stargate config is responsible for keeping track of all configuration values
|
||||
*/
|
||||
public final class StargateConfig {
|
||||
|
||||
public final ConcurrentLinkedQueue<Portal> activePortalsQueue = new ConcurrentLinkedQueue<>();
|
||||
public final ConcurrentLinkedQueue<Portal> openPortalsQueue = new ConcurrentLinkedQueue<>();
|
||||
private final HashSet<String> managedWorlds = new HashSet<>();
|
||||
|
||||
private StargateGateConfig stargateGateConfig;
|
||||
private MessageSender messageSender;
|
||||
public LanguageLoader languageLoader;
|
||||
private EconomyConfig economyConfig;
|
||||
private final Logger logger;
|
||||
|
||||
private final String languageFolder;
|
||||
private final String dataFolderPath;
|
||||
private String gateFolder;
|
||||
private String portalFolder;
|
||||
private String languageName = "en";
|
||||
|
||||
private boolean debuggingEnabled = false;
|
||||
private boolean permissionDebuggingEnabled = false;
|
||||
|
||||
/**
|
||||
* Instantiates a new stargate config
|
||||
*
|
||||
* @param logger <p>The logger to use for logging errors</p>
|
||||
*/
|
||||
public StargateConfig(Logger logger) {
|
||||
this.logger = logger;
|
||||
|
||||
dataFolderPath = Stargate.stargate.getDataFolder().getPath().replaceAll("\\\\", "/");
|
||||
portalFolder = dataFolderPath + "/portals/";
|
||||
gateFolder = dataFolderPath + "/gates/";
|
||||
languageFolder = dataFolderPath + "/lang/";
|
||||
|
||||
this.loadConfig();
|
||||
|
||||
//Enable the required channels for Bungee support
|
||||
if (stargateGateConfig.enableBungee()) {
|
||||
startStopBungeeListener(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish the config setup by loading languages, gates and portals, and loading economy if vault is loaded
|
||||
*/
|
||||
public void finishSetup() {
|
||||
//Load the translated strings before they're used by loadGates
|
||||
languageLoader = new LanguageLoader(languageFolder, languageName);
|
||||
messageSender = new MessageSender(languageLoader);
|
||||
if (debuggingEnabled) {
|
||||
languageLoader.debug();
|
||||
}
|
||||
|
||||
this.createMissingFolders();
|
||||
this.loadGates();
|
||||
this.loadAllPortals();
|
||||
|
||||
//Set up vault economy if vault has been loaded
|
||||
setupVaultEconomy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether debugging is enabled
|
||||
*
|
||||
* @return <p>Whether debugging is enabled</p>
|
||||
*/
|
||||
public boolean isDebuggingEnabled() {
|
||||
return debuggingEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether permission debugging is enabled
|
||||
*
|
||||
* @return <p>Whether permission debugging is enabled</p>
|
||||
*/
|
||||
public boolean isPermissionDebuggingEnabled() {
|
||||
return permissionDebuggingEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the object containing economy config values
|
||||
*
|
||||
* @return <p>The object containing economy config values</p>
|
||||
*/
|
||||
public EconomyConfig getEconomyConfig() {
|
||||
return this.economyConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads all portals and files
|
||||
*
|
||||
* @param sender <p>The sender of the reload request</p>
|
||||
*/
|
||||
public void reload(CommandSender sender) {
|
||||
//Unload all saved data
|
||||
unload();
|
||||
|
||||
//Store the old enable bungee state in case it changes
|
||||
boolean oldEnableBungee = stargateGateConfig.enableBungee();
|
||||
|
||||
//Load all data
|
||||
load();
|
||||
|
||||
//Enable or disable the required channels for Bungee support
|
||||
if (oldEnableBungee != stargateGateConfig.enableBungee()) {
|
||||
startStopBungeeListener(stargateGateConfig.enableBungee());
|
||||
}
|
||||
|
||||
messageSender.sendErrorMessage(sender, "stargate reloaded");
|
||||
}
|
||||
|
||||
/**
|
||||
* Un-loads all loaded data
|
||||
*/
|
||||
private void unload() {
|
||||
//De-activate all currently active portals
|
||||
for (Portal activePortal : activePortalsQueue) {
|
||||
activePortal.getPortalActivator().deactivate();
|
||||
}
|
||||
//Force all portals to close
|
||||
closeAllPortals();
|
||||
//Clear queues and lists
|
||||
activePortalsQueue.clear();
|
||||
openPortalsQueue.clear();
|
||||
managedWorlds.clear();
|
||||
|
||||
//Clear all loaded portals
|
||||
PortalRegistry.clearPortals();
|
||||
|
||||
//Clear all loaded gates
|
||||
GateHandler.clearGates();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the set of managed worlds
|
||||
*/
|
||||
public void clearManagedWorlds() {
|
||||
managedWorlds.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a copy of the set of managed worlds
|
||||
*
|
||||
* @return <p>The managed worlds</p>
|
||||
*/
|
||||
public Set<String> getManagedWorlds() {
|
||||
return new HashSet<>(managedWorlds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a world to the managed worlds
|
||||
*
|
||||
* @param worldName <p>The name of the world to manage</p>
|
||||
*/
|
||||
public void addManagedWorld(String worldName) {
|
||||
managedWorlds.add(worldName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a world from the managed worlds
|
||||
*
|
||||
* @param worldName <p>The name of the world to stop managing</p>
|
||||
*/
|
||||
public void removeManagedWorld(String worldName) {
|
||||
managedWorlds.remove(worldName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all necessary data
|
||||
*/
|
||||
private void load() {
|
||||
//Load the config from disk
|
||||
loadConfig();
|
||||
|
||||
//Load all gates
|
||||
loadGates();
|
||||
|
||||
//Load all portals
|
||||
loadAllPortals();
|
||||
|
||||
//Update the language loader in case the loaded language changed
|
||||
languageLoader.setChosenLanguage(languageName);
|
||||
languageLoader.reload();
|
||||
if (debuggingEnabled) {
|
||||
languageLoader.debug();
|
||||
}
|
||||
|
||||
//Load Economy support if enabled/clear if disabled
|
||||
reloadEconomy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the listener for listening to BungeeCord messages
|
||||
*/
|
||||
private void startStopBungeeListener(boolean start) {
|
||||
Messenger messenger = Bukkit.getMessenger();
|
||||
String bungeeChannel = "BungeeCord";
|
||||
|
||||
if (start) {
|
||||
messenger.registerOutgoingPluginChannel(Stargate.stargate, bungeeChannel);
|
||||
messenger.registerIncomingPluginChannel(Stargate.stargate, bungeeChannel, new BungeeCordListener());
|
||||
} else {
|
||||
messenger.unregisterIncomingPluginChannel(Stargate.stargate, bungeeChannel);
|
||||
messenger.unregisterOutgoingPluginChannel(Stargate.stargate, bungeeChannel);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads economy by enabling or disabling it as necessary
|
||||
*/
|
||||
private void reloadEconomy() {
|
||||
EconomyConfig economyConfig = getEconomyConfig();
|
||||
if (economyConfig.isEconomyEnabled() && economyConfig.getEconomy() == null) {
|
||||
setupVaultEconomy();
|
||||
} else if (!economyConfig.isEconomyEnabled()) {
|
||||
economyConfig.disableEconomy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces all open portals to close
|
||||
*/
|
||||
public void closeAllPortals() {
|
||||
for (Portal openPortal : openPortalsQueue) {
|
||||
openPortal.getPortalOpener().closePortal(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all config values
|
||||
*/
|
||||
public void loadConfig() {
|
||||
Stargate.stargate.reloadConfig();
|
||||
FileConfiguration newConfig = Stargate.stargate.getConfig();
|
||||
|
||||
boolean isMigrating = false;
|
||||
if (newConfig.getString("lang") != null ||
|
||||
newConfig.getString("gates.integrity.ignoreEntrance") != null ||
|
||||
newConfig.getString("ignoreEntrance") != null) {
|
||||
migrateConfig(newConfig);
|
||||
isMigrating = true;
|
||||
}
|
||||
|
||||
//Copy missing default values if any values are missing
|
||||
newConfig.options().copyDefaults(true);
|
||||
|
||||
//Get the language name from the config
|
||||
languageName = newConfig.getString("language");
|
||||
|
||||
//Get important folders from the config
|
||||
portalFolder = newConfig.getString("folders.portalFolder");
|
||||
gateFolder = newConfig.getString("folders.gateFolder");
|
||||
|
||||
//Get enabled debug settings from the config
|
||||
debuggingEnabled = newConfig.getBoolean("debugging.debug");
|
||||
permissionDebuggingEnabled = newConfig.getBoolean("debugging.permissionDebug");
|
||||
|
||||
//If users have an outdated config, assume they also need to update their default gates
|
||||
if (isMigrating) {
|
||||
GateHandler.writeDefaultGatesToFolder(gateFolder);
|
||||
}
|
||||
|
||||
//Load all gate config values
|
||||
stargateGateConfig = new StargateGateConfig(newConfig);
|
||||
|
||||
//Load all economy config values
|
||||
economyConfig = new EconomyConfig(newConfig);
|
||||
|
||||
Stargate.stargate.saveConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the object containing configuration values regarding gates
|
||||
*
|
||||
* @return <p>Gets the gate config</p>
|
||||
*/
|
||||
public StargateGateConfig getStargateGateConfig() {
|
||||
return stargateGateConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all available gates
|
||||
*/
|
||||
public void loadGates() {
|
||||
GateHandler.loadGates(gateFolder);
|
||||
logger.info(Stargate.getString("prefix") + "Loaded " + GateHandler.getGateCount() + " gate layouts");
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes all configuration values from the old name to the new name
|
||||
*
|
||||
* @param newConfig <p>The config to read from and write to</p>
|
||||
*/
|
||||
private void migrateConfig(FileConfiguration newConfig) {
|
||||
//Save the old config just in case something goes wrong
|
||||
try {
|
||||
newConfig.save(dataFolderPath + "/config.yml.old");
|
||||
} catch (IOException e) {
|
||||
Stargate.debug("Stargate::migrateConfig", "Unable to save old backup and do migration");
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
//Read all available config migrations
|
||||
Map<String, String> migrationFields;
|
||||
try {
|
||||
migrationFields = FileHelper.readKeyValuePairs(FileHelper.getBufferedReaderFromInputStream(
|
||||
FileHelper.getInputStreamForInternalFile("/config-migrations.txt")));
|
||||
} catch (IOException e) {
|
||||
Stargate.debug("Stargate::migrateConfig", "Unable to load config migration file");
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
//Replace old config names with the new ones
|
||||
for (String key : migrationFields.keySet()) {
|
||||
if (newConfig.contains(key)) {
|
||||
String newPath = migrationFields.get(key);
|
||||
Object oldValue = newConfig.get(key);
|
||||
if (!newPath.trim().isEmpty()) {
|
||||
newConfig.set(newPath, oldValue);
|
||||
}
|
||||
newConfig.set(key, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads economy from Vault
|
||||
*/
|
||||
private void setupVaultEconomy() {
|
||||
EconomyConfig economyConfig = getEconomyConfig();
|
||||
if (economyConfig.setupEconomy(Stargate.getPluginManager()) && economyConfig.getEconomy() != null) {
|
||||
String vaultVersion = economyConfig.getVault().getDescription().getVersion();
|
||||
logger.info(Stargate.getString("prefix") + Stargate.replaceVars(
|
||||
Stargate.getString("vaultLoaded"), "%version%", vaultVersion));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all portals in all un-managed worlds
|
||||
*/
|
||||
public void loadAllPortals() {
|
||||
for (World world : Stargate.stargate.getServer().getWorlds()) {
|
||||
if (!managedWorlds.contains(world.getName())) {
|
||||
PortalFileHelper.loadAllPortals(world);
|
||||
managedWorlds.add(world.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates missing folders
|
||||
*/
|
||||
private void createMissingFolders() {
|
||||
File newPortalDir = new File(portalFolder);
|
||||
if (!newPortalDir.exists()) {
|
||||
if (!newPortalDir.mkdirs()) {
|
||||
logger.severe("Unable to create portal directory");
|
||||
}
|
||||
}
|
||||
File newFile = new File(portalFolder, Stargate.stargate.getServer().getWorlds().get(0).getName() + ".db");
|
||||
if (!newFile.exists() && !newFile.getParentFile().exists()) {
|
||||
if (!newFile.getParentFile().mkdirs()) {
|
||||
logger.severe("Unable to create portal database folder: " + newFile.getParentFile().getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the folder all portals are stored in
|
||||
*
|
||||
* @return <p>The portal folder</p>
|
||||
*/
|
||||
public String getPortalFolder() {
|
||||
return portalFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the folder storing gate files
|
||||
*
|
||||
* <p>The returned String path is the full path to the folder</p>
|
||||
*
|
||||
* @return <p>The folder storing gate files</p>
|
||||
*/
|
||||
public String getGateFolder() {
|
||||
return gateFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sender for sending messages to players
|
||||
*
|
||||
* @return <p>The sender for sending messages to players</p>
|
||||
*/
|
||||
public MessageSender getMessageSender() {
|
||||
return messageSender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the language loader containing translated strings
|
||||
*
|
||||
* @return <p>The language loader</p>
|
||||
*/
|
||||
public LanguageLoader getLanguageLoader() {
|
||||
return languageLoader;
|
||||
}
|
||||
}
|
@ -55,7 +55,7 @@ public class EntityEventListener implements Listener {
|
||||
if (portal == null) {
|
||||
continue;
|
||||
}
|
||||
if (Stargate.destroyedByExplosion()) {
|
||||
if (Stargate.getGateConfig().destroyedByExplosion()) {
|
||||
PortalRegistry.unregisterPortal(portal, true);
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.knarcraft.stargate.listener;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.StargateConfig;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||
import org.bukkit.World;
|
||||
@ -22,9 +23,10 @@ public class WorldEventListener implements Listener {
|
||||
*/
|
||||
@EventHandler
|
||||
public void onWorldLoad(WorldLoadEvent event) {
|
||||
if (!Stargate.managedWorlds.contains(event.getWorld().getName()) &&
|
||||
StargateConfig config = Stargate.getStargateConfig();
|
||||
if (!config.getManagedWorlds().contains(event.getWorld().getName()) &&
|
||||
PortalFileHelper.loadAllPortals(event.getWorld())) {
|
||||
Stargate.managedWorlds.add(event.getWorld().getName());
|
||||
config.addManagedWorld(event.getWorld().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,8 +40,9 @@ public class WorldEventListener implements Listener {
|
||||
Stargate.debug("onWorldUnload", "Reloading all Stargates");
|
||||
World world = event.getWorld();
|
||||
String worldName = world.getName();
|
||||
if (Stargate.managedWorlds.contains(worldName)) {
|
||||
Stargate.managedWorlds.remove(worldName);
|
||||
StargateConfig config = Stargate.getStargateConfig();
|
||||
if (config.getManagedWorlds().contains(worldName)) {
|
||||
config.removeManagedWorld(worldName);
|
||||
PortalRegistry.clearPortals(world);
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* The portal registry keeps track of all registered portals and all their lookup blocks
|
||||
@ -263,7 +264,13 @@ public class PortalRegistry {
|
||||
|
||||
//Register the portal
|
||||
portalLookupByNetwork.get(networkName).put(portalName, portal);
|
||||
allPortalNetworks.get(networkName).add(portalName);
|
||||
|
||||
if (!allPortalNetworks.get(networkName).contains(portalName)) {
|
||||
allPortalNetworks.get(networkName).add(portalName);
|
||||
} else {
|
||||
Stargate.getConsoleLogger().log(Level.SEVERE, "Portal " + portal + " was registered twice. Check " +
|
||||
"your portal database for duplicates.");
|
||||
}
|
||||
}
|
||||
|
||||
//Register all frame blocks to the lookup list
|
||||
|
@ -50,7 +50,7 @@ public class PortalSignDrawer {
|
||||
for (int index = 0; index <= 3; index++) {
|
||||
sign.setLine(index, "");
|
||||
}
|
||||
Stargate.setLine(sign, 0, ChatColor.WHITE + "-" + Stargate.getGateConfig().getSignColor() +
|
||||
setLine(sign, 0, ChatColor.WHITE + "-" + Stargate.getGateConfig().getSignColor() +
|
||||
portal.getName() + ChatColor.WHITE + "-");
|
||||
|
||||
if (!portal.getPortalActivator().isActive()) {
|
||||
@ -116,14 +116,25 @@ public class PortalSignDrawer {
|
||||
if (freeGatesGreen) {
|
||||
Portal destination = PortalHandler.getByName(portal.getDestinationName(), portal.getNetwork());
|
||||
boolean green = PermissionHelper.isFree(portal.getActivePlayer(), portal, destination);
|
||||
Stargate.setLine(sign, signLineIndex, (green ? ChatColor.DARK_GREEN : "") + ">" +
|
||||
setLine(sign, signLineIndex, (green ? ChatColor.DARK_GREEN : "") + ">" +
|
||||
portal.getDestinationName() + (green ? ChatColor.DARK_GREEN : "") + "<");
|
||||
} else {
|
||||
Stargate.setLine(sign, signLineIndex, Stargate.getGateConfig().getSignColor() + " >" +
|
||||
setLine(sign, signLineIndex, Stargate.getGateConfig().getSignColor() + " >" +
|
||||
portal.getDestinationName() + Stargate.getGateConfig().getSignColor() + "< ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a line on a sign, adding the chosen sign color
|
||||
*
|
||||
* @param sign <p>The sign to update</p>
|
||||
* @param index <p>The index of the sign line to change</p>
|
||||
* @param text <p>The new text on the sign</p>
|
||||
*/
|
||||
public void setLine(Sign sign, int index, String text) {
|
||||
sign.setLine(index, Stargate.getGateConfig().getSignColor() + text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws one network destination on one sign line
|
||||
*
|
||||
@ -138,10 +149,10 @@ public class PortalSignDrawer {
|
||||
Portal destination = PortalHandler.getByName(destinations.getDestinations().get(destinationIndex),
|
||||
portal.getNetwork());
|
||||
boolean green = PermissionHelper.isFree(portal.getActivePlayer(), portal, destination);
|
||||
Stargate.setLine(sign, signLineIndex, (green ? ChatColor.DARK_GREEN : "") +
|
||||
setLine(sign, signLineIndex, (green ? ChatColor.DARK_GREEN : "") +
|
||||
destinations.getDestinations().get(destinationIndex));
|
||||
} else {
|
||||
Stargate.setLine(sign, signLineIndex, destinations.getDestinations().get(destinationIndex));
|
||||
setLine(sign, signLineIndex, destinations.getDestinations().get(destinationIndex));
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,9 +162,9 @@ public class PortalSignDrawer {
|
||||
* @param sign <p>The sign to re-draw</p>
|
||||
*/
|
||||
private void drawBungeeSign(Sign sign) {
|
||||
Stargate.setLine(sign, 1, Stargate.getString("bungeeSign"));
|
||||
Stargate.setLine(sign, 2, ">" + portal.getDestinationName() + "<");
|
||||
Stargate.setLine(sign, 3, "[" + portal.getNetwork() + "]");
|
||||
setLine(sign, 1, Stargate.getString("bungeeSign"));
|
||||
setLine(sign, 2, ">" + portal.getDestinationName() + "<");
|
||||
setLine(sign, 3, "[" + portal.getNetwork() + "]");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -162,12 +173,12 @@ public class PortalSignDrawer {
|
||||
* @param sign <p>The sign to re-draw</p>
|
||||
*/
|
||||
private void drawInactiveSign(Sign sign) {
|
||||
Stargate.setLine(sign, 1, Stargate.getString("signRightClick"));
|
||||
Stargate.setLine(sign, 2, Stargate.getString("signToUse"));
|
||||
setLine(sign, 1, Stargate.getString("signRightClick"));
|
||||
setLine(sign, 2, Stargate.getString("signToUse"));
|
||||
if (!portal.getOptions().isNoNetwork()) {
|
||||
Stargate.setLine(sign, 3, "(" + portal.getNetwork() + ")");
|
||||
setLine(sign, 3, "(" + portal.getNetwork() + ")");
|
||||
} else {
|
||||
Stargate.setLine(sign, 3, "");
|
||||
setLine(sign, 3, "");
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,20 +189,20 @@ public class PortalSignDrawer {
|
||||
*/
|
||||
private void drawFixedSign(Sign sign) {
|
||||
if (portal.getOptions().isRandom()) {
|
||||
Stargate.setLine(sign, 1, "> " + Stargate.getString("signRandom") + " <");
|
||||
setLine(sign, 1, "> " + Stargate.getString("signRandom") + " <");
|
||||
} else {
|
||||
Stargate.setLine(sign, 1, ">" + portal.getDestinationName() + "<");
|
||||
setLine(sign, 1, ">" + portal.getDestinationName() + "<");
|
||||
}
|
||||
if (portal.getOptions().isNoNetwork()) {
|
||||
Stargate.setLine(sign, 2, "");
|
||||
setLine(sign, 2, "");
|
||||
} else {
|
||||
Stargate.setLine(sign, 2, "(" + portal.getNetwork() + ")");
|
||||
setLine(sign, 2, "(" + portal.getNetwork() + ")");
|
||||
}
|
||||
Portal destination = PortalHandler.getByName(portal.getDestinationName(), portal.getNetwork());
|
||||
if (destination == null && !portal.getOptions().isRandom()) {
|
||||
Stargate.setLine(sign, 3, Stargate.getString("signDisconnected"));
|
||||
setLine(sign, 3, Stargate.getString("signDisconnected"));
|
||||
} else {
|
||||
Stargate.setLine(sign, 3, "");
|
||||
setLine(sign, 3, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@ public final class PermissionHelper {
|
||||
* @return <p>True if the player has the permission</p>
|
||||
*/
|
||||
public static boolean hasPermission(Player player, String perm) {
|
||||
if (Stargate.permissionDebuggingEnabled) {
|
||||
if (Stargate.getStargateConfig().isPermissionDebuggingEnabled()) {
|
||||
Stargate.debug("hasPerm::SuperPerm(" + player.getName() + ")", perm + " => " + player.hasPermission(perm));
|
||||
}
|
||||
return player.hasPermission(perm);
|
||||
@ -144,12 +144,12 @@ public final class PermissionHelper {
|
||||
*/
|
||||
public static boolean hasPermDeep(Player player, String permission) {
|
||||
if (!player.isPermissionSet(permission)) {
|
||||
if (Stargate.permissionDebuggingEnabled) {
|
||||
if (Stargate.getStargateConfig().isPermissionDebuggingEnabled()) {
|
||||
Stargate.debug("hasPermDeep::SuperPerm", permission + " => true");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (Stargate.permissionDebuggingEnabled) {
|
||||
if (Stargate.getStargateConfig().isPermissionDebuggingEnabled()) {
|
||||
Stargate.debug("hasPermDeep::SuperPerms", permission + " => " + player.hasPermission(permission));
|
||||
}
|
||||
return player.hasPermission(permission);
|
||||
|
@ -10,6 +10,7 @@ import net.knarcraft.stargate.portal.PortalLocation;
|
||||
import net.knarcraft.stargate.portal.PortalOptions;
|
||||
import net.knarcraft.stargate.portal.PortalOwner;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
@ -35,8 +36,8 @@ public final class PortalFileHelper {
|
||||
* @param world <p>The world to save portals for</p>
|
||||
*/
|
||||
public static void saveAllPortals(World world) {
|
||||
Stargate.managedWorlds.add(world.getName());
|
||||
String saveFileLocation = Stargate.getSaveLocation() + "/" + world.getName() + ".db";
|
||||
Stargate.getStargateConfig().addManagedWorld(world.getName());
|
||||
String saveFileLocation = Stargate.getPortalFolder() + "/" + world.getName() + ".db";
|
||||
|
||||
try {
|
||||
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(saveFileLocation, false));
|
||||
@ -125,7 +126,7 @@ public final class PortalFileHelper {
|
||||
* @return <p>True if portals could be loaded</p>
|
||||
*/
|
||||
public static boolean loadAllPortals(World world) {
|
||||
String location = Stargate.getSaveLocation();
|
||||
String location = Stargate.getPortalFolder();
|
||||
|
||||
File database = new File(location, world.getName() + ".db");
|
||||
|
||||
@ -268,7 +269,7 @@ public final class PortalFileHelper {
|
||||
*/
|
||||
private static void markPortalWithInvalidGate(PortalLocation portalLocation, String gateName, int lineIndex) {
|
||||
Sign sign = (Sign) portalLocation.getSignLocation().getBlock().getState();
|
||||
Stargate.setLine(sign, 3, Stargate.getString("signInvalidGate"));
|
||||
sign.setLine(3, ChatColor.DARK_RED + Stargate.getString("signInvalidGate"));
|
||||
sign.update();
|
||||
|
||||
Stargate.getConsoleLogger().info(Stargate.getString("prefix") + "Gate layout on line " + lineIndex +
|
||||
|
Loading…
x
Reference in New Issue
Block a user