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 201
Power Ups
filoghost edited this page Jul 26, 2014
·
17 revisions
Feature available from 1.8.5+
Also check this example plugin to learn how to create power ups.
A power up is very simple, is made of a floating item (the icon) and a hologram. You can assign a PickupHandler to the floating item, that is triggered when a player is near. If you want, you can create a class that holds both the hologram and the floating item.
Example: a power up (Blaze Powder) that gives fire resistance when is collected.
String text = ChatColor.GOLD + "" + ChatColor.BOLD + "Fire Resistance"
Location where = ... // Suppose you have a random location in your minigame
ItemStack powder = new ItemStack(Material.BLAZE_POWDER);
FloatingItem floatingItem = HolographicDisplaysAPI.createFloatingItem(this, where.add(0.0, 0.2, 0.0), powder);
final Hologram hologram = HolographicDisplaysAPI.createHologram(this, where.add(0.0, 0.6, 0.0), text);
floatingItem.setPickupHandler(new PickupHandler() {
@Override
public void onPickup(FloatingItem floatingItem, Player player) {
// Play a sound
player.playSound(player.getLocation(), Sound.LEVEL_UP, 1F, 2F);
// Play an effect
player.playEffect(floatingItem.getLocation(), Effect.MOBSPAWNER_FLAMES, null);
// 1 minute of fire resistance
player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 60 * 20, 1));
// Delete the hologram and the floating item
floatingItem.delete();
hologram.delete();
}
});