Fix treasure open chest bug, added some animation touches

This commit is contained in:
Shaun Bennett 2014-09-15 13:34:21 -05:00
parent 7c18e89249
commit 63b3621ae3
3 changed files with 96 additions and 9 deletions

View File

@ -13,10 +13,8 @@ import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_7_R4.util.CraftMagicNumbers;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_7_R4.PacketPlayOutBlockAction;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilParticle;
@ -26,6 +24,7 @@ import mineplex.core.treasure.animation.ChestOpenAnimation;
import mineplex.core.treasure.animation.ChestSpawnAnimation;
import mineplex.core.treasure.animation.CircleAnimation;
import mineplex.core.treasure.animation.FireworksAnimation;
import mineplex.core.treasure.animation.TreasureRemoveAnimation;
import mineplex.core.treasure.reward.ITreasureReward;
import mineplex.core.treasure.reward.RewardRarity;
@ -224,14 +223,21 @@ public class Treasure
return _centerBlock.getRelative(BlockFace.UP);
}
public void setBlock(Block block, Material material, byte data)
public void setBlock(Block block, Material material, byte data, boolean addToBlockRestoreMap)
{
_blockRestoreMap.put(block, new BlockInfo(block.getTypeId(), block.getData()));
if (addToBlockRestoreMap)
_blockRestoreMap.put(block, new BlockInfo(block.getTypeId(), block.getData()));
block.setType(material);
block.setData(data);
block.getLocation().getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId());
}
public void setBlock(Block block, Material material, byte data)
{
setBlock(block, material, data, true);
}
public void openChest(Block block)
{
ChestData data = getChestData(block);
@ -261,6 +267,8 @@ public class Treasure
if (isFinished())
{
TreasureRemoveAnimation animation = new TreasureRemoveAnimation(this, _blockRestoreMap);
_animations.add(animation);
_finished = true;
}
}
@ -278,6 +286,7 @@ public class Treasure
for (Player player : players)
{
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
System.out.println("sending chest open packet");
}
}
@ -333,9 +342,14 @@ public class Treasure
Block block = entry.getKey();
BlockInfo data = entry.getValue();
if (block.getType().equals(Material.CHEST))
{
block.getLocation().getWorld().createExplosion(block.getLocation().add(0.5, 0.5, 0.5), 0F);
}
block.getLocation().getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId());
block.setTypeId(data.getId());
block.setData(data.getData());
block.getLocation().getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId());
}
for (Animation animation : _animations)

View File

@ -30,7 +30,6 @@ import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.donation.DonationManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.treasure.event.TreasureFinishEvent;
@ -345,10 +344,22 @@ public class TreasureManager extends MiniPlugin
@EventHandler
public void join(PlayerJoinEvent event)
{
for (Treasure treasure : _playerTreasureMap.values())
final Player player = event.getPlayer();
_plugin.getServer().getScheduler().runTaskLater(_plugin, new Runnable()
{
treasure.sendChestOpenPackets(event.getPlayer());
}
@Override
public void run()
{
if (!player.isOnline())
return;
for (Treasure treasure : _playerTreasureMap.values())
{
treasure.sendChestOpenPackets(player);
}
}
}, 10L);
}
@EventHandler

View File

@ -0,0 +1,62 @@
package mineplex.core.treasure.animation;
import java.util.Random;
import org.bukkit.Material;
import org.bukkit.block.Block;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.treasure.BlockInfo;
import mineplex.core.treasure.Treasure;
/**
* Created by shaun on 14-09-15.
*/
public class TreasureRemoveAnimation extends Animation
{
private Random _random = new Random();
private NautHashMap<Block, BlockInfo> _blockRestoreMap;
public TreasureRemoveAnimation(Treasure treasure, NautHashMap<Block, BlockInfo> blockRestoreMap)
{
super(treasure);
_blockRestoreMap = blockRestoreMap;
}
@Override
protected void tick()
{
// first wait for 1 second
if (getTicks() <= 20)
return;
if (getTicks() % 2 == 0)
{
if (_blockRestoreMap.size() > 4)
{
Block block;
do
{
Block[] keyArray = _blockRestoreMap.keySet().toArray(new Block[0]);
block = keyArray[_random.nextInt(keyArray.length)];
}
while (block.getType() == Material.CHEST);
BlockInfo blockInfo = _blockRestoreMap.remove(block);
getTreasure().setBlock(block, Material.getMaterial(blockInfo.getId()), blockInfo.getData(), false);
}
else
{
finish();
}
}
}
@Override
protected void onFinish()
{
}
}