mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-03 06:37:47 +01:00
Biome change listener
This commit is contained in:
parent
97193d8341
commit
938aee4f0f
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user