PlayerJoinEvent

Discussion in 'Plugin Development' started by TheDef, Oct 6, 2014.

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

    TheDef

    Hello, I am very new at bukkit plugin development. I was wondering if there was a way to create a plugin that rewarded the first 100 players (or IP's) that joined our server. I know that there is the hasPlayedBefore. But how would I go about restricting the 101 player from receiving a reward? Any help would be greatly appreciated!
     
  2. Offline

    dan14941

    I would register the names into a file and when the file gets to 100 names the server stops rewarding.
     
  3. Offline

    TheDef

    What is the code for registering players into a file? I am familiar with registering plugins but how would I put players into a file?
     
  4. Offline

    Skionz

  5. Offline

    TheDef

    You sir, are a gentleman. Thank you.
     
  6. Offline

    BillyBobJoe168

    TheDef Instead of putting 100 names in a file (thats a lot of names :p) I would just have one int. Every time a player joins, check if they hasPlayedBefore() and if they haven't, add one to the int.
    Code:java
    1. inti;
    2. @EventHandler
    3. public void onPlayerJoin(PlayerJoinEvent e) {
    4. Player p = e.getPlayer();
    5. if (!p.hasPlayedBefore) {
    6. if (getConfig().contains("number")) {
    7. i = getConfig().getint("number");
    8. } else {
    9. i = 0;
    10. }
    11. i++;
    12. getConfig().set("number", i);
    13. }
    14. }

    That's only if you restart your server. If you don't restart your server, you have no need for the config file.
     
  7. Offline

    TheDef

    That makes sense, a little bit lighter on the server as well.
    Code:java
    1. if(i = 101){
    2. getPlayer.getInventory.clear()
    3. }else{
    4. getPlayer.getInventory.setItem()
    5. }

    Is this proper, as far as rewarding the first 100 players? Will this bit of code call upon the file containing the int?
     
  8. Offline

    fireblast709

    TheDef use addItem instead of setItem, and only if i < 100
     
  9. Offline

    TheDef

    fireblast709 Thanks for correcting my formatting. Does setItem only place an item in the currently selected slot?
     
  10. Offline

    Hawktasard

    setItem can replace items, addItem just adds an item in the next available slot.
     
Thread Status:
Not open for further replies.

Share This Page