Merge branch 'master' of ssh://184.154.0.242:7999/min/Mineplex

This commit is contained in:
CoderTim 2014-09-15 23:32:04 -04:00
commit d5313540d7
3 changed files with 125 additions and 5 deletions

View File

@ -10,9 +10,11 @@ import org.bukkit.Effect;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; 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 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.F;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilParticle;
@ -22,6 +24,7 @@ import mineplex.core.treasure.animation.ChestOpenAnimation;
import mineplex.core.treasure.animation.ChestSpawnAnimation; import mineplex.core.treasure.animation.ChestSpawnAnimation;
import mineplex.core.treasure.animation.CircleAnimation; import mineplex.core.treasure.animation.CircleAnimation;
import mineplex.core.treasure.animation.FireworksAnimation; import mineplex.core.treasure.animation.FireworksAnimation;
import mineplex.core.treasure.animation.TreasureRemoveAnimation;
import mineplex.core.treasure.reward.ITreasureReward; import mineplex.core.treasure.reward.ITreasureReward;
import mineplex.core.treasure.reward.RewardRarity; import mineplex.core.treasure.reward.RewardRarity;
@ -220,14 +223,21 @@ public class Treasure
return _centerBlock.getRelative(BlockFace.UP); 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.setType(material);
block.setData(data); block.setData(data);
block.getLocation().getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId()); 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) public void openChest(Block block)
{ {
ChestData data = getChestData(block); ChestData data = getChestData(block);
@ -257,11 +267,33 @@ public class Treasure
if (isFinished()) if (isFinished())
{ {
TreasureRemoveAnimation animation = new TreasureRemoveAnimation(this, _blockRestoreMap);
_animations.add(animation);
_finished = true; _finished = true;
} }
} }
} }
public void sendChestOpenPackets(Player... players)
{
for (ChestData data : _chestData)
{
if (data.isOpened())
{
Block block = data.getBlock();
PacketPlayOutBlockAction packet = new PacketPlayOutBlockAction(block.getX(), block.getY(), block.getZ(), CraftMagicNumbers.getBlock(block), 1, 1);
for (Player player : players)
{
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
System.out.println("sending chest open packet");
}
}
}
}
public ChestData getChestData(Block block) public ChestData getChestData(Block block)
{ {
for (ChestData data : _chestData) for (ChestData data : _chestData)
@ -310,9 +342,14 @@ public class Treasure
Block block = entry.getKey(); Block block = entry.getKey();
BlockInfo data = entry.getValue(); 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.setTypeId(data.getId());
block.setData(data.getData()); block.setData(data.getData());
block.getLocation().getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId());
} }
for (Animation animation : _animations) for (Animation animation : _animations)

View File

@ -14,6 +14,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -29,7 +30,6 @@ import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.inventory.InventoryManager; import mineplex.core.inventory.InventoryManager;
import mineplex.core.treasure.event.TreasureFinishEvent; import mineplex.core.treasure.event.TreasureFinishEvent;
@ -341,6 +341,27 @@ public class TreasureManager extends MiniPlugin
} }
} }
@EventHandler
public void join(PlayerJoinEvent event)
{
final Player player = event.getPlayer();
_plugin.getServer().getScheduler().runTaskLater(_plugin, new Runnable()
{
@Override
public void run()
{
if (!player.isOnline())
return;
for (Treasure treasure : _playerTreasureMap.values())
{
treasure.sendChestOpenPackets(player);
}
}
}, 10L);
}
@EventHandler @EventHandler
public void quit(PlayerQuitEvent event) public void quit(PlayerQuitEvent event)
{ {

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()
{
}
}