Solved Issue converting

Discussion in 'Spigot Plugin Development' started by Vertex101, Aug 2, 2020 at 3:26 AM.

Thread Status:
Not open for further replies.
  1. okay so i am working on coding a custom plugin for my server and i am having a little issue

    Code (Java):

    @EventHandler
        public void onBlockPlace(BlockPlaceEvent e) {
            if(e.getBlockPlaced().getType() == Material.HOPPER) {
                HopperMagnet.getPlugin().magnetBlocks.add(e.getBlock());
            }
        }
     
    so with this plugin i am using a hopper as the base for what i am making and i am adding the block to a list but with how i have the code its adding every hopper that is placed and i am just wanting my custom hoppers added to the list and i have been trying to figure out how to be able to check for the custom name on the hopper

    if needed here is the complete code for what i have so far with the plugin https://github.com/vertex101/HopperMagnet
     
  2. Elementeral

    Elementeral Previously Sullivan_Bognar

    I was just working on something super similar, so here's what I did for my solution. I made an ItemStack with my item, added a custom name to it, and before I did anything, I checked if the display name was the same as the ItemStack I created earlier. Here's how I did the check:
    Code (Text):
    Hopper hopper = (Hopper) e.getBlock().getState();

            if (hopper.getCustomName() != null && hopper.getCustomName().equals(ChatColor.translateAlternateColorCodes('&', "&aName Here")))
            {
                // code here
            }
    Good luck!
     
    #2 Elementeral, Aug 2, 2020 at 3:36 AM
    Last edited: Aug 2, 2020 at 3:46 AM
    • Like Like x 1
  3. Thanks for the help this actually helped and i gave credit in the commit on the code
     
Thread Status:
Not open for further replies.