Skip to content

Commit

Permalink
1.3 - Configuration begins!
Browse files Browse the repository at this point in the history
- 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
ThisKarolGajda committed Aug 30, 2022
1 parent ce92669 commit c657703
Show file tree
Hide file tree
Showing 36 changed files with 984 additions and 407 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
- OpParticle,
- OpRunnable,
- OpSound,
- OpTitle
- OpTitle,
- OpText
- Abstract JavaPlugin implementation which provided added features and Configuration file to plugin,
- String based storage system with builder built-in supporting multiple java variables (double, int, String, boolean, (custom)) with supportive reflection,
- Useful util classes
- Custom Configuration system with easy-to-add own configuration objects,
- Head database and retrieving from players

You can learn everything that this core have in the [wiki](https://github.com/ThisKarolGajda/OpC/wiki).

Expand Down
60 changes: 11 additions & 49 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,27 @@
<groupId>me.opkarol</groupId>
<artifactId>opc</artifactId>
<version>1.1.0</version>
<packaging>jar</packaging>

<name>opc</name>

<description>opc is a modern and blazingly fast spigot api extenstion which allows developers to do tasks fast.
</description>
<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<outputFile>E:/Servers/Test6Plugin - 1.19.2/plugins/opc - ${project.version}.jar</outputFile>
<filters>
<filter>
<artifact>*:*</artifact>
<includes>
<include>me/opkarol/opc/**</include>
<include>plugin.yml</include>
<include>config.yml</include>
<include>lang/**</include>
<include>lang-save.yml</include>
</includes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<packaging>jar</packaging>

<name>opc</name>

<description>opc is a modern and blazingly fast spigot api extenstion which allows developers to do tasks fast.</description>
<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
<repository>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/me/opkarol/opc/OpAPI.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.opkarol.opc;

import me.opkarol.opc.api.commands.OpCommand;
import me.opkarol.opc.api.files.Configuration;
import me.opkarol.opc.api.plugin.OpPlugin;

import java.util.ArrayList;
Expand All @@ -25,4 +26,8 @@ public static void addCommand(OpCommand command) {
public static void unregisterCommands() {
commands.forEach(OpCommand::unregister);
}

public static Configuration getConfig() {
return plugin.getConfiguration();
}
}
33 changes: 0 additions & 33 deletions src/main/java/me/opkarol/opc/OpC.java

This file was deleted.

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();
}
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;
}
}
Loading

0 comments on commit c657703

Please sign in to comment.