Fix Argument
Dieser Commit ist enthalten in:
Ursprung
76b99d20db
Commit
050fcafc71
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
package de.steamwar.command;
|
package de.steamwar.command;
|
||||||
|
|
||||||
import de.steamwar.sql.Schematic;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@ -32,7 +31,6 @@ import java.util.function.BiFunction;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Argument<T> {
|
public class Argument<T> {
|
||||||
@ -64,10 +62,6 @@ public class Argument<T> {
|
|||||||
return null;
|
return null;
|
||||||
}, Objects::nonNull, GameMode.class);
|
}, Objects::nonNull, GameMode.class);
|
||||||
public static final Argument<SteamwarUser> USER = new Argument<>(SteamwarUser::get, Objects::nonNull, PLAYER.tabCompletes);
|
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 BiFunction<String, CommandSender, T> mapper;
|
||||||
private Predicate<T> constraint;
|
private Predicate<T> constraint;
|
||||||
@ -100,7 +94,7 @@ public class Argument<T> {
|
|||||||
T argumentMapped = mapper.apply(s, sender);
|
T argumentMapped = mapper.apply(s, sender);
|
||||||
if (constraint.test(argumentMapped)) return Optional.ofNullable(argumentMapped);
|
if (constraint.test(argumentMapped)) return Optional.ofNullable(argumentMapped);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
// Ignored
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
@ -113,9 +107,12 @@ public class Argument<T> {
|
|||||||
// Check number constraints if needed
|
// Check number constraints if needed
|
||||||
if (numbers.contains(argumentMapped.getClass()) && !constraint.test(argumentMapped)) return Optional.empty();
|
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()));
|
return Optional.of(Arrays.stream(tabCompletes.apply(s)).filter(t -> t.startsWith(s)).collect(Collectors.toList()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren