Skip to content

Commit 697965e

Browse files
authored
Merge pull request #37 from CyR1en/development
Add more filters & other features
2 parents 20e8c50 + 2dcb29c commit 697965e

23 files changed

Lines changed: 590 additions & 74 deletions

build.gradle

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ java {
3939

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

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

7677
compileOnly 'me.clip:placeholderapi:2.11.2'
77-
compileOnly "net.kyori:adventure-text-serializer-legacy:4.13.1"
78-
compileOnly "net.kyori:adventure-text-serializer-plain:4.13.1"
79-
compileOnly "org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT"
78+
compileOnly "net.kyori:adventure-text-serializer-legacy:4.15.0"
79+
compileOnly "net.kyori:adventure-text-serializer-plain:4.15.0"
80+
compileOnly "net.kyori:adventure-text-minimessage:4.15.0"
81+
compileOnly 'com.palmergames.bukkit.towny:towny:0.100.0.0'
82+
compileOnly "org.spigotmc:spigot-api:1.20.4-R0.1-SNAPSHOT"
8083
compileOnly 'com.github.LeonMangler:SuperVanish:6.2.17'
8184
compileOnly 'com.github.mbax:VanishNoPacket:3.22'
8285
compileOnly 'org.jetbrains:annotations:23.0.0'
86+
compileOnly 'net.luckperms:api:5.4'
8387

8488
// Local
8589
implementation fileTree(dir: 'libs', include: '*.jar')

src/main/java/com/cyr1en/commandprompter/CommandPrompter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ public void onEnable() {
102102
Bukkit.getScheduler().runTaskLater(this, () -> {
103103
hookContainer = new HookContainer(this);
104104
hookContainer.initHooks();
105+
headCache.registerFilters();
106+
promptManager.registerPrompts();
105107
ChatPrompt.resolveListener(this);
106108
}, 1L);
107109
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.cyr1en.commandprompter.api.prompt;
2+
3+
4+
/**
5+
* A functional interface for validating input.
6+
*
7+
* <p>Implement this interface to create a custom validator for your prompt.</p>
8+
*/
9+
public interface InputValidator {
10+
11+
/**
12+
* Validate the input.
13+
*
14+
* <p>Return true if the input is valid, false otherwise.</p>
15+
*
16+
* @param input the input to validate
17+
* @return true if the input is valid, false otherwise
18+
*/
19+
boolean validate(String input);
20+
21+
/**
22+
* Get the alias for this validator.
23+
*
24+
* <p>The alias is used to identify the validator.</p>
25+
*
26+
* @return the alias for this validator
27+
*/
28+
String alias();
29+
30+
/**
31+
* Get the message to send when validation fails.
32+
*
33+
* @return the message to send when validation fails
34+
*/
35+
String messageOnFail();
36+
}

src/main/java/com/cyr1en/commandprompter/api/prompt/Prompt.java

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.cyr1en.commandprompter.prompt.PromptParser;
3131

3232
import java.util.List;
33-
import java.util.regex.Pattern;
3433

3534
public interface Prompt {
3635

@@ -70,35 +69,20 @@ public interface Prompt {
7069
PromptManager getPromptManager();
7170

7271
List<PromptParser.PromptArgument> getArgs();
73-
74-
/**
75-
* set the regex check
76-
*
77-
* @param regexCheck regular expression to check prompt input
78-
*/
79-
void setRegexCheck(String regexCheck);
80-
81-
/**
82-
* set the regex check using {@link Pattern}
83-
*
84-
* @param regexPattern regular expression to check prompt input
85-
*/
86-
void setRegexCheck(Pattern regexPattern);
87-
72+
8873
/**
89-
* Get the regex check
74+
* Set the input validator
9075
*
91-
* @return regular expression to check prompt input
76+
* @param inputValidator input validator to check prompt input
9277
*/
93-
Pattern getRegexCheck();
78+
void setInputValidator(InputValidator inputValidator);
9479

9580
/**
96-
* Check if the input is valid using {@link Prompt#getRegexCheck()}
81+
* Get the input validator
9782
*
98-
* @param input input to check
99-
* @return true if input is valid
83+
* @return input validator to check prompt input
10084
*/
101-
boolean isValidInput(String input);
85+
InputValidator getInputValidator();
10286

10387
/**
10488
* Returns a boolean value if inputs should be sanitized.

src/main/java/com/cyr1en/commandprompter/config/CommandPrompterConfig.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,17 @@ public record CommandPrompterConfig(
187187
"for CommandPrompter"
188188
})
189189
@NodeDefault("true")
190-
boolean commandTabComplete
190+
boolean commandTabComplete,
191+
192+
@ConfigNode
193+
@NodeName("Ignore-MiniMessage")
194+
@NodeComment({
195+
"If Prompt-Regex is left to default",
196+
"this will ignore MiniMessage syntax."
197+
})
198+
boolean ignoreMiniMessage
199+
200+
191201
) implements AliasedSection {
192202

193203
public String[] getPermissionAttachment(String key) {

src/main/java/com/cyr1en/commandprompter/config/PromptConfig.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
package com.cyr1en.commandprompter.config;
22

3+
import com.cyr1en.commandprompter.api.prompt.InputValidator;
34
import com.cyr1en.commandprompter.config.annotations.field.*;
45
import com.cyr1en.commandprompter.config.annotations.type.ConfigHeader;
56
import com.cyr1en.commandprompter.config.annotations.type.ConfigPath;
67
import com.cyr1en.commandprompter.config.annotations.type.Configuration;
78
import com.cyr1en.commandprompter.prompt.ui.CacheFilter;
9+
import com.cyr1en.commandprompter.prompt.validators.NoopValidator;
10+
import com.cyr1en.commandprompter.prompt.validators.OnlinePlayerValidator;
11+
import com.cyr1en.commandprompter.prompt.validators.RegexValidator;
812
import com.cyr1en.kiso.mc.configuration.base.Config;
913

14+
import java.util.regex.Pattern;
15+
1016
@Configuration
1117
@ConfigPath("prompt-config.yml")
1218
@ConfigHeader({"Prompts", "Configuration"})
@@ -21,6 +27,8 @@ public record PromptConfig(
2127
"PlayerUI formatting", "",
2228
"Skull-Name-Format - The display name format",
2329
" for the player heads", "",
30+
"Skull-Custom-Model-Data - The custom model data for the",
31+
" player heads", "",
2432
"Size - the size of the UI (multiple of 9, between 18-54)", "",
2533
"Cache-Size - Size for the head cache", "",
2634
"Cache-Delay - Delay in ticks after the player", "",
@@ -33,6 +41,11 @@ public record PromptConfig(
3341
})
3442
String skullNameFormat,
3543

44+
@ConfigNode
45+
@NodeName("PlayerUI.Skull-Custom-Model-Data")
46+
@NodeDefault("0")
47+
int skullCustomModelData,
48+
3649
@ConfigNode
3750
@NodeName("PlayerUI.Size")
3851
@NodeDefault("54")
@@ -287,20 +300,28 @@ public record PromptConfig(
287300
String strSampleErrMessage
288301

289302
) implements AliasedSection {
290-
public String findIVRegexCheckInConfig(String alias) {
303+
private String findIVRegexCheckInConfig(String alias) {
291304
return getIVValue("Alias", alias, "Regex");
292305
}
293306

294-
public String getIVErrMessage(String alias) {
307+
private String getIVErrMessage(String alias) {
295308
return getIVValue("Alias", alias, "Err-Message");
296309
}
297310

298-
public String getIVErrMessageWithRegex(String regex) {
299-
return getIVValue("Regex", regex, "Err-Message");
311+
private String getIVValue(String key, String keyVal, String query) {
312+
return getInputValidationValue("Input-Validation", key, keyVal, query);
300313
}
301314

302-
public String getIVValue(String key, String keyVal, String query) {
303-
return getInputValidationValue("Input-Validation", key, keyVal, query);
315+
public InputValidator getInputValidator(String alias) {
316+
if (alias == null || alias.isBlank())
317+
return new NoopValidator();
318+
var isPlayer = Boolean.parseBoolean(getIVValue("Alias", alias, "Online-Player"));
319+
if (isPlayer)
320+
return new OnlinePlayerValidator(alias, getIVErrMessage(alias));
321+
var regex = findIVRegexCheckInConfig(alias);
322+
if (regex != null && !regex.isBlank())
323+
return new RegexValidator(alias, Pattern.compile(regex), getIVErrMessage(alias));
324+
return new NoopValidator();
304325
}
305326

306327
/**

src/main/java/com/cyr1en/commandprompter/hook/HookContainer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public void initHooks() {
2626
hook(CarbonChatHook.class);
2727
hook(VanishNoPacketHook.class);
2828
hook(PapiHook.class);
29+
hook(TownyHook.class);
30+
hook(LuckPermsHook.class);
2931
}
3032

3133
@Override
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.cyr1en.commandprompter.hook.hooks;
2+
3+
import com.cyr1en.commandprompter.prompt.ui.HeadCache;
4+
5+
/**
6+
* A hook that registers filters to the head cache.
7+
*/
8+
public interface FilterHook {
9+
10+
/**
11+
* Register filters to the head cache.
12+
*
13+
* @param headCache the head cache
14+
*/
15+
void registerFilters(HeadCache headCache);
16+
}

0 commit comments

Comments
 (0)