Fixed loot chests expiring

This commit is contained in:
Indyuce 2022-05-23 20:30:53 +02:00
parent 31e8e42a1e
commit 6f812545b7
3 changed files with 15 additions and 29 deletions

View File

@ -189,23 +189,6 @@ public class MMOCore extends LuminePlugin {
}
}.runTaskTimer(MMOCore.plugin, 100, 20);
/*
* Clean active loot chests every 5 minutes. Cannot register this runnable in
* the loot chest manager because it is instanced when the plugin loads
*/
new BukkitRunnable() {
public void run() {
Iterator<LootChest> iterator = lootChests.getActive().iterator();
while (iterator.hasNext()) {
LootChest next = iterator.next();
if (next.shouldExpire()) {
iterator.remove();
next.expire(false);
}
}
}
}.runTaskTimer(this, 5 * 60 * 20, 5 * 60 * 20);
/*
* For the sake of the lord, make sure they aren't using MMOItems Mana and
* Stamina Addon...This should prevent a couple error reports produced by people

View File

@ -10,7 +10,6 @@ import org.bukkit.Particle;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import javax.annotation.Nullable;
@ -21,7 +20,7 @@ public class LootChest {
private final ReplacedBlock block;
@Nullable
private final BukkitRunnable effectRunnable;
private final long date = System.currentTimeMillis();
private final BukkitRunnable closeRunnable;
private boolean active = true;
@ -37,6 +36,13 @@ public class LootChest {
this.region = region;
this.block = new ReplacedBlock(block);
this.effectRunnable = tier.hasEffect() ? tier.getEffect().startNewRunnable(block.getLocation().add(.5, .5, .5)) : null;
closeRunnable = new BukkitRunnable() {
@Override
public void run() {
expire(false);
}
};
closeRunnable.runTaskLater(MMOCore.plugin, MMOCore.plugin.configManager.lootChestExpireTime);
}
public ChestTier getTier() {
@ -51,15 +57,8 @@ public class LootChest {
return region;
}
public boolean hasPlayerNearby() {
for (Player player : block.loc.getWorld().getPlayers())
if (player.getLocation().distanceSquared(block.loc.bukkit()) < 625)
return true;
return false;
}
public boolean shouldExpire() {
return System.currentTimeMillis() - date > MMOCore.plugin.configManager.lootChestExpireTime;
public boolean isActive() {
return active;
}
/**
@ -77,6 +76,10 @@ public class LootChest {
Validate.isTrue(active, "Chest has already expired");
active = false;
// Close runnable
if (!closeRunnable.isCancelled())
closeRunnable.cancel();
// If a player is responsible of closing the chest, close it with sound
if (player) {
MMOCore.plugin.soundManager.getSound(SoundEvent.CLOSE_LOOT_CHEST).playAt(block.loc.bukkit());

View File

@ -94,7 +94,7 @@ public class ConfigManager {
chatInput = MMOCore.plugin.getConfig().getBoolean("use-chat-input");
partyChatPrefix = MMOCore.plugin.getConfig().getString("party.chat-prefix");
combatLogTimer = MMOCore.plugin.getConfig().getInt("combat-log.timer") * 1000L;
lootChestExpireTime = Math.max(MMOCore.plugin.getConfig().getInt("loot-chests.chest-expire-time"), 1) * 1000L;
lootChestExpireTime = Math.max(MMOCore.plugin.getConfig().getInt("loot-chests.chest-expire-time"), 1) * 20;
lootChestPlayerCooldown = (long) MMOCore.plugin.getConfig().getDouble("player-cooldown") * 1000L;
globalSkillCooldown = MMOCore.plugin.getConfig().getLong("global-skill-cooldown") * 50;
noSkillBoundPlaceholder = getSimpleMessage("no-skill-placeholder").message();