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)
| 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 | } |