2022-04-07 01:48:51 +00:00
|
|
|
package dev.plex.services.impl;
|
|
|
|
|
2022-04-07 02:08:51 +00:00
|
|
|
import dev.plex.Plex;
|
2022-04-07 01:48:51 +00:00
|
|
|
import dev.plex.services.AbstractService;
|
2023-07-22 01:01:59 +00:00
|
|
|
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
|
2023-07-22 01:01:59 +00:00
|
|
|
public void run(ScheduledTask task)
|
2022-04-07 01:48:51 +00:00
|
|
|
{
|
2022-04-07 02:08:51 +00:00
|
|
|
if (Plex.get().config.getBoolean("autowipe.enabled"))
|
2022-04-07 01:48:51 +00:00
|
|
|
{
|
2022-04-07 02:08:51 +00:00
|
|
|
List<String> entities = plugin.config.getStringList("autowipe.entities");
|
|
|
|
|
|
|
|
for (World world : Bukkit.getWorlds())
|
2022-04-07 01:48:51 +00:00
|
|
|
{
|
2022-04-07 02:08:51 +00:00
|
|
|
for (Entity entity : world.getEntities())
|
2022-04-07 01:48:51 +00:00
|
|
|
{
|
2022-04-07 02:08:51 +00:00
|
|
|
if (entities.stream().anyMatch(entityName -> entityName.equalsIgnoreCase(entity.getType().name())))
|
|
|
|
{
|
2023-07-22 01:01:59 +00:00
|
|
|
Bukkit.getRegionScheduler().run(Plex.get(), entity.getLocation(), this::entityRun);
|
2022-04-07 02:08:51 +00:00
|
|
|
}
|
2022-04-07 01:48:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-22 01:01:59 +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"));
|
|
|
|
}
|
|
|
|
}
|