Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-830 Teleport to default home feature #858

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.eternalcode.core.feature.home.command;

import com.eternalcode.annotations.scan.command.DescriptionDocs;
import com.eternalcode.core.configuration.implementation.PluginConfiguration;
import com.eternalcode.core.feature.home.Home;
import com.eternalcode.core.feature.home.HomeService;
import com.eternalcode.core.feature.home.HomeTeleportService;
Expand All @@ -12,22 +13,27 @@
import dev.rollczi.litecommands.annotations.execute.Execute;
import dev.rollczi.litecommands.annotations.permission.Permission;
import java.util.Collection;
import java.util.Optional;

import org.bukkit.entity.Player;

@Command(name = "home")
@Permission("eternalcore.home")
class HomeCommand {

private final PluginConfiguration.Homes homesConfig;
private final NoticeService noticeService;
private final HomeService homeService;
private final HomeTeleportService homeTeleportService;

@Inject
HomeCommand(
PluginConfiguration.Homes homesConfig,
NoticeService noticeService,
HomeService homeService,
HomeTeleportService homeTeleportService
) {
this.homesConfig = homesConfig;
this.noticeService = noticeService;
this.homeService = homeService;
this.homeTeleportService = homeTeleportService;
Expand All @@ -46,13 +52,22 @@ void execute(@Context Player player) {
return;
}

if (playerHomes.size() != 1) {
if (playerHomes.size() > 1) {
String homes = String.join(
", ",
this.homeService.getHomes(player.getUniqueId()).stream()
playerHomes.stream()
.map(Home::getName)
.toList());

Optional<Home> mainHome = playerHomes.stream()
.filter(home -> home.getName().equals(this.homesConfig.defaultHomeName))
.findFirst();

if (mainHome.isPresent()) {
this.homeTeleportService.teleport(player, mainHome.get());
return;
}
Rollczi marked this conversation as resolved.
Show resolved Hide resolved

igoyek marked this conversation as resolved.
Show resolved Hide resolved
vLuckyyy marked this conversation as resolved.
Show resolved Hide resolved
this.noticeService.create()
.player(player.getUniqueId())
.notice(translation -> translation.home().homeList())
Expand Down