Skip to content
This repository has been archived by the owner on Mar 5, 2021. It is now read-only.

Commit

Permalink
2.0.5 Bukkit & Bungee Config.
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraLS3 committed Aug 27, 2017
1 parent a9341bf commit 2768931
Show file tree
Hide file tree
Showing 13 changed files with 470 additions and 36 deletions.
2 changes: 1 addition & 1 deletion AbstractPluginFramework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.djrapitops</groupId>
<artifactId>AbstractPluginFramework</artifactId>
<version>2.0.4</version>
<version>2.0.5</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.command.bukkit.BukkitCommand;
import com.djrapitops.plugin.config.BukkitConfig;
import com.djrapitops.plugin.config.IConfig;
import com.djrapitops.plugin.pluginchannel.MessageSubChannel;
import com.djrapitops.plugin.settings.ColorScheme;
import com.djrapitops.plugin.settings.Version;
Expand Down Expand Up @@ -232,4 +234,9 @@ public void registerPluginMessageSubChannel(MessageSubChannel channel) {
public NotificationCenter getNotificationCenter() {
return notificationCenter;
}

public IConfig getIConfig() throws IOException {
BukkitConfig bukkitConfig = new BukkitConfig(getDataFolder(), "config.yml");
return bukkitConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.command.bungee.BungeeCommand;
import com.djrapitops.plugin.config.BungeeConfig;
import com.djrapitops.plugin.config.IConfig;
import com.djrapitops.plugin.settings.ColorScheme;
import com.djrapitops.plugin.settings.Version;
import com.djrapitops.plugin.task.RunnableFactory;
Expand Down Expand Up @@ -219,8 +221,9 @@ public void copyDefaultConfig(String header) {
}
}

public Configuration getConfig() throws IOException {
return ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
public IConfig getIConfig() throws IOException {
BungeeConfig bungeeConfig = new BungeeConfig(getDataFolder(), "config.yml");
return bungeeConfig;
}

public void saveConfig(Configuration config) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.djrapitops.plugin;

import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.config.IConfig;
import com.djrapitops.plugin.settings.ColorScheme;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.BenchUtil;
Expand All @@ -9,6 +10,9 @@
import com.djrapitops.plugin.utilities.player.Fetch;
import com.djrapitops.plugin.utilities.status.TaskStatus;

import java.io.File;
import java.io.IOException;

/**
* Interface all APF Plugin classes implement.
* @author Rsl1122
Expand Down Expand Up @@ -58,4 +62,8 @@ public interface IPlugin {
void copyDefaultConfig(String header);

NotificationCenter getNotificationCenter();

File getDataFolder();

IConfig getIConfig() throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public class StaticHolder {

private static final String apfVersion = "2.0.4";
private static final String apfVersion = "2.0.5";
private static final Map<Class, BukkitPlugin> INSTANCES_BUKKIT = new HashMap<>();
private static final Map<Class, BungeePlugin> INSTANCES_BUNGEE = new HashMap<>();
private static Class utilityProvider = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.djrapitops.plugin.config;

import com.djrapitops.plugin.BukkitPlugin;

import java.io.File;
import java.io.IOException;

import com.djrapitops.plugin.IPlugin;
import com.djrapitops.plugin.config.fileconfig.BukkitFileConfig;
import com.djrapitops.plugin.config.fileconfig.IFileConfig;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
Expand All @@ -11,51 +16,25 @@
* Config file class for creating Bukkit config file classes more easily.
*
* @author Rsl1122
* @param <T> BukkitPlugin implementation this config class is for.
* @since 2.0.0
*/
public class BukkitConfig<T extends BukkitPlugin> {

private File folder;
private String filename;
private FileConfiguration fileConfig;
public class BukkitConfig extends IConfig {

public BukkitConfig(T plugin, String filename) throws IOException, InvalidConfigurationException {
public BukkitConfig(IPlugin plugin, String filename) throws IOException {
this(plugin.getDataFolder(), filename);
}

public BukkitConfig(File folder, String filename) throws IOException, InvalidConfigurationException {
this.folder = folder;
this.filename = filename;
public BukkitConfig(File folder, String filename) throws IOException {
super(folder, filename);
load();
}

public final File createFile() throws IOException {
File file = new File(folder, filename + ".yml");
if (!file.exists()) {
file.createNewFile();
}
return file;
}

public final void load() throws IOException, InvalidConfigurationException {
load(createFile());
}

public final void load(File file) throws IOException, InvalidConfigurationException {
fileConfig = new YamlConfiguration();
public final void load(File file) throws IOException {
fileConfig = new BukkitFileConfig(new YamlConfiguration());
fileConfig.load(file);
}

public final void save() throws IOException {
save(createFile());
}

public final void save(File file) throws IOException {
fileConfig.save(file);
}

public final FileConfiguration getConfig() {
return fileConfig;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.djrapitops.plugin.config;

import com.djrapitops.plugin.IPlugin;
import com.djrapitops.plugin.config.fileconfig.BukkitFileConfig;
import com.djrapitops.plugin.config.fileconfig.BungeeFileConfig;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.io.IOException;

/**
* Config file class for creating Bukkit config file classes more easily.
*
* @author Rsl1122
* @since 2.0.0
*/
public class BungeeConfig extends IConfig {

public BungeeConfig(IPlugin plugin, String filename) throws IOException {
this(plugin.getDataFolder(), filename);
}

public BungeeConfig(File folder, String filename) throws IOException {
super(folder, filename);
load();
}

public final void load(File file) throws IOException {
fileConfig = new BungeeFileConfig();
fileConfig.load(file);
}

public final void save(File file) throws IOException {
fileConfig.save(file);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.plugin.config;

import com.djrapitops.plugin.config.fileconfig.IFileConfig;
import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;
import org.bukkit.configuration.InvalidConfigurationException;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;

/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public abstract class IConfig {

private final File folder;
private final String fileName;
private File file;
protected IFileConfig fileConfig;

public IConfig(File folder, String fileName) throws IOException {
this.folder = folder;
this.fileName = fileName;
load();
}

public File copyFromStream(InputStream inputStream) throws IOException {
try {
if (folder.exists()) {
folder.mkdirs();
}
File file = new File(folder, fileName);
if (!file.exists()) {
Files.copy(inputStream, file.toPath());
}
return file;
} finally {
inputStream.close();
}
}

public File createFile() throws IOException {
file = new File(folder, fileName);
if (!file.exists()) {
file.createNewFile();
}
return file;
}

public void save() throws IOException {
save(file);
}

public abstract void save(File file) throws IOException;

public final void load() throws IOException {
load(createFile());
}

public abstract void load(File file) throws IOException;

public IFileConfig getConfig() {
return fileConfig;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.plugin.config.fileconfig;

import org.bukkit.configuration.ConfigurationSection;

import java.util.List;
import java.util.Set;

/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class BukkitConfigSection implements IConfigSection {

private final ConfigurationSection cs;

public BukkitConfigSection(ConfigurationSection cs) {
this.cs = cs;
}

@Override
public void set(String path, Object object) {
cs.set(path, object);
}

@Override
public boolean getBoolean(String path) {
return cs.getBoolean(path);
}

@Override
public Integer getInt(String path) {
return cs.getInt(path);
}

@Override
public Double getDouble(String path) {
return cs.getDouble(path);
}

@Override
public Long getLong(String path) {
return cs.getLong(path);
}

@Override
public String getString(String path) {
return cs.getString(path);
}

@Override
public List<String> getStringList(String path) {
return cs.getStringList(path);
}

@Override
public List<Integer> getIntegerList(String path) {
return cs.getIntegerList(path);
}


@Override
public IConfigSection getConfigSection(String path) {
return new BukkitConfigSection(cs.getConfigurationSection(path));
}

@Override
public Set<String> getKeys() {
return cs.getKeys(false);
}
}
Loading

0 comments on commit 2768931

Please sign in to comment.