Skip to content

Commit

Permalink
* Fixed key and value discovery for JsonConfiguration.java using new …
Browse files Browse the repository at this point in the history
…MapDecompressionUtils service.

* Added new docket type AnvilDocket.java for retrieving simple context from an anvil.
* Added new management methods to FileManager.java
* Added example to Disabled.java javadoc
* Added new pagination builder AdvancedPagination.java for including page in formatting.
* Added new UniqueHolder.java interface for signifying a docket as a singular object translator.
* Added the start of the Vent provided event system for UnityLib (gui) MenuClickEvent.java, MenuDragItemEvent.java
  • Loading branch information
Hempfest committed Jun 24, 2022
1 parent 64ae19d commit 448e770
Show file tree
Hide file tree
Showing 27 changed files with 636 additions and 169 deletions.
2 changes: 1 addition & 1 deletion labyrinth-common/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>labyrinth</artifactId>
<groupId>com.github.the-h-team</groupId>
<version>1.7.8</version>
<version>1.7.9</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Expand Up @@ -84,6 +84,17 @@ public void write(Consumer<? super DataTable> table) {
write(t);
}

/**
* Set/Replace & save multiple keyed value spaces within this file.
*
* @see FileManager#write(DataTable, boolean)
* @param table The data table to use when setting values.
*/
@Note("You can create a fresh DataTable really easily see DataTable#newTable()")
public void write(@Note("Provided table gets cleared upon finalization.") DataTable table) {
write(table, true);
}

/**
* Set & save multiple keyed value spaces within this file.
*
Expand All @@ -95,19 +106,11 @@ public void write(Consumer<? super DataTable> table) {
* <p>By default this method is set to override any already existing nodes store
* within the configurable</p>
*
* @param table The data table to use when setting values.
*/
@Note("You can create a fresh DataTable really easily see DataTable#newTable()")
public void write(@Note("Custom implementations will work here!") DataTable table) {
write(table, true);
}

/**
* @param replace Whether to replace already set values from file with ones from the table
* @see FileManager#write(DataTable)
*/
@Note("You can create a fresh DataTable really easily see DataTable#newTable()")
public void write(@Note("Custom implementations will work here!") DataTable table, boolean replace) {
public void write(@Note("Provided table gets cleared upon finalization.") DataTable table, boolean replace) {
for (Map.Entry<String, Object> entry : table.values().entrySet()) {
if (replace) {
if (entry.getValue().equals("NULL")) {
Expand All @@ -123,67 +126,91 @@ public void write(@Note("Custom implementations will work here!") DataTable tabl
}
}
}
// instantly clear up space (help GC)
// instantly clear up space (help GC, we don't need these elements anymore.)
table.clear();
configuration.save();
}

public @NotNull FileManager toJSON(String name, String dir) {
/**
* Copy all values from this yml file to a json file of similar stature.
*
* @param name The new name of the file.
* @param dir The optional new directory, null places in base folder.
* @return a new json file containing all values from this yml file.
*/
public @NotNull FileManager toJSON(@NotNull String name, String dir) {
FileManager n = FileList.search(plugin).get(name, dir, FileType.JSON);
Configurable c = getRoot();
if (c instanceof YamlConfiguration) {
DataTable inquiry = DataTable.newTable();
for (String entry : c.getKeys(true)) {
if (c.isNode(entry)) {
ConfigurationSection s = c.getNode(entry).get(ConfigurationSection.class);
for (String e : s.getKeys(true)) {
if (s.isConfigurationSection(e)) {
ConfigurationSection a = s.getConfigurationSection(e);
inquiry.set(e, a.get(e));
}
}
} else {
inquiry.set(entry, c.getNode(entry).get());
}
}
n.write(inquiry, false);
n.write(copy(), false);
return n;
}
return this;
}

public @NotNull FileManager toYaml(String name, String dir) {
/**
* Copy all values from this json file to a yml file of similar stature.
*
* @param name The new name of the file.
* @param dir The optional new directory, null places in base folder.
* @return a new yml file containing all values from this json file.
*/
public @NotNull FileManager toYaml(@NotNull String name, String dir) {
FileManager n = FileList.search(plugin).get(name, dir, FileType.JSON);
Configurable c = getRoot();
if (c instanceof JsonConfiguration) {
DataTable inquiry = DataTable.newTable();
for (String entry : c.getKeys(true)) {
if (c.isNode(entry)) {
Node s = c.getNode(entry);
for (String e : s.getKeys(true)) {
if (s.isNode(e)) {
Node a = s.getNode(e);
inquiry.set(e, a.get());
}
}
} else {
inquiry.set(entry, c.getNode(entry).get());
}
}
n.write(inquiry, false);
n.write(copy(), false);
return n;
}
return this;
}

/**
* Copy all values from this yml file to a json file of similar stature.
*
* @return a new json file containing all values from this yml file.
*/
public @NotNull FileManager toJSON() {
return toJSON(getRoot().getName(), getRoot().getDirectory());
}

/**
* Copy all values from this json file to a yml file of similar stature.
*
* @return a new yml file containing all values from this json file.
*/
public @NotNull FileManager toYaml() {
return toYaml(getRoot().getName(), getRoot().getDirectory());
}

/**
* Move this file to another location. Retains all values but doesn't retain comments, only headers.
* *Automatically deletes old file when moved*
*
* @param dir The optional new directory to move to, null places in base folder.
* @return a new file containing all the values from this file.
*/
public @NotNull FileManager toMoved(String dir) {
// gotta love our api sometimes, just look at how clean it is to copy ALL values from a config to another location.
final FileManager n = FileList.search(plugin).get(getRoot().getName(), dir, getRoot().getType());
Configurable c = getRoot();
n.write(copy(), false);
c.delete();
return n;
}

/**
* Copy all contents to a datatable.
*
* @return a fresh datatable containing all values from this file.
*/
public @NotNull DataTable copy() {
Configurable c = getRoot();
DataTable inquiry = DataTable.newTable();
c.getValues(true).forEach(inquiry::set);
return inquiry;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Expand Up @@ -301,38 +301,11 @@ public Node getNode(String key) {
@SuppressWarnings("unchecked")
@Override
public Set<String> getKeys(boolean deep) {
Set<String> keys = new HashSet<>();
for (Object o : json.entrySet()) {
Map.Entry<String, Object> entry = (Map.Entry<String, Object>) o;
if (deep) {
if (entry.getValue() instanceof JSONObject) {
JSONObject obj = (JSONObject) entry.getValue();
for (Object ob : obj.entrySet()) {
Map.Entry<String, Object> en = (Map.Entry<String, Object>) ob;
if (en.getValue() instanceof JSONObject) {
JSONObject j = (JSONObject) entry.getValue();
for (Object e : j.entrySet()) {
Map.Entry<String, Object> ent = (Map.Entry<String, Object>) e;
if (ent.getValue() instanceof JSONObject) {
JSONObject ja = (JSONObject) ent.getValue();
for (Object ex : ja.entrySet()) {
Map.Entry<String, Object> entr = (Map.Entry<String, Object>) ex;
keys.add(entry.getKey() + "." + en.getKey() + "." + ent.getKey() + "." + entr.getKey());
}
} else {
keys.add(entry.getKey() + "." + en.getKey() + "." + ent.getKey());
}
}
} else {
keys.add(entry.getKey() + "." + en.getKey());
}
}
} else {
keys.add(entry.getKey());
}
} else {
keys.add(entry.getKey());
}
Set<String> keys;
if (deep) {
return MapDecompressionUtils.getInstance().decompress((Set<Map.Entry<String, Object>>)json.entrySet(), '.', null).toSet();
} else {
keys = new HashSet<>((Set<String>) json.keySet());
}
return keys;
}
Expand All @@ -341,37 +314,13 @@ public Set<String> getKeys(boolean deep) {
@Override
public Map<String, Object> getValues(boolean deep) {
Map<String, Object> map = new HashMap<>();
for (Object o : json.entrySet()) {
Map.Entry<String, Object> entry = (Map.Entry<String, Object>) o;
if (deep) {
if (entry.getValue() instanceof JSONObject) {
JSONObject obj = (JSONObject) entry.getValue();
for (Object ob : obj.entrySet()) {
Map.Entry<String, Object> en = (Map.Entry<String, Object>) ob;
if (en.getValue() instanceof JSONObject) {
JSONObject j = (JSONObject) entry.getValue();
for (Object e : j.entrySet()) {
Map.Entry<String, Object> ent = (Map.Entry<String, Object>) e;
if (ent.getValue() instanceof JSONObject) {
JSONObject ja = (JSONObject) ent.getValue();
for (Object ex : ja.entrySet()) {
Map.Entry<String, Object> entr = (Map.Entry<String, Object>) ex;
map.put(entry.getKey() + "." + en.getKey() + "." + ent.getKey() + "." + entr.getKey(), entr.getValue());
}
} else {
map.put(entry.getKey() + "." + en.getKey() + "." + ent.getKey(), ent.getValue());
}
}
} else {
map.put(entry.getKey() + "." + en.getKey(), en.getValue());
}
}
} else {
map.put(entry.getKey(), entry.getValue());
}
} else {
if (deep) {
return MapDecompressionUtils.getInstance().decompress((Set<Map.Entry<String, Object>>)json.entrySet(), '.', null).toMap();
} else {
json.entrySet().forEach(e -> {
Map.Entry<String, Object> entry = (Map.Entry<String, Object>)e;
map.put(entry.getKey(), entry.getValue());
}
});
}
return map;
}
Expand Down
Expand Up @@ -9,6 +9,14 @@

/**
* An annotation marking a {@link VentListener} subscription not valid for runtime usage.
*
* Example:
* <pre>{@code
* @Disabled
* @Subscribe
* public void onMyEvent(Vent e) {
*
* }}</pre>
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
Expand All @@ -17,4 +25,6 @@

String until() default "N/A";



}
Expand Up @@ -7,6 +7,9 @@
import java.lang.annotation.Target;
import org.jetbrains.annotations.NotNull;

/**
* An annotation that's capable of keying a class. Giving it a unique identifier.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
Expand Down
Expand Up @@ -27,8 +27,9 @@
* Wraps around any objects, detects methods annotated with {@link Subscribe} and creates SubscriberCalls with it.
* Also, it recognises methods annotated with {@link Extend} and adds them to the method linking pool
* Always has s string as key, which may be "null", when not specified by {@link LabeledAs};
*
* @author Rigo
*/

public class VentListener {

/**
Expand Down

0 comments on commit 448e770

Please sign in to comment.