Differentiation Posted October 8, 2017 Posted October 8, 2017 (edited) 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, 2017 by Differentiation Quote
Alexiy Posted October 8, 2017 Posted October 8, 2017 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. 1 Quote
Choonster Posted October 8, 2017 Posted October 8, 2017 On 10/8/2017 at 4:29 PM, Alexiy said: 1. I believe you must do stuff by adding a scheduled task to server world: Expand 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. Quote 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.
Recommended Posts
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.