Right_Click_Block error?

Discussion in 'Plugin Development' started by militiaspack, Dec 14, 2013.

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

    militiaspack

    Alright so i am a bit new to coding but still understand it. I got pretty far but i don't understand why im getting a bunch of errors on this code. Any help?


    RIGHT_CLICK_BLOCK can not be resolved to a variable
    and location errors

    @SuppressWarnings("deprecation")
    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent e) {
    Player p = e.getPlayer();
    World w = p.getWorld();
    if(!(e.getItem().getType() == Material.STICK)) return;
    if(e.getAction() == Action.RIGHT_CLICK_BLOCK) return;
    Block b = p.getTargetBlock(null, 100);
    Location l = b.getLocation();
    w.strikeLightning(location);
    w.createExplosion(location, 2);
     
  2. Offline

    The_Doctor_123

  3. Offline

    militiaspack


    import java.awt.Desktop.Action;
    import java.awt.Event;
    import java.util.ArrayList;
    import java.util.HashMap;

    import javax.tools.JavaFileManager.Location;

    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.HumanEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.OfflinePlayer;
    import org.bukkit.Server;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.enchantments.EnchantmentWrapper;
    import org.bukkit.entity.Item;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.CraftItemEvent;
    import org.bukkit.event.inventory.PrepareItemCraftEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.Recipe;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
  4. Offline

    The_Doctor_123

    militiaspack
    You have got to be kidding me...
     
  5. Offline

    militiaspack


    Well thanks for showing me my mistake i guess. I started checking out tutorials online for java too :p


    I am glad i took your advice. I started reading a online book about java and once you showed me that mistake i instantly knew what i did wrong :D Fixed it

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

    The_Doctor_123

    militiaspack
    Okay, good. But really start to learn Java before you find yourself in more, bigger holes than that.
     
  7. Offline

    militiaspack


    Alright thanks but I have one quick question. Right now i have it so if i do /lightningrod then i get a custom stick named lightning rod. But i wanna make it so only the custom stick can shoot lightning so what would i do instead of this?

    @SuppressWarnings("deprecation")
    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent e) {
    Player p = e.getPlayer();
    World w = p.getWorld();
    if(!(e.getItem().getType() == Material.STICK)) return;
    if(e.getAction() == Action.RIGHT_CLICK_BLOCK) return;
    Block b = p.getTargetBlock(null, 100);
    Location l = b.getLocation();
    w.strikeLightning(l);
    w.createExplosion(l, 2);
    }
     
  8. Offline

    Gater12

    militiaspack Check if the stick has the display name of whatever.
     
  9. Offline

    militiaspack


    Alright thanks :D
     
  10. Offline

    The_Doctor_123

  11. Offline

    militiaspack


    I got it already but thanks :D Told u i was learning java lol
     
  12. Offline

    Developing

    militiaspack Oh yeah by the way , its better to use
    Code:java
    1. if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK))

    instead of
    Code:java
    1. if(e.getAction() == Action.RIGHT_CLICK_BLOCK)
     
  13. Offline

    The_Doctor_123

Thread Status:
Not open for further replies.

Share This Page