Search in sources :

Example 1 with WorldGuardUtils

use of gg.projecteden.nexus.utils.WorldGuardUtils in project Nexus by ProjectEdenGG.

the class Pride20Command method leaveParade.

@Path("parade leave [player]")
void leaveParade(@Arg(value = "self", permission = Group.STAFF) OfflinePlayer player) {
    boolean isSelf = isSelf(player);
    String playerText = isSelf ? "You have" : Nickname.of(player) + " has";
    Setting setting = service.get(player, "pride20Parade");
    if (!setting.getBoolean())
        error(playerText + " not joined the parade");
    WorldGuardUtils worldguard = new WorldGuardUtils(Bukkit.getWorld("safepvp"));
    for (Entity entity : worldguard.getEntitiesInRegion("pride20_parade")) {
        if (!entity.hasMetadata("NPC"))
            continue;
        if (entity.getName().equalsIgnoreCase(player.getName()))
            CitizensAPI.getNPCRegistry().getNPC(entity).destroy();
    }
    setting.setBoolean(false);
    service.save(setting);
    send(PREFIX + playerText + " left the pride parade");
}
Also used : Entity(org.bukkit.entity.Entity) Setting(gg.projecteden.nexus.models.setting.Setting) WorldGuardUtils(gg.projecteden.nexus.utils.WorldGuardUtils) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path)

Example 2 with WorldGuardUtils

use of gg.projecteden.nexus.utils.WorldGuardUtils in project Nexus by ProjectEdenGG.

the class InteractListener method onPutt.

@EventHandler
public void onPutt(PlayerInteractEvent event) {
    if (event.getHand() == null)
        return;
    if (!event.getHand().equals(EquipmentSlot.HAND))
        return;
    MiniGolfUser user = MiniGolfUtils.getUser(event.getPlayer().getUniqueId());
    if (user == null)
        return;
    ItemStack item = event.getItem();
    if (isNullOrAir(item)) {
        user.debug("item is null or air, returning");
        return;
    }
    Action action = event.getAction();
    Block block = event.getClickedBlock();
    if (item.getType().equals(Material.SNOWBALL)) {
        user.debug("placing golf ball...");
        if (user.getGolfBall() != null && user.getGolfBall().getSnowball() != null) {
            user.debug("you already have a ball placed");
            event.setCancelled(true);
            return;
        }
        if (isNullOrAir(block)) {
            user.debug("placed on block is air or null");
            event.setCancelled(true);
            return;
        }
        GolfBall golfBall = new GolfBall(user.getUuid());
        // Verify region
        WorldGuardUtils worldguard = new WorldGuardUtils(block);
        Set<ProtectedRegion> regions = worldguard.getRegionsLikeAt(MiniGolf.holeRegionRegex, block.getLocation());
        ProtectedRegion region = regions.stream().findFirst().orElse(null);
        if (region == null) {
            user.debug("hole region not found");
            event.setCancelled(true);
            return;
        }
        golfBall.setHoleRegion(region.getId());
        // Place Event
        MiniGolfUserPlaceBallEvent placeBallEvent = new MiniGolfUserPlaceBallEvent(user, golfBall, Set.of(Material.GREEN_WOOL));
        if (!placeBallEvent.callEvent()) {
            user.debug("place ball event cancelled");
            event.setCancelled(true);
            return;
        }
        if (!placeBallEvent.canPlaceBall(block.getType())) {
            user.debug("incorrect starting position");
            event.setCancelled(true);
            return;
        }
        // Spawn Event
        MiniGolfBallSpawnEvent ballSpawnEvent = new MiniGolfBallSpawnEvent(golfBall, block.getLocation());
        if (!ballSpawnEvent.callEvent()) {
            user.debug("place spawn event cancelled");
            event.setCancelled(true);
            return;
        }
        item.setAmount(item.getAmount() - 1);
        ballSpawnEvent.spawnBall();
        MiniGolf.getGolfBalls().add(golfBall);
    }
// TODO
}
Also used : MiniGolfUser(gg.projecteden.nexus.features.minigolf.models.MiniGolfUser) Action(org.bukkit.event.block.Action) MiniGolfUserPlaceBallEvent(gg.projecteden.nexus.features.minigolf.models.events.MiniGolfUserPlaceBallEvent) MiniGolfBallSpawnEvent(gg.projecteden.nexus.features.minigolf.models.events.MiniGolfBallSpawnEvent) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack) WorldGuardUtils(gg.projecteden.nexus.utils.WorldGuardUtils) GolfBall(gg.projecteden.nexus.features.minigolf.models.GolfBall) EventHandler(org.bukkit.event.EventHandler)

Example 3 with WorldGuardUtils

use of gg.projecteden.nexus.utils.WorldGuardUtils in project Nexus by ProjectEdenGG.

the class BannerCommand method onBuyBanner.

@EventHandler
public void onBuyBanner(PlayerInteractEvent event) {
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
        return;
    if (event.getClickedBlock() == null || !MaterialTag.SIGNS.isTagged(event.getClickedBlock().getType()))
        return;
    if (!"safepvp".equals(event.getPlayer().getWorld().getName()))
        return;
    if (!new WorldGuardUtils(event.getPlayer()).isInRegion(event.getPlayer().getLocation(), "banners"))
        return;
    Sign sign = (Sign) event.getClickedBlock().getState();
    String id = sign.getLine(0);
    if (isNullOrEmpty(id))
        return;
    Block banner = event.getClickedBlock().getLocation().add(0, -1, 0).getBlock();
    if (!MaterialTag.STANDING_BANNERS.isTagged(banner.getType()))
        return;
    ConfirmationMenu.builder().onConfirm(e -> {
        try {
            new VoterService().edit(event.getPlayer(), voter -> voter.takePoints(5));
        } catch (InvalidInputException ex) {
            send(event.getPlayer(), ex.getMessage());
            return;
        }
        PlayerUtils.giveItems(event.getPlayer(), banner.getDrops());
        send(event.getPlayer(), StringUtils.getPrefix("VPS") + colorize("You purchased banner &e" + id + " &3for &e5 vote points"));
    }).open(event.getPlayer());
}
Also used : StringUtils(gg.projecteden.nexus.utils.StringUtils) Arg(gg.projecteden.nexus.framework.commands.models.annotations.Arg) Action(org.bukkit.event.block.Action) BannerMeta(org.bukkit.inventory.meta.BannerMeta) VoterService(gg.projecteden.nexus.models.voter.VoterService) ColorType(gg.projecteden.nexus.utils.ColorType) Nullables.isNullOrEmpty(gg.projecteden.nexus.utils.Nullables.isNullOrEmpty) EventHandler(org.bukkit.event.EventHandler) InvalidInputException(gg.projecteden.nexus.framework.exceptions.postconfigured.InvalidInputException) PlayerUtils(gg.projecteden.nexus.utils.PlayerUtils) Block(org.bukkit.block.Block) MaterialTag(gg.projecteden.nexus.utils.MaterialTag) Permission(gg.projecteden.nexus.framework.commands.models.annotations.Permission) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) WorldGuardUtils(gg.projecteden.nexus.utils.WorldGuardUtils) ConfirmationMenu(gg.projecteden.nexus.features.menus.MenuUtils.ConfirmationMenu) Listener(org.bukkit.event.Listener) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) Sign(org.bukkit.block.Sign) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) NonNull(lombok.NonNull) Symbol(gg.projecteden.nexus.utils.SymbolBanner.Symbol) CustomCommand(gg.projecteden.nexus.framework.commands.models.CustomCommand) SymbolBanner(gg.projecteden.nexus.utils.SymbolBanner) ItemStack(org.bukkit.inventory.ItemStack) Aliases(gg.projecteden.nexus.framework.commands.models.annotations.Aliases) CommandEvent(gg.projecteden.nexus.framework.commands.models.events.CommandEvent) StringUtils.colorize(gg.projecteden.nexus.utils.StringUtils.colorize) DyeColor(org.bukkit.DyeColor) NoArgsConstructor(lombok.NoArgsConstructor) InvalidInputException(gg.projecteden.nexus.framework.exceptions.postconfigured.InvalidInputException) Block(org.bukkit.block.Block) Sign(org.bukkit.block.Sign) WorldGuardUtils(gg.projecteden.nexus.utils.WorldGuardUtils) VoterService(gg.projecteden.nexus.models.voter.VoterService) EventHandler(org.bukkit.event.EventHandler)

Example 4 with WorldGuardUtils

use of gg.projecteden.nexus.utils.WorldGuardUtils in project Nexus by ProjectEdenGG.

the class NPCListener method onNpcSpawn.

@EventHandler
public void onNpcSpawn(NPCSpawnEvent event) {
    UUID uuid = event.getNPC().getTrait(Owner.class).getOwnerId();
    if (uuid == null)
        return;
    if (ALLOWED_NPCS.contains(event.getNPC().getId()))
        return;
    if (event.getLocation().getWorld().getName().equals("events") && new WorldGuardUtils(event.getLocation()).isInRegion(event.getLocation(), "pride21_parade"))
        return;
    OfflinePlayer owner = PlayerUtils.getPlayer(uuid);
    if (Rank.of(owner).gte(Rank.NOBLE) || Dev.of(owner.getUniqueId()) != null)
        return;
    if (isPerkAllowedAt(owner, event.getLocation()))
        return;
    event.setCancelled(true);
    PlayerUtils.send(owner, "&cYou cannot teleport NPCs here");
    Nexus.warn("Preventing NPC spawn: " + event.getNPC().getId() + " from " + getShortLocationString(event.getNPC().getStoredLocation()) + " to " + getShortLocationString(event.getLocation()));
}
Also used : Owner(net.citizensnpcs.api.trait.trait.Owner) OfflinePlayer(org.bukkit.OfflinePlayer) UUID(java.util.UUID) WorldGuardUtils(gg.projecteden.nexus.utils.WorldGuardUtils) EventHandler(org.bukkit.event.EventHandler)

Example 5 with WorldGuardUtils

use of gg.projecteden.nexus.utils.WorldGuardUtils in project Nexus by ProjectEdenGG.

the class NPCListener method onNpcTeleport.

@EventHandler
public void onNpcTeleport(NPCTeleportEvent event) {
    UUID uuid = event.getNPC().getTrait(Owner.class).getOwnerId();
    if (uuid == null)
        return;
    if (event.getTo() == null)
        return;
    if (event.getTo().getWorld().getName().equals("events") && new WorldGuardUtils(event.getTo()).isInRegion(event.getTo(), "pride21_parade"))
        return;
    OfflinePlayer owner = PlayerUtils.getPlayer(uuid);
    if (!event.getFrom().getWorld().equals(event.getTo().getWorld())) {
        event.setCancelled(true);
        PlayerUtils.send(owner, "&cNPCs cannot be teleported across worlds");
        Nexus.warn("Preventing NPC cross-world teleport: " + event.getNPC().getId() + " from " + getShortLocationString(event.getFrom()) + " to " + getShortLocationString(event.getTo()));
        return;
    }
    if (ALLOWED_NPCS.contains(event.getNPC().getId()))
        return;
    if (Rank.of(owner).gte(Rank.NOBLE) || Dev.of(owner.getUniqueId()) != null)
        return;
    if (isPerkAllowedAt(owner, event.getTo()))
        return;
    event.setCancelled(true);
    PlayerUtils.send(owner, "&cYou cannot teleport NPCs here");
    Nexus.warn("Preventing NPC teleport: " + event.getNPC().getId() + " from " + getShortLocationString(event.getFrom()) + " to " + getShortLocationString(event.getTo()));
}
Also used : Owner(net.citizensnpcs.api.trait.trait.Owner) OfflinePlayer(org.bukkit.OfflinePlayer) UUID(java.util.UUID) WorldGuardUtils(gg.projecteden.nexus.utils.WorldGuardUtils) EventHandler(org.bukkit.event.EventHandler)

Aggregations

WorldGuardUtils (gg.projecteden.nexus.utils.WorldGuardUtils)34 EventHandler (org.bukkit.event.EventHandler)19 Location (org.bukkit.Location)14 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)12 Block (org.bukkit.block.Block)10 Player (org.bukkit.entity.Player)8 Path (gg.projecteden.nexus.framework.commands.models.annotations.Path)7 Setting (gg.projecteden.nexus.models.setting.Setting)4 OfflinePlayer (org.bukkit.OfflinePlayer)4 World (org.bukkit.World)4 ItemStack (org.bukkit.inventory.ItemStack)4 Rank (gg.projecteden.nexus.models.nerd.Rank)2 ColorType (gg.projecteden.nexus.utils.ColorType)2 MaterialTag (gg.projecteden.nexus.utils.MaterialTag)2 UUID (java.util.UUID)2 NPC (net.citizensnpcs.api.npc.NPC)2 Owner (net.citizensnpcs.api.trait.trait.Owner)2 DyeColor (org.bukkit.DyeColor)2 Material (org.bukkit.Material)2 Sign (org.bukkit.block.Sign)2