Search in sources :

Example 6 with ParallelUniverse

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

the class MultiBlockChangePacketHandler method rewrite.

@Override
public Object rewrite(Object packet, EnginePlayer EnginePlayer, boolean cacheSetting) {
    ParallelUniverse universe = EnginePlayer.getUniverse();
    if (universe == null)
        return packet;
    String worldName = EnginePlayer.getBukkitPlayer().getWorld().getName();
    ParallelWorld parallelWorld = universe.getWorld(worldName);
    try {
        SectionPosition aValue = (SectionPosition) a.get(packet);
        int chunkX = aValue.getX();
        int chunkZ = aValue.getZ();
        ParallelChunk parallelChunk = parallelWorld.getChunk(chunkX, chunkZ);
        if (parallelChunk == null)
            return packet;
        SectionTypeArray sectionTypeArray = parallelChunk.getSectionTypeArray(aValue.getY());
        if (sectionTypeArray == null)
            return packet;
        short[] bValue = (short[]) b.get(packet);
        IBlockData[] cValueClone = ((IBlockData[]) c.get(packet)).clone();
        for (int i = 0; i < bValue.length; i++) {
            short coord = bValue[i];
            int x = coord >> 8;
            int y = coord & 0xF;
            int z = (coord >> 4) & 0xF;
            IBlockData iBlockData = (IBlockData) sectionTypeArray.getType(x, y, z);
            if (iBlockData != null) {
                cValueClone[i] = iBlockData;
            }
        }
        boolean dValue = d.getBoolean(packet);
        PacketPlayOutMultiBlockChange newPacket = new PacketPlayOutMultiBlockChange();
        a.set(newPacket, aValue);
        b.set(newPacket, bValue);
        c.set(newPacket, cValueClone);
        d.set(newPacket, dValue);
        return newPacket;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return packet;
}
Also used : ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) SectionPosition(net.minecraft.server.v1_16_R3.SectionPosition) PacketPlayOutMultiBlockChange(net.minecraft.server.v1_16_R3.PacketPlayOutMultiBlockChange) ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk) SectionTypeArray(thpmc.engine.util.SectionTypeArray) IBlockData(net.minecraft.server.v1_16_R3.IBlockData) ParallelUniverse(thpmc.engine.api.world.parallel.ParallelUniverse)

Example 7 with ParallelUniverse

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

the class parallelCommandExecutor method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (args == null)
        return false;
    if (args.length == 0)
        return false;
    if (args[0].equals("structure")) {
        if (args.length < 3) {
            return false;
        }
        // parallel structure set-data [structure-name] [data-name] [player]
        if (args[1].equals("set-data")) {
            if (args.length < 5) {
                return false;
            }
            ParallelStructure parallelStructure = ParallelStructure.getParallelStructure(args[2]);
            if (parallelStructure == null) {
                sender.sendMessage(ChatColor.RED + "指定された名前の構造体は存在しません。");
                return true;
            }
            ImplStructureData implStructureData = (ImplStructureData) ImplStructureData.getStructureData(args[3]);
            if (implStructureData == null) {
                sender.sendMessage(ChatColor.RED + "指定された名前の構造データは存在しません。");
                return true;
            }
            Player player = Bukkit.getPlayer(args[4]);
            if (player == null) {
                sender.sendMessage(ChatColor.RED + "指定されたプレイヤーが見つかりませんでした。");
                return true;
            }
            parallelStructure.setStructureData(player, implStructureData);
            sender.sendMessage(ChatColor.GREEN + "適用しました。");
            return true;
        }
        // parallel structure remove-data [structure-name] [player]
        if (args[1].equals("remove-data")) {
            if (args.length < 4) {
                return false;
            }
            ParallelStructure parallelStructure = ParallelStructure.getParallelStructure(args[2]);
            if (parallelStructure == null) {
                sender.sendMessage(ChatColor.RED + "指定された名前の構造体は存在しません。");
                return true;
            }
            Player player = Bukkit.getPlayer(args[3]);
            if (player == null) {
                sender.sendMessage(ChatColor.RED + "指定されたプレイヤーが見つかりませんでした。");
                return true;
            }
            parallelStructure.clearStructureData(player, true);
            sender.sendMessage(ChatColor.GREEN + "適用しました。");
            return true;
        }
    }
    if (!(sender instanceof Player)) {
        sender.sendMessage(ChatColor.RED + "このコマンドはコンソールから実行できません。");
        return true;
    }
    if (args[0].equals("menu")) {
        Player player = (Player) sender;
        UniverseGUI.openUniverseGUI(player);
        return true;
    }
    if (args[0].equals("join-universe")) {
        if (args.length != 2)
            return false;
        String universeName = args[1];
        ParallelUniverse universe = THPEngineAPI.getInstance().getUniverse(universeName);
        if (universe == null) {
            sender.sendMessage("§aThe universe is not found.");
            return true;
        }
        EnginePlayer enginePlayer = EnginePlayer.getParallelPlayer((Player) sender);
        if (enginePlayer == null)
            return false;
        enginePlayer.setUniverse(universe);
        enginePlayer.getBukkitPlayer().sendMessage("§7Switched to §r" + universe.getName());
    }
    if (args[0].equals("leave-universe")) {
        EnginePlayer enginePlayer = EnginePlayer.getParallelPlayer((Player) sender);
        if (enginePlayer == null)
            return false;
        enginePlayer.setUniverse(null);
    }
    // parallel structure-data create [name]
    if (args[0].equals("structure-data")) {
        if (args.length < 3) {
            return false;
        }
        if (args[1].equals("create")) {
            Player player = (Player) sender;
            com.sk89q.worldedit.entity.Player wePlayer = BukkitAdapter.adapt(player);
            SessionManager sessionManager = WorldEdit.getInstance().getSessionManager();
            LocalSession localSession = sessionManager.get(wePlayer);
            com.sk89q.worldedit.world.World selectionWorld = localSession.getSelectionWorld();
            Region region;
            try {
                if (selectionWorld == null)
                    throw new IncompleteRegionException();
                region = localSession.getSelection(selectionWorld);
            } catch (IncompleteRegionException ex) {
                sender.sendMessage(ChatColor.GREEN + "範囲が選択されていません。");
                return true;
            }
            BlockVector3 max = region.getMaximumPoint();
            BlockVector3 min = region.getMinimumPoint();
            World world = BukkitAdapter.adapt(region.getWorld());
            Vector maxLocation = new Vector(max.getX(), max.getY(), max.getZ());
            Vector minLocation = new Vector(min.getX(), min.getY(), min.getZ());
            RegionBlocks regionBlocks = new RegionBlocks(minLocation.toLocation(world), maxLocation.toLocation(world));
            ImplStructureData implStructureData = (ImplStructureData) StructureData.getStructureData(args[2]);
            if (implStructureData != null) {
                sender.sendMessage(ChatColor.RED + "指定された名前の構造データは既に存在しています。");
                return true;
            }
            implStructureData = new ImplStructureData(args[2]);
            implStructureData.setBlockData(minLocation.toLocation(world), regionBlocks.getBlocks());
            sender.sendMessage(ChatColor.GREEN + "作成しました。");
            return true;
        }
        if (args[1].equals("save")) {
            ImplStructureData implStructureData = (ImplStructureData) ImplStructureData.getStructureData(args[2]);
            if (implStructureData == null) {
                sender.sendMessage(ChatColor.RED + "指定された名前の構造データは存在しません。");
                return true;
            }
            implStructureData.saveData();
            sender.sendMessage(ChatColor.GREEN + "保存しました。");
            return true;
        }
    }
    if (args[0].equals("structure")) {
        if (args.length < 3) {
            return false;
        }
        // parallel structure create [name]
        if (args[1].equals("create")) {
            Player player = (Player) sender;
            com.sk89q.worldedit.entity.Player wePlayer = BukkitAdapter.adapt(player);
            SessionManager sessionManager = WorldEdit.getInstance().getSessionManager();
            LocalSession localSession = sessionManager.get(wePlayer);
            com.sk89q.worldedit.world.World selectionWorld = localSession.getSelectionWorld();
            Region region;
            try {
                if (selectionWorld == null)
                    throw new IncompleteRegionException();
                region = localSession.getSelection(selectionWorld);
            } catch (IncompleteRegionException ex) {
                sender.sendMessage(ChatColor.GREEN + "範囲が選択されていません。");
                return true;
            }
            BlockVector3 min = region.getMinimumPoint();
            World world = BukkitAdapter.adapt(region.getWorld());
            Vector minLocation = new Vector(min.getX(), min.getY(), min.getZ());
            ParallelStructure parallelStructure = ParallelStructure.getParallelStructure(args[2]);
            if (parallelStructure != null) {
                sender.sendMessage(ChatColor.RED + "指定された名前の構造体は既に存在しています。");
                return true;
            }
            parallelStructure = new ParallelStructure(args[2]);
            parallelStructure.setBaseLocation(minLocation.toLocation(world));
            sender.sendMessage(ChatColor.GREEN + "作成しました。");
            return true;
        }
        // parallel structure save [name]
        if (args[1].equals("save")) {
            ParallelStructure parallelStructure = ParallelStructure.getParallelStructure(args[2]);
            if (parallelStructure == null) {
                sender.sendMessage(ChatColor.RED + "指定された名前の構造体は存在しません。");
                return true;
            }
            parallelStructure.saveData();
            sender.sendMessage(ChatColor.GREEN + "保存しました。");
            return true;
        }
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) EnginePlayer(thpmc.engine.api.player.EnginePlayer) SessionManager(com.sk89q.worldedit.session.SessionManager) LocalSession(com.sk89q.worldedit.LocalSession) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) BlockVector3(com.sk89q.worldedit.math.BlockVector3) World(org.bukkit.World) RegionBlocks(thpmc.engine.util.RegionBlocks) ImplStructureData(thpmc.engine.structure.ImplStructureData) ParallelUniverse(thpmc.engine.api.world.parallel.ParallelUniverse) Region(com.sk89q.worldedit.regions.Region) ParallelStructure(thpmc.engine.structure.ParallelStructure) EnginePlayer(thpmc.engine.api.player.EnginePlayer) Vector(org.bukkit.util.Vector)

Example 8 with ParallelUniverse

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

the class ParallelStructure method clearStructureData.

/**
 * 適用されている構造物データを消去します
 * @param EnginePlayer 構造物を変化させて見せるプレイヤー
 * @param chunkUpdate チャンクアップデートのパケットを送信するかどうか
 */
public void clearStructureData(EnginePlayer EnginePlayer, boolean chunkUpdate) {
    ParallelUniverse universe = EnginePlayer.getUniverse();
    if (universe == null)
        return;
    Set<Block> blocks = dataMap.get(universe.getName());
    if (blocks == null)
        return;
    ParallelWorld parallelWorld = universe.getWorld(Objects.requireNonNull(baseLocation.getWorld()).getName());
    for (Block block : blocks) {
        parallelWorld.removeBlockData(block.getX(), block.getY(), block.getZ());
    }
    Set<BlockPosition3i> blockPosition3iSet = new HashSet<>();
    blocks.forEach(block -> blockPosition3iSet.add(new BlockPosition3i(block.getX(), block.getY(), block.getZ())));
    parallelWorld.sendMultiBlockUpdate(blockPosition3iSet);
}
Also used : ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) BlockPosition3i(thpmc.engine.util.BlockPosition3i) ParallelUniverse(thpmc.engine.api.world.parallel.ParallelUniverse) Block(org.bukkit.block.Block)

Example 9 with ParallelUniverse

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

the class BlockChangePacketHandler method rewrite.

@Override
public Object rewrite(Object packet, EnginePlayer EnginePlayer, boolean cacheSetting) {
    ParallelUniverse universe = EnginePlayer.getUniverse();
    if (universe == null)
        return packet;
    String worldName = EnginePlayer.getBukkitPlayer().getWorld().getName();
    ParallelWorld parallelWorld = universe.getWorld(worldName);
    try {
        PacketPlayOutBlockChange blockChange = (PacketPlayOutBlockChange) packet;
        BlockPosition bp = (BlockPosition) a.get(blockChange);
        BlockData blockData = parallelWorld.getBlockData(bp.getX(), bp.getY(), bp.getZ());
        if (blockData == null)
            return packet;
        PacketPlayOutBlockChange newPacket = new PacketPlayOutBlockChange();
        a.set(newPacket, bp);
        newPacket.block = ((CraftBlockData) blockData).getState();
        return newPacket;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return packet;
}
Also used : ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) BlockPosition(net.minecraft.server.v1_15_R1.BlockPosition) ParallelUniverse(thpmc.engine.api.world.parallel.ParallelUniverse) PacketPlayOutBlockChange(net.minecraft.server.v1_15_R1.PacketPlayOutBlockChange) BlockData(org.bukkit.block.data.BlockData) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData)

Example 10 with ParallelUniverse

use of thpmc.engine.api.world.parallel.ParallelUniverse 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)

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