SteamWar/SpigotCore
Archiviert
13
0

Add SWCommandUtils.addMapper

Dieser Commit ist enthalten in:
yoyosource 2021-03-13 16:02:44 +01:00
Ursprung d028b27ec5
Commit 03bbdcfe29

Datei anzeigen

@ -61,7 +61,7 @@ class SWCommandUtils {
}; };
static { static {
MAPPER_FUNCTIONS.put(boolean.class, new TypeMapper<Boolean>() { addMapper(boolean.class, Boolean.class, new TypeMapper<Boolean>() {
@Override @Override
public Boolean map(String s) { public Boolean map(String s) {
return Boolean.parseBoolean(s); return Boolean.parseBoolean(s);
@ -72,18 +72,7 @@ class SWCommandUtils {
return Arrays.asList("true", "false"); return Arrays.asList("true", "false");
} }
}); });
MAPPER_FUNCTIONS.put(Boolean.class, new TypeMapper<Boolean>() { addMapper(float.class, Float.class, new TypeMapper<Float>() {
@Override
public Boolean map(String s) {
return Boolean.parseBoolean(s);
}
@Override
public List<String> tabCompletes(String s) {
return Arrays.asList("true", "false");
}
});
MAPPER_FUNCTIONS.put(float.class, new TypeMapper<Float>() {
@Override @Override
public Float map(String s) { public Float map(String s) {
return Float.parseFloat(s); return Float.parseFloat(s);
@ -99,23 +88,7 @@ class SWCommandUtils {
} }
} }
}); });
MAPPER_FUNCTIONS.put(Float.class, new TypeMapper<Float>() { addMapper(double.class, Double.class, new TypeMapper<Double>() {
@Override
public Float map(String s) {
return Float.parseFloat(s);
}
@Override
public List<String> tabCompletes(String s) {
try {
Float.parseFloat(s);
return Collections.singletonList(s);
} catch (NumberFormatException e) {
return Collections.emptyList();
}
}
});
MAPPER_FUNCTIONS.put(double.class, new TypeMapper<Double>() {
@Override @Override
public Double map(String s) { public Double map(String s) {
return Double.parseDouble(s); return Double.parseDouble(s);
@ -131,39 +104,7 @@ class SWCommandUtils {
} }
} }
}); });
MAPPER_FUNCTIONS.put(Double.class, new TypeMapper<Double>() { addMapper(int.class, Integer.class, new TypeMapper<Integer>() {
@Override
public Double map(String s) {
return Double.parseDouble(s);
}
@Override
public List<String> tabCompletes(String s) {
try {
Double.parseDouble(s);
return Collections.singletonList(s);
} catch (NumberFormatException e) {
return Collections.emptyList();
}
}
});
MAPPER_FUNCTIONS.put(int.class, new TypeMapper<Integer>() {
@Override
public Integer map(String s) {
return Integer.parseInt(s);
}
@Override
public List<String> tabCompletes(String s) {
try {
Integer.parseInt(s);
return Collections.singletonList(s);
} catch (NumberFormatException e) {
return Collections.emptyList();
}
}
});
MAPPER_FUNCTIONS.put(Integer.class, new TypeMapper<Integer>() {
@Override @Override
public Integer map(String s) { public Integer map(String s) {
return Integer.parseInt(s); return Integer.parseInt(s);
@ -214,6 +155,11 @@ class SWCommandUtils {
}); });
} }
private static void addMapper(Class<?> clazz, Class<?> alternativeClazz, TypeMapper<?> mapper) {
MAPPER_FUNCTIONS.put(clazz, mapper);
MAPPER_FUNCTIONS.put(alternativeClazz, mapper);
}
static final CommandMap commandMap; static final CommandMap commandMap;
static { static {