Fixed issue with crate animation and improved code.

This commit is contained in:
Brianna O'Keefe 2019-01-17 01:59:07 -05:00
parent 05cb6490c5
commit c06c6f5207
2 changed files with 6 additions and 14 deletions

View File

@ -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) {

View File

@ -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;
}
}