diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cec1e2ef..89eaf15e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,27 @@ +### Added: +- Ability to define spawner type in prizes +```yml + '1': + # The name of the item to display in the gui. + DisplayName: "Creeper Spawner" + # The enchants to display in the gui. + DisplayItem: "spawner" + # Prize settings + Settings: + # The custom model data of the item, -1 is disabled. + Custom-Model-Data: -1 + # The type of mob for the spawner. + Mob-Type: creeper + # The amount to display in the gui. + DisplayAmount: 1 + # The max range i.e. 15/100 = 15% chance to win. + MaxRange: 100 + # The chance to win i.e. 15% + Chance: 23 + Items: + - 'Item: spawner, Mob: creeper' +``` + ### Changes: - Play knockback/sounds if they don't have the required keys. - Removed runtime dependency loader. diff --git a/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java b/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java index ffc89727d..222ca7e24 100644 --- a/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java +++ b/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java @@ -10,6 +10,7 @@ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; @@ -262,6 +263,14 @@ public final boolean hasPermission(@NotNull final Player player) { builder.setCustomModelData(this.section.getInt("Settings.Custom-Model-Data", -1)); + if (this.section.contains("Settings.Mob-Type")) { + final EntityType type = ItemUtil.getEntity(this.section.getString("Settings.Mob-Type", "cow")); + + if (type != null) { + builder.setEntityType(type); + } + } + if (this.section.contains("Skull") && this.plugin.getApi() != null) { builder.setSkull(section.getString("Skull", ""), this.plugin.getApi()); } diff --git a/src/main/java/com/badbones69/crazycrates/api/utils/ItemUtils.java b/src/main/java/com/badbones69/crazycrates/api/utils/ItemUtils.java index e856a24f1..954f6ed6b 100644 --- a/src/main/java/com/badbones69/crazycrates/api/utils/ItemUtils.java +++ b/src/main/java/com/badbones69/crazycrates/api/utils/ItemUtils.java @@ -12,6 +12,7 @@ import org.bukkit.Material; import org.bukkit.block.banner.PatternType; import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; @@ -312,6 +313,13 @@ public static ItemBuilder convertString(String itemString, String section) { case "item" -> itemBuilder.withType(value.toLowerCase()); case "data" -> itemBuilder = itemBuilder.fromBase64(value); case "name" -> itemBuilder.setDisplayName(value); + case "mob" -> { + final EntityType type = ItemUtil.getEntity(value); + + if (type != null) { + itemBuilder.setEntityType(type); + } + } case "amount" -> { final Optional amount = StringUtil.tryParseInt(value); itemBuilder.setAmount(amount.map(Number::intValue).orElse(1)); @@ -347,12 +355,10 @@ public static ItemBuilder convertString(String itemString, String section) { try { DyeColor color = DyeUtil.getDyeColor(value); - if (color != null) { - PatternType patternType = ItemUtil.getPatternType(option); + PatternType patternType = ItemUtil.getPatternType(option); - if (patternType != null) { - itemBuilder.addPattern(patternType, color); - } + if (patternType != null) { + itemBuilder.addPattern(patternType, color); } } catch (Exception ignored) {} } diff --git a/src/main/resources/crates/CrateExample.yml b/src/main/resources/crates/CrateExample.yml index 09de56751..a26a44cb0 100644 --- a/src/main/resources/crates/CrateExample.yml +++ b/src/main/resources/crates/CrateExample.yml @@ -276,4 +276,23 @@ Crate: # The max range i.e. 15/100 = 15% chance to win. MaxRange: 100 # The chance to win i.e. 15% - Chance: 15 \ No newline at end of file + Chance: 15 + '7': + # The name of the item to display in the gui. + DisplayName: "Creeper Spawner" + # The enchants to display in the gui. + DisplayItem: "spawner" + # Prize settings + Settings: + # The custom model data of the item, -1 is disabled. + Custom-Model-Data: -1 + # The type of mob for the spawner. + Mob-Type: creeper + # The amount to display in the gui. + DisplayAmount: 1 + # The max range i.e. 15/100 = 15% chance to win. + MaxRange: 100 + # The chance to win i.e. 15% + Chance: 23 + Items: + - 'Item: spawner, Mob: creeper' \ No newline at end of file