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