Hi to all! I want add item when logging in to the server

Discussion in 'Plugin Development' started by Flaksfqa, Apr 28, 2021.

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

    Flaksfqa

    Hi to all! I want
    add item when logging in to the server
    I would like to click to execute the command when clicking, clicking on the object

    package ru.flaks.heartguild;import org.bukkit.entity.Player;import org.bukkit.event.Listener;public class Items implements Listener{

    public void OnJoin(Player p) {

    }
    }
     
  2. Offline

    xpaintall

    @Flaksfqa Okay, first of all you should be doing is
    Code:
    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
    //code
    }
    because it triggers every time a player joins a server.
    If you want to give a player an item, you should make a seperate class which stores your items. I believe Technovision has a tutorial on this, so I am going to link his tutorial below:



    I hope my reply helps! And yes, if you want to execute a command just do:
    Code:
    player#Chat("/yourcommand");
     
  3. Offline

    KarimAKL

    There is probably no difference in the result, but I prefer Bukkit#dispatchCommand(CommandSender, String) because it is clearer that you want to "dispatch a command," rather than "make the player chat."
     
    Newdel likes this.
  4. Offline

    Flaksfqa

    Thank you for the video! But how can I make my head crash when I log into the server
    2. how to givemy head
     
  5. Offline

    Xp10d3

    Please learn how to code first. Your code is very difficult to read:
    package ru.flaks.heartguild;import org.bukkit.entity.Player;import org.bukkit.event.Listener;public class Items implements Listener{

    public void OnJoin(Player p) {

    }
    }

    I have no clue what that means. It really should be:

    Should be:
    package ru.flaks.heartguild;

    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;

    public class Items implements Listener {
    public void onJoin(Player p) {
    // give player item
    }
    }

    And even better with the website syntax tags.
    Code:java
    1.  
    2. package ru.flaks.heartguild;
    3.  
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.Listener;
    6.  
    7. public class Items implements Listener {
    8. public void onJoin(Player p) {
    9. // give player item
    10. }
    11. }
    12.  


    Learn basic formatting and Java such as camel casing and spacing before learning Bukkit API. While some people might be willing to help it hurts my brain when people try to learn Bukkit API without prior coding experience (I'm guilty of that, although I at least attempted to learn Java on Codecademy and had 5+ years of prior coding experience with web development). Camel casing and basic formatting is something anyone with prior coding experience should know. I started with freaking HTML, CSS, and JavaScript and even that had basic formatting skills that were required.

    But to answer your question...
    https://bukkit.org/threads/give-player-predefined-heads.150859/

    Or:
    Code:java
    1.  
    2. ItemStack is = new ItemStack(Material.SKULL);
    3. ItemMeta im = is.getItemMeta();
    4. // Do something with the meta idk
    5. player.getInventory().addItem(is);
    6.  
     
    Last edited: Apr 29, 2021
    Newdel likes this.
Thread Status:
Not open for further replies.

Share This Page