Skip to content

Commit

Permalink
Merge pull request #37 from CyR1en/development
Browse files Browse the repository at this point in the history
Add more filters & other features
  • Loading branch information
CyR1en authored Feb 18, 2024
2 parents 20e8c50 + 2dcb29c commit 697965e
Show file tree
Hide file tree
Showing 23 changed files with 590 additions and 74 deletions.
12 changes: 8 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ java {

PluginManifest pluginManifest = [
name : 'CommandPrompter',
version : new Version(major: 2, minor: 7, patch: 0, fix: 0, classifier: 'SNAPSHOT'),
version : new Version(major: 2, minor: 8, patch: 0, fix: 0, classifier: 'SNAPSHOT'),
author : 'CyR1en',
description: 'Perfect companion plugin for inventory UI menu.',
entry : 'com.cyr1en.commandprompter.CommandPrompter'
Expand All @@ -57,6 +57,7 @@ repositories {
maven { url 'https://repo.codemc.io/repository/maven-snapshots/' }
maven { url 'https://repo.extendedclip.com/content/repositories/placeholderapi/' }
maven { url 'https://jitpack.io' }
maven { url 'https://repo.glaremasters.me/repository/towny/'}
flatDir { dirs 'libs' }
}

Expand All @@ -74,12 +75,15 @@ dependencies {
implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.11'

compileOnly 'me.clip:placeholderapi:2.11.2'
compileOnly "net.kyori:adventure-text-serializer-legacy:4.13.1"
compileOnly "net.kyori:adventure-text-serializer-plain:4.13.1"
compileOnly "org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT"
compileOnly "net.kyori:adventure-text-serializer-legacy:4.15.0"
compileOnly "net.kyori:adventure-text-serializer-plain:4.15.0"
compileOnly "net.kyori:adventure-text-minimessage:4.15.0"
compileOnly 'com.palmergames.bukkit.towny:towny:0.100.0.0'
compileOnly "org.spigotmc:spigot-api:1.20.4-R0.1-SNAPSHOT"
compileOnly 'com.github.LeonMangler:SuperVanish:6.2.17'
compileOnly 'com.github.mbax:VanishNoPacket:3.22'
compileOnly 'org.jetbrains:annotations:23.0.0'
compileOnly 'net.luckperms:api:5.4'

// Local
implementation fileTree(dir: 'libs', include: '*.jar')
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/cyr1en/commandprompter/CommandPrompter.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public void onEnable() {
Bukkit.getScheduler().runTaskLater(this, () -> {
hookContainer = new HookContainer(this);
hookContainer.initHooks();
headCache.registerFilters();
promptManager.registerPrompts();
ChatPrompt.resolveListener(this);
}, 1L);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.cyr1en.commandprompter.api.prompt;


/**
* A functional interface for validating input.
*
* <p>Implement this interface to create a custom validator for your prompt.</p>
*/
public interface InputValidator {

/**
* Validate the input.
*
* <p>Return true if the input is valid, false otherwise.</p>
*
* @param input the input to validate
* @return true if the input is valid, false otherwise
*/
boolean validate(String input);

/**
* Get the alias for this validator.
*
* <p>The alias is used to identify the validator.</p>
*
* @return the alias for this validator
*/
String alias();

/**
* Get the message to send when validation fails.
*
* @return the message to send when validation fails
*/
String messageOnFail();
}
30 changes: 7 additions & 23 deletions src/main/java/com/cyr1en/commandprompter/api/prompt/Prompt.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.cyr1en.commandprompter.prompt.PromptParser;

import java.util.List;
import java.util.regex.Pattern;

public interface Prompt {

Expand Down Expand Up @@ -70,35 +69,20 @@ public interface Prompt {
PromptManager getPromptManager();

List<PromptParser.PromptArgument> getArgs();

/**
* set the regex check
*
* @param regexCheck regular expression to check prompt input
*/
void setRegexCheck(String regexCheck);

/**
* set the regex check using {@link Pattern}
*
* @param regexPattern regular expression to check prompt input
*/
void setRegexCheck(Pattern regexPattern);


/**
* Get the regex check
* Set the input validator
*
* @return regular expression to check prompt input
* @param inputValidator input validator to check prompt input
*/
Pattern getRegexCheck();
void setInputValidator(InputValidator inputValidator);

/**
* Check if the input is valid using {@link Prompt#getRegexCheck()}
* Get the input validator
*
* @param input input to check
* @return true if input is valid
* @return input validator to check prompt input
*/
boolean isValidInput(String input);
InputValidator getInputValidator();

/**
* Returns a boolean value if inputs should be sanitized.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,17 @@ public record CommandPrompterConfig(
"for CommandPrompter"
})
@NodeDefault("true")
boolean commandTabComplete
boolean commandTabComplete,

@ConfigNode
@NodeName("Ignore-MiniMessage")
@NodeComment({
"If Prompt-Regex is left to default",
"this will ignore MiniMessage syntax."
})
boolean ignoreMiniMessage


) implements AliasedSection {

public String[] getPermissionAttachment(String key) {
Expand Down
33 changes: 27 additions & 6 deletions src/main/java/com/cyr1en/commandprompter/config/PromptConfig.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.cyr1en.commandprompter.config;

import com.cyr1en.commandprompter.api.prompt.InputValidator;
import com.cyr1en.commandprompter.config.annotations.field.*;
import com.cyr1en.commandprompter.config.annotations.type.ConfigHeader;
import com.cyr1en.commandprompter.config.annotations.type.ConfigPath;
import com.cyr1en.commandprompter.config.annotations.type.Configuration;
import com.cyr1en.commandprompter.prompt.ui.CacheFilter;
import com.cyr1en.commandprompter.prompt.validators.NoopValidator;
import com.cyr1en.commandprompter.prompt.validators.OnlinePlayerValidator;
import com.cyr1en.commandprompter.prompt.validators.RegexValidator;
import com.cyr1en.kiso.mc.configuration.base.Config;

import java.util.regex.Pattern;

@Configuration
@ConfigPath("prompt-config.yml")
@ConfigHeader({"Prompts", "Configuration"})
Expand All @@ -21,6 +27,8 @@ public record PromptConfig(
"PlayerUI formatting", "",
"Skull-Name-Format - The display name format",
" for the player heads", "",
"Skull-Custom-Model-Data - The custom model data for the",
" player heads", "",
"Size - the size of the UI (multiple of 9, between 18-54)", "",
"Cache-Size - Size for the head cache", "",
"Cache-Delay - Delay in ticks after the player", "",
Expand All @@ -33,6 +41,11 @@ public record PromptConfig(
})
String skullNameFormat,

@ConfigNode
@NodeName("PlayerUI.Skull-Custom-Model-Data")
@NodeDefault("0")
int skullCustomModelData,

@ConfigNode
@NodeName("PlayerUI.Size")
@NodeDefault("54")
Expand Down Expand Up @@ -287,20 +300,28 @@ public record PromptConfig(
String strSampleErrMessage

) implements AliasedSection {
public String findIVRegexCheckInConfig(String alias) {
private String findIVRegexCheckInConfig(String alias) {
return getIVValue("Alias", alias, "Regex");
}

public String getIVErrMessage(String alias) {
private String getIVErrMessage(String alias) {
return getIVValue("Alias", alias, "Err-Message");
}

public String getIVErrMessageWithRegex(String regex) {
return getIVValue("Regex", regex, "Err-Message");
private String getIVValue(String key, String keyVal, String query) {
return getInputValidationValue("Input-Validation", key, keyVal, query);
}

public String getIVValue(String key, String keyVal, String query) {
return getInputValidationValue("Input-Validation", key, keyVal, query);
public InputValidator getInputValidator(String alias) {
if (alias == null || alias.isBlank())
return new NoopValidator();
var isPlayer = Boolean.parseBoolean(getIVValue("Alias", alias, "Online-Player"));
if (isPlayer)
return new OnlinePlayerValidator(alias, getIVErrMessage(alias));
var regex = findIVRegexCheckInConfig(alias);
if (regex != null && !regex.isBlank())
return new RegexValidator(alias, Pattern.compile(regex), getIVErrMessage(alias));
return new NoopValidator();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public void initHooks() {
hook(CarbonChatHook.class);
hook(VanishNoPacketHook.class);
hook(PapiHook.class);
hook(TownyHook.class);
hook(LuckPermsHook.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.cyr1en.commandprompter.hook.hooks;

import com.cyr1en.commandprompter.prompt.ui.HeadCache;

/**
* A hook that registers filters to the head cache.
*/
public interface FilterHook {

/**
* Register filters to the head cache.
*
* @param headCache the head cache
*/
void registerFilters(HeadCache headCache);
}
Loading

0 comments on commit 697965e

Please sign in to comment.