I'm writing gun plugin for my BattleRoyale Server. So, I don't know how to do reload in code. My current algorythm: 1. Check If we are already reloading (HashMap reload<Playername, Is On Reload>) 2. If we aren't reloading: 3. runtasktimer() 4. set item durability to 0 (Max Durablilty) But it is not working properly. Here is the code: Code (Text): public static void reload(Player player) { if(countAmmo(player, getGun(player.getItemInHand().getType())) >= getGun(player.getItemInHand().getType()).getMagazine()) { if(TLFortGuns.onReload.containsKey(player.getName())) { player.sendTitle("",ChatColor.RED + "Уже перезаряжаемся!"); } else { TLFortGuns.onReload.put(player.getName(), true); Bukkit.getScheduler().runTaskTimer(TLFortGuns.getMainPlugin(), new Runnable() { int time = getGun(player.getItemInHand().getType()).getReloadTime(); @Override public void run() { if (this.time == 0) { if(player.getItemInHand().getDurability() == player.getItemInHand().getType().getMaxDurability() - 1) { TLFortGuns.onReload.remove(player.getName()); player.getItemInHand().setDurability((short) 0); } return; } player.sendTitle("",ChatColor.RED + "Ждите"); this.time--; } }, 0L, 1L); } } else { player.sendTitle("",ChatColor.RED + "Закончились патроны!"); } }
In the map store the UUID of the Player That is reloading (or not) and a timestamp (System.currentTimeMilis()). If the player shot -> put him into the map. On reload -> check the map and if the current time minus the stored time (or 0 per default) is greater than your threshold, allow reload, else deny.
Uh oh, just a little bug. It was fixed, but only once it reloads gun with delay, as it should, but then - immediate reload
You can use Code (Java): BukkitTask task = Bukkit.getScheduler().runTaskTimer(TLFortGuns.getMa......... task.cancel(); There is also Code (Java): int taskid = task.getTaskId(); Bukkit.getScheduler().cancelTask(taskid); to cancel the task by it's integer ID.