diff --git a/Power-Ups.md b/Power-Ups.md index 61d2c53..38e638f 100644 --- a/Power-Ups.md +++ b/Power-Ups.md @@ -2,4 +2,35 @@ Feature available from 1.8.5+ -For the moment you can 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. \ No newline at end of file +For the moment you can 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 to the floating item, that is triggered when a player is near. If you want, you can use [this](...) helper class in your plugin. + +**Example**: a power up 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 +FloatingItem floatingItem = HolographicDisplaysAPI.createFloatingItem(this, where.add(0.0, 0.2, 0.0), new ItemStack(Material.SUGAR)); +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(); + + } +}); +``` \ No newline at end of file