mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-11-04 03:03:43 +01:00 
			
		
		
		
	@@ -11,7 +11,7 @@ import java.util.Set;
 | 
			
		||||
 * A type of {@link ConfigurationSection} that is stored in memory.
 | 
			
		||||
 */
 | 
			
		||||
public class MemorySection implements ConfigurationSection {
 | 
			
		||||
    protected final Map<String, Object> map = new LinkedHashMap<String, Object>();
 | 
			
		||||
    protected final Map<String, Object> map = new LinkedHashMap<>();
 | 
			
		||||
    private final Configuration root;
 | 
			
		||||
    private final ConfigurationSection parent;
 | 
			
		||||
    private final String path;
 | 
			
		||||
@@ -24,7 +24,8 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
        if (obj instanceof String) {
 | 
			
		||||
            try {
 | 
			
		||||
                return Double.parseDouble((String) obj);
 | 
			
		||||
            } catch (final Exception e) {}
 | 
			
		||||
            } catch (NumberFormatException ignored) {
 | 
			
		||||
            }
 | 
			
		||||
        } else if (obj instanceof List) {
 | 
			
		||||
            final List<?> val = ((List<?>) obj);
 | 
			
		||||
            if (val.size() > 0) {
 | 
			
		||||
@@ -41,7 +42,8 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
        if (obj instanceof String) {
 | 
			
		||||
            try {
 | 
			
		||||
                return Integer.parseInt((String) obj);
 | 
			
		||||
            } catch (final Exception e) {}
 | 
			
		||||
            } catch (NumberFormatException ignored) {
 | 
			
		||||
            }
 | 
			
		||||
        } else if (obj instanceof List) {
 | 
			
		||||
            final List<?> val = ((List<?>) obj);
 | 
			
		||||
            if (val.size() > 0) {
 | 
			
		||||
@@ -58,7 +60,8 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
        if (obj instanceof String) {
 | 
			
		||||
            try {
 | 
			
		||||
                return Long.parseLong((String) obj);
 | 
			
		||||
            } catch (final Exception e) {}
 | 
			
		||||
            } catch (NumberFormatException ignored) {
 | 
			
		||||
            }
 | 
			
		||||
        } else if (obj instanceof List) {
 | 
			
		||||
            final List<?> val = ((List<?>) obj);
 | 
			
		||||
            if (val.size() > 0) {
 | 
			
		||||
@@ -119,7 +122,7 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
    
 | 
			
		||||
    @Override
 | 
			
		||||
    public Set<String> getKeys(final boolean deep) {
 | 
			
		||||
        final Set<String> result = new LinkedHashSet<String>();
 | 
			
		||||
        final Set<String> result = new LinkedHashSet<>();
 | 
			
		||||
        
 | 
			
		||||
        final Configuration root = getRoot();
 | 
			
		||||
        if ((root != null) && root.options().copyDefaults()) {
 | 
			
		||||
@@ -137,7 +140,7 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
    
 | 
			
		||||
    @Override
 | 
			
		||||
    public Map<String, Object> getValues(final boolean deep) {
 | 
			
		||||
        final Map<String, Object> result = new LinkedHashMap<String, Object>();
 | 
			
		||||
        final Map<String, Object> result = new LinkedHashMap<>();
 | 
			
		||||
        
 | 
			
		||||
        final Configuration root = getRoot();
 | 
			
		||||
        if ((root != null) && root.options().copyDefaults()) {
 | 
			
		||||
@@ -462,10 +465,10 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
        final List<?> list = getList(path);
 | 
			
		||||
        
 | 
			
		||||
        if (list == null) {
 | 
			
		||||
            return new ArrayList<String>(0);
 | 
			
		||||
            return new ArrayList<>(0);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        final List<String> result = new ArrayList<String>();
 | 
			
		||||
        final List<String> result = new ArrayList<>();
 | 
			
		||||
        
 | 
			
		||||
        for (final Object object : list) {
 | 
			
		||||
            if ((object instanceof String) || (isPrimitiveWrapper(object))) {
 | 
			
		||||
@@ -481,10 +484,10 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
        final List<?> list = getList(path);
 | 
			
		||||
        
 | 
			
		||||
        if (list == null) {
 | 
			
		||||
            return new ArrayList<Integer>(0);
 | 
			
		||||
            return new ArrayList<>(0);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        final List<Integer> result = new ArrayList<Integer>();
 | 
			
		||||
        final List<Integer> result = new ArrayList<>();
 | 
			
		||||
        
 | 
			
		||||
        for (final Object object : list) {
 | 
			
		||||
            if (object instanceof Integer) {
 | 
			
		||||
@@ -492,9 +495,10 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
            } else if (object instanceof String) {
 | 
			
		||||
                try {
 | 
			
		||||
                    result.add(Integer.valueOf((String) object));
 | 
			
		||||
                } catch (final Exception ex) {}
 | 
			
		||||
                } catch (NumberFormatException ignored) {
 | 
			
		||||
                }
 | 
			
		||||
            } else if (object instanceof Character) {
 | 
			
		||||
                result.add((int) ((Character) object).charValue());
 | 
			
		||||
                result.add((int) (Character) object);
 | 
			
		||||
            } else if (object instanceof Number) {
 | 
			
		||||
                result.add(((Number) object).intValue());
 | 
			
		||||
            }
 | 
			
		||||
@@ -508,10 +512,10 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
        final List<?> list = getList(path);
 | 
			
		||||
        
 | 
			
		||||
        if (list == null) {
 | 
			
		||||
            return new ArrayList<Boolean>(0);
 | 
			
		||||
            return new ArrayList<>(0);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        final List<Boolean> result = new ArrayList<Boolean>();
 | 
			
		||||
        final List<Boolean> result = new ArrayList<>();
 | 
			
		||||
        
 | 
			
		||||
        for (final Object object : list) {
 | 
			
		||||
            if (object instanceof Boolean) {
 | 
			
		||||
@@ -533,10 +537,10 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
        final List<?> list = getList(path);
 | 
			
		||||
        
 | 
			
		||||
        if (list == null) {
 | 
			
		||||
            return new ArrayList<Double>(0);
 | 
			
		||||
            return new ArrayList<>(0);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        final List<Double> result = new ArrayList<Double>();
 | 
			
		||||
        final List<Double> result = new ArrayList<>();
 | 
			
		||||
        
 | 
			
		||||
        for (final Object object : list) {
 | 
			
		||||
            if (object instanceof Double) {
 | 
			
		||||
@@ -544,9 +548,10 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
            } else if (object instanceof String) {
 | 
			
		||||
                try {
 | 
			
		||||
                    result.add(Double.valueOf((String) object));
 | 
			
		||||
                } catch (final Exception ex) {}
 | 
			
		||||
                } catch (NumberFormatException ignored) {
 | 
			
		||||
                }
 | 
			
		||||
            } else if (object instanceof Character) {
 | 
			
		||||
                result.add((double) ((Character) object).charValue());
 | 
			
		||||
                result.add((double) (Character) object);
 | 
			
		||||
            } else if (object instanceof Number) {
 | 
			
		||||
                result.add(((Number) object).doubleValue());
 | 
			
		||||
            }
 | 
			
		||||
@@ -560,10 +565,10 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
        final List<?> list = getList(path);
 | 
			
		||||
        
 | 
			
		||||
        if (list == null) {
 | 
			
		||||
            return new ArrayList<Float>(0);
 | 
			
		||||
            return new ArrayList<>(0);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        final List<Float> result = new ArrayList<Float>();
 | 
			
		||||
        final List<Float> result = new ArrayList<>();
 | 
			
		||||
        
 | 
			
		||||
        for (final Object object : list) {
 | 
			
		||||
            if (object instanceof Float) {
 | 
			
		||||
@@ -571,9 +576,10 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
            } else if (object instanceof String) {
 | 
			
		||||
                try {
 | 
			
		||||
                    result.add(Float.valueOf((String) object));
 | 
			
		||||
                } catch (final Exception ex) {}
 | 
			
		||||
                } catch (NumberFormatException ignored) {
 | 
			
		||||
                }
 | 
			
		||||
            } else if (object instanceof Character) {
 | 
			
		||||
                result.add((float) ((Character) object).charValue());
 | 
			
		||||
                result.add((float) (Character) object);
 | 
			
		||||
            } else if (object instanceof Number) {
 | 
			
		||||
                result.add(((Number) object).floatValue());
 | 
			
		||||
            }
 | 
			
		||||
@@ -587,10 +593,10 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
        final List<?> list = getList(path);
 | 
			
		||||
        
 | 
			
		||||
        if (list == null) {
 | 
			
		||||
            return new ArrayList<Long>(0);
 | 
			
		||||
            return new ArrayList<>(0);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        final List<Long> result = new ArrayList<Long>();
 | 
			
		||||
        final List<Long> result = new ArrayList<>();
 | 
			
		||||
        
 | 
			
		||||
        for (final Object object : list) {
 | 
			
		||||
            if (object instanceof Long) {
 | 
			
		||||
@@ -598,9 +604,10 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
            } else if (object instanceof String) {
 | 
			
		||||
                try {
 | 
			
		||||
                    result.add(Long.valueOf((String) object));
 | 
			
		||||
                } catch (final Exception ex) {}
 | 
			
		||||
                } catch (NumberFormatException ignored) {
 | 
			
		||||
                }
 | 
			
		||||
            } else if (object instanceof Character) {
 | 
			
		||||
                result.add((long) ((Character) object).charValue());
 | 
			
		||||
                result.add((long) (Character) object);
 | 
			
		||||
            } else if (object instanceof Number) {
 | 
			
		||||
                result.add(((Number) object).longValue());
 | 
			
		||||
            }
 | 
			
		||||
@@ -614,10 +621,10 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
        final List<?> list = getList(path);
 | 
			
		||||
        
 | 
			
		||||
        if (list == null) {
 | 
			
		||||
            return new ArrayList<Byte>(0);
 | 
			
		||||
            return new ArrayList<>(0);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        final List<Byte> result = new ArrayList<Byte>();
 | 
			
		||||
        final List<Byte> result = new ArrayList<>();
 | 
			
		||||
        
 | 
			
		||||
        for (final Object object : list) {
 | 
			
		||||
            if (object instanceof Byte) {
 | 
			
		||||
@@ -625,7 +632,8 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
            } else if (object instanceof String) {
 | 
			
		||||
                try {
 | 
			
		||||
                    result.add(Byte.valueOf((String) object));
 | 
			
		||||
                } catch (final Exception ex) {}
 | 
			
		||||
                } catch (NumberFormatException ignored) {
 | 
			
		||||
                }
 | 
			
		||||
            } else if (object instanceof Character) {
 | 
			
		||||
                result.add((byte) ((Character) object).charValue());
 | 
			
		||||
            } else if (object instanceof Number) {
 | 
			
		||||
@@ -641,10 +649,10 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
        final List<?> list = getList(path);
 | 
			
		||||
        
 | 
			
		||||
        if (list == null) {
 | 
			
		||||
            return new ArrayList<Character>(0);
 | 
			
		||||
            return new ArrayList<>(0);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        final List<Character> result = new ArrayList<Character>();
 | 
			
		||||
        final List<Character> result = new ArrayList<>();
 | 
			
		||||
        
 | 
			
		||||
        for (final Object object : list) {
 | 
			
		||||
            if (object instanceof Character) {
 | 
			
		||||
@@ -668,10 +676,10 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
        final List<?> list = getList(path);
 | 
			
		||||
        
 | 
			
		||||
        if (list == null) {
 | 
			
		||||
            return new ArrayList<Short>(0);
 | 
			
		||||
            return new ArrayList<>(0);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        final List<Short> result = new ArrayList<Short>();
 | 
			
		||||
        final List<Short> result = new ArrayList<>();
 | 
			
		||||
        
 | 
			
		||||
        for (final Object object : list) {
 | 
			
		||||
            if (object instanceof Short) {
 | 
			
		||||
@@ -679,7 +687,8 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
            } else if (object instanceof String) {
 | 
			
		||||
                try {
 | 
			
		||||
                    result.add(Short.valueOf((String) object));
 | 
			
		||||
                } catch (final Exception ex) {}
 | 
			
		||||
                } catch (NumberFormatException ignored) {
 | 
			
		||||
                }
 | 
			
		||||
            } else if (object instanceof Character) {
 | 
			
		||||
                result.add((short) ((Character) object).charValue());
 | 
			
		||||
            } else if (object instanceof Number) {
 | 
			
		||||
@@ -693,7 +702,7 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<Map<?, ?>> getMapList(final String path) {
 | 
			
		||||
        final List<?> list = getList(path);
 | 
			
		||||
        final List<Map<?, ?>> result = new ArrayList<Map<?, ?>>();
 | 
			
		||||
        final List<Map<?, ?>> result = new ArrayList<>();
 | 
			
		||||
        
 | 
			
		||||
        if (list == null) {
 | 
			
		||||
            return result;
 | 
			
		||||
@@ -827,16 +836,14 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
        final char separator = root.options().pathSeparator();
 | 
			
		||||
        
 | 
			
		||||
        final StringBuilder builder = new StringBuilder();
 | 
			
		||||
        if (section != null) {
 | 
			
		||||
            for (ConfigurationSection parent = section; (parent != null) && (parent != relativeTo); parent = parent.getParent()) {
 | 
			
		||||
                if (builder.length() > 0) {
 | 
			
		||||
                    builder.insert(0, separator);
 | 
			
		||||
                }
 | 
			
		||||
                
 | 
			
		||||
                builder.insert(0, parent.getName());
 | 
			
		||||
        for (ConfigurationSection parent = section; (parent != null) && (parent != relativeTo); parent = parent.getParent()) {
 | 
			
		||||
            if (builder.length() > 0) {
 | 
			
		||||
                builder.insert(0, separator);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            builder.insert(0, parent.getName());
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        if ((key != null) && (key.length() > 0)) {
 | 
			
		||||
            if (builder.length() > 0) {
 | 
			
		||||
                builder.append(separator);
 | 
			
		||||
@@ -851,7 +858,7 @@ public class MemorySection implements ConfigurationSection {
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        final Configuration root = getRoot();
 | 
			
		||||
        return new StringBuilder().append(getClass().getSimpleName()).append("[path='").append(getCurrentPath()).append("', root='").append(root == null ? null : root.getClass().getSimpleName())
 | 
			
		||||
        .append("']").toString();
 | 
			
		||||
        return getClass().getSimpleName() + "[path='" + getCurrentPath() + "', root='" + (root == null ? null : root.getClass().getSimpleName()) +
 | 
			
		||||
                "']";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,10 @@
 | 
			
		||||
package com.intellectualcrafters.configuration.file;
 | 
			
		||||
 | 
			
		||||
import com.intellectualcrafters.configuration.Configuration;
 | 
			
		||||
import com.intellectualcrafters.configuration.InvalidConfigurationException;
 | 
			
		||||
import com.intellectualcrafters.configuration.MemoryConfiguration;
 | 
			
		||||
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
 | 
			
		||||
 | 
			
		||||
import java.io.BufferedReader;
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.io.FileInputStream;
 | 
			
		||||
@@ -14,12 +19,6 @@ import java.io.Writer;
 | 
			
		||||
import java.nio.charset.Charset;
 | 
			
		||||
import java.nio.charset.StandardCharsets;
 | 
			
		||||
 | 
			
		||||
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
 | 
			
		||||
 | 
			
		||||
import com.intellectualcrafters.configuration.Configuration;
 | 
			
		||||
import com.intellectualcrafters.configuration.InvalidConfigurationException;
 | 
			
		||||
import com.intellectualcrafters.configuration.MemoryConfiguration;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This is a base class for all File based implementations of {@link
 | 
			
		||||
 * Configuration}
 | 
			
		||||
@@ -99,13 +98,10 @@ public abstract class FileConfiguration extends MemoryConfiguration {
 | 
			
		||||
        file.getParentFile().mkdirs();
 | 
			
		||||
        
 | 
			
		||||
        final String data = saveToString();
 | 
			
		||||
        
 | 
			
		||||
        final Writer writer = new OutputStreamWriter(new FileOutputStream(file), UTF8_OVERRIDE && !UTF_BIG ? StandardCharsets.UTF_8 : Charset.defaultCharset());
 | 
			
		||||
        
 | 
			
		||||
        try {
 | 
			
		||||
 | 
			
		||||
        try (Writer writer = new OutputStreamWriter(new FileOutputStream(file),
 | 
			
		||||
                UTF8_OVERRIDE && !UTF_BIG ? StandardCharsets.UTF_8 : Charset.defaultCharset())) {
 | 
			
		||||
            writer.write(data);
 | 
			
		||||
        } finally {
 | 
			
		||||
            writer.close();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
@@ -212,19 +208,16 @@ public abstract class FileConfiguration extends MemoryConfiguration {
 | 
			
		||||
     * @throws IllegalArgumentException thrown when reader is null
 | 
			
		||||
     */
 | 
			
		||||
    public void load(final Reader reader) throws IOException, InvalidConfigurationException {
 | 
			
		||||
        final BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader);
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        final StringBuilder builder = new StringBuilder();
 | 
			
		||||
        
 | 
			
		||||
        try {
 | 
			
		||||
 | 
			
		||||
        try (BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader)) {
 | 
			
		||||
            String line;
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
            while ((line = input.readLine()) != null) {
 | 
			
		||||
                builder.append(line);
 | 
			
		||||
                builder.append('\n');
 | 
			
		||||
            }
 | 
			
		||||
        } finally {
 | 
			
		||||
            input.close();
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        loadFromString(builder.toString());
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user