Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.creepysoul.luckypackages.animation;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.bukkit.ChatColor;
- import org.bukkit.Effect;
- import org.bukkit.Location;
- import org.bukkit.block.Block;
- import org.bukkit.block.Chest;
- import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
- import org.bukkit.entity.Item;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.util.Vector;
- import com.gmail.filoghost.holographicdisplays.api.Hologram;
- import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
- import com.gmail.filoghost.holographicdisplays.api.line.TextLine;
- import fr.creepysoul.luckypackages.utils.MathUtils;
- import me.chubbyduck1.luckypackages.Core;
- import me.chubbyduck1.luckypackages.files.AnimationFile;
- import me.chubbyduck1.luckypackages.files.CratesFile;
- import me.chubbyduck1.luckypackages.utils.CrateUtils;
- import net.minecraft.server.v1_8_R3.BlockPosition;
- import net.minecraft.server.v1_8_R3.TileEntityChest;
- import net.minecraft.server.v1_8_R3.World;
- public class Animation {
- public static Item item = null;
- public Animation(Location location, String crate) {
- List<ItemStack> rewards = getRewards(crate);
- Location loc = MathUtils.getCenter(location.clone());
- loc.add(0.0, 2.3, 0.0);
- Hologram hologram = summonHologram(crate, loc);
- new BukkitRunnable() {
- boolean error = false;
- int step = 0;
- int rewardCount = 0;
- Item item = null;
- @Override
- public void run() {
- if (error) {
- if (item != null) {
- item.remove();
- }
- cancel();
- } else {
- if (step == 0) {
- Block chest = location.getBlock();
- if (chest.getState() instanceof Chest) {
- playChestAction((Chest) chest.getState(), true);
- } else {
- error = true;
- }
- step++;
- } else if (step == 1) {
- Location loc = MathUtils.getCenter(location.clone());
- loc.add(0.0, 1.0, 0.0);
- loc.setDirection(new Vector(0.0, 10.0, 0.0));
- loc.getWorld().playEffect(loc, Effect.valueOf(AnimationFile.getConfig().getString("particles")), 0);
- item = summonItem(loc, rewards.get(rewardCount));
- item.setVelocity(new Vector(0.0, 0.2, 0.0));
- item.setPickupDelay(Integer.MAX_VALUE);
- String itemName = null;
- for (String crates : CratesFile.getConfig().getConfigurationSection("Crates").getKeys(false)) {
- if (crates.equalsIgnoreCase(crate)) {
- itemName = ChatColor.translateAlternateColorCodes('&', CratesFile.getConfig().getString("Crates." + crates + ".Rewards." + String.valueOf(rewardCount + 1) + ".Name"));
- }
- }
- setItemName(hologram, itemName);
- rewardCount++;
- if (rewardCount >= rewards.size()) {
- rewardCount = 0;
- }
- step++;
- } else if (step == 6) {
- Block chest = location.getBlock();
- if (chest.getState() instanceof Chest) {
- playChestAction((Chest) chest.getState(), false);
- } else {
- error = true;
- }
- step++;
- } else if (step == 7) {
- if (item != null) {
- item.remove();
- }
- step++;
- } else if (step == 10) {
- step = 0;
- } else {
- step++;
- }
- if (item != null) {
- Animation.item = item;
- }
- }
- }
- }.runTaskTimer(Core.core, 5, 5);
- }
- public static void playChestAction(Chest chest, boolean open) {
- Location location = chest.getLocation();
- World world = ((CraftWorld) location.getWorld()).getHandle();
- BlockPosition position = new BlockPosition(location.getX(), location.getY(), location.getZ());
- TileEntityChest tileChest = (TileEntityChest) world.getTileEntity(position);
- world.playBlockAction(position, tileChest.w(), 1, open ? 1 : 0);
- }
- public static Hologram summonHologram(String crate, Location location) {
- Hologram hologram = HologramsAPI.createHologram(Core.core, location);
- hologram.appendTextLine(ChatColor.translateAlternateColorCodes('&', AnimationFile.getConfig().getString("hologram.line1").replace("%crateName%", crate)));
- return hologram;
- }
- public static void setItemName(Hologram hologram, String itemName) {
- try {
- hologram.removeLine(1);
- } catch (Exception e) {
- }
- hologram.appendTextLine(itemName);
- }
- public static Item summonItem(Location location, ItemStack itemStack) {
- Item item = location.getWorld().dropItem(location, itemStack);
- return item;
- }
- private List<ItemStack> getRewards(String Crate) {
- List<ItemStack> crateRewards = new ArrayList<ItemStack>();
- for (String crate : CratesFile.getConfig().getConfigurationSection("Crates.").getKeys(false)) {
- if (crate.equalsIgnoreCase(Crate)) {
- for (String item : CratesFile.getConfig().getConfigurationSection("Crates." + crate + ".Rewards").getKeys(false)) {
- String[] material = CratesFile.getConfig().getString("Crates." + crate + ".Rewards." + item + ".Material").split(":");
- if (material[0].equalsIgnoreCase("SKULL")) {
- crateRewards.add(CrateUtils.getCrateRewardSkull(crate, item));
- } else {
- crateRewards.add(CrateUtils.getCrateReward(crate, item));
- }
- }
- }
- }
- return crateRewards;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement