Discord Thread Cannot loop java list, array, dict, etc with skript-reflect

  • 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!

This thread came from the skUnity Discord. You can't reply to it here but if you join the skUnity Discord, you'll be able to post a reply there. The thread link is part of the thread's message.
Status
Not open for further replies.

skUnity Discord

Site Manager
Aug 5, 2023
12,755
0
0
The skUnity Discord
discord.gg
code_language.skript:
import:
    org.bukkit.Bukkit
    java.util.regex.Pattern

function getshortprefix(prefix: text) :: text:
    {_pattern} = Pattern.compile("&[0-9a-fA-Fk-or]")
    {_matcher} = {_pattern}.matcher({_prefix})
    loop {_matcher}.find(): #Skript says, this is a single value, so it cant loop
        {_lastcolorcode} = {_matcher}.group()
    return {_lastcolorcode}

Posted by: Sussy Man from the skUnity Discord. View the thread on skUnity Discord here
 
skript version: dev37c
hey ducky, what's the problem in this code:
code_language.skript:
import:
    org.bukkit.Bukkit
    java.util.regex.Pattern

function getshortprefix(prefix: text) :: text:
    {_pattern} = Pattern.compile("&[0-9a-fA-Fk-or]")
    {_matcher} = {_pattern}.matcher({_prefix})
    loop {_matcher}.find(): #Skript says, this is a single value, so it cant loop
        {_lastcolorcode} = {_matcher}.group()
    return {_lastcolorcode}
<@297061196060950531>

Posted by: Sussy Man from the skUnity Discord.
 
1.
{_var} = something is not assignment, it's a condition that checks for equality; use set {_var} to something

2. The org.bukkit.Bukkit import is useless
3. looping Matcher#find() makes no sense; did you mean
while Matcher.find()
?
4. Using Regex for this seems a bit over the top. Have you considered starting from the end of the string and looping all characters backwards until you find a colour code? Or https://hub.spigotmc.org/javadocs/spigot/org/bukkit/ChatColor.html#getLastColors(java.lang.String) which does the exact same thing?
5. Why are you using 2.2-dev37c? It's incredibly old. If you are using 1.8, consider Matocolotoe's fork
And, for future reference:
6. To convert a Java array or Collection/Iterable/blah blah, you can do
loop ...{_hello this is an array}: (the ...
convert it to a Skript list)

Posted by: mr_darth from the skUnity Discord.
 
You dont need 6 since you arent dealing with an actual collection are you
Also you only import
org.bukkit.ChatColor


Posted by: mr_darth from the skUnity Discord.
 
Status
Not open for further replies.