public HousingManager(PluginTrace trace, Configuration config) { Contract.Requires<ArgumentNullException>(trace != null); Contract.Requires<ArgumentNullException>(config != null); this.Trace = trace; this.config = config; }
public bool CheckHouseRegionValidSize(Rectangle regionArea, out Configuration.HouseSizeConfig problematicConfig) { int areaTotalTiles = regionArea.Width * regionArea.Height; problematicConfig = this.Config.MinSize; if ( regionArea.Width < this.Config.MinSize.Width || regionArea.Height < this.Config.MinSize.Height || areaTotalTiles < this.Config.MinSize.TotalTiles ) return false; problematicConfig = this.Config.MaxSize; if ( regionArea.Width > this.Config.MaxSize.Width || regionArea.Height > this.Config.MaxSize.Height || areaTotalTiles > this.Config.MaxSize.TotalTiles ) return false; problematicConfig = default(Configuration.HouseSizeConfig); return true; }
public static Configuration Read(string filePath) { XmlReaderSettings configReaderSettings = new XmlReaderSettings { ValidationType = ValidationType.Schema, ValidationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints | XmlSchemaValidationFlags.ReportValidationWarnings }; string configSchemaPath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + ".xsd"); configReaderSettings.Schemas.Add(null, configSchemaPath); XmlDocument document = new XmlDocument(); using (XmlReader configReader = XmlReader.Create(filePath, configReaderSettings)) document.Load(configReader); // Before validating using the schema, first check if the configuration file's version matches with the supported version. XmlElement rootElement = document.DocumentElement; string fileVersionRaw; if (rootElement.HasAttribute("Version")) fileVersionRaw = rootElement.GetAttribute("Version"); else fileVersionRaw = "1.0"; if (fileVersionRaw != Configuration.CurrentVersion) { throw new FormatException(string.Format( "The configuration file is either outdated or too new. Expected version was: {0}. File version is: {1}", Configuration.CurrentVersion, fileVersionRaw )); } Configuration resultingConfig = new Configuration(); resultingConfig.MaxHousesPerUser = int.Parse(rootElement["MaxHousesPerUser"].InnerText); resultingConfig.MinSize = HouseSizeConfig.FromXmlElement(rootElement["MinHouseSize"]); resultingConfig.MaxSize = HouseSizeConfig.FromXmlElement(rootElement["MaxHouseSize"]); resultingConfig.AllowTShockRegionOverlapping = BoolEx.ParseEx(rootElement["AllowTShockRegionOverlapping"].InnerText); resultingConfig.DefaultZIndex = int.Parse(rootElement["DefaultZIndex"].InnerText); return resultingConfig; }
public UserInteractionHandler( PluginTrace trace, PluginInfo pluginInfo, Configuration config, HousingManager housingManager, Func<Configuration> reloadConfigurationCallback ) : base(trace) { Contract.Requires<ArgumentNullException>(trace != null); Contract.Requires<ArgumentException>(!pluginInfo.Equals(PluginInfo.Empty)); Contract.Requires<ArgumentNullException>(config != null); Contract.Requires<ArgumentNullException>(housingManager != null); Contract.Requires<ArgumentNullException>(reloadConfigurationCallback != null); this.PluginInfo = pluginInfo; this.Config = config; this.HousingManager = housingManager; this.ReloadConfigurationCallback = reloadConfigurationCallback; #region Command Setup base.RegisterCommand( new[] { "house", "housing" }, this.RootCommand_Exec, this.RootCommand_HelpCallback ); #endregion }
private void ExplainInvalidRegionSize(TSPlayer toPlayer, Rectangle area, Configuration.HouseSizeConfig restrictingConfig) { if (restrictingConfig.Equals(this.Config.MinSize)) { toPlayer.SendErrorMessage("This region has no valid house size, it's too small:"); toPlayer.SendErrorMessage("Min width: {0} (you've tried to set {1}).", restrictingConfig.Width, area.Width); toPlayer.SendErrorMessage("Min height: {0} (you've tried to set {1}).", restrictingConfig.Height, area.Height); toPlayer.SendErrorMessage("Min total blocks: {0} (you've tried to set {1}).", restrictingConfig.TotalTiles, area.Width * area.Height); } else { toPlayer.SendErrorMessage("This region has no valid house size, it's too large:"); toPlayer.SendErrorMessage("Max width: {0} (you've tried to set {1}).", restrictingConfig.Width, area.Width); toPlayer.SendErrorMessage("Max height: {0} (you've tried to set {1}).", restrictingConfig.Height, area.Height); toPlayer.SendErrorMessage("Max total blocks: {0} (you've tried to set {1}).", restrictingConfig.TotalTiles, area.Width * area.Height); } }
public InvalidHouseSizeException(Configuration.HouseSizeConfig restrictingConfig) : base("The size of the house does not match with the configured min / max settings.") { this.restrictingConfig = restrictingConfig; }