Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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 by Differentiation

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.