Skip to content

Commit 7ab03ee

Browse files
committed
Implement NMS#createNativeProxyCommandSenderin the test toolkit
Since this doesn't have to worry about NMS compatibility, MockNativeProxyCommandSender is basically the same as the old implementation of NativeProxyCommandSender :P
1 parent 275479b commit 7ab03ee

File tree

2 files changed

+171
-0
lines changed

2 files changed

+171
-0
lines changed

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIBukkit.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ public MockCommandSource getBrigadierSourceFromCommandSender(AbstractCommandSend
130130
return new MockCommandSource(sender.getSource());
131131
}
132132

133+
@Override
134+
public NativeProxyCommandSender createNativeProxyCommandSender(CommandSender caller, CommandSender callee, Location location, World world) {
135+
return new MockNativeProxyCommandSender(caller, callee, location, world);
136+
}
137+
133138
// Miscellaneous methods
134139
/**
135140
* A global toggle for whether the default logger returned by {@link #getLogger()} should print messages to the
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
package dev.jorel.commandapi.wrappers;
2+
3+
import net.kyori.adventure.text.Component;
4+
import org.bukkit.Location;
5+
import org.bukkit.Server;
6+
import org.bukkit.World;
7+
import org.bukkit.command.CommandSender;
8+
import org.bukkit.permissions.Permission;
9+
import org.bukkit.permissions.PermissionAttachment;
10+
import org.bukkit.permissions.PermissionAttachmentInfo;
11+
import org.bukkit.plugin.Plugin;
12+
import org.jetbrains.annotations.NotNull;
13+
import org.jetbrains.annotations.Nullable;
14+
15+
import java.util.Set;
16+
import java.util.UUID;
17+
18+
public class MockNativeProxyCommandSender implements NativeProxyCommandSender {
19+
20+
private final CommandSender caller;
21+
private final CommandSender callee;
22+
private final Location location;
23+
private final World world;
24+
25+
/**
26+
* Constructs a NativeProxyCommandSender, which is basically Minecraft's CommandListenerWrapper
27+
* @param caller the command sender that actually sent the command
28+
* @param callee the command sender that will be executing the command
29+
* @param location the proxied location that the command will be run at
30+
* @param world the proxied world that the command will be run in
31+
*/
32+
public MockNativeProxyCommandSender(CommandSender caller, CommandSender callee, Location location, World world) {
33+
this.caller = caller;
34+
this.callee = callee == null ? caller : callee;
35+
this.location = location;
36+
this.world = world;
37+
}
38+
39+
// NativeProxyCommandSenderMethods
40+
@Override
41+
public Location getLocation() {
42+
return this.location;
43+
}
44+
45+
@Override
46+
public World getWorld() {
47+
return this.world;
48+
}
49+
50+
// ProxiedCommandSender methods
51+
@Override
52+
public @NotNull CommandSender getCaller() {
53+
return this.caller;
54+
}
55+
56+
@Override
57+
public @NotNull CommandSender getCallee() {
58+
return this.callee;
59+
}
60+
61+
// CommandSender methods
62+
@Override
63+
public void sendMessage(@NotNull String s) {
64+
this.caller.sendMessage(s);
65+
}
66+
67+
@Override
68+
public void sendMessage(@NotNull String... strings) {
69+
this.caller.sendMessage(strings);
70+
}
71+
72+
@Override
73+
public void sendMessage(@Nullable UUID uuid, @NotNull String s) {
74+
this.caller.sendMessage(uuid, s);
75+
}
76+
77+
@Override
78+
public void sendMessage(@Nullable UUID uuid, @NotNull String... strings) {
79+
this.caller.sendMessage(uuid, strings);
80+
}
81+
82+
@Override
83+
public @NotNull Server getServer() {
84+
return this.callee.getServer();
85+
}
86+
87+
@Override
88+
public @NotNull String getName() {
89+
return this.callee.getName();
90+
}
91+
92+
@Override
93+
public @NotNull Spigot spigot() {
94+
return this.caller.spigot();
95+
}
96+
97+
@Override
98+
public @NotNull Component name() {
99+
return this.callee.name();
100+
}
101+
102+
@Override
103+
public boolean isPermissionSet(@NotNull String s) {
104+
return this.caller.isPermissionSet(s);
105+
}
106+
107+
@Override
108+
public boolean isPermissionSet(@NotNull Permission permission) {
109+
return this.caller.isPermissionSet(permission);
110+
}
111+
112+
@Override
113+
public boolean hasPermission(@NotNull String s) {
114+
return this.caller.hasPermission(s);
115+
}
116+
117+
@Override
118+
public boolean hasPermission(@NotNull Permission permission) {
119+
return this.caller.hasPermission(permission);
120+
}
121+
122+
@Override
123+
public @NotNull PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String s, boolean b) {
124+
return this.caller.addAttachment(plugin, s, b);
125+
}
126+
127+
@Override
128+
public @NotNull PermissionAttachment addAttachment(@NotNull Plugin plugin) {
129+
return this.caller.addAttachment(plugin);
130+
}
131+
132+
@Override
133+
public @Nullable PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String s, boolean b, int i) {
134+
return this.caller.addAttachment(plugin, s, b, i);
135+
}
136+
137+
@Override
138+
public @Nullable PermissionAttachment addAttachment(@NotNull Plugin plugin, int i) {
139+
return this.caller.addAttachment(plugin, i);
140+
}
141+
142+
@Override
143+
public void removeAttachment(@NotNull PermissionAttachment permissionAttachment) {
144+
this.caller.removeAttachment(permissionAttachment);
145+
}
146+
147+
@Override
148+
public void recalculatePermissions() {
149+
this.caller.recalculatePermissions();
150+
}
151+
152+
@Override
153+
public @NotNull Set<PermissionAttachmentInfo> getEffectivePermissions() {
154+
return this.caller.getEffectivePermissions();
155+
}
156+
157+
@Override
158+
public boolean isOp() {
159+
return this.caller.isOp();
160+
}
161+
162+
@Override
163+
public void setOp(boolean b) {
164+
this.caller.setOp(b);
165+
}
166+
}

0 commit comments

Comments
 (0)