mirror of
https://github.com/songoda/UltimateKits.git
synced 2024-11-26 20:25:53 +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)
|
if (amt != amtToGive)
|
||||||
Collections.shuffle(innerContents);
|
Collections.shuffle(innerContents);
|
||||||
|
|
||||||
CrateAnimateTask task = null;
|
|
||||||
|
|
||||||
for (int i = 0; i < innerContents.size(); i ++) {
|
for (int i = 0; i < innerContents.size(); i ++) {
|
||||||
KitItem item = innerContents.get(i);
|
KitItem item = innerContents.get(i);
|
||||||
if (amtToGive == 0) continue;
|
if (amtToGive == 0) continue;
|
||||||
@ -314,8 +312,7 @@ public class Kit {
|
|||||||
amtToGive--;
|
amtToGive--;
|
||||||
|
|
||||||
if (kitAnimation != KitAnimation.NONE) {
|
if (kitAnimation != KitAnimation.NONE) {
|
||||||
final CrateAnimateTask cTask = new CrateAnimateTask(plugin, player, this, item.getItem());
|
final CrateAnimateTask cTask = new CrateAnimateTask(plugin, player, this, item.getItem(), i == (innerContents.size() - 1));
|
||||||
task = cTask;
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, cTask::start, 140 * i);
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, cTask::start, 140 * i);
|
||||||
} else {
|
} else {
|
||||||
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(item.getItem());
|
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(item.getItem());
|
||||||
@ -325,9 +322,6 @@ public class Kit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (task != null) {
|
|
||||||
task.setLast(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -33,15 +33,16 @@ 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;
|
private boolean last;
|
||||||
private int num = 0;
|
private int num = 0;
|
||||||
|
|
||||||
private Listener listener;
|
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.plugin = plugin;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.give = give;
|
this.give = give;
|
||||||
|
this.last = last;
|
||||||
this.inventory = Bukkit.createInventory(null, 27, TextComponent.formatText(kit.getShowableName()));
|
this.inventory = Bukkit.createInventory(null, 27, TextComponent.formatText(kit.getShowableName()));
|
||||||
|
|
||||||
List<KitItem> items = kit.getContents();
|
List<KitItem> items = kit.getContents();
|
||||||
@ -128,14 +129,11 @@ public class CrateAnimateTask extends BukkitRunnable {
|
|||||||
|
|
||||||
private void finish() {
|
private void finish() {
|
||||||
instance.cancel();
|
instance.cancel();
|
||||||
|
HandlerList.unregisterAll(listener);
|
||||||
if (last) {
|
if (last) {
|
||||||
HandlerList.unregisterAll(listener);
|
Bukkit.broadcastMessage("last");
|
||||||
listener = null;
|
listener = null;
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLast(boolean last) {
|
|
||||||
this.last = last;
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user