当前位置: 首页>>代码示例>>Java>>正文


Java DataTransactionResult类代码示例

本文整理汇总了Java中org.spongepowered.api.data.DataTransactionResult的典型用法代码示例。如果您正苦于以下问题:Java DataTransactionResult类的具体用法?Java DataTransactionResult怎么用?Java DataTransactionResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DataTransactionResult类属于org.spongepowered.api.data包,在下文中一共展示了DataTransactionResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setModel

import org.spongepowered.api.data.DataTransactionResult; //导入依赖的package包/类
@Override
public final void setModel(String model) {
    if(!getDefinition().getModels().contains(model))
        throw new IllegalArgumentException("This custom tool has no model called '" + model
                + "'. Available, defined models: "
                + getDefinition().getModels().stream().collect(Collectors.joining(", ")));

    applyModel(model);

    DataTransactionResult result = getDataHolder().offer(CustomItemLibraryKeys.CUSTOM_FEATURE_MODEL, model);

    if(!result.isSuccessful())
        throw new IllegalStateException("Could not update the item model; rejected: " + result.getRejectedData()
                + "; replaced: " + result.getReplacedData());
}
 
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:16,代码来源:AbstractCustomModelledFeature.java

示例2: awardPlayer

import org.spongepowered.api.data.DataTransactionResult; //导入依赖的package包/类
@Override
public boolean awardPlayer(Player player) {
    final Optional<Integer> expAmountOpt = Util.safeGetInt(this.data, "amount");
    if (!expAmountOpt.isPresent()) {
        this.plugin.getLogger().error("No experience amount specified. Aborting.");
        return false;
    }

    int existingExperience = player.get(Keys.TOTAL_EXPERIENCE).get();

    DataTransactionResult result = player.offer(Keys.TOTAL_EXPERIENCE, existingExperience + expAmountOpt.get());
    return result.isSuccessful();
}
 
开发者ID:BadgeUp,项目名称:badgeup-sponge-client,代码行数:14,代码来源:ExperienceAward.java

示例3: awardPlayer

import org.spongepowered.api.data.DataTransactionResult; //导入依赖的package包/类
@Override
public boolean awardPlayer(Player player) {
    final Optional<String> potionEffectTypeIDOpt = Util.safeGetString(this.data, "potionEffectType");
    if (!potionEffectTypeIDOpt.isPresent()) {
        this.plugin.getLogger().error("No potion effect type specified. Aborting.");
        return false;
    }

    String potionEffectTypeID = potionEffectTypeIDOpt.get();

    final Optional<PotionEffectType> optType = Sponge.getRegistry().getType(PotionEffectType.class,
            potionEffectTypeID);
    if (!optType.isPresent()) {
        this.plugin.getLogger().error("Potion effect type " + potionEffectTypeID + " not found. Aborting.");
        return false;
    }

    PotionEffect.Builder builder = Sponge.getRegistry().createBuilder(PotionEffect.Builder.class)
            .potionType(optType.get());

    Optional<Integer> durationOpt = Util.safeGetInt(this.data, "duration");
    if (!durationOpt.isPresent()) {
        this.plugin.getLogger().error("Potion effect duration not specified. Aborting.");
        return false;
    }
    builder.duration(durationOpt.get());

    builder.amplifier(Util.safeGetInt(this.data, "amplifier").orElse(1));

    List<PotionEffect> currentEffects = player.get(Keys.POTION_EFFECTS).orElse(new ArrayList<>());
    currentEffects.add(builder.build());

    DataTransactionResult result = player.offer(Keys.POTION_EFFECTS, currentEffects);
    return result.isSuccessful();
}
 
开发者ID:BadgeUp,项目名称:badgeup-sponge-client,代码行数:36,代码来源:PotionEffectAward.java

示例4: registerKeys

import org.spongepowered.api.data.DataTransactionResult; //导入依赖的package包/类
@Override
public void registerKeys() {
    super.registerKeys();
    final ValueCollection c = getValueCollection();
    c.register(Keys.DISPLAY_NAME, null);
    c.registerProcessor(LanternKeys.INVENTORY_SNAPSHOT).add(builder -> builder
            .offerHandler(((key, valueContainer, inventorySnapshot) -> {
                this.inventory.clear();
                inventorySnapshot.offerTo(this.inventory);
                return DataTransactionResult.successNoData();
            }))
            .failAlwaysRemoveHandler()
            .retrieveHandler((key, valueContainer) -> Optional.of(InventorySnapshot.ofInventory(this.inventory))));
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:15,代码来源:LanternShulkerBox.java

示例5: execute

import org.spongepowered.api.data.DataTransactionResult; //导入依赖的package包/类
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	int number = ctx.<Integer> getOne("number").get();

	if (src instanceof Player)
	{
		Player player = (Player) src;

		if (player.getItemInHand(HandTypes.MAIN_HAND).isPresent())
		{
			ItemStack stack = player.getItemInHand(HandTypes.MAIN_HAND).get();
			LoreData loreData = stack.getOrCreate(LoreData.class).get();
			List<Text> newLore = loreData.lore().get();
			newLore.remove(number - 1);
			DataTransactionResult dataTransactionResult = stack.offer(Keys.ITEM_LORE, newLore);

			if (dataTransactionResult.isSuccessful())
			{
				player.setItemInHand(HandTypes.MAIN_HAND, stack);
				src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Removed lore from item."));
			}
			else
			{
				src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Could not remove lore from item."));
			}
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be holding an item!"));
		}
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be a player to name items."));
	}
	return CommandResult.success();
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:38,代码来源:LoreBase.java

示例6: copyFromNoEvents

import org.spongepowered.api.data.DataTransactionResult; //导入依赖的package包/类
default DataTransactionResult copyFromNoEvents(DataHolder that, MergeFunction function) {
    final Collection<DataManipulator<?, ?>> containers = that.getContainers();
    final DataTransactionResult.Builder builder = DataTransactionResult.builder();
    boolean success = false;
    for (DataManipulator<?, ?> thatContainer : containers) {
        final DataManipulator<?, ?> thisContainer = get(thatContainer.getClass()).orElse(null);
        final DataManipulator<?, ?> merged = function.merge(thisContainer, thatContainer);
        final DataTransactionResult result = offerNoEvents(merged, MergeFunction.IGNORE_ALL);
        builder.absorbResult(result);
        if (!result.getSuccessfulData().isEmpty()) {
            success = true;
        }
    }
    return builder.result(success ? DataTransactionResult.Type.SUCCESS : DataTransactionResult.Type.FAILURE).build();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:16,代码来源:IDataHolder.java

示例7: execute

import org.spongepowered.api.data.DataTransactionResult; //导入依赖的package包/类
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	String name = ctx.<String> getOne("name").get();

	if (src instanceof Player)
	{
		Player player = (Player) src;

		if (player.getItemInHand(HandTypes.MAIN_HAND).isPresent())
		{
			ItemStack stack = player.getItemInHand(HandTypes.MAIN_HAND).get();
			Text textName = TextSerializers.FORMATTING_CODE.deserialize(name);
			DataTransactionResult dataTransactionResult = stack.offer(Keys.DISPLAY_NAME, textName);
			
			if(dataTransactionResult.isSuccessful())
			{
				player.setItemInHand(HandTypes.MAIN_HAND, stack);
				src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Set name on item."));
			}
			else
			{
				src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Could not set name on item."));
			}
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be holding an item!"));
		}
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be a player to name items."));
	}

	return CommandResult.success();
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:37,代码来源:SetNameExecutor.java

示例8: signChange

import org.spongepowered.api.data.DataTransactionResult; //导入依赖的package包/类
@Listener
public void signChange(ChangeSignEvent event) throws Exception {
    ListValue<Text> lines = event.getText().lines();

    // Check that the first line is [warp]
    if (lines.get(0).toPlain().equalsIgnoreCase(Constants.WARP_SIGN_PREFIX)) {
        // Second line has to be the name of the warp
        String warpName = lines.get(1).toPlain();
        Optional<Warp> optWarp = this.plugin.getWarpManager().getOne(warpName);
        if (!optWarp.isPresent()) {
            return;
        }
        event.getText().set(Util.generateWarpSignData(optWarp.get()).getValues());

        WarpDataManipulatorBuilder builder = (WarpDataManipulatorBuilder) Sponge.getDataManager().getManipulatorBuilder(WarpData.class).get();
        WarpData data = builder.createFrom(optWarp.get());
        DataTransactionResult result = event.getTargetTile().offer(data);

        if (!result.isSuccessful()) {
            // Couldn't offer WarpData to the sign - log in the console and
            // warn the possible player that placed the sign
            String error =
                    "Failed to offer WarpData " + data.toContainer().toString() + " to the Sign at "
                            + event.getTargetTile().getLocation().toString();
            plugin.getLogger().warn(error);
            Optional<Player> optPlayer = event.getCause().first(Player.class);
            if (optPlayer.isPresent()) {
                optPlayer.get().sendMessage(Text.of(TextColors.RED, Constants.PREFIX, " ", error));
            }

        }
    }

}
 
开发者ID:RobertHerhold,项目名称:BLWarps,代码行数:35,代码来源:ChangeSignEventHandler.java

示例9: getKeys

import org.spongepowered.api.data.DataTransactionResult; //导入依赖的package包/类
protected static Set<Key<?>> getKeys(DataTransactionResult result) {
    final Set<Key<?>> keys = new HashSet<>();
    result.getReplacedData().forEach(value -> keys.add(value.getKey()));
    result.getSuccessfulData().forEach(value -> keys.add(value.getKey()));
    // We don't need the rejected keys, they didn't modify any values
    return keys;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:8,代码来源:CompositeValueStoreHelper.java

示例10: undoFast

import org.spongepowered.api.data.DataTransactionResult; //导入依赖的package包/类
protected static <H extends ValueContainer<?>> boolean undoFast(ICompositeValueStore<?, H> store, DataTransactionResult result) {
    final boolean hasListeners = hasListeners(store, getKeys(result));
    if (hasListeners) {
        return undo(store, result, () -> true).isSuccessful();
    }
    return store.undoFastNoEvents(result);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:8,代码来源:CompositeValueStoreHelper.java

示例11: offerNoEvents

import org.spongepowered.api.data.DataTransactionResult; //导入依赖的package包/类
default DataTransactionResult offerNoEvents(Iterable<H> valueContainers, MergeFunction function) {
    final DataTransactionResult.Builder builder = DataTransactionResult.builder();
    for (H valueContainer : valueContainers) {
        builder.absorbResult(offerNoEvents(valueContainer, function));
    }
    return builder.build();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:8,代码来源:ICompositeValueStore.java

示例12: offer

import org.spongepowered.api.data.DataTransactionResult; //导入依赖的package包/类
protected static <H extends ValueContainer<?>> DataTransactionResult offer(ICompositeValueStore<?, H> store,
        Iterable<H> valueContainers, MergeFunction function) {
    return offer(store, valueContainers, function, () -> {
        final Set<Key<?>> keys = new HashSet<>();
        for (H valueContainer : valueContainers) {
            keys.addAll(valueContainer.getKeys());
        }
        return hasListeners(store, keys);
    });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:11,代码来源:CompositeValueStoreHelper.java

示例13: removeFrom

import org.spongepowered.api.data.DataTransactionResult; //导入依赖的package包/类
@Override
public DataTransactionResult removeFrom(IValueContainer<?> valueContainer) {
    DataTransactionResult result = null;
    for (Processor<V, E> processor : this.processors) {
        result = processor.removeFrom(valueContainer);
        if (result.isSuccessful()) {
            return result;
        }
    }
    return result == null ? DataTransactionResult.failNoData() : result;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:12,代码来源:SimpleProcessorKeyRegistration.java

示例14: offerTo

import org.spongepowered.api.data.DataTransactionResult; //导入依赖的package包/类
@Override
public DataTransactionResult offerTo(IValueContainer<?> valueContainer, E element) {
    DataTransactionResult result = null;
    for (Processor<V, E> processor : this.processors) {
        result = processor.offerTo(valueContainer, element);
        if (result.isSuccessful()) {
            return result;
        }
    }
    return result == null ? DataTransactionResult.failNoData() : result;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:12,代码来源:SimpleProcessorKeyRegistration.java

示例15: offerTo

import org.spongepowered.api.data.DataTransactionResult; //导入依赖的package包/类
@Override
public DataTransactionResult offerTo(IValueContainer<?> valueContainer, E element) {
    if (!isApplicableTo(valueContainer)) {
        return DataTransactionResult.failNoData();
    }
    return isApplicableTo(valueContainer) ? this.offerHandler.offer(valueContainer, getKey(), element) : DataTransactionResult.failNoData();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:8,代码来源:SimpleValueProcessor.java


注:本文中的org.spongepowered.api.data.DataTransactionResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。