本文整理汇总了Java中org.spongepowered.api.data.manipulator.mutable.item.DurabilityData类的典型用法代码示例。如果您正苦于以下问题:Java DurabilityData类的具体用法?Java DurabilityData怎么用?Java DurabilityData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DurabilityData类属于org.spongepowered.api.data.manipulator.mutable.item包,在下文中一共展示了DurabilityData类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: execute
import org.spongepowered.api.data.manipulator.mutable.item.DurabilityData; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
checkIfPlayer(sender);
checkPermission(sender, ItemPermissions.UC_ITEM_ITEMDURABILITY_BASE);
Player p = (Player) sender;
if (!p.getItemInHand(HandTypes.MAIN_HAND).isPresent() || p.getItemInHand(HandTypes.MAIN_HAND).get().getItem().equals(ItemTypes.NONE)) {
throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand"));
}
ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND).get();
int durability = args.<Integer>getOne("durability").get();
if (!stack.supports(DurabilityData.class)) {
throw new ErrorMessageException(Messages.getFormatted(sender, "item.command.itemdurability.notsupported"));
}
if (durability < stack.get(DurabilityData.class).get().durability().getMinValue() || durability > stack.get(DurabilityData.class).get().durability().getMaxValue()) {
throw new ErrorMessageException(Messages.getFormatted(sender, "item.numberinvalid", "%number%", durability));
}
stack.offer(Keys.ITEM_DURABILITY, durability);
p.setItemInHand(HandTypes.MAIN_HAND, stack);
Messages.send(sender, "item.command.itemdurability.success", "%arg%", durability);
return CommandResult.success();
}
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:26,代码来源:ItemdurabilityCommand.java
示例2: getDamageValue
import org.spongepowered.api.data.manipulator.mutable.item.DurabilityData; //导入依赖的package包/类
/**
* Converts a given {@link DataManipulator} value to a raw damage value.
*
* @param data The {@link DataManipulator} value to convert
* @return The raw damage value corresponding to {@code data}, or
* {@code 0} if one cannot be obtained.
*/
public static int getDamageValue(DataManipulator<?, ?> data) {
if (data instanceof VariantData) {
return getDamageValueFromEnum((VariantData) data);
} else if (data instanceof DurabilityData) {
return ((DurabilityData) data).durability().get();
}
return 0;
}
开发者ID:LapisBlue,项目名称:Pore,代码行数:16,代码来源:DurabilityConverter.java
示例3: getItemData
import org.spongepowered.api.data.manipulator.mutable.item.DurabilityData; //导入依赖的package包/类
/**
* Obtains {@link DataManipulator} from an ItemStack.
* @param item The ItemStack to retrieve {@link DataManipulator} from
* @return The obtained {@link DataManipulator}, or {@code null} if none can
* be discerned
*/
@SuppressWarnings("rawtypes") // I tried parameterizing the return value but Java absolutely spazzed out about it
public static DataManipulator getItemData(ItemStack item) {
switch (item.getType()) {
case COAL:
return getItemData(item, COAL_ITEM_DATA, COAL_MAP);
case COOKED_FISH:
return getItemData(item, COOKED_FISH_ITEM_DATA, COOKED_FISH_MAP);
case WOOL:
break;
case INK_SACK:
break;
case STAINED_CLAY:
break;
case STAINED_GLASS:
break;
case STAINED_GLASS_PANE:
return getItemData(item, DYEABLE_DATA, DYE_MAP);
case RAW_FISH:
return getItemData(item, FISH_DATA, FISH_MAP);
case GOLDEN_APPLE:
return getItemData(item, GOLDEN_APPLE_ITEM_DATA, GOLDEN_APPLE_MAP);
default:
Optional<DurabilityData> data =
org.spongepowered.api.item.inventory.ItemStack.builder()
.itemType(MaterialConverter.asItem(item.getType()))
.quantity(1).build().get(DURABILITY_DATA);
if (data.isPresent()) {
return data.get();
} else {
throw new UnsupportedOperationException();
}
}
return null;
}
开发者ID:LapisBlue,项目名称:Pore,代码行数:41,代码来源:DurabilityConverter.java
示例4: DurabilityDataView
import org.spongepowered.api.data.manipulator.mutable.item.DurabilityData; //导入依赖的package包/类
public DurabilityDataView(DurabilityData value) {
super(value);
this.unbreakable = value.unbreakable().get();
this.durability = value.durability().get();
}
开发者ID:Valandur,项目名称:Web-API,代码行数:7,代码来源:DurabilityDataView.java
示例5: execute
import org.spongepowered.api.data.manipulator.mutable.item.DurabilityData; //导入依赖的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();
}
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:43,代码来源:RepairExecutor.java
注:本文中的org.spongepowered.api.data.manipulator.mutable.item.DurabilityData类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论