Plugin Help

Discussion in 'Spigot Plugin Development' started by HarleySwtfus, Jun 12, 2017.

  1. Hey, so I'm trying to make a very simple plugin for my friend, but I am coming across something I can not solve.

    I am trying to make it, so when you place a cauldron, a hologram appears above it saying some text, and when the cauldron is removed, it removes the hologram along with it.

    My code:
    Code (Text):
    package me.hawauh.cauldronbox;

    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    import com.gmail.filoghost.holographicdisplays.api.Hologram;
    import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;

    public class Main extends JavaPlugin implements Listener {

        public void onEnable() {
            System.out.println("[CauldronBox] Plugin enabled");
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }

        public void onDisable() {
            System.out.println("[CauldronBox] Plugin disabled");

        }

        @EventHandler
        public void onCauldronPlace(BlockPlaceEvent e) {
            if (e.getBlock().getType() == Material.CAULDRON) {
                Hologram hologram = HologramsAPI.createHologram(this, e.getBlock().getLocation().add(0.5, 2, 0.5));
                hologram.appendTextLine("§b§lCauldron Box");
                hologram.appendTextLine("§7(Right Click)");
            }
        }

        @EventHandler
        public void onCauldronBreak(BlockBreakEvent e) {
            if (e.getBlock().getType() == Material.CAULDRON) {

            }

        }
    }
     
    I am using HolographicDisplaysAPI for the holograms.

    I am trying to remove the Hologram when the Cauldron is broken.
     
    #1 HarleySwtfus, Jun 12, 2017
    Last edited: Jun 12, 2017
  2. Soo.... what's the problem?
     
  3. He propably doesn't know how to remove the hologram.
     
  4. I am trying to remove the Hologram when the Cauldron is broken.
     
  5. Simply save the hologram inside a hashmap in relation to a location.
    then when the block is broken remove it by hologram.remove();


    Edit: See here
    Edit: HashMap<Location, Hologram> would be better I guess.
     
    • Agree Agree x 1
  6. Ah okay! Thank you