Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.chickenstyle.luckyblocks.utilsfolder;
- import org.bukkit.Effect;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.entity.ArmorStand;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.util.EulerAngle;
- import me.chickenstyle.luckyblocks.LuckyCube;
- import me.chickenstyle.luckyblocks.Main;
- import me.chickenstyle.luckyblocks.Message;
- public class CrateAnimation extends BukkitRunnable {
- ArmorStand stand;
- Player player;
- Location loc;
- LuckyCube block;
- ItemStack prize;
- int ticks = 0;
- int newTicks = 0;
- boolean runOnce = false;
- @SuppressWarnings("deprecation")
- public CrateAnimation(Location loc,Player player,LuckyCube block,ItemStack prize) {
- loc.add(0.5,0,0.5);
- stand = (ArmorStand) loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND);
- stand.setArms(true);
- stand.setVisible(false);
- stand.setGravity(false);
- stand.setSmall(true);
- stand.setHelmet(Utils.createLuckyCube(block));
- this.loc = loc;
- this.player = player;
- this.block = block;
- this.prize = prize;
- }
- @SuppressWarnings("deprecation")
- @Override
- public void run() {
- if (ticks <= 100) {
- EulerAngle oldrot = stand.getHeadPose();
- EulerAngle newrot = oldrot.add(0, 0.2f, 0);
- stand.setHeadPose(newrot);
- stand.teleport(stand.getLocation().add(0,0.01,0));
- ticks = ticks + 2;
- } else {
- if (runOnce == false) {
- player.playSound(player.getLocation(), Utils.getChestOpenSound(), 1f, 1f);
- stand.getWorld().playEffect(player.getLocation(), Effect.valueOf("CRIT"), 250);
- stand.setHelmet(new ItemStack(Material.AIR));
- stand.setRightArmPose(new EulerAngle(90f, 90f, 10f));
- stand.setItemInHand(prize);
- }
- if (newTicks <= 100) {
- Location rotatingLoc = stand.getLocation().clone();
- float yaw = rotatingLoc.getYaw() + 4;
- if (yaw >= 180)
- yaw *= -1;
- rotatingLoc.setYaw(yaw);
- stand.teleport(rotatingLoc);
- newTicks = newTicks + 2;
- } else {
- stand.remove();
- //Give item
- if (player.getInventory().firstEmpty() != -1) {
- player.getInventory().addItem(prize);
- } else {
- player.getWorld().dropItemNaturally(player.getLocation(), prize);
- }
- //Send message
- String message = Message.GIVE_MESSAGE.getMSG();
- ItemMeta meta = prize.getItemMeta();
- message = message.replace("{amount}", prize.getAmount() + "");
- if (meta.hasDisplayName()) {
- message = message.replace("{item}", meta.getDisplayName());
- } else {
- message = message.replace("{item}", Utils.getName(prize.getType()));
- }
- if (Main.getInstance().getConfig().getBoolean("sendMessageOnOpen")) {
- player.sendMessage(Utils.color(message));
- }
- stand.getWorld().playEffect(player.getLocation(), Effect.valueOf("CRIT"), 250);
- player.playSound(player.getLocation(), Utils.getChestCloseSound(), 1f, 1f);
- cancel();
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment