Skip to content

Commit

Permalink
add entity type support to prizes
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Jul 22, 2024
1 parent 515c74a commit d9987af
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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: "<green>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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/com/badbones69/crazycrates/api/utils/ItemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Number> amount = StringUtil.tryParseInt(value);
itemBuilder.setAmount(amount.map(Number::intValue).orElse(1));
Expand Down Expand Up @@ -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) {}
}
Expand Down
21 changes: 20 additions & 1 deletion src/main/resources/crates/CrateExample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Chance: 15
'7':
# The name of the item to display in the gui.
DisplayName: "<green>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'

0 comments on commit d9987af

Please sign in to comment.