IF-Else

Discussion in 'Plugin Development' started by Achezito, Jul 21, 2022.

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

    Achezito

    Hello! I'm kind of new to creating plugins, I'm trying a way to give the player a nether star when a new player logs in and when he's a returning player, don't give him that item again, but I'm kind of stuck, why really? I have no idea how to do it, I would really appreciate your help

    Code:
    package me.linsaftw.Libro;
    
    import java.net.http.WebSocket.Listener;
    
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    
    
    
    public class LibrodeHabilidades implements Listener{
            @EventHandler
            public void Entrada (AsyncPlayerPreLoginEvent event )
            {
           
           
           
                if(event.player().equals(getLoginResult)){
    
    
                    event.getPlayer().sendRawMessage("┬ž6┬žnUsalo con cuidado");
                }
            }
    
         
           
    }
     
    Last edited by a moderator: Jul 21, 2022
  2. Offline

    pixelrider2000

    I would use a 'PlayerLoginEvent.' Whether or not the player has logged in before could maybe be saved as a boolean in a hashmap. The information of the hashmap must then be saved in a config file (you could also directly read/write from the config).
    If you are not sure how to create listeners in bukkit or how to save data in a config, I would highly advise you to watch a tutorial. There are plenty out there, I'm sure you're gonna find one :)
     
  3. Offline

    KarimAKL

    @Achezito You should listen to the PlayerJoinEvent instead of the AsyncPlayerPreLoginEvent. The PlayerJoinEvent happens in a later phase of the login process, after the Player object has been created and you can actually give items to the player. You can then use the Player#hasPlayedBefore() method to check if this is the first time the player joins the server.
    The process should look like the following (pseduo-code):
    Code:Java
    1. #(PlayerJoinEvent event)
    2. if event.player has NOT played before:
    3. give nether star to event.player
     
Thread Status:
Not open for further replies.

Share This Page