DREAMFIRE Docs ← Back to site
Loading...
Searching...
No Matches
DreamFakeBlockAPI.java
Go to the documentation of this file.
1/*
2 * MIT License
3 *
4 * Copyright (c) 2025 Dreamfire Studio
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24package com.dreamfirestudios.dreamcore.DreamFakeBlock;
25
26import com.dreamfirestudios.dreamcore.DreamCore;
27import org.bukkit.Location;
28import org.bukkit.Material;
29import org.bukkit.entity.Player;
30
37public class DreamFakeBlockAPI {
38
47 public static void createFakeBlock(String id, Location location, Material material, Player... players){
48 var fakeBlock = new DreamFakeBlock(location, material);
49 for (var player : players) {
50 fakeBlock.addObserver(player);
51 }
52 DreamCore.DreamFakeBlocks.put(id, fakeBlock);
53 new FakeBlockCreatedEvent(fakeBlock, id);
54 }
55
59 public static void removePlayerFromFakeBlock(Player player, Location location){
60 for (var fakeBlock : DreamCore.DreamFakeBlocks.values()){
61 if (fakeBlock.isPlayerObservingAtLocation(player, location)) {
62 fakeBlock.removeObserver(player);
63 }
64 }
65 }
66
70 public static void removePlayerFromFakeBlock(Player player, String id){
71 var fakeBlock = DreamCore.DreamFakeBlocks.getOrDefault(id, null);
72 if (fakeBlock != null) fakeBlock.removeObserver(player);
73 }
74
78 public static void removeFakeBlock(Location location){
79 for (var fakeBlock : DreamCore.DreamFakeBlocks.values()){
80 if (fakeBlock.isLocation(location)) {
81 fakeBlock.removeAllObservers();
82 }
83 }
84 }
85
89 public static void removeFakeBlock(String id){
90 var fakeBlock = DreamCore.DreamFakeBlocks.getOrDefault(id, null);
91 if (fakeBlock != null) fakeBlock.removeAllObservers();
92 }
93
97 public static Material returnMaterialForPlayer(Player player, Location location){
98 for (var fakeBlock : DreamCore.DreamFakeBlocks.values()){
99 if (fakeBlock.isPlayerObservingAtLocation(player, location)) {
100 return fakeBlock.getMaterial();
101 }
102 }
103 return null;
104 }
105
109 public static Material returnMaterialForID(String id){
110 var fakeBlock = DreamCore.DreamFakeBlocks.getOrDefault(id, null);
111 return fakeBlock != null ? fakeBlock.getMaterial() : null;
112 }
113}
static final LinkedHashMap< String, DreamFakeBlock > DreamFakeBlocks
Static utility methods for creating, managing and querying fake blocks.
static void createFakeBlock(String id, Location location, Material material, Player... players)
Create and register a new fake block with observers.
static Material returnMaterialForPlayer(Player player, Location location)
Returns the fake material a player sees at a location, or null if none.
static Material returnMaterialForID(String id)
Returns the fake material for a block ID, or null if not present.
static void removeFakeBlock(Location location)
Remove and clear a fake block by location.
static void removePlayerFromFakeBlock(Player player, Location location)
Remove a player from observing the fake block at a specific location.
static void removeFakeBlock(String id)
Remove and clear a fake block by ID.
static void removePlayerFromFakeBlock(Player player, String id)
Remove a player from observing a fake block by ID.
Represents a single fake block at a given location for one or more observers.
Fired when a new DreamFakeBlock is created and registered.