diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/commands/boss/BossGiveEggCmd.java b/plugin-modules/Core/src/com/songoda/epicbosses/commands/boss/BossGiveEggCmd.java index 97ad670..39d4d86 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/commands/boss/BossGiveEggCmd.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/commands/boss/BossGiveEggCmd.java @@ -1,7 +1,16 @@ package com.songoda.epicbosses.commands.boss; +import com.songoda.epicbosses.entity.BossEntity; +import com.songoda.epicbosses.managers.BossEntityManager; +import com.songoda.epicbosses.managers.files.BossesFileManager; +import com.songoda.epicbosses.utils.Message; +import com.songoda.epicbosses.utils.NumberUtils; +import com.songoda.epicbosses.utils.Permission; import com.songoda.epicbosses.utils.command.SubCommand; +import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; /** * @author Charles Cullen @@ -10,12 +19,68 @@ import org.bukkit.command.CommandSender; */ public class BossGiveEggCmd extends SubCommand { - public BossGiveEggCmd() { + private BossEntityManager bossEntityManager; + private BossesFileManager bossesFileManager; + + public BossGiveEggCmd(BossesFileManager bossesFileManager, BossEntityManager bossEntityManager) { super("give", "giveegg"); + + this.bossesFileManager = bossesFileManager; + this.bossEntityManager = bossEntityManager; } @Override public void execute(CommandSender sender, String[] args) { + if(!Permission.give.hasPermission(sender)) { + Message.Boss_GiveEgg_NoPermission.msg(sender); + return; + } + if(args.length < 3) { + Message.Boss_GiveEgg_InvalidArgs.msg(sender); + return; + } + + int amount = 1; + + if(args.length == 4) { + String amountInput = args[3]; + + if(NumberUtils.get().isInt(amountInput)) { + amount = Integer.valueOf(amountInput); + } else { + Message.General_NotNumber.msg(sender); + return; + } + } + + String playerInput = args[2]; + Player player = Bukkit.getPlayer(playerInput); + + if(player == null) { + Message.General_NotOnline.msg(sender, playerInput); + return; + } + + String bossInput = args[1]; + BossEntity bossEntity = this.bossesFileManager.getBossEntity(bossInput); + + if(bossEntity == null) { + Message.Boss_GiveEgg_InvalidBoss.msg(sender); + return; + } + + ItemStack spawnItem = this.bossEntityManager.getSpawnItem(bossEntity); + + if(spawnItem == null) { + Message.Boss_GiveEgg_NotSet.msg(sender); + return; + } + + spawnItem.setAmount(amount); + player.getInventory().addItem(spawnItem); + + Message.Boss_GiveEgg_Given.msg(sender, player.getName(), amount, bossInput); + Message.Boss_GiveEgg_Received.msg(player, amount, bossInput); } } diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossCommandManager.java b/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossCommandManager.java index 60aea5f..18d374d 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossCommandManager.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossCommandManager.java @@ -33,7 +33,7 @@ public class BossCommandManager implements ILoadable { this.commandService.registerSubCommand(new BossDebugCmd(this.customBosses.getDebugManager())); this.commandService.registerSubCommand(new BossDropTableCmd(this.customBosses.getBossPanelManager())); this.commandService.registerSubCommand(new BossEditCmd(this.customBosses.getBossPanelManager())); - this.commandService.registerSubCommand(new BossGiveEggCmd()); + this.commandService.registerSubCommand(new BossGiveEggCmd(this.customBosses.getBossesFileManager(), this.customBosses.getBossEntityManager())); this.commandService.registerSubCommand(new BossHelpCmd()); this.commandService.registerSubCommand(new BossInfoCmd(this.customBosses.getBossesFileManager(), this.customBosses.getBossEntityManager())); this.commandService.registerSubCommand(new BossItemsCmd(this.customBosses.getBossPanelManager())); diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/utils/Message.java b/plugin-modules/Core/src/com/songoda/epicbosses/utils/Message.java index 35faa00..086665c 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/utils/Message.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/utils/Message.java @@ -17,7 +17,9 @@ public enum Message { General_LocationFormat("{world}, {x}, {y}, {z}"), General_MustBePlayer("&c&l(!) &cYou must be a player to use this command."), + General_NotOnline("&c&l(!) &cThe specified player, {0}, is not online or a valid player."), General_CannotSpawn("&c&l(!) &cYou cannot spawn a boss at this location! &c&l(!)"), + General_NotNumber("&c&l(!) &cThe number you have provided is not a proper number."), General_Disarmed("&4&l(!) &f&lYOU HAVE BEEN DISARMED! CHECK THE GROUND AROUND YOU FOR YOUR ITEM!"), Boss_Create_EntityTypeNotFound("&c&l(!) &cThe specified entity type {0} was not found. If you think this is an error please contact &fAMinecraftDev&c."), @@ -37,6 +39,13 @@ public enum Message { Boss_Edit_ItemStackHolderNull("&c&l(!) &cThe itemstack name that is provided for the spawn item doesn't exist or wasn't found."), Boss_Edit_CannotSpawn("&c&l(!) &cYou cannot spawn this boss while editing is enabled. If you think this is a mistake please contact an administrator to disable the editing of the boss."), + Boss_GiveEgg_NoPermission("&c&l(!) &cYou do not have access to this command."), + Boss_GiveEgg_InvalidArgs("&c&l(!) &cYou must use &n/boss giveegg [name] [player] (amount)&c to give an egg."), + Boss_GiveEgg_InvalidBoss("&c&l(!) &cThe specified boss is not a valid type."), + Boss_GiveEgg_NotSet("&c&l(!) &cThe spawn item for the {0} boss has not been set yet."), + Boss_GiveEgg_Given("&b&lEpicBosses &8» &7You have given {0} {1}x {2}'s boss spawn item."), + Boss_GiveEgg_Received("&b&lEpicBosses &8» &7You have received {0}x {1} boss spawn item(s)."), + Boss_Help_Page1( "&8&m----*--------&3&l[ &b&lBoss Help &7(Page 1/3) &3&l]&8&m--------*----\n" + "&b/boss help (page) &8» &7Displays boss commands.\n" + @@ -62,7 +71,7 @@ public enum Message { Boss_Help_Page3( "&8&m----*--------&3&l[ &b&lBoss Help &7(Page 3/3) &3&l]&8&m--------*----\n" + "&b/boss debug &8» &7Used to toggle the debug aspect of the plugin.\n" + - "&b/boss giveegg [name] [player] &8» &7Used to be given a spawn item of the boss.\n" + + "&b/boss giveegg [name] [player] (amount) &8» &7Used to be given a spawn item of the boss.\n" + "&b/boss list &8» &7Shows all the list of current boss entities.\n" + "&b\n" + "&b\n" + diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/utils/Permission.java b/plugin-modules/Core/src/com/songoda/epicbosses/utils/Permission.java index 2bc2760..acf649a 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/utils/Permission.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/utils/Permission.java @@ -13,6 +13,7 @@ public enum Permission { admin("boss.admin"), create("boss.create"), debug("boss.debug"), + give("boss.give"), reload("boss.reload"), nearby("boss.nearby"); diff --git a/pom.xml b/pom.xml index f831acd..cade8a4 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ - 1.0.0-SNAPSHOT-U51 + 1.0.0-SNAPSHOT-U52 EpicBosses com.songoda.epicbosses.CustomBosses AMinecraftDev