-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
283 additions
and
28 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/info/itsthesky/skriptstorage/api/queue/Queue.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,30 @@ | ||
package info.itsthesky.skriptstorage.api.queue; | ||
|
||
import de.leonhard.storage.internal.FlatFile; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
public class Queue { | ||
|
||
private final String path; | ||
private final List<Consumer<FlatFile>> consumers; | ||
|
||
public String getPath() { | ||
return path; | ||
} | ||
|
||
public List<Consumer<FlatFile>> getConsumers() { | ||
return consumers; | ||
} | ||
|
||
public Queue(String path) { | ||
this.path = path; | ||
this.consumers = new ArrayList<>(); | ||
} | ||
|
||
public void add(Consumer<FlatFile> queue) { | ||
consumers.add(queue); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/info/itsthesky/skriptstorage/api/queue/QueueManager.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,25 @@ | ||
package info.itsthesky.skriptstorage.api.queue; | ||
|
||
import java.util.HashMap; | ||
|
||
public class QueueManager { | ||
|
||
private static final HashMap<String, Queue> QUEUES = new HashMap<>(); | ||
|
||
public static void addQueue(Queue queue) { | ||
QUEUES.put(queue.getPath(), queue); | ||
} | ||
|
||
public static boolean queueExist(String path) { | ||
return QUEUES.containsKey(path); | ||
} | ||
|
||
public static Queue parse(String path) { | ||
return QUEUES.getOrDefault(path, null); | ||
} | ||
|
||
public static void remove(String path) { | ||
QUEUES.remove(path); | ||
} | ||
|
||
} |
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
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
65 changes: 65 additions & 0 deletions
65
src/main/java/info/itsthesky/skriptstorage/core/elements/StartQueue.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,65 @@ | ||
package info.itsthesky.skriptstorage.core.elements; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.config.Node; | ||
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.Effect; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.skript.log.SkriptLogger; | ||
import ch.njol.util.Kleenean; | ||
import info.itsthesky.skriptstorage.api.queue.Queue; | ||
import info.itsthesky.skriptstorage.api.queue.QueueManager; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
|
||
@Name("Start Queue") | ||
@Description({"Start a new queue for a specific file path.", | ||
"Every change made with that path will be queued, and not saved directly.", | ||
"You will either need to save the queue (make every save) or clear it (cancel every changes) to return to a normal state.", | ||
"This system is recommended when you are managing a huge quantity of data in a single time."}) | ||
@Examples({"start queue for \"config\"", | ||
"enable the queue for \"plugins/test.json\""}) | ||
@Since("1.3.0") | ||
public class StartQueue extends Effect { | ||
|
||
static { | ||
Skript.registerEffect( | ||
StartQueue.class, | ||
"(enable|start) [the] queue for [the] [path] %string%" | ||
); | ||
} | ||
|
||
private Expression<String> exprPath; | ||
private Node node; | ||
|
||
@Override | ||
protected void execute(@NotNull Event e) { | ||
final String path = CreateShortcut.parse(exprPath.getSingle(e), node); | ||
if (path == null) | ||
return; | ||
if (QueueManager.queueExist(path)) { | ||
Skript.error("Unable to create a queue for '"+path+"' since there's already one started."); | ||
return; | ||
} | ||
final Queue queue = new Queue(path); | ||
QueueManager.addQueue(queue); | ||
} | ||
|
||
@Override | ||
public @NotNull String toString(Event e, boolean debug) { | ||
return "start the queue for " + exprPath.toString(e, debug); | ||
} | ||
|
||
@Override | ||
public boolean init(Expression<?> @NotNull [] exprs, int matchedPattern, @NotNull Kleenean isDelayed, SkriptParser.@NotNull ParseResult parseResult) { | ||
exprPath = (Expression<String>) exprs[0]; | ||
node = SkriptLogger.getNode(); | ||
return true; | ||
} | ||
} |
Oops, something went wrong.