本文整理汇总了Java中org.spongepowered.api.data.DataTransactionResult.isSuccessful方法的典型用法代码示例。如果您正苦于以下问题:Java DataTransactionResult.isSuccessful方法的具体用法?Java DataTransactionResult.isSuccessful怎么用?Java DataTransactionResult.isSuccessful使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.data.DataTransactionResult
的用法示例。
在下文中一共展示了DataTransactionResult.isSuccessful方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例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();
}
示例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();
}
示例4: 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;
}
示例5: 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;
}
示例6: 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();
}
示例7: execute
import org.spongepowered.api.data.DataTransactionResult; //导入方法依赖的package包/类
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
String lore = ctx.<String> getOne("lore").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();
Text textLore = TextSerializers.FORMATTING_CODE.deserialize(lore);
List<Text> newLore = loreData.lore().get();
newLore.add(textLore);
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, "Added lore to item."));
}
else
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Could not add lore to 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();
}
示例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));
}
}
}
}
示例9: execute
import org.spongepowered.api.data.DataTransactionResult; //导入方法依赖的package包/类
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
if (src instanceof Player)
{
Player player = (Player) src;
if (player.getItemInHand(HandTypes.MAIN_HAND).isPresent())
{
ItemStack stack = player.getItemInHand(HandTypes.MAIN_HAND).get();
if (stack.get(DurabilityData.class).isPresent())
{
DurabilityData durabilityData = stack.get(DurabilityData.class).get();
DataTransactionResult transactionResult = stack.offer(Keys.ITEM_DURABILITY, durabilityData.durability().getMaxValue());
if (transactionResult.isSuccessful())
{
player.setItemInHand(HandTypes.MAIN_HAND, stack);
src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Repaired item in hand."));
}
else
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Failed to repair item."));
}
}
else
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "The item you're holding is not reparable."));
}
}
else
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be holding something to repair!"));
}
}
else
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /repair!"));
}
return CommandResult.success();
}