17 Power Ups
filoghost edited this page 2022-06-04 19:17:58 +02:00

Final result

A power up is very simple, is made of a hologram with two lines. You can assign a PickupHandler to the floating item, that is triggered when a player picks it up.

Also check this example plugin to learn how to create power ups.

Example

A power up (Blaze Powder) that gives fire resistance when is collected.

Location where = ... // Suppose you have a random location in your minigame

String text = ChatColor.GOLD  + "" + ChatColor.BOLD + "Fire Resistance";
ItemStack icon = new ItemStack(Material.BLAZE_POWDER);

HolographicDisplaysAPI api = HolographicDisplaysAPI.get(this);
final Hologram hologram = api.createHologram(where.add(0.0, 0.6, 0.0));
hologram.getLines().appendText(text);
ItemHologramLine itemLine = hologram.getLines().appendItem(icon);

itemLine.setPickupListener((HologramLinePickupEvent pickupEvent) -> {
	Player player = pickupEvent.getPlayer();
	
	// Play a sound
	player.playSound(player.getLocation(), Sound.LEVEL_UP, 1F, 2F);

	// Play an effect
	player.playEffect(hologram.getLocation(), Effect.MOBSPAWNER_FLAMES, null);

	// 1 minute of fire resistance
	player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 60 * 20, 0));

	// Delete the hologram
	hologram.delete();
	
});