Java Language: Why our theses lines of code not working??

Discussion in 'Spigot Plugin Development' started by Jbot_James, May 4, 2015.

  1. Hello, I am new to the programming world but I know how helpful spigot can be with anything so I came here. The plugin I am trying to make is that if you Right click a blaze rod you will get SPEED effect. Here is my code

    package me.RegularMoments;

    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.potion.Potion;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.potion.PotionType;

    public class SpeedStick extends JavaPlugin {

    public void onEnable() {
    getLogger().info("Plugin Enabled");
    public void onDisable() {


    public void onPlayerInteract(PlayerInteractEvent e) {
    Player p = e.getPlayer();
    if (e.getAction() == Action.RIGHT_CLICK_AIR)
    if (p.getItemInHand().getType() == Material.BLAZE_ROD) {
    p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10000, 1));




    I tried it out and after a few days of trying to make it work it dident. If you can tell me what I need to do that would be great. Thank you. Also be sort of, very specific, I have only been learning JAVA for a week :)
  2. Just going to help you out here.

    If I were you, I would learn Java before Bukkit. I tried doing the two together and failed miserably. It took me twice the time to learn.

    If you want to show us code, you should use the code syntax.

    Now with your problem.

    You're not registering the event. What you want to do is...

    Code (Text):
    getServer().getPluginManager().registerEvents(this, this);
  3. wasn't this question already answered?
  4. THANK YOU SO MUCH AND I will take your advice but this is going to sound SO DUMB.... were do I put that text LOL srry. Right now my code looks like this

    public void onPlayerInteract(PlayerInteractEvent e) {
    getServer().getPluginManager().registerEvents(this, this);
    Player p = e.getPlayer();
    if (e.getAction() == Action.RIGHT_CLICK_AIR) {
    if (p.getItemInHand().getType() == Material.BLAZE_ROD)
    p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10000, 1));

    Please help please I want to learn.
  5. It does sound dumb... I read your other posts, you need to go back and learn Java and programming in general.

    Just because I'm nice:

    It goes in your onEnable.
  6. Well thanks ALOT for being nice but...... I have a error under it. Heres the photo.

    Sooo now I have a CAUTION under that code.

    Also should I replace the this, this part of the text the same or should I replace it with something.

    Attached Files:

  7. Your problem lies in the fact registerEvents is expecting an instance of Listener, you are passing it a JavaPlugin.

    Change you class signature to also implement Listener and you should be golden.

    - flamin
  8. Please, do yourself a favor: learn Java first. Stop bukkit completely. Any bukkit tutorial or documentation you will find will either teach you bad practices or expect that you already learn Java and therefore not mention things that someone who already knows Java would know.
  9. Finnaly someone that knows what their doing :p
  10. I want to learn JAVA by learning how to make plugins/mods.
  11. That's a bad idea. Learn Java (not JAVA) by creating small demo/practice programs, such as a Notepad clone. I suggest you start here.
  12. From what I have seen, his real problem is that fact that he doesn't know Java. ;)
    • Agree Agree x 1
    • Winner Winner x 1
  13. Make sure to register your events like they said ^
  14. agree, but the problem goes little bit deeper...he needs to know what the programming is...
    • Winner Winner x 2
    • Agree Agree x 1
    • Funny Funny x 1
  15. I have a great solution.

    Learn basic Java, tell me what static, protected, and void mean (basic keywords), then more people will help you