Implemented Clearing dropped items feature
This commit is contained in:
		@@ -78,6 +78,11 @@ public final class STPlugin extends JavaPlugin implements CommandExecutor, Liste
 | 
			
		||||
    private void scheduleTasks() {
 | 
			
		||||
        Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new TPS(), 0, 1);
 | 
			
		||||
 | 
			
		||||
        if (this.config.getBoolean("ClearDropItems.enabled")) {
 | 
			
		||||
            new ClearDropItemsTask(this).runTaskTimer(this, 20L, 20L);
 | 
			
		||||
            this.log.info(ChatColor.stripColor(this.getPrefix()) + "Clear dropped items enabled!");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (this.config.getBoolean("Saving.enabled") && this.config.getInt("Saving.interval") > 0) {
 | 
			
		||||
            long intervalTicks = Math.convert(Math.Convert.SECONDS, Math.Convert.TICKS, instance.config.getInt("Saving.interval"));
 | 
			
		||||
            Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new SaveHandler(), 0L, intervalTicks);
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,76 @@
 | 
			
		||||
package hu.ditservices.handlers;
 | 
			
		||||
 | 
			
		||||
import hu.ditservices.STPlugin;
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.World;
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
import org.bukkit.entity.Item;
 | 
			
		||||
import org.bukkit.scheduler.BukkitRunnable;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public class ClearDropItemsTask extends BukkitRunnable {
 | 
			
		||||
    private final STPlugin plugin;
 | 
			
		||||
    private int countdown;
 | 
			
		||||
    private final int interval; // In seconds
 | 
			
		||||
    private final List<String> exceptItemList;
 | 
			
		||||
    private final List<String> exceptWorldList;
 | 
			
		||||
    private final boolean shouldBroadcast;
 | 
			
		||||
 | 
			
		||||
    public ClearDropItemsTask(STPlugin plugin) {
 | 
			
		||||
        this.plugin = plugin;
 | 
			
		||||
        this.interval = plugin.getConfig().getInt("ClearDropItems.interval", 300);
 | 
			
		||||
        this.countdown = this.interval;
 | 
			
		||||
        // Get the exception list from the config (should be a list of item type names, e.g., ["DIAMOND", "GOLD_INGOT"])
 | 
			
		||||
        this.exceptItemList = plugin.getConfig().getStringList("ClearDropItems.except");
 | 
			
		||||
        this.exceptWorldList = plugin.getConfig().getStringList("ClearDropItems.skipWorlds");
 | 
			
		||||
        this.shouldBroadcast = plugin.getConfig().getBoolean("ClearDropItems.broadcastMsg", true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void run() {
 | 
			
		||||
        if (this.shouldBroadcast) {
 | 
			
		||||
            if (countdown == 60) {
 | 
			
		||||
                Bukkit.broadcastMessage(plugin.getPrefix() + ChatColor.RED + plugin.getTranslatedText("cleardropitems.oneMin"));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (countdown == 10) {
 | 
			
		||||
                Bukkit.broadcastMessage(plugin.getPrefix() + ChatColor.RED + plugin.getTranslatedText("cleardropitems.tenSec"));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        if (countdown <= 0) {
 | 
			
		||||
            int removed = 0;
 | 
			
		||||
 | 
			
		||||
            for (World world : Bukkit.getWorlds()) {
 | 
			
		||||
                if (this.exceptWorldList.contains(world.getName())) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
                for (Entity entity : world.getEntities()) {
 | 
			
		||||
 | 
			
		||||
                    if (entity instanceof Item) {
 | 
			
		||||
                        Item item = (Item) entity;
 | 
			
		||||
                        String itemType = item.getItemStack().getType().toString();
 | 
			
		||||
                        // Check if the item is in the exception list
 | 
			
		||||
                        boolean isException = this.exceptItemList.stream()
 | 
			
		||||
                                .anyMatch(ex -> ex.equalsIgnoreCase(itemType));
 | 
			
		||||
                        if (!isException) {
 | 
			
		||||
                            item.remove();
 | 
			
		||||
                            removed++;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (this.shouldBroadcast) {
 | 
			
		||||
                Bukkit.broadcastMessage(plugin.getPrefix() + ChatColor.GREEN + plugin.getTranslatedText("cleardropitems.cleared").replace("%REMOVECOUNT%",String.valueOf(removed)));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Reset the countdown to the interval for the next cycle
 | 
			
		||||
            countdown = interval;
 | 
			
		||||
        } else {
 | 
			
		||||
            countdown--;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -91,12 +91,28 @@ ServerPassword:
 | 
			
		||||
  preventMove: true
 | 
			
		||||
  preventBuild: true
 | 
			
		||||
 | 
			
		||||
# Dropped items clearing options
 | 
			
		||||
ClearDropItems:
 | 
			
		||||
  enabled: false
 | 
			
		||||
  interval: 300  # Interval in seconds between each clear cycle
 | 
			
		||||
  broadcastMsg: true # Broadcasts alerts before clearing 1 minutes and 10 seconds before and when cleared. Set this to 'false' to make cleaning silently.
 | 
			
		||||
  # Dropped items that should always be kept (never cleared)
 | 
			
		||||
  except:
 | 
			
		||||
    - DIAMOND
 | 
			
		||||
    - GOLD_INGOT
 | 
			
		||||
   # - COAL
 | 
			
		||||
   # - IRON_INGOT
 | 
			
		||||
   # - BREAD
 | 
			
		||||
  # Worlds to skip (dropped items in these worlds won't be cleared)
 | 
			
		||||
  skipWorlds:
 | 
			
		||||
      - world_nether
 | 
			
		||||
      - world_the_end
 | 
			
		||||
 | 
			
		||||
# Cooldown options (only applicable for this plugin!)
 | 
			
		||||
Cooldown:
 | 
			
		||||
  enabled: true
 | 
			
		||||
  # The time must be passed between using this plugin commands.
 | 
			
		||||
  seconds: 2 #The command cooldown in seconds
 | 
			
		||||
  seconds: 1 #The command cooldown in seconds
 | 
			
		||||
  Msg: '{PREFIX} Please wait {SECONDS} seconds!' # The message when the user spamming a command
 | 
			
		||||
#
 | 
			
		||||
# Plugin Manager - Enable/Disable plugins without server restart
 | 
			
		||||
 
 | 
			
		||||
@@ -36,4 +36,7 @@ pmanager.already.enabled: " already enabled!"
 | 
			
		||||
pmanager.success.enabled: " successfully enabled!"
 | 
			
		||||
pmanager.already.disabled: " already disabled!"
 | 
			
		||||
pmanager.success.disabled: " successfully disabled!"
 | 
			
		||||
list.help: "To list all SimplifyTools commands use the '/help SIMPLIFYTOOLS' command!"
 | 
			
		||||
list.help: "To list all SimplifyTools commands use the '/help SIMPLIFYTOOLS' command!"
 | 
			
		||||
cleardropitems.oneMin: "Attention: Dropped items will be cleared in 1 minute!"
 | 
			
		||||
cleardropitems.tenSec: "Attention: Dropped items will be cleared in 10 seconds!"
 | 
			
		||||
cleardropitems.cleared: "Dropped items have been cleared (%REMOVECOUNT% items removed)."
 | 
			
		||||
@@ -36,4 +36,7 @@ pmanager.already.enabled: " már eddig is engedélyezve volt!"
 | 
			
		||||
pmanager.success.enabled: " sikeresen engedélyezve!"
 | 
			
		||||
pmanager.already.disabled: " már kivolt kapcsolva eddig is!"
 | 
			
		||||
pmanager.success.disabled: " sikeresen kikapcsolva!"
 | 
			
		||||
list.help: "Használd a '/help SIMPLIFYTOOLS' parancsot a plugin parancsainak listázásához!"
 | 
			
		||||
list.help: "Használd a '/help SIMPLIFYTOOLS' parancsot a plugin parancsainak listázásához!"
 | 
			
		||||
cleardropitems.oneMin: "Figyelem! Az eldobott tárgyak 1 perc múlva törlésre kerülnek!"
 | 
			
		||||
cleardropitems.tenSec: "Figyelem! Az eldobott tárgyak 10 másodpercen belül törlésre kerülnek!"
 | 
			
		||||
cleardropitems.cleared: "Az eldobott tárgyak törlésre kerültek. (%REMOVECOUNT% tárgy lett eltávolítva)."
 | 
			
		||||
		Reference in New Issue
	
	Block a user