Backpack Plugin

Discussion in 'Plugin Development' started by Saith1998, Aug 25, 2014.

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

    Saith1998

    Hi guys I just want to ask if someone can code me a save.yml for my Backpack Plugin
    Here is my Main:
    Code:java
    1. package me.saith1999.team;
    2.  
    3. import org.bukkit.plugin.java.JavaPlugin;
    4.  
    5. import Commands.backpack;
    6. public class Main extends JavaPlugin {
    7. public void onEnable(){
    8. this.getCommand("bp").setExecutor(new backpack());
    9. }
    10. public void onDisable(){
    11. }
    12. }
    13.  

    Here is the backpack:
    Code:java
    1. package Commands;
    2.  
    3.  
    4.  
    5.  
    6.  
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.Sound;
    10. import org.bukkit.command.Command;
    11. import org.bukkit.command.CommandExecutor;
    12. import org.bukkit.command.CommandSender;
    13. import org.bukkit.command.ConsoleCommandSender;
    14. import org.bukkit.entity.Player;
    15. import org.bukkit.inventory.Inventory;
    16.  
    17.  
    18.  
    19.  
    20. public class backpack implements CommandExecutor {
    21.  
    22. public static Inventory BACKPACK;
    23. @Override
    24. public boolean onCommand(CommandSender sender, Command cmd, String label,
    25. String[] args) {
    26.  
    27.  
    28. if(sender instanceof ConsoleCommandSender){
    29. System.out.println("nope");
    30. return true;
    31. }
    32. if(cmd.getName().equalsIgnoreCase("bp")){
    33. Player p = (Player) sender;
    34. if(!(p.hasPermission("saith.bp.Ironraider"))){
    35. p.sendMessage("§0[§6§lStarNetwork§0]§4§m§lPermissions");
    36. p.playSound(p.getLocation(), Sound.FIZZ, 1F, 1F);
    37. p.playSound(p.getLocation(), Sound.FIZZ, 1F, 1F);
    38. p.playSound(p.getLocation(), Sound.FIZZ, 1F, 1F);
    39.  
    40. return true;
    41. }
    42. BACKPACK = Bukkit.createInventory(null, 9, "§7§l"+ p.getName()+ "'s §4Backpack");
    43. ((Player) p).openInventory(BACKPACK);
    44.  
    45. return true;
    46.  
    47. }
    48.  
    49. return false;
    50. }
    51.  
    52. }
    53.  

    Thx
     
  2. Offline

    mrCookieSlime

    Saith1998
    This probably belongs to "Plugin Developement" not "Plugin Requests".

    Also something like this is pretty easy. In fact there are multiple backpack plugins out there...

    But since I havent got much time right now, I will not send you any code for now. I will just explain you how you can do this:

    1. You probably wanna insert if (sender instanceof Player) there as well before casting it.
    2. Since every player probably will have its own backpack, dont make a public variable. Use an ArrayList with player UUIDs/Names instead.
    3. On closing the inventory (InventoryCloseEvent) just loop through all Slots of the closed Inventory and store the item in this slot in the save.yml
    under something like "backpacks.Moewe1.inventory.0" and then 1,2,3,4...
    4. Then on opening the backpack look if the file contains the players name. If so loop through the slots again, and create an Inventory which has the same Items in the same Slots.
    put the players UUID/Name in the ArrayList. And then check for the players UUID/Name in the list in step 3.
     
  3. Offline

    Marten Mooij

    Saith1998 Wrong section, Also you should watch this video about Backpacks by Pogostick29dev:
    this should help you out a bit.
     
  4. Offline

    Saith1998

  5. Offline

    JaguarJo

    Moved thread to a more appropriate forum section.
     
  6. Offline

    TheMcScavenger

    I suggest you learn Java and Bukkit, before attempting to "make" a plugin.
    • You're casting sender to player, then checking if it's the console.
    • You're casting sender to player twice, instead of using the player variable the second time
     
  7. Offline

    Saith1998

    TheMcScavenger
    I started learning Java and Bukkit just 3 ore 4 days ago.
    That's the reasonwhy I am making some silly mistakes.
     
  8. Offline

    TheMcScavenger

    While "doing it" is a great way to learn, you can't do it without any knowledge in advance. Learn the basics before you attempt coding yourself, because this simply isn't going to work out. You're stuck with mistakes you'll learn about in the first or second tutorial on the Bukkit API, causing you to not even get around to fixing the mistakes in your actual code.
     
Thread Status:
Not open for further replies.

Share This Page