Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.github.vaerys.interfaces;
- import com.github.vaerys.commands.CommandObject;
- import com.github.vaerys.objects.ReplaceObject;
- import org.apache.commons.lang3.StringUtils;
- import java.util.Arrays;
- import java.util.List;
- import java.util.regex.Pattern;
- public abstract class TagInterface extends TagObject {
- public TagInterface(int priority) {
- super(priority);
- }
- public abstract String execute(String from, CommandObject command, String args);
- ReplaceObject executeReplace(String from, CommandObject command, String args) {
- return null;
- }
- public abstract String tagName();
- public abstract int argsRequired();
- public abstract String usage();
- public abstract String desc();
- private boolean cont(String from) {
- if (argsRequired() > 0) {
- return Pattern.compile(prefix() + "*." + suffix()).matcher(from).find();
- } else {
- return Pattern.compile(tagName()).matcher(from).find();
- }
- }
- private String contents(String from) {
- if (argsRequired() > 0) {
- return StringUtils.substringBetween(from, prefix(), suffix());
- } else {
- return "";
- }
- }
- private List<String> getSplit(String args) {
- return Arrays.asList(args.split(splitter()));
- }
- private String removeFirst(String from, String args) {
- return StringUtils.replaceOnce(from, args, "");
- }
- private String removeAll(String from, String args) {
- return from.replace(args, "");
- }
- private String replaceFirst(String from, String replace, String withThis) {
- return StringUtils.replaceOnce(from, replace, withThis);
- }
- private String replaceAll(String from, String replace, String withThis) {
- return from.replace(replace, withThis);
- }
- private String splitter() {
- return ";;";
- }
- private String prefix() {
- if (argsRequired() == 0) {
- return tagName();
- } else {
- return tagName() + "{";
- }
- }
- private String suffix() {
- if (argsRequired() == 0) {
- return "";
- } else {
- return "}";
- }
- }
- public String handleTag(String from, CommandObject command, String args) {
- while (cont(from)) {
- from = execute(from, command, args);
- }
- return from;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement