Error with RightClickEvent

Discussion in 'Plugin Development' started by BiskitDEV, Apr 13, 2015.

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


    Hey, I am working on this plugin, and this code doesn't seem to work when I tested it, I have googled and looked around for a while and I couldn't find anything. (Before you haters start, yes... I am new Bukkit)


    public class //Plugin Name extends JavaPlugin {
    public void onEnable() {
        ItemStack speed = new ItemStack(Material.FEATHER);
        ItemMeta im = speed.getItemMeta();
        im.setDisplayName(ChatColor.AQUA + "Feather of Speed");
        ArrayList<String> lore = new ArrayList<String>();
        lore.add(ChatColor.DARK_AQUA + "Right-Click for a boost!");
        lore.add(ChatColor.DARK_RED + "Beware of the side-effects!");
        ShapedRecipe speedFeather = new ShapedRecipe(speed);
        speedFeather.setIngredient('*', Material.EMERALD);
        speedFeather.setIngredient('%', Material.FEATHER);
        public void PlayerInteract(PlayerInteractEvent event) { 
            Player p = event.getPlayer();
            if (event.getPlayer().getItemInHand().getType().equals(Material.FEATHER)) {
            if(event.getAction() == Action.RIGHT_CLICK_AIR) {
            if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                event.getPlayer().sendMessage(ChatColor.GOLD + "Adding Effect.");
                    p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 15, 2));
  2. Offline


    Logic error, action cannot be both right click air and block.
    Also prefer to compare Enums with == (as you already do, only change it for getType()
  3. Offline


    Okay, thanks for that dude!
  4. Offline


    @BiskitDEV Np! Dont forget to mark your thread as "Solved"
  5. Offline


    @BiskitDEV - You have quite a few things preventing this from working. The obvious was stated above, you are creating logic that cannot occur (right click == AIR & BLOCK).

    Aside from that, clicking AIR will never fire as it is cancelled by default, so you must ignorecancelled=false. I also see no registration of the event, so everything else is moot.

    -> getServer().getPluginManager().registerEvents(new <EventName>(), <PLUGIN>);
    -> @EventHandler(priority = EventPriority.<priority>, ignoreCancelled = false)

    Moving on from that, you are allowing ANY feather to trigger your event, not just the special feather you defined. You are not controlling how often someone can click the feather (allowing for unlimited usage) and finally you are giving only 15 TICKS worth of a potion effect.

    Does your recipe work? I am not sure you can omit the entire recipe and only provide 1 set of parameters. My understanding of ShapedRecipes is it requires you to define the entire recipe like -> recipe.shape("###", "#%#", "###"); and leaving blanks where you expect empty space to be like -> recipe.shape(" ", "#%#", " ");

    Finally, "(Before you haters start, yes... I am new Bukkit)". I would say you are new to Java in general.
    mine-care likes this.
  6. Offline


    I saw the ticks problem, and I fixed that, but thanks anyway!

    I do not understand registering the event.

    What is the <EventName> ? Am I supposed to replace the event name with what I defined the event in the ~
    'public void PlayerInteract(PlayerInteractEvent event) {' ? The same goes with the 'PLUGIN' part. I am having a better look into it now, but I just thought that I would ask.

    And yes, the recipe does work. 'recipe.shape(" ", "#%#", " ");'. The blank spaces in this mean that you cannot have anything in those slots when you open the crafting table. The recipe is stuck to the middle three slots. Keep in mind that this is before you define the characters use to represent each item, e.g. customItem.setIngredient('*', Material.EGG);

    customItem.shape("%*%"); allows the recipe to go anywhere in the crafting table, as long as the recipe is in correct order and in horizontal.

    And yes, I am new to Java. That's why I am here.. To learn. Thanks!!
  7. Offline

    I Al Istannen

    @BiskitDEV The first argument is the "Listener instance". So if the interactEventis in your main class, you would put "this". If it is in the class "InteractListener" you would put "new InteractListener()" or an instance of this class. The second class is the owning plugin. That is the plugin instance the Listener belongs to. I think your interactListener is in your plugin, so i would put "this" in this field.
  8. Offline


    Except this is not a Java forum, it is a Bukkit development forum. Many of your issues stem from your lack of fundamental programming knowledge, not a lack of how Bukkit works.
Thread Status:
Not open for further replies.

Share This Page