autowipe + toggledrops

yay!
This commit is contained in:
ayunami2000 2022-04-06 21:48:51 -04:00
parent 03e5833f0a
commit 705500bddd
6 changed files with 120 additions and 1 deletions

View File

@ -0,0 +1,47 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import dev.plex.services.ServiceManager;
import dev.plex.services.impl.AutoWipeService;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.toggledrops", source = RequiredCommandSource.ANY)
@CommandParameters(name = "toggledrops", description = "Toggle immediately removing drops.", usage = "/<command>", aliases = "td")
public class ToggleDropsCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
{
if (plugin.config.getBoolean("allowdrops"))
{
plugin.config.set("allowdrops", false);
plugin.config.save();
sender.sendMessage(messageComponent("allowDropsDisabled"));
}
else
{
plugin.config.set("allowdrops", true);
plugin.config.save();
sender.sendMessage(messageComponent("allowDropsEnabled"));
}
return null;
}
}

View File

@ -0,0 +1,14 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerDropItemEvent;
public class DropListener extends PlexListener
{
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event)
{
if (!plugin.config.getBoolean("allowdrops")) event.setCancelled(true);
}
}

View File

@ -2,6 +2,7 @@ package dev.plex.services;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import dev.plex.Plex; import dev.plex.Plex;
import dev.plex.services.impl.AutoWipeService;
import dev.plex.services.impl.BanService; import dev.plex.services.impl.BanService;
import dev.plex.services.impl.GameRuleService; import dev.plex.services.impl.GameRuleService;
import dev.plex.services.impl.UpdateCheckerService; import dev.plex.services.impl.UpdateCheckerService;
@ -19,6 +20,7 @@ public class ServiceManager
registerService(new BanService()); registerService(new BanService());
registerService(new GameRuleService()); registerService(new GameRuleService());
registerService(new UpdateCheckerService()); registerService(new UpdateCheckerService());
if (Plex.get().config.getBoolean("autowipe.enabled")) registerService(new AutoWipeService());
} }
public void startServices() public void startServices()

View File

@ -0,0 +1,40 @@
package dev.plex.services.impl;
import dev.plex.services.AbstractService;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import java.util.List;
public class AutoWipeService extends AbstractService
{
public AutoWipeService()
{
super(true, false);
}
@Override
public void run()
{
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();
}
}
}
}
@Override
public int repeatInSeconds()
{
return Math.max(1, plugin.config.getInt("autowipe.interval"));
}
}

View File

@ -141,6 +141,19 @@ entitywipe_list:
- "ZOMBIFIED_PIGLIN" - "ZOMBIFIED_PIGLIN"
- "PUFFERFISH" - "PUFFERFISH"
# Automatically wipe the specified entities
autowipe:
# Should we automatically wipe entities?
enabled: true
# How often, in seconds, to automatically wipe entities. Default is 5 minutes.
interval: 300
# Entities to automatically wipe
entities:
- "DROPPED_ITEM"
# Should we allow drops from players?
allowdrops: true
worlds: worlds:
flatlands: flatlands:
name: "Flatlands" name: "Flatlands"

View File

@ -160,3 +160,6 @@ noRemovedEntities: "<gray>No entities were removed."
# 0 - The command sender # 0 - The command sender
# 1 - Number of mobs removed # 1 - Number of mobs removed
removedMobs: "<red>{0} - Removed {1} mobs" removedMobs: "<red>{0} - Removed {1} mobs"
autoWipeDisabled: "<gray>Item wiping is currently disabled in the config!"
allowDropsDisabled: "<gray>No longer allowing drops from players."
allowDropsEnabled: "<gray>Now allowing drops from players."