24package com.dreamfirestudios.dreamcore.DreamFakeBlock;
27import org.bukkit.Location;
28import org.bukkit.Material;
29import org.bukkit.entity.Player;
31import java.util.HashSet;
46 @Getter
private final Location location;
47 private Material material;
48 private final Set<Player> observers =
new HashSet<>();
61 if (location ==
null || material ==
null)
throw new IllegalArgumentException(
"Location and material cannot be null");
62 this.location = location;
63 this.material = material;
72 if (player ==
null)
throw new IllegalArgumentException(
"Player cannot be null");
73 player.sendBlockChange(location, material.createBlockData());
74 observers.add(player);
84 if (player ==
null)
throw new IllegalArgumentException(
"Player cannot be null");
85 player.sendBlockChange(location, location.getBlock().getType().createBlockData());
86 observers.remove(player);
94 for (Player player :
new HashSet<>(observers)) {
109 if (player ==
null || location ==
null)
throw new IllegalArgumentException(
"Player and location cannot be null");
110 return observers.contains(player) && this.location.equals(location);
120 return this.location.equals(location);
129 if (newMaterial ==
null)
throw new IllegalArgumentException(
"Material cannot be null");
130 this.material = newMaterial;
131 for (Player player : observers) {
132 player.sendBlockChange(location, newMaterial.createBlockData());
141 for (Player player : observers) {
142 player.sendBlockChange(location, material.createBlockData());
148 return observers.size();
Represents a single fake block at a given location for one or more observers.
void addObserver(Player player)
Adds a player to the observer list and sends them the fake block.
boolean isLocation(Location location)
Checks if a given location matches this fake block’s location.
Material getMaterial()
The current fake block material.
void removeAllObservers()
Removes all observers, restoring the world block to them.
DreamFakeBlock(Location location, Material material)
Creates a new fake block at a location with a specific material.
void updateMaterialForAllObservers(Material newMaterial)
Updates the material of the fake block for all observers.
int getObserverCount()
The number of players observing this fake block.
void removeObserver(Player player)
Removes a player from observers and restores the real block to them.
boolean isPlayerObservingAtLocation(Player player, Location location)
Checks if a player is observing this block at a given location.
void displayNextFrame()
Re-sends the current block state to all observers (e.g.
Fired after all observers are removed from a DreamFakeBlock.
Fired when a player is added as an observer to a DreamFakeBlock.
Fired when a player is removed from observing a DreamFakeBlock.
Fired when a DreamFakeBlock's material is updated and pushed to all observers.