Skip to content

Commit

Permalink
Add content and metadata to guis
Browse files Browse the repository at this point in the history
  • Loading branch information
virustotalop committed Feb 22, 2021
1 parent af3b8d3 commit 3fd4e5b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,22 @@ public class GuiToken implements Serializable {
private static final int MAX_SLOT_SIZE = 100; //Temporary fix

private String title;
private String content;
private List<String> alias;
private List<String> locations;
private Map<String, List<Integer>> npcs;
private Map<Integer, SlotToken> slots;
private MacroParser macroParser;
private FunctionTree functions;
private List<String> loadMacros;
private Map<String, String> metadata;

public GuiToken(ConfigurationSection section) {
this(section, new ArrayList<MacroToken>());
}

public GuiToken(ConfigurationSection section, List<MacroToken> macroTokens) {
List<MacroToken> copyMacroTokens = new ArrayList<MacroToken>();
List<MacroToken> copyMacroTokens = new ArrayList<>();
for(MacroToken token : macroTokens) {
copyMacroTokens.add(token);
}
Expand All @@ -61,6 +63,7 @@ public GuiToken(ConfigurationSection section, List<MacroToken> macroTokens) {

this.macroParser = new MacroParser(copyMacroTokens);
this.title = this.macroParser.parseStringMacros(section.getString("title"));
this.content = this.macroParser.parseStringMacros(section.getString("content"));
this.alias = this.macroParser.parseListMacros(section.getStringList("alias"));
this.locations = this.macroParser.parseListMacros(section.getStringList("locations"));
this.loadNpcs(section);
Expand All @@ -69,6 +72,9 @@ public GuiToken(ConfigurationSection section, List<MacroToken> macroTokens) {
ConfigurationSection guiFunctionsSection = section.getConfigurationSection("functions");
this.functions = new FunctionTree(guiFunctionsSection, this.macroParser);
this.loadMacros = section.getStringList("load-macros");

ConfigurationSection metadataSection = section.getConfigurationSection("metadata");
this.metadata = this.parseMetadata(metadataSection);
}

private void loadNpcs(ConfigurationSection section) {
Expand All @@ -91,10 +97,25 @@ private void loadSlots(ConfigurationSection section) {
}
}
}


private Map<String, String> parseMetadata(ConfigurationSection section) {
Map<String, String> metadata = new HashMap<>();
for(String key : section.getKeys()) {
String parsedKey = this.macroParser.parseStringMacros(key);
String value = section.getString(parsedKey);
value = this.macroParser.parseStringMacros(value);
metadata.put(parsedKey, value);
}
return metadata;
}

public String getTitle() {
return this.title;
}

public String getContent() {
return this.content;
}

public List<String> getAlias() {
return this.alias;
Expand Down Expand Up @@ -123,4 +144,8 @@ public MacroParser getMacroParser() {
public List<String> getLoadMacros() {
return this.loadMacros;
}

public Map<String, String> getMetadata() {
return this.metadata;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.clubobsidian.dynamicform.parser.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
Expand Down Expand Up @@ -50,6 +51,19 @@ public void testTitle() {
String title = token.getTitle();
assertTrue("Gui title is not 'test gui title'", title.equals("test gui title"));
}

@Test
public void testContent() {
String title = token.getContent();
assertEquals(title, "foobar");
}

@Test
public void testMetadata() {
Map<String, String> metadata = token.getMetadata();
System.out.println(metadata.get("some"));
assertEquals(metadata.get("some"), "metadata");
}

@Test
public void testNpcs() {
Expand Down
3 changes: 3 additions & 0 deletions test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
title: "test gui title"
content: "foobar"
rows: 1
mode: "set"
close: true
metadata:
some: "metadata"
npcs:
citizens:
- 5
Expand Down

0 comments on commit 3fd4e5b

Please sign in to comment.