|
1 | 1 | package com.fastasyncworldedit.bukkit.util.image; |
2 | 2 |
|
3 | | -import com.fastasyncworldedit.core.util.TaskManager; |
4 | 3 | import com.fastasyncworldedit.core.util.image.Drawable; |
5 | | -import com.fastasyncworldedit.core.util.image.ImageUtil; |
6 | 4 | import com.fastasyncworldedit.core.util.image.ImageViewer; |
7 | | -import org.bukkit.Bukkit; |
8 | | -import org.bukkit.Location; |
9 | | -import org.bukkit.Material; |
10 | | -import org.bukkit.Rotation; |
11 | | -import org.bukkit.World; |
12 | | -import org.bukkit.block.BlockFace; |
13 | | -import org.bukkit.entity.Entity; |
14 | 5 | import org.bukkit.entity.ItemFrame; |
15 | 6 | import org.bukkit.entity.Player; |
16 | | -import org.bukkit.inventory.ItemStack; |
17 | | -import org.bukkit.inventory.PlayerInventory; |
18 | | -import org.inventivetalent.mapmanager.MapManagerPlugin; |
19 | | -import org.inventivetalent.mapmanager.controller.MapController; |
20 | | -import org.inventivetalent.mapmanager.controller.MultiMapController; |
21 | | -import org.inventivetalent.mapmanager.manager.MapManager; |
22 | | -import org.inventivetalent.mapmanager.wrapper.MapWrapper; |
23 | 7 |
|
24 | | -import javax.annotation.Nullable; |
25 | | -import java.awt.RenderingHints; |
26 | | -import java.awt.image.BufferedImage; |
27 | 8 | import java.io.IOException; |
28 | | -import java.util.Collection; |
29 | 9 |
|
| 10 | +/** |
| 11 | + * @deprecated for removal with no replacement. Out of scope for FAWE. |
| 12 | + */ |
| 13 | +@Deprecated(forRemoval = true, since = "TODO") |
30 | 14 | public class BukkitImageViewer implements ImageViewer { |
31 | 15 |
|
32 | | - private final MapManager mapManager; |
33 | | - private final Player player; |
34 | | - private BufferedImage last; |
35 | | - private ItemFrame[][] frames; |
36 | | - private boolean reverse; |
37 | | - |
38 | 16 | public BukkitImageViewer(Player player) { |
39 | | - mapManager = ((MapManagerPlugin) Bukkit.getPluginManager().getPlugin("MapManager")).getMapManager(); |
40 | | - this.player = player; |
| 17 | + throw new UnsupportedOperationException("No longer supported."); |
41 | 18 | } |
42 | 19 |
|
43 | 20 | public void selectFrame(ItemFrame start) { |
44 | | - Location pos1 = start.getLocation().clone(); |
45 | | - Location pos2 = start.getLocation().clone(); |
46 | | - |
47 | | - BlockFace facing = start.getFacing(); |
48 | | - int planeX = facing.getModX() == 0 ? 1 : 0; |
49 | | - int planeY = facing.getModY() == 0 ? 1 : 0; |
50 | | - int planeZ = facing.getModZ() == 0 ? 1 : 0; |
51 | | - |
52 | | - ItemFrame[][] res = find(pos1, pos2, facing); |
53 | | - Location tmp; |
54 | | - while (true) { |
55 | | - if (res != null) { |
56 | | - frames = res; |
57 | | - } |
58 | | - tmp = pos1.clone().subtract(planeX, planeY, planeZ); |
59 | | - if ((res = find(tmp, pos2, facing)) != null) { |
60 | | - pos1 = tmp; |
61 | | - continue; |
62 | | - } |
63 | | - tmp = pos2.clone().add(planeX, planeY, planeZ); |
64 | | - if ((res = find(pos1, tmp, facing)) != null) { |
65 | | - pos2 = tmp; |
66 | | - continue; |
67 | | - } |
68 | | - tmp = pos1.clone().subtract(planeX, 0, planeZ); |
69 | | - if ((res = find(tmp, pos2, facing)) != null) { |
70 | | - pos1 = tmp; |
71 | | - continue; |
72 | | - } |
73 | | - tmp = pos2.clone().add(planeX, 0, planeZ); |
74 | | - if ((res = find(pos1, tmp, facing)) != null) { |
75 | | - pos2 = tmp; |
76 | | - continue; |
77 | | - } |
78 | | - tmp = pos1.clone().subtract(0, 1, 0); |
79 | | - if ((res = find(tmp, pos2, facing)) != null) { |
80 | | - pos1 = tmp; |
81 | | - continue; |
82 | | - } |
83 | | - tmp = pos2.clone().add(0, 1, 0); |
84 | | - if ((res = find(pos1, tmp, facing)) != null) { |
85 | | - pos2 = tmp; |
86 | | - continue; |
87 | | - } |
88 | | - break; |
89 | | - } |
| 21 | + throw new UnsupportedOperationException("No longer supported."); |
90 | 22 | } |
91 | 23 |
|
92 | 24 | public ItemFrame[][] getItemFrames() { |
93 | | - return frames; |
94 | | - } |
95 | | - |
96 | | - private ItemFrame[][] find(Location pos1, Location pos2, BlockFace facing) { |
97 | | - try { |
98 | | - Location distance = pos2.clone().subtract(pos1).add(1, 1, 1); |
99 | | - int width = Math.max(distance.getBlockX(), distance.getBlockZ()); |
100 | | - ItemFrame[][] frames = new ItemFrame[width][distance.getBlockY()]; |
101 | | - |
102 | | - World world = pos1.getWorld(); |
103 | | - |
104 | | - this.reverse = facing == BlockFace.NORTH || facing == BlockFace.EAST; |
105 | | - int v = 0; |
106 | | - for (double y = pos1.getY(); y <= pos2.getY(); y++, v++) { |
107 | | - int h = 0; |
108 | | - for (double z = pos1.getZ(); z <= pos2.getZ(); z++) { |
109 | | - for (double x = pos1.getX(); x <= pos2.getX(); x++, h++) { |
110 | | - Location pos = new Location(world, x, y, z); |
111 | | - Collection<Entity> entities = world.getNearbyEntities(pos, 0.1, 0.1, 0.1); |
112 | | - boolean contains = false; |
113 | | - for (Entity ent : entities) { |
114 | | - if (ent instanceof ItemFrame && ent.getFacing() == facing) { |
115 | | - ItemFrame itemFrame = (ItemFrame) ent; |
116 | | - itemFrame.setRotation(Rotation.NONE); |
117 | | - contains = true; |
118 | | - frames[reverse ? width - 1 - h : h][v] = (ItemFrame) ent; |
119 | | - break; |
120 | | - } |
121 | | - } |
122 | | - if (!contains) { |
123 | | - return null; |
124 | | - } |
125 | | - } |
126 | | - } |
127 | | - } |
128 | | - return frames; |
129 | | - } catch (Throwable e) { |
130 | | - e.printStackTrace(); |
131 | | - } |
132 | | - return null; |
| 25 | + throw new UnsupportedOperationException("No longer supported."); |
133 | 26 | } |
134 | 27 |
|
135 | 28 | @Override |
136 | 29 | public void view(Drawable drawable) { |
137 | | - view(null, drawable); |
138 | | - } |
139 | | - |
140 | | - private void view(@Nullable BufferedImage image, @Nullable Drawable drawable) { |
141 | | - if (image == null && drawable == null) { |
142 | | - throw new IllegalArgumentException("An image or drawable must be provided. Both cannot be null"); |
143 | | - } |
144 | | - boolean initializing = last == null; |
145 | | - |
146 | | - if (this.frames != null) { |
147 | | - if (image == null && drawable != null) { |
148 | | - image = drawable.draw(); |
149 | | - } |
150 | | - last = image; |
151 | | - int width = frames.length; |
152 | | - int height = frames[0].length; |
153 | | - BufferedImage scaled = ImageUtil.getScaledInstance( |
154 | | - image, |
155 | | - 128 * width, |
156 | | - 128 * height, |
157 | | - RenderingHints.VALUE_INTERPOLATION_BILINEAR, |
158 | | - false |
159 | | - ); |
160 | | - MapWrapper mapWrapper = mapManager.wrapMultiImage(scaled, width, height); |
161 | | - MultiMapController controller = (MultiMapController) mapWrapper.getController(); |
162 | | - controller.addViewer(player); |
163 | | - controller.sendContent(player); |
164 | | - controller.showInFrames(player, frames, true); |
165 | | - } else { |
166 | | - int slot = getMapSlot(player); |
167 | | - TaskManager.taskManager().sync(() -> { |
168 | | - if (slot == -1) { |
169 | | - if (initializing) { |
170 | | - player.getInventory().setItemInMainHand(new ItemStack(Material.MAP)); |
171 | | - } else { |
172 | | - return null; |
173 | | - } |
174 | | - } else if (player.getInventory().getHeldItemSlot() != slot) { |
175 | | - player.getInventory().setHeldItemSlot(slot); |
176 | | - } |
177 | | - return null; |
178 | | - }); |
179 | | - if (image == null && drawable != null) { |
180 | | - image = drawable.draw(); |
181 | | - } |
182 | | - last = image; |
183 | | - BufferedImage scaled = ImageUtil.getScaledInstance( |
184 | | - image, |
185 | | - 128, |
186 | | - 128, |
187 | | - RenderingHints.VALUE_INTERPOLATION_BILINEAR, |
188 | | - false |
189 | | - ); |
190 | | - MapWrapper mapWrapper = mapManager.wrapImage(scaled); |
191 | | - MapController controller = mapWrapper.getController(); |
192 | | - controller.addViewer(player); |
193 | | - controller.sendContent(player); |
194 | | - controller.showInHand(player, true); |
195 | | - } |
196 | | - } |
197 | | - |
198 | | - private int getMapSlot(Player player) { |
199 | | - PlayerInventory inventory = player.getInventory(); |
200 | | - for (int i = 0; i < 9; i++) { |
201 | | - ItemStack item = inventory.getItem(i); |
202 | | - if (item != null && item.getType() == Material.MAP) { |
203 | | - return i; |
204 | | - } |
205 | | - } |
206 | | - return -1; |
| 30 | + throw new UnsupportedOperationException("No longer supported."); |
207 | 31 | } |
208 | 32 |
|
209 | 33 | public void refresh() { |
210 | | - if (last != null) { |
211 | | - view(last, null); |
212 | | - } |
| 34 | + throw new UnsupportedOperationException("No longer supported."); |
213 | 35 | } |
214 | 36 |
|
215 | 37 | @Override |
216 | 38 | public void close() throws IOException { |
217 | | - last = null; |
| 39 | + throw new UnsupportedOperationException("No longer supported."); |
218 | 40 | } |
219 | 41 |
|
220 | 42 | } |
0 commit comments