Jump to content

[Solved] Command Alias


daneleo5
 Share

Recommended Posts

i have added commands to my project but i was wondering how i go about making alias like

 

/mt Help

/mt add

etc

 

i have already created the commands class and its registered in my proxy's and so on. so if its possible would you be able to show an example thank you  :)

Link to comment
Share on other sites

In your command class, if you add this method:

 

  
@Override
  public List getCommandAliases()
  {
    ArrayList<> al = new ArrayList<String>();
    al.add("Alias");
    al.add("another Alias"); //if needed
    al.add("and so on"); //if needed
    return this.aliases;
  }

 

it should add the alias(es) to that command.

 

I.E. if my command is terrain, i might add alias(es) tn and tr to the alias list

 

--d4rkfly3r

Link to comment
Share on other sites

He wasn't actually asking about aliases I believe. And that is wrong. What you returned in that method was nothing. Because you created a new array list that you hadn't added the aliases to.

 

I believe he means sub commands of the command. i.e. /block <set/remove/pick> sort of thing.

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

Haha, no worries! xD

 

Here is an example of what you want:

public class GoldCommand implements ICommand{

@Override
public int compareTo(Object arg0) {
	return 0;
}

@Override
public String getCommandName() {
	return "gold";
}

@Override
public String getCommandUsage(ICommandSender icommandsender) {
	return "/gold <set|get|mod> player amount";
}

@Override
public List getCommandAliases() {
	List l = new ArrayList<String>();
	l.add("gold");
	return l;
}

@Override
public void processCommand(ICommandSender icommandsender, String[] astring) {
	//hides
//		for(String s : TheMod.admins){
//			if(s.equals(icommandsender.getCommandSenderName())){
			if(astring.length != 3){
				if(astring.length == 2){
					if(astring[0].equals("get")){
						List playerList = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
						EntityPlayerMP player;
						for(int i =0; i < playerList.size(); i++){
							player =  (EntityPlayerMP)playerList.get(i);
							if(player.username.equals(astring[1])){
								PlayerInfo info = Database.getPlayerInfo(player.username);
								icommandsender.sendChatToPlayer("<Server> player "+astring[1]+" has "+info.getGold()+" gold");
								return;

							}
						}
					}
				}
				icommandsender.sendChatToPlayer(EnumChatFormatting.RED+getCommandUsage(icommandsender));
			}else{
				if(astring[0].equals("set")){
					List playerList = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
					EntityPlayerMP player;
					for(int i =0; i < playerList.size(); i++){
						player =  (EntityPlayerMP)playerList.get(i);
						if(player.username.equals(astring[1])){
							try{
								PlayerInfo info = Database.getPlayerInfo(player.username);
								info.setGold(Integer.parseInt(astring[2]));
								TheMod.proxy.sendRessourceToPlayer(player.username);
								return;
							}catch(Exception e){
								icommandsender.sendChatToPlayer(EnumChatFormatting.RED+astring[2] +" is not a integer");
							}
						}
					}
				}else if(astring[0].equals("mod")){
					List playerList = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
					EntityPlayerMP player;
					for(int i =0; i < playerList.size(); i++){
						player =  (EntityPlayerMP)playerList.get(i);
						if(player.username.equals(astring[1])){
							try{
								PlayerInfo info = Database.getPlayerInfo(player.username);
								info.modGold(Integer.parseInt(astring[2]));
								TheMod.proxy.sendRessourceToPlayer(player.username);
								return;
							}catch(Exception e){
								icommandsender.sendChatToPlayer(EnumChatFormatting.RED+astring[2] +" is not a integer");
							}
						}
					}
				}
			}
//			}
//		}
	//hidee
	icommandsender.sendChatToPlayer(EnumChatFormatting.RED+"dont try, we log every suspicious move");
}

@Override
public boolean canCommandSenderUseCommand(ICommandSender icommandsender) {
	return true;
}

@Override
public List addTabCompletionOptions(ICommandSender icommandsender,
		String[] astring) {
	return null;
}

@Override
public boolean isUsernameIndex(String[] astring, int i) {
	return false;
}

}

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

sorry to be even more of a pain but i really should of said im working with 1.4.7 until some mods i have got updates for redpower, ic2 etc, really sorry about that im guessing thats why some of them are red for me :P once again my apologies for u writing all that code :(

Link to comment
Share on other sites

That is code for 1.5.2... From what I know not much really changed :/

 

What is it the is not working???

 

Can you show me code and then point out what is not working correctly?

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

oh that's good felt like an idiot haha, yer sure

 

PlayerInfo info = Database.getPlayerInfo(player.username); Playerinfo & database cant be resolved
TheMod - cant be resolved(gussing its my client proxy? tried that and it erred 
EnumChatFormatting - cannot be resolved to a variable

@Override
public boolean isUsernameIndex(String[] astring, int i) {
	return false;
}

must override supertype or method

Link to comment
Share on other sites

Oh right... HAHA!

 

That was my fault partially. Ill redo that for ya xD

 

public class GoldCommand implements ICommand{

@Override
public int compareTo(Object arg0) {
	return 0;
}

@Override
public String getCommandName() {
	return "gold";
}

@Override
public String getCommandUsage(ICommandSender icommandsender) {
	return "/gold <set|get|mod> player amount";
}

@Override
public List getCommandAliases() {
	List l = new ArrayList<String>();
	l.add("gold");
	return l;
}

@Override
public void processCommand(ICommandSender icommandsender, String[] astring) {
                if (astring[0].equals("StringOfSubCommand1")) {
                        // execute the code you want to do
                } else if (astring[0].equals("StringOfSubcommand2")) {
                        // execute code for second sub command
                } // etc.
}

@Override
public boolean canCommandSenderUseCommand(ICommandSender icommandsender) {
	return true;
}

@Override
public List addTabCompletionOptions(ICommandSender icommandsender,
		String[] astring) {
	return null;
}

@Override
public boolean isUsernameIndex(String[] astring, int i) {
	return false;
}

}

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

Thx Mew :D

 

the only problem i have now is

The method isUsernameIndex(String[], int) of type commands must override or implement a supertype method

 

but i just put it to

@Override
public boolean isUsernameIndex(int var1) {
	// TODO Auto-generated method stub
	return false;
}

 

which fixed it i think since it loads up the only problem is if i type /gold it "an unknown error occurred while attempting to perform this command"

 

Also thx a bunch Mew if it wasn't for u i would't have got this far :)

Link to comment
Share on other sites

Whats the code now then?

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

i put it back to yours because it just didn't do anything :P

 

just this part of your code doesn't like me lol

 

 

 

[] - errors

 

@Override
public boolean [isUsernameIndex(String[] astring, int i)] {
	return false;

The method isUsernameIndex(String[], int) of type commands must override or implement a supertype method

 

public class [commands] implements ICommand{

The type commands must implement the inherited abstract method ICommand.isUsernameIndex(int)

 

 

java.lang.Error: Unresolved compilation problem: 
The type commands must implement the inherited abstract method ICommand.isUsernameIndex(int)

at daneleo5.commands.isUsernameIndex(commands.java:14)
at net.minecraft.command.CommandHandler.getUsernameIndex(CommandHandler.java:231)
at net.minecraft.command.CommandHandler.executeCommand(CommandHandler.java:35)
at net.minecraft.network.NetServerHandler.handleSlashCommand(NetServerHandler.java:769)
at net.minecraft.network.NetServerHandler.handleChat(NetServerHandler.java:735)
at net.minecraft.network.packet.Packet3Chat.processPacket(Packet3Chat.java:60)
at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:80)
at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:136)
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:57)
at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:108)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:703)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:599)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:123)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:497)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
--- END ERROR REPORT adbfaca6 ----------

 

Link to comment
Share on other sites

change it to just an int. That should fix it... If it doesn't I will try to see what is wrong.

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

@Override
public boolean isUsernameIndex(int astring) {
	return false;
}

 

seemed to have fixed it. i also added in this to display text when you type /gold help but it doesn't do noting

 

@Override
public void processCommand(ICommandSender icommandsender, String[] astring) {
                if (astring[0].equals("StringOfSubCommand1")) {
                	EntityPlayer player = (EntityPlayer)icommandsender;
                	
                	player.addChatMessage("test"); //Just send a simple message to player
                } else if (astring[0].equals("StringOfSubcommand2")) {
                        // execute code for second sub command
                } // etc.

Link to comment
Share on other sites

thats because you would have to type:

 

/gold StringOfSubCommand1

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Try removing the Curios mod and any mods that depend on it. Add them back in one at a time, test launching each time.
    • I am new in modding. I have a registry class for all minecraft items. How I add information an Item without opening new class?
    • Seriously, is this gonna plague future versions of Forge? Because how the hell am I supposed to load mods correctly like I did before if this keeps going on? (Here's the error.) [07Feb2023 12:06:56.387] [Render thread/WARN] [mixin/]: Error loading class: com/mojang/math/Quaternion (java.lang.ClassNotFoundException: com.mojang.math.Quaternion) [07Feb2023 12:06:56.390] [Render thread/FATAL] [mixin/]: Mixin apply failed flywheel.mixins.json:matrix.PoseStackMixin -> com.mojang.blaze3d.vertex.PoseStack: org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException Unexpecteded ClassMetadataNotFoundException whilst transforming the mixin class: [MAIN Applicator Phase -> flywheel.mixins.json:matrix.PoseStackMixin -> Apply Methods -> (Lcom/mojang/math/Quaternion;)Lcom/jozufozu/flywheel/util/transform/TransformStack;:multiply -> Transform LVT -> var=quaternion -> desc=Lcom/mojang/math/Quaternion;] org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException: Unexpecteded ClassMetadataNotFoundException whilst transforming the mixin class: [MAIN Applicator Phase -> flywheel.mixins.json:matrix.PoseStackMixin -> Apply Methods -> (Lcom/mojang/math/Quaternion;)Lcom/jozufozu/flywheel/util/transform/TransformStack;:multiply -> Transform LVT -> var=quaternion -> desc=Lcom/mojang/math/Quaternion;]     at org.spongepowered.asm.mixin.transformer.MixinTargetContext.transformMethod(MixinTargetContext.java:491) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.applyNormalMethod(MixinApplicatorStandard.java:532) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.applyMethods(MixinApplicatorStandard.java:518) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.applyMixin(MixinApplicatorStandard.java:386) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.apply(MixinApplicatorStandard.java:325) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.TargetClassContext.apply(TargetClassContext.java:383) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.TargetClassContext.applyMixins(TargetClassContext.java:365) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:363) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.MixinTransformer.transformClass(MixinTransformer.java:250) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.service.modlauncher.MixinTransformationHandler.processClass(MixinTransformationHandler.java:131) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.launch.MixinLaunchPluginLegacy.processClass(MixinLaunchPluginLegacy.java:131) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at cpw.mods.modlauncher.serviceapi.ILaunchPluginService.processClassWithFlags(ILaunchPluginService.java:156) ~[modlauncher-10.0.8.jar:10.0.8+10.0.8+main.0ef7e830]     at cpw.mods.modlauncher.LaunchPluginHandler.offerClassNodeToPlugins(LaunchPluginHandler.java:88) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.modlauncher.ClassTransformer.transform(ClassTransformer.java:120) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.modlauncher.TransformingClassLoader.maybeTransformClassBytes(TransformingClassLoader.java:50) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.cl.ModuleClassLoader.readerToClass(ModuleClassLoader.java:113) ~[securejarhandler-2.1.6.jar:?]     at cpw.mods.cl.ModuleClassLoader.lambda$findClass$15(ModuleClassLoader.java:219) ~[securejarhandler-2.1.6.jar:?]     at cpw.mods.cl.ModuleClassLoader.loadFromModule(ModuleClassLoader.java:229) ~[securejarhandler-2.1.6.jar:?]     at cpw.mods.cl.ModuleClassLoader.findClass(ModuleClassLoader.java:219) ~[securejarhandler-2.1.6.jar:?]     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:135) ~[securejarhandler-2.1.6.jar:?]     at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?]     at com.mojang.blaze3d.systems.RenderSystem.<clinit>(RenderSystem.java:83) ~[1.19.3-forge-44.1.16.jar:?]     at net.minecraft.client.main.Main.m_239872_(Main.java:174) ~[1.19.3-forge-44.1.16.jar:?]     at net.minecraft.client.main.Main.main(Main.java:51) ~[1.19.3-forge-44.1.16.jar:?]     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]     at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]     at net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:27) ~[fmlloader-1.19.3-44.1.16.jar:?]     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) ~[bootstraplauncher-1.1.2.jar:?] Caused by: org.spongepowered.asm.mixin.throwables.ClassMetadataNotFoundException: com.mojang.math.Quaternion     at org.spongepowered.asm.mixin.transformer.MixinTargetContext.transformSingleDescriptor(MixinTargetContext.java:983) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.MixinTargetContext.transformSingleDescriptor(MixinTargetContext.java:943) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.MixinTargetContext.transformLVT(MixinTargetContext.java:544) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.MixinTargetContext.transformMethod(MixinTargetContext.java:450) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4] This has been going on since 44.1.8 and how on Earth is this not even fixed yet?
    • Error downloading asset (try 2) : minecraft/sounds/block/fence_gate/close2.ogg java.io.IOException: Server returned HTTP response code: 400 for URL: http://resources.download.minecraft.net/58/58d63232621aaa03e4d09598700561214e7c2477     at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1902)     at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1500)     at java.net.URL.openStream(URL.java:1093)     at net.minecraftforge.gradle.tasks.DownloadAssetsTask$GetAssetTask.call(DownloadAssetsTask.java:189)     at net.minecraftforge.gradle.tasks.DownloadAssetsTask$GetAssetTask.call(DownloadAssetsTask.java:150)     at java.util.concurrent.FutureTask.run(FutureTask.java:266)     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)     at java.lang.Thread.run(Thread.java:750) This and countless other assets failing to download. This is my school laptop, Programs such as Fortiguard are installed, Could this possibly be interfering? 
    • you do realize we have no idea what you wrote and where? also, even if you did it right, maybe a code from one of the goals is changing y-rotation after your code. read through all the goals that are active. delete all goals unless they meet two requirements: 1) you want the goal to execute, and 2) you 100% understand everything it does.
  • Topics

×
×
  • Create New...

Important Information

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