本文整理汇总了Java中org.spongepowered.api.CatalogType类的典型用法代码示例。如果您正苦于以下问题:Java CatalogType类的具体用法?Java CatalogType怎么用?Java CatalogType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CatalogType类属于org.spongepowered.api包,在下文中一共展示了CatalogType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCatalogType
import org.spongepowered.api.CatalogType; //导入依赖的package包/类
private static CatalogType getCatalogType(String id, LookupType lookupType) throws CommandException {
switch (lookupType) {
case BLOCK_LOOKUP:
Optional<BlockType> block = Sponge.getRegistry().getType(BlockType.class, id);
if (block.isPresent())
return block.get();
throw new CommandException(Text.of(TextColors.RED, "Unknown block id: " + id));
case ITEM_LOOKUP:
Optional<ItemType> item = Sponge.getRegistry().getType(ItemType.class, id);
if (item.isPresent())
return item.get();
throw new CommandException(Text.of(TextColors.RED, "Unknown item id: " + id));
default:
throw new CommandException(Text.of(TextColors.RED, "Could not determine lookup type!"));
}
}
示例2: parseValue
import org.spongepowered.api.CatalogType; //导入依赖的package包/类
@Nullable
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
String arg = args.next().toLowerCase();
// Try
GameRegistry registry = Sponge.getRegistry();
Optional<? extends CatalogType> catalogType = registry.getType(this.type, arg);
if (!catalogType.isPresent() && !arg.contains(":")) {
catalogType = registry.getType(this.type, "minecraft:" + arg);
if (!catalogType.isPresent()) {
catalogType = registry.getType(this.type, "happytrails:" + arg);
}
}
final String trimmedId = catalogType
.map(trail -> trail.getId().contains(":") ? trail.getId().split(":")[1] : trail.getId())
.orElse("");
if (catalogType.isPresent() && source.hasPermission(this.permissionPrefix + trimmedId)) {
return catalogType.get();
}
throw args.createError(Text.of(TextColors.RED, ""));
}
示例3: complete
import org.spongepowered.api.CatalogType; //导入依赖的package包/类
@Override
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
try {
String arg = args.peek().toLowerCase();
return Sponge.getRegistry().getAllOf(this.type).stream()
.filter(x ->
x.getId().startsWith(arg)
|| x.getId().startsWith("happytrails:" + arg)
)
.filter(x -> {
final String trimmedId = x.getId().contains(":") ? x.getId().split(":")[1] : x.getId();
return src.hasPermission(this.permissionPrefix + trimmedId);
})
.map(CatalogType::getId)
.collect(Collectors.toList());
} catch (Exception e) {
return Sponge.getRegistry().getAllOf(this.type).stream().map(CatalogType::getId).collect(Collectors.toList());
}
}
示例4: checkCatalogType
import org.spongepowered.api.CatalogType; //导入依赖的package包/类
public static boolean checkCatalogType(Class clazz, String type, ScriptEvent.ScriptEventData data, Action<String> error, String tname) {
if (!data.switches.containsKey(tname)) {
return true;
}
for (AbstractTagObject ato : ListTag.getFor(error, data.switches.get(tname)).getInternal()) {
Optional<CatalogType> opt = Sponge.getRegistry().getType(clazz, ato.toString());
if (!opt.isPresent()) {
error.run("Invalid " + clazz.getSimpleName() + " type: '" + ato.debug() + "'!");
return false;
}
else if (Utilities.getIdWithoutDefaultPrefix(opt.get().getId()).equals(type)) {
return true;
}
}
return false;
}
示例5: help
import org.spongepowered.api.CatalogType; //导入依赖的package包/类
@Override
public Text help(final CommandSource source) {
Builder build = Text.builder("/" + this.getName() + " <");
List<Text> populator = new ArrayList<Text>();
for (CatalogType type : this.plugin.getGame().getRegistry().getAllOf(PopulatorObject.class)){
populator.add(Text.builder(type.getId().replaceAll("minecraft:", ""))
.onClick(TextActions.suggestCommand("/" + this.getName() + " " + type.getId().replaceAll("minecraft:", "").toUpperCase()))
.build());
}
build.append(Text.joinWith(Text.of("|"), populator));
return build.append(Text.of(">"))
.onClick(TextActions.suggestCommand("/" + this.getName() + " "))
.color(TextColors.RED)
.build();
}
示例6: getRegistry
import org.spongepowered.api.CatalogType; //导入依赖的package包/类
@Endpoint(method = HttpMethod.GET, path = "/:class", perm = "one")
public void getRegistry(ServletData data, String className) {
try {
Class rawType = Class.forName(className);
if (!CatalogType.class.isAssignableFrom(rawType)) {
data.sendError(HttpServletResponse.SC_BAD_REQUEST, "Class must be a CatalogType");
return;
}
Class<? extends CatalogType> type = rawType;
if (registryCache.containsKey(type)) {
data.addData("ok", true, false);
data.addData("types", registryCache.get(type), false);
return;
}
Optional<Collection<? extends CatalogType>> optTypes = WebAPI.runOnMain(() -> Sponge.getRegistry().getAllOf(type));
optTypes.map(types -> registryCache.put(type, types));
data.addData("ok", optTypes.isPresent(), false);
data.addData("types", optTypes.orElse(null), false);
} catch (ClassNotFoundException e) {
data.sendError(HttpServletResponse.SC_NOT_FOUND, "Class " + className + " could not be found");
}
}
示例7: create
import org.spongepowered.api.CatalogType; //导入依赖的package包/类
@Nullable
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
final Class<? super T> raw = type.getRawType();
if (!CatalogType.class.isAssignableFrom(raw)) {
return null;
}
final TypeAdapter<JsonElement> jsonElementTypeAdapter = gson.getAdapter(JsonElement.class);
return new TypeAdapter<T>() {
@Override
public void write(JsonWriter out, T value) throws IOException {
jsonElementTypeAdapter.write(out, new JsonPrimitive(((CatalogType) value).getId()));
}
@Override
public T read(JsonReader in) throws IOException {
final String id = jsonElementTypeAdapter.read(in).getAsString();
//noinspection unchecked
return (T) Sponge.getRegistry().getType((Class<? extends CatalogType>) raw, id).orElseThrow(
() -> new IllegalArgumentException("There does not exist a " + raw.getName() + " with id: " + id));
}
};
}
示例8: constructAll
import org.spongepowered.api.CatalogType; //导入依赖的package包/类
public <T extends CatalogType> Collection<T> constructAll(String assetDirectory, Class<T> objectType) {
final AssetRepository assetRepository = Lantern.getAssetRepository();
return assetRepository.getAssets(assetDirectory, false).stream()
.map(asset -> {
final String assetId = asset.getId();
int index = assetId.lastIndexOf('/');
if (index == -1) {
index = assetId.indexOf(':');
}
String id = assetId.substring(index + 1);
index = id.lastIndexOf('.');
if (index != -1) {
id = id.substring(0, index);
}
try {
return construct(asset, id, objectType);
} catch (Exception e) {
throw new RuntimeException("Failed to construct a " + objectType.getName() + " from the asset: " + assetId, e);
}
})
.collect(ImmutableList.toImmutableList());
}
示例9: construct
import org.spongepowered.api.CatalogType; //导入依赖的package包/类
public <T extends CatalogType> T construct(Asset asset, String id, Class<T> objectType) {
checkNotNull(asset, "asset");
checkNotNull(objectType, "objectType");
checkArgument(this.constructorClasses.containsKey(objectType),
"The object type %s isn't supported!", objectType.getName());
final Class<?> constructorClass = this.constructorClasses.get(objectType);
final CatalogTypeConstructor<T> constructor;
try (final InputStream is = asset.getUrl().openStream()) {
final InputStreamReader reader = new InputStreamReader(is);
constructor = (CatalogTypeConstructor<T>) this.gson.fromJson(reader, constructorClass);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
final String pluginId = asset.getOwner().getId();
return constructor.create(pluginId, id);
}
示例10: getSerializableList
import org.spongepowered.api.CatalogType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T extends DataSerializable> Optional<List<T>> getSerializableList(DataQuery path, Class<T> clazz) {
checkNotNull(path, "path");
checkNotNull(clazz, "clazz");
return Stream.<Supplier<Optional<List<T>>>>of(
() -> {
if (clazz.isAssignableFrom(CatalogType.class)) {
return (Optional<List<T>>) (Optional<?>) getCatalogTypeList(path, (Class<? extends CatalogType>) clazz);
}
return Optional.empty();
},
() -> getViewList(path)
.flatMap(list -> Sponge.getDataManager().getBuilder(clazz)
.map(builder -> list.stream()
.map(builder::build)
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList()))))
.map(Supplier::get)
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst();
}
示例11: getConverter
import org.spongepowered.api.CatalogType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> Function<String, T> getConverter(final Class<T> type, String converterKey) {
if (!converters.containsKey(converterKey)) {
try {
final Method valueOf = type.getMethod("valueOf", String.class);
converters.put(converterKey, LanternSelectorFactory.<String, T>methodAsFunction(valueOf, true));
} catch (NoSuchMethodException ignored) {
if (CatalogType.class.isAssignableFrom(type)) {
Class<? extends CatalogType> type2 = type.asSubclass(CatalogType.class);
converters.put(converterKey, input -> (T) Sponge.getRegistry()
.getType(type2, input).get());
} else {
throw new IllegalStateException("Can't convert " + type);
}
} catch (SecurityException e) {
Lantern.getLogger().warn("There occurred a security exception", e);
}
}
return (Function<String, T>) converters.get(converterKey);
}
示例12: tabCompleteInternalStatisticOrAchievementName
import org.spongepowered.api.CatalogType; //导入依赖的package包/类
@Override
public List<String> tabCompleteInternalStatisticOrAchievementName(String token, List<String> completions) {
List<String> found = StringUtil.copyPartialMatches(
token,
Iterables.transform(Pore.getGame().getRegistry().getAllOf(Achievement.class), //TODO is this right?
CatalogType::getName),
completions
);
found.addAll(StringUtil.copyPartialMatches(
token,
Iterables.transform(
Pore.getGame().getRegistry().getAllOf(org.spongepowered.api.statistic.Statistic.class),
CatalogType::getName), //TODO is this right?
completions
));
return found;
}
示例13: LookupLine
import org.spongepowered.api.CatalogType; //导入依赖的package包/类
public LookupLine(Vector3i pos, UUID world, ActionType type, String cause, String data, CatalogType target,
int count, int slot, boolean rolledBack, long timestamp) {
this.pos = pos;
this.world = world;
this.type = type;
this.cause = cause;
this.target = target;
this.count = count;
this.slot = slot;
this.data = data;
this.rolledBack = rolledBack;
this.timestamp = timestamp;
}
示例14: getQueryCondition
import org.spongepowered.api.CatalogType; //导入依赖的package包/类
@Override
public String getQueryCondition(LookupType lookupType) {
Iterator<CatalogType> iter = include.iterator();
String result = "(AS_Id.value = '" + iter.next().getId() + "'";
while (iter.hasNext()) {
result += " OR AS_Id.value = '" + iter.next().getId() + "'";
}
result += ")";
return result;
}
示例15: getQueryCondition
import org.spongepowered.api.CatalogType; //导入依赖的package包/类
@Override
public String getQueryCondition(LookupType lookupType) {
Iterator<CatalogType> iter = exclude.iterator();
String result = "NOT (AS_Id.value = '" + iter.next().getId() + "'";
while (iter.hasNext()) {
result += " OR AS_Id.value = '" + iter.next().getId() + "'";
}
result += ")";
return result;
}