Search in sources :

Example 6 with EnginePlayer

use of thpmc.engine.api.player.EnginePlayer in project THP-Engine by TheHollowPlanetMC.

the class EnginePlayerEntity method playTickResult.

@Override
public void playTickResult(EnginePlayer player, boolean absolute) {
    INMSHandler nmsHandler = THPEngineAPI.getInstance().getNMSHandler();
    Player bukkitPlayer = player.getBukkitPlayer();
    nmsHandler.sendPacket(bukkitPlayer, nmsHandler.createHeadRotationPacket(nmsEntity, yaw));
    if (absolute) {
        nmsHandler.sendPacket(bukkitPlayer, nmsHandler.createTeleportPacket(nmsEntity));
    } else {
        nmsHandler.sendPacket(bukkitPlayer, nmsHandler.createRelEntityMoveLookPacket(nmsEntity, x - previousX, y - previousY, z - previousZ, yaw, pitch));
    }
}
Also used : EnginePlayer(thpmc.engine.api.player.EnginePlayer) NMSEntityPlayer(thpmc.engine.api.nms.entity.NMSEntityPlayer) Player(org.bukkit.entity.Player) INMSHandler(thpmc.engine.api.nms.INMSHandler)

Example 7 with EnginePlayer

use of thpmc.engine.api.player.EnginePlayer in project THP-Engine by TheHollowPlanetMC.

the class TickRunner method run.

@Override
public void run() {
    if (beforeTime + TIME - 20 > System.currentTimeMillis())
        return;
    if (isStopped)
        return;
    if (i % TPS == 0) {
        long time = System.currentTimeMillis();
        tps = ((double) Math.round((20.0 / (((double) (time - beforeTime)) / 1000.0)) * 10)) / 10;
        beforeTime = time;
    }
    currentThread = Thread.currentThread();
    this.lastTickMS = System.currentTimeMillis();
    // Should remove check
    entities.removeIf(TickBase::shouldRemove);
    tickOnlyEntities.removeIf(TickBase::shouldRemove);
    // Add entities
    if (addEntities.size() != 0) {
        try {
            ADD_LOCK.lock();
            for (TickBase entity : addEntities) {
                if (entity instanceof EngineEntity) {
                    entities.add((EngineEntity) entity);
                } else {
                    tickOnlyEntities.add(entity);
                }
            }
            addEntities.clear();
        } finally {
            ADD_LOCK.unlock();
        }
    }
    // tick
    tickOnlyEntities.forEach(TickBase::tick);
    entities.forEach(TickBase::tick);
    // Tracker
    for (EnginePlayer enginePlayer : EnginePlayer.getAllPlayers()) {
        EntityTracker entityTracker = getEntityTracker(enginePlayer);
        entityTracker.tick(entities);
    }
    if (i % 40 == 0) {
        trackerMap.keySet().removeIf(enginePlayer -> !enginePlayer.getBukkitPlayer().isOnline());
    }
    entities.forEach(EngineEntity::setPreviousPosition);
    if (i % 100 == 0)
        System.out.printf("ID -> %d   TPS: %.1f%n", ID, tps);
    i++;
}
Also used : EngineEntity(thpmc.engine.api.entity.EngineEntity) TickBase(thpmc.engine.api.entity.TickBase) EnginePlayer(thpmc.engine.api.player.EnginePlayer)

Example 8 with EnginePlayer

use of thpmc.engine.api.player.EnginePlayer in project THP-Engine by TheHollowPlanetMC.

the class ImplParallelUniverse method addDiffs.

@Override
public void addDiffs(ParallelUniverse universe) {
    int indexStart = NMSManager.isHigher_v1_18_R1() ? -4 : 0;
    int indexEnd = NMSManager.isHigher_v1_18_R1() ? 20 : 16;
    for (ParallelWorld diffWorld : universe.getAllWorld()) {
        for (ParallelChunk diffChunk : diffWorld.getAllChunk()) {
            for (int i = indexStart; i < indexEnd; i++) {
                ParallelWorld thisWorld = null;
                ParallelChunk thisChunk = null;
                SectionTypeArray sectionTypeArray = diffChunk.getSectionTypeArray(i);
                if (sectionTypeArray != null) {
                    thisWorld = this.getWorld(diffWorld.getName());
                    thisChunk = ((ImplParallelWorld) thisWorld).createChunkIfAbsent(diffChunk.getChunkX(), diffChunk.getChunkZ());
                    SectionTypeArray thisType = ((ImplParallelChunk) thisChunk).createSectionTypeArrayIfAbsent(i);
                    sectionTypeArray.threadsafeIteration(thisType::setType);
                }
                SectionLevelArray blockLightLevelArray = diffChunk.getBlockLightSectionLevelArray(i);
                if (blockLightLevelArray != null) {
                    if (thisWorld == null)
                        thisWorld = this.getWorld(diffWorld.getName());
                    if (thisChunk == null)
                        thisChunk = ((ImplParallelWorld) thisWorld).createChunkIfAbsent(diffChunk.getChunkX(), diffChunk.getChunkZ());
                    SectionLevelArray thisLevel = ((ImplParallelChunk) thisChunk).createBlockLightSectionLevelArrayIfAbsent(i);
                    blockLightLevelArray.threadsafeIteration(thisLevel::setLevel);
                }
                SectionLevelArray skyLightLevelArray = diffChunk.getSkyLightSectionLevelArray(i);
                if (skyLightLevelArray != null) {
                    if (thisWorld == null)
                        thisWorld = this.getWorld(diffWorld.getName());
                    if (thisChunk == null)
                        thisChunk = ((ImplParallelWorld) thisWorld).createChunkIfAbsent(diffChunk.getChunkX(), diffChunk.getChunkZ());
                    SectionLevelArray thisLevel = ((ImplParallelChunk) thisChunk).createSkyLightSectionLevelArrayIfAbsent(i);
                    skyLightLevelArray.threadsafeIteration(thisLevel::setLevel);
                }
            }
        }
    }
    for (EnginePlayer EnginePlayer : this.getResidents()) {
        ((ImplEnginePlayer) EnginePlayer).setUniverseRaw(null);
        EnginePlayer.setUniverse(this);
    }
}
Also used : ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk) EnginePlayer(thpmc.engine.api.player.EnginePlayer) SectionTypeArray(thpmc.engine.util.SectionTypeArray) SectionLevelArray(thpmc.engine.util.SectionLevelArray)

Example 9 with EnginePlayer

use of thpmc.engine.api.player.EnginePlayer in project THP-Engine by TheHollowPlanetMC.

the class UniverseGUI method openUniverseGUI.

public static void openUniverseGUI(Player player) {
    EnginePlayer enginePlayer = EnginePlayer.getParallelPlayer(player);
    if (enginePlayer == null)
        return;
    Artist artist = new Artist(() -> {
        ArtButton V = null;
        ArtButton G = new ArtButton(new ItemBuilder(Material.GRAY_STAINED_GLASS_PANE).name("&a").build());
        PageNextButton N = new PageNextButton(new ItemBuilder(Material.ARROW).name("&rNext page &7[{NextPage}/{MaxPage}]").build());
        PageBackButton P = new PageBackButton(new ItemBuilder(Material.ARROW).name("&rPrevious page &7[{PreviousPage}/{MaxPage}]").build());
        MenuBackButton B = new MenuBackButton(new ItemBuilder(Material.OAK_DOOR).name("&7Back to &r{PreviousName}").build());
        ArtButton L = new ArtButton(new ItemBuilder(Material.BARRIER).name("&b&nLeave from current universe").build()).listener((inventoryClickEvent, menu) -> {
            enginePlayer.setUniverse(null);
            player.closeInventory();
        });
        return new ArtButton[] { V, V, V, V, V, V, V, G, G, V, V, V, V, V, V, V, G, N, V, V, V, V, V, V, V, G, P, V, V, V, V, V, V, V, G, G, V, V, V, V, V, V, V, G, L, V, V, V, V, V, V, V, G, B };
    });
    ArtMenu artMenu = artist.createMenu(THPEngine.getPlugin().getArtGUI(), "&nUniverse list");
    artMenu.asyncCreate(menu -> {
        for (ParallelUniverse universe : THPEngineAPI.getInstance().getAllUniverse()) {
            menu.addButton(new ArtButton(new ItemBuilder(Material.END_PORTAL_FRAME).name(universe.getName()).lore("&7Click to join.").build()).listener((inventoryClickEvent, menu1) -> {
                enginePlayer.setUniverse(universe);
                player.closeInventory();
                player.sendMessage("§7Switched to §r" + universe.getName());
            }));
        }
    });
    artMenu.open(player);
}
Also used : Artist(be4rjp.artgui.frame.Artist) THPEngine(thpmc.engine.THPEngine) be4rjp.artgui.button(be4rjp.artgui.button) Artist(be4rjp.artgui.frame.Artist) EnginePlayer(thpmc.engine.api.player.EnginePlayer) ParallelUniverse(thpmc.engine.api.world.parallel.ParallelUniverse) THPEngineAPI(thpmc.engine.api.THPEngineAPI) Player(org.bukkit.entity.Player) Material(org.bukkit.Material) ArtMenu(be4rjp.artgui.menu.ArtMenu) ArtMenu(be4rjp.artgui.menu.ArtMenu) ParallelUniverse(thpmc.engine.api.world.parallel.ParallelUniverse) EnginePlayer(thpmc.engine.api.player.EnginePlayer)

Example 10 with EnginePlayer

use of thpmc.engine.api.player.EnginePlayer in project THP-Engine by TheHollowPlanetMC.

the class EnginePlayerEntity method show.

@Override
public void show(EnginePlayer player) {
    INMSHandler nmsHandler = THPEngineAPI.getInstance().getNMSHandler();
    Player bukkitPlayer = player.getBukkitPlayer();
    nmsHandler.sendPacket(bukkitPlayer, nmsHandler.createPlayerInfoPacket(nmsEntity, WrappedPlayerInfoAction.ADD_PLAYER));
    nmsHandler.sendPacket(bukkitPlayer, nmsHandler.createSpawnNamedEntityPacket(nmsEntity));
    nmsHandler.sendPacket(bukkitPlayer, nmsHandler.createTeleportPacket(nmsEntity));
}
Also used : EnginePlayer(thpmc.engine.api.player.EnginePlayer) NMSEntityPlayer(thpmc.engine.api.nms.entity.NMSEntityPlayer) Player(org.bukkit.entity.Player) INMSHandler(thpmc.engine.api.nms.INMSHandler)

Aggregations

EnginePlayer (thpmc.engine.api.player.EnginePlayer)11 Player (org.bukkit.entity.Player)6 INMSHandler (thpmc.engine.api.nms.INMSHandler)3 NMSEntityPlayer (thpmc.engine.api.nms.entity.NMSEntityPlayer)3 ParallelUniverse (thpmc.engine.api.world.parallel.ParallelUniverse)3 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 Region (com.sk89q.worldedit.regions.Region)1 SessionManager (com.sk89q.worldedit.session.SessionManager)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 Material (org.bukkit.Material)1 World (org.bukkit.World)1 EventHandler (org.bukkit.event.EventHandler)1 Vector (org.bukkit.util.Vector)1 THPEngine (thpmc.engine.THPEngine)1 THPEngineAPI (thpmc.engine.api.THPEngineAPI)1