Added effects to chets opening and changed flowers to leaves so they don't drop any items when removed

This commit is contained in:
LCastr0 2017-04-07 14:02:30 -03:00
parent 888c26c12d
commit 45e3223962
4 changed files with 139 additions and 49 deletions

View File

@ -224,6 +224,15 @@ public class Treasure
block.getLocation().add(.5 + rX, .7, .5 + rZ));
coloredParticle.display();
}
else if (_treasureType == TreasureType.SPRING)
{
int r = (int) (Math.random() * 2);
double rX = Math.random() * 2 - 1, rZ = Math.random() * 2 - 1;
ColoredParticle coloredParticle = new ColoredParticle(UtilParticle.ParticleType.RED_DUST,
new DustSpellColor((r == 0) ? Color.RED : Color.YELLOW),
block.getLocation().add(.5 + rX, .7, .5 + rZ));
coloredParticle.display();
}
else
{
UtilParticle.PlayParticle(type, block.getLocation().add(0.5, 0.5, 0.5), 0.5F, 0.5F, 0.5F, 0.2F, 0,

View File

@ -3,15 +3,10 @@ package mineplex.core.treasure.animation;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Skull;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPhysicsEvent;
import mineplex.core.common.MaterialData;
import mineplex.core.common.skin.SkinData;
@ -21,7 +16,7 @@ import mineplex.core.treasure.BlockInfo;
import mineplex.core.treasure.Treasure;
import mineplex.core.treasure.TreasureType;
public class BlockChangeAnimation extends Animation implements Listener
public class BlockChangeAnimation extends Animation
{
private static final int MAX_RADIUS = 4;
@ -36,7 +31,6 @@ public class BlockChangeAnimation extends Animation implements Listener
_currentRadius = 0;
_blockInfoList = blockInfoList;
_chests = chests;
Bukkit.getPluginManager().registerEvents(this, treasure.getTreasureManager().getPlugin());
}
@Override
@ -266,32 +260,19 @@ public class BlockChangeAnimation extends Animation implements Listener
else if (getTreasure().getTreasureType() == TreasureType.SPRING)
{
List<MaterialData> materials = new ArrayList<>();
materials.add(MaterialData.of(Material.LONG_GRASS, (byte) 1));
materials.add(MaterialData.of(Material.LONG_GRASS, (byte) 2));
materials.add(MaterialData.of(Material.DEAD_BUSH, (byte) 0));
materials.add(MaterialData.of(Material.YELLOW_FLOWER, (byte) 0));
materials.add(MaterialData.of(Material.RED_ROSE, (byte) 0));
materials.add(MaterialData.of(Material.RED_ROSE, (byte) 1));
materials.add(MaterialData.of(Material.RED_ROSE, (byte) 2));
materials.add(MaterialData.of(Material.RED_ROSE, (byte) 3));
materials.add(MaterialData.of(Material.RED_ROSE, (byte) 4));
materials.add(MaterialData.of(Material.RED_ROSE, (byte) 5));
materials.add(MaterialData.of(Material.RED_ROSE, (byte) 6));
materials.add(MaterialData.of(Material.RED_ROSE, (byte) 7));
materials.add(MaterialData.of(Material.RED_ROSE, (byte) 8));
materials.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 0));
materials.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 1));
materials.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 2));
materials.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 3));
materials.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 4));
materials.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 5));
materials.add(MaterialData.of(Material.LEAVES, (byte) 0));
materials.add(MaterialData.of(Material.LEAVES, (byte) 1));
materials.add(MaterialData.of(Material.LEAVES, (byte) 2));
materials.add(MaterialData.of(Material.LEAVES, (byte) 3));
materials.add(MaterialData.of(Material.LEAVES_2, (byte) 0));
materials.add(MaterialData.of(Material.LEAVES_2, (byte) 1));
for (Block c : _chests)
{
if (c.equals(b))
{
_blockInfoList.add(new BlockInfo(b));
int r = UtilMath.random.nextInt(materials.size());
MaterialData materialData = materials.get(r);
_blockInfoList.add(new BlockInfo(b));
b.setType(materialData.getMaterial());
b.setData(materialData.getData());
}
@ -308,7 +289,6 @@ public class BlockChangeAnimation extends Animation implements Listener
@Override
protected void onFinish()
{
HandlerList.unregisterAll(this);
}
private byte getDirection(Block block)
@ -350,18 +330,4 @@ public class BlockChangeAnimation extends Animation implements Listener
return BlockFace.SOUTH;
}
}
@EventHandler
public void onFlowerDrop(BlockPhysicsEvent event)
{
for (Block block : _chests)
{
if (event.getBlock().equals(block))
{
event.setCancelled(true);
event.getBlock().setType(Material.AIR);
return;
}
}
}
}

View File

@ -1,22 +1,32 @@
package mineplex.core.treasure.animation;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.MathHelper;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import com.google.common.collect.Lists;
import mineplex.core.Managers;
import mineplex.core.common.MaterialData;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
@ -30,13 +40,14 @@ import mineplex.core.common.util.particles.ColoredParticle;
import mineplex.core.common.util.particles.DustSpellColor;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.disguise.disguises.DisguiseBat;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.particleeffects.BabyFireworkEffect;
import mineplex.core.particleeffects.CircleEffect;
import mineplex.core.treasure.BlockInfo;
import mineplex.core.treasure.Treasure;
import mineplex.core.treasure.TreasureType;
public class ChestSpawnAnimation extends Animation
public class ChestSpawnAnimation extends Animation implements Listener
{
private static final int ANIMATION_DURATION = 80;
@ -47,6 +58,8 @@ public class ChestSpawnAnimation extends Animation
private Location _particleLocation;
private Vector _particleDirection;
private Location _openingCenter;
private List<BlockInfo> _chestBlockInfo;
private double _radialOffset;
@ -58,6 +71,8 @@ public class ChestSpawnAnimation extends Animation
private int _currentHauntedColor = 0;
private List<ArmorStand> _bats = Lists.newArrayList();
private List<MaterialData> _flowers = new ArrayList<>();
private List<Item> _droppedFlowers = new ArrayList<>();
public ChestSpawnAnimation(Treasure treasure, Block block, List<BlockInfo> chestBlockInfo, Block openingCenter, double radialOffset, JavaPlugin javaPlugin)
{
@ -83,8 +98,10 @@ public class ChestSpawnAnimation extends Animation
_centerLocation = block.getLocation().clone().add(0.5, 0.5, 0.5);
_chestBlockInfo = chestBlockInfo;
_particleLocation = openingCenter.getLocation().add(0.5, 4, 0.5);
_particleLocation = openingCenter.getLocation().clone().add(0.5, 4, 0.5);
_openingCenter = openingCenter.getLocation();
_particleDirection = UtilAlg.getTrajectory(_particleLocation, _centerLocation);
_particleDirection.multiply(UtilMath.offset(_particleLocation, _centerLocation) / (double)ANIMATION_DURATION);
@ -103,6 +120,8 @@ public class ChestSpawnAnimation extends Animation
_radialOffset = radialOffset;
_javaPlugin = javaPlugin;
Bukkit.getPluginManager().registerEvents(this, javaPlugin);
}
@Override
@ -112,7 +131,18 @@ public class ChestSpawnAnimation extends Animation
//Move Particle Forwards
_particleLocation.add(_particleDirection);
Iterator<Item> droppedFlowersIterator = _droppedFlowers.iterator();
while (droppedFlowersIterator.hasNext())
{
Item flower = droppedFlowersIterator.next();
if (flower.getTicksLived() >= 20)
{
flower.remove();
droppedFlowersIterator.remove();
}
}
//Play Particles
if (getTreasure().getTreasureType() == TreasureType.OLD || getTreasure().getTreasureType() == TreasureType.LOVE_CHEST)
{
@ -246,10 +276,20 @@ public class ChestSpawnAnimation extends Animation
doBats(true, _centerLocation.clone().add(0, 6, 0), _bats);
}
}
else if (getTreasure().getTreasureType() == TreasureType.ST_PATRICKS)
else if (getTreasure().getTreasureType() == TreasureType.SPRING)
{
Location location = _centerLocation.clone().add(0, 5, 0);
if (getTicks() % 5 == 0)
{
if (_flowers.size() == 0)
generateFlowerList();
int r = UtilMath.random.nextInt(_flowers.size());
MaterialData materialData = _flowers.get(r);
Item flower = _openingCenter.getWorld().dropItem(_openingCenter.clone().add(0.5, 0, 0.5), ItemStackFactory.Instance.CreateStack(materialData.getMaterial(), materialData.getData(), 1, "Flower" + getTicks()));
Vector vel = new Vector(_openingCenter.getX() - _centerLocation.getX(), 0, _openingCenter.getZ() - _centerLocation.getZ());
UtilAction.velocity(flower, vel, 0.1, false, 0, 0.2 + 1 * 0.4, 1, false);
_droppedFlowers.add(flower);
}
}
//Spawn Chest
@ -338,7 +378,12 @@ public class ChestSpawnAnimation extends Animation
@Override
protected void onFinish()
{
HandlerList.unregisterAll(this);
for (Item item : _droppedFlowers)
{
item.remove();
}
_droppedFlowers.clear();
}
private void doBats(boolean initial, Location center, List<ArmorStand> bats)
@ -372,4 +417,34 @@ public class ChestSpawnAnimation extends Animation
}
}
}
private void generateFlowerList()
{
_flowers.add(MaterialData.of(Material.LONG_GRASS, (byte) 1));
_flowers.add(MaterialData.of(Material.LONG_GRASS, (byte) 2));
_flowers.add(MaterialData.of(Material.DEAD_BUSH, (byte) 0));
_flowers.add(MaterialData.of(Material.YELLOW_FLOWER, (byte) 0));
_flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 0));
_flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 1));
_flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 2));
_flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 3));
_flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 4));
_flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 5));
_flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 6));
_flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 7));
_flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 8));
_flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 0));
_flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 1));
_flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 2));
_flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 3));
_flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 4));
_flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 5));
}
@EventHandler
public void onPickup(PlayerPickupItemEvent event)
{
if (_droppedFlowers.contains(event.getItem()))
event.setCancelled(true);
}
}

View File

@ -1,5 +1,6 @@
package mineplex.core.treasure.animation;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@ -9,7 +10,9 @@ import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import mineplex.core.common.MaterialData;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilMath;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.treasure.BlockInfo;
import mineplex.core.treasure.Treasure;
@ -20,6 +23,7 @@ public class TreasureRemoveAnimation extends Animation
private Random _random = new Random();
private List<BlockInfo> _otherChests;
private int _count = 0;
private List<MaterialData> _flowers = new ArrayList<>();
public TreasureRemoveAnimation(Treasure treasure, List<BlockInfo> otherChests)
{
@ -42,6 +46,19 @@ public class TreasureRemoveAnimation extends Animation
dropItem(ItemStackFactory.Instance.CreateStack(Material.GOLD_NUGGET, (byte) 0, 1, "DroppedNugget" + _count), info);
_count++;
}
else if (getTreasure().getTreasureType() == TreasureType.SPRING)
{
// Drops random flower
if (_flowers.size() == 0)
generateFlowerList();
int r = UtilMath.random.nextInt(_flowers.size());
MaterialData materialData = _flowers.get(r);
dropItem(ItemStackFactory.Instance.CreateStack(materialData.getMaterial(), materialData.getData(), 1, "Flower" + _count), info);
_count++;
info.getBlock().setType(Material.AIR);
info.getBlock().setData((byte) 0);
}
}
else
{
@ -60,6 +77,29 @@ public class TreasureRemoveAnimation extends Animation
getTreasure().getTreasureManager().addItem(item);
}
private void generateFlowerList()
{
_flowers.add(MaterialData.of(Material.LONG_GRASS, (byte) 1));
_flowers.add(MaterialData.of(Material.LONG_GRASS, (byte) 2));
_flowers.add(MaterialData.of(Material.DEAD_BUSH, (byte) 0));
_flowers.add(MaterialData.of(Material.YELLOW_FLOWER, (byte) 0));
_flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 0));
_flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 1));
_flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 2));
_flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 3));
_flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 4));
_flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 5));
_flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 6));
_flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 7));
_flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 8));
_flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 0));
_flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 1));
_flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 2));
_flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 3));
_flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 4));
_flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 5));
}
@Override
protected void onFinish()
{