2016-04-14 16:24:03 +00:00
|
|
|
package me.mrCookieSlime.Slimefun.AncientAltar;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import me.mrCookieSlime.CSCoreLibPlugin.general.Particles.MC_1_8.ParticleEffect;
|
|
|
|
import me.mrCookieSlime.Slimefun.SlimefunStartup;
|
|
|
|
import me.mrCookieSlime.Slimefun.listeners.AncientAltarListener;
|
2018-05-03 18:47:12 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.Variables;
|
2016-04-14 16:24:03 +00:00
|
|
|
|
|
|
|
import org.bukkit.Effect;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.Sound;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.Item;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
public class RitualAnimation implements Runnable {
|
|
|
|
|
|
|
|
List<Block> altars;
|
2018-07-15 06:02:45 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
Block altar;
|
|
|
|
Location l;
|
|
|
|
ItemStack output;
|
|
|
|
List<Block> pedestals;
|
|
|
|
List<ItemStack> items;
|
2018-07-15 06:02:45 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
List<Location> particles;
|
2018-07-15 06:02:45 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
boolean running;
|
2018-03-02 19:40:45 +00:00
|
|
|
int stage;
|
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;
|
|
|
|
this.particles = new ArrayList<Location>();
|
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;
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
idle();
|
2018-03-02 19:40:45 +00:00
|
|
|
if(this.stage == 36) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(this.stage > 0 && this.stage % 4 == 0) {
|
|
|
|
checkPedestal(pedestals.get(this.stage / 4 - 1));
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
private void idle() {
|
|
|
|
try {
|
|
|
|
ParticleEffect.SPELL_WITCH.display(l, 1.2F, 0F, 1.2F, 0, 16);
|
|
|
|
ParticleEffect.FIREWORKS_SPARK.display(l, 0.2F, 0F, 0.2F, 0, 8);
|
|
|
|
for (Location l2: particles) {
|
|
|
|
ParticleEffect.ENCHANTMENT_TABLE.display(l2, 0.3F, 0.2F, 0.3F, 0, 16);
|
|
|
|
ParticleEffect.CRIT_MAGIC.display(l2, 0.3F, 0.2F, 0.3F, 0, 8);
|
|
|
|
}
|
|
|
|
} 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);
|
|
|
|
if (item == null) abort();
|
|
|
|
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()));
|
2016-04-14 16:24:03 +00:00
|
|
|
pedestal.getWorld().playSound(pedestal.getLocation(), Sound.ENTITY_ENDERMEN_TELEPORT, 5F, 2F);
|
2018-07-15 06:02:45 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
try {
|
|
|
|
ParticleEffect.ENCHANTMENT_TABLE.display(pedestal.getLocation().add(0.5, 1.5, 0.5), 0.3F, 0.2F, 0.3F, 0, 16);
|
|
|
|
ParticleEffect.CRIT_MAGIC.display(pedestal.getLocation().add(0.5, 1.5, 0.5), 0.3F, 0.2F, 0.3F, 0, 8);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2018-07-15 06:02:45 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
item.remove();
|
|
|
|
pedestal.removeMetadata("item_placed", SlimefunStartup.instance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void abort() {
|
|
|
|
running = false;
|
2018-08-06 19:13:46 +00:00
|
|
|
|
2018-05-03 18:47:12 +00:00
|
|
|
pedestals.forEach((pblock)->{
|
|
|
|
Variables.altarinuse.remove(pblock.getLocation());
|
|
|
|
});
|
2018-08-06 19:13:46 +00:00
|
|
|
|
2018-07-15 06:02:45 +00:00
|
|
|
Variables.altarinuse.remove(altar.getLocation()); // should re-enable altar blocks on craft failure.
|
|
|
|
l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 5F, 1F);
|
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
|
|
|
|
2018-07-09 14:41:22 +00:00
|
|
|
pedestals.forEach((pblock)->{
|
|
|
|
Variables.altarinuse.remove(pblock.getLocation());
|
|
|
|
});
|
2018-07-15 06:02:45 +00:00
|
|
|
Variables.altarinuse.remove(altar.getLocation()); // should re-enable altar blocks on craft completion.
|
|
|
|
altars.remove(altar);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_BREAK_DOOR_WOOD, 1F, 1F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|