Skip to content

Commit 7622502

Browse files
committed
Initial commit
0 parents  commit 7622502

34 files changed

+2148
-0
lines changed

.gitignore

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/intellij+all,macos,java,gradle
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=intellij+all,macos,java,gradle
4+
5+
### Intellij+all ###
6+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
7+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
8+
9+
# User-specific stuff
10+
.idea/**/workspace.xml
11+
.idea/**/tasks.xml
12+
.idea/**/usage.statistics.xml
13+
.idea/**/dictionaries
14+
.idea/**/shelf
15+
16+
# Generated files
17+
.idea/**/contentModel.xml
18+
19+
# Sensitive or high-churn files
20+
.idea/**/dataSources/
21+
.idea/**/dataSources.ids
22+
.idea/**/dataSources.local.xml
23+
.idea/**/sqlDataSources.xml
24+
.idea/**/dynamic.xml
25+
.idea/**/uiDesigner.xml
26+
.idea/**/dbnavigator.xml
27+
28+
# Gradle
29+
.idea/**/gradle.xml
30+
.idea/**/libraries
31+
32+
# Gradle and Maven with auto-import
33+
# When using Gradle or Maven with auto-import, you should exclude module files,
34+
# since they will be recreated, and may cause churn. Uncomment if using
35+
# auto-import.
36+
# .idea/artifacts
37+
# .idea/compiler.xml
38+
# .idea/jarRepositories.xml
39+
# .idea/modules.xml
40+
# .idea/*.iml
41+
# .idea/modules
42+
# *.iml
43+
# *.ipr
44+
45+
# CMake
46+
cmake-build-*/
47+
48+
# Mongo Explorer plugin
49+
.idea/**/mongoSettings.xml
50+
51+
# File-based project format
52+
*.iws
53+
54+
# IntelliJ
55+
out/
56+
57+
# mpeltonen/sbt-idea plugin
58+
.idea_modules/
59+
60+
# JIRA plugin
61+
atlassian-ide-plugin.xml
62+
63+
# Cursive Clojure plugin
64+
.idea/replstate.xml
65+
66+
# Crashlytics plugin (for Android Studio and IntelliJ)
67+
com_crashlytics_export_strings.xml
68+
crashlytics.properties
69+
crashlytics-build.properties
70+
fabric.properties
71+
72+
# Editor-based Rest Client
73+
.idea/httpRequests
74+
75+
# Android studio 3.1+ serialized cache file
76+
.idea/caches/build_file_checksums.ser
77+
78+
### Intellij+all Patch ###
79+
# Ignores the whole .idea folder and all .iml files
80+
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
81+
82+
.idea/
83+
84+
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
85+
86+
*.iml
87+
modules.xml
88+
.idea/misc.xml
89+
*.ipr
90+
91+
# Sonarlint plugin
92+
.idea/sonarlint
93+
94+
### Java ###
95+
# Compiled class file
96+
*.class
97+
98+
# Log file
99+
*.log
100+
101+
# BlueJ files
102+
*.ctxt
103+
104+
# Mobile Tools for Java (J2ME)
105+
.mtj.tmp/
106+
107+
# Package Files #
108+
*.jar
109+
*.war
110+
*.nar
111+
*.ear
112+
*.zip
113+
*.tar.gz
114+
*.rar
115+
116+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
117+
hs_err_pid*
118+
119+
### macOS ###
120+
# General
121+
.DS_Store
122+
.AppleDouble
123+
.LSOverride
124+
125+
# Icon must end with two \r
126+
Icon
127+
128+
# Thumbnails
129+
._*
130+
131+
# Files that might appear in the root of a volume
132+
.DocumentRevisions-V100
133+
.fseventsd
134+
.Spotlight-V100
135+
.TemporaryItems
136+
.Trashes
137+
.VolumeIcon.icns
138+
.com.apple.timemachine.donotpresent
139+
140+
# Directories potentially created on remote AFP share
141+
.AppleDB
142+
.AppleDesktop
143+
Network Trash Folder
144+
Temporary Items
145+
.apdisk
146+
147+
### Gradle ###
148+
.gradle
149+
build/
150+
151+
# Ignore Gradle GUI config
152+
gradle-app.setting
153+
154+
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
155+
!gradle-wrapper.jar
156+
157+
# Cache of project
158+
.gradletasknamecache
159+
160+
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
161+
# gradle/wrapper/gradle-wrapper.properties
162+
163+
### Gradle Patch ###
164+
**/build/
165+
166+
# End of https://www.toptal.com/developers/gitignore/api/intellij+all,macos,java,gradle

README.MD

+193
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
# ConfigAPI
2+
Config API for Bukkit 1.8 - 1.16 based on Dynamic Proxies
3+
4+
## Features:
5+
- Create config via Interface with `default` getters and setters
6+
- Automatic generation of YAML files based on Java code
7+
- Automatic updates of YAML file after adding new field to config
8+
- Support of comments in YAML files
9+
- Support of multiple config files
10+
- System of serializers for custom objects (e.g. ItemStack, Location)
11+
- Automatic translation of `&` based colors
12+
13+
## Import
14+
#### Gradle
15+
```groovy
16+
maven {
17+
url = 'https://repo.mikigal.pl/releases'
18+
}
19+
20+
compile group: 'pl.mikigal', name: 'ConfigAPI', version: '1.0'
21+
```
22+
23+
#### Maven
24+
```xml
25+
<repository>
26+
<id>mikigal-repo</id>
27+
<url>https://repo.mikigal.pl/releases</url>
28+
</repository>
29+
30+
<dependency>
31+
<groupId>pl.mikigal</groupId>
32+
<artifactId>ConfigAPI</artifactId>
33+
<version>1.0</version>
34+
<scope>compile</scope>
35+
</dependency>
36+
```
37+
38+
## How to use?
39+
#### Java code
40+
```java
41+
public class TestPlugin extends JavaPlugin {
42+
43+
private static TestConfig testConfig;
44+
45+
@Override
46+
public void onEnable() {
47+
testConfig = ConfigAPI.init(
48+
TestConfig.class, // Class of config's interface
49+
NameStyle.UNDERSCORE, // Style of fields' name in YAML file
50+
CommentStyle.INLINE, // Style of comments in YAML file
51+
true, // Automatic translation of '&' based colors
52+
this // Instance of plugin
53+
);
54+
55+
// You can simply access data from the config by getters
56+
System.out.println(testConfig.getExampleMessage());
57+
Bukkit.getPlayer("mikigal").getInventory().addItem(testConfig.getAward());
58+
59+
// After calling setter new data are automatically saved to file
60+
testConfig.setAward(new ItemStack(Material.DIRT));
61+
62+
// If you want to do something manually you can access instance of YamlConfiguration
63+
testConfig.getBukkitConfiguration();
64+
}
65+
66+
public static TestConfig getTestConfig() {
67+
return testConfig;
68+
}
69+
}
70+
71+
@ConfigName("test.yml") // Name of YAML file
72+
public interface TestConfig extends Config {
73+
74+
@Comment("This comment will be saved to YAML file!")
75+
default String getExampleMessage() {
76+
// Getter method should return default value of the field
77+
return "&cIt's default value of example message";
78+
}
79+
80+
default ItemStack getAward() {
81+
return Item.of(Material.DIAMOND_SWORD)
82+
.name("&cAward")
83+
.lore("&aFirst line", "&cSecond line")
84+
.toItem();
85+
}
86+
87+
public void setAward(ItemStack award);
88+
89+
// Key of Map must be String
90+
default Map<String, Integer> getValues() {
91+
Map<String, Integer> map = new HashMap<>();
92+
map.put("a", 1);
93+
map.put("b", 2);
94+
95+
return map;
96+
}
97+
98+
default List<Location> getSpawnPoints() {
99+
World world = Bukkit.getWorld("world");
100+
return Arrays.asList(
101+
new Location(world, 0, 100, 0),
102+
new Location(world, 10, 90, 10, 90f, 0f),
103+
new Location(world, 20, 80, 20, 0f, 180f)
104+
);
105+
}
106+
}
107+
```
108+
109+
#### Automatic generated YAML from above Java code
110+
```yaml
111+
values:
112+
a: 1
113+
b: 2
114+
example_message: '&cIt''s default value of example message' # This comment will be saved to YAML file!
115+
spawn_points:
116+
type: org.bukkit.Location
117+
'0':
118+
world: world
119+
x: 0.0
120+
y: 100.0
121+
z: 0.0
122+
yaw: 0.0
123+
pitch: 0.0
124+
'1':
125+
world: world
126+
x: 10.0
127+
y: 90.0
128+
z: 10.0
129+
yaw: 90.0
130+
pitch: 0.0
131+
'2':
132+
world: world
133+
x: 20.0
134+
y: 80.0
135+
z: 20.0
136+
yaw: 0.0
137+
pitch: 180.0
138+
award:
139+
material: DIAMOND_SWORD
140+
amount: 1
141+
name: '&cAward'
142+
lore:
143+
- '&aFirst line'
144+
- '&cSecond line'
145+
146+
```
147+
148+
## Serializers
149+
### API has built-in serializers for:
150+
- ItemStack
151+
- Location
152+
- PotionEffect
153+
- ShapedRecipe
154+
- UUID
155+
156+
#### You can also make your own serializers
157+
```java
158+
public class PotionEffectSerializer extends Serializer<PotionEffect> {
159+
160+
@Override
161+
protected void saveObject(String path, PotionEffect object, BukkitConfiguration configuration) {
162+
// In saveObject() method you have to set data of object to config. You can use set() method to set another object which need serialization too
163+
configuration.set(path + ".type", object.getType().getName());
164+
configuration.set(path + ".duration", object.getDuration());
165+
configuration.set(path + ".amplifier", object.getAmplifier());
166+
}
167+
168+
@Override
169+
public PotionEffect deserialize(String path, BukkitConfiguration configuration) {
170+
// In deserialize() method you have to load data from config and return instance of object
171+
PotionEffectType type = PotionEffectType.getByName(configuration.getString(path + ".type"));
172+
int duration = configuration.getInt(path + ".duration");
173+
int amplifier = configuration.getInt(path + ".amplifier");
174+
175+
if (type == null) {
176+
throw new InvalidConfigFileException("Invalid PotionEffect type (path: " + path + ")");
177+
}
178+
179+
return new PotionEffect(type, duration, amplifier);
180+
}
181+
}
182+
183+
public class TestPlugin extends JavaPlugin {
184+
185+
@Override
186+
public void onEnable() {
187+
// Remember to register you Serializer before use!
188+
ConfigAPI.registerSerializer(PotionEffect.class, new PotionEffectSerializer());
189+
190+
// Init your configs...
191+
192+
}
193+
}

0 commit comments

Comments
 (0)