Skip to content

Commit

Permalink
Merge pull request #18 from demkom58/1.17-update
Browse files Browse the repository at this point in the history
1.17 update
  • Loading branch information
demkom58 authored Jun 26, 2021
2 parents 403a75e + 3500cb1 commit 6b5f804
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pluginGroup = com.demkom58.divinedrop
pluginDesc = Awesome removal of items from the ground
pluginVersion = 2.7.2
pluginVersion = 2.7.3
url = https://www.spigotmc.org/members/98068/
26 changes: 24 additions & 2 deletions src/main/java/com/demkom58/divinedrop/drop/ItemHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
import org.bukkit.metadata.MetadataValue;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.ReentrantLock;

public class ItemHandler {

Expand All @@ -30,6 +32,11 @@ public class ItemHandler {

private final DivineTimer itemTickTimer;

private List<Item> toRemove = new ArrayList<>();
private List<Item> shadow = new ArrayList<>();
private final ReentrantLock lockRemove = new ReentrantLock();
private final ReentrantLock lockShadowing = new ReentrantLock();

public ItemHandler(@NotNull final DivineDrop plugin,
@NotNull final VersionManager versionManager,
@NotNull final ConfigData data) {
Expand All @@ -40,7 +47,19 @@ public ItemHandler(@NotNull final DivineDrop plugin,
this.registry = new ItemRegistry(plugin, data, this);

final Set<Item> timedItems = registry.getTimedItems();
this.itemTickTimer = new DivineTimer(plugin, () -> timedItems.forEach(this::itemTick));
this.itemTickTimer = new DivineTimer(plugin, () -> {
timedItems.forEach(this::itemTick);
Bukkit.getScheduler().runTask(plugin, () -> {
lockRemove.lock();
List<Item> items = toRemove;
this.toRemove = shadow;
this.shadow = items;
lockRemove.unlock();

items.forEach(Item::remove);
items.clear();
});
});
}

public void reload() {
Expand Down Expand Up @@ -116,7 +135,10 @@ public void tickTimer(@NotNull final Item item,
public void updateTimedItem(@NotNull final Item item,
@NotNull final DataContainer container) {
if (container.getTimer() <= 0) {
item.remove();
lockShadowing.lock();
toRemove.add(item);
lockShadowing.unlock();

registry.getTimedItems().remove(item);
}

Expand Down

0 comments on commit 6b5f804

Please sign in to comment.