Move ChunkLoadEvent to separate ChunkListener class

This commit is contained in:
ceze88 2023-04-07 22:43:31 +02:00
parent 4bf2d9b479
commit f234cdd73e
4 changed files with 31 additions and 9 deletions

View File

@ -281,6 +281,7 @@ public class UltimateStacker extends SongodaPlugin {
}
}
});
getServer().getPluginManager().registerEvents(new ChunkListener(this), this);
}
public void addExp(Player player, EntityStack stack) {

View File

@ -47,14 +47,6 @@ public class BlockListeners implements Listener {
this.plugin = plugin;
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
if (!Settings.STACK_BLOCKS.getBoolean()) return;
Chunk chunk = event.getChunk();
BlockStackManager blockStackManager = plugin.getBlockStackManager();
blockStackManager.getStacks().stream().filter(stack -> stack.getLocation().getChunk().equals(chunk)).forEach(plugin::updateHologram);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockInteract(PlayerInteractEvent event) {
if (event.useInteractedBlock() == Event.Result.DENY) return;

View File

@ -0,0 +1,28 @@
package com.songoda.ultimatestacker.listeners;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.settings.Settings;
import com.songoda.ultimatestacker.stackable.block.BlockStackManager;
import org.bukkit.Chunk;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkLoadEvent;
public class ChunkListener implements Listener {
private final BlockStackManager blockStackManager;
private final UltimateStacker plugin;
public ChunkListener(UltimateStacker plugin) {
this.blockStackManager = plugin.getBlockStackManager();
this.plugin = plugin;
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
if (!Settings.STACK_BLOCKS.getBoolean()) return;
Chunk chunk = event.getChunk();
BlockStackManager blockStackManager = plugin.getBlockStackManager();
blockStackManager.getStacks().stream().filter(stack -> stack.getLocation().getChunk().equals(chunk)).forEach(plugin::updateHologram);
}
}

View File

@ -8,10 +8,11 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class BlockStackManager {
private final Map<Location, BlockStack> registeredBlocks = new HashMap<>();
private final Map<Location, BlockStack> registeredBlocks = new ConcurrentHashMap<>();
public void addBlocks(Map<Location, BlockStack> blocks) {
this.registeredBlocks.putAll(blocks);