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()));
}
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()));
}
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);
}
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;
}
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");
}
Aggregations