From ab80ffcd0e85d7a265a7b76a2b5b23bdaa05957e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9meth=20Noel?= Date: Tue, 29 Jun 2021 22:38:37 +0200 Subject: [PATCH] Updated ArgumentTime.java --- .../arguments/minecraft/ArgumentTime.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentTime.java b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentTime.java index 37c80edc6..548448790 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentTime.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentTime.java @@ -6,16 +6,19 @@ import net.minestom.server.command.builder.NodeMaker; import net.minestom.server.command.builder.arguments.Argument; import net.minestom.server.command.builder.exception.ArgumentSyntaxException; import net.minestom.server.network.packet.server.play.DeclareCommandsPacket; -import net.minestom.server.utils.time.TimeUnit; -import net.minestom.server.utils.time.UpdateOption; +import net.minestom.server.utils.time.Tick; import org.jetbrains.annotations.NotNull; +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.time.temporal.TemporalUnit; + /** * Represents an argument giving a time (day/second/tick). *

* Example: 50d, 25s, 75t */ -public class ArgumentTime extends Argument { +public class ArgumentTime extends Argument { public static final int INVALID_TIME_FORMAT = -2; public static final int NO_NUMBER = -3; @@ -28,21 +31,21 @@ public class ArgumentTime extends Argument { @NotNull @Override - public UpdateOption parse(@NotNull String input) throws ArgumentSyntaxException { + public Duration parse(@NotNull String input) throws ArgumentSyntaxException { final char lastChar = input.charAt(input.length() - 1); - TimeUnit timeUnit; + TemporalUnit timeUnit; if (Character.isDigit(lastChar)) - timeUnit = TimeUnit.TICK; + timeUnit = Tick.TICKS; else if (SUFFIXES.contains(lastChar)) { input = input.substring(0, input.length() - 1); if (lastChar == 'd') { - timeUnit = TimeUnit.DAY; + timeUnit = ChronoUnit.DAYS; } else if (lastChar == 's') { - timeUnit = TimeUnit.SECOND; + timeUnit = ChronoUnit.SECONDS; } else if (lastChar == 't') { - timeUnit = TimeUnit.TICK; + timeUnit = Tick.TICKS; } else { throw new ArgumentSyntaxException("Time needs to have the unit d, s, t, or none", input, NO_NUMBER); } @@ -52,7 +55,7 @@ public class ArgumentTime extends Argument { try { // Check if value is a number final int time = Integer.parseInt(input); - return new UpdateOption(time, timeUnit); + return Duration.of(time, timeUnit); } catch (NumberFormatException e) { throw new ArgumentSyntaxException("Time needs to be a number", input, NO_NUMBER); }