Search in sources :

Example 1 with HomeService

use of gg.projecteden.nexus.models.home.HomeService in project Nexus by ProjectEdenGG.

the class TrustCommand method home.

@Description("Allow specified player(s) to a specific home")
@Path("home <home> <players>")
void home(Home home, @Arg(type = OfflinePlayer.class) List<OfflinePlayer> players) {
    players.forEach(home::allow);
    new HomeService().save(home.getOwner());
    send(PREFIX + "Trusted &e" + nicknames(players, "&3, &e") + " &3to home &e" + home.getName());
}
Also used : HomeService(gg.projecteden.nexus.models.home.HomeService) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Description(gg.projecteden.nexus.framework.commands.models.annotations.Description)

Example 2 with HomeService

use of gg.projecteden.nexus.models.home.HomeService in project Nexus by ProjectEdenGG.

the class HomeListener method onDeath.

@EventHandler
public void onDeath(PlayerDeathEvent event) {
    Player player = event.getEntity();
    if (!WorldGroup.of(player).equals(WorldGroup.SURVIVAL))
        return;
    HomeService service = new HomeService();
    HomeOwner homeOwner = service.get(player);
    if (homeOwner.getHomes().size() != 0)
        return;
    if (homeOwner.isUsedDeathHome())
        return;
    Location deathLoc = player.getLocation();
    deathLocations.putIfAbsent(player.getUniqueId(), deathLoc);
}
Also used : Player(org.bukkit.entity.Player) HomeService(gg.projecteden.nexus.models.home.HomeService) HomeOwner(gg.projecteden.nexus.models.home.HomeOwner) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 3 with HomeService

use of gg.projecteden.nexus.models.home.HomeService in project Nexus by ProjectEdenGG.

the class HomeListener method onRespawn.

@EventHandler
public void onRespawn(PlayerRespawnEvent event) {
    Player player = event.getPlayer();
    if (!WorldGroup.of(player).equals(WorldGroup.SURVIVAL))
        return;
    UUID uuid = player.getUniqueId();
    if (!deathLocations.containsKey(uuid))
        return;
    Location deathLoc = deathLocations.get(uuid);
    String homeName = "death";
    HomeService service = new HomeService();
    HomeOwner homeOwner = service.get(player);
    homeOwner.add(Home.builder().uuid(uuid).name(homeName).location(deathLoc).build());
    Koda.dm(player, "Uh oh! You died without a home set! On Project Eden we have a system called Homes that allow " + "you to save your location. I saved a home for you where you died, and you can teleport back to it with " + "&c/home " + homeName + " &e- but be careful! I can only do this once for you! Use &c/sethome [name] &eand &c/homes edit " + "&eto manage your homes in the future. Good luck!");
    homeOwner.setUsedDeathHome(true);
    deathLocations.remove(uuid);
    service.save(homeOwner);
}
Also used : Player(org.bukkit.entity.Player) HomeService(gg.projecteden.nexus.models.home.HomeService) HomeOwner(gg.projecteden.nexus.models.home.HomeOwner) UUID(java.util.UUID) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 4 with HomeService

use of gg.projecteden.nexus.models.home.HomeService in project Nexus by ProjectEdenGG.

the class HomeListener method onPlayerRespawn.

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerRespawn(PlayerRespawnEvent event) {
    WorldGroup group = WorldGroup.of(event.getPlayer());
    if (!Arrays.asList(WorldGroup.SURVIVAL, WorldGroup.SKYBLOCK).contains(group))
        return;
    HomeOwner homeOwner = new HomeService().get(event.getPlayer().getUniqueId());
    Optional<Home> respawn = homeOwner.getHomes().stream().filter(Home::isRespawn).findFirst();
    Optional<Home> main = homeOwner.getHome("home");
    Optional<Home> first = homeOwner.getHomes().stream().findFirst();
    if (respawn.isPresent())
        event.setRespawnLocation(respawn.get().getLocation());
    else if (main.isPresent())
        event.setRespawnLocation(main.get().getLocation());
    else if (first.isPresent())
        event.setRespawnLocation(first.get().getLocation());
    else
        event.setRespawnLocation(Warps.getSpawn());
}
Also used : WorldGroup(gg.projecteden.nexus.utils.WorldGroup) HomeService(gg.projecteden.nexus.models.home.HomeService) HomeOwner(gg.projecteden.nexus.models.home.HomeOwner) Home(gg.projecteden.nexus.models.home.Home) EventHandler(org.bukkit.event.EventHandler)

Example 5 with HomeService

use of gg.projecteden.nexus.models.home.HomeService in project Nexus by ProjectEdenGG.

the class HomesFeature method deleteFromWorld.

public static void deleteFromWorld(String world, Runnable callback) {
    HomeService service = new HomeService();
    Tasks.async(() -> {
        deleted.clear();
        List<HomeOwner> all = service.getAll();
        all.forEach(homeOwner -> {
            homeOwner.getHomes().stream().filter(home -> home.getLocation() == null || home.getLocation().getWorld() == null || home.getLocation().getWorld().getName().equals(world)).forEach(deleted::add);
            deleted.forEach(homeOwner::delete);
            // MongoDB no longer recognizes the homes after serialization so it can't merge the deletions
            // Easy workaround is to delete the entire homeowner and re-save it
            service.deleteSync(homeOwner);
            service.saveSync(homeOwner);
        });
        if (callback != null)
            callback.run();
    });
}
Also used : Home(gg.projecteden.nexus.models.home.Home) List(java.util.List) HomeOwner(gg.projecteden.nexus.models.home.HomeOwner) StringUtils(gg.projecteden.nexus.utils.StringUtils) Getter(lombok.Getter) Feature(gg.projecteden.nexus.framework.features.Feature) Tasks(gg.projecteden.nexus.utils.Tasks) HomeService(gg.projecteden.nexus.models.home.HomeService) ArrayList(java.util.ArrayList) HomeService(gg.projecteden.nexus.models.home.HomeService) HomeOwner(gg.projecteden.nexus.models.home.HomeOwner)

Aggregations

HomeService (gg.projecteden.nexus.models.home.HomeService)7 HomeOwner (gg.projecteden.nexus.models.home.HomeOwner)4 Home (gg.projecteden.nexus.models.home.Home)3 EventHandler (org.bukkit.event.EventHandler)3 Path (gg.projecteden.nexus.framework.commands.models.annotations.Path)2 Location (org.bukkit.Location)2 Player (org.bukkit.entity.Player)2 Description (gg.projecteden.nexus.framework.commands.models.annotations.Description)1 Feature (gg.projecteden.nexus.framework.features.Feature)1 StringUtils (gg.projecteden.nexus.utils.StringUtils)1 Tasks (gg.projecteden.nexus.utils.Tasks)1 WorldGroup (gg.projecteden.nexus.utils.WorldGroup)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 Getter (lombok.Getter)1