Custom methods problems

Discussion in 'Spigot Plugin Development' started by DimoKouli, Jun 21, 2015.

  1. I am trying to do a kill list plugin but i cant really understand how custom methods work any help appreciated!
    Thanks in advance
    Code (Text):

    }
         [USER=17846]@EventHandler[/USER]
         public void onplayer(EntityDeathEvent e){
           
            setKills(e.getEntity().getKiller(), + 1);
           
         }
        public void setKills(Player player, int kills){
            List<Integer> kills1 = new ArrayList<Integer>();
            kills1.add(kills);
         
        }
        public void getKills(String s){
            Player p = Bukkit.getOnlinePlayers();
            int kills1;
            setKills(p, kills1);
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
                if(args.length == 1){
                    if(cmd.getName().equalsIgnoreCase("Kills")){
                        Bukkit.broadcastMessage(getkills(args[0]));
                    }
                }
     
     
  2. you're doing +1 not just 1. Also for the ArrayList<Integer>(); you dont need the Integer you can just do ArrayList<>();
     
  3. Learn basic java.
     
    • Like Like x 2
  4. @Janmm14 thx for ur help jerk @ExtendedHorizons yeah but the thing is that i want to add every new kill in the list... so when cmd /kills occurs it should list all args[0] kills..
     
    • Funny Funny x 1
  5. God im rereading your code and as @Janmm14 said learn basic java... You could just use a hashmap then the key is a player and the value is the players kills.
    Code (Text):
    public static HashMap<Player, Integer> kills = new HashMap<>();

        @EventHandler
        public static void kills(EntityDeathEvent e){
            if(e.getEntity().getKiller() instanceof Player) {
                Player p = e.getEntity().getKiller();
                kills.put(p, kills.get(p) + 1);
            }else{
                return;
            }
        }
        public static Integer getKills(Player p){
            if(kills.containsKey(p)) {
                return kills.get(p);
            }else{
                return 0;
            }
        }
    Should work
     
    #5 ExtendedHorizons, Jun 21, 2015
    Last edited: Jun 21, 2015
  6. @ExtendedHorizons could u please If you have time explain me how custom methods are created?
     
    • Funny Funny x 1
  7. @DimoKouli im not going to explain it but the reply above ur reply is the code you need
     
    • Optimistic Optimistic x 1
  8. @ExtendedHorizons It works but when i am trying to broadcast the getkills method it says that i cant because args[0] is string and getkills refers to a Player
     
  9. ah then just change getKills(Player); to getKills(String string); and then in the get kills method just do Player p = Bukkit.getPlayer(string);
     
    • Agree Agree x 1
  10. That's spoonfeeding; and it doesn't help.
     
    • Agree Agree x 2
  11. It helps because it fixes his problem and rn I dont want to be bothered to teach him java
     
  12. @ExtendedHorizons still not work :( i must change the getkill method from integer to string but then returns wont work..
     
  13. As I said do Player p = Bukkit.getPlayer(string);
    Code (Text):
    public static Integer getKills(String string){
            Player p = Bukkit.getPlayer(string);
            if(kills.containsKey(p)) {
                return kills.get(p);
            }else{
                return 0;
            }
        }
     
  14. xD It doesn't help... They'll come back with the same problem, not knowing what to do.. Either stop spoonfeeding, or don't help at all.
     
  15. When I started and I needed help when people said "learn java" it didnt help for shit. The stuff like this believe it or not DID help me I learned from the code then made an understanding of it then used it later on.
     
  16. No it tells me that i need to change the return type.. Public static INTEGER ..
    @_Cory_ Please stop talking nosense smart ass i am trying to learn java some months now and tutorials or books online wont help a lot just by copying i can preceive things...if you got any alt please feel free to speak it out
    @ExtendedHorizons is right ^ i can learn only like that..
     
    • Optimistic Optimistic x 1
  17. Thats odd because its returning an integer...
    Code (Text):
    if(kills.containsKey(p)) {
                return kills.get(p);
            }else{
                return 0;
            }
     
  18. He asked you for further explanation to understand it, but you just said:
    My question: How shall he learn sth if you don't explain it?
     
    • Agree Agree x 1