Feedback on my project

Discussion in 'Plugin Development' started by NoLife, Apr 7, 2015.

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

    NoLife

    Hi Bukkit
    I'm new to this with plugins(and bukkit, so sry if the thread is in wrong category.). Okay, but i have now make my first "plugin", i want to get some feedback on, like what is bad/good code. do i do it wrong, or some thing like that. I just want to be better. :D The plugin is a plugin that give you the possible to switch equipment. So when you type /switch you get your second equipment. if you so type /switch again, you get that from before back.

    Here is the code:

    Main:
    Code:
    package io.github.Waterman2707.ItemSwitcher;
    
    import io.github.Waterman2707.ItemSwitcher.ItemSwitcherCommandExecutor;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin{
    
        @Override
        public void onEnable() {
            this.getCommand("switch").setExecutor(new ItemSwitcherCommandExecutor(this));
        }
      
        @Override
        public void onDisable() {
          
        }
      
    }
    
    CommandExecutor:
    Code:
    package io.github.Waterman2707.ItemSwitcher;
    
    import java.util.HashMap;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    
    public class ItemSwitcherCommandExecutor implements CommandExecutor{
      
        private final Main plugin;
      
        public ItemSwitcherCommandExecutor(Main plugin) {
            this.plugin = plugin;
        }
      
        HashMap<String , ItemStack[]> armor1 = new HashMap<String , ItemStack[]>();
        HashMap<String , ItemStack[]> armor2 = new HashMap<String , ItemStack[]>();
        HashMap<String , ItemStack[]> inv1 = new HashMap<String , ItemStack[]>();
        HashMap<String , ItemStack[]> inv2 = new HashMap<String , ItemStack[]>();
      
        public boolean onCommand(CommandSender sender, Command cmd,
                String label, String[] args) {
            if (!(sender instanceof Player)) {
                return false;
            }
          
            Player p = (Player) sender;
            String pn = p.getName();
          
            if (cmd.getName().equalsIgnoreCase("switch")){
                if (p.hasPermission("IE.switch")) {
                if (args.length == 0) {
                    if(armor1.containsKey(pn)) {
                        armor2.put(pn, p.getInventory().getArmorContents());
                        inv2.put(pn, p.getInventory().getContents());
                        p.getInventory().clear();
                        p.getInventory().setArmorContents(armor1.get(pn));
                        p.getInventory().setContents(inv1.get(pn));
                        armor1.remove(pn);
                        inv1.remove(pn);
                        p.sendMessage(ChatColor.AQUA + "[ItemSwitcher] " + ChatColor.RED + "Your item has switced");
                        return true;
                    } else if (armor2.containsKey(pn)) {
                        armor1.put(pn, p.getInventory().getArmorContents());
                        inv1.put(pn, p.getInventory().getContents());
                        p.getInventory().clear();
                        p.getInventory().setArmorContents(armor2.get(pn));
                        p.getInventory().setContents(inv2.get(pn));
                        armor2.remove(pn);
                        inv2.remove(pn);
                        p.sendMessage(ChatColor.AQUA + "[ItemSwitcher] " + ChatColor.RED + "Your item has switced");
                        return true;
                    } else {
                        armor1.put(pn, p.getInventory().getArmorContents());
                        inv1.put(pn, p.getInventory().getContents());
                        p.getInventory().clear();
                        p.sendMessage(ChatColor.AQUA + "[ItemSwitcher] " + ChatColor.RED + "Your item has switced");
                        return true;
                    }
                  
                  
                } else return false;
            } else return false;
            }
          
            return true;
        }
    
    }
    
    I just started so this is the first version of the plugin, i have plan to update it with diffrent things. That things i have now is:
    - Save it in config then the server stop(and load it then it start)
    - make so you can use a sign.
    - do so you can write /switchsee [1/2] and you then get ca GUI, that show you what you have in it.
    - cooldown
    - config fil

    It will be also be nice if you come with more thing i can put in to the plugin. (and what is best of the thing i have say, to begin/easyest to begin with.)

    //NoLife

    And sry for my english :(
     
  2. remove onDisable, it is empty.
    The rest of it looks good but its not perfect :)
     
  3. Offline

    NoLife

    @FisheyLP Thanks ;) but i will need the onDisable to the config saving ;) so i will just let it be there ;)
     
  4. Offline

    Msrules123

    Nice start.
    You may want to fix this spelling error though ;)
     
  5. Offline

    NoLife

    Haha, yes i'm not the best to english ;)
     
Thread Status:
Not open for further replies.

Share This Page