mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
fancynpcs: Check if value contains blocked commands before adding action
This commit is contained in:
@@ -3,4 +3,4 @@
|
|||||||
- Improved logging
|
- Improved logging
|
||||||
- Fixed various bugs for the player-npcs fflag
|
- Fixed various bugs for the player-npcs fflag
|
||||||
- Added an optional flag to disable arm swinging in Npc#update
|
- Added an optional flag to disable arm swinging in Npc#update
|
||||||
- Added HologramManager#isLoaded method
|
- Added NpcManager#isLoaded method
|
||||||
@@ -1 +1 @@
|
|||||||
2.7.1.295
|
2.7.1.296
|
||||||
@@ -38,6 +38,11 @@ public enum ActionCMD {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (value != null && DisplayNameCMD.INSTANCE.hasBlockedCommands(value)) {
|
||||||
|
translator.translate("command_input_contains_blocked_command").send(sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (actionType.requiresValue() && (value == null || value.isEmpty())) {
|
if (actionType.requiresValue() && (value == null || value.isEmpty())) {
|
||||||
translator
|
translator
|
||||||
.translate("npc_action_requires_value")
|
.translate("npc_action_requires_value")
|
||||||
@@ -73,6 +78,11 @@ public enum ActionCMD {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (value != null && DisplayNameCMD.INSTANCE.hasBlockedCommands(value)) {
|
||||||
|
translator.translate("command_input_contains_blocked_command").send(sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (actionType.requiresValue() && (value == null || value.isEmpty())) {
|
if (actionType.requiresValue() && (value == null || value.isEmpty())) {
|
||||||
translator
|
translator
|
||||||
.translate("npc_action_requires_value")
|
.translate("npc_action_requires_value")
|
||||||
@@ -110,6 +120,11 @@ public enum ActionCMD {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (value != null && DisplayNameCMD.INSTANCE.hasBlockedCommands(value)) {
|
||||||
|
translator.translate("command_input_contains_blocked_command").send(sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (actionType.requiresValue() && (value == null || value.isEmpty())) {
|
if (actionType.requiresValue() && (value == null || value.isEmpty())) {
|
||||||
translator
|
translator
|
||||||
.translate("npc_action_requires_value")
|
.translate("npc_action_requires_value")
|
||||||
@@ -147,6 +162,11 @@ public enum ActionCMD {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (value != null && DisplayNameCMD.INSTANCE.hasBlockedCommands(value)) {
|
||||||
|
translator.translate("command_input_contains_blocked_command").send(sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (actionType.requiresValue() && (value == null || value.isEmpty())) {
|
if (actionType.requiresValue() && (value == null || value.isEmpty())) {
|
||||||
translator
|
translator
|
||||||
.translate("npc_action_requires_value")
|
.translate("npc_action_requires_value")
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import de.oliver.fancylib.translations.Translator;
|
|||||||
import de.oliver.fancynpcs.FancyNpcs;
|
import de.oliver.fancynpcs.FancyNpcs;
|
||||||
import de.oliver.fancynpcs.api.Npc;
|
import de.oliver.fancynpcs.api.Npc;
|
||||||
import de.oliver.fancynpcs.api.events.NpcModifyEvent;
|
import de.oliver.fancynpcs.api.events.NpcModifyEvent;
|
||||||
import org.lushplugins.chatcolorhandler.ModernChatColorHandler;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.ComponentIteratorType;
|
import net.kyori.adventure.text.ComponentIteratorType;
|
||||||
import net.kyori.adventure.text.event.ClickEvent;
|
import net.kyori.adventure.text.event.ClickEvent;
|
||||||
@@ -16,19 +15,18 @@ import org.incendo.cloud.annotations.Permission;
|
|||||||
import org.incendo.cloud.annotations.suggestion.Suggestions;
|
import org.incendo.cloud.annotations.suggestion.Suggestions;
|
||||||
import org.incendo.cloud.context.CommandContext;
|
import org.incendo.cloud.context.CommandContext;
|
||||||
import org.incendo.cloud.context.CommandInput;
|
import org.incendo.cloud.context.CommandInput;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.lushplugins.chatcolorhandler.ModernChatColorHandler;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public enum DisplayNameCMD {
|
public enum DisplayNameCMD {
|
||||||
INSTANCE; // SINGLETON
|
INSTANCE; // SINGLETON
|
||||||
|
|
||||||
private final Translator translator = FancyNpcs.getInstance().getTranslator();
|
|
||||||
|
|
||||||
// Storing in a static variable to avoid re-creating the array each time suggestion is requested.
|
// Storing in a static variable to avoid re-creating the array each time suggestion is requested.
|
||||||
private static final List<String> NONE_SUGGESTIONS = List.of("@none");
|
private static final List<String> NONE_SUGGESTIONS = List.of("@none");
|
||||||
|
private final Translator translator = FancyNpcs.getInstance().getTranslator();
|
||||||
|
|
||||||
@Command("npc displayname <npc> <name>")
|
@Command("npc displayname <npc> <name>")
|
||||||
@Permission("fancynpcs.command.npc.displayname")
|
@Permission("fancynpcs.command.npc.displayname")
|
||||||
@@ -66,8 +64,10 @@ public enum DisplayNameCMD {
|
|||||||
|
|
||||||
/* UTILITY METHODS */
|
/* UTILITY METHODS */
|
||||||
|
|
||||||
/** Returns {@code true} if specified component contains blocked command, {@code false} otherwise. */
|
/**
|
||||||
private boolean hasBlockedCommands(final @NotNull String message) {
|
* Returns {@code true} if specified component contains blocked command, {@code false} otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasBlockedCommands(final @NotNull String message) {
|
||||||
// Converting message to a Component.
|
// Converting message to a Component.
|
||||||
final Component component = ModernChatColorHandler.translate(message);
|
final Component component = ModernChatColorHandler.translate(message);
|
||||||
// Getting the list of all blocked commands.
|
// Getting the list of all blocked commands.
|
||||||
|
|||||||
Reference in New Issue
Block a user