Solved Why is my add-on not working

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

jaylawl

Active Member
Jan 29, 2017
173
31
0
33
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":

Java:
package com.jaylawl.hellofucks;

import ch.njol.skript.Skript;
import ch.njol.skript.lang.ExpressionType;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import com.jaylawl.hellofucks.elements.expressions.ExprBreak;

public class HelloFucks extends JavaPlugin {

    public HelloFucks() {}

    @Override
    public void onEnable() {
        if ((Bukkit.getPluginManager().getPlugin("Skript") != null) && (Skript.isAcceptRegistrations())) {
            getLogger().info("Skript found; enabling...");
            Skript.registerAddon(this);
            Skript.registerExpression(ExprBreak.class, String.class, ExpressionType.SIMPLE, "(br|break)");
        }
        else {
            getLogger().info("Skript was not found: disabling");
            Bukkit.getPluginManager().disablePlugin(this);
        }
    }

    @Override
    public void onDisable() {}

}

###################################################

package com.jaylawl.hellofucks.elements.expressions;

import org.bukkit.event.Event;

import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import javax.annotation.Nullable;

public class ExprBreak extends SimpleExpression<String> {

    @Override
    public Class<? extends String> getReturnType() {
        return null;
    }

    @Override
    public boolean isSingle() {
        return true;
    }

    @Override
    public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parser) {
        return false;
    }

    @Override
    public String toString(@Nullable Event event, boolean debug) {
        return null;
    }

    @Override
    @Nullable
    protected String[] get(Event event) {
        return new String[] {"fuck"};
        //return new String[] {System.getProperty("line.separator")};
    }

}

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:
 
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
 
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
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!
 
Last edited: