Player Manupliation

Discussion in 'Plugin Development' started by cruz2000, Nov 2, 2013.

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

    cruz2000

    Ok so ive been readying java for dummies 5th eddtion and learning so much about java that i didn't know and am still learning. But as you know to make perfect you need practice so am practing a bit and testing my self. Am also learning from the wiki bukkit plugin and i saw player manupliation. But its not working i get no errors and i check the script and everything seems find not sure whats problem
    Code:java
    1. package me.cruz2000;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.player.PlayerJoinEvent;
    6. import org.bukkit.inventory.ItemStack;
    7. import org.bukkit.inventory.PlayerInventory;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class IventoryManu extends JavaPlugin {
    11.  
    12. public void onPlayerJoin(PlayerJoinEvent evt) {
    13. Player player = evt.getPlayer(); // The player who joined
    14. PlayerInventory inventory = player.getInventory(); // The player's inventory
    15. ItemStack itemstack = new ItemStack(Material.DIAMOND, 64); // A stack of diamonds
    16.  
    17. if (inventory.contains(itemstack)) {
    18. inventory.addItem(itemstack); // Adds a stack of diamonds to the player's inventory
    19. player.sendMessage("Welcome! You seem to be reeeally rich, so we gave you some more diamonds!");
    20. }
    21. }
    22. }


    Plugin.yml

    Code:java
    1. name: Inventory
    2. version: 1.0
    3. main: me.cruz2000.IventoryManu
    4. description: Inventory manu!
     
  2. Offline

    slater96

  3. Offline

    MrSparkzz

    cruz2000
    change your code to this
    Code:java
    1.  
    2. package me.cruz2000;
    3.  
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.PlayerJoinEvent;
    9. import org.bukkit.inventory.ItemStack;
    10. import org.bukkit.inventory.PlayerInventory;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class IventoryManu extends JavaPlugin implements Listener {
    14.  
    15. @Override
    16. public void onEnable() {
    17. getServer().getPluginManager().registerEvents(this, this);
    18. }
    19.  
    20. @EventHandler
    21. public void onPlayerJoin(PlayerJoinEvent evt) {
    22. Player player = evt.getPlayer(); // The player who joined
    23. PlayerInventory inventory = player.getInventory(); // The player's inventory
    24. ItemStack itemstack = new ItemStack(Material.DIAMOND, 64); // A stack of diamonds
    25.  
    26. if (inventory.contains(itemstack)) {
    27. inventory.addItem(itemstack); // Adds a stack of diamonds to the player's inventory
    28. player.sendMessage("Welcome! You seem to be reeeally rich, so we gave you some more diamonds!");
    29. }
    30. }
    31. }
    32.  

    should be all set now! ;)

    You don't need either of those methods, unless you plan on registering commands/events like he is here. These methods will override the default actions.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  4. Offline

    cruz2000

    Thank you so much works!
     
Thread Status:
Not open for further replies.

Share This Page