Moved to ticks

This commit is contained in:
stijnb1234 2021-01-22 20:46:24 +01:00
parent f81813383a
commit 1c5f34f699
6 changed files with 42 additions and 25 deletions

View file

@ -10,30 +10,30 @@ import java.util.UUID;
*/
public class ShowCue {
private final UUID cueID;
private final int timeSeconds;
private final int ticks;
private final TriggerData data;
private int taskID;
/**
* Create a new cue point
*
* @param timeSeconds The starttime in seconds
* @param ticks The starttime in ticks
* @param data The data
*/
public ShowCue(int timeSeconds, TriggerData data) {
this(UUID.randomUUID(), timeSeconds, data);
public ShowCue(int ticks, TriggerData data) {
this(UUID.randomUUID(), ticks, data);
}
/**
* Load an exisiting cue point
*
* @param uuid The UUID
* @param timeSeconds The starttime in seconds
* @param ticks The starttime in ticks
* @param data The data
*/
public ShowCue(UUID uuid, int timeSeconds, TriggerData data) {
public ShowCue(UUID uuid, int ticks, TriggerData data) {
this.cueID = uuid;
this.timeSeconds = timeSeconds;
this.ticks = ticks;
this.data = data;
}
@ -51,8 +51,8 @@ public class ShowCue {
*
* @return The time in seconds
*/
public int getTimeSeconds() {
return timeSeconds;
public int getTicks() {
return ticks;
}
/**
@ -68,7 +68,7 @@ public class ShowCue {
* Start this cue point
*/
public void runAtTime() {
this.taskID = Bukkit.getScheduler().runTaskLater(ShowAPIPlugin.getInstance(), data::trigger, 20 * timeSeconds).getTaskId();
this.taskID = Bukkit.getScheduler().runTaskLater(ShowAPIPlugin.getInstance(), data::trigger, ticks).getTaskId();
}
/**

View file

@ -59,7 +59,7 @@ public class ShowCMD implements CommandExecutor {
return false;
}
int seconds = TimeUtil.parseSeconds(args[2]);
int ticks = TimeUtil.parseTicks(args[2]);
StringBuilder builder = new StringBuilder();
for (int i = 3; i < args.length; i++) {
@ -72,7 +72,7 @@ public class ShowCMD implements CommandExecutor {
return false;
}
Shows.addPoint(name, seconds, data);
Shows.addPoint(name, ticks, data);
sender.sendMessage(ChatColor.GREEN + "De show " + ChatColor.WHITE + name + ChatColor.GREEN + " bevat nu een extra punt!");
return true;

View file

@ -12,6 +12,8 @@ import java.util.UUID;
public class DataSaving {
public static void load() {
boolean newSystem = ShowAPIPlugin.getData().getFile().contains("NewSystem");
for (String name : ShowAPIPlugin.getData().getFile().getConfigurationSection("Shows").getKeys(false)) {
List<ShowCue> cues = new ArrayList<>();
@ -20,6 +22,16 @@ public class DataSaving {
TriggerData data = MainUtil.parseData(ShowAPIPlugin.getData().getFile().getString("Shows." + name + "." + id + ".Type") + " " + ShowAPIPlugin.getData().getFile().getString("Shows." + name + "." + id + ".Data"));
int ticks;
if (!newSystem) ticks = ShowAPIPlugin.getData().getFile().getInt("Shows." + name + "." + id + ".Time") * 20;
else ticks = ShowAPIPlugin.getData().getFile().getInt("Shows." + name + "." + id + ".Time");
if (!newSystem) {
ShowAPIPlugin.getData().getFile().set("Shows." + name + "." + id + ".Time", ticks);
ShowAPIPlugin.getData().getFile().set("NewSystem", true);
ShowAPIPlugin.getData().saveFile();
}
cues.add(new ShowCue(cueID, ShowAPIPlugin.getData().getFile().getInt("Shows." + name + "." + id + ".Time"), data));
}
@ -30,7 +42,7 @@ public class DataSaving {
public static void save() {
for (Map.Entry<String, List<ShowCue>> entry : Shows.getShowsMap().entrySet()) {
for (ShowCue cue : entry.getValue()) {
ShowAPIPlugin.getData().getFile().set("Shows." + entry.getKey() + "." + cue.getCueID().toString() + ".Time", cue.getTimeSeconds());
ShowAPIPlugin.getData().getFile().set("Shows." + entry.getKey() + "." + cue.getCueID().toString() + ".Time", cue.getTicks());
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() + ".Data", cue.getData().getDataString());
}

View file

@ -33,9 +33,9 @@ public class Shows {
return showsMap.get(name);
}
public static void addPoint(String name, int sec, TriggerData data) {
public static void addPoint(String name, int ticks, TriggerData data) {
if (!exists(name)) return;
getPoints(name).add(new ShowCue(sec, data));
getPoints(name).add(new ShowCue(ticks, data));
Bukkit.getScheduler().runTaskAsynchronously(ShowAPIPlugin.getInstance(), DataSaving::save);
}

View file

@ -19,7 +19,7 @@ import java.util.List;
public class MainUtil {
public static ItemStack pointToItem(ShowCue point) {
ItemBuilder builder = new ItemBuilder(Material.NOTE_BLOCK);
builder.name(ChatColor.ITALIC + "TimeCode: " + TimeUtil.showTime(point.getTimeSeconds()));
builder.name(ChatColor.ITALIC + "TimeCode: " + TimeUtil.showTime(point.getTicks()));
List<String> lores = new ArrayList<>();
lores.add(ChatColor.GREEN + "Type: " + ChatColor.AQUA + StringUtils.capitalize(point.getData().getType().name()));

View file

@ -14,16 +14,16 @@ public class TimeUtil {
private static final int y = (int)(d * 365.25);
public static String showTime(int seconds) {
LocalTime timeOfDay = LocalTime.ofSecondOfDay(seconds);
LocalTime timeOfDay = LocalTime.ofSecondOfDay(seconds / 20);
return timeOfDay.toString();
}
public static int parseSeconds(String str) {
public static int parseTicks(String str) {
try {
LocalTime localTime = LocalTime.parse(str);
return localTime.toSecondOfDay();
} catch (DateTimeParseException ex) {
Pattern pattern = Pattern.compile("^(-?(?:\\d+)?\\.?\\d+) *(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$");
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;
@ -35,33 +35,38 @@ public class TimeUtil {
case "yrs":
case "yr":
case "y":
return (int)(n * y) / 1000;
return (int)(n * y) / 20000;
case "weeks":
case "week":
case "w":
return (int)(n * w) / 1000;
return (int)(n * w) / 20000;
case "days":
case "day":
case "d":
return (int)(n * d) / 1000;
return (int)(n * d) / 20000;
case "hours":
case "hour":
case "hrs":
case "hr":
case "h":
return (int)(n * h) / 1000;
return (int)(n * h) / 20000;
case "minutes":
case "minute":
case "mins":
case "min":
case "m":
return (int)(n * m) / 1000;
return (int)(n * m) / 20000;
case "seconds":
case "second":
case "secs":
case "sec":
case "s":
return (int)(n * s) / 1000;
return (int)(n * s) / 20000;
case "ticks":
case "tick":
case "ts":
case "t":
return (int) n / 20000;
default:
return 0;
}