Search in sources :

Example 1 with SessionManager

use of com.sk89q.worldedit.session.SessionManager 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 2 with SessionManager

use of com.sk89q.worldedit.session.SessionManager in project bteConoSurCore by BTEConoSur.

the class Methods method getSelection.

public static Region getSelection(Player p) throws IncompleteRegionException {
    com.sk89q.worldedit.entity.Player actor = new BukkitPlayer((WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"), ((WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit")).getServerInterface(), p);
    WorldEdit worldEdit = WorldEdit.getInstance();
    SessionManager manager = worldEdit.getSessionManager();
    LocalSession localSession = manager.get(actor);
    Region region;
    World selectionWorld = localSession.getSelectionWorld();
    region = localSession.getSelection(selectionWorld);
    return region;
}
Also used : SessionManager(com.sk89q.worldedit.session.SessionManager) Polygonal2DRegion(com.sk89q.worldedit.regions.Polygonal2DRegion) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) BteConoSur.mainWorld(pizzaaxx.bteconosur.BteConoSur.mainWorld) World(com.sk89q.worldedit.world.World) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) BukkitPlayer(com.sk89q.worldedit.bukkit.BukkitPlayer)

Example 3 with SessionManager

use of com.sk89q.worldedit.session.SessionManager in project NotQuests by AlessioGr.

the class WorldEditManager method handleReachLocationObjectiveCreation.

public void handleReachLocationObjectiveCreation(final Player player, final String locationName, @NonNull final CommandContext<CommandSender> context) {
    // WorldEdit's native Player class extends Actor
    BukkitPlayer actor = BukkitAdapter.adapt(player);
    SessionManager manager = main.getIntegrationsManager().getWorldEditManager().getWorldEdit().getWorldEdit().getSessionManager();
    LocalSession localSession = manager.get(actor);
    Region region;
    com.sk89q.worldedit.world.World selectionWorld = localSession.getSelectionWorld();
    try {
        if (selectionWorld == null)
            throw new IncompleteRegionException();
        region = localSession.getSelection(selectionWorld);
        final Location min = new Location(BukkitAdapter.adapt(selectionWorld), region.getMinimumPoint().getX(), region.getMinimumPoint().getY(), region.getMinimumPoint().getZ());
        final Location max = new Location(BukkitAdapter.adapt(selectionWorld), region.getMaximumPoint().getX(), region.getMaximumPoint().getY(), region.getMaximumPoint().getZ());
        // Create Objective
        ReachLocationObjective reachLocationObjective = new ReachLocationObjective(main);
        reachLocationObjective.setLocationName(locationName);
        reachLocationObjective.setMinLocation(min);
        reachLocationObjective.setMaxLocation(max);
        main.getObjectiveManager().addObjective(reachLocationObjective, context);
    } catch (IncompleteRegionException ex) {
        main.adventure().player(player).sendMessage(MiniMessage.miniMessage().deserialize(NotQuestColors.errorGradient + "Please make a region selection using WorldEdit first.</gradient>"));
    }
}
Also used : ReachLocationObjective(rocks.gravili.notquests.spigot.structs.objectives.ReachLocationObjective) SessionManager(com.sk89q.worldedit.session.SessionManager) LocalSession(com.sk89q.worldedit.LocalSession) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) Region(com.sk89q.worldedit.regions.Region) BukkitPlayer(com.sk89q.worldedit.bukkit.BukkitPlayer) Location(org.bukkit.Location)

Example 4 with SessionManager

use of com.sk89q.worldedit.session.SessionManager in project NotQuests by AlessioGr.

the class WorldEditManager method handleReachLocationObjectiveCreation.

public void handleReachLocationObjectiveCreation(final Player player, final String locationName, @NonNull final CommandContext<CommandSender> context) {
    // WorldEdit's native Player class extends Actor
    BukkitPlayer actor = BukkitAdapter.adapt(player);
    SessionManager manager = main.getIntegrationsManager().getWorldEditManager().getWorldEdit().getWorldEdit().getSessionManager();
    LocalSession localSession = manager.get(actor);
    Region region;
    com.sk89q.worldedit.world.World selectionWorld = localSession.getSelectionWorld();
    try {
        if (selectionWorld == null)
            throw new IncompleteRegionException();
        region = localSession.getSelection(selectionWorld);
        final Location min = new Location(BukkitAdapter.adapt(selectionWorld), region.getMinimumPoint().getX(), region.getMinimumPoint().getY(), region.getMinimumPoint().getZ());
        final Location max = new Location(BukkitAdapter.adapt(selectionWorld), region.getMaximumPoint().getX(), region.getMaximumPoint().getY(), region.getMaximumPoint().getZ());
        // Create Objective
        ReachLocationObjective reachLocationObjective = new ReachLocationObjective(main);
        reachLocationObjective.setLocationName(locationName);
        reachLocationObjective.setMinLocation(min);
        reachLocationObjective.setMaxLocation(max);
        main.getObjectiveManager().addObjective(reachLocationObjective, context);
    } catch (IncompleteRegionException ex) {
        player.sendMessage(main.parse("<error>Please make a region selection using WorldEdit first."));
    }
}
Also used : ReachLocationObjective(rocks.gravili.notquests.paper.structs.objectives.ReachLocationObjective) SessionManager(com.sk89q.worldedit.session.SessionManager) LocalSession(com.sk89q.worldedit.LocalSession) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) Region(com.sk89q.worldedit.regions.Region) BukkitPlayer(com.sk89q.worldedit.bukkit.BukkitPlayer) Location(org.bukkit.Location)

Example 5 with SessionManager

use of com.sk89q.worldedit.session.SessionManager in project bteConoSurCore by BTEConoSur.

the class Methods method setSelection.

public static void setSelection(Player p, Polygonal2DRegionSelector selector) {
    com.sk89q.worldedit.entity.Player actor = new BukkitPlayer((WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"), ((WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit")).getServerInterface(), p);
    WorldEdit worldEdit = WorldEdit.getInstance();
    SessionManager manager = worldEdit.getSessionManager();
    LocalSession localSession = manager.get(actor);
    localSession.setRegionSelector((World) new BukkitWorld(mainWorld), selector);
    localSession.dispatchCUISelection(actor);
}
Also used : SessionManager(com.sk89q.worldedit.session.SessionManager) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) BukkitPlayer(com.sk89q.worldedit.bukkit.BukkitPlayer)

Aggregations

SessionManager (com.sk89q.worldedit.session.SessionManager)6 LocalSession (com.sk89q.worldedit.LocalSession)4 BukkitPlayer (com.sk89q.worldedit.bukkit.BukkitPlayer)4 Region (com.sk89q.worldedit.regions.Region)4 IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)3 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)2 World (com.sk89q.worldedit.world.World)2 Location (org.bukkit.Location)2 Player (com.sk89q.worldedit.entity.Player)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)1 Polygonal2DRegion (com.sk89q.worldedit.regions.Polygonal2DRegion)1 World (org.bukkit.World)1 Player (org.bukkit.entity.Player)1 Vector (org.bukkit.util.Vector)1 BteConoSur.mainWorld (pizzaaxx.bteconosur.BteConoSur.mainWorld)1 ReachLocationObjective (rocks.gravili.notquests.paper.structs.objectives.ReachLocationObjective)1 ReachLocationObjective (rocks.gravili.notquests.spigot.structs.objectives.ReachLocationObjective)1 EnginePlayer (thpmc.engine.api.player.EnginePlayer)1 ParallelUniverse (thpmc.engine.api.world.parallel.ParallelUniverse)1