Fixed timing issues with crate animation close.

This commit is contained in:
Brianna O'Keefe 2018-10-25 14:15:56 -04:00
parent bdb3703481
commit 08611d1eb3
2 changed files with 15 additions and 10 deletions

View File

@ -28,6 +28,7 @@ import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.RegisteredServiceProvider;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
/**
* Created by songoda on 2/24/2017.
@ -456,6 +457,8 @@ public class Kit {
int amt = innerContents.size();
int amtToGive = key == null ? amt : key.getAmt();
AtomicReference<CrateAnimateTask> task = null;
int num = 0;
for (KitItem item : innerContents) {
if (amtToGive == 0) continue;
@ -487,7 +490,7 @@ public class Kit {
if (kitAnimation != KitAnimation.NONE) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin,
() -> new CrateAnimateTask(plugin, player, this, item.getItem()), 210 * num);
() -> task.set(new CrateAnimateTask(plugin, player, this, item.getItem())), 210 * num);
} else {
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(item.getItem());
for (ItemStack item2 : overfilled.values()) {
@ -497,12 +500,8 @@ public class Kit {
num ++;
}
}
if (kitAnimation != KitAnimation.NONE) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin,
() -> {
plugin.getPlayerDataManager().getPlayerAction(player).setInCrate(false);
player.closeInventory();
}, (210 * num) + 20);
if (task.get() != null) {
task.get().setLast(true);
}
player.updateInventory();

View File

@ -34,6 +34,7 @@ public class CrateAnimateTask extends BukkitRunnable {
private boolean slow = false;
private boolean finish = false;
private boolean done = false;
private boolean last = false;
public CrateAnimateTask(UltimateKits plugin, Player player, Kit kit, ItemStack give) {
this.plugin = plugin;
@ -103,20 +104,25 @@ public class CrateAnimateTask extends BukkitRunnable {
}
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 10f, 10f);
player.sendMessage(plugin.getReferences().getPrefix() + TextComponent.formatText(Lang.CRATE_WON.getConfigValue(WordUtils.capitalize(give.getType().name().toLowerCase().replace("_", " ")))));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> finish(), 50);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, this::finish, 50);
}
done = true;
}
}
player.openInventory(inventory);
}
private void finish() {
instance.cancel();
if (last) {
plugin.getPlayerDataManager().getPlayerAction(player).setInCrate(false);
player.closeInventory();
}
}
public void setLast(boolean last) {
this.last = last;
}
}