1
mirror of https://github.com/Shiewk/SModeration.git synced 2026-04-28 05:54:16 +02:00
Files
SModeration/src/main/java/de/shiewk/smoderation/paper/util/PlayerUtil.java
T
Shiewk 823093be35 Rework save format and punishment manager
- Punishments are now saved as JSON in files named after their targets
- Each punishment type now has its own Java class
- Each file contains a list of JSON objects that is updated every time something changes (e.g. player muted, banned or unbanned)
- Punishments have a unique ID now; if something changes, the new version is added to the list and overwrites the old version
- 'Undo' has been renamed to 'cancel'
- You can no longer mute or ban players if they are already muted or banned
2026-04-08 16:12:01 +02:00

40 lines
1.2 KiB
Java

package de.shiewk.smoderation.paper.util;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
public final class PlayerUtil {
private PlayerUtil(){}
public static final UUID UUID_CONSOLE = new UUID(0, 0);
public static @NotNull String offlinePlayerName(UUID uuid){
if (uuid.equals(UUID_CONSOLE)){
return "CONSOLE";
}
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
return player.getName() == null ? uuid.toString() : player.getName();
}
public static @Nullable CommandSender senderByUUID(@NotNull UUID uid){
if (uid.equals(UUID_CONSOLE)){
return Bukkit.getConsoleSender();
} else {
return Bukkit.getPlayer(uid);
}
}
public static UUID uuidFromString(String string) {
if (string.length() == 36) {
return UUID.fromString(string);
} else {
return UUID.fromString(string.replaceFirst("(.{8})(.{4})(.{4})(.{4})(.{12})", "$1-$2-$3-$4-$5"));
}
}
}