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-911 Fix typo in afk config, fix permission check order, add constant for permission for afk permission. #911

Merged
merged 4 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -24,6 +24,8 @@
)
class AfkCommand {

private static final String AFK_BYPASS_PERMISSION = "eternalcore.afk.bypass";

private final NoticeService noticeService;
private final PluginConfiguration pluginConfiguration;
private final AfkService afkService;
Expand All @@ -38,10 +40,15 @@ class AfkCommand {
}

@Execute
@DescriptionDocs(description = "Marks you as AFK, if player has eternalcore.afk.bypass permission, eternalcore will be ignore afk delay")
@DescriptionDocs(description = "Marks you as AFK, if player has eternalcore.afk.bypass permission, eternalcore will ignore afk delay")
void execute(@Context Player player) {
UUID uuid = player.getUniqueId();

if (player.hasPermission(AFK_BYPASS_PERMISSION)) {
this.afkService.switchAfk(uuid, AfkReason.COMMAND);
return;
}

if (this.delay.hasDelay(uuid)) {
Duration time = this.delay.getDurationToExpire(uuid);

Expand All @@ -56,11 +63,6 @@ void execute(@Context Player player) {
}

this.afkService.switchAfk(uuid, AfkReason.COMMAND);

if (player.hasPermission("eternalcore.afk.bypass")) {
return;
}

this.delay.markDelay(uuid, this.pluginConfiguration.afk.getAfkDelay());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
import java.util.Optional;

@Controller
class AftPlaceholderSetup {
class AfkPlaceholderSetup {

private final TranslationManager translationManager;

@Inject
AftPlaceholderSetup(TranslationManager translationManager) {
AfkPlaceholderSetup(TranslationManager translationManager) {
this.translationManager = translationManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import java.time.Duration;
import java.time.Instant;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Map;
import java.util.UUID;

Expand All @@ -24,9 +24,9 @@ class AfkServiceImpl implements AfkService {
private final UserManager userManager;
private final EventCaller eventCaller;

private final Map<UUID, Afk> afkByPlayer = new HashMap<>();
private final Map<UUID, Integer> interactionsCount = new HashMap<>();
private final Map<UUID, Instant> lastInteraction = new HashMap<>();
private final Map<UUID, Afk> afkByPlayer = new ConcurrentHashMap<>();
private final Map<UUID, Integer> interactionsCount = new ConcurrentHashMap<>();
private final Map<UUID, Instant> lastInteraction = new ConcurrentHashMap<>();

@Inject
AfkServiceImpl(AfkSettings afkSettings, NoticeService noticeService, UserManager userManager, EventCaller eventCaller) {
Expand Down Expand Up @@ -126,5 +126,4 @@ private void sendAfkNotification(UUID playerUniqueId, boolean afk) {
.placeholder("{PLAYER}", this.userManager.getUser(playerUniqueId).map(User::getName))
.send();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import com.eternalcode.core.feature.vanish.VanishService;
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.injector.annotations.component.Task;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.bukkit.Server;
import org.bukkit.entity.Player;

import java.util.UUID;

@Task(delay = 1L, period = 1L, unit = TimeUnit.MINUTES)
class AfkTask implements Runnable {

Expand Down Expand Up @@ -55,5 +54,4 @@ void markAllInactivePlayers() {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ public class PLAfkMessages implements AfkMessages {

@Description("# {PLAYER} - Gracz ")
public Notice afkOn = Notice.chat("<green>► <white>{PLAYER} jest AFK!");

@Description("# {PLAYER} - Gracz ")
public Notice afkOff = Notice.chat("<green>► <white>{PLAYER} już nie jest AFK!");

@Description({" ", "# {TIME} - Czas po którym gracz może użyć komendy"})
public Notice afkDelay = Notice.chat("<red>► <dark_red>Możesz użyć tej komendy dopiero po <dark_red>{TIME}!");

@Description({" "})
public String afkKickReason = "<red>Zostałeś wyrzucone z powodu braku aktywności!";
public String afkKickReason = "<red>Zostałeś wyrzucony z powodu braku aktywności!";

@Description({" ", "# Używane w %eternalcore_afk_formatted% do wskazania statusu AFK"})
public String afkEnabledPlaceholder = "<red><b>AFK";
public String afkDisabledPlaceholder = "";

public String afkDisabledPlaceholder = "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
@Service
class RandomTeleportSafeLocationService {

private static final int DEFAULT_NETHER_HEIGHT = 125;
private static final int NETHER_MAX_HEIGHT = 127;

private final RandomTeleportSettings randomTeleportSettings;
Expand All @@ -37,14 +36,11 @@ class RandomTeleportSafeLocationService {
}

public CompletableFuture<Location> getSafeRandomLocation(World world, RandomTeleportRadius radius, int attemptCount) {
if (attemptCount < 0) {
if (attemptCount <= 0) {
return CompletableFuture.failedFuture(new RuntimeException("Cannot find safe location"));
}

boolean noneWorld = this.locationsConfiguration.spawn.isNoneWorld();
Location spawnLocation = !noneWorld
? PositionAdapter.convert(this.locationsConfiguration.spawn)
: world.getSpawnLocation();
Location spawnLocation = getSpawnLocation(world);

int spawnX = spawnLocation.getBlockX();
int spawnZ = spawnLocation.getBlockZ();
Expand All @@ -55,10 +51,6 @@ public CompletableFuture<Location> getSafeRandomLocation(World world, RandomTele
return PaperLib.getChunkAtAsync(new Location(world, randomX, 100, randomZ)).thenCompose(chunk -> {
int randomY = chunk.getWorld().getHighestBlockYAt(randomX, randomZ);

if (world.getEnvironment() == World.Environment.NETHER) {
randomY = this.random.nextInt(DEFAULT_NETHER_HEIGHT);
}

RandomTeleportHeightRange heightRange = this.randomTeleportSettings.heightRange();
int minHeight = heightRange.getMinY();
int maxHeight = heightRange.getMaxY() - 1;
Expand All @@ -74,6 +66,19 @@ public CompletableFuture<Location> getSafeRandomLocation(World world, RandomTele
});
}

private Location getSpawnLocation(World targetWorld) {
if (this.locationsConfiguration.spawn.isNoneWorld()) {
return targetWorld.getSpawnLocation();
}

Location configSpawn = PositionAdapter.convert(this.locationsConfiguration.spawn);
if (configSpawn.getWorld().getName().equals(targetWorld.getName())) {
return configSpawn;
}

return targetWorld.getSpawnLocation();
}

private boolean isSafeLocation(Chunk chunk, Location location) {
if (location.getWorld() == null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@ public CompletableFuture<Location> getSafeRandomLocationInWorldBorder(World worl

private RandomTeleportRadius getWorldBorderRadius(World world) {
WorldBorder worldBorder = world.getWorldBorder();
int borderRadius = (int) (worldBorder.getSize() / 2);
return RandomTeleportRadius.of(-borderRadius, borderRadius, -borderRadius, borderRadius);
double size = worldBorder.getSize();
double centerX = worldBorder.getCenter().getX();
double centerZ = worldBorder.getCenter().getZ();

int minX = (int) (centerX - size/2);
int maxX = (int) (centerX + size/2);
int minZ = (int) (centerZ - size/2);
int maxZ = (int) (centerZ + size/2);

return RandomTeleportRadius.of(minX, maxX, minZ, maxZ);
}
}