give a pufferfish when player move(amateur)

Discussion in 'Plugin Development' started by Yep, Apr 2, 2021.

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

    Yep

    My code just doesn't work, and a evil entity called Asmaholeth the purple, will kill my father if i dont finish this until the next full moon.

    This is my main
    Code:
    package sugarpietro.Tutorialbooa;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    import sugarpietro.Tutorialbooa.Eventos.Eventos;
    
    
    public class Main extends JavaPlugin {
        public void OnEnable(){
            getServer().getConsoleSender().sendMessage("Eu, eu fui ativado novamente");
            getServer().getConsoleSender().sendMessage("de qualquer forma, minha missão e ajudar vocês com o que precisam, caso necessitem de minha benção podem chamar-me, ");
            getServer().getPluginManager().registerEvents(new Eventos(), this);
        }    
    }
    This is the code

    Code:
    package sugarpietro.Tutorialbooa.Eventos;
    
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    
    public class Eventos implements Listener{
        @EventHandler
        public void onPlayerMove (PlayerMoveEvent evento){
        Player jogador =evento.getPlayer();
        jogador.sendMessage("Ricardo Milos");
        Inventory inventario = jogador.getInventory();
        ItemStack a = new ItemStack(Material.PUFFERFISH);
        inventario.addItem(a);
        }
    }   
    It would be very nice if you guys could help me, i really like my father.
     
  2. Offline

    Chr0mosom3

    What doesn't work, what is the error? Do you get any errors in the console? Can you paste your console here?

    The first thing that I can spot is in your main class:
    Code:
    public void OnEnable(){
    is sopposed to be:
    Code:
    public void onEnable(){
    The o has to be lowercase. If that doesn't fix it then at least tell us what the problem is.
     
  3. Offline

    Newdel

    And he forgot the @Override
     
  4. Offline

    Chr0mosom3

    Having the @Override notation isn't required per say, your program will still run exactly the same without it, but you should have it, just in case. For example, if you try to override a function, but you miss a argument or misspell the method name, it will throw an error and you will know. It also improves the readability of your code.
     
    KarimAKL and Newdel like this.
  5. Offline

    Yep

    So, Eclipse doesn't notice anything wrong with the code, but when I run it in minecraft nothing happens. I will try doing what was suggested and see what happens, thanks for the help.
     
  6. Offline

    davidclue

    You probably didn't even export the jar file to your plugins folder, check the server logs if it even enables your plugin.
     
    Last edited: Apr 6, 2021
  7. Offline

    KarimAKL

    Eclipse tells you about compiler errors, not how to make a Bukkit plugin.
     
    Amster likes this.
  8. Offline

    Yep

    oh, I already did that, and java enables my plugin.
     
  9. Offline

    davidclue

    Then what's not working here like is the server sending a message when you move? Are you just not receiving the item? Are you getting any errors in the console? Your code looks like it should work just fine.
     
  10. Offline

    Amster

    We can't figure out your error, but I might have an idea?
    Change

    getServer().getPluginManager().registerEvents(new Eventos(), this);

    to

    this.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this);

    in your onEnable()

    The second one registers event correctly for me, so yours might be right, but use mine if you want, just in case, since mine works.

    EDIT: As Wick states, this won't change anything, nevermind!
     
    Last edited: Apr 8, 2021
  11. Offline

    Wick

    No, don't do this. The only difference between those lines of code is that the first one is registering a listener as another class, whereas the second is registering your main class. OP has a separate class for his listener and therefore should not change this line of code.
     
    KarimAKL, davidclue and Newdel like this.
  12. Offline

    Amster

    Sorry for the misinformation
     
  13. Offline

    Yep

    Exactly, the console dont send the message, and i dont receive the item, nothing works, and i dont see any error message
     
  14. Offline

    KarimAKL

    @Yep, could you post your server log and current code for both classes (with pastebin or something similar)?
     
  15. Offline

    Yep

    IT WORKED!
    Thank you very much to everyone who helped, this community is one of the most welcoming I have ever seen.
    My father is also very grateful to everyone!

     
    Last edited: Apr 10, 2021
    Chr0mosom3 likes this.
Thread Status:
Not open for further replies.

Share This Page