Jump to content

[1.10.2] registerServerCommand not working as expected.


_Zerys

Recommended Posts

I Want to add a server command I set it up and am not getting any issues or anything the command is simply not showing up via /help.

 

When I  tried simply doing /fly and the log comes up with "You do not have permission to access this command".

 

I have also messed with permissions via the code and nothing is working as well.

 

I also tested being op on the test server. Any help?

 

Main class

 

package zTestMod;

import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandManager;
import net.minecraft.command.ServerCommandManager;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;

@Mod(modid = Ztestmod.MOD_ID, name = Ztestmod.MOD_NAME, version=Ztestmod.VERSION, acceptableRemoteVersions = "*")

public class Ztestmod {

	public static final String MOD_ID = "Ztestmod";
	public static final String MOD_NAME = "Ztestmod";
	public static final String VERSION = "1.10.2";

	@EventHandler
	public void severStart(FMLServerStartingEvent e) {
		MinecraftServer server = e.getServer();
		e.registerServerCommand(new Fly());
	}
}

 

Fly Class

package zTestMod;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;

public class Fly extends CommandBase{


    private final List<String> aliases = new ArrayList<String>();

    public Fly()
    {
        aliases.add("fly");
        aliases.add("Fly");
        aliases.add("Flying");
    }

    @Override
    public int getRequiredPermissionLevel()
    {
        return 4;
    }
    
    @Override
    public String getCommandUsage(ICommandSender commandSender)
    {
        return getCommandName() + " help";
    }
    
    @Override
    public List<String> getCommandAliases()
    {
        return aliases;
    }
    
    
    @Override
public int compareTo(ICommand o) {
	// TODO Auto-generated method stub
	return 0;
}

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
	// TODO Auto-generated method stub

}

@Override
public boolean checkPermission(MinecraftServer server, ICommandSender sender) {
	// TODO Auto-generated method stub
	return false;
}

@Override
public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args,
		BlockPos pos) {
	// TODO Auto-generated method stub
	return null;
}

@Override
public boolean isUsernameIndex(String[] args, int index) {
	// TODO Auto-generated method stub
	return false;
}

@Override
public String getCommandName() {
	// TODO Auto-generated method stub
	return "/fly";
}

public boolean canCommandSenderUseCommand(ICommandSender sender) {
	return true;
}
}

Link to comment
Share on other sites

Already tried that, It was having none of it.

what do you mean? errors? if still it says that you dont have permissions lower again until you see that it works... im currently have my head on my mod but that's the only thing i can think of that would cause no permissions stuff.. its not spigot/bukkit or something.. it should be basic power levels

Doing stuff n' things

Link to comment
Share on other sites

Found the issue, I needed to essentially tell the code to check the required permission. An oversight to say the least. For those that are having a simliar issue this is what I changed.

 

	

@Override
public boolean checkPermission(MinecraftServer server, ICommandSender sender) {
	return true;
}

 

 

Link to comment
Share on other sites

Can you tell me why I shouldn't override said methods? Since removing them doesn't throw any error's why are they there to begin with? Still rather new to Java.

they got generated i think... its never happend to me.. i guess its an eclipse thing?

Doing stuff n' things

Link to comment
Share on other sites

Can you tell me why I shouldn't override said methods? Since removing them doesn't throw any error's why are they there to begin with? Still rather new to Java.

 

Only override a method if you plan on DOING something with it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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