Skip to content

Commit 67b4158

Browse files
committed
Update 3.5.2
Fixed MobSpawning protection to use Paper spigot method which doesn't cause lag like the old method I was using. NOTE: This option now only works on Paper/Folia servers
1 parent 3d58672 commit 67b4158

12 files changed

Lines changed: 45 additions & 197 deletions

File tree

.idea/dictionaries/project.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules/IdeaProjects.AFKPlus.main.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2025 Benjamin Martin
2+
* Copyright 2026 Benjamin Martin
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@ plugins {
2222

2323
group = 'net.lapismc'
2424
archivesBaseName = "AFKPlus"
25-
version = '3.5.1'
25+
version = '3.5.2'
2626
description = 'AFK for professional servers'
2727
sourceCompatibility = '21'
2828
targetCompatibility = '21'
@@ -50,9 +50,13 @@ repositories {
5050
}
5151

5252
dependencies {
53-
implementation 'net.lapismc:LapisCore:1.13.9'
53+
implementation 'net.lapismc:LapisCore:1.13.11'
5454
implementation 'org.ocpsoft.prettytime:prettytime:5.0.8.Final'
55-
compileOnly 'net.essentialsx:EssentialsX:2.20.1'
55+
compileOnly 'io.papermc.paper:paper-api:1.21.11-R0.1-SNAPSHOT'
56+
compileOnly('net.essentialsx:EssentialsX:2.20.1') {
57+
//This exclusion is so we can use the paper api without class collisions
58+
exclude group: "org.spigotmc", module: "spigot-api"
59+
}
5660
compileOnly 'net.luckperms:api:5.4'
5761
compileOnly 'com.discordsrv:discordsrv:1.29.0'
5862
}

src/main/java/net/lapismc/afkplus/AFKPlus.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2025 Benjamin Martin
2+
* Copyright 2026 Benjamin Martin
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -53,23 +53,27 @@ public void onEnable() {
5353
registerConfiguration(new AFKPlusConfiguration(this, 20, 8));
5454
registerPermissions(new AFKPlusPermissions(this));
5555
registerLuckPermsContext();
56-
update();
56+
checkForUpdate();
5757
fileWatcher = new LapisCoreFileWatcher(this);
5858
Locale loc = new Locale(config.getMessage("PrettyTimeLocale"));
5959
prettyTime = new PrettyTime(loc);
6060
prettyTime.removeUnit(JustNow.class);
6161
prettyTime.removeUnit(Millisecond.class);
62+
//Register Commands
6263
new AFK(this);
6364
new AFKPlusCmd(this);
6465
listeners = new AFKPlusListeners(this);
66+
//Provide main class to API classes
6567
new AFKPlusAPI(this);
6668
new AFKPlusPlayerAPI(this);
69+
//Setup BStats
6770
new Metrics(this, 424);
6871
//Safely handle the stopping of AFKPlus in regard to player data
6972
tasks.addShutdownTask(() -> {
7073
players.values().forEach(player -> player.stopAFK(true));
7174
players.clear();
7275
});
76+
//This task is for processing AFK start, warn and kick
7377
tasks.addTask(tasks.runTaskTimer(getRepeatingTasks(), 20, 20, true));
7478
getLogger().info(getName() + " v." + getDescription().getVersion() + " has been enabled!");
7579
}
@@ -128,7 +132,7 @@ public void storeAFKSession(AFKSession session) {
128132
playerSessions.put(session.getUUID(), session);
129133
}
130134

131-
private void update() {
135+
private void checkForUpdate() {
132136
//Don't check for updates if the update check setting is set to false
133137
if (!getConfig().getBoolean("UpdateCheck"))
134138
return;

src/main/java/net/lapismc/afkplus/AFKPlusListeners.java

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2025 Benjamin Martin
2+
* Copyright 2026 Benjamin Martin
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
1919
import net.lapismc.afkplus.api.AFKMachineDetectEvent;
2020
import net.lapismc.afkplus.playerdata.AFKPlusPlayer;
2121
import net.lapismc.afkplus.playerdata.AFKSession;
22-
import net.lapismc.afkplus.util.EntitySpawnManager;
2322
import net.lapismc.afkplus.util.PlayerMovementMonitoring;
2423
import net.lapismc.afkplus.util.PlayerMovementStorage;
2524
import net.lapismc.lapiscore.commands.CommandRegistry;
@@ -35,7 +34,9 @@
3534
import org.bukkit.event.block.Action;
3635
import org.bukkit.event.block.BlockBreakEvent;
3736
import org.bukkit.event.block.BlockPlaceEvent;
38-
import org.bukkit.event.entity.*;
37+
import org.bukkit.event.entity.EntityDamageByEntityEvent;
38+
import org.bukkit.event.entity.EntityDamageEvent;
39+
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
3940
import org.bukkit.event.inventory.InventoryInteractEvent;
4041
import org.bukkit.event.player.*;
4142

@@ -47,14 +48,12 @@ public class AFKPlusListeners implements Listener {
4748
private final AFKPlus plugin;
4849
private final HashMap<UUID, Location> playerLocations = new HashMap<>();
4950
private LapisTaskHandler.LapisTask AfkMachineDetectionTask;
50-
private final EntitySpawnManager spawnManager;
5151
private final PlayerMovementMonitoring monitoring;
5252

5353
AFKPlusListeners(AFKPlus plugin) {
5454
this.plugin = plugin;
5555
monitoring = new PlayerMovementMonitoring();
5656
startAFKMachineDetection();
57-
spawnManager = new EntitySpawnManager(plugin);
5857
Bukkit.getPluginManager().registerEvents(this, plugin);
5958
}
6059

@@ -250,34 +249,6 @@ public void onPlayerHurt(EntityDamageEvent e) {
250249
e.setCancelled(true);
251250
}
252251

253-
/*
254-
Mob Spawning Protections
255-
*/
256-
257-
@EventHandler
258-
public void onNaturalMonsterSpawn(CreatureSpawnEvent e) {
259-
if (!plugin.getConfig().getBoolean("Protections.MobSpawning"))
260-
return;
261-
//Return if it's not a monster or if it isn't natural
262-
if (!(e.getEntity() instanceof Monster) || !e.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL))
263-
return;
264-
boolean shouldSpawn = spawnManager.shouldNaturalSpawn(e.getLocation());
265-
if (!shouldSpawn)
266-
e.setCancelled(true);
267-
}
268-
269-
@EventHandler
270-
public void onSpawnerMonsterSpawn(SpawnerSpawnEvent e) {
271-
if (!plugin.getConfig().getBoolean("Protections.MobSpawning"))
272-
return;
273-
//Return if it's not a monster
274-
if (!(e.getEntity() instanceof Monster))
275-
return;
276-
boolean shouldSpawn = spawnManager.shouldSpawnerSpawn(e.getSpawner());
277-
if (!shouldSpawn)
278-
e.setCancelled(true);
279-
}
280-
281252
/*
282253
Mob targeting protection
283254
*/
@@ -289,7 +260,6 @@ public void onEntityTarget(EntityTargetLivingEntityEvent e) {
289260
return;
290261
if (!(e.getTarget() instanceof Player player))
291262
return;
292-
if (player == null) return;
293263
if (!plugin.getPlayer(player).isAFK())
294264
return;
295265
e.setCancelled(true);

src/main/java/net/lapismc/afkplus/playerdata/AFKPlusPlayer.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2025 Benjamin Martin
2+
* Copyright 2026 Benjamin Martin
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
2323
import net.lapismc.afkplus.api.AFKStopEvent;
2424
import net.lapismc.afkplus.util.AFKPlusDiscordSRVHook;
2525
import net.lapismc.afkplus.util.EssentialsAFKHook;
26+
import net.lapismc.lapiscore.compatibility.ServerImplementations;
2627
import net.lapismc.lapiscore.compatibility.XSound;
2728
import org.bukkit.Bukkit;
2829
import org.bukkit.entity.Player;
@@ -251,6 +252,14 @@ public void forceStartAFK() {
251252
p.setSleepingIgnored(true);
252253
}
253254
}
255+
//Set the player as being ignored for mob spawning on paper servers if it is enabled
256+
if (plugin.getConfig().getBoolean("Protections.MobSpawning")) {
257+
if (new ServerImplementations().getImplementations().contains(ServerImplementations.imp.Paper)) {
258+
Player p = Bukkit.getPlayer(getUUID());
259+
if (p != null)
260+
p.setAffectsSpawning(false);
261+
}
262+
}
254263
}
255264

256265
/**
@@ -319,6 +328,14 @@ public void forceStopAFK() {
319328
p.setSleepingIgnored(false);
320329
}
321330
}
331+
//Set the player as being included for mob spawning on paper servers if it is enabled
332+
if (plugin.getConfig().getBoolean("Protections.MobSpawning")) {
333+
if (new ServerImplementations().getImplementations().contains(ServerImplementations.imp.Paper)) {
334+
Player p = Bukkit.getPlayer(getUUID());
335+
if (p != null)
336+
p.setAffectsSpawning(true);
337+
}
338+
}
322339
}
323340

324341
/**

src/main/java/net/lapismc/afkplus/util/EntitySpawnManager.java

Lines changed: 0 additions & 150 deletions
This file was deleted.

src/main/resources/config.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ Protections:
9191
#Same as HurtByPlayer but stops any non-player damage
9292
HurtByOther: true
9393
#When enabled, mobs will not spawn if the AFK player is the cause of the spawning
94-
#This only applies to natural and spawner spawning
95-
#This may cause minor lag on high-end servers
94+
#This feature uses an API only available on Paper based servers, so will not function on Spigot/Bukkit
9695
MobSpawning: false
9796
#When enabled AFK players will not be targeted by mobs
9897
MobTargeting: false

updater/AFKPlus/AFKPlus.jar

-812 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)