mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
autowipe + toggledrops
yay!
This commit is contained in:
parent
03e5833f0a
commit
705500bddd
47
src/main/java/dev/plex/command/impl/ToggleDropsCMD.java
Normal file
47
src/main/java/dev/plex/command/impl/ToggleDropsCMD.java
Normal 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;
|
||||
}
|
||||
}
|
14
src/main/java/dev/plex/listener/impl/DropListener.java
Normal file
14
src/main/java/dev/plex/listener/impl/DropListener.java
Normal 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);
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package dev.plex.services;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.services.impl.AutoWipeService;
|
||||
import dev.plex.services.impl.BanService;
|
||||
import dev.plex.services.impl.GameRuleService;
|
||||
import dev.plex.services.impl.UpdateCheckerService;
|
||||
@ -19,6 +20,7 @@ public class ServiceManager
|
||||
registerService(new BanService());
|
||||
registerService(new GameRuleService());
|
||||
registerService(new UpdateCheckerService());
|
||||
if (Plex.get().config.getBoolean("autowipe.enabled")) registerService(new AutoWipeService());
|
||||
}
|
||||
|
||||
public void startServices()
|
||||
|
40
src/main/java/dev/plex/services/impl/AutoWipeService.java
Normal file
40
src/main/java/dev/plex/services/impl/AutoWipeService.java
Normal 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"));
|
||||
}
|
||||
}
|
@ -141,6 +141,19 @@ entitywipe_list:
|
||||
- "ZOMBIFIED_PIGLIN"
|
||||
- "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:
|
||||
flatlands:
|
||||
name: "Flatlands"
|
||||
|
@ -159,4 +159,7 @@ invalidEntityType: "<gray>Notice: Entity type {0} is invalid!"
|
||||
noRemovedEntities: "<gray>No entities were removed."
|
||||
# 0 - The command sender
|
||||
# 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."
|
Loading…
Reference in New Issue
Block a user