1. 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!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Why is my add-on not working

Discussion in 'Java' started by jaylawl, Aug 20, 2018.

  1. jaylawl

    jaylawl Active Member

    Joined:
    Jan 29, 2017
    Messages:
    173
    Likes Received:
    31
    I'm taking my first steps in writing actual java. Messing around with skript-mirror long enough gave me the balls to try, good times. This code works, there are no errors, everything compiles fine. But the expression i added is not registered ingame - skript says "can't understand this expression":

    Code (Java):
    1. package com.jaylawl.hellofucks;
    2.  
    3. import ch.njol.skript.Skript;
    4. import ch.njol.skript.lang.ExpressionType;
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7. import com.jaylawl.hellofucks.elements.expressions.ExprBreak;
    8.  
    9. public class HelloFucks extends JavaPlugin {
    10.  
    11.     public HelloFucks() {}
    12.  
    13.     @Override
    14.     public void onEnable() {
    15.         if ((Bukkit.getPluginManager().getPlugin("Skript") != null) && (Skript.isAcceptRegistrations())) {
    16.             getLogger().info("Skript found; enabling...");
    17.             Skript.registerAddon(this);
    18.             Skript.registerExpression(ExprBreak.class, String.class, ExpressionType.SIMPLE, "(br|break)");
    19.         }
    20.         else {
    21.             getLogger().info("Skript was not found: disabling");
    22.             Bukkit.getPluginManager().disablePlugin(this);
    23.         }
    24.     }
    25.  
    26.     @Override
    27.     public void onDisable() {}
    28.  
    29. }
    30.  
    31. ###################################################
    32.  
    33. package com.jaylawl.hellofucks.elements.expressions;
    34.  
    35. import org.bukkit.event.Event;
    36.  
    37. import ch.njol.skript.lang.Expression;
    38. import ch.njol.skript.lang.SkriptParser.ParseResult;
    39. import ch.njol.skript.lang.util.SimpleExpression;
    40. import ch.njol.util.Kleenean;
    41. import javax.annotation.Nullable;
    42.  
    43. public class ExprBreak extends SimpleExpression<String> {
    44.  
    45.     @Override
    46.     public Class<? extends String> getReturnType() {
    47.         return null;
    48.     }
    49.  
    50.     @Override
    51.     public boolean isSingle() {
    52.         return true;
    53.     }
    54.  
    55.     @Override
    56.     public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parser) {
    57.         return false;
    58.     }
    59.  
    60.     @Override
    61.     public String toString(@Nullable Event event, boolean debug) {
    62.         return null;
    63.     }
    64.  
    65.     @Override
    66.     @Nullable
    67.     protected String[] get(Event event) {
    68.         return new String[] {"fuck"};
    69.         //return new String[] {System.getProperty("line.separator")};
    70.     }
    71.  
    72. }
    73.  
    Java is confusing enough for beginners - so please, emphasize on what i'm doing wrong, not on how everything else could be more optimal :emoji_grinning:
     
  2. Best Answer:
    Post #2 by Donut, Aug 20, 2018
  3. Donut

    Donut Well-Known Member

    Joined:
    Mar 27, 2017
    Messages:
    1,340
    Likes Received:
    176
    Medals:
    looks like you stopped after a few paragraphs of lime's expression tutorial... the null and false returns were just placeholders until he explained each method
     
    • Useful Useful x 1
  4. jaylawl

    jaylawl Active Member

    Joined:
    Jan 29, 2017
    Messages:
    173
    Likes Received:
    31
    That makes sense, i was doing a weird mixture between trying everything from scratch by reading existing code - and then i "gave up" and went into lime's tutorial. I'm gonna go back to that and find what i missed, thank you

    /edit:
    Went back to the steps i accidentally skipped -now it works!
     
    #3 jaylawl, Aug 20, 2018
    Last edited: Aug 20, 2018

Share This Page

Loading...