Plugin Help Instant Potions error

Discussion in 'Plugin Help/Development/Requests' started by KeybladePaladin, Jan 11, 2015.

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

    KeybladePaladin

    Alright, I used to make Bukkit plugins a long time ago.
    I stopped and forgot how, so I went back to the basics, as my first new plugin I thought it would be cool to make an instant potions plugin thinking it would be very simple.

    This is my code:

    Code:
    package key.Test.main;
    
    import net.minecraft.server.v1_7_R3.ItemStack;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.command.ConsoleCommandSender;
    import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemStack;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.inventory.ClickType;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.Potion;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    @SuppressWarnings("unused")
    public class Main extends JavaPlugin implements Listener{
        public static Main main;
       
        public void onEnable(){
            getServer().getPluginManager().registerEvents((Listener) this, this);
            main = this;
        }
        public void onDisable() {
        }
        public static Main getPlugin() {
            return main;
           
                }
        public boolean onCommand(CommandSender sender, Command cmd,  
                String label, String[] args) {
           
           
            if (sender instanceof Player) {
                Player player = (Player) sender;
                @EventHandler
                public void onPlayerClick(PlayerInteractEvent event;
                {
                    if(event.getItem() != null && event.getItem().getType() == Material.POTION)
                    {
                        Potion potion = Potion.fromItemStack(event.getItem());
                        potion.apply(event.getPlayer());
                       
                        ItemStack item = CraftItemStack.asNMSCopy(event.getItem());
                        item.count--;
                        event.getPlayer().setItemInHand(CraftItemStack.asBukkitCopy(item));
                    }
                }
            }else if (sender instanceof ConsoleCommandSender) {
           
            }
            return false;
        }
            {
        }
    }
       
       
    
    And it throws an Invalid Type error at "onPlayerClick"
    Please Help :3
     
  2. Offline

    pie_flavor

    I am fairly certain that you forgot how Java works, too, or just programming in general.
    • Why do you have a method inside another method?
    • Why did you even attempt to do it wrong in the first place? What's the command for?
     
  3. Offline

    nverdier

    @KeybladePaladin

    @pie_flavor If you want people to be more likely to see your post, then you have to Tahg them or reply to their post!
     
  4. Offline

    pie_flavor

    @nverdier He made the thread, so he's notified automatically. Because YOU tagged him, it will give him 2 notifications which is annoying. Furthermore, if you are subscribed to the thread (you autosubscribe on create) it will show you 1 notification no matter how many people responded, but you will see a separate notification for each tag.

    @KeybladePaladin
    Also, more comments.
    Why do you use CraftItemStack? NMS is confusing and complicated, and you didn't really use any NMS specific features.
    You should really have a right click detector - if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
     
    Last edited: Jan 12, 2015
  5. Offline

    nverdier

    @pie_flavor Not true, most people change it so you don't auto-subscribe.
     
  6. Offline

    pie_flavor

    @nverdier Most people don't know the option exists, or even how to manually subscribe.
     
  7. Offline

    nverdier

  8. Offline

    KeybladePaladin

  9. Offline

    Crazyyy

    Certain that you have forgotten how to Program Java,
    1 you haven't even put a targeted potion effect or anything.
    Once you have defined p
    ( Player p = (Player) sender;

    if its a instant potion effect just make a
    p.addPotionEffect(arg0, arg1)
     
  10. Offline

    pie_flavor

    @KeybladePaladin
    This is a method, which means you can't put methods in it.
    This is a command, which means that nothing in it will be run unless the command is typed.

    @Crazyyy That's not what he's trying to do. He's trying to get the potion effect off the item stack and add it to the player.

    Also, KeybladePaladin, the methods you're using accept an ItemStack from Bukkit, not an ItemStack from NMS.
    By the way, the specific error: void isn't a Java type, and the only thing you can declare in the scope of a method is a temporary class or a variable.
     
  11. Offline

    KeybladePaladin

    Basically, ignore the previous code.

    That code was built AROUND command code, meaning i accidentally left certain bits from the previous commands left there.
    I redid the class file, so most of the REALLY DUMB errors are gone.

    BTW, nobody lock this thread yet! I may still need help soon!

    @pie_flavor @Crazyyy @nverdier

    Above ^
    Forgot to Tahg you guys x3

    Alright, this is my working code, the Insta-drink works just fine, but if you click on the Glass Bottle, it will refill with the potion, if you drink another potion, the last Potion you drank will reappear in your inventory.
    How do I stop this?

    This is my code:

    Code:
    package key.Test.main;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.command.ConsoleCommandSender;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.inventory.ClickType;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.Potion;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    @SuppressWarnings("unused")
    public class Main extends JavaPlugin implements Listener{
        public static Main main;
        public void onEnable(){
            getServer().getPluginManager().registerEvents((Listener) this, this);
            main = this;
        }
        public void onDisable() {
        }
        public static Main getPlugin() {
            return main;
                }
                @SuppressWarnings("deprecation")
                @EventHandler
                public void onPlayerClick(PlayerInteractEvent event) {
                {
                    if(event.getItem() != null && event.getItem().getType() == Material.POTION)
                    {
                        Potion potion = Potion.fromItemStack(event.getItem());
                        potion.apply(event.getPlayer());
                        event.getPlayer().getInventory().setItemInHand(new ItemStack(Material.AIR));    
                        event.getPlayer().updateInventory();
                        event.getPlayer().getInventory().addItem(new ItemStack(Material.GLASS_BOTTLE, 1));
                        event.getPlayer().updateInventory();
                    }}}{}}
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
Thread Status:
Not open for further replies.

Share This Page