diff --git a/CHANGELOG.md b/CHANGELOG.md
index 291b245..a1e4a3c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,8 @@
+# 1.5
+
+ - Add giveskill command
+
# 1.4
- Add instructional lore on prepared skills for unpreparing
diff --git a/pom.xml b/pom.xml
index 0480a65..4c67117 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
com.elmakers.mine.bukkit
HeroesHotbar
- 1.4
+ 1.5
Heroes Hotbar
A hotbar GUI add-on to the Heroes Bukkit plugin
diff --git a/src/main/java/com/elmakers/mine/bukkit/heroes/GiveSkillCommandExecutor.java b/src/main/java/com/elmakers/mine/bukkit/heroes/GiveSkillCommandExecutor.java
new file mode 100644
index 0000000..fd0cb57
--- /dev/null
+++ b/src/main/java/com/elmakers/mine/bukkit/heroes/GiveSkillCommandExecutor.java
@@ -0,0 +1,58 @@
+package com.elmakers.mine.bukkit.heroes;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+
+/**
+ * Command executor responsible for handling the /giveskill command.
+ */
+public class GiveSkillCommandExecutor implements CommandExecutor {
+ private final HotbarController controller;
+
+ public GiveSkillCommandExecutor(HotbarController controller) {
+ this.controller = controller;
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ if (!sender.hasPermission("Heroes.commands.skillmenu")) {
+ sender.sendMessage(ChatColor.RED + "You don't have permission for this command");
+ return true;
+ }
+ if (!(sender instanceof Player) && args.length <= 1) {
+ sender.sendMessage(ChatColor.RED + "Console Usage: giveskill ");
+ return true;
+ }
+ if (args.length <= 0) {
+ sender.sendMessage(ChatColor.RED + "Usage: giveskill [player] ");
+ return true;
+ }
+
+ Player player = sender instanceof Player ? (Player)sender : null;
+ if (args.length >= 2) {
+ player = Bukkit.getPlayer(args[0]);
+ }
+ if (player == null) {
+ sender.sendMessage(ChatColor.RED + "Unknown player: " + args[0]);
+ return true;
+ }
+
+ String skillName = args.length > 1 ? args[1] : args[0];
+ SkillDescription skillDescription = new SkillDescription(controller, player, skillName);
+ if (!skillDescription.isValid()) {
+ sender.sendMessage(ChatColor.RED + "Unknown skill: " + skillName);
+ return true;
+ }
+
+ ItemStack item = controller.createSkillItem(skillDescription, player);
+ player.getInventory().addItem(item);
+ sender.sendMessage(ChatColor.LIGHT_PURPLE + "Gave skill " + skillName + " to " + player.getName());
+ return true;
+ }
+}
diff --git a/src/main/java/com/elmakers/mine/bukkit/heroes/HotbarPlugin.java b/src/main/java/com/elmakers/mine/bukkit/heroes/HotbarPlugin.java
index e1a447c..bd48ba7 100644
--- a/src/main/java/com/elmakers/mine/bukkit/heroes/HotbarPlugin.java
+++ b/src/main/java/com/elmakers/mine/bukkit/heroes/HotbarPlugin.java
@@ -70,6 +70,8 @@ protected void initialize() {
// Set up command executors
CommandExecutor skillsMenuCommand = new SkillsMenuCommandExecutor(controller);
getCommand("skillmenu").setExecutor(skillsMenuCommand);
+ CommandExecutor giveSkillCommand = new GiveSkillCommandExecutor(controller);
+ getCommand("giveskill").setExecutor(giveSkillCommand);
// Set up listeners
InventoryListener inventoryListener = new InventoryListener(controller);
diff --git a/src/main/java/com/elmakers/mine/bukkit/heroes/SkillDescription.java b/src/main/java/com/elmakers/mine/bukkit/heroes/SkillDescription.java
index 6045187..06ca871 100644
--- a/src/main/java/com/elmakers/mine/bukkit/heroes/SkillDescription.java
+++ b/src/main/java/com/elmakers/mine/bukkit/heroes/SkillDescription.java
@@ -20,8 +20,8 @@ public SkillDescription(HotbarController controller, Player player, String skill
this.skillKey = skillKey;
this.skillLevel = controller.getSkillLevel(player, skillKey);
- String iconURL = SkillConfigManager.getRaw(skill, "icon-url", SkillConfigManager.getRaw(skill, "icon_url", null));
- String icon = SkillConfigManager.getRaw(skill, "icon", null);
+ String iconURL = skill == null ? null : SkillConfigManager.getRaw(skill, "icon-url", SkillConfigManager.getRaw(skill, "icon_url", null));
+ String icon = skill == null ? null : SkillConfigManager.getRaw(skill, "icon", null);
if (icon != null && icon.startsWith("http://")) {
icon = null;
iconURL = icon;
@@ -29,8 +29,8 @@ public SkillDescription(HotbarController controller, Player player, String skill
this.icon = icon == null || icon.isEmpty() ? null : new MaterialAndData(icon);
this.iconURL = iconURL;
- String iconDisabledURL = SkillConfigManager.getRaw(skill, "icon-disabled-url", SkillConfigManager.getRaw(skill, "icon_disabled_url", null));
- String iconDisabled = SkillConfigManager.getRaw(skill, "icon-disabled", SkillConfigManager.getRaw(skill, "icon_disabled", null));
+ String iconDisabledURL = skill == null ? null : SkillConfigManager.getRaw(skill, "icon-disabled-url", SkillConfigManager.getRaw(skill, "icon_disabled_url", null));
+ String iconDisabled = skill == null ? null : SkillConfigManager.getRaw(skill, "icon-disabled", SkillConfigManager.getRaw(skill, "icon_disabled", null));
if (iconDisabled != null && iconDisabled.startsWith("http://")) {
iconDisabled = null;
iconDisabledURL = icon;
@@ -44,9 +44,9 @@ public SkillDescription(HotbarController controller, Player player, String skill
this.disabledIconURL = iconDisabledURL;
- String skillDisplayName = SkillConfigManager.getRaw(skill, "name", skill.getName());
+ String skillDisplayName = skill == null ? null : SkillConfigManager.getRaw(skill, "name", skill.getName());
this.name = skillDisplayName == null || skillDisplayName.isEmpty() ? skillKey : skillDisplayName;
- this.description = SkillConfigManager.getRaw(skill, "description", "");
+ this.description = skill == null ? null : SkillConfigManager.getRaw(skill, "description", "");
}
public boolean isHeroes() {
@@ -88,4 +88,8 @@ public Skill getSkill() {
public String getDescription() {
return description;
}
+
+ public boolean isValid() {
+ return skill != null;
+ }
};
\ No newline at end of file
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index c2823b0..0683ab0 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -10,8 +10,16 @@ commands:
description: Get Heroes skills
usage: /skillmenu
permission: Heroes.commands.skillmenu
+ giveskill:
+ description: Give a specific skill item to a player
+ usage: /giveskill [player]
+ permission: Heroes.commands.giveskill
permissions:
Heroes.commands.skillmenu:
description: Player may use the /skillmenu command
type: boolean
default: true
+ Heroes.commands.giveskill:
+ description: Player may use the /giveskill command
+ type: boolean
+ default: op