Skip to content

Commit b7097d4

Browse files
committed
fixed bypass check order, typo in AfkPlaceholderSetup, fixed placeholder formatting
1 parent 34aa32c commit b7097d4

File tree

7 files changed

+42
-30
lines changed

7 files changed

+42
-30
lines changed

eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkCommand.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ class AfkCommand {
3838
}
3939

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

45+
if (player.hasPermission("eternalcore.afk.bypass")) {
46+
this.afkService.switchAfk(uuid, AfkReason.COMMAND);
47+
return;
48+
}
49+
4550
if (this.delay.hasDelay(uuid)) {
4651
Duration time = this.delay.getDurationToExpire(uuid);
4752

@@ -56,11 +61,6 @@ void execute(@Context Player player) {
5661
}
5762

5863
this.afkService.switchAfk(uuid, AfkReason.COMMAND);
59-
60-
if (player.hasPermission("eternalcore.afk.bypass")) {
61-
return;
62-
}
63-
6464
this.delay.markDelay(uuid, this.pluginConfiguration.afk.getAfkDelay());
6565
}
6666
}

eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AftPlaceholderSetup.java renamed to eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkPlaceholderSetup.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
import java.util.Optional;
1515

1616
@Controller
17-
class AftPlaceholderSetup {
17+
class AfkPlaceholderSetup {
1818

1919
private final TranslationManager translationManager;
2020

2121
@Inject
22-
AftPlaceholderSetup(TranslationManager translationManager) {
22+
AfkPlaceholderSetup(TranslationManager translationManager) {
2323
this.translationManager = translationManager;
2424
}
2525

eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkServiceImpl.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import java.time.Duration;
1414
import java.time.Instant;
15-
import java.util.HashMap;
15+
import java.util.concurrent.ConcurrentHashMap;
1616
import java.util.Map;
1717
import java.util.UUID;
1818

@@ -24,9 +24,9 @@ class AfkServiceImpl implements AfkService {
2424
private final UserManager userManager;
2525
private final EventCaller eventCaller;
2626

27-
private final Map<UUID, Afk> afkByPlayer = new HashMap<>();
28-
private final Map<UUID, Integer> interactionsCount = new HashMap<>();
29-
private final Map<UUID, Instant> lastInteraction = new HashMap<>();
27+
private final Map<UUID, Afk> afkByPlayer = new ConcurrentHashMap<>();
28+
private final Map<UUID, Integer> interactionsCount = new ConcurrentHashMap<>();
29+
private final Map<UUID, Instant> lastInteraction = new ConcurrentHashMap<>();
3030

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

eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkTask.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
import com.eternalcode.core.feature.vanish.VanishService;
44
import com.eternalcode.core.injector.annotations.Inject;
55
import com.eternalcode.core.injector.annotations.component.Task;
6+
import java.util.UUID;
67
import java.util.concurrent.TimeUnit;
78
import org.bukkit.Server;
89
import org.bukkit.entity.Player;
910

10-
import java.util.UUID;
11-
1211
@Task(delay = 1L, period = 1L, unit = TimeUnit.MINUTES)
1312
class AfkTask implements Runnable {
1413

@@ -55,5 +54,4 @@ void markAllInactivePlayers() {
5554
}
5655
}
5756
}
58-
5957
}

eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/messages/PLAfkMessages.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ public class PLAfkMessages implements AfkMessages {
1313

1414
@Description("# {PLAYER} - Gracz ")
1515
public Notice afkOn = Notice.chat("<green>► <white>{PLAYER} jest AFK!");
16+
17+
@Description("# {PLAYER} - Gracz ")
1618
public Notice afkOff = Notice.chat("<green>► <white>{PLAYER} już nie jest AFK!");
1719

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

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

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

29+
public String afkDisabledPlaceholder = "";
2830
}

eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
@Service
2121
class RandomTeleportSafeLocationService {
2222

23-
private static final int DEFAULT_NETHER_HEIGHT = 125;
2423
private static final int NETHER_MAX_HEIGHT = 127;
2524

2625
private final RandomTeleportSettings randomTeleportSettings;
@@ -37,14 +36,11 @@ class RandomTeleportSafeLocationService {
3736
}
3837

3938
public CompletableFuture<Location> getSafeRandomLocation(World world, RandomTeleportRadius radius, int attemptCount) {
40-
if (attemptCount < 0) {
39+
if (attemptCount <= 0) {
4140
return CompletableFuture.failedFuture(new RuntimeException("Cannot find safe location"));
4241
}
4342

44-
boolean noneWorld = this.locationsConfiguration.spawn.isNoneWorld();
45-
Location spawnLocation = !noneWorld
46-
? PositionAdapter.convert(this.locationsConfiguration.spawn)
47-
: world.getSpawnLocation();
43+
Location spawnLocation = getSpawnLocation(world);
4844

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

58-
if (world.getEnvironment() == World.Environment.NETHER) {
59-
randomY = this.random.nextInt(DEFAULT_NETHER_HEIGHT);
60-
}
61-
6254
RandomTeleportHeightRange heightRange = this.randomTeleportSettings.heightRange();
6355
int minHeight = heightRange.getMinY();
6456
int maxHeight = heightRange.getMaxY() - 1;
@@ -74,6 +66,19 @@ public CompletableFuture<Location> getSafeRandomLocation(World world, RandomTele
7466
});
7567
}
7668

69+
private Location getSpawnLocation(World targetWorld) {
70+
if (this.locationsConfiguration.spawn.isNoneWorld()) {
71+
return targetWorld.getSpawnLocation();
72+
}
73+
74+
Location configSpawn = PositionAdapter.convert(this.locationsConfiguration.spawn);
75+
if (configSpawn.getWorld().getName().equals(targetWorld.getName())) {
76+
return configSpawn;
77+
}
78+
79+
return targetWorld.getSpawnLocation();
80+
}
81+
7782
private boolean isSafeLocation(Chunk chunk, Location location) {
7883
if (location.getWorld() == null) {
7984
return false;

eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportServiceImpl.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,15 @@ public CompletableFuture<Location> getSafeRandomLocationInWorldBorder(World worl
8787

8888
private RandomTeleportRadius getWorldBorderRadius(World world) {
8989
WorldBorder worldBorder = world.getWorldBorder();
90-
int borderRadius = (int) (worldBorder.getSize() / 2);
91-
return RandomTeleportRadius.of(-borderRadius, borderRadius, -borderRadius, borderRadius);
90+
double size = worldBorder.getSize();
91+
double centerX = worldBorder.getCenter().getX();
92+
double centerZ = worldBorder.getCenter().getZ();
93+
94+
int minX = (int) (centerX - size/2);
95+
int maxX = (int) (centerX + size/2);
96+
int minZ = (int) (centerZ - size/2);
97+
int maxZ = (int) (centerZ + size/2);
98+
99+
return RandomTeleportRadius.of(minX, maxX, minZ, maxZ);
92100
}
93101
}

0 commit comments

Comments
 (0)