Posted October 8, 20178 yr Hey! So I wanted to make this command called "boom" and its purpose is to launch all players to the air. However, it doesn't seem to work My code: package me.mycustommod.command; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.server.MinecraftServer; import net.minecraft.util.text.TextComponentString; public class CommandBoom extends CommandBase { @Override public String getCommandName() { return "boom"; } @Override public String getCommandUsage(ICommandSender sender) { return "/boom"; } @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) { if (sender instanceof EntityPlayer) { ((EntityPlayer) sender).addChatMessage(new TextComponentString(TextFormatting.GREEN + "Command successfully executed")); ((EntityPlayer) sender).addVelocity(0, 10, 0); } } @Override public int getRequiredPermissionLevel() { return 0; } @Override public boolean checkPermission(MinecraftServer server, ICommandSender sender) { return sender instanceof EntityPlayer; } } *Yes, I did register the command. So whenever I run the command, it only sends the message "Command successfully executed" to the player, but doesn't launch the players to the air. Please help. Thanks! Edited October 8, 20178 yr by Differentiation
October 8, 20178 yr 1. I believe you must do stuff by adding a scheduled task to server world: @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { WorldServer world= (WorldServer) sender.getEntityWorld(); world.addScheduledTask(() -> { EntityPlayer player= (EntityPlayer) sender.getCommandSenderEntity(); player.addVelocity(0,3,0); //the value 10 is too much, players will be sent into sky with it }); } 2. You act only on the player who ran the command. If you want to launch all players, retrieve them from world.playerEntities or from bounding box.
October 8, 20178 yr 4 hours ago, Alexiy said: 1. I believe you must do stuff by adding a scheduled task to server world: That's only necessary when the original method is being called on a thread other than the main client/server thread, e.g. packet handlers are run on a Netty thread. Commands are run on the main server thread, so scheduling a task like that just runs it immediately on the same thread; making it completely pointless to do so. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.