|
20 | 20 | *******************************************************************************/ |
21 | 21 | package dev.jorel.commandapi.wrappers; |
22 | 22 |
|
23 | | -import java.util.Set; |
24 | | -import java.util.UUID; |
25 | | - |
26 | 23 | import org.bukkit.Location; |
27 | | -import org.bukkit.Server; |
28 | 24 | import org.bukkit.World; |
29 | | -import org.bukkit.command.CommandSender; |
30 | 25 | import org.bukkit.command.ProxiedCommandSender; |
31 | | -import org.bukkit.permissions.Permission; |
32 | | -import org.bukkit.permissions.PermissionAttachment; |
33 | | -import org.bukkit.permissions.PermissionAttachmentInfo; |
34 | | -import org.bukkit.plugin.Plugin; |
35 | | -import org.jetbrains.annotations.NotNull; |
36 | | - |
37 | | -import net.kyori.adventure.text.Component; |
38 | 26 |
|
39 | 27 | /** |
40 | 28 | * A simple representation of Minecraft's CommandListenerWrapper, in the form of |
41 | 29 | * Bukkit's ProxiedCommandSender |
42 | 30 | */ |
43 | | -public class NativeProxyCommandSender implements ProxiedCommandSender { |
44 | | - |
45 | | - private final CommandSender caller; |
46 | | - private final CommandSender callee; |
47 | | - private final Location location; |
48 | | - private final World world; |
49 | | - |
50 | | - /** |
51 | | - * Constructs a NativeProxyCommandSender, which is basically Minecraft's CommandListenerWrapper |
52 | | - * @param caller the command sender that actually sent the command |
53 | | - * @param callee the command sender that will be executing the command |
54 | | - * @param location the proxied location that the command will be run at |
55 | | - * @param world the proxied world that the command will be run in |
56 | | - */ |
57 | | - public NativeProxyCommandSender(CommandSender caller, CommandSender callee, Location location, World world) { |
58 | | - this.caller = caller; |
59 | | - this.callee = callee == null ? caller : callee; |
60 | | - this.location = location; |
61 | | - this.world = world; |
62 | | - } |
63 | | - |
64 | | - /** |
65 | | - * Adds a new empty PermissionAttachment to this object |
66 | | - * |
67 | | - * @param plugin Plugin responsible for this attachment, may not be null |
68 | | - * or disabled |
69 | | - * @return The PermissionAttachment that was just created |
70 | | - */ |
71 | | - @Override |
72 | | - public PermissionAttachment addAttachment(Plugin plugin) { |
73 | | - return this.caller.addAttachment(plugin); |
74 | | - } |
75 | | - |
76 | | - /** |
77 | | - * Temporarily adds a new empty PermissionAttachment to this |
78 | | - * object |
79 | | - * |
80 | | - * @param plugin Plugin responsible for this attachment, may not be null |
81 | | - * or disabled |
82 | | - * @param ticks Amount of ticks to automatically remove this attachment |
83 | | - * after |
84 | | - * @return The PermissionAttachment that was just created |
85 | | - */ |
86 | | - @Override |
87 | | - public PermissionAttachment addAttachment(Plugin plugin, int ticks) { |
88 | | - return this.caller.addAttachment(plugin, ticks); |
89 | | - } |
90 | | - |
91 | | - /** |
92 | | - * Adds a new PermissionAttachment with a single permission by |
93 | | - * name and value |
94 | | - * |
95 | | - * @param plugin Plugin responsible for this attachment, may not be null |
96 | | - * or disabled |
97 | | - * @param name Name of the permission to attach |
98 | | - * @param value Value of the permission |
99 | | - * @return The PermissionAttachment that was just created |
100 | | - */ |
101 | | - @Override |
102 | | - public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) { |
103 | | - return this.caller.addAttachment(plugin, name, value); |
104 | | - } |
105 | | - |
106 | | - /** |
107 | | - * Temporarily adds a new PermissionAttachment with a single |
108 | | - * permission by name and value |
109 | | - * |
110 | | - * @param plugin Plugin responsible for this attachment, may not be null |
111 | | - * or disabled |
112 | | - * @param name Name of the permission to attach |
113 | | - * @param value Value of the permission |
114 | | - * @param ticks Amount of ticks to automatically remove this attachment |
115 | | - * after |
116 | | - * @return The PermissionAttachment that was just created |
117 | | - */ |
118 | | - @Override |
119 | | - public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) { |
120 | | - return this.caller.addAttachment(plugin, name, value, ticks); |
121 | | - } |
122 | | - |
123 | | - /** |
124 | | - * Returns the CommandSender which is being used to call the command |
125 | | - * |
126 | | - * @return the caller which the command is being run as |
127 | | - */ |
128 | | - @Override |
129 | | - public CommandSender getCallee() { |
130 | | - return this.callee; |
131 | | - } |
132 | | - |
133 | | - /** |
134 | | - * Returns the CommandSender which triggered this proxied command |
135 | | - * |
136 | | - * @return the caller which triggered the command |
137 | | - */ |
138 | | - @Override |
139 | | - public CommandSender getCaller() { |
140 | | - return this.caller; |
141 | | - } |
142 | | - |
143 | | - /** |
144 | | - * Gets a set containing all of the permissions currently in effect by |
145 | | - * this object |
146 | | - * |
147 | | - * @return Set of currently effective permissions |
148 | | - */ |
149 | | - @Override |
150 | | - public Set<PermissionAttachmentInfo> getEffectivePermissions() { |
151 | | - return this.caller.getEffectivePermissions(); |
152 | | - } |
153 | | - |
| 31 | +public interface NativeProxyCommandSender extends ProxiedCommandSender { |
154 | 32 | /** |
155 | 33 | * Returns the location that this native command sender represents |
156 | 34 | * @return the location that this native command sender represents |
157 | 35 | */ |
158 | | - public Location getLocation() { |
159 | | - return this.location; |
160 | | - } |
161 | | - |
162 | | - /** |
163 | | - * Gets the name of this command sender |
164 | | - * |
165 | | - * @return Name of the sender |
166 | | - */ |
167 | | - @Override |
168 | | - public String getName() { |
169 | | - return this.callee.getName(); |
170 | | - } |
171 | | - |
172 | | - /** |
173 | | - * Returns the server instance that this command is running on |
174 | | - * |
175 | | - * @return Server instance |
176 | | - */ |
177 | | - @Override |
178 | | - public Server getServer() { |
179 | | - return this.callee.getServer(); |
180 | | - } |
| 36 | + Location getLocation(); |
181 | 37 |
|
182 | 38 | /** |
183 | 39 | * Returns the world that this native command sender represents |
184 | 40 | * @return the world that this native command sender represents |
185 | 41 | */ |
186 | | - public World getWorld() { |
187 | | - return this.world; |
188 | | - } |
189 | | - |
190 | | - /** |
191 | | - * Gets the value of the specified permission, if set. |
192 | | - * <p> |
193 | | - * If a permission override is not set on this object, the default value |
194 | | - * of the permission will be returned |
195 | | - * |
196 | | - * @param perm Permission to get |
197 | | - * @return Value of the permission |
198 | | - */ |
199 | | - @Override |
200 | | - public boolean hasPermission(Permission perm) { |
201 | | - return this.caller.hasPermission(perm); |
202 | | - } |
203 | | - |
204 | | - /** |
205 | | - * Gets the value of the specified permission, if set. |
206 | | - * <p> |
207 | | - * If a permission override is not set on this object, the default value |
208 | | - * of the permission will be returned. |
209 | | - * |
210 | | - * @param name Name of the permission |
211 | | - * @return Value of the permission |
212 | | - */ |
213 | | - @Override |
214 | | - public boolean hasPermission(String name) { |
215 | | - return this.caller.hasPermission(name); |
216 | | - } |
217 | | - |
218 | | - /** |
219 | | - * Checks if this object is a server operator |
220 | | - * |
221 | | - * @return true if this is an operator, otherwise false |
222 | | - */ |
223 | | - @Override |
224 | | - public boolean isOp() { |
225 | | - return this.caller.isOp(); |
226 | | - } |
227 | | - |
228 | | - /** |
229 | | - * Checks if this object contains an override for the specified Permission |
230 | | - * |
231 | | - * @param perm Permission to check |
232 | | - * @return true if the permission is set, otherwise false |
233 | | - */ |
234 | | - @Override |
235 | | - public boolean isPermissionSet(Permission perm) { |
236 | | - return this.caller.isPermissionSet(perm); |
237 | | - } |
238 | | - |
239 | | - /** |
240 | | - * Checks if this object contains an override for the specified |
241 | | - * permission, by fully qualified name |
242 | | - * |
243 | | - * @param name Name of the permission |
244 | | - * @return true if the permission is set, otherwise false |
245 | | - */ |
246 | | - @Override |
247 | | - public boolean isPermissionSet(String name) { |
248 | | - return this.caller.isPermissionSet(name); |
249 | | - } |
250 | | - |
251 | | - /** |
252 | | - * Recalculates the permissions for this object, if the attachments have |
253 | | - * changed values. |
254 | | - * <p> |
255 | | - * This should very rarely need to be called from a plugin. |
256 | | - */ |
257 | | - @Override |
258 | | - public void recalculatePermissions() { |
259 | | - this.caller.recalculatePermissions(); |
260 | | - } |
261 | | - |
262 | | - /** |
263 | | - * Removes the given PermissionAttachment from this object |
264 | | - * |
265 | | - * @param attachment Attachment to remove |
266 | | - * @throws IllegalArgumentException Thrown when the specified attachment |
267 | | - * isn't part of this object |
268 | | - */ |
269 | | - @Override |
270 | | - public void removeAttachment(PermissionAttachment attachment) { |
271 | | - this.caller.removeAttachment(attachment); |
272 | | - } |
273 | | - |
274 | | - /** |
275 | | - * Sends this sender a message |
276 | | - * |
277 | | - * @param message Message to be displayed |
278 | | - */ |
279 | | - @Override |
280 | | - public void sendMessage(String message) { |
281 | | - this.caller.sendMessage(message); |
282 | | - } |
283 | | - |
284 | | - /** |
285 | | - * Sends this sender multiple messages |
286 | | - * |
287 | | - * @param messages An array of messages to be displayed |
288 | | - */ |
289 | | - @Override |
290 | | - public void sendMessage(String... messages) { |
291 | | - this.caller.sendMessage(messages); |
292 | | - } |
293 | | - |
294 | | - /** |
295 | | - * Sends this sender a message |
296 | | - * |
297 | | - * @param message Message to be displayed |
298 | | - * @param sender The sender of this message |
299 | | - */ |
300 | | - @Override |
301 | | - public void sendMessage(UUID sender, String message) { |
302 | | - this.caller.sendMessage(sender, message); |
303 | | - } |
304 | | - |
305 | | - /** |
306 | | - * Sends this sender multiple messages |
307 | | - * |
308 | | - * @param messages An array of messages to be displayed |
309 | | - * @param sender The sender of this message |
310 | | - */ |
311 | | - @Override |
312 | | - public void sendMessage(UUID sender, String... messages) { |
313 | | - this.caller.sendMessage(sender, messages); |
314 | | - } |
315 | | - |
316 | | - /** |
317 | | - * Sets the operator status of this object |
318 | | - * |
319 | | - * @param value New operator value |
320 | | - */ |
321 | | - @Override |
322 | | - public void setOp(boolean value) { |
323 | | - this.caller.setOp(value); |
324 | | - } |
325 | | - |
326 | | - /** |
327 | | - * Returns a Spigot instance of this object |
328 | | - * @return a Spigot instance of this object |
329 | | - */ |
330 | | - @Override |
331 | | - public Spigot spigot() { |
332 | | - return this.caller.spigot(); |
333 | | - } |
334 | | - |
335 | | - @Override |
336 | | - public @NotNull Component name() { |
337 | | - return this.caller.name(); |
338 | | - } |
339 | | - |
| 42 | + World getWorld(); |
340 | 43 | } |
0 commit comments