Fixed ms and tick delays, and moved to another gui util

This commit is contained in:
stijnb1234 2021-01-25 13:30:02 +01:00
parent 19b861c3fd
commit 97e66d65f1
20 changed files with 919 additions and 197 deletions

15
pom.xml
View file

@ -54,10 +54,6 @@
<pattern>org.inventivetalent.apihelper</pattern> <pattern>org.inventivetalent.apihelper</pattern>
<shadedPattern>nl.sbdeveloper.showapi.helpers.apihelper</shadedPattern> <shadedPattern>nl.sbdeveloper.showapi.helpers.apihelper</shadedPattern>
</relocation> </relocation>
<relocation>
<pattern>com.samjakob.spigui</pattern>
<shadedPattern>nl.sbdeveloper.showapi.helpers.guihelper</shadedPattern>
</relocation>
</relocations> </relocations>
</configuration> </configuration>
</execution> </execution>
@ -144,10 +140,15 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.samjakob</groupId> <groupId>fr.minuskube.inv</groupId>
<artifactId>SpiGUI</artifactId> <artifactId>smart-invs</artifactId>
<version>v1.1</version> <version>1.2.7</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>
<version>7.8.0</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View file

@ -137,27 +137,48 @@ public class ShowAPI implements API, Listener {
SpotRunnable spot = spots.get(name); SpotRunnable spot = spots.get(name);
new BukkitRunnable() { new BukkitRunnable() {
boolean fired = false;
Location oldLoc = spot.posLoc; Location oldLoc = spot.posLoc;
@Override @Override
public void run() { public void run() {
if (oldLoc.getBlockX() != posLoc.getBlockX()) {
if (oldLoc.getX() > posLoc.getX()) { //De x gaat omhoog if (oldLoc.getX() > posLoc.getX()) { //De x gaat omhoog
oldLoc = oldLoc.add(0.01, 0, 0); oldLoc = oldLoc.add(0.01, 0, 0);
} else { } else {
oldLoc = oldLoc.add(-0.01, 0, 0); oldLoc = oldLoc.add(-0.01, 0, 0);
} }
fired = true;
} else {
fired = false;
}
if (oldLoc.getBlockY() != posLoc.getBlockY()) {
if (oldLoc.getY() > posLoc.getY()) { //De y gaat omhoog if (oldLoc.getY() > posLoc.getY()) { //De y gaat omhoog
oldLoc = oldLoc.add(0, 0.01, 0); oldLoc = oldLoc.add(0, 0.01, 0);
} else { } else {
oldLoc = oldLoc.add(0, -0.01, 0); oldLoc = oldLoc.add(0, -0.01, 0);
} }
fired = true;
} else {
fired = false;
}
if (oldLoc.getBlockZ() != posLoc.getBlockZ()) {
if (oldLoc.getZ() > posLoc.getZ()) { //De z gaat omhoog if (oldLoc.getZ() > posLoc.getZ()) { //De z gaat omhoog
oldLoc = oldLoc.add(0, 0, 0.01); oldLoc = oldLoc.add(0, 0, 0.01);
} else { } else {
oldLoc = oldLoc.add(0, 0, -0.01); oldLoc = oldLoc.add(0, 0, -0.01);
} }
fired = true;
} else {
fired = false;
}
if (!fired) {
cancel();
return;
}
spot.changePositionLocation(oldLoc); spot.changePositionLocation(oldLoc);
} }
@ -250,27 +271,48 @@ public class ShowAPI implements API, Listener {
LaserRunnable laser = lasers.get(name); LaserRunnable laser = lasers.get(name);
new BukkitRunnable() { new BukkitRunnable() {
boolean fired = false;
Location oldLoc = laser.posLoc; Location oldLoc = laser.posLoc;
@Override @Override
public void run() { public void run() {
if (oldLoc.getBlockX() != posLoc.getBlockX()) {
if (oldLoc.getX() > posLoc.getX()) { //De x gaat omhoog if (oldLoc.getX() > posLoc.getX()) { //De x gaat omhoog
oldLoc = oldLoc.add(0.01, 0, 0); oldLoc = oldLoc.add(0.01, 0, 0);
} else { } else {
oldLoc = oldLoc.add(-0.01, 0, 0); oldLoc = oldLoc.add(-0.01, 0, 0);
} }
fired = true;
} else {
fired = false;
}
if (oldLoc.getBlockY() != posLoc.getBlockY()) {
if (oldLoc.getY() > posLoc.getY()) { //De y gaat omhoog if (oldLoc.getY() > posLoc.getY()) { //De y gaat omhoog
oldLoc = oldLoc.add(0, 0.01, 0); oldLoc = oldLoc.add(0, 0.01, 0);
} else { } else {
oldLoc = oldLoc.add(0, -0.01, 0); oldLoc = oldLoc.add(0, -0.01, 0);
} }
fired = true;
} else {
fired = false;
}
if (oldLoc.getBlockZ() != posLoc.getBlockZ()) {
if (oldLoc.getZ() > posLoc.getZ()) { //De z gaat omhoog if (oldLoc.getZ() > posLoc.getZ()) { //De z gaat omhoog
oldLoc = oldLoc.add(0, 0, 0.01); oldLoc = oldLoc.add(0, 0, 0.01);
} else { } else {
oldLoc = oldLoc.add(0, 0, -0.01); oldLoc = oldLoc.add(0, 0, -0.01);
} }
fired = true;
} else {
fired = false;
}
if (!fired) {
cancel();
return;
}
laser.changePositionLocation(oldLoc); laser.changePositionLocation(oldLoc);
} }

View file

@ -1,8 +1,9 @@
package nl.sbdeveloper.showapi; package nl.sbdeveloper.showapi;
import com.samjakob.spigui.SpiGUI;
import nl.sbdeveloper.showapi.commands.ShowCMD; import nl.sbdeveloper.showapi.commands.ShowCMD;
import nl.sbdeveloper.showapi.data.DataSaving; import nl.sbdeveloper.showapi.data.DataSaving;
import nl.sbdeveloper.showapi.data.Shows;
import nl.sbdeveloper.showapi.utils.Inventory;
import nl.sbdeveloper.showapi.utils.YamlFile; import nl.sbdeveloper.showapi.utils.YamlFile;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -12,7 +13,6 @@ public final class ShowAPIPlugin extends JavaPlugin {
private static ShowAPIPlugin instance; private static ShowAPIPlugin instance;
private final ShowAPI showAPI = new ShowAPI(); private final ShowAPI showAPI = new ShowAPI();
private static SpiGUI spiGUI;
private static YamlFile data; private static YamlFile data;
@Override @Override
@ -29,8 +29,7 @@ public final class ShowAPIPlugin extends JavaPlugin {
APIManager.initAPI(ShowAPI.class); APIManager.initAPI(ShowAPI.class);
spiGUI = new SpiGUI(this); Inventory.init();
spiGUI.setEnableAutomaticPagination(true);
getCommand("mctpshow").setExecutor(new ShowCMD()); getCommand("mctpshow").setExecutor(new ShowCMD());
@ -43,6 +42,8 @@ public final class ShowAPIPlugin extends JavaPlugin {
DataSaving.save(); DataSaving.save();
Shows.getShowsMap().values().forEach(show -> show.forEach(showCue -> showCue.getTask().remove()));
APIManager.disableAPI(ShowAPI.class); APIManager.disableAPI(ShowAPI.class);
} }
@ -50,10 +51,6 @@ public final class ShowAPIPlugin extends JavaPlugin {
return instance; return instance;
} }
public static SpiGUI getSpiGUI() {
return spiGUI;
}
public static YamlFile getData() { public static YamlFile getData() {
return data; return data;
} }

View file

@ -1,8 +1,5 @@
package nl.sbdeveloper.showapi.api; package nl.sbdeveloper.showapi.api;
import nl.sbdeveloper.showapi.ShowAPIPlugin;
import org.bukkit.Bukkit;
import java.util.UUID; import java.util.UUID;
/** /**
@ -10,30 +7,29 @@ import java.util.UUID;
*/ */
public class ShowCue { public class ShowCue {
private final UUID cueID; private final UUID cueID;
private final int ticks; private final Long time;
private final TriggerData data; private final TriggerTask data;
private int taskID;
/** /**
* Create a new cue point * Create a new cue point
* *
* @param ticks The starttime in ticks * @param time The starttime (milli)
* @param data The data * @param data The data
*/ */
public ShowCue(int ticks, TriggerData data) { public ShowCue(Long time, TriggerTask data) {
this(UUID.randomUUID(), ticks, data); this(UUID.randomUUID(), time, data);
} }
/** /**
* Load an exisiting cue point * Load an exisiting cue point
* *
* @param uuid The UUID * @param uuid The UUID
* @param ticks The starttime in ticks * @param time The starttime (milli)
* @param data The data * @param data The data
*/ */
public ShowCue(UUID uuid, int ticks, TriggerData data) { public ShowCue(UUID uuid, Long time, TriggerTask data) {
this.cueID = uuid; this.cueID = uuid;
this.ticks = ticks; this.time = time;
this.data = data; this.data = data;
} }
@ -47,12 +43,12 @@ public class ShowCue {
} }
/** /**
* Get the time in seconds * Get the time (milli)
* *
* @return The time in seconds * @return The time (milli)
*/ */
public int getTicks() { public Long getTime() {
return ticks; return time;
} }
/** /**
@ -60,21 +56,7 @@ public class ShowCue {
* *
* @return The data * @return The data
*/ */
public TriggerData getData() { public TriggerTask getTask() {
return data; return data;
} }
/**
* Start this cue point
*/
public void runAtTime() {
this.taskID = Bukkit.getScheduler().runTaskLater(ShowAPIPlugin.getInstance(), data::trigger, ticks).getTaskId();
}
/**
* Cancel this cue point
*/
public void cancel() {
Bukkit.getScheduler().cancelTask(taskID);
}
} }

View file

@ -1,13 +1,13 @@
package nl.sbdeveloper.showapi.api; package nl.sbdeveloper.showapi.api;
public abstract class TriggerData { public abstract class TriggerTask {
private final TriggerType type; private final TriggerType type;
private final String[] dataString; private final String[] dataString;
/** /**
* Create a new trigger * Create a new trigger
*/ */
public TriggerData(TriggerType type, String[] dataString) { public TriggerTask(TriggerType type, String[] dataString) {
this.type = type; this.type = type;
this.dataString = dataString; this.dataString = dataString;
} }

View file

@ -10,15 +10,15 @@ public enum TriggerType {
ANIMA(AnimaTrigger.class, 2), ANIMA(AnimaTrigger.class, 2),
PARTICLE(ParticleTrigger.class, 7); PARTICLE(ParticleTrigger.class, 7);
private final Class<? extends TriggerData> trigger; private final Class<? extends TriggerTask> trigger;
private final int minArgs; private final int minArgs;
TriggerType(Class<? extends TriggerData> trigger, int minArgs) { TriggerType(Class<? extends TriggerTask> trigger, int minArgs) {
this.trigger = trigger; this.trigger = trigger;
this.minArgs = minArgs; this.minArgs = minArgs;
} }
public Class<? extends TriggerData> getTrigger() { public Class<? extends TriggerTask> getTrigger() {
return trigger; return trigger;
} }

View file

@ -1,10 +1,10 @@
package nl.sbdeveloper.showapi.api.triggers; package nl.sbdeveloper.showapi.api.triggers;
import nl.sbdeveloper.showapi.api.TriggerData; import nl.sbdeveloper.showapi.api.TriggerTask;
import nl.sbdeveloper.showapi.api.TriggerType; import nl.sbdeveloper.showapi.api.TriggerType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
public class AnimaTrigger extends TriggerData { public class AnimaTrigger extends TriggerTask {
private final String name; private final String name;
public AnimaTrigger(String[] data) { public AnimaTrigger(String[] data) {

View file

@ -1,10 +1,10 @@
package nl.sbdeveloper.showapi.api.triggers; package nl.sbdeveloper.showapi.api.triggers;
import nl.sbdeveloper.showapi.api.TriggerData; import nl.sbdeveloper.showapi.api.TriggerTask;
import nl.sbdeveloper.showapi.api.TriggerType; import nl.sbdeveloper.showapi.api.TriggerType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
public class CommandTrigger extends TriggerData { public class CommandTrigger extends TriggerTask {
private final String command; private final String command;
public CommandTrigger(String[] data) { public CommandTrigger(String[] data) {
@ -15,7 +15,7 @@ public class CommandTrigger extends TriggerData {
@Override @Override
public void trigger() { public void trigger() {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command);
} }
@Override @Override

View file

@ -1,7 +1,7 @@
package nl.sbdeveloper.showapi.api.triggers; package nl.sbdeveloper.showapi.api.triggers;
import nl.sbdeveloper.showapi.ShowAPI; import nl.sbdeveloper.showapi.ShowAPI;
import nl.sbdeveloper.showapi.api.TriggerData; import nl.sbdeveloper.showapi.api.TriggerTask;
import nl.sbdeveloper.showapi.api.TriggerType; import nl.sbdeveloper.showapi.api.TriggerType;
import nl.sbdeveloper.showapi.utils.Color; import nl.sbdeveloper.showapi.utils.Color;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -9,7 +9,7 @@ import org.bukkit.FireworkEffect;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
public class FireworkTrigger extends TriggerData { public class FireworkTrigger extends TriggerTask {
private ShowAPI.Fireworks.Firework fw; private ShowAPI.Fireworks.Firework fw;
private Location spawnLoc; private Location spawnLoc;

View file

@ -1,13 +1,13 @@
package nl.sbdeveloper.showapi.api.triggers; package nl.sbdeveloper.showapi.api.triggers;
import nl.sbdeveloper.showapi.ShowAPI; import nl.sbdeveloper.showapi.ShowAPI;
import nl.sbdeveloper.showapi.api.TriggerData; import nl.sbdeveloper.showapi.api.TriggerTask;
import nl.sbdeveloper.showapi.api.TriggerType; import nl.sbdeveloper.showapi.api.TriggerType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
public class LaserTrigger extends TriggerData { public class LaserTrigger extends TriggerTask {
private final String name; private final String name;
private Location newLocation; private Location newLocation;

View file

@ -1,13 +1,13 @@
package nl.sbdeveloper.showapi.api.triggers; package nl.sbdeveloper.showapi.api.triggers;
import nl.sbdeveloper.showapi.api.TriggerData; import nl.sbdeveloper.showapi.api.TriggerTask;
import nl.sbdeveloper.showapi.api.TriggerType; import nl.sbdeveloper.showapi.api.TriggerType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Particle; import org.bukkit.Particle;
import org.bukkit.World; import org.bukkit.World;
public class ParticleTrigger extends TriggerData { public class ParticleTrigger extends TriggerTask {
private Particle type; private Particle type;
private Location spawnLoc; private Location spawnLoc;
private int count; private int count;

View file

@ -1,13 +1,13 @@
package nl.sbdeveloper.showapi.api.triggers; package nl.sbdeveloper.showapi.api.triggers;
import nl.sbdeveloper.showapi.ShowAPI; import nl.sbdeveloper.showapi.ShowAPI;
import nl.sbdeveloper.showapi.api.TriggerData; import nl.sbdeveloper.showapi.api.TriggerTask;
import nl.sbdeveloper.showapi.api.TriggerType; import nl.sbdeveloper.showapi.api.TriggerType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
public class SpotTrigger extends TriggerData { public class SpotTrigger extends TriggerTask {
private final String name; private final String name;
private Location newLocation; private Location newLocation;

View file

@ -1,6 +1,6 @@
package nl.sbdeveloper.showapi.commands; package nl.sbdeveloper.showapi.commands;
import nl.sbdeveloper.showapi.api.TriggerData; import nl.sbdeveloper.showapi.api.TriggerTask;
import nl.sbdeveloper.showapi.data.Shows; import nl.sbdeveloper.showapi.data.Shows;
import nl.sbdeveloper.showapi.gui.ShowCueGUI; import nl.sbdeveloper.showapi.gui.ShowCueGUI;
import nl.sbdeveloper.showapi.utils.MainUtil; import nl.sbdeveloper.showapi.utils.MainUtil;
@ -59,20 +59,26 @@ public class ShowCMD implements CommandExecutor {
return false; return false;
} }
int ticks = TimeUtil.parseTicks(args[2]); Long time;
try {
time = TimeUtil.toMilis(args[2]);
} catch (Exception e) {
sender.sendMessage(ChatColor.RED + "Heeft een correcte tijd mee.");
return false;
}
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (int i = 3; i < args.length; i++) { for (int i = 3; i < args.length; i++) {
builder.append(args[i]).append(" "); builder.append(args[i]).append(" ");
} }
TriggerData data = MainUtil.parseData(builder.toString().trim()); TriggerTask data = MainUtil.parseData(builder.toString().trim());
if (data == null) { if (data == null) {
sender.sendMessage(ChatColor.RED + "Je hebt niet genoeg informatie meegeven voor de trigger."); sender.sendMessage(ChatColor.RED + "Je hebt niet genoeg informatie meegeven voor de trigger.");
return false; return false;
} }
Shows.addPoint(name, ticks, data); Shows.addPoint(name, time, data);
sender.sendMessage(ChatColor.GREEN + "De show " + ChatColor.WHITE + name + ChatColor.GREEN + " bevat nu een extra punt!"); sender.sendMessage(ChatColor.GREEN + "De show " + ChatColor.WHITE + name + ChatColor.GREEN + " bevat nu een extra punt!");
return true; return true;
@ -112,7 +118,7 @@ public class ShowCMD implements CommandExecutor {
return false; return false;
} }
ShowCueGUI.openGUI(name, p); new ShowCueGUI(p, name);
return true; return true;
} }
} }

View file

@ -2,7 +2,7 @@ package nl.sbdeveloper.showapi.data;
import nl.sbdeveloper.showapi.ShowAPIPlugin; import nl.sbdeveloper.showapi.ShowAPIPlugin;
import nl.sbdeveloper.showapi.api.ShowCue; import nl.sbdeveloper.showapi.api.ShowCue;
import nl.sbdeveloper.showapi.api.TriggerData; import nl.sbdeveloper.showapi.api.TriggerTask;
import nl.sbdeveloper.showapi.utils.MainUtil; import nl.sbdeveloper.showapi.utils.MainUtil;
import java.util.ArrayList; import java.util.ArrayList;
@ -12,7 +12,7 @@ import java.util.UUID;
public class DataSaving { public class DataSaving {
public static void load() { public static void load() {
boolean newSystem = ShowAPIPlugin.getData().getFile().contains("NewSystem"); boolean newSystem = ShowAPIPlugin.getData().getFile().contains("NewestSystem");
for (String name : ShowAPIPlugin.getData().getFile().getConfigurationSection("Shows").getKeys(false)) { for (String name : ShowAPIPlugin.getData().getFile().getConfigurationSection("Shows").getKeys(false)) {
List<ShowCue> cues = new ArrayList<>(); List<ShowCue> cues = new ArrayList<>();
@ -20,31 +20,34 @@ public class DataSaving {
for (String id : ShowAPIPlugin.getData().getFile().getConfigurationSection("Shows." + name).getKeys(false)) { for (String id : ShowAPIPlugin.getData().getFile().getConfigurationSection("Shows." + name).getKeys(false)) {
UUID cueID = UUID.fromString(id); UUID cueID = UUID.fromString(id);
TriggerData data = MainUtil.parseData(ShowAPIPlugin.getData().getFile().getString("Shows." + name + "." + id + ".Type") + " " + ShowAPIPlugin.getData().getFile().getString("Shows." + name + "." + id + ".Data")); TriggerTask data = MainUtil.parseData(ShowAPIPlugin.getData().getFile().getString("Shows." + name + "." + id + ".Type") + " " + ShowAPIPlugin.getData().getFile().getString("Shows." + name + "." + id + ".Data"));
int ticks; long time;
if (!newSystem) ticks = ShowAPIPlugin.getData().getFile().getInt("Shows." + name + "." + id + ".Time") * 20; if (!newSystem) time = Math.round(ShowAPIPlugin.getData().getFile().getInt("Shows." + name + "." + id + ".Time") * 50);
else ticks = ShowAPIPlugin.getData().getFile().getInt("Shows." + name + "." + id + ".Time"); else time = ShowAPIPlugin.getData().getFile().getLong("Shows." + name + "." + id + ".Time");
if (!newSystem) { if (!newSystem) {
ShowAPIPlugin.getData().getFile().set("Shows." + name + "." + id + ".Time", ticks); ShowAPIPlugin.getData().getFile().set("Shows." + name + "." + id + ".Time", time);
ShowAPIPlugin.getData().getFile().set("NewSystem", true);
ShowAPIPlugin.getData().saveFile();
} }
cues.add(new ShowCue(cueID, ShowAPIPlugin.getData().getFile().getInt("Shows." + name + "." + id + ".Time"), data)); cues.add(new ShowCue(cueID, ShowAPIPlugin.getData().getFile().getLong("Shows." + name + "." + id + ".Time"), data));
} }
Shows.getShowsMap().put(name, cues); Shows.getShowsMap().put(name, cues);
} }
if (!newSystem) {
ShowAPIPlugin.getData().getFile().set("NewestSystem", true);
ShowAPIPlugin.getData().saveFile();
}
} }
public static void save() { public static void save() {
for (Map.Entry<String, List<ShowCue>> entry : Shows.getShowsMap().entrySet()) { for (Map.Entry<String, List<ShowCue>> entry : Shows.getShowsMap().entrySet()) {
for (ShowCue cue : entry.getValue()) { for (ShowCue cue : entry.getValue()) {
ShowAPIPlugin.getData().getFile().set("Shows." + entry.getKey() + "." + cue.getCueID().toString() + ".Time", cue.getTicks()); ShowAPIPlugin.getData().getFile().set("Shows." + entry.getKey() + "." + cue.getCueID().toString() + ".Time", cue.getTime());
ShowAPIPlugin.getData().getFile().set("Shows." + entry.getKey() + "." + cue.getCueID().toString() + ".Type", cue.getData().getType().name()); ShowAPIPlugin.getData().getFile().set("Shows." + entry.getKey() + "." + cue.getCueID().toString() + ".Type", cue.getTask().getType().name());
ShowAPIPlugin.getData().getFile().set("Shows." + entry.getKey() + "." + cue.getCueID().toString() + ".Data", cue.getData().getDataString()); ShowAPIPlugin.getData().getFile().set("Shows." + entry.getKey() + "." + cue.getCueID().toString() + ".Data", cue.getTask().getDataString());
} }
ShowAPIPlugin.getData().saveFile(); ShowAPIPlugin.getData().saveFile();
} }

View file

@ -2,15 +2,19 @@ package nl.sbdeveloper.showapi.data;
import nl.sbdeveloper.showapi.ShowAPIPlugin; import nl.sbdeveloper.showapi.ShowAPIPlugin;
import nl.sbdeveloper.showapi.api.ShowCue; import nl.sbdeveloper.showapi.api.ShowCue;
import nl.sbdeveloper.showapi.api.TriggerData; import nl.sbdeveloper.showapi.api.TriggerTask;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class Shows { public class Shows {
private static final HashMap<String, List<ShowCue>> showsMap = new HashMap<>(); private static final HashMap<String, List<ShowCue>> showsMap = new HashMap<>();
private static final HashMap<String, ScheduledExecutorService> showTimers = new HashMap<>();
public static void create(String name) { public static void create(String name) {
showsMap.put(name, new ArrayList<>()); showsMap.put(name, new ArrayList<>());
@ -33,16 +37,16 @@ public class Shows {
return showsMap.get(name); return showsMap.get(name);
} }
public static void addPoint(String name, int ticks, TriggerData data) { public static void addPoint(String name, Long time, TriggerTask data) {
if (!exists(name)) return; if (!exists(name)) return;
getPoints(name).add(new ShowCue(ticks, data)); getPoints(name).add(new ShowCue(time, data));
Bukkit.getScheduler().runTaskAsynchronously(ShowAPIPlugin.getInstance(), DataSaving::save); Bukkit.getScheduler().runTaskAsynchronously(ShowAPIPlugin.getInstance(), DataSaving::save);
} }
public static void removePoint(String name, ShowCue point) { public static void removePoint(String name, ShowCue point) {
if (!exists(name)) return; if (!exists(name)) return;
point.getData().remove(); point.getTask().remove();
showsMap.get(name).remove(point); showsMap.get(name).remove(point);
ShowAPIPlugin.getData().getFile().set("Shows." + name + "." + point.getCueID(), null); ShowAPIPlugin.getData().getFile().set("Shows." + name + "." + point.getCueID(), null);
@ -51,12 +55,20 @@ public class Shows {
public static void startShow(String name) { public static void startShow(String name) {
if (!exists(name)) return; if (!exists(name)) return;
getPoints(name).forEach(ShowCue::runAtTime); ScheduledExecutorService showTimer = Executors.newSingleThreadScheduledExecutor();
Bukkit.getLogger().info("Scheduled show " + name);
for (ShowCue point : getPoints(name)) {
Bukkit.getLogger().info("Point " + point.getTask().getDataString() + " on " + point.getTime());
showTimer.schedule(() -> Bukkit.getScheduler().runTask(ShowAPIPlugin.getInstance(), () -> point.getTask().trigger()), point.getTime(), TimeUnit.MILLISECONDS);
}
showTimers.put(name, showTimer);
} }
public static void cancelShow(String name) { public static void cancelShow(String name) {
if (!exists(name)) return; if (!exists(name)) return;
getPoints(name).forEach(ShowCue::cancel); if (!showTimers.containsKey(name)) return;
ScheduledExecutorService showTimer = showTimers.get(name);
showTimer.shutdownNow();
} }
public static HashMap<String, List<ShowCue>> getShowsMap() { public static HashMap<String, List<ShowCue>> getShowsMap() {

View file

@ -1,30 +1,68 @@
package nl.sbdeveloper.showapi.gui; package nl.sbdeveloper.showapi.gui;
import com.samjakob.spigui.SGMenu; import fr.minuskube.inv.ClickableItem;
import com.samjakob.spigui.buttons.SGButton; import fr.minuskube.inv.content.InventoryContents;
import nl.sbdeveloper.showapi.ShowAPIPlugin; import fr.minuskube.inv.content.Pagination;
import fr.minuskube.inv.content.SlotIterator;
import nl.sbdeveloper.showapi.api.ShowCue; import nl.sbdeveloper.showapi.api.ShowCue;
import nl.sbdeveloper.showapi.data.Shows; import nl.sbdeveloper.showapi.data.Shows;
import nl.sbdeveloper.showapi.utils.Inventory;
import nl.sbdeveloper.showapi.utils.ItemBuilder;
import nl.sbdeveloper.showapi.utils.MainUtil; import nl.sbdeveloper.showapi.utils.MainUtil;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
public class ShowCueGUI { import java.util.ArrayList;
public static void openGUI(String name, Player p) { import java.util.Comparator;
SGMenu menu = ShowAPIPlugin.getSpiGUI().create(ChatColor.DARK_AQUA + "Show Cue Manager:", 5); import java.util.List;
menu.setAutomaticPaginationEnabled(true); import java.util.stream.Collectors;
for (ShowCue cue : Shows.getPoints(name)) { import static nl.sbdeveloper.showapi.utils.MainUtil.__;
SGButton button = new SGButton(MainUtil.pointToItem(cue))
.withListener((InventoryClickEvent e) -> {
Shows.removePoint(name, cue); //Remove the point
openGUI(name, p); //Refresh
});
menu.addButton(button); public class ShowCueGUI extends Inventory {
private final String showName;
public ShowCueGUI(Player p, String name) {
super(5, ChatColor.DARK_AQUA + "Show Cue Manager:");
this.showName = name;
open(p);
} }
p.openInventory(menu.getInventory()); @Override
public void init(Player player, InventoryContents contents) {
Pagination pagination = contents.pagination();
List<ClickableItem> items = new ArrayList<>();
for (ShowCue cue : Shows.getPoints(showName).stream().sorted(Comparator.comparing(ShowCue::getTime)).collect(Collectors.toList())) {
items.add(ClickableItem.of(MainUtil.pointToItem(cue), e -> {
Shows.removePoint(showName, cue);
open(player, pagination.getPage());
}));
}
ClickableItem[] itemsArray = new ClickableItem[items.size()];
itemsArray = items.toArray(itemsArray);
pagination.setItems(itemsArray);
pagination.setItemsPerPage(45);
pagination.addToIterator(contents.newIterator(SlotIterator.Type.HORIZONTAL, 0, 0));
contents.set(5, 0, ClickableItem.of(new ItemBuilder(Material.PLAYER_HEAD, 1)
.setName(__("&7Vorige pagina"))
.setLore(__("&eGa naar de vorige pagina."))
.setSkullTexture("http://textures.minecraft.net/texture/6e8c3ce2aee6cf2faade7db37bbae73a36627ac1473fef75b410a0af97659f")
.toItemStack(), e -> open(player, pagination.previous().getPage())));
contents.set(5, 4, ClickableItem.of(new ItemBuilder(Material.BARRIER, 1)
.setName(__("&7Sluiten"))
.setLore(__("&eSluit dit menu."))
.toItemStack(), e -> player.closeInventory()));
contents.set(5, 8, ClickableItem.of(new ItemBuilder(Material.PLAYER_HEAD, 1)
.setName(__("&7Volgende pagina"))
.setLore(__("&eGa naar de volgende pagina."))
.setSkullTexture("http://textures.minecraft.net/texture/6e8cd53664d9307b6869b9abbae2b7737ab762bb18bb34f31c5ca8f3edb63b6")
.toItemStack(), e -> open(player, pagination.next().getPage())));
} }
} }

View file

@ -0,0 +1,53 @@
package nl.sbdeveloper.showapi.utils;
import fr.minuskube.inv.InventoryManager;
import fr.minuskube.inv.SmartInventory;
import fr.minuskube.inv.content.InventoryContents;
import fr.minuskube.inv.content.InventoryProvider;
import nl.sbdeveloper.showapi.ShowAPIPlugin;
import org.bukkit.entity.Player;
import static nl.sbdeveloper.showapi.utils.MainUtil.__;
public abstract class Inventory implements InventoryProvider {
/*
This file is part of FrogRacing.
Copyright (c) 2018-2021 FrogNetwork - All Rights Reserved
Unauthorized copying of this file, via any medium is strictly prohibited
Proprietary and confidential
Written by Stijn Bannink <stijnbannink23@gmail.com>, March 2020
*/
private static InventoryManager manager;
protected SmartInventory inventory;
public Inventory(int rows, String title) {
this(rows, title, true); //Standaard sluitbaar!
}
public Inventory(int rows, String title, boolean closeable) {
this.inventory = SmartInventory.builder().id(title).provider(this).manager(manager).size(rows, 9).closeable(closeable).title(__("&8" + title)).build();
}
@Override
public void update(Player player, InventoryContents contents) {
// Niet altijd nodig, daarom staat hij hier alvast.
}
protected void open(Player player) {
this.inventory.open(player);
}
protected void open(Player player, int page) {
this.inventory.open(player, page);
}
public void close(Player player) {
this.inventory.close(player);
}
public static void init() {
manager = new InventoryManager(ShowAPIPlugin.getInstance());
manager.init();
}
}

View file

@ -0,0 +1,601 @@
package nl.sbdeveloper.showapi.utils;
import com.cryptomorin.xseries.SkullUtils;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.material.MaterialData;
import org.bukkit.potion.PotionType;
import java.util.*;
import java.util.function.Function;
/**
* @author Blutkrone
*/
public class ItemBuilder {
/*
This file is part of FrogRacing.
Copyright (c) 2018-2021 FrogNetwork - All Rights Reserved
Unauthorized copying of this file, via any medium is strictly prohibited
Proprietary and confidential
Written by Stijn Bannink <stijnbannink23@gmail.com>, March 2020
*/
private final ItemStack is;
private static boolean loaded = false;
private static boolean usePotionSetColor = false;
/** */
private static void init() {
try {
Class.forName("org.bukkit.Color");
usePotionSetColor = true;
} catch (Exception e) {
usePotionSetColor = false;
}
loaded = true;
}
/**
* Create a new ItemBuilder from scratch.
*
* @param m The material to create the ItemBuilder with.
*/
public ItemBuilder(Material m) {
this(m, 1);
}
/**
* Create a new ItemBuilder over an existing itemstack.
*
* @param is The itemstack to create the ItemBuilder over.
*/
public ItemBuilder(ItemStack is) {
this.is = is;
}
/**
* Create a new ItemBuilder from scratch.
*
* @param m The material of the item.
* @param amount The evaluate of the item.
*/
public ItemBuilder(Material m, int amount) {
this(m, amount, (short) 0);
}
/**
* Create a new ItemBuilder from scratch.
*
* @param m The material of the item.
* @param amount The evaluate of the item.
* @param durability The durability of the item.
*/
public ItemBuilder(Material m, int amount, short durability) {
this(m, amount, durability, null);
}
/**
* Create a new ItemBuilder from scratch.
*
* @param m The material of the item.
* @param amount The evaluate of the item.
* @param durability The durability of the item.
*/
public ItemBuilder(Material m, int amount, short durability, Byte data) {
if (!loaded) init();
if (data != null && data > 0 && data <= 15) {
is = new ItemStack(m, amount);
setDurability(durability);
// Ensure that we only allow applying data on valid objects.
if (is.getType().name().contains("STAINED_GLASS")) {
setData(GlassColor.values()[data]);
} else if (is.getType().name().contains("WOOL")) {
setData(WoolColor.values()[data]);
} else if (is.getType().name().contains("DYE") || DyeColor.is(is.getType())) {
setData(DyeColor.values()[data]);
} else
Bukkit.getLogger().warning("Unable to assign " + m + " a data value!");
} else {
is = new ItemStack(m, amount);
setDurability(durability);
}
}
public static ItemBuilder create(ItemStack from) {
return new ItemBuilder(from);
}
public ItemBuilder setData(GlassColor color) {
if (is.getType().name().contains("STAINED_GLASS")) {
color.apply(this);
} else
throw new IllegalArgumentException("Cannot apply " + color.getClass().getSimpleName() + " on " + is.getType());
return this;
}
public ItemBuilder setData(WoolColor color) {
if (is.getType().name().contains("WOOL")) {
color.apply(this);
} else
throw new IllegalArgumentException("Cannot apply " + color.getClass().getSimpleName() + " on " + is.getType());
return this;
}
public ItemBuilder setData(DyeColor color) {
if (is.getType().name().contains("DYE") || DyeColor.is(is.getType())) {
color.apply(this);
} else
throw new IllegalArgumentException("Cannot apply " + color.getClass().getSimpleName() + " on " + is.getType());
return this;
}
public ItemBuilder setData(PotionColor color) {
if (is.getType().name().contains("POTION")) {
color.apply(this);
} else
throw new IllegalArgumentException("Cannot apply " + color.getClass().getSimpleName() + " on " + is.getType());
return this;
}
/**
* Clone the ItemBuilder into a new one.
*
* @return The cloned instance.
*/
public ItemBuilder clone() {
return new ItemBuilder(is.clone());
}
/**
* Change the durability of the item.
*
* @param dur The durability to set it to.
*/
public ItemBuilder setDurability(short dur) {
if (is.getType() == Material.AIR) return this;
ItemMeta meta = is.getItemMeta();
if (meta instanceof org.bukkit.inventory.meta.Damageable) {
((org.bukkit.inventory.meta.Damageable) meta).setDamage(dur);
is.setItemMeta(meta);
}
return this;
}
/**
* Change the durability of the item.
*
* @param data The durability to set it to.
*/
@Deprecated
public ItemBuilder setData(byte data) {
if (is.getType() == Material.AIR) return this;
is.setData(new MaterialData(is.getType(), data));
return this;
}
/**
* Change the unbreakable of the item.
*
* @param unbreakable The unbreakable to set it to.
*/
public ItemBuilder setUnbreakable(boolean unbreakable) {
if (is.getType() == Material.AIR) return this;
ItemMeta meta = is.getItemMeta();
meta.setUnbreakable(unbreakable);
is.setItemMeta(meta);
return this;
}
/**
* Change the evaluate of the item.
*
* @param amount The evaluate to set it to.
*/
public ItemBuilder setAmount(int amount) {
if (is.getType() == Material.AIR) return this;
is.setAmount(amount);
return this;
}
/**
* Add an item flag
*
* @param flags item flagS
*/
public ItemBuilder addFlags(ItemFlag... flags) {
if (is.getType() == Material.AIR) return this;
ItemMeta im = is.getItemMeta();
im.addItemFlags(flags);
is.setItemMeta(im);
return this;
}
/**
* Remove an item flag
*
* @param flags item flagS
*/
public ItemBuilder removeFlags(ItemFlag... flags) {
if (is.getType() == Material.AIR) return this;
ItemMeta im = is.getItemMeta();
im.removeItemFlags(flags);
is.setItemMeta(im);
return this;
}
/**
* Set the displayname of the item.
*
* @param name The name to change it to.
*/
public ItemBuilder setName(String name) {
if (is.getType() == Material.AIR || name == null || name.isEmpty()) return this;
ItemMeta im = is.getItemMeta();
im.setDisplayName(name);
is.setItemMeta(im);
return this;
}
/**
* Add an unsafe enchantment.
*
* @param ench The enchantment to add.
* @param level The level to put the enchant on.
*/
public ItemBuilder addUnsafeEnchantment(Enchantment ench, int level) {
if (is.getType() == Material.AIR) return this;
is.addUnsafeEnchantment(ench, level);
return this;
}
/**
* Remove a certain enchant from the item.
*
* @param ench The enchantment to remove
*/
public ItemBuilder removeEnchantment(Enchantment ench) {
if (is.getType() == Material.AIR) return this;
is.removeEnchantment(ench);
return this;
}
public ItemBuilder glow() {
if (is.getType() == Material.AIR) return this;
is.addUnsafeEnchantment(Enchantment.LURE, 0);
ItemMeta im = is.getItemMeta();
im.addItemFlags(ItemFlag.HIDE_ENCHANTS);
is.setItemMeta(im);
return this;
}
/**
* Set the skull getOwner for the item. Works on skulls only.
*
* @param owner The name of the skull's getOwner.
*/
public ItemBuilder setSkullOwner(String owner) {
if (is.getType() == Material.AIR) return this;
try {
SkullMeta im = (SkullMeta) is.getItemMeta();
im.setOwner(owner);
is.setItemMeta(im);
} catch (ClassCastException expected) {
}
return this;
}
public ItemBuilder setSkullTexture(String url) {
if (is.getType() == Material.AIR) return this;
is.setItemMeta(SkullUtils.applySkin(is.getItemMeta(), url));
return this;
}
/**
* Add an enchant to the item.
*
* @param ench The enchant to add
* @param level The level
*/
public ItemBuilder addEnchant(Enchantment ench, int level) {
if (is.getType() == Material.AIR) return this;
ItemMeta im = is.getItemMeta();
im.addEnchant(ench, level, true);
is.setItemMeta(im);
return this;
}
/**
* Add multiple enchants at once.
*
* @param enchantments The enchants to add.
*/
public ItemBuilder addEnchantments(Map<Enchantment, Integer> enchantments) {
if (is.getType() == Material.AIR) return this;
is.addEnchantments(enchantments);
return this;
}
/**
* Sets infinity durability on the item by setting the durability to Short.MAX_VALUE.
*/
public ItemBuilder setInfinityDurability() {
if (is.getType() == Material.AIR) return this;
is.setDurability(Short.MAX_VALUE);
return this;
}
/**
* Re-sets the lore.
*
* @param lore The lore to set it to.
*/
public ItemBuilder setLore(String... lore) {
if (is.getType() == Material.AIR || lore == null) return this;
ItemMeta im = is.getItemMeta();
im.setLore(Arrays.asList(lore));
is.setItemMeta(im);
return this;
}
/**
* Re-sets the lore.
*
* @param lore The lore to set it to.
*/
public ItemBuilder setLore(List<String> lore) {
if (is.getType() == Material.AIR) return this;
ItemMeta im = is.getItemMeta();
im.setLore(lore);
is.setItemMeta(im);
return this;
}
/**
* Remove a lore line.
*
* @param line The lore to remove.
*/
public ItemBuilder removeLoreLine(String line) {
if (is.getType() == Material.AIR) return this;
ItemMeta im = is.getItemMeta();
List<String> lore = new ArrayList<>(im.getLore());
if (!lore.contains(line)) return this;
lore.remove(line);
im.setLore(lore);
is.setItemMeta(im);
return this;
}
/**
* Remove a lore line.
*
* @param index The index of the lore line to remove.
*/
public ItemBuilder removeLoreLine(int index) {
if (is.getType() == Material.AIR) return this;
ItemMeta im = is.getItemMeta();
List<String> lore = new ArrayList<>(im.getLore());
if (index < 0 || index > lore.size()) return this;
lore.remove(index);
im.setLore(lore);
is.setItemMeta(im);
return this;
}
/**
* Add a lore line.
*
* @param line The lore line to add.
*/
public ItemBuilder addLoreLine(String line) {
if (is.getType() == Material.AIR) return this;
ItemMeta im = is.getItemMeta();
List<String> lore = new ArrayList<>();
if (im.hasLore()) lore = new ArrayList<>(im.getLore());
lore.add(line);
im.setLore(lore);
is.setItemMeta(im);
return this;
}
public ItemBuilder addLoreLine(String... lines) {
if (is.getType() == Material.AIR) return this;
for (String line : lines) {
addLoreLine(line);
}
return this;
}
public ItemBuilder addLoreLine(Collection<String> lines) {
if (is.getType() == Material.AIR) return this;
for (String line : lines) {
addLoreLine(line);
}
return this;
}
/**
* Add a lore line.
*
* @param line The lore line to add.
* @param pos The index of where to put it.
*/
public ItemBuilder addLoreLine(String line, int pos) {
if (is.getType() == Material.AIR) return this;
ItemMeta im = is.getItemMeta();
List<String> lore = new ArrayList<>(im.getLore());
lore.set(pos, line);
im.setLore(lore);
is.setItemMeta(im);
return this;
}
/**
* Direct access to the item meta
*
* @param modifier function to modify the meta.
*/
public ItemBuilder writeMeta(
Function<ItemMeta, ItemMeta> modifier
) {
if (is.getType() == Material.AIR) return this;
is.setItemMeta(modifier.apply(is.getItemMeta()));
return this;
}
/**
* Retrieves the itemstack from the ItemBuilder.
*
* @return The itemstack created/modified by the ItemBuilder instance.
*/
public ItemStack toItemStack() {
return is;
}
public enum GlassColor {
WHITE,
ORANGE,
MAGENTA,
LIGHT_BLUE,
YELLOW,
LIME,
PINK,
GRAY,
LIGHT_GRAY,
CYAN,
PURPLE,
BLUE,
BROWN,
GREEN,
RED,
BLACK;
private void apply(ItemBuilder builder) {
boolean panel = builder.is.getType().name().contains("STAINED_GLASS_PANE");
builder.is.setType(Material.valueOf(name() + (panel ? "_STAINED_GLASS_PANE" : "STAINED_GLASS")));
}
}
public enum WoolColor {
WHITE,
ORANGE,
MAGENTA,
LIGHT_BLUE,
YELLOW,
LIME,
PINK,
GRAY,
LIGHT_GRAY,
CYAN,
PURPLE,
BLUE,
BROWN,
GREEN,
RED,
BLACK;
private void apply(ItemBuilder builder) {
builder.is.setType(Material.valueOf(name() + "_WOOL"));
}
}
public enum DyeColor {
BLACK(0, "INK_SACK"),
RED(1, "ROSE_RED"),
GREEN(2, "CACTUS_GREEN"),
BROWN(3, "COCOA_BEANS"),
BLUE(4, "LAPIS_LAZULI"),
PURPLE(5, "PURPLE_DYE"),
CYAN(6, "CYAN_DYE"),
LIGHT_GRAY(7, "LIGHT_GRAY_DYE"),
GRAY(8, "GRAY_DYE"),
PINK(9, "PINK_DYE"),
LIME(10, "LIME_DYE"),
YELLOW(11, "DANDELION_YELLOW"),
LIGHT_BLUE(12, "LIGHT_BLUE_DYE"),
MAGENTA(13, "MAGENTA_DYE"),
ORANGE(14, "ORANGE_DYE"),
WHITE(15, "BONE_MEAL");
private final String coded;
DyeColor(int data, String coded) {
this.coded = coded;
}
static boolean is(Material mat) {
if (mat.name().contains("DYE")) return true;
if (mat.name().contains("INK_SAC")) return true;
for (DyeColor dyeColor : values()) {
if (dyeColor.name().equalsIgnoreCase(mat.name()))
return true;
}
return false;
}
private void apply(ItemBuilder builder) {
builder.is.setType(Material.valueOf(coded));
}
}
public enum PotionColor {
PINK("REGEN", 0xF442E2),
CYAN("SPEED", 0x42f1f4),
GOLD("FIRE_RESISTANCE", 0xf4b942),
DARK_GREEN("POISON", 0x365b0e),
RED("INSTANT_HEAL", 0xe5251b),
DARK_BLUE("NIGHT_VISION", 0x092366),
DARK_GRAY("WEAKNESS", 0x2e2f33),
DARK_RED("STRENGTH", 0x4f0a01),
GRAY("SLOWNESS", 0x939393),
LIGHT_GREEN("JUMP", 0x42f4b0),
BROWN("INSTANT_DAMAGE", 0xa54126),
BLUE("WATER_BREATHING", 0x0e59ef), // TEAL
LIGHT_GRAY("INVISIBILITY", 0xc4c4c4),
GREEN("LUCK", 0x1f890f),
BLACK(null, 0x161616),
LIGHT_BROWN("TURTLE_MASTER", 0xad581b),
SILVER("SLOW_FALLING", 0xd8ccc3);
private final String potionType;
private final int rgb;
PotionColor(String potionType, int rgb) {
this.potionType = potionType;
this.rgb = rgb;
}
private void apply(ItemBuilder builder) {
PotionMeta meta = (PotionMeta) builder.is.getItemMeta();
if (usePotionSetColor) {
meta.setColor(Color.fromRGB(rgb));
} else if (potionType != null) {
try {
meta.setBasePotionData(new org.bukkit.potion.PotionData(PotionType.valueOf(potionType)));
} catch (Exception e) {
Bukkit.getLogger().severe("Unknown Potion Color: " + this + ", " +
"the underlying " + potionType + " handle isn't available in this version!");
}
}
builder.is.setItemMeta(meta);
}
}
public enum FireworkColor {
}
}

View file

@ -1,8 +1,7 @@
package nl.sbdeveloper.showapi.utils; package nl.sbdeveloper.showapi.utils;
import com.samjakob.spigui.item.ItemBuilder;
import nl.sbdeveloper.showapi.api.ShowCue; import nl.sbdeveloper.showapi.api.ShowCue;
import nl.sbdeveloper.showapi.api.TriggerData; import nl.sbdeveloper.showapi.api.TriggerTask;
import nl.sbdeveloper.showapi.api.TriggerType; import nl.sbdeveloper.showapi.api.TriggerType;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -17,24 +16,28 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
public class MainUtil { public class MainUtil {
public static String __(String in) {
return ChatColor.translateAlternateColorCodes('&', in);
}
public static ItemStack pointToItem(ShowCue point) { public static ItemStack pointToItem(ShowCue point) {
ItemBuilder builder = new ItemBuilder(Material.NOTE_BLOCK); ItemBuilder builder = new ItemBuilder(Material.NOTE_BLOCK);
builder.name(ChatColor.ITALIC + "TimeCode: " + TimeUtil.showTime(point.getTicks())); builder.setName(ChatColor.ITALIC + "TimeCode: " + TimeUtil.makeReadable(point.getTime()));
List<String> lores = new ArrayList<>(); List<String> lores = new ArrayList<>();
lores.add(ChatColor.GREEN + "Type: " + ChatColor.AQUA + StringUtils.capitalize(point.getData().getType().name())); lores.add(ChatColor.GREEN + "Type: " + ChatColor.AQUA + StringUtils.capitalize(point.getTask().getType().name()));
lores.add(ChatColor.GREEN + "Data:"); lores.add(ChatColor.GREEN + "Data:");
for (String str : ChatPaginator.paginate(point.getData().getDataString(), 20).getLines()) { for (String str : ChatPaginator.paginate(point.getTask().getDataString(), 20).getLines()) {
lores.add(ChatColor.AQUA + ChatColor.stripColor(str)); lores.add(ChatColor.AQUA + ChatColor.stripColor(str));
} }
lores.add(""); lores.add("");
lores.add(ChatColor.RED + ChatColor.BOLD.toString() + "Click to remove!"); lores.add(ChatColor.RED + ChatColor.BOLD.toString() + "Click to remove!");
builder.lore(lores); builder.setLore(lores);
return builder.build(); return builder.toItemStack();
} }
public static TriggerData parseData(String data) { public static TriggerTask parseData(String data) {
String[] dataSplitter = data.split(" "); String[] dataSplitter = data.split(" ");
String[] dataSplitterNew = Arrays.copyOfRange(dataSplitter, 1, dataSplitter.length); String[] dataSplitterNew = Arrays.copyOfRange(dataSplitter, 1, dataSplitter.length);
@ -46,7 +49,7 @@ public class MainUtil {
} }
try { try {
Constructor<? extends TriggerData> ctor = type.getTrigger().getConstructor(String[].class); Constructor<? extends TriggerTask> ctor = type.getTrigger().getConstructor(String[].class);
if (dataSplitter.length < type.getMinArgs()) return null; if (dataSplitter.length < type.getMinArgs()) return null;
return ctor.newInstance(new Object[] { dataSplitterNew }); return ctor.newInstance(new Object[] { dataSplitterNew });
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {

View file

@ -1,75 +1,59 @@
package nl.sbdeveloper.showapi.utils; package nl.sbdeveloper.showapi.utils;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.format.DateTimeParseException; import java.time.format.DateTimeFormatter;
import java.util.regex.Matcher; import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
/**
* Source from:
* https://github.com/Mindgamesnl/OpenAudioMc/blob/master/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/show/util/TimeParser.java
*/
public class TimeUtil { public class TimeUtil {
private static final int s = 1000;
private static final int m = s * 60;
private static final int h = m * 60;
private static final int d = h * 24;
private static final int w = d * 7;
private static final int y = (int)(d * 365.25);
public static String showTime(int seconds) { public static Long toMilis(String input) {
LocalTime timeOfDay = LocalTime.ofSecondOfDay(seconds / 20); long time = 0L;
return timeOfDay.toString();
// ITS A TIMECODE
if (input.contains(":")) {
return LocalTime.parse(input, DateTimeFormatter.ofPattern("HH:mm:ss")).toSecondOfDay() * 1000L;
} }
public static int parseTicks(String str) { input = input.toLowerCase() + "-";
try {
LocalTime localTime = LocalTime.parse(str);
return localTime.toSecondOfDay();
} catch (DateTimeParseException ex) {
Pattern pattern = Pattern.compile("^(-?(?:\\d+)?\\.?\\d+) *(ticks?|tick?|t|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$");
Matcher matcher = pattern.matcher(str);
if (!matcher.find()) return 0; String[] milisSplit = input.split("ms");
if (isValid(milisSplit)) {
time += Long.parseLong(milisSplit[0]);
return time;
}
float n = Float.parseFloat(matcher.group(1)); String[] secondsSplit = input.split("s");
switch (matcher.group(2).toLowerCase()) { if (isValid(secondsSplit)) {
case "years": time += Math.round(Double.parseDouble(secondsSplit[0]) * 1000);
case "year": return time;
case "yrs":
case "yr":
case "y":
return (int)(n * y) / 20000;
case "weeks":
case "week":
case "w":
return (int)(n * w) / 20000;
case "days":
case "day":
case "d":
return (int)(n * d) / 20000;
case "hours":
case "hour":
case "hrs":
case "hr":
case "h":
return (int)(n * h) / 20000;
case "minutes":
case "minute":
case "mins":
case "min":
case "m":
return (int)(n * m) / 20000;
case "seconds":
case "second":
case "secs":
case "sec":
case "s":
return (int)(n * s) / 20000;
case "ticks":
case "tick":
case "ts":
case "t":
return (int) n / 20000;
default:
return 0;
} }
String[] minutesSplit = input.split("m");
if (isValid(minutesSplit)) {
time += Math.round(Double.parseDouble(minutesSplit[0]) * 60000);
return time;
} }
String[] tickSplit = input.split("t");
if (isValid(tickSplit)) {
time += Math.round(Integer.parseInt(tickSplit[0]) * 50);
return time;
}
return time;
}
private static boolean isValid(String[] array) {
return array.length > 1 && array[0].length() > 0;
}
public static Object makeReadable(Long time) {
return String.format("%02d:%02d:%02d", 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)));
} }
} }