danik159

Untitled

Aug 16th, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. package me.chickenstyle.luckyblocks.utilsfolder;
  2.  
  3. import org.bukkit.Effect;
  4. import org.bukkit.Location;
  5. import org.bukkit.Material;
  6. import org.bukkit.entity.ArmorStand;
  7. import org.bukkit.entity.EntityType;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.inventory.ItemStack;
  10. import org.bukkit.inventory.meta.ItemMeta;
  11. import org.bukkit.scheduler.BukkitRunnable;
  12. import org.bukkit.util.EulerAngle;
  13.  
  14. import me.chickenstyle.luckyblocks.LuckyCube;
  15. import me.chickenstyle.luckyblocks.Main;
  16. import me.chickenstyle.luckyblocks.Message;
  17.  
  18.  
  19.  
  20. public class CrateAnimation extends BukkitRunnable {
  21.  
  22. ArmorStand stand;
  23. Player player;
  24. Location loc;
  25. LuckyCube block;
  26. ItemStack prize;
  27.  
  28. int ticks = 0;
  29. int newTicks = 0;
  30. boolean runOnce = false;
  31.  
  32.  
  33. @SuppressWarnings("deprecation")
  34. public CrateAnimation(Location loc,Player player,LuckyCube block,ItemStack prize) {
  35. loc.add(0.5,0,0.5);
  36. stand = (ArmorStand) loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND);
  37. stand.setArms(true);
  38. stand.setVisible(false);
  39. stand.setGravity(false);
  40. stand.setSmall(true);
  41. stand.setHelmet(Utils.createLuckyCube(block));
  42. this.loc = loc;
  43. this.player = player;
  44. this.block = block;
  45. this.prize = prize;
  46.  
  47. }
  48.  
  49. @SuppressWarnings("deprecation")
  50. @Override
  51. public void run() {
  52. if (ticks <= 100) {
  53. EulerAngle oldrot = stand.getHeadPose();
  54. EulerAngle newrot = oldrot.add(0, 0.2f, 0);
  55. stand.setHeadPose(newrot);
  56. stand.teleport(stand.getLocation().add(0,0.01,0));
  57. ticks = ticks + 2;
  58. } else {
  59. if (runOnce == false) {
  60. player.playSound(player.getLocation(), Utils.getChestOpenSound(), 1f, 1f);
  61. stand.getWorld().playEffect(player.getLocation(), Effect.valueOf("CRIT"), 250);
  62. stand.setHelmet(new ItemStack(Material.AIR));
  63. stand.setRightArmPose(new EulerAngle(90f, 90f, 10f));
  64. stand.setItemInHand(prize);
  65. }
  66.  
  67. if (newTicks <= 100) {
  68. Location rotatingLoc = stand.getLocation().clone();
  69. float yaw = rotatingLoc.getYaw() + 4;
  70. if (yaw >= 180)
  71. yaw *= -1;
  72. rotatingLoc.setYaw(yaw);
  73. stand.teleport(rotatingLoc);
  74. newTicks = newTicks + 2;
  75. } else {
  76. stand.remove();
  77. //Give item
  78. if (player.getInventory().firstEmpty() != -1) {
  79. player.getInventory().addItem(prize);
  80. } else {
  81. player.getWorld().dropItemNaturally(player.getLocation(), prize);
  82. }
  83.  
  84. //Send message
  85. String message = Message.GIVE_MESSAGE.getMSG();
  86. ItemMeta meta = prize.getItemMeta();
  87.  
  88. message = message.replace("{amount}", prize.getAmount() + "");
  89. if (meta.hasDisplayName()) {
  90. message = message.replace("{item}", meta.getDisplayName());
  91. } else {
  92. message = message.replace("{item}", Utils.getName(prize.getType()));
  93. }
  94.  
  95. if (Main.getInstance().getConfig().getBoolean("sendMessageOnOpen")) {
  96. player.sendMessage(Utils.color(message));
  97. }
  98.  
  99.  
  100. stand.getWorld().playEffect(player.getLocation(), Effect.valueOf("CRIT"), 250);
  101.  
  102.  
  103. player.playSound(player.getLocation(), Utils.getChestCloseSound(), 1f, 1f);
  104. cancel();
  105.  
  106. return;
  107. }
  108. }
  109. }
  110.  
  111. }
  112.  
Advertisement
Add Comment
Please, Sign In to add comment