Development Assistance Omg i am so lost...

Discussion in 'Plugin Help/Development/Requests' started by haussik, Nov 25, 2014.

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

    haussik

    First of all, sorry for my english :)

    I will show you the code than talk after :
    Code:java
    1. boolean offerNow = false;
    2.  
    3. public boolean onCommand(CommandSender sender, Command cmd, String label,String[] args) {
    4.  
    5. if (cmd.getName().toLowerCase().equalsIgnoreCase("offer") && sender instanceof Player) {
    6. if(!(sender instanceof Player)){
    7. System.out.println("Nope");
    8. }else{
    9. if (args.length == 2) {
    10.  
    11. HashMap<String, Integer> offer = new HashMap<String, Integer>();
    12.  
    13. Player player = (Player) sender;
    14. long cashOffer = 0;
    15. Player target = Bukkit.getServer().getPlayer(args[0]);
    16.  
    17. try{
    18. cashOffer = Integer.parseInt(args[1]);
    19. player.sendMessage("error");
    20. }
    21.  
    22. if(target != null && cashOffer != 0){
    23.  
    24. if(offerNow == true){
    25. sender.sendMessage("There is already a offer for " + offer.get(target.getName()) + " for the amount of " + offer.get(cashOffer) + " !");
    26. }else{
    27.  
    28. offerNow = true;
    29. offer.put(target.getPlayer(), cashOffer);
    30.  
    31. target.sendMessage(ChatColor.RED + "You have an offer!");
    32. sender.sendMessage(ChatColor.RED + "You have placed an offer !");
    33. return true;
    34. }
    35. }
    36. }else{
    37.  
    38. Player player = (Player) sender;
    39.  
    40. player.sendMessage("error");
    41. return false;
    42. }
    43. }
    44. }
    45. return true;
    46. }
    47. }
    48.  


    Now, IG i do /offer haussik 100

    -> Everything is ok

    I do the same command again /offer haussik 100

    -> say that there is already an offer. Perfect

    BUT, the "offer.get(target.getName())" print 'null' (the target name) and "offer.get(cashOffer)" print null too ! But i had put the value of the target and the cashOffer while typing for the first time the command! Help me D:

    I hope you understand ?
     
  2. Offline

    Qaisar101

    Honestly, I know barely anything about coding, but I am replying so that others can see this.
    You're very welcome. :)
     
  3. Offline

    ZanderMan9

    It looks to me like you are never actually putting the offer value and offer-er's name into your hashmap. You just need to put it in there once you know how much and who is offering.
     
  4. Offline

    haussik

    But now i am not in my Main class, do i need to import it to my Main class?
     
  5. Offline

    Skionz

    haussik Your putting a 'Player' in a HashMap that takes a String and an Integer. Are you getting a syntax error?
     
  6. Offline

    haussik

    nothing :( Keep saying that the value are null for both
     
  7. Offline

    Qaisar101

    Are you using Eclipse? Yes you are. Just tell us if you get any errors. I know how to fix those. :)
     
  8. Offline

    haussik

    I don't have any errors, i don't understand .. well, close this topic because it will never be fixed :p
     
  9. Offline

    mrCookieSlime Retired Staff

    Locked per request.
     
Thread Status:
Not open for further replies.

Share This Page