Skip to content

Commit

Permalink
GCS Fixes (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Tapply committed May 28, 2024
1 parent 9d57032 commit bbd986e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void registerCommands() {
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args Passed command arguments
* @return Whether the command was successful
* @return
*/
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
Expand Down Expand Up @@ -99,7 +99,10 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
// Execute the command and call the event that should be triggered when the command is run
try {
wynncraftCommand.execute(sender, args);
wynncraftCommand.getTriggerEvent().callEvent();

if (wynncraftCommand.getTriggerEvent() != null) {
wynncraftCommand.getTriggerEvent().callEvent();
}
} catch (Exception e) {
// In the event of incorrect usage, send an error message to the sender and console to notify of the error
Component errorMessage = Component.text("An error occurred while executing the command '")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ public boolean isPlayerOnly() {
* The event that triggers when the command is executed
* @return The event that is called when the command is run
*/
public abstract WynncraftEvent getTriggerEvent();
public WynncraftEvent getTriggerEvent() {
return null;
};

/**
* The method that is called when the command is executed
* @param sender The sender of the command
* @param args The arguments of the command
* @return Whether or not the command was executed successfully
* @return
*/
public abstract boolean execute(CommandSender sender, String[] args) throws Exception;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.iantapply.wynncraft.command.commands;

import com.iantapply.wynncraft.command.WynncraftCommand;
import org.bukkit.command.CommandSender;

public class ExampleCommand extends WynncraftCommand {
/**
* The name that is appended after the leading '/' character
*
* @return The name
*/
@Override
public String name() {
return "example";
}

/**
* The syntax of the command to display in the help menu and other places
* This should be in the format of "command [args]"
*
* @return The syntax
*/
@Override
public String syntax() {
return "example";
}

/**
* The description of the command to display in the help menu and other places
*
* @return The description
*/
@Override
public String description() {
return "An example command using the Wynncraft command framework";
}

/**
* The minimum amount of arguments that are required to execute the command
*
* @return The minimum amount of arguments
*/
@Override
public int minArgs() {
return 0;
}

/**
* The maximum amount of arguments that are required to execute the command
*
* @return The maximum amount of arguments
*/
@Override
public int maxArgs() {
return 0;
}
/**
* The method that is called when the command is executed
*
* @param sender The sender of the command
* @param args The arguments of the command
* @return
*/
@Override
public boolean execute(CommandSender sender, String[] args) throws Exception {
sender.sendMessage("This is an example command!");
return false;
}
}

0 comments on commit bbd986e

Please sign in to comment.