Send chest open packets for new players that join in the middle of a treasure

This commit is contained in:
Shaun Bennett 2014-09-15 10:37:40 -05:00
parent c7e0ebefd1
commit 7c18e89249
2 changed files with 33 additions and 0 deletions

View File

@ -10,8 +10,12 @@ import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.block.Block;
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;
@ -262,6 +266,25 @@ public class Treasure
}
}
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);
}
}
}
}
public ChestData getChestData(Block block)
{
for (ChestData data : _chestData)

View File

@ -14,6 +14,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
@ -341,6 +342,15 @@ public class TreasureManager extends MiniPlugin
}
}
@EventHandler
public void join(PlayerJoinEvent event)
{
for (Treasure treasure : _playerTreasureMap.values())
{
treasure.sendChestOpenPackets(event.getPlayer());
}
}
@EventHandler
public void quit(PlayerQuitEvent event)
{