Plex/server/src/main/java/dev/plex/services/impl/AutoWipeService.java

61 lines
1.7 KiB
Java
Raw Normal View History

2022-04-07 01:48:51 +00:00
package dev.plex.services.impl;
import dev.plex.Plex;
2022-04-07 01:48:51 +00:00
import dev.plex.services.AbstractService;
import dev.plex.util.PlexLog;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import java.util.List;
2022-04-07 01:48:51 +00:00
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Entity;
public class AutoWipeService extends AbstractService
{
public AutoWipeService()
{
super(true, false);
}
@Override
public void run(ScheduledTask task)
2022-04-07 01:48:51 +00:00
{
if (Plex.get().config.getBoolean("autowipe.enabled"))
2022-04-07 01:48:51 +00:00
{
List<String> entities = plugin.config.getStringList("autowipe.entities");
for (World world : Bukkit.getWorlds())
2022-04-07 01:48:51 +00:00
{
for (Entity entity : world.getEntities())
2022-04-07 01:48:51 +00:00
{
if (entities.stream().anyMatch(entityName -> entityName.equalsIgnoreCase(entity.getType().name())))
{
Bukkit.getRegionScheduler().run(Plex.get(), entity.getLocation(), this::entityRun);
}
2022-04-07 01:48:51 +00:00
}
}
}
}
private void entityRun(ScheduledTask task)
{
List<String> entities = plugin.config.getStringList("autowipe.entities");
for (World world : Bukkit.getWorlds())
{
for (Entity entity : world.getEntities())
{
if (entities.stream().anyMatch(entityName -> entityName.equalsIgnoreCase(entity.getType().name())))
{
entity.remove();
task.cancel();
}
}
}
}
2022-04-07 01:48:51 +00:00
@Override
public int repeatInSeconds()
{
return Math.max(1, plugin.config.getInt("autowipe.interval"));
}
}