Skip to content

Commit 0693e78

Browse files
committed
[+] Updated examples
1 parent 3edaaae commit 0693e78

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
package xyz.damt.example;
22

33
import lombok.Getter;
4+
import org.bukkit.inventory.ItemStack;
45
import org.bukkit.plugin.java.JavaPlugin;
56
import xyz.damt.command.CommandHandler;
67
import xyz.damt.example.command.FlyCommand;
8+
import xyz.damt.example.command.ItemStackCommand;
9+
import xyz.damt.example.provider.ItemStackProvider;
710

811
@Getter
912
public class Main extends JavaPlugin {
1013

1114
@Getter
1215
private static Main instance;
1316

14-
private CommandHandler commandHandler;
15-
1617
@Override
1718
public void onLoad() {
1819
instance = this;
1920
}
2021

2122
@Override
2223
public void onEnable() {
23-
this.commandHandler = new CommandHandler(this);
24-
commandHandler.register(new FlyCommand());
24+
new CommandHandler(this).bind(ItemStack.class, new ItemStackProvider())
25+
.register(new FlyCommand(), new ItemStackCommand()).registerCommands();
2526
}
2627

2728
}

src/test/java/xyz/damt/example/command/FlyCommand.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ public class FlyCommand {
1010

1111
/**
1212
* So this is a simple command example
13-
* There are 2 rules to every command:
14-
* <p>
13+
* There is 1 rule to every command:
14+
*
1515
* 1- Must have a sender could be a player or a command sender
16-
* 2- Must have an array of strings
1716
*
1817
* @param player sender
19-
* @param args arguments to execute with
2018
*/
2119

2220
@Command(value = "fly", description = "Fly Command", usage = "fly")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package xyz.damt.example.command;
2+
3+
import org.bukkit.ChatColor;
4+
import org.bukkit.entity.Player;
5+
import org.bukkit.inventory.ItemStack;
6+
import xyz.damt.command.annotation.Command;
7+
import xyz.damt.command.annotation.Name;
8+
import xyz.damt.command.annotation.Permission;
9+
import xyz.damt.command.annotation.Sender;
10+
11+
public class ItemStackCommand {
12+
13+
@Command(value = "kekw", async = true, usage = "/kekw itemStack", description = "Just makes an itemstack lol")
14+
@Permission(permission = "kekw.kekew", message = "no perm noob")
15+
public void itemStackCommand(@Sender Player player, @Name("itemStack") ItemStack itemStack) {
16+
player.getInventory().addItem(itemStack);
17+
player.sendMessage(ChatColor.GREEN + "Gave ya your itemstack!");
18+
}
19+
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package xyz.damt.example.provider;
2+
3+
import org.bukkit.ChatColor;
4+
import org.bukkit.Material;
5+
import org.bukkit.inventory.ItemStack;
6+
import xyz.damt.command.exception.CommandProviderNullException;
7+
import xyz.damt.command.provider.CommandProvider;
8+
9+
public class ItemStackProvider implements CommandProvider<ItemStack> {
10+
11+
@Override
12+
public ItemStack provide(String s) throws CommandProviderNullException {
13+
14+
if (!s.equalsIgnoreCase("itemStack"))
15+
throw new CommandProviderNullException(ChatColor.RED + "You need to type 'itemStack' to get this provider!");
16+
17+
return new ItemStack(Material.DIRT);
18+
}
19+
20+
}

0 commit comments

Comments
 (0)