mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2025-01-08 07:27:41 +01:00
Fixed an issue with loot chest unregistration
This commit is contained in:
parent
52c2a07e47
commit
cb460b7752
@ -58,7 +58,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.HashSet;
|
import java.util.Iterator;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class MMOCore extends LuminePlugin {
|
public class MMOCore extends LuminePlugin {
|
||||||
@ -200,8 +200,14 @@ public class MMOCore extends LuminePlugin {
|
|||||||
*/
|
*/
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
for (LootChest chest : new HashSet<>(lootChests.getActive()))
|
Iterator<LootChest> iterator = lootChests.getActive().iterator();
|
||||||
if (chest.shouldExpire()) chest.unregister(false);
|
while (iterator.hasNext()) {
|
||||||
|
LootChest next = iterator.next();
|
||||||
|
if (next.shouldExpire()) {
|
||||||
|
iterator.remove();
|
||||||
|
next.expire(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.runTaskTimer(this, 5 * 60 * 20, 5 * 60 * 20);
|
}.runTaskTimer(this, 5 * 60 * 20, 5 * 60 * 20);
|
||||||
|
|
||||||
@ -369,7 +375,7 @@ public class MMOCore extends LuminePlugin {
|
|||||||
mineManager.resetRemainingBlocks();
|
mineManager.resetRemainingBlocks();
|
||||||
|
|
||||||
// Clear spawned loot chests
|
// Clear spawned loot chests
|
||||||
lootChests.getActive().forEach(chest -> chest.unregister(false));
|
lootChests.getActive().forEach(chest -> chest.expire(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,6 +17,6 @@ public class LootableChestsListener implements Listener {
|
|||||||
Chest chest = (Chest) event.getInventory().getHolder();
|
Chest chest = (Chest) event.getInventory().getHolder();
|
||||||
LootChest lootChest = MMOCore.plugin.lootChests.getChest(chest.getLocation());
|
LootChest lootChest = MMOCore.plugin.lootChests.getChest(chest.getLocation());
|
||||||
if (lootChest != null)
|
if (lootChest != null)
|
||||||
lootChest.unregister(true);
|
lootChest.expire(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package net.Indyuce.mmocore.loot.chest;
|
|||||||
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.SoundEvent;
|
import net.Indyuce.mmocore.api.SoundEvent;
|
||||||
import net.Indyuce.mmocore.manager.SoundManager;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Particle;
|
import org.bukkit.Particle;
|
||||||
@ -12,13 +12,18 @@ import org.bukkit.block.data.BlockData;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class LootChest {
|
public class LootChest {
|
||||||
private final ChestTier tier;
|
private final ChestTier tier;
|
||||||
private final LootChestRegion region;
|
private final LootChestRegion region;
|
||||||
private final ReplacedBlock block;
|
private final ReplacedBlock block;
|
||||||
|
@Nullable
|
||||||
private final BukkitRunnable effectRunnable;
|
private final BukkitRunnable effectRunnable;
|
||||||
private final long date = System.currentTimeMillis();
|
private final long date = System.currentTimeMillis();
|
||||||
|
|
||||||
|
private boolean active = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a loot chest is placed as a Bukkit block, and used
|
* Called when a loot chest is placed as a Bukkit block, and used
|
||||||
* to save the data of the block which has been replaced.
|
* to save the data of the block which has been replaced.
|
||||||
@ -57,19 +62,24 @@ public class LootChest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This does NOT remove the loot chest from the plugin registry.
|
||||||
|
*
|
||||||
* @param player If a player triggered the unregistration of that chest by
|
* @param player If a player triggered the unregistration of that chest by
|
||||||
* opening and then closing it for the first time. It's set
|
* opening and then closing it for the first time. It's set
|
||||||
* to false when a loot chest expires or when MMOCore disables.
|
* to false when a loot chest expires or when MMOCore disables.
|
||||||
* <p>
|
* <p>
|
||||||
* When no player is closing the chest, its content should be lost
|
* When no player is closing the chest, its content should be lost
|
||||||
*/
|
*/
|
||||||
public void unregister(boolean player) {
|
public void expire(boolean player) {
|
||||||
|
|
||||||
|
// Check for expire
|
||||||
|
Validate.isTrue(active, "Chest has already expired");
|
||||||
|
active = false;
|
||||||
|
|
||||||
// If a player is responsible of closing the chest, close it with sound
|
// If a player is responsible of closing the chest, close it with sound
|
||||||
if (player) {
|
if (player) {
|
||||||
MMOCore.plugin.soundManager.getSound(SoundEvent.CLOSE_LOOT_CHEST).playAt(block.loc);
|
MMOCore.plugin.soundManager.getSound(SoundEvent.CLOSE_LOOT_CHEST).playAt(block.loc);
|
||||||
block.loc.getWorld().spawnParticle(Particle.CRIT, block.loc.clone().add(.5, .5, .5), 16, 0, 0, 0, .5);
|
block.loc.getWorld().spawnParticle(Particle.CRIT, block.loc.clone().add(.5, .5, .5), 16, 0, 0, 0, .5);
|
||||||
MMOCore.plugin.lootChests.unregister(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user