Classes that help with plugin development!
Report Bug
·
Request Feature
Template made to facilitate the making of spigot plugins!
Features:
- Better command handling
- Managing Config/Language
- Easier handling of GUIs
This project was built with:
public class ExampleMenu extends BaseGUI {
public ExampleMenu(Player player) {
super(player);
}
@Override
public void handleClick(InventoryClickEvent event) {
NBTItem nbtItem = new NBTItem(event.getCurrentItem());
if(nbtItem.hasKey(GUIButton.IDENTIFIER_KEY)) {
switch(nbtItem.getString(GUIButton.IDENTIFIER_KEY)) {
case "TEST":
player.sendMessage("BTN = TEST");
break;
}
}
else player.sendMessage("BTN = NULL");
}
@Override
public void setupInventoryItems() {
inventory.setItem(0, new GUIButton(new ItemStack(XMaterial.COAL_BLOCK.parseMaterial()), "TEST").getItemStack());
fillInventory(0, getSize());
}
@Override
public @NotNull String getName() {
return "Example menu";
}
@Override
public int getSize() {
return 9;
}
}
public class ExamplePaginatedMenu extends PaginatedGUI {
public ExamplePaginatedMenu(Player player) {
super(player);
}
@Override
public void handleClick(InventoryClickEvent event) {
NBTItem nbtItem = new NBTItem(event.getCurrentItem());
if(nbtItem.hasKey(GUIButton.IDENTIFIER_KEY)) {
switch(nbtItem.getString(GUIButton.IDENTIFIER_KEY)) {
case "NEXT_PAGE":
setPage(page + 1);
break;
case "PREVIOUS_PAGE":
setPage(page - 1);
break;
}
}
}
@Override
public void setupInventoryItems() {
inventory.setItem(47, new GUIButton(new ItemStack(XMaterial.STONE_BUTTON.parseMaterial()), "PREVIOUS_PAGE").getItemStack());
inventory.setItem(51, new GUIButton(new ItemStack(XMaterial.STONE_BUTTON.parseMaterial()), "NEXT_PAGE").getItemStack());
fillInventory(45, getSize());
}
@Override
public @NotNull String getName() {
return "Example Paginated Menu";
}
@Override
public int getSize() {
return 54;
}
@Override
public @NotNull ArrayList<ItemStack> getPageItems() {
ArrayList<ItemStack> items = new ArrayList<>();
for(int i = 0; i < 128; i++) {
if(i % 2 == 0) {
items.add(new ItemStack(Material.DIAMOND));
}else{
items.add(new ItemStack(Material.EMERALD));
}
}
return items;
}
@Override
public int getPageSize() {
return 45;
}
public ExampleCommand(TemplatePlugin plugin) {
super(plugin);
//add all subcommands here
subCommands.put("TEST", new ExampleSubCommand());
}
@Override
public void executeStockSubCommand(CommandSender sender) {
//stock command is executed if there are no arguments
plugin.getLog().info("executing stock command!");
}
@Override
public @NotNull String getPermission() {
//permission to execute the command (includes all subcommands)
return Permission.TPCOMMAND;
}
@Override
public @NotNull String getName() {
//command name (same one as in plugin.yml)
return "excommand";
}
@Override
public @NotNull List<String> getAliases() {
//aliases (same ones as in plugin.yml)
return Arrays.asList(new String[]{"excmd"}.clone());
}
@Override
public boolean isPlayerOnly() {
//is the command meant to be executed only by players
return false;
}
public class ExampleSubCommand implements SubCommand {
@Override
public void executeCommand(CommandSender sender, String[] args, TemplatePlugin plugin) {
//subcommand logic
sender.sendMessage(plugin.getLanguageManager().getHelloWorld());
Player player = (Player) sender;
if(sender instanceof Player){
plugin.getLanguageManager().getClickSound().playSound((Player) sender);
}
}
@Override
public @NotNull String getPermission() {
//permission needed to execute this subcommand
return Permission.ADMIN;
}
@Override
public @Nullable String[] getArguments() {
//subcommand arguments (used to help with tab completion)
return null;
}
}
In order to register the command you'll need to add this into your main class.
private void loadCommands() {
loadCommand(new ExampleCommand(this));
}
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Giovani Valgas - @giovalgas - giovalgascom@gmail.com
Project Link: https://github.com/giovalgas/TemplatePlugin