Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Commit

Permalink
Add support for custom models - 2.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
virustotalop committed Nov 18, 2021
1 parent 545b2ee commit a4dc68d
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ public List<MacroToken> getTokens() {
}

public String parseStringMacros(final String replaceIn) {
if (replaceIn == null)
if (replaceIn == null) {
return null;
}

String replace = replaceIn;
for (MacroToken token : this.tokens) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class SlotToken implements Serializable {
private final List<String> lore;
private final List<String> enchants;
private final List<String> itemFlags;
private final String modelProvider;
private final String modelData;
private final int updateInterval;
private final MacroParser macroParser;
private final FunctionTree functionTree;
Expand Down Expand Up @@ -73,13 +75,17 @@ public SlotToken(int index, ConfigurationSection section, List<MacroToken> macro
this.lore = this.macroParser.parseListMacros(section.getStringList("lore"));
this.enchants = this.macroParser.parseListMacros(section.getStringList("enchants"));
this.itemFlags = this.macroParser.parseListMacros(section.getStringList("item-flags"));
this.modelProvider = this.macroParser.parseStringMacros(section.getString("model.provider"));
this.modelData = this.macroParser.parseStringMacros(section.getString("model.data"));
this.updateInterval = this.parseUpdateInterval(section.getString("update-interval"));

ConfigurationSection functionsSection = section.getConfigurationSection("functions");
this.functionTree = new FunctionTree(functionsSection, this.macroParser);

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


}

private int parseAmount(int amount) {
Expand Down Expand Up @@ -192,6 +198,14 @@ public List<String> getItemFlags() {
return this.itemFlags;
}

public String getModelProvider() {
return this.modelProvider;
}

public String getModelData() {
return this.modelData;
}

public FunctionTree getFunctionTree() {
return this.functionTree;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void testSlotData() {
assertTrue("Data was not 1", data == 1);
}


@Test
public void testSlotFunctionTree() {
FunctionTree tree = token.getFunctionTree();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2021 Club Obsidian and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.clubobsidian.dynamicgui.parser.test.slot;

import com.clubobsidian.dynamicgui.parser.slot.SlotToken;
import com.clubobsidian.wrappy.Configuration;
import com.clubobsidian.wrappy.ConfigurationSection;
import org.junit.Test;

import java.io.File;

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

public class ModelTest {

@Test
public void testModelProvider() {
File slotFolder = new File("test", "slot");
File file = new File(slotFolder, "model.yml");
Configuration config = Configuration.load(file);
ConfigurationSection section = config.getConfigurationSection("0");
SlotToken token = new SlotToken(0, section);
assertEquals("vanilla", token.getModelProvider());
}

@Test
public void testModelData() {
File slotFolder = new File("test", "slot");
File file = new File(slotFolder, "model.yml");
Configuration config = Configuration.load(file);
ConfigurationSection section = config.getConfigurationSection("0");
SlotToken token = new SlotToken(0, section);
assertEquals("1", token.getModelData());
}

@Test
public void testNonExistentModelProvider() {
File slotFolder = new File("test", "slot");
File file = new File(slotFolder, "model.yml");
Configuration config = Configuration.load(file);
ConfigurationSection section = config.getConfigurationSection("1");
SlotToken token = new SlotToken(1, section);
assertNull(token.getModelProvider());
}

@Test
public void testNonExistentModelData() {
File slotFolder = new File("test", "slot");
File file = new File(slotFolder, "model.yml");
Configuration config = Configuration.load(file);
ConfigurationSection section = config.getConfigurationSection("1");
SlotToken token = new SlotToken(1, section);
assertNull(token.getModelData());
}
}
4 changes: 4 additions & 0 deletions test/slot/model.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'0':
model:
provider: "vanilla"
data: "1"

0 comments on commit a4dc68d

Please sign in to comment.