MCPcopy Create free account
hub / github.com/boxbeam/RedLib / wrap

Method wrap

src/redempt/redlib/misc/PlayerWrapper.java:18–25  ·  view source on GitHub ↗

Wraps a player using a Proxy, disabling some methods from being called. Very hacky, do not use if it can be avoided. Meant for when you want to send a fake event to test if it will be cancelled, but don't want the plugins to be able to do certain things with the player based on the event. @param pl

(Player player, String... disable)

Source from the content-addressed store, hash-verified

16 * @return The wrapped player
17 */
18 public static Player wrap(Player player, String... disable) {
19 return (Player) Proxy.newProxyInstance(player.getClass().getClassLoader(), new Class<?>[]{Player.class}, (proxy, method, args) -> {
20 if (Arrays.stream(disable).anyMatch(s -> s.equals(method.getName()))) {
21 return null;
22 }
23 return method.invoke(player, args);
24 });
25 }
26
27}

Callers

nothing calls this directly

Calls 5

getClassMethod · 0.80
invokeMethod · 0.80
streamMethod · 0.45
equalsMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected