Java Code Examples for org.bukkit.material.MaterialData#getData()

The following examples show how to use org.bukkit.material.MaterialData#getData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CraftParticle.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public static int[] toData(Particle particle, Object obj) {
    if (particle.getDataType().equals(Void.class)) {
        return new int[0];
    }
    if (particle.getDataType().equals(ItemStack.class)) {
        if (obj == null) {
            return new int[]{0, 0};
        }
        ItemStack itemStack = (ItemStack) obj;
        return new int[]{itemStack.getType().getId(), itemStack.getDurability()};
    }
    if (particle.getDataType().equals(MaterialData.class)) {
        if (obj == null) {
            return new int[]{0};
        }
        MaterialData data = (MaterialData) obj;
        return new int[]{data.getItemTypeId() + ((int) (data.getData()) << 12)};
    }
    throw new IllegalArgumentException(particle.getDataType().toString());
}
 
Example 2
Source File: CraftingModuleBuilder.java    From CardinalPGM with MIT License 6 votes vote down vote up
@Override
public ModuleCollection<CraftingModule> load(Match match) {
    Set<AbstractRecipe> recipes = new HashSet<>();
    Set<Material> disabledMaterials = new HashSet<>();
    Set<MaterialData> disabledMaterialData = new HashSet<>();
    for (Element crafting : match.getDocument().getRootElement().getChildren("crafting")) {
        for (Element shaped : crafting.getChildren("shaped"))
            recipes.add(addOverrides(getShapedRecipe(shaped), shaped));
        for (Element shapeless : crafting.getChildren("shapeless"))
            recipes.add(addOverrides(getShapelessRecipe(shapeless), shapeless));
        for (Element smelt : crafting.getChildren("smelt"))
            recipes.add(addOverrides(getSmeltRecipe(smelt), smelt));
        for (Element disable : crafting.getChildren("disable")) {
            MaterialData data = Parser.parseMaterialData(disable.getText());
            if ((data.getData() == -1))
                disabledMaterials.add(data.getItemType());
            else
                disabledMaterialData.add(data);
        }
    }
    for (AbstractRecipe recipe : recipes) {
        if (recipe.getOverride()) disabledMaterialData.add(recipe.getRecipe().getResult().getData());
        if (recipe.getOverrideAll()) disabledMaterials.add(recipe.getRecipe().getResult().getType());
    }
    return new ModuleCollection<>(new CraftingModule(recipes, disabledMaterials, disabledMaterialData));
}
 
Example 3
Source File: FlagVote.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
	SpleefPlayer player = heavySpleef.getSpleefPlayer(event.getPlayer());
	GameManager manager = heavySpleef.getGameManager();
	
	Game game = manager.getGame(player);
	if (game == null) {
		return;
	}
	
	if (!game.isFlagPresent(FlagVote.class)) {
		return;
	}
	
	DefaultConfig config = heavySpleef.getConfiguration(ConfigType.DEFAULT_CONFIG);
	FlagSection section = config.getFlagSection();
	MaterialData readyBlock = section.getReadyBlock();
	
	Block clickedBlock = event.getClickedBlock();
	if (clickedBlock == null || clickedBlock.getType() != readyBlock.getItemType() || clickedBlock.getData() != readyBlock.getData()) {
		return;
	}
	
	if (game.getGameState() != GameState.LOBBY) {
		player.sendMessage(i18n.getString(Messages.Command.FUNCTION_ONLY_IN_LOBBY));
		return;
	}
	
	FlagVote flag = game.getFlag(FlagVote.class);
	boolean success = flag.vote(player, game);
	player.sendMessage(i18n.getString(success ? Messages.Command.SUCCESSFULLY_VOTED : Messages.Command.ALREADY_VOTED));
}
 
Example 4
Source File: SingleMaterialMatcher.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public SingleMaterialMatcher(MaterialData materialData) {
  this.material = materialData.getItemType();
  this.data = materialData.getData();
  this.dataMatters = true;
}
 
Example 5
Source File: SingleMaterialMatcher.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public boolean matches(MaterialData materialData) {
  return materialData.getItemType() == this.material
      && (!this.dataMatters || materialData.getData() == this.data);
}
 
Example 6
Source File: MaterialPattern.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public boolean matches(MaterialData materialData) {
    return materialData.getItemType() == this.material &&
           (!data.isPresent() || data.get() == materialData.getData());
}
 
Example 7
Source File: ItemManager.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public static byte getData(MaterialData data) {
	return data.getData();
}
 
Example 8
Source File: FurnaceRecipe.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Create a furnace recipe to craft the specified ItemStack.
 *
 * @param result The item you want the recipe to create.
 * @param source The input material.
 */
public FurnaceRecipe(ItemStack result, MaterialData source) {
    this(result, source.getItemType(), source.getData(), 0);
}
 
Example 9
Source File: FurnaceRecipe.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Create a furnace recipe to craft the specified ItemStack.
 *
 * @param result     The item you want the recipe to create.
 * @param source     The input material.
 * @param experience The experience given by this recipe
 */
public FurnaceRecipe(ItemStack result, MaterialData source, float experience) {
    this(result, source.getItemType(), source.getData(), experience);
}