Solved Kit won't work?

Discussion in 'Plugin Development' started by BeastCraft3, Dec 6, 2014.

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

    BeastCraft3

    Hello, I created a kit plugin, and today I've tried to add a cooldown on it. It worked perfect before I added the cooldown, and now it doesn't do anything. Please help me this is the HashMap I store the usage in:
    Code:java
    1. public HashMap<UUID, Long> map = new HashMap<UUID, Long>();

    and this is the kit:
    Code:java
    1. if(args[0].equalsIgnoreCase("warrior")) {
    2. long cooldown = 1800;
    3. if(map.containsKey(p.getUniqueId())) {
    4. p.sendMessage(kit);
    5. long diff = (System.currentTimeMillis() - map.get(p.getUniqueId()))/1000;
    6. if (diff < cooldown) {
    7. p.sendMessage(ChatColor.RED + "Time remaining on kit warrior is "+(cooldown - diff)+" seconds");
    8. } else {
    9. p.sendMessage(ChatColor.DARK_AQUA + "Kit recieved!");
    10. p.getInventory().addItem(new ItemStack(Material.DIAMOND_SWORD, 1));
    11. p.getInventory().addItem(new ItemStack(Material.DIAMOND_AXE, 1));
    12. p.getInventory().addItem(new ItemStack(Material.DIAMOND_PICKAXE, 1));
    13. p.getInventory().addItem(new ItemStack(Material.IRON_HOE, 1));
    14. p.getInventory().addItem(new ItemStack(Material.COOKED_BEEF, 384));
    15. p.getInventory().addItem(new ItemStack(Material.FLINT, 320));
    16. p.getInventory().addItem(new ItemStack(Material.SEEDS, 320));
    17. p.getInventory().addItem(new ItemStack(Material.CLAY_BALL, 320));
    18. p.getInventory().setBoots(new ItemStack(Material.DIAMOND_BOOTS));
    19. pi.setLeggings(new ItemStack(Material.DIAMOND_LEGGINGS));
    20. pi.setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE));
    21. pi.setHelmet(new ItemStack(Material.DIAMOND_HELMET));
    22. map.put(p.getUniqueId(), System.currentTimeMillis());
    23. }
    24. }
    25. }
     
  2. Offline

    Skionz

    BeastCraft3 Debug. My bet is that you never added the player to the Map.
     
  3. Offline

    BeastCraft3

    Skionz
    ohh, I want to add the player to a map each time he use the kit warrior. so i'm a little confused where I should add him. Maybe in a PlayerJoinEvent ??

    EDIT: Maybe I should check if a player isn't in the map then send him the message(String) and continue it with an else statement.
    If that gave any sence xD
     
  4. Offline

    TheCodingCat

    BeastCraft3 I would actually prefer to use configs for kit cooldowns because if you reload or have to restart the server they can use it right away and I wouldn't want that :)
     
  5. Offline

    BeastCraft3

    TheCodingCat
    Ik, but thats not really the issue atm, first I wan't to find out how to make the cooldown work.
    I tried to make a kit like this, but it gave the same resualt :p
    Code:java
    1. if(args[0].equalsIgnoreCase("mage")) {
    2. long cooldown = 2700;
    3. if(map.containsKey(p.getUniqueId())) {
    4. p.sendMessage(kit);
    5. } else {
    6. long diff = (System.currentTimeMillis() - map.get(p.getUniqueId()))/1000;
    7. if (diff < cooldown) {
    8. p.sendMessage(ChatColor.RED + "Time remaining on kit Mage is "+(cooldown - diff)+" seconds");
    9. } else if(!map.containsKey(p.getUniqueId())) {
    10. p.sendMessage(ChatColor.DARK_AQUA + "Kit recieved!");
    11. p.getInventory().addItem(new ItemStack(Material.DIAMOND_SWORD, 1));
    12. p.getInventory().addItem(new ItemStack(Material.DIAMOND_AXE, 1));
    13. p.getInventory().addItem(new ItemStack(Material.DIAMOND_PICKAXE, 1));
    14. p.getInventory().addItem(new ItemStack(Material.IRON_HOE, 1));
    15. p.getInventory().addItem(new ItemStack(Material.COOKED_BEEF, 384));
    16. p.getInventory().addItem(new ItemStack(Material.FLINT, 320));
    17. p.getInventory().addItem(new ItemStack(Material.SEEDS, 320));
    18. p.getInventory().addItem(new ItemStack(Material.CLAY_BALL, 320));
    19. p.getInventory().setBoots(new ItemStack(Material.DIAMOND_BOOTS));
    20. pi.setLeggings(new ItemStack(Material.DIAMOND_LEGGINGS));
    21. pi.setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE));
    22. pi.setHelmet(new ItemStack(Material.DIAMOND_HELMET));
    23. map.put(p.getUniqueId(), System.currentTimeMillis());
    24. }
    25.  
    26. return true;
    27. }
    28. }
     
  6. Offline

    xTrollxDudex

  7. Offline

    BeastCraft3

    xTrollxDudex
    I'm don't know how to use that code for a command, and I really want to find out how to make the countdown work with my current code ;3
     
  8. Offline

    Skionz

    BeastCraft3 You can't because your current code does not work.
     
  9. Offline

    BeastCraft3

    Skionz
    then give me some help?
     
  10. Offline

    xTrollxDudex

  11. Offline

    BeastCraft3

    xTrollxDudex
    I read the entire thingy and it was a little advanced, I didn't understand it completly, so am asking for help..
     
  12. Offline

    xTrollxDudex

    Skionz likes this.
  13. Offline

    BeastCraft3

    xTrollxDudex
    Ik I should try, but whats the point of trying something when you don't even know what it means?!
     
  14. Offline

    Skionz

  15. Offline

    xTrollxDudex

    BeastCraft3
    You don't know if you can do something if you've never done it before
     
  16. Offline

    BeastCraft3

    xTrollxDudex Skionz
    omg, I'm closing this thread.....
    I came for help, not someone telling me to test something out when I've done it.. and someone else telling me to google it.. Don't you think I've googled it?! I always google if I don't understand something.
     
Thread Status:
Not open for further replies.

Share This Page