mirror of
https://github.com/songoda/UltimateKits.git
synced 2024-12-04 16:13:28 +01:00
Fixed timing issues with crate animation close.
This commit is contained in:
parent
bdb3703481
commit
08611d1eb3
@ -28,6 +28,7 @@ import org.bukkit.inventory.meta.SkullMeta;
|
|||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by songoda on 2/24/2017.
|
* Created by songoda on 2/24/2017.
|
||||||
@ -456,6 +457,8 @@ public class Kit {
|
|||||||
int amt = innerContents.size();
|
int amt = innerContents.size();
|
||||||
int amtToGive = key == null ? amt : key.getAmt();
|
int amtToGive = key == null ? amt : key.getAmt();
|
||||||
|
|
||||||
|
AtomicReference<CrateAnimateTask> task = null;
|
||||||
|
|
||||||
int num = 0;
|
int num = 0;
|
||||||
for (KitItem item : innerContents) {
|
for (KitItem item : innerContents) {
|
||||||
if (amtToGive == 0) continue;
|
if (amtToGive == 0) continue;
|
||||||
@ -487,7 +490,7 @@ public class Kit {
|
|||||||
|
|
||||||
if (kitAnimation != KitAnimation.NONE) {
|
if (kitAnimation != KitAnimation.NONE) {
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin,
|
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 {
|
} else {
|
||||||
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(item.getItem());
|
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(item.getItem());
|
||||||
for (ItemStack item2 : overfilled.values()) {
|
for (ItemStack item2 : overfilled.values()) {
|
||||||
@ -497,12 +500,8 @@ public class Kit {
|
|||||||
num ++;
|
num ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (kitAnimation != KitAnimation.NONE) {
|
if (task.get() != null) {
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin,
|
task.get().setLast(true);
|
||||||
() -> {
|
|
||||||
plugin.getPlayerDataManager().getPlayerAction(player).setInCrate(false);
|
|
||||||
player.closeInventory();
|
|
||||||
}, (210 * num) + 20);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
|
@ -34,6 +34,7 @@ public class CrateAnimateTask extends BukkitRunnable {
|
|||||||
private boolean slow = false;
|
private boolean slow = false;
|
||||||
private boolean finish = false;
|
private boolean finish = false;
|
||||||
private boolean done = false;
|
private boolean done = false;
|
||||||
|
private boolean last = false;
|
||||||
|
|
||||||
public CrateAnimateTask(UltimateKits plugin, Player player, Kit kit, ItemStack give) {
|
public CrateAnimateTask(UltimateKits plugin, Player player, Kit kit, ItemStack give) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -103,20 +104,25 @@ public class CrateAnimateTask extends BukkitRunnable {
|
|||||||
}
|
}
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 10f, 10f);
|
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("_", " ")))));
|
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;
|
done = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
player.openInventory(inventory);
|
player.openInventory(inventory);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void finish() {
|
private void finish() {
|
||||||
instance.cancel();
|
instance.cancel();
|
||||||
|
if (last) {
|
||||||
|
plugin.getPlayerDataManager().getPlayerAction(player).setInCrate(false);
|
||||||
|
player.closeInventory();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLast(boolean last) {
|
||||||
|
this.last = last;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user