Bumped GuardianBeam to 2.3.5 (fixes Spot), fixed time combinations
This commit is contained in:
parent
a4dbdab581
commit
47f496133c
3 changed files with 30 additions and 37 deletions
10
pom.xml
10
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>tech.sbdevelopment</groupId>
|
||||
<artifactId>ShowControl</artifactId>
|
||||
<version>1.6</version>
|
||||
<version>1.6.1</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>ShowControl</name>
|
||||
<url>https://sbdevelopment.tech</url>
|
||||
|
@ -157,7 +157,7 @@
|
|||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.20.1-R0.1-SNAPSHOT</version>
|
||||
<version>1.20.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -177,9 +177,9 @@
|
|||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.skytasul</groupId>
|
||||
<artifactId>guardianbeam</artifactId>
|
||||
<version>2.3.4</version>
|
||||
<groupId>com.github.SkytAsul</groupId>
|
||||
<artifactId>GuardianBeam</artifactId>
|
||||
<version>97b0078aba</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -61,7 +61,7 @@ public class ShowCMD extends BaseCommand {
|
|||
|
||||
Long timeMilli;
|
||||
try {
|
||||
timeMilli = TimeUtil.toMilis(time);
|
||||
timeMilli = TimeUtil.toMillis(time);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + "Provide a valid time, for example 5s (5 seconds) or 10m (10 minutes).");
|
||||
return;
|
||||
|
|
|
@ -3,54 +3,47 @@ package tech.sbdevelopment.showcontrol.utils;
|
|||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
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 static Long toMilis(String input) {
|
||||
public static Long toMillis(String input) {
|
||||
long time = 0L;
|
||||
|
||||
// ITS A TIMECODE
|
||||
if (input.contains(":")) {
|
||||
return LocalTime.parse(input, DateTimeFormatter.ofPattern("HH:mm:ss")).toSecondOfDay() * 1000L;
|
||||
}
|
||||
|
||||
input = input.toLowerCase() + "-";
|
||||
|
||||
String[] milisSplit = input.split("ms");
|
||||
if (isValid(milisSplit)) {
|
||||
time += Long.parseLong(milisSplit[0]);
|
||||
return time;
|
||||
}
|
||||
Pattern pattern = Pattern.compile("(\\d+)([a-z]+)");
|
||||
Matcher matcher = pattern.matcher(input);
|
||||
|
||||
String[] secondsSplit = input.split("s");
|
||||
if (isValid(secondsSplit)) {
|
||||
time += Math.round(Double.parseDouble(secondsSplit[0]) * 1000);
|
||||
return time;
|
||||
}
|
||||
while (matcher.find()) {
|
||||
String value = matcher.group(1);
|
||||
String unit = matcher.group(2);
|
||||
|
||||
String[] minutesSplit = input.split("m");
|
||||
if (isValid(minutesSplit)) {
|
||||
time += Math.round(Double.parseDouble(minutesSplit[0]) * 60000);
|
||||
return time;
|
||||
switch (unit) {
|
||||
case "ms":
|
||||
time += Long.parseLong(value);
|
||||
break;
|
||||
case "s":
|
||||
time += Math.round(Double.parseDouble(value) * 1000);
|
||||
break;
|
||||
case "m":
|
||||
time += Math.round(Double.parseDouble(value) * 60000);
|
||||
break;
|
||||
case "t":
|
||||
time += Integer.parseInt(value) * 50L;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown time unit: " + unit);
|
||||
}
|
||||
|
||||
String[] tickSplit = input.split("t");
|
||||
if (isValid(tickSplit)) {
|
||||
time += Integer.parseInt(tickSplit[0]) * 50L;
|
||||
return time;
|
||||
}
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
private static boolean isValid(String[] array) {
|
||||
return array.length > 1 && !array[0].isEmpty();
|
||||
}
|
||||
|
||||
public static String makeReadable(Long time) {
|
||||
return String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(time),
|
||||
TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)),
|
||||
|
|
Loading…
Add table
Reference in a new issue