mirror of
https://github.com/songoda/UltimateKits.git
synced 2024-11-02 16:49:34 +01:00
Fixed issue with crate animation and improved code.
This commit is contained in:
parent
05cb6490c5
commit
c06c6f5207
@ -283,8 +283,6 @@ public class Kit {
|
||||
if (amt != amtToGive)
|
||||
Collections.shuffle(innerContents);
|
||||
|
||||
CrateAnimateTask task = null;
|
||||
|
||||
for (int i = 0; i < innerContents.size(); i ++) {
|
||||
KitItem item = innerContents.get(i);
|
||||
if (amtToGive == 0) continue;
|
||||
@ -314,8 +312,7 @@ public class Kit {
|
||||
amtToGive--;
|
||||
|
||||
if (kitAnimation != KitAnimation.NONE) {
|
||||
final CrateAnimateTask cTask = new CrateAnimateTask(plugin, player, this, item.getItem());
|
||||
task = cTask;
|
||||
final CrateAnimateTask cTask = new CrateAnimateTask(plugin, player, this, item.getItem(), i == (innerContents.size() - 1));
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, cTask::start, 140 * i);
|
||||
} else {
|
||||
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(item.getItem());
|
||||
@ -325,9 +322,6 @@ public class Kit {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (task != null) {
|
||||
task.setLast(true);
|
||||
}
|
||||
|
||||
player.updateInventory();
|
||||
} catch (Exception e) {
|
||||
|
@ -33,15 +33,16 @@ public class CrateAnimateTask extends BukkitRunnable {
|
||||
private boolean slow = false;
|
||||
private boolean finish = false;
|
||||
private boolean done = false;
|
||||
private boolean last = false;
|
||||
private boolean last;
|
||||
private int num = 0;
|
||||
|
||||
private Listener listener;
|
||||
|
||||
public CrateAnimateTask(UltimateKits plugin, Player player, Kit kit, ItemStack give) {
|
||||
public CrateAnimateTask(UltimateKits plugin, Player player, Kit kit, ItemStack give, boolean last) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
this.give = give;
|
||||
this.last = last;
|
||||
this.inventory = Bukkit.createInventory(null, 27, TextComponent.formatText(kit.getShowableName()));
|
||||
|
||||
List<KitItem> items = kit.getContents();
|
||||
@ -128,14 +129,11 @@ public class CrateAnimateTask extends BukkitRunnable {
|
||||
|
||||
private void finish() {
|
||||
instance.cancel();
|
||||
HandlerList.unregisterAll(listener);
|
||||
if (last) {
|
||||
HandlerList.unregisterAll(listener);
|
||||
Bukkit.broadcastMessage("last");
|
||||
listener = null;
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
|
||||
public void setLast(boolean last) {
|
||||
this.last = last;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user