Add help to create command.

This commit is contained in:
Jesse Prescott 2018-06-04 14:12:35 +01:00
parent a54386c98d
commit 1f5d15cdf4

View File

@ -16,6 +16,7 @@ package com.gmail.bleedobsidian.itemcase.commands;
import com.gmail.bleedobsidian.itemcase.ChatLogger;
import com.gmail.bleedobsidian.itemcase.ItemCaseCore;
import com.gmail.bleedobsidian.itemcase.LanguageTranslator;
import java.util.ArrayList;
import org.bukkit.Location;
import org.bukkit.Material;
@ -45,12 +46,19 @@ public final class CreateCommand implements Command {
return;
}
// Get chat logger.
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
// Cast sender to player.
Player player = (Player) sender;
// Check if player is asking for help.
if(this.isAskingForHelp(player, label, args)) {
// Exit.
return;
}
// Get chat logger.
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
// Check if player has permission.
if(!player.hasPermission("itemcase.create")) {
@ -114,4 +122,43 @@ public final class CreateCommand implements Command {
// Show message.
chatLogger.message(player, "command.create.success");
}
/**
* @return If the command sender is asking for help about this command.
*/
public boolean isAskingForHelp(Player player, String label, String[] args) {
// If args length equals 2.
if(args.length != 2) {
// False.
return false;
}
// Get argument.
String argument = args[1];
// If not equal to help.
if(!argument.equalsIgnoreCase("help")) {
return false;
}
// Get chat logger.
ChatLogger chatLogger = ItemCaseCore.instance.getChatLogger();
// Get translator.
LanguageTranslator translator = ItemCaseCore.instance.getTranslator();
// Set placeholder.
translator.setPlaceholder("%COMMAND%", "/" + label + " create");
// Show command help.
chatLogger.message(player, "command.itemcase-help");
// Show specific help.
chatLogger.message(player, "command.create.help");
return true;
}
}