Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
Updating Konstruct with more functions
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkKronicle committed Jan 25, 2022
1 parent cfcc43b commit 8442e19
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ archives_base_name=AdvancedChatCore

kommandlib_version=1.0.0-build1
malilib_version = 0.10.0-dev.26
konstruct_version=2.0.0-build1
konstruct_version=2.0.2-build1
mxparser_version=4.4.2
owo_version=2.0.0
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.darkkronicle.advancedchatcore.util;
package io.github.darkkronicle.advancedchatcore.konstruct;

import io.github.darkkronicle.Konstruct.functions.Function;
import io.github.darkkronicle.Konstruct.functions.NamedFunction;
Expand All @@ -10,6 +10,9 @@
import io.github.darkkronicle.Konstruct.type.StringObject;
import io.github.darkkronicle.addons.*;
import io.github.darkkronicle.advancedchatcore.AdvancedChatCore;
import io.github.darkkronicle.advancedchatcore.util.Color;
import io.github.darkkronicle.advancedchatcore.util.Colors;
import io.github.darkkronicle.advancedchatcore.util.TextUtil;
import lombok.Getter;
import net.minecraft.util.Util;

Expand All @@ -29,7 +32,6 @@ public static AdvancedChatKonstruct getInstance() {
private AdvancedChatKonstruct() {
reset();
addFunction(new CalculatorFunction());
addFunction(new GetFunction());
addFunction(new RandomFunction());
addFunction(new ReplaceFunction());
addFunction(new RoundFunction());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package io.github.darkkronicle.advancedchatcore.konstruct;

import io.github.darkkronicle.Konstruct.functions.ObjectFunction;
import io.github.darkkronicle.Konstruct.nodes.Node;
import io.github.darkkronicle.Konstruct.parser.IntRange;
import io.github.darkkronicle.Konstruct.parser.ParseContext;
import io.github.darkkronicle.Konstruct.parser.Result;
import io.github.darkkronicle.Konstruct.type.IntegerObject;
import io.github.darkkronicle.Konstruct.type.KonstructObject;
import io.github.darkkronicle.Konstruct.type.StringObject;
import io.github.darkkronicle.advancedchatcore.util.SearchResult;
import io.github.darkkronicle.advancedchatcore.util.StringMatch;

import java.util.List;

public class StringMatchObject extends KonstructObject<StringMatchObject> {

private final StringMatch result;

private final static List<ObjectFunction<StringMatchObject>> FUNCTIONS = List.of(
new ObjectFunction<>() {
@Override
public Result parse(ParseContext context, StringMatchObject self, List<Node> input) {
return Result.success(new IntegerObject(self.result.start));
}

@Override
public String getName() {
return "getStart";
}

@Override
public IntRange getArgumentCount() {
return IntRange.of(0);
}
},
new ObjectFunction<>() {
@Override
public Result parse(ParseContext context, StringMatchObject self, List<Node> input) {
return Result.success(new IntegerObject(self.result.end));
}

@Override
public String getName() {
return "getEnd";
}

@Override
public IntRange getArgumentCount() {
return IntRange.of(0);
}
},
new ObjectFunction<>() {
@Override
public Result parse(ParseContext context, StringMatchObject self, List<Node> input) {
return Result.success(new StringObject(self.result.match));
}

@Override
public String getName() {
return "getMessage";
}

@Override
public IntRange getArgumentCount() {
return IntRange.of(0);
}
}
);

public StringMatchObject(StringMatch result) {
this.result = result;
}

@Override
public String getString() {
return result.toString();
}

@Override
public String getTypeName() {
return "string_match";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.ToString;

/**
* A class to store data about a match.
*
* <p>This class is comparable based on where it starts.
*/
@EqualsAndHashCode
@ToString
@AllArgsConstructor
public class StringMatch implements Comparable<StringMatch> {

Expand Down

0 comments on commit 8442e19

Please sign in to comment.