This repository has been archived by the owner on Mar 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
470 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
AbstractPluginFramework/src/main/java/com/djrapitops/plugin/config/BungeeConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
AbstractPluginFramework/src/main/java/com/djrapitops/plugin/config/IConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
} |
75 changes: 75 additions & 0 deletions
75
...nFramework/src/main/java/com/djrapitops/plugin/config/fileconfig/BukkitConfigSection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.