Search in sources :

Example 1 with ReachLocationObjective

use of rocks.gravili.notquests.spigot.structs.objectives.ReachLocationObjective 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)

Aggregations

IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)1 LocalSession (com.sk89q.worldedit.LocalSession)1 BukkitPlayer (com.sk89q.worldedit.bukkit.BukkitPlayer)1 Region (com.sk89q.worldedit.regions.Region)1 SessionManager (com.sk89q.worldedit.session.SessionManager)1 Location (org.bukkit.Location)1 ReachLocationObjective (rocks.gravili.notquests.spigot.structs.objectives.ReachLocationObjective)1