-
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
0 parents
commit cbc643a
Showing
4 changed files
with
256 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
MIT License | ||
|
||
Copyright (c) [2023] [Jiří Apjár] | ||
Copyright (c) [2023] [Filip Zeman] | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,99 @@ | ||
# ForestConfigAPI | ||
![badge](https://img.shields.io/github/v/release/FlyUltra/TheBungeeConfig) | ||
[![badge](https://jitpack.io/v/FlyUltra/TheBungeeConfig.svg)](https://jitpack.io/#FlyUltra/TheBungeeConfig) | ||
![badge](https://img.shields.io/github/downloads/FlyUltra/TheBungeeConfig/total) | ||
![badge](https://img.shields.io/github/last-commit/FlyUltra/TheBungeeConfig) | ||
![badge](https://img.shields.io/badge/platform-bungee-lightgrey) | ||
[![badge](https://img.shields.io/discord/896466173166747650?label=discord)](https://discord.gg/2PpdrfxhD4) | ||
[![badge](https://img.shields.io/github/license/FlyUltra/TheBungeeConfig)](https://github.com/FlyUltra/TheBungeeConfig/blob/master/LICENSE.txt) | ||
|
||
**[JavaDoc 1.0](https://foresttechmc.github.io/TheBungeeConfig/1.0/)** | ||
|
||
Small and effective Config API for Developers! <br> | ||
Only bungee support! <br> | ||
([Spigot version](https://github.com/ForestTechMC/ForestConfigAPI)) | ||
|
||
## Table of contents | ||
|
||
* [Getting started](#getting-started) | ||
* [Using the config API](#using-config-api) | ||
* [License](#license) | ||
|
||
## Getting started | ||
|
||
Make sure you reloaded maven or gradle in your project. | ||
|
||
### Add TheBungeeConfig to your project | ||
|
||
[![badge](https://jitpack.io/v/FlyUltra/TheBungeeConfig.svg)](https://jitpack.io/#FlyUltra/TheBungeeConfig) | ||
|
||
You need to add this dependency into your plugin, then look at under the dependencies example | ||
|
||
<details> | ||
<summary>Maven</summary> | ||
|
||
```xml | ||
<repositories> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.github.FlyUltra</groupId> | ||
<artifactId>TheBungeeConfig</artifactId> | ||
<version>VERSION</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
``` | ||
</details> | ||
|
||
<details> | ||
<summary>Gradle</summary> | ||
|
||
```gradle | ||
allprojects { | ||
repositories { | ||
... | ||
maven { url 'https://jitpack.io' } | ||
} | ||
} | ||
dependencies { | ||
implementation 'com.github.FlyUltra:TheBungeeConfig:VERSION' | ||
} | ||
``` | ||
</details> | ||
|
||
### Using Config API | ||
|
||
```java | ||
// Main class | ||
private Main plugin; | ||
// This API | ||
private ConfigAPI configAPI; | ||
|
||
// Load method | ||
public void loadConfig() { | ||
// Constructor with Main class, and name | ||
configAPI = new ConfigAPI(plugin, "coolConfig"); | ||
// Create config | ||
configAPI.create(); | ||
|
||
// getConfig() -> this return you configuration of file for using like normal config | ||
configAPI.getConfig().set("coolMessage", "Cool message in config!"); | ||
// this save your edits | ||
configAPI.save(); | ||
} | ||
|
||
// Here you can see, how to get string from your "coolConfig.yml" with path "coolMessage" | ||
public void messages() { | ||
configAPI.getConfig().getString("coolMessage"); | ||
} | ||
``` | ||
|
||
## License | ||
ForestRedisAPI is licensed under the permissive MIT license. Please see [`LICENSE.txt`](https://github.com/FlyUltra/TheBungeeConfig/blob/master/LICENSE.txt) for more information. |
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,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>cz.flyultra</groupId> | ||
<artifactId>TheBungeeConfig</artifactId> | ||
<version>1.0</version> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
<repository> | ||
<id>bungeecord-repo</id> | ||
<url>https://oss.sonatype.org/content/repositories/snapshots</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>net.md-5</groupId> | ||
<artifactId>bungeecord-api</artifactId> | ||
<version>1.19-R0.1-SNAPSHOT</version> | ||
<type>jar</type> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.22</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
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,92 @@ | ||
package cz.flyultra.api; | ||
|
||
import lombok.SneakyThrows; | ||
import net.md_5.bungee.api.plugin.Plugin; | ||
import net.md_5.bungee.config.Configuration; | ||
import net.md_5.bungee.config.ConfigurationProvider; | ||
import net.md_5.bungee.config.YamlConfiguration; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.InputStream; | ||
|
||
public class ConfigAPI { | ||
|
||
// Your plugin | ||
private Plugin plugin; | ||
|
||
// Name of file | ||
private String fileName; | ||
|
||
// The file | ||
private File file; | ||
|
||
/** | ||
* | ||
* Constructor for config | ||
* | ||
* @param plugin Your plugin | ||
* @param fileName name of the file, we want to modify | ||
*/ | ||
public ConfigAPI(Plugin plugin, String fileName) { | ||
this.plugin = plugin; | ||
if (!fileName.contains(".yml")) { | ||
fileName = fileName + ".yml"; | ||
} | ||
|
||
this.fileName = fileName; | ||
this.file = new File(plugin.getDataFolder(), fileName); | ||
} | ||
|
||
/** | ||
* | ||
* This is the essential method for using the whole config | ||
* | ||
* @return options like normal config | ||
*/ | ||
@SneakyThrows | ||
public Configuration getConfig() { | ||
return ConfigurationProvider | ||
.getProvider(YamlConfiguration.class) | ||
.load(file); | ||
} | ||
|
||
/** | ||
* | ||
* This method is the same as reload, because Bungee provider method for load do this two things | ||
* | ||
*/ | ||
@SneakyThrows | ||
public void save() { | ||
ConfigurationProvider.getProvider(YamlConfiguration.class).load(file); | ||
} | ||
|
||
/** | ||
* | ||
* Same as save method | ||
* | ||
*/ | ||
@SneakyThrows | ||
public void reload() { | ||
ConfigurationProvider.getProvider(YamlConfiguration.class).load(file); | ||
} | ||
|
||
/** | ||
* | ||
* We can see, here we create config, and copy resource into | ||
* | ||
*/ | ||
@SneakyThrows | ||
public void create() { | ||
if (!plugin.getDataFolder().exists()) { | ||
plugin.getDataFolder().mkdir(); | ||
} | ||
|
||
if (!file.exists()) { | ||
FileOutputStream outputStream = new FileOutputStream(file); | ||
InputStream in = plugin.getResourceAsStream(fileName); | ||
in.transferTo(outputStream); | ||
} | ||
} | ||
|
||
} |