Java Code Examples for org.bukkit.Material

The following are top voted examples for showing how to use org.bukkit.Material. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: UltraCore   File: Events.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void onInventoryClick1(InventoryClickEvent event) {
	Player player = (Player) event.getWhoClicked();
	ItemStack is = event.getCurrentItem();
	if ((event.getCurrentItem() != null) && (event.getCurrentItem().getType() != Material.AIR)) {
		if (event.getInventory().getName().equals(ChatColor.DARK_GRAY + "Teleport Menu - Page 1")) {
			event.setCancelled(true);
               for (int i = 0; i < Bukkit.getOnlinePlayers().size(); i++) {   
               Player targetPlayer = (Player) Bukkit.getOnlinePlayers().toArray()[i];
               Location location = player.getLocation();
               if ((event.getCurrentItem().getType() == Material.SKULL_ITEM) && (is.hasItemMeta()) && (is.getItemMeta().getDisplayName().equals(ChatColor.YELLOW + "Teleport to " + ChatColor.GREEN + targetPlayer.getName()))) {
                   player.closeInventory();
                   player.teleport(targetPlayer);
           		player.sendMessage(ChatColor.YELLOW + "You've teleported to " + ChatColor.GREEN + targetPlayer.getDisplayName() + ChatColor.YELLOW + "!");
           		player.playSound(location, Sound.ENTITY_ENDERMEN_TELEPORT, 100, 1);
           		player.playEffect(location, Effect.ENDER_SIGNAL, 1);
           		targetPlayer.playEffect(location, Effect.ENDER_SIGNAL, 1);
               }
               }
           }
	}
}
 
Example 2
Project: Transport-Pipes   File: InventoryUtils.java   Source Code and License 6 votes vote down vote up
public static ItemStack createSkullItemStack(String uuid, String textureValue, String textureSignature) {

		WrappedGameProfile wrappedProfile = new WrappedGameProfile(UUID.fromString(uuid), null);
		wrappedProfile.getProperties().put("textures", new WrappedSignedProperty("textures", textureValue, textureSignature));

		ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
		SkullMeta sm = (SkullMeta) skull.getItemMeta();

		Field profileField = null;
		try {
			profileField = sm.getClass().getDeclaredField("profile");
			profileField.setAccessible(true);
			profileField.set(sm, wrappedProfile.getHandle());
		} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
			e1.printStackTrace();
		}

		skull.setItemMeta(sm);
		return skull;
	}
 
Example 3
Project: SurvivalAPI   File: DiamondFlowerModule.java   Source Code and License 6 votes vote down vote up
/**
 * Chance to drop a diamond when a player breaks a flower
 *
 * @param event Event
 */
@EventHandler
public void onItemSpawn(ItemSpawnEvent event)
{
    if (event.getEntityType() != EntityType.DROPPED_ITEM)
        return;

    if (event.getEntity().hasMetadata("playerDrop"))
        return;

    if (event.getEntity().getItemStack().getType() != Material.YELLOW_FLOWER
            && event.getEntity().getItemStack().getType() != Material.RED_ROSE
            && (event.getEntity().getItemStack().getType() != Material.DOUBLE_PLANT
                || (event.getEntity().getItemStack().getDurability() > 1 && event.getEntity().getItemStack().getDurability() < 4)))
        return;

    if (this.random.nextDouble() <= (double) this.moduleConfiguration.get("chance"))
        event.getEntity().getWorld().dropItemNaturally(event.getLocation(), Meta.addMeta(new ItemStack(Material.DIAMOND, (int) this.moduleConfiguration.get("diamonds"))));

    event.setCancelled(true);
}
 
Example 4
Project: SurvivalAPI   File: FastTreeModule.java   Source Code and License 6 votes vote down vote up
public boolean isNearWood(Block block, int range)
{
    if(range <= 0)
        return false;

    for(BlockFace face : this.faces)
    {
        Block block1 = block.getRelative(face);

        if(block1.getType() == Material.LOG || block1.getType() == Material.LOG_2)
            return true;
        else if((block1.getType() == Material.LEAVES || block1.getType() == Material.LEAVES_2) && this.isNearWood(block1, range-1))
            return true;
    }

    return false;
}
 
Example 5
Project: HCFCore   File: BardClass.java   Source Code and License 6 votes vote down vote up
@Override
public boolean isApplicableFor(Player player) {
    ItemStack helmet = player.getInventory().getHelmet();
    if (helmet == null || helmet.getType() != Material.GOLD_HELMET)
        return false;

    ItemStack chestplate = player.getInventory().getChestplate();
    if (chestplate == null || chestplate.getType() != Material.GOLD_CHESTPLATE)
        return false;

    ItemStack leggings = player.getInventory().getLeggings();
    if (leggings == null || leggings.getType() != Material.GOLD_LEGGINGS)
        return false;

    ItemStack boots = player.getInventory().getBoots();
    return !(boots == null || boots.getType() != Material.GOLD_BOOTS);
}
 
Example 6
Project: SurvivalPlus   File: StarBattleaxeWither.java   Source Code and License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onAttack(EntityDamageByEntityEvent event)
{
	if(event.isCancelled()) return;
	if(event.getDamager() instanceof Player && event.getEntity() instanceof LivingEntity && event.getCause() == DamageCause.ENTITY_ATTACK)
	{
		Player player = (Player)event.getDamager();
		ItemStack mainItem = player.getInventory().getItemInMainHand();
		LivingEntity enemy = (LivingEntity)event.getEntity();

		Random rand = new Random();
		
		if(mainItem.getType() == Material.GOLD_AXE)
		{
			enemy.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 480, 2, false));
			enemy.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 480, 0, false));
           	enemy.getLocation().getWorld().playSound(enemy.getLocation(), Sound.ENTITY_WITHER_SPAWN, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
		}
	}
}
 
Example 7
Project: Debuggery   File: InputFormatterTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testMaterialData() throws InputException {
    Class[] inputTypes = {MaterialData.class};
    String[] input = {"diamond_spade:24"};

    Object[] output = InputFormatter.getTypesFromInput(inputTypes, Arrays.asList(input), null);

    // First let's make sure we didn't lose anything, or get anything
    assertEquals(inputTypes.length, output.length);

    // Next let's make sure everything is the right type
    for (Object object : output) {
        assertTrue(object instanceof MaterialData);
    }

    // Finally, let's make sure the values are correct
    assertSame(((MaterialData) output[0]).getItemType(), Material.DIAMOND_SPADE);
}
 
Example 8
Project: EscapeLag   File: BonemealDupePatch.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void TreeGrowChecker(StructureGrowEvent event) {
    if (ConfigPatch.safetyBonemeal) {
    	if(event.isFromBonemeal() == false) {
    		return;
    	}
    	List<BlockState> blocks = event.getBlocks();
    	int bs = blocks.size();
    	for(int i = 0;i<bs;i++){
    		Block block = blocks.get(i).getBlock();
    		if(block.getType() != Material.AIR && block.getType() != Material.SAPLING && block.getType() != event.getLocation().getBlock().getRelative(BlockFace.DOWN).getType()){
    			event.setCancelled(true);
                if (event.getPlayer() != null) {
                    AzureAPI.log(event.getPlayer(), "§c这棵树生长区域有方块阻挡,请不要尝试利用骨粉BUG!");
                    return;
                }
    		}
    	}
    }
}
 
Example 9
Project: Crescent   File: InventoryTweaksB.java   Source Code and License 6 votes vote down vote up
@Override
public void call(Event event) {
	if (event instanceof InventoryClickEvent) {
		final InventoryClickEvent ice = (InventoryClickEvent) event;

		if (ice.getCurrentItem().getType() == Material.BOWL) {

			final int slot = ice.getSlot();

			if (!slotsChosen.containsKey(slot)) {
				slotsChosen.put(slot, 1);
			} else {
				slotsChosen.put(slot, slotsChosen.get(slot) + 1);
			}

			if (getStackChance() >= 100.0) {
				callback(true);
			}
		}
	}
}
 
Example 10
Project: FactionsXL   File: SetBannerCommand.java   Source Code and License 6 votes vote down vote up
@Override
public void onExecute(String[] args, CommandSender sender) {
    Player player = (Player) sender;
    Faction faction = getSenderFactionOrFromArg(sender, args, 1);
    if (faction == null) {
        return;
    }

    if (!faction.isAdmin(player)) {
        ParsingUtil.sendMessage(sender, FMessage.ERROR_NO_PERMISSION.getMessage());
        return;
    }

    ItemStack item = player.getInventory().getItemInMainHand();
    if (item == null || item.getType() != Material.BANNER) {
        displayHelp(player);
        return;
    }

    faction.setBanner(item);
    faction.sendMessage(FMessage.CMD_SET_BANNER_SUCCESS.getMessage(), player, faction);
}
 
Example 11
Project: AsgardAscension   File: RuneManager.java   Source Code and License 6 votes vote down vote up
private void handleFreeze(Player player, Rune rune) {
	Player target = Utility.getTargetPlayer(player, 10);
	if(target == null || !Utility.canAttack(player, target)) {
		return;
	}
	
	LineEffect eff = new LineEffect(plugin.getEffectManager());
	eff.setEntity(player);
	eff.setTargetEntity(target);
	eff.particle = ParticleEffect.SNOW_SHOVEL;
	eff.start();
	target.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 60, 6));
	target.playSound(target.getLocation(), Sound.ENTITY_SNOWMAN_DEATH, 1F, 1F);
	
	player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
	player.sendMessage(Lang.HEADERS_TOKENS.toString() + Lang.TOKENS_RUNE_APPLY.toString()
		.replaceAll("%s", rune.getName()));
	target.sendMessage(Lang.HEADERS_TOKENS.toString() + Lang.TOKENS_FROZEN.toString()
			.replaceAll("%s", player.getName()));
	finish(player, false);
}
 
Example 12
Project: Kineticraft   File: LazerPuzzle.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void onBlockClick(PlayerInteractEvent evt, Block bk, boolean rightClick) {
    if (!canTrigger() || MetadataManager.updateCooldownSilently(evt.getPlayer(), "lazerBk", 2))
        return;

    int y = getGateLocation().getBlockY();
    Block above = bk.getRelative(BlockFace.UP);
    if (isPuzzle(bk, y, Material.WOOL) && above.getType() == Material.AIR && rightClick) {
        above.setType(Material.DIODE_BLOCK_OFF);
        above.setData((byte) 0);
    }

    // Remove the next
    if (isPuzzle(bk, y + 1, Material.DIODE_BLOCK_OFF)) {
        if (!rightClick) {
            bk.setType(Material.AIR);
            return;
        }

        bk.setData((byte) (bk.getData() >= 3 ? 0 : bk.getData() + 1));
        evt.setCancelled(true);
    }
}
 
Example 13
Project: OpenUHC   File: Overcook.java   Source Code and License 6 votes vote down vote up
/**
 * Handles the action of smelting all items at once, exploding the furnace, and dropping the smelted items on the
 * ground.
 *
 * @param event The event
 */
@EventHandler(ignoreCancelled = true)
public void onFurnaceSmelt(FurnaceSmeltEvent event) {
  ItemStack resultItem = event.getResult();
  final Material result = resultItem.getType();
  //TODO: Verify that the "smelting amount" contains any extra ingredients
  final int amount = ((Furnace) event.getBlock().getState()).getInventory().getSmelting().getAmount();

  event.getSource().setType(Material.AIR);
  resultItem.setType(Material.AIR);

  Block block = event.getBlock();
  block.setType(Material.AIR);
  Location location = block.getLocation().add(0.5, 0.5, 0.5);
  World world = location.getWorld();
  world.createExplosion(location, 7);
  world.dropItem(location, new ItemStack(result, amount));
}
 
Example 14
Project: HCFCore   File: UnRepairableListener.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void onRepair(final PrepareAnvilRepairEvent e) {
    if (e.getInventory().getContents() == null) {
        return;
    }
    for (final ItemStack itemStack : e.getInventory().getContents()) {
        if (!itemStack.hasItemMeta()) {
            return;
        }
        if (!itemStack.getItemMeta().hasLore()) {
            return;
        }
        if (itemStack.getItemMeta().getLore() == null) {
            return;
        }
        for (final String lore : itemStack.getItemMeta().getLore()) {
            final String fixedLore = ChatColor.stripColor(lore.toLowerCase());
            if (fixedLore.contains("no repair") || fixedLore.contains("unrepairable") || fixedLore.contains("norepair") || fixedLore.contains("nofix") || fixedLore.contains("no fix")) {
                e.setCancelled(true);
                e.setResult(new ItemStack(Material.AIR));
                e.getRepairer().closeInventory();
                ((Player)e.getRepairer()).sendMessage(ChatColor.RED + "This item cannot be repaired.");
            }
        }
    }
}
 
Example 15
Project: Uranium   File: CraftBlock.java   Source Code and License 6 votes vote down vote up
public static void dumpMaterials() {
    if (MinecraftServer.getServer().cauldronConfig.dumpMaterials.getValue())
    {
        FMLLog.info("Cauldron Dump Materials is ENABLED. Starting dump...");
        for (int i = 0; i < 32000; i++)
        {
            Material material = Material.getMaterial(i);
            if (material != null)
            {
                FMLLog.info("Found material " + material + " with ID " + i);
            }
        }
        FMLLog.info("Cauldron Dump Materials complete.");
        FMLLog.info("To disable these dumps, set cauldron.dump-materials to false in bukkit.yml.");
    }
}
 
Example 16
Project: ProjectAres   File: Uncarried.java   Source Code and License 6 votes vote down vote up
public Uncarried(Flag flag, Post post, @Nullable Location location) {
    super(flag, post);
    if(location == null) location = flag.getReturnPoint(post);
    this.location = new Location(location.getWorld(),
                                 location.getBlockX() + 0.5,
                                 location.getBlockY(),
                                 location.getBlockZ() + 0.5,
                                 location.getYaw(),
                                 location.getPitch());

    if(!flag.getMatch().getWorld().equals(this.location.getWorld())) {
        throw new IllegalStateException("Tried to place flag in the wrong world");
    }

    Block block = this.location.getBlock();
    if(block.getType() == Material.STANDING_BANNER) {
        // Banner may already be here at match start
        this.oldBlock = BlockStateUtils.cloneWithMaterial(block, Material.AIR);
    } else {
        this.oldBlock = block.getState();
    }
    this.oldBase = block.getRelative(BlockFace.DOWN).getState();
}
 
Example 17
Project: PA   File: AntiGravity.java   Source Code and License 6 votes vote down vote up
@Override
public void play(PAUser u) {
    if (isInCooldown(u, getName())) return;

    final ArmorStand as = (ArmorStand) spawnEntity(u.getLoc(), EntityType.ARMOR_STAND);
    as.setGravity(false);
    as.setSmall(true);
    as.setVisible(false);
    as.setHelmet(new ItemStack(Material.SEA_LANTERN));
    as.setPassenger(u.getPlayer());

    as.teleport(as.getLocation().add(0, 5, 0));

    bt = plugin.getServer().getScheduler().runTaskTimer(plugin, ()-> {
        as.teleport(as.getLocation().add(0, 0.2, 0));

        if (count <= 0) {
            remove(u, as);
            bt.cancel();
            return;
        }
        count--;
    }, 0, 20);
}
 
Example 18
Project: HCFCore   File: KitsCommand.java   Source Code and License 6 votes vote down vote up
private ItemStack titaniumKitGlass(Player player) {
	ItemStack stack = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 0, (byte) 14);
	ItemMeta meta = stack.getItemMeta();
	addGlow(stack);
	meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&4Titanium &7Kit"));
	List<String> lore = new ArrayList<String>();
	lore.add(ChatColor.translateAlternateColorCodes('&', "&7This is a kit contains:"));
	lore.add(ChatColor.translateAlternateColorCodes('&', "&fGod Diamond kit!"));
	lore.add("");
	lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &cPurchase the Titanium Rank from store.hcriots.net"));
	lore.add("");
	lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7CoolDown: &c3 Days"));
	if(cooldowns.containsKey(player.getUniqueId())) {
		if(cooldowns.get(player.getUniqueId()).containsKey("TitaniumKit")) {
			lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &c" + DurationFormatUtils.formatDurationWords(cooldowns.get(player.getUniqueId()).get("TitaniumKit"), true, true)));
		} else {
			lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &aNow"));
		}
	} else {
		lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &aNow"));
	}
	meta.setLore(lore);
	stack.setItemMeta(meta);
	return stack;
}
 
Example 19
Project: Hub   File: StepEffect.java   Source Code and License 6 votes vote down vote up
@Override
public void onRun()
{
    // Prevents an excess of particles
    if (last != null && last.getX() == getEntity().getLocation().getX() && last.getZ() == getEntity().getLocation().getZ())
        return;
    last = getEntity().getLocation();

    Block block = this.getEntity().getLocation().add(0, -0.4, 0).getBlock();
    Material type = block.getType();

    // If the step should be displayed or not
    if (type.isBlock() && type.isSolid() && !type.isTransparent()) {
        Location loc = getEntity().getLocation();
        loc.setY(block.getY());
        loc = loc.add(0, 1 + Math.random() / 100, 0);
        Vector dir = VectorUtils.rotateAroundAxisY(getEntity().getLocation().getDirection().setY(0).normalize(), p ? 90 : -90).multiply(0.25);
        display(ParticleEffect.FOOTSTEP, loc.add(dir.getX(), 0, dir.getZ()), 7, 0);

        p = !p;
    }
}
 
Example 20
Project: NavyCraft2-Lite   File: MoveCraft_PlayerListener.java   Source Code and License 5 votes vote down vote up
public void playerDisableUpdate(final Player player, final Craft craft) {
	plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
		if ((craft != null) && (player != null) && player.isOnline()) {
			craft.doRemove = true;
			if (player.getInventory().contains(Material.GOLD_SWORD)) {
				player.getInventory().remove(Material.GOLD_SWORD);
			}
			player.sendMessage("Vehicle disabled.");
		}
	});
}
 
Example 21
Project: QuarSK   File: SExprBannerBlockLayers.java   Source Code and License 5 votes vote down vote up
@Nullable
@Override
protected Pattern[] get(Event e) {
	Block b = block.getSingle(e);
	if (b == null) {
		return null;
	}
	if (b.getType() == Material.STANDING_BANNER || b.getType() == Material.WALL_BANNER) {
		return ((Banner) b.getState()).getPatterns().stream().toArray(Pattern[]::new);
	}
	return null;
}
 
Example 22
Project: AsgardAscension   File: MainInventory.java   Source Code and License 5 votes vote down vote up
public static void setupInventory(Player player){
	Inventory inv = Bukkit.createInventory(player, 9, ChatColor.BOLD + "Asgard Ascension");
	inv.setItem(0, ItemStackGenerator.createItem(Material.NETHER_STAR, 0, 0, 
			ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Rank-ups and Challenges", null));
	inv.setItem(1, ItemStackGenerator.createItem(Material.DIAMOND, 0, 0,
			ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Ragnorak", null));
	inv.setItem(2, ItemStackGenerator.createItem(Material.GOLDEN_CARROT, 0, 0,
			ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Food of the Gods", null));
	inv.setItem(8, ItemStackGenerator.createItem(Material.REDSTONE_BLOCK, 0, 0,
			ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Reload Configs", null));
	player.openInventory(inv);
}
 
Example 23
Project: AstralEdit   File: DisplayArmorstand.java   Source Code and License 5 votes vote down vote up
/**
 * Initializes the armorstand
 *
 * @param player   player
 * @param location location
 * @param id       id
 * @param data     data
 * @param watchers watchers
 */
public DisplayArmorstand(Player player, Location location, int id, byte data, Set<Player> watchers) {
    super();
    this.watchers = watchers;
    this.player = player;
    this.armorStand = new EntityArmorStand(((CraftWorld) player.getWorld()).getHandle());
    final NBTTagCompound compound = new NBTTagCompound();
    compound.setBoolean("invulnerable", true);
    compound.setBoolean("Invisible", true);
    compound.setBoolean("PersistenceRequired", true);
    compound.setBoolean("NoBasePlate", true);
    this.armorStand.a(compound);
    this.armorStand.setLocation(location.getX(), location.getY(), location.getZ(), 0, 0);
    this.storedId = id;
    this.storedData = data;

    ItemStackBuilder stackBuilder = new ItemStackBuilder(Material.getMaterial(id), 1, data);
    this.getCraftEntity().setHelmet(stackBuilder.build());
    this.getCraftEntity().setBodyPose(new EulerAngle(3.15, 0, 0));
    this.getCraftEntity().setLeftLegPose(new EulerAngle(3.15, 0, 0));
    this.getCraftEntity().setRightLegPose(new EulerAngle(3.15, 0, 0));

    if (((ArmorStand) this.armorStand.getBukkitEntity()).getHelmet().getType() == Material.AIR) {
        stackBuilder = new ItemStackBuilder(Material.SKULL_ITEM, 1, (short) 3);
        if (id == Material.WATER.getId() || id == Material.STATIONARY_WATER.getId()) {
            stackBuilder.setSkin(NMSRegistry.WATER_HEAD);
        } else if (id == Material.LAVA.getId() || id == Material.STATIONARY_LAVA.getId()) {
            stackBuilder.setSkin(NMSRegistry.LAVA_HEAD);
        } else {
            stackBuilder.setSkin(NMSRegistry.NOT_FOUND);
        }
        ((ArmorStand) this.armorStand.getBukkitEntity()).setHelmet(stackBuilder.build());
    }
}
 
Example 24
Project: Slimefun4-Chinese-Version   File: ItemEnergy.java   Source Code and License 5 votes vote down vote up
public static float addStoredEnergy(ItemStack item, float energy)
{
    if(item == null || item.getType() == null || item.getType().equals(Material.AIR))
        return 0.0F;
    if(!item.hasItemMeta() || !item.getItemMeta().hasLore())
        return 0.0F;
    float rest = 0.0F;
    float capacity = getMaxEnergy(item);
    if(capacity == 0.0F)
        return rest;
    float stored = getStoredEnergy(item);
    if(stored + energy > capacity)
    {
        rest = (stored + energy) - capacity;
        stored = capacity;
    } else
    if(stored + energy < 0.0F)
        stored = 0.0F;
    else
        stored += energy;
    List lore = item.getItemMeta().getLore();
    int index = -1;
    for(int i = 0; i < lore.size(); i++)
    {
        String line = (String)lore.get(i);
        if(!line.startsWith(ChatColor.translateAlternateColorCodes('&', "&c&o&8\u21E8 &e\u26A1 &7")) || !line.contains(" / ") || !line.endsWith(" J"))
            continue;
        index = i;
        break;
    }

    BigDecimal decimal = (new BigDecimal(stored)).setScale(2, 4);
    lore.set(index, (new StringBuilder(String.valueOf(ChatColor.translateAlternateColorCodes('&', "&c&o&8\u21E8 &e\u26A1 &7")))).append(decimal.floatValue()).append(" / ").append(capacity).append(" J").toString());
    ItemMeta im = item.getItemMeta();
    im.setLore(lore);
    item.setItemMeta(im);
    return rest;
}
 
Example 25
Project: MCLibrary   File: PageGUI.java   Source Code and License 5 votes vote down vote up
private void setContents(Inventory inv) {
    GUIData data = getData();
    ItemStack[] contents = data.contents();
    int start = currPage * spaceSize;
    int end = start + spaceSize;
    for (int i = start; i < end; i++) {
        if (contents.length <= i)
            break;
        ItemStack item = contents[i];
        if (item != null && item.getType() != Material.AIR) {
            inv.setItem(i - start + 9, item);
        }
    }
}
 
Example 26
Project: BedwarsXP   File: XPItemShop.java   Source Code and License 5 votes vote down vote up
private VillagerTrade getTradingItem(MerchantCategory category,
		ItemStack stack, Game game, Player player) {
	for (VillagerTrade trade : category.getOffers()) {
		if ((trade.getItem1().getType() != Material.AIR)
				|| (trade.getRewardItem().getType() != Material.AIR)) {
			ItemStack iStack = toItemStack(trade, player, game);
			if ((iStack.getType() == Material.ENDER_CHEST)
					&& (stack.getType() == Material.ENDER_CHEST))
				return trade;
			if (((iStack.getType() == Material.POTION) || ((Main
					.getInstance().getCurrentVersion().startsWith("v1_9")) && ((iStack
					.getType().equals(Material.valueOf("TIPPED_ARROW")))
					|| (iStack.getType().equals(Material
							.valueOf("LINGERING_POTION"))) || (iStack
						.getType()
					.equals(Material.valueOf("SPLASH_POTION"))))))
					&& (((PotionMeta) iStack.getItemMeta())
							.getCustomEffects().equals(((PotionMeta) stack
							.getItemMeta()).getCustomEffects()))) {
				return trade;
			}
			if (iStack.equals(stack)) {
				return trade;
			}
		}
	}
	return null;
}
 
Example 27
Project: DungeonGen   File: Passageway.java   Source Code and License 5 votes vote down vote up
/** Opens or closes the exit of this Passageway according to its DoorType.
 * @param open	true: opens, false: closes
 */
public void toggleExit(boolean open) {
	switch (exitType) {
	case APPEARING:
		if (open)
			genWall(exit.doorLoc,exit.height,exit.width,Material.AIR);
		else//close
			genWall(exit.doorLoc,exit.height,exit.width,exit.doorMaterial);
		break;
	case FALLING:
		Vector v_above = exit.doorLoc.add(0,exit.height,0); // the door location but height higher for stuff to fall down
		Vector v_below = exit.doorLoc.add(0,-exit.height,0); // the door location but height deeper
		if (open) {
			genWall(v_below,exit.height,exit.width,Material.AIR);
			genWall(v_above,exit.height,exit.width,Material.SMOOTH_BRICK);
		}else{//close
			genWall(v_above,exit.height,exit.width,exit.doorMaterial);
		}
		break;
	case PISTON:
		Vector v = toGlobal(exit.redstonePos);
		if (open)
			parent.world.getBlockAt(v.getBlockX(),v.getBlockY(),v.getBlockZ()).setType(Material.AIR);
		else //close
			parent.world.getBlockAt(v.getBlockX(),v.getBlockY(),v.getBlockZ()).setType(Material.REDSTONE_BLOCK);
		break;
	}
}
 
Example 28
Project: Warzone   File: WoolObjective.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onCollect(InventoryClickEvent event) {
    if (event.getCurrentItem() != null && event.getCurrentItem().getType() == Material.WOOL) {
        if (event.getCurrentItem().getData().getData() == color) {
            handleWoolPickup((Player) event.getWhoClicked());
        }
    }
}
 
Example 29
Project: Slimefun4-Chinese-Version   File: ItemEnergy.java   Source Code and License 5 votes vote down vote up
public static float getMaxEnergy(ItemStack item)
{
    if(item == null || item.getType() == null || item.getType().equals(Material.AIR))
        return 0.0F;
    if(!item.hasItemMeta() || !item.getItemMeta().hasLore())
        return 0.0F;
    for(Iterator iterator = item.getItemMeta().getLore().iterator(); iterator.hasNext();)
    {
        String line = (String)iterator.next();
        if(line.startsWith(ChatColor.translateAlternateColorCodes('&', "&c&o&8\u21E8 &e\u26A1 &7")) && line.contains(" / ") && line.endsWith(" J"))
            return Float.valueOf(line.split(" / ")[1].replace(" J", "")).floatValue();
    }

    return 0.0F;
}
 
Example 30
Project: ZentrelaCore   File: RParticles.java   Source Code and License 5 votes vote down vote up
public static boolean isAirlike(Material m) {
    switch (m.getId()) {
        case 0: //air
        case 78: //snow layer
        case 51: //fire
        case 50: //torch
        case 59: //wheat
        case 39: //mushroom
        case 40: //mushroom
        case 55: //redstone wire
        case 70: //stone pressure
        case 72: //wood pressure
        case 106: //vines
        case 141: //carrots
        case 142: //potatoes
        case 175: //flowers
        case 31: //grasses
        case 32: //dead shrub
        case 323: //sign (item, just in case)
        case 63: //standing sign
        case 68: //wall-mounted sign
        case 69: //lever
        case 77: //stone button
        case 143: //wood button
        case 75: //redstone torch on
        case 76: //redstone torch off
        case 65: //ladder
        case 66: //rail
        case 83: //sugar cane
        case 171: // carpet
            return true;
        default:
            return false;
    }
}
 
Example 31
Project: SparseBukkitAPI   File: ExampleMenu.java   Source Code and License 5 votes vote down vote up
public ExampleMenu()
{
	super("Test Menu", 4);
	
	setItem(0, 0, new MenuItem()
	{
		public ItemStack getItem()
		{
			return new ItemBuilder(Material.PAPER).colorName("&a0,0").enchantEffect().build();
		}
		
		public boolean shouldUpdateItem()
		{
			return false;
		}
		
		public boolean onClick(Player player, ClickType clickType, InventoryAction action)
		{
			Bukkit.broadcastMessage(player.getName()+" clicked");
			return false;
		}
	});
	
	setItem(1,1, new BasicItem(
			new ItemBuilder(Material.PAPER).colorName("&a1,1").enchantEffect().build(),
			(player, clickType, action) ->
			{
				Bukkit.broadcastMessage(player.getName() + " clicked BasicItem");
				return false;
			})
	);
}
 
Example 32
Project: ZentrelaRPG   File: MelodaBomb.java   Source Code and License 5 votes vote down vote up
@Override
public void castSpell(LivingEntity caster, MobData md, Player target) {
    for (int k = 0; k < RMath.randInt(20, 35); k++) {
        RScheduler.schedule(Spell.plugin, new Runnable() {
            public void run() {
                if (caster == null || !caster.isValid() || caster.isDead() || md.dead || md.despawned)
                    return;
                Location loc = caster.getLocation();
                double range = 10;
                Location l = loc.clone().add(RMath.randDouble(-range, range), RMath.randDouble(10, 15), RMath.randDouble(-range, range));
                FallingBlock fall = l.getWorld().spawnFallingBlock(l, Material.PACKED_ICE, (byte) 0);
                fall.setDropItem(false);
                fall.setHurtEntities(false);
                RScheduler.schedule(Spell.plugin, new Runnable() {
                    public void run() {
                        if (fall.isDead()) {
                            MelodaBombEffect effect = new MelodaBombEffect(EffectFactory.em(), fall.getLocation());
                            effect.run();
                            Spell.damageNearby(md.getDamage() * 3, caster, fall.getLocation(), 2, null);
                        } else {
                            RScheduler.schedule(Spell.plugin, this, 3);
                        }
                    }
                });
            }
        }, RMath.randInt(RTicks.seconds(1), RTicks.seconds(7)));
    }
}
 
Example 33
Project: HCFCore   File: HCF.java   Source Code and License 5 votes vote down vote up
public void resetGlowstoneMountain() {
	for(int x = 502 ; x <= 582 ; x++) {
		for(int y = 76 ; y <= 112 ; y++) {
			for(int z = 594 ; z > 514 ; z--) {
	    			Block block = Bukkit.getWorld("world_nether").getBlockAt(new Location(Bukkit.getWorld("world_nether"), -1 * x, y ,z));
	    			if(block.getType().equals(Material.BEDROCK)) {
	    				block.setType(Material.GLOWSTONE);
	    			}
	    	}
    	}
	}
}
 
Example 34
Project: HCFCore   File: ModeratorMode.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onRightClick2(PlayerInteractEvent event)
{
    if(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
          Player player = event.getPlayer();
          if ((modMode.contains(player.getName())) && (player.getItemInHand().getType() == Material.FEATHER)) {
              player.chat("/v");
          }
    }
}
 
Example 35
Project: WC   File: PokeEgg.java   Source Code and License 5 votes vote down vote up
public void registerRecipe(){
    ItemStack i = getPokeEgg();

    ShapedRecipe pokeEgg = new ShapedRecipe(i);

    pokeEgg.shape("BAB", "DCD", "BAB");

    pokeEgg.setIngredient('B', Material.WOOL);
    pokeEgg.setIngredient('A', Material.STRING);
    pokeEgg.setIngredient('D', Material.GOLD_NUGGET);
    pokeEgg.setIngredient('C', Material.EGG);

    Bukkit.addRecipe(pokeEgg);
}
 
Example 36
Project: KingdomFactions   File: Item.java   Source Code and License 5 votes vote down vote up
public ItemStack getItem(Material m, String name, int amount, ArrayList<String> lore, int in) {
	ItemStack i = new ItemStack(m, amount, (short) in);
	ItemMeta im = i.getItemMeta();
	im.setDisplayName(name);
	im.setLore(lore);
	i.setItemMeta(im);
	return i;
}
 
Example 37
Project: RealSurvival   File: Items.java   Source Code and License 5 votes vote down vote up
public static ItemStack getPlaceholder13(){
	ItemStack sw=new ItemStack(Material.STAINED_GLASS_PANE,1,(short)9);
	ItemMeta im = sw.getItemMeta();
	im.setDisplayName("��3��l��ˮ");
	sw.setItemMeta(im);
	return sw;
}
 
Example 38
Project: ProjectAres   File: BukkitTranslatorImpl.java   Source Code and License 5 votes vote down vote up
@Override
public Optional<String> materialKey(Material material) {
    return Optionals.first(
        Optional.ofNullable(substance(material))
                .map(Substance::key),
        Optional.ofNullable(NMSHacks.getTranslationKey(material))
    );
}
 
Example 39
Project: KingdomFactions   File: PortalTravelEventListener.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onPortalDestroy(BlockBreakEvent e) {
	if (e.getBlock() == null)
		return;
	if(e.getBlock().getType() == Material.PORTAL) {
		if(!e.getPlayer().isOp()) {
			e.setCancelled(true);
		}
	}
}
 
Example 40
Project: MT_Communication   File: CellularPhoneListener.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onCellPhoneInteract(PlayerInteractEvent e) {
  Player p = e.getPlayer();
  
  if (p.getInventory().getItemInMainHand().getType() != Material.WATCH)
    return;
  
  e.setCancelled(true);
  
  CellularPhone phone = new CellularPhone(main);
  
  // Left click for recipient toggle
  if (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
    if (p.isSneaking()) {
      phone.getNextContact(p);
      
    } else {
      phone.getPreviousContact(p);
      
    }
  }
  
  // Right click for text messages
  if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    if (p.isSneaking()) {
      phone.checkTextMessages(p);
      
    } else {
      phone.deleteTextMessage(p);
      
    }
  }
  
}
 
Example 41
Project: AstralEdit   File: DisplayArmorstand.java   Source Code and License 5 votes vote down vote up
/**
 * Initializes the armorstand
 *
 * @param player   player
 * @param location location
 * @param id       id
 * @param data     data
 * @param watchers watchers
 */
public DisplayArmorstand(Player player, Location location, int id, byte data, Set<Player> watchers) {
    super();
    this.watchers = watchers;
    this.player = player;
    this.armorStand = new EntityArmorStand(((CraftWorld) player.getWorld()).getHandle());
    final NBTTagCompound compound = new NBTTagCompound();
    compound.setBoolean("invulnerable", true);
    compound.setBoolean("Invisible", true);
    compound.setBoolean("PersistenceRequired", true);
    compound.setBoolean("NoBasePlate", true);
    this.armorStand.a(compound);
    this.armorStand.setLocation(location.getX(), location.getY(), location.getZ(), 0, 0);
    this.storedId = id;
    this.storedData = data;

    ItemStackBuilder stackBuilder = new ItemStackBuilder(Material.getMaterial(id), 1, data);
    this.getCraftEntity().setHelmet(stackBuilder.build());
    this.getCraftEntity().setBodyPose(new EulerAngle(3.15, 0, 0));
    this.getCraftEntity().setLeftLegPose(new EulerAngle(3.15, 0, 0));
    this.getCraftEntity().setRightLegPose(new EulerAngle(3.15, 0, 0));

    if (((ArmorStand) this.armorStand.getBukkitEntity()).getHelmet().getType() == Material.AIR) {
        stackBuilder = new ItemStackBuilder(Material.SKULL_ITEM, 1, (short) 3);
        if (id == Material.WATER.getId() || id == Material.STATIONARY_WATER.getId()) {
            stackBuilder.setSkin(NMSRegistry.WATER_HEAD);
        } else if (id == Material.LAVA.getId() || id == Material.STATIONARY_LAVA.getId()) {
            stackBuilder.setSkin(NMSRegistry.LAVA_HEAD);
        } else {
            stackBuilder.setSkin(NMSRegistry.NOT_FOUND);
        }
        ((ArmorStand) this.armorStand.getBukkitEntity()).setHelmet(stackBuilder.build());
    }
}
 
Example 42
Project: ProjectAres   File: PotionClassificationTest.java   Source Code and License 5 votes vote down vote up
@Test
public void potionItem() throws Exception {
    final ItemStack item = new ItemStack(Material.POTION);
    final PotionMeta meta = (PotionMeta) item.getItemMeta();
    meta.setPotionBrew(Bukkit.potionRegistry().get(Bukkit.key("healing")));
    item.setItemMeta(meta);

}
 
Example 43
Project: RealSurvival   File: WorkbenchCMD.java   Source Code and License 5 votes vote down vote up
/**
 * ���趨һ���䷽
 * @param player ���
 * @param sfName �䷽��
 * @param time ʱ��
 * @return �Ƿ�ɹ�
 */
public static boolean resetSF(Player player,String sfName,String time){
	 if(!new File(rs.getDataFolder()+File.separator+"SyntheticFormula"+sfName+".yml").exists()){
		 player.sendMessage("��9[RealSurvival] ��bû�ҵ�ָ���ĺϳɹ�ʽ...");
		 return false;
	 }
	 long l=-1;
	 try{ l=Long.parseLong(time);}catch(Exception e){}
	 if(l<0){
		 player.sendMessage("��9[RealSurvival] ��b����ʱ�����!...");
		 return false;
	 }
	player.openInventory(CraftItemGUI.resetSF(Items.createItemKey(Material.STAINED_GLASS_PANE, (short)15,sfName+":"+time)));
	return true;
}
 
Example 44
Project: HCFCore   File: EnderPearlTimer.java   Source Code and License 5 votes vote down vote up
@Override
public void run() {
    ItemStack stack = player.getItemInHand();
    if (stack != null && stack.getType() == Material.ENDER_PEARL) {
        long remaining = timer.getRemaining(player);
        net.minecraft.server.v1_7_R4.ItemStack item = ((CraftItemStack) stack).handle;
        if (remaining > 0L) {
            item = item.cloneItemStack();
            item.c(ChatColor.LIGHT_PURPLE + "Enderpearl Cooldown" + ChatColor.GRAY + " : " + ChatColor.WHITE + DurationFormatter.getRemaining(remaining, true, true));
            setFakeItem(item, player.getInventory().getHeldItemSlot());
        } else {
            cancel();
        }
    }
}
 
Example 45
Project: ProjectAres   File: Materials.java   Source Code and License 5 votes vote down vote up
/**
 * Is the given {@link Material} a block that collides with entities?
 *
 * Note that this is not always 100% correct. There are a few blocks for which
 * solidness depends on state, such as fence gates.
 */
public static boolean isColliding(Material material) {
    if(material == null) {
        return false;
    }

    switch(material) {
        // Missing from Bukkit
        case CARPET:
        case WATER_LILY:
            return true;

        // Incorrectly included by Bukkit
        case SIGN_POST:
        case WALL_SIGN:
        case WOOD_PLATE:
        case STONE_PLATE:
        case IRON_PLATE:
        case GOLD_PLATE:
        case STANDING_BANNER:
        case WALL_BANNER:
            return false;

        default:
            return material.isSolid();
    }
}
 
Example 46
Project: SurvivalAPI   File: SecurityListener.java   Source Code and License 5 votes vote down vote up
/**
 * Prevent portal trap
 *
 * @param event Event
 */
@EventHandler
public void onBlockPlace(BlockPlaceEvent event)
{
    if(!this.game.isGameStarted() || !this.game.hasPlayer(event.getPlayer()))
    {
        event.setCancelled(true);
        return;
    }

    boolean flag = false;

    if(event.getBlock().getWorld().getBlockAt(event.getBlock().getLocation().add(1.0D, 0.0D, 0.0D)).getType() == Material.PORTAL)
        flag = true;

    if(event.getBlock().getWorld().getBlockAt(event.getBlock().getLocation().subtract(1.0D, 0.0D, 0.0D)).getType() == Material.PORTAL)
        flag = true;

    if(event.getBlock().getWorld().getBlockAt(event.getBlock().getLocation().add(0.0D, 0.0D, 1.0D)).getType() == Material.PORTAL)
        flag = true;

    if(event.getBlock().getWorld().getBlockAt(event.getBlock().getLocation().subtract(0.0D, 0.0D, 1.0D)).getType() == Material.PORTAL)
        flag = true;

    if(flag)
    {
        event.setCancelled(true);
        event.getPlayer().sendMessage(ChatColor.RED + "Vous ne pouvez pas placer de bloc ici !");
    }
}
 
Example 47
Project: EchoPet   File: ParticleEffect.java   Source Code and License 5 votes vote down vote up
/**
 * Construct a new particle data
 * 
 * @param material Material of the item/block
 * @param data Data value of the item/block
 */
@SuppressWarnings("deprecation")
public ParticleData(Material material, byte data){
	this.material = material;
	this.data = data;
	this.packetData = new int[]{material.getId(), data};
}
 
Example 48
Project: OMGPI   File: BukkitEventHandler.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void event(BlockBurnEvent e) {
    if (g.state != GameState.INGAME) {
        e.setCancelled(true);
        return;
    }
    if (Area.registeredAreas.values().stream().filter(a -> a.isInside(e.getBlock().getLocation())).noneMatch(a -> a.allowBurn)) {
        e.setCancelled(true);
        return;
    }
    if (g.settings.isLootingOn && e.getBlock().getType() == Material.CHEST) {
        e.setCancelled(true);
        Inventory inv = ((Chest) e.getBlock().getState()).getBlockInventory();
        String lootid = inv.getTitle() == null ? "" : inv.getTitle();
        OMGLoot.LootParser lp = g.loot_contents(null, lootid);
        if (lp != null) {
            inv.clear();
            for (int i = 0; i < inv.getSize(); i++) {
                ItemStack ii = lp.getRandom().toItem();
                if (ii != null && NBTParser.getTagCompound(ii).getByte("Undroppable") != 1)
                    e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), ii);
            }
        }
        e.getBlock().setType(Material.AIR);
        e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new ItemStack(Material.CHEST));
    }
    if (!GameArea.isBlockInside(e.getBlock())) e.setCancelled(true);
}
 
Example 49
Project: Scorch   File: ObsidianToLava.java   Source Code and License 5 votes vote down vote up
@Override
public void run(){
    if(locations.isEmpty()) return;
    for(Location loc : locations.keySet()){
        int x = locations.get(loc) - 1;
        locations.remove(loc);
        locations.put(loc, x);
        if (locations.get(loc) <= 0){
            Main.getMainWorld().playEffect(loc, Effect.SMOKE, 31);
            Main.getMainWorld().getBlockAt(loc).setType(Material.STATIONARY_LAVA);
            locations.remove(loc);
        }
    }
}
 
Example 50
Project: AsgardAscension   File: MainInventory.java   Source Code and License 5 votes vote down vote up
public static void setupFoodEditMenu(Player player, int food) {
	Inventory inv = Bukkit.createInventory(player, 9, ChatColor.BOLD + "" + food + " Edit Menu");
	inv.setItem(0, ItemStackGenerator.createItem(Material.PAPER, 0, 0, ChatColor.LIGHT_PURPLE + "Change name", null));
	inv.setItem(1, ItemStackGenerator.createItem(Material.WORKBENCH, 0, 0, ChatColor.LIGHT_PURPLE + "Change item", null));
	inv.setItem(2, ItemStackGenerator.createItem(Material.ARROW, 16, 0, ChatColor.LIGHT_PURPLE + "Change amount", null));
	inv.setItem(3, ItemStackGenerator.createItem(Material.STICK, 0, 0, ChatColor.LIGHT_PURPLE + "Change data value", null));
	inv.setItem(4, ItemStackGenerator.createItem(Material.WATER_LILY, 0, 0, ChatColor.LIGHT_PURPLE + "Add Effect", null));
	inv.setItem(5, ItemStackGenerator.createItem(Material.BLAZE_POWDER, 0, 0, ChatColor.LIGHT_PURPLE + "Remove all Effects", null));
	inv.setItem(8, ItemStackGenerator.createItem(Material.IRON_BARDING, 0, 0, ChatColor.LIGHT_PURPLE + "Test Food of the Gods", null));
	player.openInventory(inv);
}
 
Example 51
Project: InventoryAPI   File: GUILabel.java   Source Code and License 5 votes vote down vote up
public GUILabel(String title, Material icon) {
    this.title = title;
    this.icon = icon;
    item = new ItemStack(icon, 1);
    ItemMeta itemMeta = item.getItemMeta();
    itemMeta.setDisplayName(title);
    itemMeta.addItemFlags(ItemFlag.values());
    item.setItemMeta(itemMeta);
}
 
Example 52
Project: SuperiorCraft   File: CustomTexturedBlock.java   Source Code and License 5 votes vote down vote up
@Override
public boolean placeBlock(ArmorStand e, Player p) {
	getTexture().placeBlock(e.getLocation().add(0, 0.125, -0.375));
	e.getLocation().getBlock().setType(getMaterial());
	if (getMaterial().equals(Material.MOB_SPAWNER)) {
		CreatureSpawner cs = (CreatureSpawner) e.getLocation().getBlock().getState();
		cs.setSpawnedType(EntityType.DROPPED_ITEM);
		cs.update();
	}
	setLe(e);
	return true;
}
 
Example 53
Project: PA   File: Warrior.java   Source Code and License 5 votes vote down vote up
public void setItems(Player p) {
    p.getInventory().setItem(0, new ItemStack(Material.DIAMOND_SWORD));

    p.getInventory().setItem(3, new ItemMaker(Material.SOUL_SAND).setDisplayName("Cadenas").build());

    p.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
    p.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
    p.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
    p.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));
}
 
Example 54
Project: uppercore   File: GuiUtil.java   Source Code and License 5 votes vote down vote up
public static ItemStack splashPotion(PotionType type, boolean extended, boolean upgraded, String name, String... lores) {
    ItemStack potion = new ItemStack(Material.SPLASH_POTION, 1);
    PotionMeta meta = (PotionMeta) potion.getItemMeta();
    meta.setBasePotionData(new PotionData(type, extended, upgraded));
    potion.setItemMeta(meta);
    return potion;
}
 
Example 55
Project: ZentrelaRPG   File: ItemRunnable.java   Source Code and License 5 votes vote down vote up
protected void takeOneItemInstant(Player p) {
    ItemStack item = p.getEquipment().getItemInMainHand();
    if (item.getAmount() > 1) {
        item.setAmount(item.getAmount() - 1);
        p.getEquipment().setItemInMainHand(item);
    } else {
        p.getEquipment().setItemInMainHand(new ItemStack(Material.AIR));
    }
}
 
Example 56
Project: GhostScavengerHunt   File: Main.java   Source Code and License 5 votes vote down vote up
public ItemStack constructGhostSkull() {
    ItemStack itemStack = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
    SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta();

    skullMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&f&lGhost Skull"));
    itemStack.setItemMeta(skullMeta);

    new SkullProfile(this.getConfig().getString("ghost-skull-hash"))
            .applyTextures(itemStack);

    return itemStack;
}
 
Example 57
Project: MockBukkit   File: WorldMockTest.java   Source Code and License 5 votes vote down vote up
@Test
public void getBlockAt_StandardWorld_DefaultBlocks()
{
	WorldMock world = new WorldMock(Material.DIRT, 3);
	assertEquals(Material.BEDROCK, world.getBlockAt(0, 0, 0).getType());
	assertEquals(Material.DIRT, world.getBlockAt(0, 1, 0).getType());
	assertEquals(Material.DIRT, world.getBlockAt(0, 2, 0).getType());
	assertEquals(Material.DIRT, world.getBlockAt(0, 3, 0).getType());
	assertEquals(Material.AIR, world.getBlockAt(0, 4, 0).getType());
}
 
Example 58
Project: mczone   File: Utils.java   Source Code and License 4 votes vote down vote up
public static boolean isWall(Block b) {
	if (b.getType()==Material.SAND || b.getType()==Material.GRAVEL)
		return true;
	else
		return false;
}
 
Example 59
Project: FlexMC   File: RecipeManager.java   Source Code and License 4 votes vote down vote up
public RecipeManager() {
    /*RecipeConfig recipeConfig = new RecipeConfig( new File( "config" ) );

    for( short i = 0; i < 4; i++ ) {
        recipeConfig.getShapelessRecipes().add( new ShapelessRecipeConfig( new ItemStackConfig( Material.WOOD.getId(), 4, i ), new ItemStackConfig( Material.LOG.getId(), 1, i ) ) );
    }

    try {
        recipeConfig.init();
    } catch ( InvalidConfigurationException e ) {
        e.printStackTrace();
    }

    for( ShapelessRecipeConfig c : recipeConfig.getShapelessRecipes() ) {
        ItemStack[] ingredients = new ItemStack[c.getInput().size()];
        int i = 0;
        for ( ItemStackConfig itemStackConfig : c.getInput() ) {
            ingredients[ i ] = itemStackConfig.getItemStack();
            i++;
        }
        this.recipes.add( new ShapelessRecipe( c.getResult().getItemStack(), ingredients ) );
    }*/

    for ( int i = 0; i < 4; i++ ) {
        this.recipes.add( new ShapelessRecipe( new ItemStack( Material.WOOD, 4, (short) i ), new ItemStack( Material.LOG, 1, (short) i ) ) );
    }
    this.recipes.add( new ShapedRecipe( new ItemStack( Material.WORKBENCH ),
            new ShapeBuilder( "MM", "MM" ).addIgnoreData( 'M', Material.WOOD ).build() ) );
    this.recipes.add( new ShapedRecipe( new ItemStack( Material.STICK, 4 ),
            new ShapeBuilder( "M", "M" ).add( 'M', Material.WOOD ).build() ) );
    this.recipes.add( new ShapedRecipe( new ItemStack( Material.WOOD_PLATE ),
            new ShapeBuilder( "MM" ).addIgnoreData( 'M', Material.WOOD ).build() ) );
    this.recipes.add( new ShapedRecipe( new ItemStack( Material.STONE_PLATE ),
            new ShapeBuilder( "MM" ).addIgnoreData( 'M', Material.STONE ).build() ) );
    this.recipes.add( new ShapedRecipe( new ItemStack( Material.TORCH, 4 ),
            new ShapeBuilder( "M", "N" ).addIgnoreData( 'M', Material.COAL ).add( 'N', Material.STICK ).build() ) );
    this.recipes.add( new ShapedRecipe( new ItemStack( Material.FLINT_AND_STEEL ),
            new ShapeBuilder( "M0","0N" ).add( 'M', Material.IRON_INGOT ).add( 'N', Material.FLINT ).build() ) );
    this.recipes.add( new ShapedRecipe( new ItemStack( Material.SHEARS ),
            new ShapeBuilder( "0M", "M0" ).add( 'M', Material.IRON_INGOT ).build() ) );
    this.recipes.add( new ShapedRecipe( Material.LEVER,
            new ShapeBuilder( "M", "N" ).add( 'M', Material.STICK ).add( 'N', Material.COBBLESTONE ).build() ) );
    this.recipes.add( new ShapedRecipe( Material.GLOWSTONE,
            new ShapeBuilder( "MM", "MM" ).add( 'M', Material.GLOWSTONE ).build() ) );
    this.recipes.add( new ShapedRecipe( Material.SNOW_BLOCK,
            new ShapeBuilder( "MM", "MM" ).add( 'M', Material.SNOW_BALL ).build() ) );
    this.recipes.add( new ShapedRecipe( new ItemStack( Material.SMOOTH_BRICK ),
            new ShapeBuilder( "MM", "MM" ).add( 'M', Material.STONE ).build() ) );
    this.recipes.add( new ShapedRecipe( Material.SANDSTONE ,
            new ShapeBuilder( "MM", "MM" ).add( 'M', Material.SAND ).build() ) );


}
 
Example 60
Project: Uranium   File: CraftEventFactory.java   Source Code and License 4 votes vote down vote up
public static Cancellable handleStatisticsIncrease(EntityPlayer entityHuman, net.minecraft.stats.StatBase statistic, int current, int incrementation) {
    Player player = ((EntityPlayerMP) entityHuman).getBukkitEntity();
    Event event;
    if (statistic instanceof net.minecraft.stats.Achievement) {
        if (current != 0) {
            return null;
        }
        event = new PlayerAchievementAwardedEvent(player, CraftStatistic.getBukkitAchievement((net.minecraft.stats.Achievement) statistic));
    } else {
        org.bukkit.Statistic stat = CraftStatistic.getBukkitStatistic(statistic);
        if (stat == null)
        {
            return null;
        }
        switch (stat) {
            case FALL_ONE_CM:
            case BOAT_ONE_CM:
            case CLIMB_ONE_CM:
            case DIVE_ONE_CM:
            case FLY_ONE_CM:
            case HORSE_ONE_CM:
            case MINECART_ONE_CM:
            case PIG_ONE_CM:
            case PLAY_ONE_TICK:
            case SWIM_ONE_CM:
            case WALK_ONE_CM:
                // Do not process event for these - too spammy
                return null;
            default:
        }
        if (stat.getType() == Type.UNTYPED) {
            event = new PlayerStatisticIncrementEvent(player, stat, current, current + incrementation);
        } else if (stat.getType() == Type.ENTITY) {
            EntityType entityType = CraftStatistic.getEntityTypeFromStatistic(statistic);
            event = new PlayerStatisticIncrementEvent(player, stat, current, current + incrementation, entityType);
        } else {
            Material material = CraftStatistic.getMaterialFromStatistic(statistic);
            event = new PlayerStatisticIncrementEvent(player, stat, current, current + incrementation, material);
        }
    }
    entityHuman.worldObj.getServer().getPluginManager().callEvent(event);
    return (Cancellable) event;
}