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


Java ItemType.getId方法代码示例

本文整理汇总了Java中org.spongepowered.api.item.ItemType.getId方法的典型用法代码示例。如果您正苦于以下问题:Java ItemType.getId方法的具体用法?Java ItemType.getId怎么用?Java ItemType.getId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.spongepowered.api.item.ItemType的用法示例。


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

示例1: onInteractBlockPrimaryMain

import org.spongepowered.api.item.ItemType; //导入方法依赖的package包/类
@Listener
public void onInteractBlockPrimaryMain(InteractBlockEvent.Primary event, @Root Player player) {
    Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
    if(itemStackOptional.isPresent()) {

        BlockState blockState = event.getTargetBlock().getState();
        String blockTypeId = blockState.getType().getId();
        String blockStateId = blockState.getId();

        ItemType itemType = itemStackOptional.get().getType();
        String itemId = itemType.getId();

        PermHandler ph = PermHandler.getInstance();

        if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + blockTypeId + ".primary",
                "protectionperms.item.use." + itemId + ".on." + blockStateId + ".primary")) {
            event.setCancelled(true);
            player.sendMessage(ChatTypes.ACTION_BAR,
                    Text.of(TextColors.RED, "You don't have permission to primary use " + itemType.getName() + " on " + blockState.getName() + '!'));
        }
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:23,代码来源:PrimaryBlockListener.java

示例2: onInteractBlockSecondaryMain

import org.spongepowered.api.item.ItemType; //导入方法依赖的package包/类
@Listener
public void onInteractBlockSecondaryMain(InteractBlockEvent.Secondary event, @Root Player player) {
    Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
    if(itemStackOptional.isPresent()) {

        BlockState blockState = event.getTargetBlock().getState();
        String blockTypeId = blockState.getType().getId();
        String blockStateId = blockState.getId();

        ItemType itemType = itemStackOptional.get().getType();
        String itemId = itemType.getId();

        PermHandler ph = PermHandler.getInstance();

        if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + blockTypeId + ".secondary",
                "protectionperms.item.use." + itemId + ".on." + blockStateId + ".secondary")) {
            event.setCancelled(true);
            player.sendMessage(ChatTypes.ACTION_BAR,
                    Text.of(TextColors.RED, "You don't have permission to secondary use " + itemType.getName() + " on " + blockState.getName() + '!'));
        }
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:23,代码来源:SecondaryBlockListener.java

示例3: onInteractEntitySecondaryMain

import org.spongepowered.api.item.ItemType; //导入方法依赖的package包/类
@Listener
public void onInteractEntitySecondaryMain(InteractEntityEvent.Secondary event, @Root Player player) {
    Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
    if(itemStackOptional.isPresent()) {

        EntityType entityType = event.getTargetEntity().getType();
        String entityId = entityType.getId();

        ItemType itemType = itemStackOptional.get().getType();
        String itemId = itemType.getId();

        PermHandler ph = PermHandler.getInstance();

        if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + entityId + ".primary")) {
            event.setCancelled(true);
            player.sendMessage(ChatTypes.ACTION_BAR,
                    Text.of(TextColors.RED, "You don't have permission to secondary use " + itemType.getName() + " on " + entityType.getName() + "s!"));
        }
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:21,代码来源:SecondaryEntityListener.java

示例4: onInteractEntityPrimaryMain

import org.spongepowered.api.item.ItemType; //导入方法依赖的package包/类
@Listener
public void onInteractEntityPrimaryMain(InteractEntityEvent.Primary event, @Root Player player) {
    Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
    if(itemStackOptional.isPresent()) {

        EntityType entityType = event.getTargetEntity().getType();
        String entityId = entityType.getId();

        ItemType itemType = itemStackOptional.get().getType();
        String itemId = itemType.getId();

        PermHandler ph = PermHandler.getInstance();

        if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + entityId + ".primary")) {
            event.setCancelled(true);
            player.sendMessage(ChatTypes.ACTION_BAR,
                    Text.of(TextColors.RED, "You don't have permission to primary use " + itemType.getName() + " on " + entityType.getName() + "s!"));
        }
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:21,代码来源:PrimaryEntityListener.java

示例5: BlockChunkLoaderConfig

import org.spongepowered.api.item.ItemType; //导入方法依赖的package包/类
public BlockChunkLoaderConfig(String name, String duration, boolean afk, BlockType block, ItemType item, ItemType fuel, String fuelDuration) {
	super(name, duration, afk);
	this.blockId = block.getId();
	this.itemId = item.getId();
	this.fuel = fuel.getId();
	this.fuelDuration = fuelDuration;
}
 
开发者ID:DevOnTheRocks,项目名称:StickyChunk,代码行数:8,代码来源:BlockChunkLoaderConfig.java

示例6: onItemUse

import org.spongepowered.api.item.ItemType; //导入方法依赖的package包/类
@Listener
public void onItemUse(UseItemStackEvent.Start event, @Root Player player) {

    ItemType itemType = event.getItemStackInUse().getType();
    String itemId = itemType.getId();

    PermHandler ph = PermHandler.getInstance();

    if (!ph.checkPerm(player, "protectionperms.item.use." + itemId)) {
        event.setCancelled(true);
        player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to use " + itemType.getName() + '!'));
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:14,代码来源:UseItemListener.java

示例7: onItemPickup

import org.spongepowered.api.item.ItemType; //导入方法依赖的package包/类
@Listener
public void onItemPickup(ChangeInventoryEvent.Pickup.Pre event, @Root Player player) {

    ItemType itemType = event.getOriginalStack().getType();
    String itemId = itemType.getId();

    PermHandler ph = PermHandler.getInstance();

    if (!ph.checkPerm(player, "protectionperms.item.pickup." + itemId)) {
        event.setCancelled(true);
        player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to pick up " + itemType.getName() + '!'));
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:14,代码来源:PickupItemListener.java

示例8: ItemTypeView

import org.spongepowered.api.item.ItemType; //导入方法依赖的package包/类
public ItemTypeView(ItemType value) {
    super(value);

    this.id = value.getId();
    this.name = value.getTranslation().get();
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:7,代码来源:ItemTypeView.java

示例9: generateResourcePack

import org.spongepowered.api.item.ItemType; //导入方法依赖的package包/类
public void generateResourcePack(Path directory) {
    for (Map.Entry<ItemType, BiMap<Integer, Identifier>> entry : typeToDurabilityToModelId.entrySet()) {
        ItemType itemType = entry.getKey();
        BiMap<Integer, Identifier> durabilityToModelId = entry.getValue();
        JsonArray modelOverrides = new JsonArray();
        List<Integer> durabilities = Lists.newArrayList(durabilityToModelId.keySet());

        Collections.sort(durabilities, Collections.reverseOrder());

        for (int durability : durabilities) {
            Identifier modelId = durabilityToModelId.get(durability);
            String pluginId = modelId.getNamespace();
            String model = modelId.getValue();

            double damage = 1.0 - (double) durability / (double) CustomToolDefinition.getNumberOfUses(itemType)
                    .orElseThrow(() -> new IllegalStateException("Could not access the max number of uses."));

            JsonObject modelPredicate = new JsonObject();
            modelPredicate.addProperty("damaged", 0);
            modelPredicate.addProperty("damage", damage);

            JsonObject modelJson = new JsonObject();
            DurabilityIdentifier durabilityId = new DurabilityIdentifier(itemType, durability);
            String modelDirectory = durabilityIdToDirectoryName.get(durabilityId);
            modelJson.add("predicate", modelPredicate);
            modelJson.addProperty("model", getFileIdentifier(pluginId, modelDirectory, model));
            modelOverrides.add(modelJson);
        }

        String typeId = itemType.getId();
        String namespace = Identifier.getNamespaceFromIdString(typeId);
        String typeName = Identifier.getValueFromIdString(typeId);
        JsonObject defaultModelPredicate = new JsonObject();
        defaultModelPredicate.addProperty("damaged", 1);
        defaultModelPredicate.addProperty("damage", 0.0);

        JsonObject defaultModel = new JsonObject();
        defaultModel.add("predicate", defaultModelPredicate);
        defaultModel.addProperty("model", getItemModelIdentifier(null, typeName));
        modelOverrides.add(defaultModel);

        JsonObject modelTextures = new JsonObject();
        modelTextures.addProperty("layer0", getItemTextureIdentifier(null, typeName));

        JsonObject descriptorRoot = new JsonObject();
        descriptorRoot.addProperty("parent", getItemModelIdentifier(null, "handheld"));
        descriptorRoot.add("textures", modelTextures);
        descriptorRoot.add("overrides", modelOverrides);

        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        Path modelPath = CustomItemServiceImpl.getDirectoryResourcePack()
                .resolve("assets").resolve(namespace).resolve("models")
                .resolve("item").resolve(typeName + ".json");

        try {
            Files.createDirectories(modelPath.getParent());

            try (Writer writer = new FileWriter(modelPath.toFile())) {
                gson.toJson(descriptorRoot, writer);
            }
        } catch (IOException e) {
            CustomItemLibrary.getInstance().getLogger()
                    .error("Could not write a model file for custom tools.");
            e.printStackTrace();
        }
    }
}
 
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:68,代码来源:DurabilityRegistry.java

示例10: convertToDatabaseColumn

import org.spongepowered.api.item.ItemType; //导入方法依赖的package包/类
@Override
public String convertToDatabaseColumn(ItemType attribute) {
	return attribute.getId();
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:5,代码来源:ItemType2String.java


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