-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Introduce sections support with new Skript's API and support legacy…
… sections
- Loading branch information
Showing
7 changed files
with
254 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/main/java/fr/romitou/mongosk/skript/legacySections/SectLegacyMongoDocument.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package fr.romitou.mongosk.skript.legacySections; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.Since; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.skript.lang.Variable; | ||
import ch.njol.util.Kleenean; | ||
import fr.romitou.mongosk.LoggerHelper; | ||
import fr.romitou.mongosk.MongoSK; | ||
import fr.romitou.mongosk.MongoSection; | ||
import fr.romitou.mongosk.elements.MongoSKDocument; | ||
import org.bukkit.event.Event; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
@Name("Mongo section document") | ||
@Description("This section can be used to create documents quickly and easily. " + | ||
"To know how to use this section completely, see the \"Mongo section document value\" effect. " + | ||
"Please note: you must specify a variable that will be affected by this section, as in the example.") | ||
@Examples({"set {_doc} to a new mongo document with:", | ||
"\tmongo \"key\": \"value\"", | ||
"send {_doc}"}) | ||
@Since("2.1.0") | ||
public class SectLegacyMongoDocument extends MongoSection<MongoSKDocument> { | ||
|
||
public static MongoSKDocument mongoSKDocument = new MongoSKDocument(); | ||
|
||
static { | ||
if (!MongoSK.isUsingNewSections()) | ||
Skript.registerCondition( | ||
SectLegacyMongoDocument.class, | ||
"set %object% to [a] new mongo[(db|sk)] document with" | ||
); | ||
} | ||
|
||
@Override | ||
public boolean init(@Nonnull Expression<?>[] exprs, int matchedPattern, @Nonnull Kleenean isDelayed, @Nonnull SkriptParser.ParseResult parseResult) { | ||
|
||
if (isConditional()) { | ||
LoggerHelper.severe("You cannot use conditions with this section.", | ||
"Use the section like this: set {_variable} to a new mongo document with:"); | ||
return false; | ||
} | ||
|
||
Expression<?> variable = exprs[0]; | ||
if (!(variable instanceof Variable<?>)) { | ||
LoggerHelper.severe("In order to use this section, you must provide a variable as the first argument.", | ||
"Use the section like this: set {_variable} to a new mongo document with:"); | ||
return false; | ||
} | ||
|
||
loadSection(); | ||
setVariable((Variable<?>) variable); | ||
return true; | ||
} | ||
|
||
@Override | ||
protected MongoSKDocument provideValue() { | ||
return mongoSKDocument; | ||
} | ||
|
||
@Override | ||
protected void endSection() { | ||
mongoSKDocument = new MongoSKDocument(); | ||
} | ||
|
||
|
||
@Nonnull | ||
@Override | ||
public String toString(Event e, boolean debug) { | ||
return "set " + getVariable().toString(e, debug) + " to a new mongo document with"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.