I have created a class that is a custom command sender You can use this to use NMS commands in your own plugins Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide Spoiler Code:java import net.minecraft.server.v1_13_R2.*;import org.bukkit.command.CommandSender;import org.bukkit.craftbukkit.v1_13_R2.CraftServer;import org.bukkit.craftbukkit.v1_13_R2.CraftWorld;import org.bukkit.craftbukkit.v1_13_R2.entity.CraftMinecartCommand;import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;import org.bukkit.entity.Player; import javax.annotation.Nullable; public class CustomCommandSender extends CraftMinecartCommand { private Player player; public CustomCommandSender(Player player) { super((CraftServer) (player).getServer(), new CustomMinecart(((CraftWorld) player.getWorld()).getHandle())); this.player = player; ((CustomMinecart) this.getHandle()).setCustomCommandListenerWrapper((CustomCommandListenerWrapper) getCommandListenerWrapper()); } private CommandListenerWrapper getCommandListenerWrapper() { EntityPlayer p = ((CraftPlayer) player).getHandle(); return new CustomCommandListenerWrapper(new CustomCommandListener(p, this), p.bI(), p.aO(), p.getWorldServer(), 0, "", null, p.server, null); } @Override public void sendMessage(String message) { System.out.println("Bukkit command: " + message); } private static class CustomCommandListener implements ICommandListener { EntityPlayer player; CustomCommandSender customCommandSender; public CustomCommandListener(EntityPlayer player, CustomCommandSender customCommandSender) { this.player = player; this.customCommandSender = customCommandSender; } @Override public void sendMessage(IChatBaseComponent iChatBaseComponent) { } @Override public boolean a() { return player.a(); } @Override public boolean b() { return player.b(); } @Override public boolean B_() { return player.B_(); } @Override public CommandSender getBukkitSender(CommandListenerWrapper commandListenerWrapper) { return customCommandSender; } } private static class CustomMinecart extends EntityMinecartCommandBlock { private CustomCommandListenerWrapper customCommandListenerWrapper; private CustomCommandBlock customCommandBlock; public CustomMinecart(net.minecraft.server.v1_13_R2.World world) { super(world); } @Override public CommandListenerWrapper getCommandListener() { return customCommandListenerWrapper; } public void setCustomCommandListenerWrapper(CustomCommandListenerWrapper customCommandListenerWrapper) { this.customCommandListenerWrapper = customCommandListenerWrapper; this.customCommandBlock = new CustomCommandBlock(customCommandListenerWrapper); } @Override public CommandBlockListenerAbstract getCommandBlock() { return customCommandBlock; } } private static class CustomCommandBlock extends CommandBlockListenerAbstract { CustomCommandListenerWrapper customCommandListenerWrapper; public CustomCommandBlock(CustomCommandListenerWrapper customCommandListenerWrapper) { this.customCommandListenerWrapper = customCommandListenerWrapper; } @Override public CommandSender getBukkitSender(CommandListenerWrapper commandListenerWrapper) { return null; } @Override public WorldServer d() { return null; } @Override public void e() { } @Override public CommandListenerWrapper getWrapper() { return customCommandListenerWrapper; } } private class CustomCommandListenerWrapper extends CommandListenerWrapper { public CustomCommandListenerWrapper(ICommandListener icommandlistener, Vec3D vec3d, Vec2F vec2f, WorldServer worldserver, int i, String s, IChatBaseComponent ichatbasecomponent, MinecraftServer minecraftserver, @Nullable Entity entity) { super(icommandlistener, vec3d, vec2f, worldserver, i, s, ichatbasecomponent, minecraftserver, entity); } @Override public void sendFailureMessage(IChatBaseComponent ichatbasecomponent) { System.out.println("failed vanilla command: " + ichatbasecomponent.getString()); } @Override public void sendMessage(IChatBaseComponent ichatbasecomponent, boolean flag) { System.out.println("vanilla command: " + ichatbasecomponent.getString()); } }} usage: Code:java Bukkit.dispatchCommand(new CustomCommandSender(player), "locate Monument");
@The_Spaceman Why the System.out.println and not using a logger? But what does it do? What does it differently from using a Player as CommandSender ?
System.out.println is shorter in Intellij to type (type 'sout' and that will appear...) when using a player as CommandSender the player will recieve all the messages, but when you want to get the location of a Monument (for example) you can't use Bukkit.findMonument or someting. so you use this... and use the IChatBaseComponent to extract the location of the nearest Monument. This is for getting the return values of commands (for Minecraft commands of Bukkit commands)
@The_Spaceman How about a custom log function? And maybe an interface so you can get the values out of the commands being used.
That is possible, but I'm not going to make that, because it all depends on what command is used. and it would be a hell to make this possible for all commands in the whole Bukkit comunity...
A log function would just replace all instances of System.out.println, that way the user can catch it with their plugin and use the information.
I might be able to create a static method where you can give a runnable with your code in, if that is what you ment...
I was thinking replacing the System.out.println, but this only works 1 time, because I have no idea of how to returning the values of the sendMessage methods this is it...
There are many ways to pass this along. Runnable is a way, don't see why you need a runnable though as it is sync already.
Bukkit.dispatchCommand(new CustomCommandSender(player), "locate Monument"); so I have this for example, where does the String of the sendMessage come from? how do I get this? maybe I can create a method that return a ID, and with that ID I can save the String from the sendMessage in a HashMap, and the user can with the ID get the String from that map...
@The_Spaceman If you have an interface that accepts the message from sendMessage then the user can handle it however they want. Not to forget that it is a synchronized action.