001/* 002 * PlotSquared, a land and world management plugin for Minecraft. 003 * Copyright (C) IntellectualSites <https://intellectualsites.com> 004 * Copyright (C) IntellectualSites team and contributors 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 018 */ 019package com.plotsquared.core.configuration.file; 020 021import com.plotsquared.core.configuration.Configuration; 022import com.plotsquared.core.configuration.MemoryConfiguration; 023import com.plotsquared.core.configuration.MemoryConfigurationOptions; 024 025/** 026 * Various settings for controlling the input and output of a {@link 027 * FileConfiguration}. 028 */ 029public class FileConfigurationOptions extends MemoryConfigurationOptions { 030 031 private String header = null; 032 private boolean copyHeader = true; 033 034 protected FileConfigurationOptions(MemoryConfiguration configuration) { 035 super(configuration); 036 } 037 038 @Override 039 public FileConfiguration configuration() { 040 return (FileConfiguration) super.configuration(); 041 } 042 043 @Override 044 public FileConfigurationOptions copyDefaults(boolean value) { 045 super.copyDefaults(value); 046 return this; 047 } 048 049 /** 050 * Gets the header that will be applied to the top of the saved output. 051 * 052 * <p>This header will be commented out and applied directly at the top of 053 * the generated output of the {@link FileConfiguration}. It is not 054 * required to include a newline at the end of the header as it will 055 * automatically be applied, but you may include one if you wish for extra 056 * spacing. 057 * 058 * <p>{@code null} is a valid value which will indicate that no header] 059 * is to be applied. The default value is {@code null}. 060 * 061 * @return Header 062 */ 063 public String header() { 064 return header; 065 } 066 067 /** 068 * Sets the header that will be applied to the top of the saved output. 069 * 070 * <p>This header will be commented out and applied directly at the top of 071 * the generated output of the {@link FileConfiguration}. It is not 072 * required to include a newline at the end of the header as it will 073 * automatically be applied, but you may include one if you wish for extra 074 * spacing. 075 * 076 * <p>{@code null} is a valid value which will indicate that no header 077 * is to be applied. 078 * 079 * @param value New header 080 * @return This object, for chaining 081 */ 082 public FileConfigurationOptions header(String value) { 083 header = value; 084 return this; 085 } 086 087 /** 088 * Gets whether or not the header should be copied from a default source. 089 * 090 * <p>If this is true, if a default {@link FileConfiguration} is passed to 091 * {@link FileConfiguration#setDefaults(Configuration)} 092 * then upon saving it will use the header from that config, instead of 093 * the one provided here. 094 * 095 * <p>If no default is set on the configuration, or the default is not of 096 * type FileConfiguration, or that config has no header ({@link #header()} 097 * returns null) then the header specified in this configuration will be 098 * used. 099 * 100 * <p>Defaults to true. 101 * 102 * @return Whether or not to copy the header 103 */ 104 public boolean copyHeader() { 105 return copyHeader; 106 } 107 108 /** 109 * Sets whether or not the header should be copied from a default source. 110 * 111 * <p>If this is true, if a default {@link FileConfiguration} is passed to 112 * {@link FileConfiguration#setDefaults(Configuration)} 113 * then upon saving it will use the header from that config, instead of 114 * the one provided here. 115 * 116 * <p>If no default is set on the configuration, or the default is not of 117 * type FileConfiguration, or that config has no header ({@link #header()} 118 * returns null) then the header specified in this configuration will be 119 * used. 120 * 121 * <p>Defaults to true. 122 * 123 * @param value Whether or not to copy the header 124 * @return This object, for chaining 125 */ 126 public FileConfigurationOptions copyHeader(boolean value) { 127 copyHeader = value; 128 129 return this; 130 } 131 132}