Trying to check the customname of an entity

Discussion in 'Plugin Development' started by Crack498, Aug 19, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Crack498

    I'm just tryting to check the customname of a mob, I tried ".getEntity().getCustomName().equalsIgnoreCase("Heligiex Guard")".
    This is the "full" code:
    Code:java
    1. public void onEntityDeath(EntityDeathEvent event){
    2. if(event.getEntity().getCustomName().equalsIgnoreCase("Heligiex Guard")){
    3. Bukkit.broadcastMessage(ChatColor.GREEN + "Heligiex Guard has been defeated!" );
    4. Bukkit.broadcastMessage(ChatColor.GOLD + "Diamond ore is no longer blocked!" );
    5. ItemStack im = Helgstone();
    6. Random numb = new Random();
    7. im.setAmount(numb.nextInt(10) + 45);
    8. }
    9. }
     
  2. Offline

    Gerov

  3. Offline

    mine-care

    The issue is?
    Any errors?
    Do a if entity.hascustomname before looking for,it
     
  4. Offline

    Lactem

    Make sure the event is registered.
     
  5. Offline

    sparta417

    First of all, you don't have the @EventHandler annotation above your method. Second, make sure your listener is registered. Third, check if the entity has a name by calling entity.hasCustomName(), before trying to use a compare method (like equals())
     
  6. Offline

    Crack498

    The code is put directly on the main code:
    Code:java
    1. package me.Crack498;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5. import java.util.Random;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.Material;
    10. import org.bukkit.command.Command;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.event.entity.EntityDeathEvent;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.inventory.meta.ItemMeta;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. public class Code extends JavaPlugin {
    19.  
    20. @Override
    21. public void onEnable() {
    22. new BlockListener(this);
    23. }
    24.  
    25. public void onDisable() {
    26.  
    27. }
    28.  
    29. public static ItemStack Helgstone(){
    30. ItemStack Helgstone = new ItemStack(Material.CLAY_BRICK);
    31. ItemMeta meta = Helgstone.getItemMeta();
    32. List<String> lore = new ArrayList<String>();
    33. lore.add("A stone from the Healgiex realm");
    34. meta.setDisplayName("Helgstone");
    35. meta.setLore(lore);
    36. return Helgstone;
    37. }
    38.  
    39. public void onEntityDeath(EntityDeathEvent event){ // <-- HERE IS THE CODE
    40. if(event.getEntity().getCustomName().equalsIgnoreCase("Heligiex Guard")){
    41. Bukkit.broadcastMessage(ChatColor.GREEN + "Heligiex Guard has been defeated!" );
    42. Bukkit.broadcastMessage(ChatColor.GOLD + "Diamond ore is no longer blocked!" );
    43. ItemStack im = Helgstone();
    44. Random numb = new Random();
    45. im.setAmount(numb.nextInt(10) + 45);
    46. }
    47. }

    Is this code in the appropiate place to be? First time trying to code bukkit so I don't untderstand a lot of its functions :(
     
Thread Status:
Not open for further replies.

Share This Page