My plugin wont spawn in the pet

Discussion in 'Plugin Development' started by Banjer_HD, Nov 21, 2015.

Thread Status:
Not open for further replies.
  1. Hello,
    Is there any fault in this code?
    Last edited
    Code:
    @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if(label.equalsIgnoreCase("pet")) {
                    if(Bukkit.getPlayerExact(args[0]) != null && Bukkit.getPlayerExact(args[0]).isOnline()) {
    
                    }else if(args[0].equalsIgnoreCase("remove")) {
                        if(args.length == 2 || args.length == 3) {
                            if(args.length == 2) {
                                if(Bukkit.getPlayerExact(args[1]) != null && Bukkit.getPlayerExact(args[1]).isOnline()) {
                                Player targetP = Bukkit.getPlayerExact(args[1]);
                                sender.sendMessage(ChatColor.AQUA + "Optie 1: " + ChatColor.AQUA + "Soort: " + ChatColor.GRAY + getConfig().getString("Players." + targetP.getUniqueId() + ".1" + ".soort") + ChatColor.AQUA +  " Naam: " + ChatColor.GRAY + getConfig().getString("Players." + targetP.getUniqueId() + ".1" + ".naam"));
                                sender.sendMessage(ChatColor.AQUA + "Optie 2: " + ChatColor.AQUA + "Soort: " + ChatColor.GRAY + getConfig().getString("Players." + targetP.getUniqueId() + ".2" + ".soort") + ChatColor.AQUA +  " Naam: " + ChatColor.GRAY + getConfig().getString("Players." + targetP.getUniqueId() + ".2" + ".naam"));
                                sender.sendMessage(ChatColor.AQUA + "Optie 3: " + ChatColor.AQUA + "Soort: " + ChatColor.GRAY + getConfig().getString("Players." + targetP.getUniqueId() + ".3" + ".soort") + ChatColor.AQUA +  " Naam: " + ChatColor.GRAY + getConfig().getString("Players." + targetP.getUniqueId() + ".3" + ".naam"));
                                }else {
                                    sender.sendMessage(ChatColor.RED + "Die speler is niet online!");
                                }
                            }else if(args.length == 3) {
                                if(Bukkit.getPlayerExact(args[1]) != null && Bukkit.getPlayerExact(args[1]).isOnline()) {
                                    Player targetP = Bukkit.getPlayerExact(args[1]);
                                    String optie = args[2];
                                    if(optie.equalsIgnoreCase("1") || optie.equalsIgnoreCase("2") || optie.equalsIgnoreCase("3")) {
                                        if(optie.equalsIgnoreCase("1")) {
                                            getConfig().set("Players." + targetP.getUniqueId() + ".1", null);
                                            saveConfig();
                                        }else
                                        if(optie.equalsIgnoreCase("2")) {
                                            getConfig().set("Players." + targetP.getUniqueId() + ".2", null);
                                            saveConfig();
                                        }else
                                        if(optie.equalsIgnoreCase("3")) {
                                            getConfig().set("Players." + targetP.getUniqueId() + ".3", null);
                                            saveConfig();
                                        }
                                       
                                    }else {
                                        sender.sendMessage(ChatColor.RED + "Gebruik /pet remove <speler> [1, 2, 3]");
                                    }
                                }
                            }
                        }else {
                            sender.sendMessage(ChatColor.RED + "Gebruik /pet remove <speler>");
                            sender.sendMessage(ChatColor.RED + "En daarna /pet remove <speler> <optie>");
                        }
                    }else {
                        sender.sendMessage(ChatColor.RED + "Die speler is niet online!");
                    }
    }
    }
    
    Spawn code:
    Code:
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
                Player p = e.getPlayer();
                for(int i = 1; i <=3; i++) {
                    if(getConfig().getString("Players." + p.getUniqueId() + "." + i) == null) {
                       
                    }else {
                        String type = getConfig().getString("Players." + p.getUniqueId() + "." + i + ".type");
                        String name = getConfig().getString("Players." + p.getUniqueId() + "." + i + ".name");
                        if(soort == "cat") {
                            String catType = getConfig().getString("Players." + p.getUniqueId() + "." + i + ".cattype");
                           
                            Ocelot o = (Ocelot) p.getWorld().spawnEntity(p.getLocation(), EntityType.OCELOT);
                            o.setOwner(p);
                            o.setCustomName(naam);
                            if(catType.toLowerCase().equals("black")) {
                                o.setCatType(Type.BLACK_CAT);
                            }else if(katSoort.toLowerCase().equals("red")) {
                                o.setCatType(Type.RED_CAT);
                            }else if(katSoort.toLowerCase().equals("white")) {
                                o.setCatType(Type.SIAMESE_CAT);
                            }else if(katSoort.toLowerCase().equals("normal")) {
                                o.setCatType(Type.WILD_OCELOT);
                            }
                        }else if(soort == "dog") {
                            Wolf w = (Wolf) p.getWorld().spawnEntity(p.getLocation(), EntityType.WOLF);
                            w.setOwner(p);
                            w.setCustomName(name);
                        }
                    }   
                }
        }
       
    
    Thank you in advance!
     
  2. Offline

    mcdorli

    1.:
    You can use .equalsIgnoreCase instead of this
    2.: Don't use commandLabel, use cmd.getName(), this way you can get the aliases too
    3.:Why is this line
    Code:
    sender.sendMessage(ChatColor.AQUA + "Optie 1: " + ChatColor.AQUA + "Soort: " + ChatColor.GRAY + getConfig().getString("Players." + targetP.getUniqueId() + ".1" + ".soort") + ChatColor.AQUA +  " Naam: " + ChatColor.GRAY + getConfig().getString("Players." + targetP.getUniqueId() + ".1" + ".naam"));
    
    Three times in the code with only a few differences?
    4.: Don't create the usage message yourself, use the usage in the plugin.yml file.


    Are there any errors?
     
    Last edited: Nov 21, 2015
  3. Offline

    Zombie_Striker

    If you have to ask, this thread should not have been created.
     
  4. Translate=
    Code:
    sender.sendMessage(ChatColor.AQUA + "Option 1: " + ChatColor.AQUA + "Type: " + ChatColor.GRAY + getConfig().getString("Players." + targetP.getUniqueId() + ".1" + ".Type") + ChatColor.AQUA +  " Name: " + ChatColor.GRAY + getConfig().getString("Players." + targetP.getUniqueId() + ".1" + ".Name"));
    
    then they can delete 1 of the 3 Options ./pet remove <Playername> <1, 2, 3>

    No errors..
    I replaced .equalsIgnoreCase
    But why i need cmd.getName()?
    EDIT by Banjer_HD: 1 error on plugin start:
    Code:
    Plugin `DownTown_System v1.0' uses the space-character (0x20) in its name `DownTown System' - this is discouraged
    
     Plugin `Real_Time v0.1' uses the space-character (0x20) in its name `Real Time' - this is discouraged
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited: Nov 21, 2015
  5. Offline

    teej107

     
    mcdorli likes this.
  6. @teej107 Can you help me with the problem? I have changed the cmd.getName()
     
  7. Offline

    mcdorli

    Don't use spaces in plugin name, please read the errors 1 time before you post them
     
  8. But that is not the problem xD
     
  9. Offline

    mcdorli

    please read, that is A problem
     
  10. @mcdorli
    A problem but not THE problem
     
  11. Offline

    mcdorli

    Errors in the console? Does it work? Anything?
     
  12. @mcdorli My problem is that the plugin doesnt spawn in the pet onjoin
     
Thread Status:
Not open for further replies.

Share This Page