Minecraft PC IP: play.cubecraft.net

xM7MDx

Member
Feb 18, 2017
4
0
1
23
Hello
i have this code :




public boolean onCommand(CommandSender sender, Command cmd, String CommandLable, String[] args){

if(cmd.getName().equalsIgnoreCase("test")){

p.sendMessage("This is a test");


}



i need to change command sender : "test" from config how i can do it?
 

Despacito 2

Forum Professional
Dec 6, 2015
7,507
10,289
564
23
Quick question is this for a Mod or Plugin. I don't have any experience with plugins what so ever. Also could please send a screenshot of your project. It's hard to understand what exactly want to make.
 

Power Ranger

Forum Professional
Apr 20, 2016
4,294
6,813
558
23
The ♡
www.cubecraft.net
Quick question is this for a Mod or Plugin. I don't have any experience with plugins what so ever. Also could please send a screenshot of your project. It's hard to understand what exactly want to make.
He's making a basic command for a test plugin.

I'll have to double check how to set up the .yml exactly before I can answer this right though xD I also only have experience with eclipse so if your using a different IDE could you tell me which? I'm pretty noobish at coding myself xD I'll try to get back to this as soon as possible.
 

Despacito 2

Forum Professional
Dec 6, 2015
7,507
10,289
564
23
He's making a basic command for a test plugin.

I'll have to double check how to set up the .yml exactly before I can answer this right though xD I also only have experience with eclipse so if your using a different IDE could you tell me which? I'm pretty noobish at coding myself xD I'll try to get back to this as soon as possible.
Hm okay.
So if I'm correct the .yml needs the main file information, version and name of the plugin.
Example:
main: src.examplemod.example
version: 1.69
name: Example Plugin
 
Last edited:

DocMenios

Well-Known Member
Jul 21, 2016
463
163
118
In a country
Hello
i have this code :




public boolean onCommand(CommandSender sender, Command cmd, String CommandLable, String[] args){

if(cmd.getName().equalsIgnoreCase("test")){

p.sendMessage("This is a test");


}



i need to change command sender : "test" from config how i can do it?
@Nyaruko could you help?
 

Nyaruko

Well-Known Member
Oct 17, 2016
7
50
88
26
England
nyaruko.io
Hello
i have this code :




public boolean onCommand(CommandSender sender, Command cmd, String CommandLable, String[] args){

if(cmd.getName().equalsIgnoreCase("test")){

p.sendMessage("This is a test");


}



i need to change command sender : "test" from config how i can do it?
Do you mean so that you can change what you put after the / by config? So it would be like /{config text here}?
 
  • Like
Reactions: xM7MDx

FalseHonesty

Dedicated Member
Mar 5, 2016
907
916
173
My House
saltsquadstrong.weebly.com
Code:
private FileConfiguration conf = getConfig();

public void onEnable(){
   if(!getDataFolder().exists()) {
      conf.addDefault("commandname", "test");
      conf.options().copyDefaults(true);
      saveConfig();
   }
}

public boolean onCommand(CommandSender sender, Command    cmd, String CommandLable, String[] args){
  conf = getConfig();
   String command = conf.getString("commandname");
   if(cmd.getName().equalsIgnoreCase(command)){
      p.sendMessage("This is a test");
   }
}

That should work, then you can change the default in the code, and you could also change it in the config file. Post another message if there are any problems, as is untested.
 

Nyaruko

Well-Known Member
Oct 17, 2016
7
50
88
26
England
nyaruko.io
You don't need to use the plugin.yml for this, once you've loaded the command string from your config you can catch people running it with the PlayerCommandPreprocessEvent and pass out the parameters to a normal method.
 

Wolfii

Well-Known Member
Aug 9, 2016
10
62
93
25
Portsmouth, United Kingdom
Code:
private FileConfiguration conf = getConfig();

public void onEnable(){
   if(!getDataFolder().exists()) {
      conf.addDefault("commandname", "test");
      conf.options().copyDefaults(true);
      saveConfig();
   }
}

public boolean onCommand(CommandSender sender, Command    cmd, String CommandLable, String[] args){
  conf = getConfig();
   String command = conf.getString("commandname");
   if(cmd.getName().equalsIgnoreCase(command)){
      p.sendMessage("This is a test");
   }
}

That should work, then you can change the default in the code, and you could also change it in the config file. Post another message if there are any problems, as is untested.

Also that won't work. In order to use the command executor you have to define an alias when registering it. That means that only commands defined in the plugin.yml will work with what you mentioned and if people attempt to use anything else it won't work.

Not to mention the fact that you arent even registering the command in the onEnable
 

FalseHonesty

Dedicated Member
Mar 5, 2016
907
916
173
My House
saltsquadstrong.weebly.com
Also that won't work. In order to use the command executor you have to define an alias when registering it. That means that only commands defined in the plugin.yml will work with what you mentioned and if people attempt to use anything else it won't work.

Not to mention the fact that you arent even registering the command in the onEnable
I figured he had already sorted that out, but that is my bad for not including it. Thanks <3
 
Members Online

Team online

Members online

Latest posts

Latest profile posts

TheOrderOfSapphire wrote on Roxlad's profile.
Happy Birthday ^-^
TheOrderOfSapphire wrote on Ferrcho's profile.
Happy Birthday!:D
Thunder wrote on Roxlad's profile.
Happy birthday!
Thunder wrote on Ferrcho's profile.
Happy birthday!
qKhalidd wrote on Ferrcho's profile.
happy birthday!
Top Bottom