Solved Better detection for a certain string.

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Farid

Active Member
Feb 5, 2017
179
11
18
23
I was trying to block certain commands. I was having issues with on command event, however PlayerCommandPreProcessis amazing and fires really fast. I was wondering if there is a way to detect if there is an argument after the command is fired. This code below works however, it doesn't work when there is an argument into the command, for example /pl s would fire the command.
code_language.skript:
on script load:
    add "/sk" to {blockedcmd::*}
    add "/skript" to {blockedcmd::*}
    add "/bukkit:help" to {blockedcmd::*}
    add "/bukkit:ver" to {blockedcmd::*}
    add "/ver" to {blockedcmd::*}
    add "/version" to {blockedcmd::*}
    add "/about" to {blockedcmd::*}
    add "/bukkit:about" to {blockedcmd::*}
    add "//calc" to {blockedcmd::*}
    add "//eval" to {blockedcmd::*}
    add "//calculate" to {blockedcmd::*}
    add "//evaluate" to {blockedcmd::*}
    add "/pl" to {blockedcmd::*}
    add "/plugins" to {blockedcmd::*}
    add "/bukkit:pl" to {blockedcmd::*}
    add "/?" to {blockedcmd::*}
    add "/bukkit:?" to {blockedcmd::*}

on "org.bukkit.event.player.PlayerCommandPreprocessEvent":
    loop {blockedcmd::*}:
        if loop-value.contains(event.getMessage().toLowerCase().toString()) = true:
            if getGroup(event.getPlayer()) isn't "Owner" or "Developer":
                send "&c&l(!) &eCommand was not found!" to event.getPlayer()
                event.setCancelled(true)
 
code_language.skript:
on "org.bukkit.event.player.PlayerCommandPreprocessEvent":
    if {blockedcmd::*} contains first element of event.getMessage() split at " ":
        if getGroup(event.getPlayer()) isn't "Owner" or "Developer":
            send "&c&l(!) &eCommand was not found!" to event.getPlayer()
            cancel event
 
code_language.skript:
on "org.bukkit.event.player.PlayerCommandPreprocessEvent":
    if {blockedcmd::*} contains first element of event.getMessage() split at " ":
        if getGroup(event.getPlayer()) isn't "Owner" or "Developer":
            send "&c&l(!) &eCommand was not found!" to event.getPlayer()
            cancel event

Thanks for the response! The code didn't seem to work, so I debugged and found out that it's not going through, hence I'm not getting the message 1 at all.


code_language.skript:
on "org.bukkit.event.player.PlayerCommandPreprocessEvent":
    if {blockedcmd::*} contains first element of event.getMessage() split at " ":
        send "1" to event.getPlayer()
        if getGroups(event.getPlayer()) doesn't contain "Owner" or "Developer":
            send "2" to event.getPlayer()
            send "&c&l(!) &eCommand was not found!" to event.getPlayer()
            event.setCancelled(true)
 
this is what i tested with and it works fine
code_language.skript:
on "org.bukkit.event.player.PlayerCommandPreprocessEvent":
    set {blockedcmd::*} to "/test"
    if {blockedcmd::*} contains first element of event.getMessage() split at " ":
        if getGroup(event.getPlayer()) isn't "Owner" or "Developer":
            send "&c&l(!) &eCommand was not found!" to event.getPlayer()
            cancel event
 
this is what i tested with and it works fine
code_language.skript:
on "org.bukkit.event.player.PlayerCommandPreprocessEvent":
    set {blockedcmd::*} to "/test"
    if {blockedcmd::*} contains first element of event.getMessage() split at " ":
        if getGroup(event.getPlayer()) isn't "Owner" or "Developer":
            send "&c&l(!) &eCommand was not found!" to event.getPlayer()
            cancel event

That didn't work, but this did.


code_language.skript:
on "org.bukkit.event.player.PlayerCommandPreprocessEvent":
    set {_s::*} to event.getMessage() split at " "
    loop {_s::*}:
        if contains({blockedcmd::*}, loop-value) = true:
            if getGroups(event.getPlayer()) doesn't contain "Owner" or "Developer":
                send "&c&l(!) &eCommand was not found!" to event.getPlayer()
                event.setCancelled(true)

code_language.skript:
function contains(list: objects, check: object) :: boolean:
    loop {_list::*}:
        if loop-value is {_check}:
            return true
    return false
 
Status
Not open for further replies.