Skip to content

Commit

Permalink
Add /giveskill command
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanWolf committed Nov 3, 2017
1 parent aea2f2f commit 6ac5cc7
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

# 1.5

- Add giveskill command

# 1.4

- Add instructional lore on prepared skills for unpreparing
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.elmakers.mine.bukkit</groupId>
<artifactId>HeroesHotbar</artifactId>
<version>1.4</version>
<version>1.5</version>

<name>Heroes Hotbar</name>
<description>A hotbar GUI add-on to the Heroes Bukkit plugin</description>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <player> <skill>");
return true;
}
if (args.length <= 0) {
sender.sendMessage(ChatColor.RED + "Usage: giveskill [player] <skill>");
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ 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;
}
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;
Expand All @@ -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() {
Expand Down Expand Up @@ -88,4 +88,8 @@ public Skill getSkill() {
public String getDescription() {
return description;
}

public boolean isValid() {
return skill != null;
}
};
8 changes: 8 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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] <skill>
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

0 comments on commit 6ac5cc7

Please sign in to comment.