-
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.
- NOTE: Removed plugin.yml and other files that were included into OpC (from now on OpC is not a standalone lib, and cannot be placed in /plugins directory) - Added Configuration system which allows you to easily save / get configuration objects and create your own, - Added OpText.java, so you can use its configuration methods, - Moved classes to their own packages,
- Loading branch information
1 parent
ce92669
commit c657703
Showing
36 changed files
with
984 additions
and
407 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 was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
src/main/java/me/opkarol/opc/api/configuration/CustomConfigurable.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,16 @@ | ||
package me.opkarol.opc.api.configuration; | ||
|
||
import java.util.function.Consumer; | ||
|
||
public interface CustomConfigurable { | ||
default void save(String path) { | ||
save().accept(new CustomConfiguration().setPath(path)); | ||
} | ||
|
||
default void get(String path) { | ||
get().accept(new CustomConfiguration().setPath(path)); | ||
} | ||
Consumer<CustomConfiguration> get(); | ||
|
||
Consumer<CustomConfiguration> save(); | ||
} |
168 changes: 168 additions & 0 deletions
168
src/main/java/me/opkarol/opc/api/configuration/CustomConfiguration.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,168 @@ | ||
package me.opkarol.opc.api.configuration; | ||
|
||
import me.opkarol.opc.OpAPI; | ||
import me.opkarol.opc.api.files.Configuration; | ||
import me.opkarol.opc.api.location.OpSerializableLocation; | ||
import me.opkarol.opc.api.misc.OpParticle; | ||
import me.opkarol.opc.api.misc.OpSound; | ||
import me.opkarol.opc.api.misc.OpText; | ||
import me.opkarol.opc.api.misc.OpTitle; | ||
import me.opkarol.opc.api.utils.ReflectionUtil; | ||
import me.opkarol.opc.api.utils.StringUtil; | ||
import me.opkarol.opc.api.utils.Util; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Consumer; | ||
|
||
public class CustomConfiguration { | ||
private final Configuration configuration = OpAPI.getConfig(); | ||
private String defaultPath; | ||
|
||
public Configuration getConfiguration() { | ||
return configuration; | ||
} | ||
|
||
public FileConfiguration getConfig() { | ||
return configuration.getConfig(); | ||
} | ||
|
||
public CustomConfiguration setString(String path, String object) { | ||
getConfig().set(getPath(path), object); | ||
return this; | ||
} | ||
|
||
public CustomConfiguration setInt(String path, int object) { | ||
getConfig().set(getPath(path), object); | ||
return this; | ||
} | ||
|
||
public CustomConfiguration setFloat(String path, float object) { | ||
getConfig().set(getPath(path), object); | ||
return this; | ||
} | ||
|
||
public CustomConfiguration setDouble(String path, double object) { | ||
getConfig().set(getPath(path), object); | ||
return this; | ||
} | ||
|
||
public CustomConfiguration setLocation(String path, @NotNull OpSerializableLocation object) { | ||
return setString(path, object.toString()); | ||
} | ||
|
||
public CustomConfiguration set(String path, Object object) { | ||
getConfig().set(getPath(path), object); | ||
return this; | ||
} | ||
|
||
public CustomConfiguration setConfigurable(String path, CustomConfigurable configurable) { | ||
if (configurable != null) { | ||
configurable.save(getPath(path)); | ||
} | ||
return this; | ||
} | ||
|
||
public CustomConfiguration setEnum(String path, @NotNull Enum<?> anEnum) { | ||
return setString(path, anEnum.name()); | ||
} | ||
|
||
public Object get(String path) { | ||
return getConfig().get(getPath(path)); | ||
} | ||
|
||
public String getString(String path) { | ||
return getConfig().getString(getPath(path)); | ||
} | ||
|
||
public int getInt(String path) { | ||
return StringUtil.getIntFromString(getString(path)); | ||
} | ||
|
||
public float getFloat(String path) { | ||
return StringUtil.getFloatFromString(getString(path)); | ||
} | ||
|
||
public double getDouble(String path) { | ||
return StringUtil.getDoubleFromString(getString(path)); | ||
} | ||
|
||
@Deprecated | ||
public <M extends CustomConfigurable> M getConfigurable(String path, Class<M> clazz) { | ||
M main = ReflectionUtil.getInstance(clazz); | ||
main.get(path); | ||
return main; | ||
} | ||
|
||
public OpSerializableLocation getLocation(String path) { | ||
return new OpSerializableLocation(getString(path)); | ||
} | ||
|
||
public <K extends Enum<K>> Optional<K> getEnum(String path, Class<K> clazz) { | ||
return StringUtil.getEnumValue(getPath(path), clazz); | ||
} | ||
|
||
public <K extends Enum<K>> K getUnsafeEnum(String path, Class<K> clazz) { | ||
Optional<K> optional = getEnum(path, clazz); | ||
if (optional.isEmpty()) { | ||
return null; | ||
} | ||
return optional.get(); | ||
} | ||
|
||
public CustomConfiguration save() { | ||
configuration.save(); | ||
return this; | ||
} | ||
|
||
public CustomConfiguration useSectionKeys(Consumer<String> consumer) { | ||
configuration.useSectionKeys(defaultPath, consumer); | ||
return this; | ||
} | ||
|
||
public CustomConfiguration useSectionKeys(String path, Consumer<String> consumer) { | ||
configuration.useSectionKeys(getPath(path), consumer); | ||
return this; | ||
} | ||
|
||
public <T> CustomConfiguration forEachIterable(Iterable<T> iterable, Consumer<T> consumer) { | ||
if (iterable != null && consumer != null) { | ||
iterable.forEach(consumer); | ||
} | ||
return this; | ||
} | ||
|
||
public String getPath(String path) { | ||
return Util.getOrDefault(defaultPath + path, path); | ||
} | ||
|
||
public CustomConfiguration setPath(String defaultPath) { | ||
this.defaultPath = Util.ifNotEndsWithAdd(defaultPath, "."); | ||
return this; | ||
} | ||
|
||
public OpText getText(String path) { | ||
OpText obj = new OpText(); | ||
obj.save(path); | ||
return obj; | ||
} | ||
|
||
public OpParticle getParticle(String path) { | ||
OpParticle obj = new OpParticle(); | ||
obj.save(path); | ||
return obj; | ||
} | ||
|
||
public OpTitle getTitle(String path) { | ||
OpTitle obj = new OpTitle(); | ||
obj.save(path); | ||
return obj; | ||
} | ||
|
||
public OpSound getSound(String path) { | ||
OpSound obj = new OpSound(); | ||
obj.save(path); | ||
return obj; | ||
} | ||
} |
Oops, something went wrong.