12
0

WIP: CommandFramework #84

Geschlossen
YoyoNow möchte 53 Commits von CommandFramework nach master mergen
4 geänderte Dateien mit 68 neuen und 4 gelöschten Zeilen
Nur Änderungen aus Commit 96eb3e52ae werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -31,8 +31,8 @@ public class Argument<T> {
public static final Argument<Integer> INT = new Argument<>(ArgumentType.INT, integer -> true);
public static final Argument<Long> LONG = new Argument<>(ArgumentType.LONG, l -> true);
public static final Argument<Float> FLOAT = new Argument<>(ArgumentType.FLOAT, integer -> true);
public static final Argument<Double> DOUBLE = new Argument<>(ArgumentType.DOUBLE, integer -> true);
public static final Argument<Float> FLOAT = new Argument<>(ArgumentType.FLOAT, f -> true);
public static final Argument<Double> DOUBLE = new Argument<>(ArgumentType.DOUBLE, d -> true);
public static final Argument<String> STRING = new Argument<>(ArgumentType.STRING, string -> true);
public static final Argument<String> PLAYER = new Argument<>(ArgumentType.STRING, string -> Bukkit.getPlayer(string) == null, Bukkit::getPlayer);
@ -50,6 +50,14 @@ public class Argument<T> {
this.valueMapper = valueMapper;
}
public static Argument<String> of(String argument) {
return new Argument<>(ArgumentType.STRING, string -> string.equals(argument));
}
public static Argument<String> ofIgnoreCase(String argument) {
return new Argument<>(ArgumentType.STRING, string -> string.equalsIgnoreCase(argument));
}
public Optional<?> valueSupplier(String s) {
try {
T argumentMapped = argumentType.mapper.apply(s);

Datei anzeigen

@ -0,0 +1,56 @@
/*
*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* /
*/
package de.steamwar.command;
import java.util.Arrays;
public class ArgumentMap {
private Object[] objects;
public ArgumentMap(Object[] objects) {
this.objects = objects;
}
public int length() {
return objects.length;
}
public <T> T get(int index) {
return (T)objects[index];
}
@Override
public String toString() {
StringBuilder st = new StringBuilder();
st.append("ArgumentMap{");
boolean b = false;
for (Object o : objects) {
if (b) st.append(", ");
b = true;
st.append(o.getClass().getSimpleName()).append("=").append(o);
}
st.append("}");
return st.toString();
}
}

Datei anzeigen

@ -25,5 +25,5 @@ import org.bukkit.entity.Player;
@FunctionalInterface
public interface Executor {
boolean execute(Player player, Object[] args);
boolean execute(Player player, ArgumentMap argumentMap);
}

Datei anzeigen

@ -56,7 +56,7 @@ public class SWCommand {
if (!optional.isPresent()) throw new IllegalStateException();
objects[i] = optional.get();
}
return Optional.of(executor.execute(player, objects));
return Optional.of(executor.execute(player, new ArgumentMap(objects)));
}
}