Discussion in 'Plugin Development' started by Yarmoam, Sep 20, 2015.

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


    Hey I'm relatively new to coding and am wondering if I'm missing something for my plugin to work.
    The plugin loads up in my server just fine, but it doesn't trigger anything when I right click with sugar.
    I, myself, can't help but feel that there's something missing, but I can't put my finger on it.

    Any help, advice, or comments are warmly welcomed and appreciated!

    Code which does not currently work ( (open)
    package me.jason.sugarrush;
    import java.util.Collection;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.ClickType;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    public final class Main extends JavaPlugin implements Listener {
        //To Do List
        //- Add a custom inventory that displays what the drugs do and what effects they give.
        String consoleprefix = "[Drugs]: ";
        String ingameprefix = "§7[§4Drugs§7]: ";
        public void onEnable()
            Bukkit.getServer().getLogger().info(consoleprefix + "v" + this.getDescription().getVersion() + " enabled.");
        public void onDisable()
            Bukkit.getServer().getLogger().info(consoleprefix + "v" + this.getDescription().getVersion() + " disabled.");
        @EventHandler (priority=EventPriority.HIGHEST)
        public void onPlayerUse(PlayerInteractEvent event) {
            Player p = event.getPlayer();
            if(p.getItemInHand().getType() == Material.SUGAR)
                p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 90, 3), true);
                p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 90, 3), true);
                p.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 15, 2), true);
                p.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 9, 0));
                p.getInventory().removeItem(new ItemStack (Material.SUGAR, 1));
                p.sendMessage(ingameprefix + "I FEEL LIKE IM THE KING OF THE WORLD!");

    plugin.yml (open)
    name: SugarRush
    main: me.jason.sugarrush.Main
    version: 1.0
    author: Adjasont_
    description: Adds magic 'powders'!
  2. Offline


    @Yarmoam You do not register your events. In your onEnable, simply add
    Bukkit.getPluginManager().registerEvents(this, this);
    //first arg is the JavaPlugin instance, second is the Listener class instance.
    and it should work.
  3. Offline


    Resgister your events, getServer().getPluginManager().registerEvents(this,this); on your onEnable
    EDIT: Ninja'd by shadowlax
    ShadowLAX likes this.
  4. Offline


    Also, Java Naming Conventions. Don't use "Main" for your main class.
  5. Offline


    Also, if the player has TWO sugar items in their hand (Itemstack.getAmount() == 2), the item should not be removed since you are specifying that it would have to be the same as that new itemstack (you set the amount to be 1, and as such anything more than that will not be removed). You would need to test if the amount is greater than 1, and if so, set the amount to the amount - 1.
  6. Offline


    I recommend you to change the priority from highest to lowest. It will trigger faster that way.
  7. Offline


Thread Status:
Not open for further replies.

Share This Page