Search in sources :

Example 11 with Setting

use of gg.projecteden.nexus.models.setting.Setting in project Nexus by ProjectEdenGG.

the class Pride20Command method joinParade.

@Path("parade join [player]")
void joinParade(@Arg(value = "self", permission = Group.STAFF) OfflinePlayer player) {
    if (!isStaff())
        player = player();
    Setting setting = service.get(player, "pride20Parade");
    if (setting.getBoolean())
        error("You have already joined the parade");
    WorldGuardUtils worldguard = new WorldGuardUtils(Bukkit.getWorld("safepvp"));
    ProtectedRegion region = worldguard.getProtectedRegion("pride20_parade");
    Location npcLoc;
    if (!worldguard.getPlayersInRegion("pride20_parade").contains(player)) {
        Location random;
        int attempts = 0;
        do {
            random = Bukkit.getWorld("safepvp").getHighestBlockAt(worldguard.getRandomBlock(region).getLocation()).getLocation();
            attempts++;
            if (attempts >= 300) {
                error("There was an error while trying to join the parade, please try again");
                break;
            }
        } while (!region.contains(worldguard.toBlockVector3(random)) || citizenAtBlock(random) || !random.getBlock().getType().isSolid() || !isHighestBlock(random));
        npcLoc = random;
    } else {
        npcLoc = player.getPlayer().getLocation();
    }
    npcLoc.setYaw(180);
    npcLoc.setPitch(0);
    NPC npc = CitizensAPI.getNPCRegistry().createNPC(EntityType.PLAYER, player.getName());
    npc.spawn(npcLoc.add(0, 2, 0));
    npcLoc = LocationUtils.getCenteredLocation(npcLoc);
    npc.teleport(npcLoc, PlayerTeleportEvent.TeleportCause.COMMAND);
    setting.setBoolean(true);
    service.save(setting);
    send(PREFIX + "You have joined the pride parade");
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) Setting(gg.projecteden.nexus.models.setting.Setting) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) WorldGuardUtils(gg.projecteden.nexus.utils.WorldGuardUtils) Location(org.bukkit.Location) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path)

Aggregations

Setting (gg.projecteden.nexus.models.setting.Setting)11 SettingService (gg.projecteden.nexus.models.setting.SettingService)7 Path (gg.projecteden.nexus.framework.commands.models.annotations.Path)6 WorldGuardUtils (gg.projecteden.nexus.utils.WorldGuardUtils)4 Permission (gg.projecteden.nexus.framework.commands.models.annotations.Permission)2 ItemBuilder (gg.projecteden.nexus.utils.ItemBuilder)2 NPC (net.citizensnpcs.api.npc.NPC)2 Location (org.bukkit.Location)2 World (org.bukkit.World)2 Player (org.bukkit.entity.Player)2 EventHandler (org.bukkit.event.EventHandler)2 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)1 Async (gg.projecteden.annotations.Async)1 Command (gg.projecteden.discord.appcommands.annotations.Command)1 RequiredRole (gg.projecteden.discord.appcommands.annotations.RequiredRole)1 NexusAppCommand (gg.projecteden.nexus.features.discord.appcommands.NexusAppCommand)1 BadgeUserService (gg.projecteden.nexus.models.badge.BadgeUserService)1 BankerService (gg.projecteden.nexus.models.banker.BankerService)1 CooldownService (gg.projecteden.nexus.models.cooldown.CooldownService)1 DiscordUser (gg.projecteden.nexus.models.discord.DiscordUser)1