mirror of
https://github.com/kaboomserver/extras.git
synced 2025-02-15 05:33:23 +00:00
Remove entities in /de on the entity scheduler
This commit is contained in:
parent
beb00d1494
commit
a14f8b07de
5 changed files with 26 additions and 7 deletions
|
@ -1,6 +1,7 @@
|
||||||
package pw.kaboom.extras.platform;
|
package pw.kaboom.extras.platform;
|
||||||
|
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -14,4 +15,5 @@ public interface IScheduler {
|
||||||
void runAsync(final Plugin plugin, final Runnable runnable);
|
void runAsync(final Plugin plugin, final Runnable runnable);
|
||||||
void executeOnChunk(final Plugin plugin, final Chunk chunk, final Runnable runnable);
|
void executeOnChunk(final Plugin plugin, final Chunk chunk, final Runnable runnable);
|
||||||
void executeOnGlobalRegion(final Plugin plugin, final Runnable runnable);
|
void executeOnGlobalRegion(final Plugin plugin, final Runnable runnable);
|
||||||
|
void executeOnEntity(final Plugin plugin, final Entity entity, final Runnable runnable);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package pw.kaboom.extras.platform;
|
package pw.kaboom.extras.platform;
|
||||||
|
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -43,4 +44,8 @@ public final class PlatformScheduler {
|
||||||
public static void executeOnGlobalRegion(final Plugin plugin, final Runnable runnable) {
|
public static void executeOnGlobalRegion(final Plugin plugin, final Runnable runnable) {
|
||||||
currentScheduler.executeOnGlobalRegion(plugin, runnable);
|
currentScheduler.executeOnGlobalRegion(plugin, runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void executeOnEntity(final Plugin plugin, final Entity entity, final Runnable runnable) {
|
||||||
|
currentScheduler.executeOnEntity(plugin, entity, runnable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import pw.kaboom.extras.platform.IScheduler;
|
import pw.kaboom.extras.platform.IScheduler;
|
||||||
|
|
||||||
|
@ -56,6 +57,11 @@ public final class FoliaScheduler implements IScheduler {
|
||||||
GLOBAL_REGION_SCHEDULER.execute(plugin, runnable);
|
GLOBAL_REGION_SCHEDULER.execute(plugin, runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeOnEntity(final Plugin plugin, final Entity entity, final Runnable runnable) {
|
||||||
|
entity.getScheduler().run(plugin, FoliaTask.from(runnable), () -> {});
|
||||||
|
}
|
||||||
|
|
||||||
private static final class FoliaTask implements Consumer<ScheduledTask> {
|
private static final class FoliaTask implements Consumer<ScheduledTask> {
|
||||||
private final Runnable runnable;
|
private final Runnable runnable;
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package pw.kaboom.extras.platform.paper;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import pw.kaboom.extras.platform.IScheduler;
|
import pw.kaboom.extras.platform.IScheduler;
|
||||||
|
@ -50,4 +51,9 @@ public final class PaperScheduler implements IScheduler {
|
||||||
public void executeOnGlobalRegion(final Plugin plugin, final Runnable runnable) {
|
public void executeOnGlobalRegion(final Plugin plugin, final Runnable runnable) {
|
||||||
BUKKIT_SCHEDULER.runTask(plugin, runnable);
|
BUKKIT_SCHEDULER.runTask(plugin, runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeOnEntity(final Plugin plugin, final Entity entity, final Runnable runnable) {
|
||||||
|
BUKKIT_SCHEDULER.runTask(plugin, runnable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,9 @@ import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import pw.kaboom.extras.Main;
|
||||||
|
import pw.kaboom.extras.platform.PlatformScheduler;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
@ -20,16 +23,13 @@ public final class CommandDestroyEntities implements CommandExecutor {
|
||||||
int entityCount = 0;
|
int entityCount = 0;
|
||||||
int worldCount = 0;
|
int worldCount = 0;
|
||||||
|
|
||||||
|
final Main plugin = JavaPlugin.getPlugin(Main.class);
|
||||||
|
|
||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
for (Entity entity : world.getEntities()) {
|
for (Entity entity : world.getEntities()) {
|
||||||
if (!EntityType.PLAYER.equals(entity.getType())) {
|
if (!EntityType.PLAYER.equals(entity.getType())) {
|
||||||
try {
|
PlatformScheduler.executeOnEntity(plugin, entity, entity::remove);
|
||||||
entity.remove();
|
|
||||||
entityCount++;
|
entityCount++;
|
||||||
} catch (Exception ignored) {
|
|
||||||
// Broken entity
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
worldCount++;
|
worldCount++;
|
||||||
|
|
Loading…
Reference in a new issue