Skip to content

Commit 05c4072

Browse files
committed
* NEW: First draft for the new Commands API.
1 parent 5df182b commit 05c4072

18 files changed

+260
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package fr.zcraft.zlib.components.commands2;
8+
9+
public class Command<T extends CommandNode> {
10+
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package fr.zcraft.zlib.components.commands2;
8+
9+
import java.util.Collection;
10+
import org.apache.commons.lang.NotImplementedException;
11+
import org.bukkit.command.CommandSender;
12+
13+
public class CommandData<T extends CommandNode> implements CommandNode<T>
14+
{
15+
16+
@Override
17+
public T getParent()
18+
{
19+
throw new NotImplementedException();
20+
}
21+
22+
@Override
23+
public Collection getChildren()
24+
{
25+
throw new NotImplementedException();
26+
}
27+
28+
@Override
29+
public String getName()
30+
{
31+
throw new NotImplementedException();
32+
}
33+
34+
@Override
35+
public String[] getAliases()
36+
{
37+
throw new NotImplementedException();
38+
}
39+
40+
@Override
41+
public String getShortDescription()
42+
{
43+
throw new NotImplementedException();
44+
}
45+
46+
@Override
47+
public String getUsage()
48+
{
49+
throw new NotImplementedException();
50+
}
51+
52+
@Override
53+
public void run(CommandSender sender, String... arguments) throws CommandException
54+
{
55+
throw new NotImplementedException();
56+
}
57+
58+
@Override
59+
public Collection complete(CommandSender sender, String... arguments) throws CommandException
60+
{
61+
throw new NotImplementedException();
62+
}
63+
64+
@Override
65+
public boolean canExecute(CommandSender sender)
66+
{
67+
throw new NotImplementedException();
68+
}
69+
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package fr.zcraft.zlib.components.commands2;
8+
9+
public class CommandException extends Exception
10+
{
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package fr.zcraft.zlib.components.commands2;
8+
9+
public class CommandGroup extends CommandData {
10+
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package fr.zcraft.zlib.components.commands2;
8+
9+
import java.util.Collection;
10+
import org.bukkit.command.CommandSender;
11+
12+
public interface CommandNode<T extends CommandNode>
13+
{
14+
public T getParent();
15+
public Collection<CommandNode> getChildren();
16+
17+
public String getName();
18+
public String[] getAliases();
19+
public String getShortDescription();
20+
public String getUsage();
21+
22+
public void run(CommandSender sender, String... arguments) throws CommandException;
23+
public Collection complete(CommandSender sender, String... arguments) throws CommandException;
24+
public boolean canExecute(CommandSender sender);
25+
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package fr.zcraft.zlib.components.commands2;
8+
9+
public class CommandTreeBuilder
10+
{
11+
public CommandTreeBuilder command(Class<? extends Command> command)
12+
{
13+
return this;
14+
}
15+
16+
public CommandTreeBuilder command(String name, Class<? extends Command> command)
17+
{
18+
return this;
19+
}
20+
21+
public CommandTreeBuilder commands(Class<? extends Command>... command)
22+
{
23+
return this;
24+
}
25+
26+
public CommandTreeBuilder subCommand(String name, String... aliases)
27+
{
28+
return this;
29+
}
30+
31+
public CommandTreeBuilder subCommand(String name, CommandGroup group, String... aliases)
32+
{
33+
return this;
34+
}
35+
36+
public CommandTreeBuilder endGroup()
37+
{
38+
return this;
39+
}
40+
41+
public CommandTreeBuilder end()
42+
{
43+
return this;
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package fr.zcraft.zlib.components.commands2;
8+
9+
public abstract class Commands
10+
{
11+
static public CommandTreeBuilder register()
12+
{
13+
return new CommandTreeBuilder();
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package fr.zcraft.zlib.components.commands2;
8+
9+
import org.junit.Test;
10+
11+
public class CommandsTest
12+
{
13+
@Test
14+
public void simpleTest()
15+
{
16+
Commands.register()
17+
.subCommand("belovedblocks", "bb")
18+
.subCommand("give", "g")
19+
.subCommand("tool", new CustomGroup(1), "t")
20+
.command(MyCommand.class)
21+
.endGroup()
22+
.subCommand("block", new CustomGroup(2), "b")
23+
.command(MyCommand.class)
24+
.end();
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package fr.zcraft.zlib.components.commands2;
8+
9+
public class CustomGroup extends CommandGroup
10+
{
11+
private final int veryImportantNumber;
12+
13+
public CustomGroup(int veryImportantNumber)
14+
{
15+
this.veryImportantNumber = veryImportantNumber;
16+
}
17+
18+
public int getVeryImportantNumber()
19+
{
20+
return veryImportantNumber;
21+
}
22+
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package fr.zcraft.zlib.components.commands2;
8+
9+
public class MyCommand extends Command
10+
{
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)