From 8206cb403b1f478ea3ecef0da4c8b6bea61be831 Mon Sep 17 00:00:00 2001 From: Stijn Bannink Date: Sat, 9 Dec 2023 20:19:49 +0100 Subject: [PATCH] Added render distance info to README --- .idea/misc.xml | 2 ++ README.md | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/.idea/misc.xml b/.idea/misc.xml index 4a803e8..863f295 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,3 +1,4 @@ + @@ -28,6 +29,7 @@ + diff --git a/README.md b/README.md index af968b9..98f254a 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ This plugin helps developer with displaying images on maps. It supports Spigot 1 ## Usage: +### Using the API: + First, include the API using Maven: ```xml @@ -80,6 +82,84 @@ controller.showInFrames(p, frames, true); More information can be found on the [JavaDoc](https://sbdevelopment.tech/javadoc/mapreflectionapi/). +### Notes on map render distance: + +MapReflectionAPI does not implement render distance to images shown on maps. This should be implemented by yourself. An example of this is below. + +```java +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerChangedWorldEvent; +import org.bukkit.event.player.PlayerRespawnEvent; + +public class MapRenderDistanceListener implements Listener { + private static final int MAP_RENDER_DISTANCE_SQUARED = 1024; + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent e) { + Bukkit.getScheduler().runTaskLaterAsynchronously(MyPluginInstance, () -> { + //Show the maps to the player which are within distance + }); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent e) { + Bukkit.getScheduler().runTaskLaterAsynchronously(MyPluginInstance, () -> { + //Hide the maps to the player which are within distance + }); + } + + @EventHandler + public void onPlayerChangeWorld(PlayerChangedWorldEvent e) { + //Hide all the maps in the e.getFrom() world + + Bukkit.getScheduler().runTaskLaterAsynchronously(MyPluginInstance, () -> { + //Show the maps to the player which are within distance in e.getPlayer().getWorld() + }, 20); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerDeath(PlayerDeathEvent e) { + //Hide all the maps in the e.getEntity().getWorld() + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerRespawn(PlayerRespawnEvent e) { + Bukkit.getScheduler().runTaskLaterAsynchronously(MyPluginInstance, () -> { + //Show the maps to the player which are within distance in e.getPlayer().getWorld() + }, 20); + } + + @EventHandler + public void onPlayerMove(PlayerMoveEvent e) { + //Hide all the maps in the e.getFrom() world + //Show the maps to the player which are within distance in e.getTo().getWorld() + + //FOR EXAMPLE: + if (e.getTo() == null) return; + if (e.getFrom().getChunk().equals(e.getTo().getChunk())) return; + + for (Frame frame : API.getFramesInWorld(e.getPlayer().getWorld())) { + double distanceSquared = e.getTo().distanceSquared(frame.getLocation()); + + if (distanceSquared > MAP_RENDER_DISTANCE_SQUARED) { + API.hideFrame(e.getPlayer(), frame); + } else { + API.showFrame(e.getPlayer(), frame); + } + } + } + + @EventHandler + public void onPlayerTeleport(PlayerTeleportEvent e) { + //Hide all the maps in the e.getFrom() world + //Show the maps to the player which are within distance in e.getTo().getWorld() + + //SEE EXAMPLE ABOVE + } +} +``` + ## Credits: This is a fork of [MapManager](https://github.com/InventivetalentDev/MapManager). It updates the API to 1.19 and uses