1
mirror of https://github.com/Shiewk/SModeration.git synced 2026-04-29 06:34:17 +02:00

Add mute command, command usages and smaller improvements

This commit is contained in:
Shy
2024-06-08 11:03:56 +02:00
parent 1bb4c2fc47
commit fe4e87d9b4
8 changed files with 174 additions and 5 deletions
@@ -2,15 +2,31 @@ package de.shiewk.smoderation.util;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
public abstract class PlayerUtil {
private PlayerUtil(){}
public static String offlinePlayerName(UUID uuid){
public static final UUID UUID_CONSOLE = new UUID(0, 0);
public static @NotNull String offlinePlayerName(UUID uuid){
if (uuid.equals(UUID_CONSOLE)){
return "UUID_CONSOLE";
}
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
return player.getName() == null ? uuid.toString() : player.getName();
}
public static @Nullable UUID offlinePlayerUUIDByName(String name){
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayerIfCached(name);// getOfflinePlayerIfCached(String) is safer (I have experience with getOfflinePlayer(String) returning wrong UUIDs)
if (offlinePlayer != null) {
return offlinePlayer.getUniqueId();
} else {
return null;
}
}
}
@@ -77,4 +77,34 @@ public abstract class TimeUtil {
return builder.toString();
}
public static long parseDurationMillisSafely(String in){
try {
return parseDurationMillis(in);
} catch (Throwable e){
return -1;
}
}
public static long parseDurationMillis(String in){
if (in.endsWith("ms")){
return Long.parseLong(in.substring(0, in.length()-2));
} else if (in.endsWith("s")){
return Long.parseLong(in.substring(0, in.length()-1)) * 1000L;
} else if (in.endsWith("min")){
return Long.parseLong(in.substring(0, in.length()-3)) * 60000L;
} else if (in.endsWith("h")){
return Long.parseLong(in.substring(0, in.length()-1)) * 3600000L;
} else if (in.endsWith("d")){
return Long.parseLong(in.substring(0, in.length()-1)) * 86400000L;
} else if (in.endsWith("w")){
return Long.parseLong(in.substring(0, in.length()-1)) * 604800000L;
} else if (in.endsWith("mo")){
return Long.parseLong(in.substring(0, in.length()-2)) * 2592000000L;
} else if (in.endsWith("y")){
return Long.parseLong(in.substring(0, in.length()-1)) * 31536000000L;
} else {
return -1;
}
}
}