SteamWar/SpigotCore
Archiviert
13
0
Dieser Commit ist enthalten in:
yoyosource 2021-03-12 10:57:23 +01:00
Ursprung 76b99d20db
Commit 050fcafc71

Datei anzeigen

@ -20,7 +20,6 @@
package de.steamwar.command;
import de.steamwar.sql.Schematic;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
@ -32,7 +31,6 @@ import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class Argument<T> {
@ -64,10 +62,6 @@ public class Argument<T> {
return null;
}, Objects::nonNull, GameMode.class);
public static final Argument<SteamwarUser> USER = new Argument<>(SteamwarUser::get, Objects::nonNull, PLAYER.tabCompletes);
public static final Argument<Schematic> SCHEMATIC = new Argument<>((s, sender) -> {
if (sender instanceof Player) return Schematic.getSchemFromDB(s, ((Player) sender).getUniqueId());
return null;
}, Objects::nonNull, s -> new String[]{""});
private BiFunction<String, CommandSender, T> mapper;
private Predicate<T> constraint;
@ -100,7 +94,7 @@ public class Argument<T> {
T argumentMapped = mapper.apply(s, sender);
if (constraint.test(argumentMapped)) return Optional.ofNullable(argumentMapped);
} catch (Exception e) {
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
// Ignored
}
return Optional.empty();
}
@ -113,9 +107,12 @@ public class Argument<T> {
// Check number constraints if needed
if (numbers.contains(argumentMapped.getClass()) && !constraint.test(argumentMapped)) return Optional.empty();
}
} catch (Exception e) {
// Ignored
}
try {
return Optional.of(Arrays.stream(tabCompletes.apply(s)).filter(t -> t.startsWith(s)).collect(Collectors.toList()));
} catch (Exception e) {
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
return Optional.empty();
}
}