Search in sources :

Example 11 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)

Example 12 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 13 with WorldGuardUtils

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

the class Easter21Command method onEggTeleport.

@EventHandler
public void onEggTeleport(BlockFromToEvent event) {
    Block block = event.getBlock();
    if (event.getBlock().getType() != Material.DRAGON_EGG)
        return;
    WorldGuardUtils worldGuardUtils = new WorldGuardUtils(block.getWorld());
    if (!worldGuardUtils.isInRegion(block.getLocation(), "spawn"))
        return;
    event.setCancelled(true);
}
Also used : Block(org.bukkit.block.Block) WorldGuardUtils(gg.projecteden.nexus.utils.WorldGuardUtils) EventHandler(org.bukkit.event.EventHandler)

Example 14 with WorldGuardUtils

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

the class WorldGuardRegionAPI method updateRegions.

private synchronized boolean updateRegions(final Entity entity, MovementType movementType, Location newLocation, final Event parentEvent) {
    final WorldGuardUtils worldGuardUtils = new WorldGuardUtils(newLocation);
    Set<ProtectedRegion> regions = entityRegions.getOrDefault(entity.getUniqueId(), new HashSet<>());
    regions.removeIf(Objects::isNull);
    Set<ProtectedRegion> originalRegions = new HashSet<>(regions);
    Set<ProtectedRegion> applicableRegions = worldGuardUtils.getRegionsAt(newLocation);
    for (final ProtectedRegion region : applicableRegions) if (!originalRegions.contains(region))
        if (!RegionEventFactory.of(EnteringRegionEvent.class, region, entity, movementType, newLocation, parentEvent).callEvent()) {
            regions.clear();
            regions.addAll(originalRegions);
            return true;
        } else {
            Tasks.wait(1, () -> RegionEventFactory.of(EnteredRegionEvent.class, region, entity, movementType, newLocation, parentEvent).callEvent());
            regions.add(region);
        }
    for (final ProtectedRegion region : originalRegions) if (!applicableRegions.contains(region))
        if (!RegionEventFactory.of(LeavingRegionEvent.class, region, entity, movementType, newLocation, parentEvent).callEvent()) {
            regions.clear();
            regions.addAll(originalRegions);
            return true;
        } else {
            Tasks.wait(1, () -> RegionEventFactory.of(LeftRegionEvent.class, region, entity, movementType, newLocation, parentEvent).callEvent());
            regions.remove(region);
        }
    entityRegions.put(entity.getUniqueId(), regions);
    return false;
}
Also used : ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) Objects(java.util.Objects) WorldGuardUtils(gg.projecteden.nexus.utils.WorldGuardUtils) HashSet(java.util.HashSet)

Example 15 with WorldGuardUtils

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

the class WitherChallenge method onTeleportOutOfArena.

@EventHandler
public void onTeleportOutOfArena(PlayerTeleportEvent event) {
    if (!new WorldGuardUtils("events").isInRegion(event.getFrom(), "witherarena"))
        return;
    if (new WorldGuardUtils("events").isInRegion(event.getTo(), "witherarena"))
        return;
    if (currentFight == null)
        return;
    final Player player = event.getPlayer();
    if (currentFight.isSpectating(player)) {
        currentFight.getSpectators().remove(player.getUniqueId());
        player.setGameMode(GameMode.SURVIVAL);
        return;
    }
    if (!currentFight.isAlive(player))
        return;
    if (!currentFight.isStarted())
        return;
    event.setCancelled(true);
    PlayerUtils.send(player, PREFIX + "&cYou cannot teleport out of the wither arena during the fight. " + "Use &c/wither quit &3to resign from the fight");
}
Also used : Player(org.bukkit.entity.Player) WorldGuardUtils(gg.projecteden.nexus.utils.WorldGuardUtils) EventHandler(org.bukkit.event.EventHandler)

Aggregations

WorldGuardUtils (gg.projecteden.nexus.utils.WorldGuardUtils)32 EventHandler (org.bukkit.event.EventHandler)19 Location (org.bukkit.Location)13 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)11 Block (org.bukkit.block.Block)10 Player (org.bukkit.entity.Player)8 Path (gg.projecteden.nexus.framework.commands.models.annotations.Path)5 OfflinePlayer (org.bukkit.OfflinePlayer)4 World (org.bukkit.World)4 ItemStack (org.bukkit.inventory.ItemStack)4 Rank (gg.projecteden.nexus.models.nerd.Rank)2 Pride21User (gg.projecteden.nexus.models.pride21.Pride21User)2 ColorType (gg.projecteden.nexus.utils.ColorType)2 MaterialTag (gg.projecteden.nexus.utils.MaterialTag)2 UUID (java.util.UUID)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 Listener (org.bukkit.event.Listener)2