Skip to content

giovalgas/template-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues


Logo

Spigot Template

Classes that help with plugin development!

Report Bug · Request Feature

Table of Contents

About The Project

Template made to facilitate the making of spigot plugins!

Features:

  • Better command handling
  • Managing Config/Language
  • Easier handling of GUIs

Built With

This project was built with:

Getting Started

GUI Handling

Non paginated GUI

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;  
  }  
}

Paginated GUI

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;  
  }

Command Handling

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;  
}

Subcommand example

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;  
  }  
}

Main class

In order to register the command you'll need to add this into your main class.

private void loadCommands() {  
  loadCommand(new ExampleCommand(this));  
}

Contributing

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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Contact

Giovani Valgas - @giovalgas - giovalgascom@gmail.com

Project Link: https://github.com/giovalgas/TemplatePlugin

About

My spigot template.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages