Search in sources :

Example 16 with WorldGuardUtils

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

the class Flag method getSuitableLocation.

public static Location getSuitableLocation(Location originalLocation) {
    Location location = originalLocation.clone();
    double originalHeight = location.getY();
    int maxHeight = location.getWorld().getMaxHeight();
    int minHeight = location.getWorld().getMinHeight();
    while (// goal is to be in an air block
    !MaterialTag.ALL_AIR.isTagged(location.getBlock().getType()) && // don't go above the world
    location.getY() < maxHeight && // the check against the current height is to avoid warping down on stairs
    (location.getY() - originalHeight < 2 || !location.getBlock().getType().isSolid())) location.add(0, 1, 0);
    Block below = location.clone().subtract(0, 1, 0).getBlock();
    while ((MaterialTag.ALL_AIR.isTagged(below.getType()) || below.getType() == Material.BARRIER || !MaterialTag.ALL_AIR.isTagged(location.getBlock().getType())) && ArenaManager.getFromLocation(originalLocation).getRegion().contains(new WorldGuardUtils(Minigames.getWorld()).toBlockVector3(location))) {
        location.subtract(0, 1, 0);
        below = location.clone().subtract(0, 1, 0).getBlock();
        if (location.getY() <= minHeight) {
            // maybe this should throw an exception to avoid possible harm in deleting blocks?
            // although it's probably just bedrock...
            Nexus.warn("Could not find a safe location for flag, dumping it at " + location.toString() + " (overwriting " + location.getBlock().getType().name() + ")");
            break;
        }
    }
    return location;
}
Also used : Block(org.bukkit.block.Block) WorldGuardUtils(gg.projecteden.nexus.utils.WorldGuardUtils) Location(org.bukkit.Location)

Example 17 with WorldGuardUtils

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

the class RegenRegions method onBreakBlock.

@EventHandler
public void onBreakBlock(BlockBreakEvent event) {
    if (!(event.getPlayer().getGameMode().equals(GameMode.SURVIVAL)))
        return;
    Block eventBlock = event.getBlock();
    Location loc = eventBlock.getLocation();
    WorldGuardUtils worldguard = new WorldGuardUtils(loc);
    String key = "_regen_";
    for (ProtectedRegion region : worldguard.getRegionsAt(loc)) {
        String regionName = region.getId();
        if (regionName.contains(key)) {
            int ndx = regionName.indexOf('_');
            String variables = regionName.substring(ndx + key.length() - 1);
            String[] varSplit = variables.split("_");
            String cooldownStr = varSplit[varSplit.length - 1];
            int cooldown = getInteger(cooldownStr);
            String materialStr = variables;
            if (cooldown != -1)
                materialStr = variables.substring(0, variables.indexOf(cooldownStr));
            Material material = getMaterial(materialStr);
            if (material == null) {
                // throw error?
                Nexus.log("Unknown material to regen");
                return;
            }
        }
    }
}
Also used : ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) Block(org.bukkit.block.Block) Material(org.bukkit.Material) WorldGuardUtils(gg.projecteden.nexus.utils.WorldGuardUtils) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 18 with WorldGuardUtils

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

the class Pride21Command method leaveParade.

@Path("parade leave [player]")
void leaveParade(@Arg(value = "self", permission = Group.STAFF) OfflinePlayer player) {
    String playerText = isSelf(player) ? "You have" : Nickname.of(player) + " has";
    final Pride21User user = service.get(player);
    if (user.isJoinedParade())
        error(playerText + " not joined the parade");
    World world = Bukkit.getWorld("events");
    if (world == null)
        error("Could not load the event world, please report to a dev <3");
    WorldGuardUtils worldguard = new WorldGuardUtils(world);
    for (NPC npc : NPCFinder.builder().owner(player).world(world).region(worldguard.getProtectedRegion("pride21_parade")).build().get()) npc.destroy();
    user.setJoinedParade(false);
    service.save(user);
    send(PREFIX + playerText + " left the pride parade");
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) Pride21User(gg.projecteden.nexus.models.pride21.Pride21User) World(org.bukkit.World) WorldGuardUtils(gg.projecteden.nexus.utils.WorldGuardUtils) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path)

Example 19 with WorldGuardUtils

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

the class Pride21Command method joinParade.

@Path("parade join [player]")
void joinParade(@Arg(value = "self", permission = Group.STAFF) Player player) {
    String playerText = isSelf(player) ? "You have" : Nickname.of(player) + " has";
    final Pride21User user = service.get(player);
    if (user.isJoinedParade())
        error(playerText + " already joined the parade");
    World world = Bukkit.getWorld("events");
    if (world == null)
        error("Could not load the event world, please report to a dev <3");
    WorldGuardUtils worldguard = new WorldGuardUtils(world);
    if (!worldguard.isInRegion(player, "pride21_parade"))
        error("You must be standing in the Pride parade to use this command");
    Location npcLoc = LocationUtils.getCenteredLocation(player.getLocation());
    CitizensUtils.spawnNPC(player, npcLoc);
    user.setJoinedParade(true);
    service.save(user);
    send(PREFIX + playerText + " joined the pride parade");
}
Also used : Pride21User(gg.projecteden.nexus.models.pride21.Pride21User) World(org.bukkit.World) WorldGuardUtils(gg.projecteden.nexus.utils.WorldGuardUtils) Location(org.bukkit.Location) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path)

Example 20 with WorldGuardUtils

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

the class Quests method viewFloat.

public static void viewFloat(Player player, boolean view) {
    Tasks.async(() -> {
        World world = Bukkit.getWorld("events");
        BlockData gray = Material.GRAY_TERRACOTTA.createBlockData();
        if (world == null)
            return;
        for (BlockVector3 blockVector3 : new WorldGuardUtils(world).getRegion("pride21_val")) {
            Location location = new Location(world, blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ());
            Material material = location.getBlock().getType();
            if (MaterialTag.ALL_TERRACOTTAS.isTagged(material))
                player.sendBlockChange(location, view ? location.getBlock().getBlockData() : gray);
        }
    });
}
Also used : Material(org.bukkit.Material) World(org.bukkit.World) BlockData(org.bukkit.block.data.BlockData) BlockVector3(com.sk89q.worldedit.math.BlockVector3) WorldGuardUtils(gg.projecteden.nexus.utils.WorldGuardUtils) Location(org.bukkit.Location)

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