need some help!!! [easy]

Discussion in 'Plugin Development' started by TheUpdater, Apr 21, 2013.

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

    TheUpdater

    how do i get the green bar under weapons ?
    and charge it every 1 sec

    sy bad grammer
     
  2. Offline

    TheUpdater

    if you use an ex: pick axe the health of the pickaxe will go down, that is the bar i want to now how to get
     
  3. You get it by using your pickaxe, Correct?
     
  4. Offline

    kreashenz

    TheWant3dUn1corn I think he wants to be able to change the durability of an item.. I don't think it's right what I interpret from this, but I've been helping this kid for a while now..
     
  5. Offline

    TheUpdater

    ty you understand me <3
    not gay!!!
     
  6. Offline

    kreashenz

    TheUpdater You can run a task timer to get the player's item in their hand, and then set their durability for full. I'm not giving a code, because you should know how to loop through players.
     
  7. Corrent, Haha
     
  8. Offline

    Tzeentchful

    TheUpdater kreashenz
    I would like to note that it will only work for items that have the durability. Eg pickaxe, hoe, sword. Item like redstone dust and stuff won't have the bar.
     
  9. Offline

    TheUpdater

    PlayerInventory pi = player.getInventory();
    pi.getItemInHand().getDurability();
    pi.getItemInHand().setDurability((short) 5);

    like so? but do timer so its adds 5 whole the time when its on full thay can do somthing

    if(pi.getItemInHand().getDurability() == 10){
    player.sendMessage("Yey");
    }

    well i posted above but its is just example

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  10. Offline

    kreashenz

    TheUpdater You can't get a durability to EQUAL 10... That would basically break all the items. @Tzeenchtful If it doesn't send errors, and it seems to work, its fine :) What could possibly go wrong with having a durability on a building block?
    And no, that isn't a loop. That's just one time. You need to create a TaskTimer, so go read up on that.
     
  11. Offline

    TheUpdater

    haha lol
    like this then?
    Code:
            @EventHandler
            public void test(PlayerInteractEvent e) {
                Player player = e.getPlayer();
                PlayerInventory pi = player.getInventory();
                if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
                        if(pi.getItemInHand().getTypeId() == 294){
                            pi.getItemInHand().getDurability();
                            pi.getItemInHand().setDurability((short) 0.1);
                            if(pi.getItemInHand().equals(pi.getItemInHand().getDurability() == 10)){
                            player.sendMessage("lol");
                    }   
                  }       
              }
            }
        }
      }
    or like this
    Code:
            @EventHandler
            public void test(PlayerInteractEvent e) {
                Player player = e.getPlayer();
                PlayerInventory pi = player.getInventory();
                if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
                        if(pi.getItemInHand().getTypeId() == 294){
                            player.sendMessage("lol1");
                            pi.getItemInHand().getDurability();
                            short s = 50;
                            pi.getItemInHand().setDurability(s);
                            if(pi.getItemInHand().equals(pi.getItemInHand().getDurability() == 50)){
                                do{
                                    s++;
                                }while(s <= 50);
                        }
                    }
                  }
              }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  12. Offline

    kreashenz

    TheUpdater No. Loop =
    Code:java
    1. for(Player p : Bukkit.getOnlinePlayers()){
    2. // do whatever
    3. }
     
  13. Offline

    TheUpdater

    Code:java
    1.  
    2. what do i need this for???
    3. this is how i want it
    4.  
    5. when player right click whit this
    6. its durability will go 50
    7. every 1 sec it will load whit -5 durability
    8. and if durability is = to 50 agine thay can use it agine
    9.  
    10. like an cooldown
    11.  
    12. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  14. Offline

    kreashenz

    TheUpdater Oh my God, you should've said that then!! I don't know how to do that.
     
  15. Offline

    TheUpdater

    cant you do bukkit runnable then do s--; and s++; thing?
     
  16. Offline

    kreashenz

    TheUpdater I don't know, I haven't tried doing this..
     
  17. Offline

    MadArkael

    set 2 long variables = to the current system time in milliseconds and add your cooldown in milliseconds to one of them in this case its 10 seconds.

    long long1 = System.currentTimeMillis();
    long long2 = System.currentTimeMillis() + 10000;

    while (System.currentTimeMillis(); < (long1 + 10000){

    if (System.currentTimeMillis() == long1 + 1000){

    itmTool.setDurability(itmTool.getDurability() - 5);
    }

    and now for the cooldown, use an event to determine if they are using itmTool.

    and do something like:

    if (System.currentTimeMillis() < long2){

    event.setCancelled(true);
    player.sendMessage("You still have to wait " + (long2 - System.currentTimeMillis() / 1000) + " seconds to use this tool!")
    }
     
  18. Offline

    TheUpdater

    well it works but...
    its make 10 to 20 msg whit
    player.sendMessage("You still have to wait " + (long2 - System.currentTimeMillis() / 1000) + " seconds to use this
     
  19. Offline

    Austy

    Won't it create a 10 secs lag? Shouldn't it be scheduled as a task?
     
  20. Offline

    MadArkael

    You are correct austy, the whole while statement is a bad idea. however the cooldown one will work just fine if you are only checking if the cooldown time is satisfied when the player does an action. not all the time

    Code:
    Timer timer = newTimer();
     
    timer.scheduleAtFixedRate(new AddDurabilityTask(), 1000, 10000);
     
     
    where scheduleAtFixedRate(TimerTask task, long delay, long period)
     
    so you are going to have to create the task class now called AddDurabilityTask.
     
    class AddDurabilityTask extends TimerTask{
     
        public void run(){
     
            //this is where you put what the task does
            itmTool.setDurability(itmTool.getDurability() - 5);
        }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  21. Offline

    chasechocolate

    Much easier:
    Code:java
    1. new BukkitRunnable(){
    2. @Override
    3. public void run(){
    4. if(item.getDurability() - 5 > 0){
    5. item.setDurability(((short) item.getDurability) - 5);
    6. } else {
    7. this.cancel();
    8. }
    9. }
    10. }.runTaskTimer(<MAIN CLASS INSTANCE>, 0L, 20L);
     
Thread Status:
Not open for further replies.

Share This Page