Skip to content

Commit 4a10caa

Browse files
committed
Make NativeProxyCommandSender extend CraftBukkit class ProxiedNativeCommandSender so VanillaCommandWrapper can handle it
Fixes CommandAPI#477
1 parent c53e451 commit 4a10caa

File tree

27 files changed

+485
-381
lines changed

27 files changed

+485
-381
lines changed

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/NativeProxyCommandSender.java

Lines changed: 3 additions & 300 deletions
Original file line numberDiff line numberDiff line change
@@ -20,321 +20,24 @@
2020
*******************************************************************************/
2121
package dev.jorel.commandapi.wrappers;
2222

23-
import java.util.Set;
24-
import java.util.UUID;
25-
2623
import org.bukkit.Location;
27-
import org.bukkit.Server;
2824
import org.bukkit.World;
29-
import org.bukkit.command.CommandSender;
3025
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;
3826

3927
/**
4028
* A simple representation of Minecraft's CommandListenerWrapper, in the form of
4129
* Bukkit's ProxiedCommandSender
4230
*/
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 {
15432
/**
15533
* Returns the location that this native command sender represents
15634
* @return the location that this native command sender represents
15735
*/
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();
18137

18238
/**
18339
* Returns the world that this native command sender represents
18440
* @return the world that this native command sender represents
18541
*/
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();
34043
}

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.16.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_16_R3.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -836,18 +836,14 @@ public BukkitCommandSender<? extends CommandSender> getSenderForCommand(CommandC
836836
// however this may also be null, so delegate to the next most-meaningful sender.
837837
sender = Bukkit.getConsoleSender();
838838
}
839-
Vec3D pos = clw.getPosition();
840-
Vec2F rot = clw.i();
841-
World world = getWorldForCSS(clw);
842-
Location location = new Location(world, pos.getX(), pos.getY(), pos.getZ(), rot.j, rot.i);
843839

844840
Entity proxyEntity = clw.getEntity();
845841
CommandSender proxy = proxyEntity == null ? null : proxyEntity.getBukkitEntity();
846842
if (isNative || (proxy != null && !sender.equals(proxy))) {
847843
if (proxy == null) {
848844
proxy = sender;
849845
}
850-
return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world));
846+
return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender_1_16_R3(clw, sender, proxy));
851847
} else {
852848
return wrapCommandSender(sender);
853849
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package dev.jorel.commandapi.nms;
2+
3+
import dev.jorel.commandapi.CommandAPIBukkit;
4+
import dev.jorel.commandapi.wrappers.NativeProxyCommandSender;
5+
import net.minecraft.server.v1_16_R3.CommandListenerWrapper;
6+
import net.minecraft.server.v1_16_R3.Vec2F;
7+
import net.minecraft.server.v1_16_R3.Vec3D;
8+
import org.bukkit.Location;
9+
import org.bukkit.World;
10+
import org.bukkit.command.CommandSender;
11+
import org.bukkit.craftbukkit.v1_16_R3.command.ProxiedNativeCommandSender;
12+
13+
public class NativeProxyCommandSender_1_16_R3 extends ProxiedNativeCommandSender implements NativeProxyCommandSender {
14+
private final World world;
15+
private final Location location;
16+
17+
public NativeProxyCommandSender_1_16_R3(CommandListenerWrapper clw, CommandSender caller, CommandSender callee) {
18+
super(clw, caller, callee);
19+
20+
Vec3D pos = clw.getPosition();
21+
Vec2F rot = clw.i();
22+
this.world = CommandAPIBukkit.get().getWorldForCSS(clw);
23+
this.location = new Location(this.world, pos.getX(), pos.getY(), pos.getZ(), rot.j, rot.i);
24+
}
25+
26+
@Override
27+
public Location getLocation() {
28+
return location;
29+
}
30+
31+
@Override
32+
public World getWorld() {
33+
return world;
34+
}
35+
}

0 commit comments

Comments
 (0)