Updated Power Ups (markdown)

filoghost 2014-09-03 06:31:20 -07:00
parent e177beafdc
commit e4403b3905
1 changed files with 37 additions and 37 deletions

@ -1,38 +1,38 @@
![](http://i.imgur.com/8bWFG9q.jpg)
_Feature available from 1.8.5+_
Also check [this example plugin](https://github.com/filoghost/HolographicDisplays/blob/master/Example_PowerUps/src/com/gmail/filoghost/test/PowerUps.java) 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](https://github.com/filoghost/HolographicDisplays/blob/master/HolographicDisplays/src/com/gmail/filoghost/holograms/api/PickupHandler.java) 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.
``` java
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, 0));
// Delete the hologram and the floating item
floatingItem.delete();
hologram.delete();
}
});
![](http://i.imgur.com/tDR0TcA.jpg)
_Feature available from 1.8.5+_
Also check [this example plugin](https://github.com/filoghost/HolographicDisplays/blob/master/Example_PowerUps/src/com/gmail/filoghost/test/PowerUps.java) 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](https://github.com/filoghost/HolographicDisplays/blob/master/HolographicDisplays/src/com/gmail/filoghost/holograms/api/PickupHandler.java) 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.
``` java
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, 0));
// Delete the hologram and the floating item
floatingItem.delete();
hologram.delete();
}
});
```