Getting tools?

Discussion in 'Plugin Development' started by VictoryShot, Apr 18, 2014.

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

    VictoryShot

    I need help making an if statement to see if the player is holding the the tool/weapon but if he holds his fist I want it to say "You cant enchant your fist." or something like that:
    Code:
    Code:java
    1. if (event.getCurrentItem().getItemMeta().getDisplayName()
    2. .equals("§3Sharpness 3")) {
    3. if (KitPVPAPI.hasEnough(p, 80)) {
    4. KitPVPAPI.takePoints(p, 80);
    5. p.getItemInHand().addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 3);
    6. p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore(Bukkit.getOfflinePlayer(ChatColor.GOLD + "Points ")).setScore(KitPVPAPI.balancePoints(p));
    7. p.closeInventory();
    8. p.sendMessage(ChatColor.AQUA + "Enchantment Added");
    9. } else {
    10. p.closeInventory();
    11. p.sendMessage("§cYou don't have enough money!");
     
  2. Offline

    Onlineids

    if(p.getIteminHand !=null){
    //Main code here
    }else{
    p.sendMessage("You cannot enchant your fist!");
    }
     
  3. Offline

    VictoryShot

    Doesnt work.
     
  4. Offline

    Onlineids

    whats error
     
  5. Offline

    VictoryShot

    No error it still just enchants my fist.
     
  6. Offline

    Onlineids

    well thats not possible.....
     
  7. Offline

    VictoryShot

    Last edited by a moderator: Jun 7, 2016
  8. Offline

    Onlineids

    show updated code
     
  9. Offline

    CraftThatBlock

    Try
    if(p.getIteminHand() !=null && p.getIteminHand().getType() != Material.AIR){
     
  10. Offline

    VictoryShot

    Code doesnt work.

    Incompatible operand types org.bukkit.Material and net.minecraft.server.v1_7_R1.Material

    It works but it doesnt set the item as cancelled so I can just take it, and it doesnt send me the else message.
    Code:java
    1. if (event.getCurrentItem().getItemMeta().getDisplayName()
    2. .equals("§3Sharpness 3")) {
    3. if(KitPVPAPI.hasEnough(p, 80)) {
    4. event.setCancelled(true);
    5. KitPVPAPI.takePoints(p, 80);
    6. p.getItemInHand().addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 3);
    7. p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore(Bukkit.getOfflinePlayer(ChatColor.GOLD + "Points ")).setScore(KitPVPAPI.balancePoints(p));
    8. p.closeInventory();
    9. p.sendMessage(ChatColor.AQUA + "Enchantment Added");
    10. }
    11. if(p.getItemInHand().getType().equals(Material.AIR)) {
    12. p.sendMessage(ChatColor.RED + "Please use a tool.");
    13. } else {
    14. p.closeInventory();
    15. p.sendMessage("§cYou don't have enough money! / You cannot enchant your fist!");


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  11. Offline

    Onlineids

    You put air I said null, an empty inventory space in bukkit isnt air its null.
     
Thread Status:
Not open for further replies.

Share This Page