|
1 | 1 | # MapReflectionAPI |
2 | 2 |
|
3 | | -This plugin helps developer with displaying images on maps. It supports Spigot 1.12 - 1.21. |
4 | | - |
5 | | -## Usage: |
6 | | - |
7 | | -### Using the API: |
8 | | - |
9 | | -First, include the API using Maven: |
10 | | - |
11 | | -```xml |
12 | | -<repository> |
13 | | - <id>sbdevelopment-repo-releases</id> |
14 | | - <name>SBDevelopment Repository</name> |
15 | | - <url>https://repo.sbdevelopment.tech/releases</url> |
16 | | -</repository> |
17 | | - |
18 | | -<dependency> |
19 | | - <groupId>tech.sbdevelopment</groupId> |
20 | | - <artifactId>MapReflectionAPI</artifactId> |
21 | | - <version>1.6.4</version> |
22 | | - <scope>provided</scope> |
23 | | -</dependency> |
24 | | -``` |
25 | | - |
26 | | -Then, use our API. Below is an example. |
27 | | - |
28 | | -```java |
29 | | -//--- Wrap image --- |
30 | | -MapWrapper wrapper = MapReflectionAPI.getMapManager().wrapImage(ImageIO.read(new File("image.png"))); |
31 | | -MapController controller = wrapper.getController(); |
32 | | - |
33 | | -final Player p = Bukkit.getPlayer("SBDeveloper"); |
34 | | - |
35 | | -//--- Add viewer --- |
36 | | -try { |
37 | | - controller.addViewer(p); |
38 | | -} catch (MapLimitExceededException e) { |
39 | | - e.printStackTrace(); |
40 | | - return; |
41 | | -} |
42 | | -controller.sendContent(p); |
43 | | - |
44 | | -//--- Show in frame --- |
45 | | -ItemFrame frame = ...; //This is your ItemFrame. |
46 | | -controller.showInFrame(p, frame, true); |
47 | | - |
48 | | -//--- Or show in hand --- |
49 | | -controller.showInHand(p, true); |
50 | | -``` |
51 | | - |
52 | | -It's also possible to split one image onto multiple itemframes. For example using the following code. |
53 | | - |
54 | | -```java |
55 | | -//--- Wrap image (into 2 rows and 2 columns) --- |
56 | | -MultiMapWrapper wrapper = MapReflectionAPI.getMapManager().wrapMultiImage(ImageIO.read(new File("image.png")), 2, 2); |
57 | | -MultiMapController controller = wrapper.getController(); |
58 | | - |
59 | | -final Player p = Bukkit.getPlayer("SBDeveloper"); |
60 | | - |
61 | | -//--- Add viewer --- |
62 | | -try { |
63 | | - controller.addViewer(p); |
64 | | -} catch (MapLimitExceededException e) { |
65 | | - e.printStackTrace(); |
66 | | - return; |
67 | | -} |
68 | | -controller.sendContent(p); |
69 | | - |
70 | | -//--- Show in frames --- |
71 | | -//These are your itemframes |
72 | | -ItemFrame leftTopFrame = ...; |
73 | | -ItemFrame leftBottomFrame = ...; |
74 | | -ItemFrame rightTopFrame = ...; |
75 | | -ItemFrame rightBottomFrame = ...; |
76 | | -ItemFrame[][] frames = { |
77 | | - {leftTopFrame, rightTopFrame}, |
78 | | - {leftBottomFrame, rightBottomFrame} |
79 | | -}; |
80 | | -controller.showInFrames(p, frames, true); |
81 | | -``` |
82 | | - |
83 | | -More information can be found on the [JavaDoc](https://sbdevelopment.tech/javadoc/mapreflectionapi/). |
84 | | - |
85 | | -### Notes on map render distance: |
86 | | - |
87 | | -MapReflectionAPI does not implement render distance to images shown on maps. This should be implemented by yourself. An example of this is below. |
88 | | - |
89 | | -```java |
90 | | -import org.bukkit.event.EventHandler; |
91 | | -import org.bukkit.event.entity.PlayerDeathEvent; |
92 | | -import org.bukkit.event.player.PlayerChangedWorldEvent; |
93 | | -import org.bukkit.event.player.PlayerRespawnEvent; |
94 | | - |
95 | | -public class MapRenderDistanceListener implements Listener { |
96 | | - private static final int MAP_RENDER_DISTANCE_SQUARED = 1024; |
97 | | - |
98 | | - @EventHandler |
99 | | - public void onPlayerJoin(PlayerJoinEvent e) { |
100 | | - Bukkit.getScheduler().runTaskLaterAsynchronously(MyPluginInstance, () -> { |
101 | | - //Show the maps to the player which are within distance |
102 | | - }); |
103 | | - } |
104 | | - |
105 | | - @EventHandler |
106 | | - public void onPlayerLeave(PlayerQuitEvent e) { |
107 | | - Bukkit.getScheduler().runTaskLaterAsynchronously(MyPluginInstance, () -> { |
108 | | - //Hide the maps to the player which are within distance |
109 | | - }); |
110 | | - } |
111 | | - |
112 | | - @EventHandler |
113 | | - public void onPlayerChangeWorld(PlayerChangedWorldEvent e) { |
114 | | - //Hide all the maps in the e.getFrom() world |
115 | | - |
116 | | - Bukkit.getScheduler().runTaskLaterAsynchronously(MyPluginInstance, () -> { |
117 | | - //Show the maps to the player which are within distance in e.getPlayer().getWorld() |
118 | | - }, 20); |
119 | | - } |
120 | | - |
121 | | - @EventHandler(priority = EventPriority.MONITOR) |
122 | | - public void onPlayerDeath(PlayerDeathEvent e) { |
123 | | - //Hide all the maps in the e.getEntity().getWorld() |
124 | | - } |
125 | | - |
126 | | - @EventHandler(priority = EventPriority.MONITOR) |
127 | | - public void onPlayerRespawn(PlayerRespawnEvent e) { |
128 | | - Bukkit.getScheduler().runTaskLaterAsynchronously(MyPluginInstance, () -> { |
129 | | - //Show the maps to the player which are within distance in e.getPlayer().getWorld() |
130 | | - }, 20); |
131 | | - } |
132 | | - |
133 | | - @EventHandler |
134 | | - public void onPlayerMove(PlayerMoveEvent e) { |
135 | | - //Hide all the maps in the e.getFrom() world |
136 | | - //Show the maps to the player which are within distance in e.getTo().getWorld() |
137 | | - |
138 | | - //FOR EXAMPLE: |
139 | | - if (e.getTo() == null) return; |
140 | | - if (e.getFrom().getChunk().equals(e.getTo().getChunk())) return; |
141 | | - |
142 | | - for (Frame frame : API.getFramesInWorld(e.getPlayer().getWorld())) { |
143 | | - double distanceSquared = e.getTo().distanceSquared(frame.getLocation()); |
144 | | - |
145 | | - if (distanceSquared > MAP_RENDER_DISTANCE_SQUARED) { |
146 | | - API.hideFrame(e.getPlayer(), frame); |
147 | | - } else { |
148 | | - API.showFrame(e.getPlayer(), frame); |
149 | | - } |
150 | | - } |
151 | | - } |
152 | | - |
153 | | - @EventHandler |
154 | | - public void onPlayerTeleport(PlayerTeleportEvent e) { |
155 | | - //Hide all the maps in the e.getFrom() world |
156 | | - //Show the maps to the player which are within distance in e.getTo().getWorld() |
157 | | - |
158 | | - //SEE EXAMPLE ABOVE |
159 | | - } |
160 | | -} |
161 | | -``` |
162 | | - |
163 | | -## Credits: |
164 | | - |
165 | | -This is a fork of [MapManager](https://github.com/InventivetalentDev/MapManager). It updates the API to the latest version of Minecraft and uses other dependencies. |
166 | | - |
167 | | -This plugin includes classes from BKCommonLib. Please checkout the README in that package for more information. |
| 3 | +This repository has been migrated to: https://git.sbdevelopment.tech/SBDevelopment/MapReflectionAPI |
0 commit comments