Search in sources :

Example 11 with ParallelUniverse

use of thpmc.engine.api.world.parallel.ParallelUniverse in project THP-Engine by TheHollowPlanetMC.

the class ImplTHPEngineAPI method removeUniverse.

@Override
public void removeUniverse(String universeName) {
    ParallelUniverse universe = getUniverse(universeName);
    if (universe != null)
        ((ImplParallelUniverse) universe).getPlayers().forEach(player -> player.setUniverse(null));
    universeMap.remove(universeName);
}
Also used : JavaPlugin(org.bukkit.plugin.java.JavaPlugin) TimeUnit(java.util.concurrent.TimeUnit) Nullable(org.jetbrains.annotations.Nullable) INMSHandler(thpmc.engine.api.nms.INMSHandler) ParallelUniverse(thpmc.engine.api.world.parallel.ParallelUniverse) THPEngineAPI(thpmc.engine.api.THPEngineAPI) Collection(java.util.Collection) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) NMSManager(thpmc.engine.nms.NMSManager) NotNull(org.jetbrains.annotations.NotNull) ParallelUniverse(thpmc.engine.api.world.parallel.ParallelUniverse)

Example 12 with ParallelUniverse

use of thpmc.engine.api.world.parallel.ParallelUniverse in project THP-Engine by TheHollowPlanetMC.

the class PlayerJoinQuitListener method onJoin.

@EventHandler
public void onJoin(PlayerJoinEvent event) {
    // Inject packet handler
    Player player = event.getPlayer();
    EnginePlayer enginePlayer = ImplEnginePlayer.onPlayerJoin(player);
    ParallelUniverse universe = THPEngineAPI.getInstance().createUniverse(player.getUniqueId().toString());
    universe.addPlayer(enginePlayer);
    Object wrappedParallelPlayer = ChiyogamiManager.getWrappedParallelPlayer(player);
    if (wrappedParallelPlayer != null)
        ChiyogamiManager.setCheckFunction(enginePlayer, wrappedParallelPlayer);
    PacketHandler packetHandler = new PacketHandler(enginePlayer);
    try {
        ChannelPipeline pipeline = NMSManager.getNMSHandler().getChannel(player).pipeline();
        pipeline.addBefore("packet_handler", THPEngine.getPlugin().getName() + "PacketInjector:" + player.getName(), packetHandler);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ImplEnginePlayer(thpmc.engine.impl.ImplEnginePlayer) Player(org.bukkit.entity.Player) EnginePlayer(thpmc.engine.api.player.EnginePlayer) PacketHandler(thpmc.engine.nms.PacketHandler) ParallelUniverse(thpmc.engine.api.world.parallel.ParallelUniverse) ImplEnginePlayer(thpmc.engine.impl.ImplEnginePlayer) EnginePlayer(thpmc.engine.api.player.EnginePlayer) ChannelPipeline(io.netty.channel.ChannelPipeline) EventHandler(org.bukkit.event.EventHandler)

Example 13 with ParallelUniverse

use of thpmc.engine.api.world.parallel.ParallelUniverse in project THP-Engine by TheHollowPlanetMC.

the class FlyPacketHandler method rewrite.

@Override
public Object rewrite(Object packet, EnginePlayer EnginePlayer, boolean cacheSetting) {
    ParallelUniverse universe = EnginePlayer.getUniverse();
    if (universe == null)
        return packet;
    World world = EnginePlayer.getBukkitPlayer().getWorld();
    String worldName = world.getName();
    ParallelWorld parallelWorld = universe.getWorld(worldName);
    EntityPlayer entityPlayer = ((CraftPlayer) EnginePlayer.getBukkitPlayer()).getHandle();
    int x = NumberConversions.floor(entityPlayer.locX());
    int y = NumberConversions.floor(entityPlayer.locY());
    int z = NumberConversions.floor(entityPlayer.locZ());
    int downY = y - 1;
    downY = Math.max(0, downY);
    if (parallelWorld.hasBlockData(x, y, z) || parallelWorld.hasBlockData(x, downY, z)) {
        try {
            PlayerConnection playerConnection = entityPlayer.playerConnection;
            C.set(playerConnection, 0);
            E.set(playerConnection, 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return packet;
}
Also used : ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) ParallelUniverse(thpmc.engine.api.world.parallel.ParallelUniverse) EntityPlayer(net.minecraft.server.v1_16_R3.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) World(org.bukkit.World) ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) PlayerConnection(net.minecraft.server.v1_16_R3.PlayerConnection)

Example 14 with ParallelUniverse

use of thpmc.engine.api.world.parallel.ParallelUniverse in project THP-Engine by TheHollowPlanetMC.

the class LightUpdatePacketHandler method rewrite.

@Override
public Object rewrite(Object packet, EnginePlayer EnginePlayer, boolean cacheSetting) {
    ParallelUniverse universe = EnginePlayer.getUniverse();
    if (universe == null)
        return packet;
    World world = EnginePlayer.getBukkitPlayer().getWorld();
    String worldName = world.getName();
    ParallelWorld parallelWorld = universe.getWorld(worldName);
    try {
        int chunkX = a.getInt(packet);
        int chunkZ = b.getInt(packet);
        boolean iFlag = i.getBoolean(packet);
        ParallelChunk parallelChunk = parallelWorld.getChunk(chunkX, chunkZ);
        if (parallelChunk == null)
            return packet;
        Object cachedPacket = parallelChunk.getCachedLightUpdatePacket();
        if (cachedPacket != null)
            return cachedPacket;
        int cValue = c.getInt(packet);
        int dValue = d.getInt(packet);
        int eValue = e.getInt(packet);
        int fValue = f.getInt(packet);
        Deque<byte[]> gValue = new ArrayDeque<>((List<byte[]>) g.get(packet));
        Deque<byte[]> hValue = new ArrayDeque<>((List<byte[]>) h.get(packet));
        int newC = 0;
        int newD = 0;
        int newE = 0;
        int newF = 0;
        List<byte[]> newG = new ArrayList<>();
        List<byte[]> newH = new ArrayList<>();
        boolean edited = false;
        for (int index = 0; index < 18; index++) {
            int sectionIndex = index - 1;
            int cSectionBit = cValue & (1 << index);
            newC |= cSectionBit;
            newE |= eValue & (1 << index);
            int dSectionBit = dValue & (1 << index);
            newD |= dSectionBit;
            newF |= fValue & (1 << index);
            if (index == 0 || index == 17) {
                if (cSectionBit != 0) {
                    newG.add(gValue.removeFirst());
                }
                if (dSectionBit != 0) {
                    newH.add(hValue.removeFirst());
                }
                continue;
            }
            SectionLevelArray skyLevelArray = parallelChunk.getSkyLightSectionLevelArray(sectionIndex);
            SectionLevelArray blockLevelArray = parallelChunk.getBlockLightSectionLevelArray(sectionIndex);
            if (skyLevelArray == null) {
                if (cSectionBit != 0) {
                    newG.add(gValue.removeFirst());
                }
            } else {
                if (cSectionBit == 0) {
                    NibbleArray nibbleArray = new NibbleArray();
                    boolean notEmpty = skyLevelArray.threadsafeIteration(nibbleArray::a);
                    if (notEmpty)
                        edited = true;
                    newG.add(nibbleArray.asBytes());
                    if (notEmpty) {
                        newC |= 1 << index;
                        newE &= ~(1 << index);
                    } else {
                        newE |= 1 << index;
                    }
                } else {
                    NibbleArray nibbleArray = new NibbleArray(gValue.removeFirst().clone());
                    boolean notEmpty = skyLevelArray.threadsafeIteration(nibbleArray::a);
                    if (notEmpty)
                        edited = true;
                    newG.add(nibbleArray.asBytes());
                    if (notEmpty) {
                        newE &= ~(1 << index);
                    }
                }
            }
            if (blockLevelArray == null) {
                if (dSectionBit != 0) {
                    newH.add(hValue.removeFirst());
                }
            } else {
                if (dSectionBit == 0) {
                    NibbleArray nibbleArray = new NibbleArray();
                    boolean notEmpty = blockLevelArray.threadsafeIteration(nibbleArray::a);
                    if (notEmpty)
                        edited = true;
                    newH.add(nibbleArray.asBytes());
                    if (notEmpty) {
                        newD |= 1 << index;
                        newF &= ~(1 << index);
                    } else {
                        newF |= 1 << index;
                    }
                } else {
                    NibbleArray nibbleArray = new NibbleArray(hValue.removeFirst().clone());
                    boolean notEmpty = blockLevelArray.threadsafeIteration(nibbleArray::a);
                    if (notEmpty)
                        edited = true;
                    newH.add(nibbleArray.asBytes());
                    if (notEmpty) {
                        newF &= ~(1 << index);
                    }
                }
            }
        }
        if (!edited)
            return packet;
        PacketPlayOutLightUpdate newPacket = new PacketPlayOutLightUpdate();
        a.set(newPacket, chunkX);
        b.set(newPacket, chunkZ);
        c.set(newPacket, newC);
        d.set(newPacket, newD);
        e.set(newPacket, newE);
        f.set(newPacket, newF);
        g.set(newPacket, newG);
        h.set(newPacket, newH);
        i.set(newPacket, iFlag);
        if (cacheSetting)
            parallelChunk.setLightUpdatePacketCache(newPacket);
        return newPacket;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return packet;
}
Also used : ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk) PacketPlayOutLightUpdate(net.minecraft.server.v1_16_R3.PacketPlayOutLightUpdate) World(org.bukkit.World) ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) NibbleArray(net.minecraft.server.v1_16_R3.NibbleArray) ParallelUniverse(thpmc.engine.api.world.parallel.ParallelUniverse) SectionLevelArray(thpmc.engine.util.SectionLevelArray)

Example 15 with ParallelUniverse

use of thpmc.engine.api.world.parallel.ParallelUniverse in project THP-Engine by TheHollowPlanetMC.

the class MapChunkPacketHandler method rewrite.

@Override
public Object rewrite(Object packet, EnginePlayer EnginePlayer, boolean cacheSetting) {
    ParallelUniverse universe = EnginePlayer.getUniverse();
    if (universe == null)
        return packet;
    World world = EnginePlayer.getBukkitPlayer().getWorld();
    String worldName = world.getName();
    ParallelWorld parallelWorld = universe.getWorld(worldName);
    try {
        int chunkX = a.getInt(packet);
        int chunkZ = b.getInt(packet);
        ParallelChunk parallelChunk = parallelWorld.getChunk(chunkX, chunkZ);
        if (parallelChunk == null)
            return packet;
        Object cachedPacket = parallelChunk.getCachedMapChunkPacket();
        if (cachedPacket != null)
            return cachedPacket;
        ChunkSnapshot chunkSnapshot = AsyncWorldCache.getChunkCache(worldName, chunkX, chunkZ);
        if (chunkSnapshot == null)
            return packet;
        DataPaletteBlock<IBlockData>[] cachedDataBlocks = (DataPaletteBlock<IBlockData>[]) blockids.get(chunkSnapshot);
        ChunkSection[] chunkSections = new ChunkSection[16];
        int nonEmptyChunkSections = 0;
        boolean edited = false;
        for (int index = 0; index < 16; index++) {
            ChunkSection chunkSection = Chunk.a;
            SectionTypeArray sectionTypeArray = parallelChunk.getSectionTypeArray(index);
            if (sectionTypeArray != null) {
                DataPaletteBlock<IBlockData> cachedBlockData = cachedDataBlocks[index];
                if (cachedBlockData != null) {
                    final short[] nonEmptyTemp = { 0 };
                    cachedBlockData.a((iBlockData, i) -> {
                        Fluid fluid = iBlockData.getFluid();
                        if (!iBlockData.isAir()) {
                            nonEmptyTemp[0] = (short) (nonEmptyTemp[0] + i);
                        }
                        if (!fluid.isEmpty()) {
                            nonEmptyTemp[0] = (short) (nonEmptyTemp[0] + i);
                        }
                    });
                    short nonEmpty = nonEmptyTemp[0];
                    chunkSection = new ChunkSection(index << 4, nonEmpty, (short) 0, (short) 0);
                    NBTTagCompound data = new NBTTagCompound();
                    cachedBlockData.a(data, "Palette", "BlockStates");
                    DataPaletteBlock<IBlockData> blocks = chunkSection.getBlocks();
                    blocks.a(data.getList("Palette", 10), data.getLongArray("BlockStates"));
                }
                if (chunkSection == Chunk.a)
                    chunkSection = new ChunkSection(index << 4);
                ChunkSection finalChunkSection = chunkSection;
                boolean notEmpty = sectionTypeArray.threadsafeIteration((x, y, z, iBlockData) -> {
                    finalChunkSection.setType(x, y, z, (IBlockData) iBlockData);
                });
                if (notEmpty)
                    edited = true;
            } else {
                if (!chunkSnapshot.isSectionEmpty(index)) {
                    DataPaletteBlock<IBlockData> dataPaletteBlock = cachedDataBlocks[index];
                    final short[] nonEmptyTemp = { 0 };
                    dataPaletteBlock.a((iBlockData, i) -> {
                        Fluid fluid = iBlockData.getFluid();
                        if (!iBlockData.isAir()) {
                            nonEmptyTemp[0] = (short) (nonEmptyTemp[0] + i);
                        }
                        if (!fluid.isEmpty()) {
                            nonEmptyTemp[0] = (short) (nonEmptyTemp[0] + i);
                        }
                    });
                    short nonEmpty = nonEmptyTemp[0];
                    chunkSection = new ChunkSection(index << 4, nonEmpty, (short) 0, (short) 0);
                    blockIds.set(chunkSection, dataPaletteBlock);
                }
            }
            if (chunkSection != Chunk.a)
                nonEmptyChunkSections |= (1 << index);
            chunkSections[index] = chunkSection;
        }
        if (!edited)
            return packet;
        Chunk chunk = new Chunk(((CraftWorld) world).getHandle(), new ChunkCoordIntPair(chunkX, chunkZ), null, ChunkConverter.a, TickListEmpty.b(), TickListEmpty.b(), 0L, chunkSections, null);
        int cValue = c.getInt(packet);
        PacketPlayOutMapChunk newPacket = new PacketPlayOutMapChunk(chunk, nonEmptyChunkSections | cValue);
        NBTTagCompound dValue = (NBTTagCompound) d.get(packet);
        Object eValue = e.get(packet);
        List<NBTTagCompound> gValue = (List<NBTTagCompound>) g.get(packet);
        boolean hValue = h.getBoolean(packet);
        d.set(newPacket, dValue);
        e.set(newPacket, eValue);
        g.set(newPacket, gValue);
        h.set(newPacket, hValue || nonEmptyChunkSections == 65535);
        if (cacheSetting)
            parallelChunk.setMapChunkPacketCache(newPacket);
        return newPacket;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return packet;
}
Also used : ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) ChunkSnapshot(org.bukkit.ChunkSnapshot) CraftChunkSnapshot(org.bukkit.craftbukkit.v1_16_R3.CraftChunkSnapshot) ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) World(org.bukkit.World) List(java.util.List) ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk) SectionTypeArray(thpmc.engine.util.SectionTypeArray) ParallelUniverse(thpmc.engine.api.world.parallel.ParallelUniverse)

Aggregations

ParallelUniverse (thpmc.engine.api.world.parallel.ParallelUniverse)16 ParallelWorld (thpmc.engine.api.world.parallel.ParallelWorld)12 World (org.bukkit.World)7 ParallelChunk (thpmc.engine.api.world.parallel.ParallelChunk)6 BlockData (org.bukkit.block.data.BlockData)4 Player (org.bukkit.entity.Player)3 EnginePlayer (thpmc.engine.api.player.EnginePlayer)3 SectionTypeArray (thpmc.engine.util.SectionTypeArray)3 List (java.util.List)2 BlockPosition (net.minecraft.server.v1_15_R1.BlockPosition)2 ChunkSnapshot (org.bukkit.ChunkSnapshot)2 Block (org.bukkit.block.Block)2 CraftBlockData (org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData)2 THPEngineAPI (thpmc.engine.api.THPEngineAPI)2 be4rjp.artgui.button (be4rjp.artgui.button)1 Artist (be4rjp.artgui.frame.Artist)1 ArtMenu (be4rjp.artgui.menu.ArtMenu)1 IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)1 LocalSession (com.sk89q.worldedit.LocalSession)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1