-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2576 from BentoBoxWorld/2569_general_display_enti…
…tiy_support 2569 general display entitiy support
- Loading branch information
Showing
17 changed files
with
660 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/world/bentobox/bentobox/api/hooks/NPCHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package world.bentobox.bentobox.api.hooks; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.bukkit.Chunk; | ||
import org.bukkit.Location; | ||
import org.bukkit.Material; | ||
import org.bukkit.World; | ||
import org.bukkit.configuration.InvalidConfigurationException; | ||
import org.bukkit.util.Vector; | ||
import org.eclipse.jdt.annotation.NonNull; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
|
||
import de.oliver.fancynpcs.api.Npc; | ||
import lol.pyr.znpcsplus.api.npc.NpcEntry; | ||
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity; | ||
|
||
/** | ||
* NPC Hooks | ||
* @author tastybento | ||
* @since 3.2.0 | ||
*/ | ||
public abstract class NPCHook extends Hook { | ||
|
||
protected NPCHook(@NonNull String pluginName, @NonNull Material icon) { | ||
super(pluginName, icon); | ||
} | ||
|
||
public abstract boolean spawnNpc(String yaml, Location pos) throws InvalidConfigurationException; | ||
|
||
public abstract Map<? extends Vector, ? extends List<BlueprintEntity>> getNpcsInArea(World world, | ||
List<Vector> vectorsToCopy, @Nullable Vector origin); | ||
|
||
/** | ||
* Remove all NPCs in chunk | ||
* @param chunk chunk | ||
*/ | ||
public abstract void removeNPCsInChunk(Chunk chunk); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/world/bentobox/bentobox/blueprints/DisplayListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package world.bentobox.bentobox.blueprints; | ||
|
||
import java.util.UUID; | ||
|
||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.Sound; | ||
import org.bukkit.World; | ||
import org.bukkit.entity.ArmorStand; | ||
import org.bukkit.entity.Display; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerInteractAtEntityEvent; | ||
import org.bukkit.persistence.PersistentDataType; | ||
|
||
import world.bentobox.bentobox.BentoBox; | ||
|
||
/** | ||
* Provides a listener for the Display Objects pasted when a hologram is interacted with | ||
* https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/player/PlayerInteractAtEntityEvent.html | ||
*/ | ||
public class DisplayListener implements Listener { | ||
|
||
@EventHandler | ||
public void onPlayerInteractEntity(PlayerInteractAtEntityEvent event) { | ||
if (event.getRightClicked() instanceof ArmorStand) { | ||
ArmorStand armorStand = (ArmorStand) event.getRightClicked(); | ||
NamespacedKey key = new NamespacedKey(BentoBox.getInstance(), "associatedDisplayEntity"); | ||
|
||
if (armorStand.getPersistentDataContainer().has(key, PersistentDataType.STRING)) { | ||
String displayEntityUUID = armorStand.getPersistentDataContainer().get(key, PersistentDataType.STRING); | ||
|
||
// Fetch the associated DisplayEntity by UUID | ||
World world = armorStand.getWorld(); | ||
world.getEntitiesByClass(Display.class).stream() | ||
.filter(e -> e.getUniqueId().equals(UUID.fromString(displayEntityUUID))).findFirst() | ||
.ifPresent(e -> { | ||
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.BLOCK_GLASS_BREAK, 1F, | ||
1F); | ||
e.remove(); | ||
|
||
}); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.