Biome change listener

This commit is contained in:
Roch Blonndiaux 2023-03-19 14:59:33 +01:00
parent 97193d8341
commit 938aee4f0f
2 changed files with 41 additions and 0 deletions

View File

@ -22,6 +22,7 @@ public class MMOItemsBukkit {
Bukkit.getPluginManager().registerEvents(new DurabilityListener(), plugin);
Bukkit.getPluginManager().registerEvents(new DisableInteractions(), plugin);
Bukkit.getPluginManager().registerEvents(new GuiListener(), plugin);
Bukkit.getPluginManager().registerEvents(new BiomeChangeListener(), plugin);
Bukkit.getPluginManager().registerEvents(new CustomBlockListener(), plugin);
if (Bukkit.getPluginManager().getPlugin("PhatLoots") != null)
Bukkit.getPluginManager().registerEvents(new PhatLootsHook(), plugin);

View File

@ -0,0 +1,40 @@
package net.Indyuce.mmoitems.listener;
import com.google.common.collect.Maps;
import net.Indyuce.mmoitems.api.player.PlayerData;
import org.bukkit.block.Biome;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import java.util.Map;
import java.util.UUID;
/**
* mmoitems
* 19/03/2023
*
* @author Roch Blondiaux (Kiwix).
*/
public class BiomeChangeListener implements Listener {
private final Map<UUID, Biome> biomeMap = Maps.newHashMap();
/**
* This listener goal is to update the player inventory when he changes biome.
*
* @param e
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerMove(PlayerMoveEvent e) {
if (e.isCancelled() || !PlayerData.has(e.getPlayer()) || (e.getFrom().getBlockX() == e.getTo().getBlockX() && e.getFrom().getBlockZ() == e.getTo().getBlockZ()))
return;
final UUID uuid = e.getPlayer().getUniqueId();
final Biome biome = e.getTo().getBlock().getBiome();
final Biome lastBiome = biomeMap.computeIfAbsent(uuid, u1 -> biome);
if (biome != lastBiome)
PlayerData.get(e.getPlayer()).getInventory().scheduleUpdate();
biomeMap.put(uuid, biome);
}
}