New animation

This commit is contained in:
NichtStudioCode 2021-01-24 20:55:34 +01:00
parent 101ca28f70
commit d50f24e557
4 changed files with 43 additions and 18 deletions

@ -3,6 +3,7 @@ package de.studiocode.invgui.animation.impl;
import de.studiocode.invgui.InvGui;
import de.studiocode.invgui.animation.Animation;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
@ -25,8 +26,11 @@ public abstract class BaseAnimation implements Animation {
private BukkitTask task;
private int frame;
public BaseAnimation(int tickDelay) {
public BaseAnimation(int tickDelay, boolean sound) {
this.tickDelay = tickDelay;
if (sound) addShowHandler((frame, index) -> getPlayer().playSound(getPlayer().getLocation(),
Sound.ENTITY_ITEM_PICKUP, 1, 1));
}
protected abstract void handleFrame(int frame);
@ -44,8 +48,8 @@ public abstract class BaseAnimation implements Animation {
else this.show = show;
}
protected void show(int i) {
show.accept(frame, i);
protected void show(int... slots) {
for (int i : slots) show.accept(frame, i);
}
@Override
@ -62,7 +66,7 @@ public abstract class BaseAnimation implements Animation {
this.slots = new CopyOnWriteArrayList<>(slots);
}
protected void finished() {
protected void finish() {
task.cancel();
finishHandlers.forEach(Runnable::run);
}

@ -1,7 +1,6 @@
package de.studiocode.invgui.animation.impl;
import de.studiocode.invgui.item.Item;
import org.bukkit.Sound;
import java.util.List;
import java.util.Random;
@ -14,10 +13,7 @@ public class RandomAnimation extends BaseAnimation {
private final Random random = new Random();
public RandomAnimation(int tickDelay, boolean sound) {
super(tickDelay);
if (sound) addShowHandler((frame, index) -> getPlayer().playSound(getPlayer().getLocation(),
Sound.ENTITY_ITEM_PICKUP, 1, 1));
super(tickDelay, sound);
}
@Override
@ -28,7 +24,7 @@ public class RandomAnimation extends BaseAnimation {
int slot = slots.get(random.nextInt(slots.size()));
slots.remove(Integer.valueOf(slot));
show(slot);
} else finished();
} else finish();
}
}

@ -1,20 +1,16 @@
package de.studiocode.invgui.animation.impl;
import de.studiocode.invgui.item.Item;
import org.bukkit.Sound;
import java.util.List;
/**
* Lets the {@link Item}s pop up index after index.
*/
public class IndexAnimation extends BaseAnimation {
public class SequentialAnimation extends BaseAnimation {
public IndexAnimation(int tickDelay, boolean sound) {
super(tickDelay);
if (sound) addShowHandler((frame, index) -> getPlayer().playSound(getPlayer().getLocation(),
Sound.ENTITY_ITEM_PICKUP, 1, 1));
public SequentialAnimation(int tickDelay, boolean sound) {
super(tickDelay, sound);
}
@Override
@ -23,7 +19,7 @@ public class IndexAnimation extends BaseAnimation {
if (!slots.isEmpty()) {
show(slots.get(0));
slots.remove(0);
} else finished();
} else finish();
}
}

@ -0,0 +1,29 @@
package de.studiocode.invgui.animation.impl;
import java.util.List;
public class SplitSequentialAnimation extends BaseAnimation {
public SplitSequentialAnimation(int tickDelay, boolean sound) {
super(tickDelay, sound);
}
@Override
protected void handleFrame(int frame) {
List<Integer> slots = getSlots();
int i = slots.get(0);
int i2 = slots.get(slots.size() - 1);
show(i, i2);
if (slots.size() <= 2) {
finish();
return;
}
slots.remove(0);
slots.remove(slots.size() - 1);
}
}