You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
goflishMC edited this page Aug 20, 2023
·
1 revision
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.
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();
});