Search in sources :

Example 1 with WrapperPlayServerBlockChange

use of me.SuperRonanCraft.BetterRTPAddons.packets.WrapperPlayServerBlockChange in project BetterRTP by SuperRonanCraft.

the class PortalsCache method cachePortal.

public void cachePortal(Player p, Location loc, boolean loc2) {
    PortalsRegionInfo portal;
    if (portalsBeingCreated.containsKey(p)) {
        portal = portalsBeingCreated.get(p);
    } else {
        portal = new PortalsRegionInfo();
        portalsBeingCreated.put(p, portal);
    }
    Location old_loc1 = portal.loc_1;
    Location old_loc2 = portal.loc_2;
    if (loc2)
        portal.loc_2 = loc;
    else
        portal.loc_1 = loc;
    if (portal.loc_1 != null && portal.loc_2 != null)
        if (old_loc1 == null || old_loc2 == null)
            addonPortals.msgs.getLocation_Ready(p);
    if (Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
        ProtocolManager pm = ProtocolLibrary.getProtocolManager();
        // if (portal.loc_1 != null && portal.loc_2 != null) {
        // if (Math.abs(portal.loc_1.getBlockX() - portal.loc_2.getBlockX()) <= 10)
        // if (Math.abs(portal.loc_1.getBlockZ() - portal.loc_2.getBlockZ()) <= 10)
        // if (Math.abs(portal.loc_1.getBlockY() - portal.loc_2.getBlockY()) <= 10) {
        // preview(portal.loc_1, portal.loc_2);
        // }
        /*Location max = portal.loc_1;
                Location min = portal.loc_2;
                for (int x = Math.max(max.getBlockX(), min.getBlockX()); x >= Math.min(min.getBlockX(), max.getBlockX()); x--) {
                    for (int y = Math.max(max.getBlockY(), min.getBlockY()); y >= Math.min(min.getBlockY(), max.getBlockY()); y--) {
                        for (int z = Math.max(max.getBlockZ(), min.getBlockZ()); z >= Math.min(min.getBlockZ(), max.getBlockZ()); z--) {
                            WrapperPlayServerBlockChange packet = new WrapperPlayServerBlockChange(pm.createPacket(PacketType.Play.Server.BLOCK_CHANGE));
                            packet.setBlockData(WrappedBlockData.createData(Material.REDSTONE_BLOCK));
                            packet.setLocation(new BlockPosition(new Location(max.getWorld(), x, y, z).toVector()));
                            packet.sendPacket(p);
                            //Block block = max.getWorld().getBlockAt(x, y, z);
                            //block.setType(Material.GLOWSTONE);
                        }
                    }
                }*/
        // } else {
        WrapperPlayServerBlockChange packet = new WrapperPlayServerBlockChange(pm.createPacket(PacketType.Play.Server.BLOCK_CHANGE));
        packet.setBlockData(WrappedBlockData.createData(Material.GLOWSTONE));
        packet.setLocation(new BlockPosition(loc.toVector()));
        packet.sendPacket(p);
    // }
    } else {
        try {
            if (loc2)
                p.sendBlockChange(portal.loc_2, Material.GLOWSTONE.createBlockData());
            else
                p.sendBlockChange(portal.loc_1, Material.GLOWSTONE.createBlockData());
        } catch (Exception e) {
        // Not 1.13+ (dont show block changes)
        }
    }
}
Also used : ProtocolManager(com.comphenix.protocol.ProtocolManager) WrapperPlayServerBlockChange(me.SuperRonanCraft.BetterRTPAddons.packets.WrapperPlayServerBlockChange) BlockPosition(com.comphenix.protocol.wrappers.BlockPosition) InvocationTargetException(java.lang.reflect.InvocationTargetException) Location(org.bukkit.Location)

Aggregations

ProtocolManager (com.comphenix.protocol.ProtocolManager)1 BlockPosition (com.comphenix.protocol.wrappers.BlockPosition)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 WrapperPlayServerBlockChange (me.SuperRonanCraft.BetterRTPAddons.packets.WrapperPlayServerBlockChange)1 Location (org.bukkit.Location)1