Small API changes
This commit is contained in:
parent
3f5d0de26e
commit
3963d17c71
7 changed files with 99 additions and 115 deletions
|
@ -1,10 +1,9 @@
|
||||||
package tech.sbdevelopment.showcontrol;
|
package tech.sbdevelopment.showcontrol;
|
||||||
|
|
||||||
import co.aikar.commands.PaperCommandManager;
|
import co.aikar.commands.PaperCommandManager;
|
||||||
import tech.sbdevelopment.showcontrol.api.ShowAPI;
|
|
||||||
import tech.sbdevelopment.showcontrol.commands.ShowCMD;
|
import tech.sbdevelopment.showcontrol.commands.ShowCMD;
|
||||||
import tech.sbdevelopment.showcontrol.data.DataStorage;
|
import tech.sbdevelopment.showcontrol.data.DataStorage;
|
||||||
import tech.sbdevelopment.showcontrol.data.Shows;
|
import tech.sbdevelopment.showcontrol.api.SCAPI;
|
||||||
import tech.sbdevelopment.showcontrol.utils.inventories.Inventory;
|
import tech.sbdevelopment.showcontrol.utils.inventories.Inventory;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
@ -25,14 +24,14 @@ public final class ShowControlPlugin extends JavaPlugin {
|
||||||
final PaperCommandManager commandManager = new PaperCommandManager(this);
|
final PaperCommandManager commandManager = new PaperCommandManager(this);
|
||||||
commandManager.enableUnstableAPI("help");
|
commandManager.enableUnstableAPI("help");
|
||||||
commandManager.registerCommand(new ShowCMD());
|
commandManager.registerCommand(new ShowCMD());
|
||||||
commandManager.getCommandCompletions().registerCompletion("showname", c -> Shows.getShowsMap().keySet());
|
commandManager.getCommandCompletions().registerCompletion("showname", c -> SCAPI.getShowsMap().keySet());
|
||||||
commandManager.getCommandCompletions().registerCompletion("showtype", c -> ShowAPI.getTriggers().keySet());
|
commandManager.getCommandCompletions().registerCompletion("showtype", c -> SCAPI.getTriggers().keySet());
|
||||||
|
|
||||||
getLogger().info("Loading GUI manageer...");
|
getLogger().info("Loading GUI manageer...");
|
||||||
Inventory.init(this);
|
Inventory.init(this);
|
||||||
|
|
||||||
getLogger().info("Loading default triggers...");
|
getLogger().info("Loading default triggers...");
|
||||||
ShowAPI.index(ShowControlPlugin.class, "tech.sbdevelopment.showcontrol.api.triggers.impl");
|
SCAPI.index(ShowControlPlugin.class, "tech.sbdevelopment.showcontrol.api.triggers.impl");
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(this, DataStorage::load, 1L); //Load 1 tick later, because of multi world
|
Bukkit.getScheduler().runTaskLater(this, DataStorage::load, 1L); //Load 1 tick later, because of multi world
|
||||||
|
|
||||||
|
@ -44,7 +43,7 @@ public final class ShowControlPlugin extends JavaPlugin {
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
getLogger().info("Saving data...");
|
getLogger().info("Saving data...");
|
||||||
DataStorage.save();
|
DataStorage.save();
|
||||||
Shows.getShowsMap().values().forEach(show -> show.forEach(showCue -> showCue.getData().remove()));
|
SCAPI.getShowsMap().values().forEach(show -> show.forEach(showCue -> showCue.getData().remove()));
|
||||||
|
|
||||||
getLogger().info("Plugin disabled!");
|
getLogger().info("Plugin disabled!");
|
||||||
instance = null;
|
instance = null;
|
||||||
|
|
|
@ -1,26 +1,34 @@
|
||||||
package tech.sbdevelopment.showcontrol.api;
|
package tech.sbdevelopment.showcontrol.api;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import tech.sbdevelopment.showcontrol.ShowControlPlugin;
|
|
||||||
import tech.sbdevelopment.showcontrol.api.exceptions.InvalidTriggerException;
|
|
||||||
import tech.sbdevelopment.showcontrol.api.exceptions.TooFewArgumentsException;
|
|
||||||
import tech.sbdevelopment.showcontrol.api.triggers.Trigger;
|
|
||||||
import tech.sbdevelopment.showcontrol.api.triggers.TriggerIdentifier;
|
|
||||||
import org.reflections.Reflections;
|
import org.reflections.Reflections;
|
||||||
import org.reflections.scanners.Scanners;
|
import org.reflections.scanners.Scanners;
|
||||||
import org.reflections.util.ClasspathHelper;
|
import org.reflections.util.ClasspathHelper;
|
||||||
import org.reflections.util.ConfigurationBuilder;
|
import org.reflections.util.ConfigurationBuilder;
|
||||||
import org.reflections.util.FilterBuilder;
|
import org.reflections.util.FilterBuilder;
|
||||||
|
import tech.sbdevelopment.showcontrol.ShowControlPlugin;
|
||||||
|
import tech.sbdevelopment.showcontrol.api.exceptions.InvalidTriggerException;
|
||||||
|
import tech.sbdevelopment.showcontrol.api.exceptions.TooFewArgumentsException;
|
||||||
|
import tech.sbdevelopment.showcontrol.api.points.ShowCuePoint;
|
||||||
|
import tech.sbdevelopment.showcontrol.api.triggers.Trigger;
|
||||||
|
import tech.sbdevelopment.showcontrol.api.triggers.TriggerIdentifier;
|
||||||
|
import tech.sbdevelopment.showcontrol.data.DataStorage;
|
||||||
|
import tech.sbdevelopment.showcontrol.utils.YamlFile;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.Map;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.Set;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class ShowAPI {
|
public class SCAPI {
|
||||||
@Getter
|
@Getter
|
||||||
private static final Map<String, Class<? extends Trigger>> triggers = new HashMap<>();
|
private static final Map<String, Class<? extends Trigger>> triggers = new HashMap<>();
|
||||||
|
@Getter
|
||||||
|
private static final HashMap<String, List<ShowCuePoint>> showsMap = new HashMap<>();
|
||||||
|
private static final HashMap<String, ScheduledExecutorService> showTimers = new HashMap<>();
|
||||||
|
|
||||||
public static void index(Class<?> clazz, String... packages) {
|
public static void index(Class<?> clazz, String... packages) {
|
||||||
ShowControlPlugin.getInstance().getLogger().info("Indexing triggers for starting point " + clazz.getSimpleName() + "...");
|
ShowControlPlugin.getInstance().getLogger().info("Indexing triggers for starting point " + clazz.getSimpleName() + "...");
|
||||||
|
@ -59,4 +67,59 @@ public class ShowAPI {
|
||||||
throw new TooFewArgumentsException(identifier.argDesc());
|
throw new TooFewArgumentsException(identifier.argDesc());
|
||||||
return ctor.newInstance(new Object[]{dataSplitterNew});
|
return ctor.newInstance(new Object[]{dataSplitterNew});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void create(String name) {
|
||||||
|
showsMap.put(name, new ArrayList<>());
|
||||||
|
DataStorage.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void delete(String name) {
|
||||||
|
showsMap.remove(name);
|
||||||
|
|
||||||
|
File data = new File(ShowControlPlugin.getInstance().getDataFolder(), "data/" + name + ".yml");
|
||||||
|
data.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean exists(String name) {
|
||||||
|
return showsMap.containsKey(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<ShowCuePoint> getPoints(String name) {
|
||||||
|
if (!exists(name)) return new ArrayList<>();
|
||||||
|
return showsMap.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addPoint(String name, Long time, Trigger data) {
|
||||||
|
if (!exists(name)) return;
|
||||||
|
getPoints(name).add(new ShowCuePoint(time, data));
|
||||||
|
DataStorage.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removePoint(String name, ShowCuePoint point) {
|
||||||
|
if (!exists(name)) return;
|
||||||
|
|
||||||
|
point.getData().remove();
|
||||||
|
showsMap.get(name).remove(point);
|
||||||
|
|
||||||
|
YamlFile data = DataStorage.getFiles().get(name);
|
||||||
|
|
||||||
|
data.getFile().set(point.getCueID().toString(), null);
|
||||||
|
data.saveFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void startShow(String name) {
|
||||||
|
if (!exists(name)) return;
|
||||||
|
ScheduledExecutorService showTimer = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
for (ShowCuePoint point : getPoints(name)) {
|
||||||
|
showTimer.schedule(() -> Bukkit.getScheduler().runTask(ShowControlPlugin.getInstance(), () -> point.getData().trigger()), point.getTime(), TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
showTimers.put(name, showTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void cancelShow(String name) {
|
||||||
|
if (!exists(name)) return;
|
||||||
|
if (!showTimers.containsKey(name)) return;
|
||||||
|
ScheduledExecutorService showTimer = showTimers.get(name);
|
||||||
|
showTimer.shutdownNow();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -3,10 +3,9 @@ package tech.sbdevelopment.showcontrol.commands;
|
||||||
import co.aikar.commands.BaseCommand;
|
import co.aikar.commands.BaseCommand;
|
||||||
import co.aikar.commands.annotation.*;
|
import co.aikar.commands.annotation.*;
|
||||||
import tech.sbdevelopment.showcontrol.api.exceptions.InvalidTriggerException;
|
import tech.sbdevelopment.showcontrol.api.exceptions.InvalidTriggerException;
|
||||||
import tech.sbdevelopment.showcontrol.api.ShowAPI;
|
|
||||||
import tech.sbdevelopment.showcontrol.api.exceptions.TooFewArgumentsException;
|
import tech.sbdevelopment.showcontrol.api.exceptions.TooFewArgumentsException;
|
||||||
import tech.sbdevelopment.showcontrol.api.triggers.Trigger;
|
import tech.sbdevelopment.showcontrol.api.triggers.Trigger;
|
||||||
import tech.sbdevelopment.showcontrol.data.Shows;
|
import tech.sbdevelopment.showcontrol.api.SCAPI;
|
||||||
import tech.sbdevelopment.showcontrol.gui.ShowCueGUI;
|
import tech.sbdevelopment.showcontrol.gui.ShowCueGUI;
|
||||||
import tech.sbdevelopment.showcontrol.utils.TimeUtil;
|
import tech.sbdevelopment.showcontrol.utils.TimeUtil;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
@ -19,12 +18,12 @@ public class ShowCMD extends BaseCommand {
|
||||||
@Subcommand("create")
|
@Subcommand("create")
|
||||||
@Description("")
|
@Description("")
|
||||||
public void onCreate(CommandSender sender, @Single String name) {
|
public void onCreate(CommandSender sender, @Single String name) {
|
||||||
if (Shows.exists(name)) {
|
if (SCAPI.exists(name)) {
|
||||||
sender.sendMessage(ChatColor.RED + "That show already exists.");
|
sender.sendMessage(ChatColor.RED + "That show already exists.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shows.create(name);
|
SCAPI.create(name);
|
||||||
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "The show " + ChatColor.WHITE + name + ChatColor.GREEN + " has been created!");
|
sender.sendMessage(ChatColor.GREEN + "The show " + ChatColor.WHITE + name + ChatColor.GREEN + " has been created!");
|
||||||
}
|
}
|
||||||
|
@ -33,12 +32,12 @@ public class ShowCMD extends BaseCommand {
|
||||||
@Description("")
|
@Description("")
|
||||||
@CommandCompletion("@showname")
|
@CommandCompletion("@showname")
|
||||||
public void onDelete(CommandSender sender, @Single String name) {
|
public void onDelete(CommandSender sender, @Single String name) {
|
||||||
if (!Shows.exists(name)) {
|
if (!SCAPI.exists(name)) {
|
||||||
sender.sendMessage(ChatColor.RED + "That show doesn't exists.");
|
sender.sendMessage(ChatColor.RED + "That show doesn't exists.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shows.delete(name);
|
SCAPI.delete(name);
|
||||||
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "The show " + ChatColor.WHITE + name + ChatColor.GREEN + " has been removed!");
|
sender.sendMessage(ChatColor.GREEN + "The show " + ChatColor.WHITE + name + ChatColor.GREEN + " has been removed!");
|
||||||
}
|
}
|
||||||
|
@ -47,7 +46,7 @@ public class ShowCMD extends BaseCommand {
|
||||||
@Description("")
|
@Description("")
|
||||||
@CommandCompletion("@showname @empty @showtype @empty")
|
@CommandCompletion("@showname @empty @showtype @empty")
|
||||||
public void onAdd(CommandSender sender, String name, String time, String args) {
|
public void onAdd(CommandSender sender, String name, String time, String args) {
|
||||||
if (!Shows.exists(name)) {
|
if (!SCAPI.exists(name)) {
|
||||||
sender.sendMessage(ChatColor.RED + "That show doesn't exists.");
|
sender.sendMessage(ChatColor.RED + "That show doesn't exists.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -62,7 +61,7 @@ public class ShowCMD extends BaseCommand {
|
||||||
|
|
||||||
Trigger data;
|
Trigger data;
|
||||||
try {
|
try {
|
||||||
data = ShowAPI.getTrigger(args);
|
data = SCAPI.getTrigger(args);
|
||||||
} catch (ReflectiveOperationException e) {
|
} catch (ReflectiveOperationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
sender.sendMessage(ChatColor.RED + "Something went wrong! Please ask a server admin.");
|
sender.sendMessage(ChatColor.RED + "Something went wrong! Please ask a server admin.");
|
||||||
|
@ -78,7 +77,7 @@ public class ShowCMD extends BaseCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shows.addPoint(name, timeMilli, data);
|
SCAPI.addPoint(name, timeMilli, data);
|
||||||
sender.sendMessage(ChatColor.GREEN + "The show " + ChatColor.WHITE + name + ChatColor.GREEN + " now contains an extra point!");
|
sender.sendMessage(ChatColor.GREEN + "The show " + ChatColor.WHITE + name + ChatColor.GREEN + " now contains an extra point!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,12 +85,12 @@ public class ShowCMD extends BaseCommand {
|
||||||
@Description("")
|
@Description("")
|
||||||
@CommandCompletion("@showname")
|
@CommandCompletion("@showname")
|
||||||
public void onStart(CommandSender sender, @Single String name) {
|
public void onStart(CommandSender sender, @Single String name) {
|
||||||
if (!Shows.exists(name)) {
|
if (!SCAPI.exists(name)) {
|
||||||
sender.sendMessage(ChatColor.RED + "That show doesn't exists.");
|
sender.sendMessage(ChatColor.RED + "That show doesn't exists.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shows.startShow(name);
|
SCAPI.startShow(name);
|
||||||
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "The show " + ChatColor.WHITE + name + ChatColor.GREEN + " has been started!");
|
sender.sendMessage(ChatColor.GREEN + "The show " + ChatColor.WHITE + name + ChatColor.GREEN + " has been started!");
|
||||||
}
|
}
|
||||||
|
@ -100,12 +99,12 @@ public class ShowCMD extends BaseCommand {
|
||||||
@Description("")
|
@Description("")
|
||||||
@CommandCompletion("@showname")
|
@CommandCompletion("@showname")
|
||||||
public void onCancel(CommandSender sender, @Single String name) {
|
public void onCancel(CommandSender sender, @Single String name) {
|
||||||
if (!Shows.exists(name)) {
|
if (!SCAPI.exists(name)) {
|
||||||
sender.sendMessage(ChatColor.RED + "That show doesn't exists.");
|
sender.sendMessage(ChatColor.RED + "That show doesn't exists.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shows.cancelShow(name);
|
SCAPI.cancelShow(name);
|
||||||
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "The show " + ChatColor.WHITE + name + ChatColor.GREEN + " has been stopped!");
|
sender.sendMessage(ChatColor.GREEN + "The show " + ChatColor.WHITE + name + ChatColor.GREEN + " has been stopped!");
|
||||||
}
|
}
|
||||||
|
@ -114,7 +113,7 @@ public class ShowCMD extends BaseCommand {
|
||||||
@Description("")
|
@Description("")
|
||||||
@CommandCompletion("@showname")
|
@CommandCompletion("@showname")
|
||||||
public void onGUI(Player sender, @Single String name) {
|
public void onGUI(Player sender, @Single String name) {
|
||||||
if (!Shows.exists(name)) {
|
if (!SCAPI.exists(name)) {
|
||||||
sender.sendMessage(ChatColor.RED + "That show doesn't exists.");
|
sender.sendMessage(ChatColor.RED + "That show doesn't exists.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package tech.sbdevelopment.showcontrol.data;
|
package tech.sbdevelopment.showcontrol.data;
|
||||||
|
|
||||||
import tech.sbdevelopment.showcontrol.ShowControlPlugin;
|
import tech.sbdevelopment.showcontrol.ShowControlPlugin;
|
||||||
|
import tech.sbdevelopment.showcontrol.api.SCAPI;
|
||||||
import tech.sbdevelopment.showcontrol.api.exceptions.InvalidTriggerException;
|
import tech.sbdevelopment.showcontrol.api.exceptions.InvalidTriggerException;
|
||||||
import tech.sbdevelopment.showcontrol.api.ShowAPI;
|
|
||||||
import tech.sbdevelopment.showcontrol.api.points.ShowCuePoint;
|
import tech.sbdevelopment.showcontrol.api.points.ShowCuePoint;
|
||||||
import tech.sbdevelopment.showcontrol.api.exceptions.TooFewArgumentsException;
|
import tech.sbdevelopment.showcontrol.api.exceptions.TooFewArgumentsException;
|
||||||
import tech.sbdevelopment.showcontrol.api.triggers.Trigger;
|
import tech.sbdevelopment.showcontrol.api.triggers.Trigger;
|
||||||
|
@ -36,7 +36,7 @@ public class DataStorage {
|
||||||
UUID cueID = UUID.fromString(id);
|
UUID cueID = UUID.fromString(id);
|
||||||
Trigger data;
|
Trigger data;
|
||||||
try {
|
try {
|
||||||
data = ShowAPI.getTrigger(showConfig.getFile().getString(id + ".Type") + " " + showConfig.getFile().getString(id + ".Data"));
|
data = SCAPI.getTrigger(showConfig.getFile().getString(id + ".Type") + " " + showConfig.getFile().getString(id + ".Data"));
|
||||||
} catch (ReflectiveOperationException | InvalidTriggerException | TooFewArgumentsException e) {
|
} catch (ReflectiveOperationException | InvalidTriggerException | TooFewArgumentsException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
|
@ -45,12 +45,12 @@ public class DataStorage {
|
||||||
|
|
||||||
cues.add(new ShowCuePoint(cueID, time, data));
|
cues.add(new ShowCuePoint(cueID, time, data));
|
||||||
}
|
}
|
||||||
Shows.getShowsMap().put(showID, cues);
|
SCAPI.getShowsMap().put(showID, cues);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void save() {
|
public static void save() {
|
||||||
for (Map.Entry<String, List<ShowCuePoint>> entry : Shows.getShowsMap().entrySet()) {
|
for (Map.Entry<String, List<ShowCuePoint>> entry : SCAPI.getShowsMap().entrySet()) {
|
||||||
YamlFile file = files.containsKey(entry.getKey()) ? files.get(entry.getKey()) : new YamlFile(ShowControlPlugin.getInstance(), "data/" + entry.getKey());
|
YamlFile file = files.containsKey(entry.getKey()) ? files.get(entry.getKey()) : new YamlFile(ShowControlPlugin.getInstance(), "data/" + entry.getKey());
|
||||||
for (ShowCuePoint cue : entry.getValue()) {
|
for (ShowCuePoint cue : entry.getValue()) {
|
||||||
file.getFile().set(cue.getCueID().toString() + ".Time", cue.getTime());
|
file.getFile().set(cue.getCueID().toString() + ".Time", cue.getTime());
|
||||||
|
|
|
@ -1,77 +0,0 @@
|
||||||
package tech.sbdevelopment.showcontrol.data;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import tech.sbdevelopment.showcontrol.ShowControlPlugin;
|
|
||||||
import tech.sbdevelopment.showcontrol.api.points.ShowCuePoint;
|
|
||||||
import tech.sbdevelopment.showcontrol.api.triggers.Trigger;
|
|
||||||
import tech.sbdevelopment.showcontrol.utils.YamlFile;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class Shows {
|
|
||||||
@Getter
|
|
||||||
private static final HashMap<String, List<ShowCuePoint>> showsMap = new HashMap<>();
|
|
||||||
private static final HashMap<String, ScheduledExecutorService> showTimers = new HashMap<>();
|
|
||||||
|
|
||||||
public static void create(String name) {
|
|
||||||
showsMap.put(name, new ArrayList<>());
|
|
||||||
DataStorage.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void delete(String name) {
|
|
||||||
showsMap.remove(name);
|
|
||||||
|
|
||||||
File data = new File(ShowControlPlugin.getInstance().getDataFolder(), "data/" + name + ".yml");
|
|
||||||
data.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean exists(String name) {
|
|
||||||
return showsMap.containsKey(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<ShowCuePoint> getPoints(String name) {
|
|
||||||
if (!exists(name)) return new ArrayList<>();
|
|
||||||
return showsMap.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addPoint(String name, Long time, Trigger data) {
|
|
||||||
if (!exists(name)) return;
|
|
||||||
getPoints(name).add(new ShowCuePoint(time, data));
|
|
||||||
DataStorage.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void removePoint(String name, ShowCuePoint point) {
|
|
||||||
if (!exists(name)) return;
|
|
||||||
|
|
||||||
point.getData().remove();
|
|
||||||
showsMap.get(name).remove(point);
|
|
||||||
|
|
||||||
YamlFile data = DataStorage.getFiles().get(name);
|
|
||||||
|
|
||||||
data.getFile().set(point.getCueID().toString(), null);
|
|
||||||
data.saveFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void startShow(String name) {
|
|
||||||
if (!exists(name)) return;
|
|
||||||
ScheduledExecutorService showTimer = Executors.newSingleThreadScheduledExecutor();
|
|
||||||
for (ShowCuePoint point : getPoints(name)) {
|
|
||||||
showTimer.schedule(() -> Bukkit.getScheduler().runTask(ShowControlPlugin.getInstance(), () -> point.getData().trigger()), point.getTime(), TimeUnit.MILLISECONDS);
|
|
||||||
}
|
|
||||||
showTimers.put(name, showTimer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void cancelShow(String name) {
|
|
||||||
if (!exists(name)) return;
|
|
||||||
if (!showTimers.containsKey(name)) return;
|
|
||||||
ScheduledExecutorService showTimer = showTimers.get(name);
|
|
||||||
showTimer.shutdownNow();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,7 +2,7 @@ package tech.sbdevelopment.showcontrol.gui;
|
||||||
|
|
||||||
import fr.minuskube.inv.ClickableItem;
|
import fr.minuskube.inv.ClickableItem;
|
||||||
import tech.sbdevelopment.showcontrol.api.points.ShowCuePoint;
|
import tech.sbdevelopment.showcontrol.api.points.ShowCuePoint;
|
||||||
import tech.sbdevelopment.showcontrol.data.Shows;
|
import tech.sbdevelopment.showcontrol.api.SCAPI;
|
||||||
import tech.sbdevelopment.showcontrol.utils.MainUtil;
|
import tech.sbdevelopment.showcontrol.utils.MainUtil;
|
||||||
import tech.sbdevelopment.showcontrol.utils.inventories.PaginationInventory;
|
import tech.sbdevelopment.showcontrol.utils.inventories.PaginationInventory;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
@ -14,9 +14,9 @@ public class ShowCueGUI extends PaginationInventory {
|
||||||
public ShowCueGUI(Player p, String name) {
|
public ShowCueGUI(Player p, String name) {
|
||||||
super(5, ChatColor.DARK_AQUA + "Show Cue Manager:");
|
super(5, ChatColor.DARK_AQUA + "Show Cue Manager:");
|
||||||
|
|
||||||
Shows.getPoints(name).stream().sorted(Comparator.comparing(ShowCuePoint::getTime))
|
SCAPI.getPoints(name).stream().sorted(Comparator.comparing(ShowCuePoint::getTime))
|
||||||
.forEach(cue -> addItem(ClickableItem.of(MainUtil.pointToItem(cue), e -> {
|
.forEach(cue -> addItem(ClickableItem.of(MainUtil.pointToItem(cue), e -> {
|
||||||
Shows.removePoint(name, cue);
|
SCAPI.removePoint(name, cue);
|
||||||
new ShowCueGUI(p, name).open(p);
|
new ShowCueGUI(p, name).open(p);
|
||||||
})));
|
})));
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class TimeUtil {
|
||||||
return array.length > 1 && array[0].length() > 0;
|
return array.length > 1 && array[0].length() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object makeReadable(Long time) {
|
public static String makeReadable(Long time) {
|
||||||
return String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(time),
|
return String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(time),
|
||||||
TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)),
|
TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)),
|
||||||
TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time)));
|
TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time)));
|
||||||
|
|
Loading…
Add table
Reference in a new issue