2019-08-27 13:27:38 +00:00
|
|
|
package me.mrCookieSlime.Slimefun.ancient_altar;
|
2016-04-14 16:24:03 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2019-08-03 16:54:45 +00:00
|
|
|
import java.util.HashMap;
|
2016-04-14 16:24:03 +00:00
|
|
|
import java.util.List;
|
2019-08-03 16:54:45 +00:00
|
|
|
import java.util.Map;
|
2016-04-14 16:24:03 +00:00
|
|
|
|
|
|
|
import me.mrCookieSlime.Slimefun.SlimefunStartup;
|
|
|
|
import me.mrCookieSlime.Slimefun.listeners.AncientAltarListener;
|
2019-08-27 11:28:07 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.Utilities;
|
2016-04-14 16:24:03 +00:00
|
|
|
|
2019-08-03 16:54:45 +00:00
|
|
|
import org.bukkit.Effect;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.Particle;
|
|
|
|
import org.bukkit.Sound;
|
2016-04-14 16:24:03 +00:00
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.Item;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
public class RitualAnimation implements Runnable {
|
|
|
|
|
2019-08-27 11:28:07 +00:00
|
|
|
private List<Block> altars;
|
2018-07-15 06:02:45 +00:00
|
|
|
|
2019-08-27 11:28:07 +00:00
|
|
|
private Block altar;
|
|
|
|
private Location l;
|
|
|
|
private ItemStack output;
|
|
|
|
private List<Block> pedestals;
|
|
|
|
private List<ItemStack> items;
|
2018-07-15 06:02:45 +00:00
|
|
|
|
2019-08-27 11:28:07 +00:00
|
|
|
private List<Location> particles;
|
2019-08-27 12:08:09 +00:00
|
|
|
private Map<Item, Location> itemLock = new HashMap<>();
|
2018-07-15 06:02:45 +00:00
|
|
|
|
2019-08-27 11:28:07 +00:00
|
|
|
private boolean running;
|
|
|
|
private int stage;
|
|
|
|
|
2019-08-27 12:08:09 +00:00
|
|
|
private Utilities utilities = SlimefunStartup.instance.getUtilities();
|
2018-07-15 06:02:45 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
public RitualAnimation(List<Block> altars, Block altar, Location drop, ItemStack output, List<Block> pedestals, List<ItemStack> items) {
|
|
|
|
this.l = drop;
|
|
|
|
this.altar = altar;
|
|
|
|
this.altars = altars;
|
|
|
|
this.output = output;
|
|
|
|
this.pedestals = pedestals;
|
|
|
|
this.items = items;
|
2019-08-25 20:21:06 +00:00
|
|
|
this.particles = new ArrayList<>();
|
2018-07-15 06:02:45 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
this.running = true;
|
2018-03-02 19:40:45 +00:00
|
|
|
this.stage = 0;
|
2019-08-27 12:08:09 +00:00
|
|
|
|
|
|
|
for (Block pedestal: this.pedestals) {
|
|
|
|
Item item = AncientAltarListener.findItem(pedestal);
|
|
|
|
this.itemLock.put(item, item.getLocation().clone());
|
2019-08-03 16:54:45 +00:00
|
|
|
}
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
idle();
|
2019-08-25 20:21:06 +00:00
|
|
|
|
2019-08-27 12:08:09 +00:00
|
|
|
if (!checkLockedItems()) {
|
2019-08-03 16:54:45 +00:00
|
|
|
abort();
|
2019-08-03 17:47:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-08-25 20:21:06 +00:00
|
|
|
|
2019-08-27 12:08:09 +00:00
|
|
|
if (this.stage == 36) {
|
2018-03-02 19:40:45 +00:00
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
2019-08-25 20:21:06 +00:00
|
|
|
|
2019-08-27 12:08:09 +00:00
|
|
|
if (this.stage > 0 && this.stage % 4 == 0) {
|
2018-03-02 19:40:45 +00:00
|
|
|
checkPedestal(pedestals.get(this.stage / 4 - 1));
|
|
|
|
}
|
2019-08-25 20:21:06 +00:00
|
|
|
|
2018-03-02 19:40:45 +00:00
|
|
|
this.stage += 1;
|
|
|
|
SlimefunStartup.instance.getServer().getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, this, 8);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
2018-07-15 06:02:45 +00:00
|
|
|
|
2019-08-03 16:54:45 +00:00
|
|
|
private boolean checkLockedItems() {
|
2019-08-27 12:08:09 +00:00
|
|
|
for (Map.Entry<Item, Location> entry: itemLock.entrySet()) {
|
|
|
|
if (entry.getKey().getLocation().distance(entry.getValue()) > 0.3) {
|
2019-08-03 16:54:45 +00:00
|
|
|
return false;
|
2019-08-25 20:21:06 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-03 16:54:45 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
private void idle() {
|
|
|
|
try {
|
2018-09-04 15:28:41 +00:00
|
|
|
l.getWorld().spawnParticle(Particle.SPELL_WITCH, l,16, 1.2F, 0F, 1.2F);
|
|
|
|
l.getWorld().spawnParticle(Particle.FIREWORKS_SPARK,l,8, 0.2F, 0F, 0.2F);
|
2019-08-25 20:21:06 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
for (Location l2: particles) {
|
2018-09-04 15:28:41 +00:00
|
|
|
l.getWorld().spawnParticle(Particle.ENCHANTMENT_TABLE, l2,16, 0.3F, 0.2F, 0.3F);
|
|
|
|
l.getWorld().spawnParticle(Particle.CRIT_MAGIC,l2,8, 0.3F, 0.2F, 0.3F);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2018-07-15 06:02:45 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
private void checkPedestal(Block pedestal) {
|
|
|
|
Item item = AncientAltarListener.findItem(pedestal);
|
2019-08-03 16:54:45 +00:00
|
|
|
|
|
|
|
if(item == null || itemLock.remove(item) == null) {
|
|
|
|
abort();
|
|
|
|
}
|
2016-04-14 16:24:03 +00:00
|
|
|
else {
|
|
|
|
particles.add(pedestal.getLocation().add(0.5, 1.5, 0.5));
|
2017-01-05 12:53:11 +00:00
|
|
|
items.add(AncientAltarListener.fixItemStack(item.getItemStack(), item.getCustomName()));
|
2018-09-04 09:33:57 +00:00
|
|
|
pedestal.getWorld().playSound(pedestal.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 5F, 2F);
|
2018-07-15 06:02:45 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
try {
|
2018-09-04 15:28:41 +00:00
|
|
|
l.getWorld().spawnParticle(Particle.ENCHANTMENT_TABLE,pedestal.getLocation().add(0.5, 1.5, 0.5),16, 0.3F, 0.2F, 0.3F);
|
|
|
|
l.getWorld().spawnParticle(Particle.CRIT_MAGIC,pedestal.getLocation().add(0.5, 1.5, 0.5), 8,0.3F, 0.2F, 0.3F);
|
2016-04-14 16:24:03 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2019-08-03 16:54:45 +00:00
|
|
|
|
|
|
|
itemLock.remove(item);
|
2016-04-14 16:24:03 +00:00
|
|
|
item.remove();
|
2019-08-03 16:54:45 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
pedestal.removeMetadata("item_placed", SlimefunStartup.instance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void abort() {
|
|
|
|
running = false;
|
2019-08-27 12:08:09 +00:00
|
|
|
pedestals.forEach(b -> utilities.altarinuse.remove(b.getLocation()));
|
2018-08-06 19:13:46 +00:00
|
|
|
|
2019-08-27 12:08:09 +00:00
|
|
|
// This should re-enable altar blocks on craft failure.
|
|
|
|
utilities.altarinuse.remove(altar.getLocation());
|
2018-07-15 06:02:45 +00:00
|
|
|
l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 5F, 1F);
|
2019-08-03 16:54:45 +00:00
|
|
|
itemLock.clear();
|
2016-04-14 16:24:03 +00:00
|
|
|
altars.remove(altar);
|
|
|
|
}
|
2018-08-06 19:13:46 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
private void finish() {
|
2018-07-15 06:02:45 +00:00
|
|
|
if (running) {
|
|
|
|
l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_VILLAGER_CURE, 1F, 1F);
|
|
|
|
l.getWorld().playEffect(l, Effect.STEP_SOUND, Material.EMERALD_BLOCK);
|
|
|
|
l.getWorld().dropItemNaturally(l.add(0, 1, 0), output);
|
2018-08-06 19:13:46 +00:00
|
|
|
|
2019-08-27 12:08:09 +00:00
|
|
|
pedestals.forEach(b -> utilities.altarinuse.remove(b.getLocation()));
|
|
|
|
|
|
|
|
// This should re-enable altar blocks on craft completion.
|
|
|
|
utilities.altarinuse.remove(altar.getLocation());
|
2018-07-15 06:02:45 +00:00
|
|
|
altars.remove(altar);
|
|
|
|
}
|
|
|
|
else {
|
2018-09-04 09:33:57 +00:00
|
|
|
l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR, 1F, 1F);
|
2018-07-15 06:02:45 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-03 16:54:45 +00:00
|
|
|
}
|