This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 202
Power Ups
filoghost edited this page Jun 4, 2022
·
17 revisions
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.
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();
});