-
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.
✨ Introducing Mongo database and collection drops
- Loading branch information
Showing
3 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/main/java/fr/romitou/mongosk/skript/effects/EffDropMongoCollection.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,52 @@ | ||
package fr.romitou.mongosk.skript.effects; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.lang.Effect; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.util.Kleenean; | ||
import fr.romitou.mongosk.MongoSK; | ||
import fr.romitou.mongosk.SubscriberHelpers; | ||
import fr.romitou.mongosk.elements.MongoSKCollection; | ||
import org.bukkit.event.Event; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
public class EffDropMongoCollection extends Effect { | ||
|
||
private final static Boolean CAN_DROP = MongoSK.getConfiguration().getBoolean("allow-drop.collection", false); | ||
|
||
static { | ||
if (CAN_DROP) | ||
Skript.registerEffect( | ||
EffDropMongoCollection.class, | ||
"drop [the] mongo[(sk|db)] collection %mongoskcollection%" | ||
); | ||
} | ||
|
||
private Expression<MongoSKCollection> exprMongoSKCollection; | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, @Nonnull Kleenean isDelayed, @Nonnull SkriptParser.ParseResult parseResult) { | ||
exprMongoSKCollection = (Expression<MongoSKCollection>) exprs[0]; | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void execute(@Nonnull Event e) { | ||
MongoSKCollection mongoSKCollection = exprMongoSKCollection.getSingle(e); | ||
if (mongoSKCollection == null) | ||
return; | ||
SubscriberHelpers.ObservableSubscriber<Void> voidSubscriber = new SubscriberHelpers.OperationSubscriber<>(); | ||
mongoSKCollection.getMongoCollection().drop().subscribe(voidSubscriber); | ||
voidSubscriber.await(); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String toString(@Nullable Event e, boolean debug) { | ||
return "drop the mongo collection " + exprMongoSKCollection.toString(e, debug); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/fr/romitou/mongosk/skript/effects/EffDropMongoDatabase.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,52 @@ | ||
package fr.romitou.mongosk.skript.effects; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.lang.Effect; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.util.Kleenean; | ||
import fr.romitou.mongosk.MongoSK; | ||
import fr.romitou.mongosk.SubscriberHelpers; | ||
import fr.romitou.mongosk.elements.MongoSKDatabase; | ||
import org.bukkit.event.Event; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
public class EffDropMongoDatabase extends Effect { | ||
|
||
private final static Boolean CAN_DROP = MongoSK.getConfiguration().getBoolean("allow-drop.database", false); | ||
|
||
static { | ||
if (CAN_DROP) | ||
Skript.registerEffect( | ||
EffDropMongoDatabase.class, | ||
"drop [the] mongo[(sk|db)] database %mongoskdatabase%" | ||
); | ||
} | ||
|
||
private Expression<MongoSKDatabase> exprMongoSKDatabase; | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, @Nonnull Kleenean isDelayed, @Nonnull SkriptParser.ParseResult parseResult) { | ||
exprMongoSKDatabase = (Expression<MongoSKDatabase>) exprs[0]; | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void execute(@Nonnull Event e) { | ||
MongoSKDatabase mongoSKDatabase = exprMongoSKDatabase.getSingle(e); | ||
if (mongoSKDatabase == null) | ||
return; | ||
SubscriberHelpers.ObservableSubscriber<Void> voidSubscriber = new SubscriberHelpers.OperationSubscriber<>(); | ||
mongoSKDatabase.getMongoDatabase().drop().subscribe(voidSubscriber); | ||
voidSubscriber.await(); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String toString(@Nullable Event e, boolean debug) { | ||
return "drop the mongo database " + exprMongoSKDatabase.toString(e, debug); | ||
} | ||
} |
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