More refactoring, splitting api and internal

This commit is contained in:
Auxilor
2021-02-14 16:31:16 +00:00
parent 3a6a133560
commit eae213f58e
14 changed files with 71 additions and 60 deletions

View File

@@ -6,6 +6,9 @@ import com.willfp.eco.spigot.display.PacketOpenWindowMerchant;
import com.willfp.eco.spigot.display.PacketSetCreativeSlot;
import com.willfp.eco.spigot.display.PacketSetSlot;
import com.willfp.eco.spigot.display.PacketWindowItems;
import com.willfp.eco.spigot.drops.CollatedRunnable;
import com.willfp.eco.spigot.eventlisteners.EntityDeathByEntityListeners;
import com.willfp.eco.spigot.eventlisteners.NaturalExpGainListeners;
import com.willfp.eco.spigot.integrations.anticheat.AnticheatAAC;
import com.willfp.eco.spigot.integrations.anticheat.AnticheatMatrix;
import com.willfp.eco.spigot.integrations.anticheat.AnticheatNCP;
@@ -18,11 +21,8 @@ import com.willfp.eco.spigot.integrations.antigrief.AntigriefWorldGuard;
import com.willfp.eco.spigot.integrations.mcmmo.McmmoIntegrationImpl;
import com.willfp.eco.util.command.AbstractCommand;
import com.willfp.eco.util.display.Display;
import com.willfp.eco.util.drops.internal.FastCollatedDropQueue;
import com.willfp.eco.util.events.armorequip.ArmorListener;
import com.willfp.eco.util.events.armorequip.DispenserArmorListener;
import com.willfp.eco.spigot.eventlisteners.EntityDeathByEntityListeners;
import com.willfp.eco.spigot.eventlisteners.NaturalExpGainListeners;
import com.willfp.eco.util.integrations.IntegrationLoader;
import com.willfp.eco.util.integrations.anticheat.AnticheatManager;
import com.willfp.eco.util.integrations.antigrief.AntigriefManager;
@@ -54,7 +54,7 @@ public class EcoPlugin extends AbstractEcoPlugin {
@Override
public void enable() {
new FastCollatedDropQueue.CollatedRunnable(this);
new CollatedRunnable(this);
this.getEventManager().registerListener(new NaturalExpGainListeners());
this.getEventManager().registerListener(new ArmorListener());
this.getEventManager().registerListener(new DispenserArmorListener());
@@ -73,7 +73,7 @@ public class EcoPlugin extends AbstractEcoPlugin {
@Override
public void onReload() {
new FastCollatedDropQueue.CollatedRunnable(this);
new CollatedRunnable(this);
}
@Override

View File

@@ -0,0 +1,39 @@
package com.willfp.eco.spigot.drops;
import com.willfp.eco.internal.drops.FastCollatedDropQueue;
import com.willfp.eco.internal.drops.InternalDropQueue;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import lombok.Getter;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
public class CollatedRunnable {
/**
* The {@link BukkitTask} that the runnable represents.
*/
@Getter
private final BukkitTask runnableTask;
/**
* Create and run a new runnable to process collated drops.
*
* @param plugin The {@link AbstractEcoPlugin} that manages the processing.
*/
public CollatedRunnable(@NotNull final AbstractEcoPlugin plugin) {
runnableTask = plugin.getScheduler().runTimer(() -> {
for (Map.Entry<Player, FastCollatedDropQueue.CollatedDrops> entry : FastCollatedDropQueue.COLLATED_MAP.entrySet()) {
new InternalDropQueue(entry.getKey())
.setLocation(entry.getValue().getLocation())
.addItems(entry.getValue().getDrops())
.addXP(entry.getValue().getXp())
.push();
FastCollatedDropQueue.COLLATED_MAP.remove(entry.getKey());
}
FastCollatedDropQueue.COLLATED_MAP.clear();
}, 0, 1);
}
}