diff --git a/paper/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java b/paper/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java index e13002923..da0880ae6 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java @@ -93,6 +93,10 @@ public class Crate { private @NotNull final SettingsManager config = ConfigManager.getConfig(); + private boolean broadcastToggle = false; + private List broadcastMessages = new ArrayList<>(); + private String broadcastPermission = ""; + /** * @param name The name of the crate. * @param crateType The crate type of the crate. @@ -124,6 +128,11 @@ public Crate(@NotNull final String name, this.requiredKeys = requiredKeys; this.prizeMessage = prizeMessage; this.prizeCommands = prizeCommands; + + this.broadcastToggle = this.file.getBoolean("Crate.Settings.Broadcast.Toggle", false); + this.broadcastMessages = this.file.getStringList("Crate.Settings.Broadcast.Messages"); + this.broadcastPermission = this.file.getString("Crate.Settings.Broadcast.Permission", ""); + this.prizes = prizes; this.crateType = crateType; this.previewToggle = file.getBoolean("Crate.Preview.Toggle", false); @@ -220,7 +229,19 @@ public final boolean isPreviewTierToggle() { public @NotNull final AbstractCrateManager getManager() { return this.manager; } - + + public final boolean isBroadcastToggle() { + return this.broadcastToggle; + } + + public final String getBroadcastPermission() { + return this.broadcastPermission; + } + + public final List getBroadcastMessages() { + return this.broadcastMessages; + } + /** * Set the preview lines for a Crate. * diff --git a/paper/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java b/paper/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java index 601d46438..d7151eed0 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java +++ b/paper/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java @@ -297,25 +297,35 @@ public final boolean hasPermission(@NotNull final Player player) { } public void broadcast(final Crate crate) { - if (!this.broadcast) return; - final String fancyName = crate.getCrateName(); - final String prizeName = getPrizeName(); - final String strippedName = getStrippedName(); + + if (this.broadcast) { + this.plugin.getServer().getOnlinePlayers().forEach(player -> { + if (!this.broadcastPermission.isEmpty() && player.hasPermission(this.broadcastPermission)) return; + + this.broadcastMessages.forEach(message -> sendMessage(player, message, fancyName)); + }); + + return; + } this.plugin.getServer().getOnlinePlayers().forEach(player -> { - if (!this.broadcastPermission.isEmpty() && player.hasPermission(this.broadcastPermission)) return; - - this.broadcastMessages.forEach(message -> player.sendMessage(AdvUtil.parse(message, new HashMap<>() {{ - put("%player%", player.getName()); - put("%crate%", fancyName); - put("%reward%", prizeName); - put("%maxpulls%", String.valueOf(maxPulls)); - put("%reward_stripped%", strippedName); - }}, player))); + if (!crate.getBroadcastPermission().isEmpty() && player.hasPermission(crate.getBroadcastPermission())) return; + + crate.getBroadcastMessages().forEach(message -> sendMessage(player, message, fancyName)); }); } + private void sendMessage(final Player player, final String message, final String fancyName) { + player.sendMessage(AdvUtil.parse(message, new HashMap<>() {{ + put("%player%", player.getName()); + put("%crate%", fancyName); + put("%reward%", getPrizeName()); + put("%maxpulls%", String.valueOf(getMaxPulls())); + put("%reward_stripped%", getStrippedName()); + }}, player)); + } + private @NotNull ItemBuilder display() { ItemBuilder builder = new ItemBuilder(); diff --git a/paper/src/main/resources/crates/CrateExample.yml b/paper/src/main/resources/crates/CrateExample.yml index 1d6ef0cb8..4849c3aaa 100644 --- a/paper/src/main/resources/crates/CrateExample.yml +++ b/paper/src/main/resources/crates/CrateExample.yml @@ -71,6 +71,17 @@ Crate: # A default command if the prize doesn't have any commands # i.e. Commands: [] or the value isn't there. Prize-Commands: [] + # Global Settings + Settings: + # Broadcast a message to the server + Broadcast: + # If the messages should be sent. + Toggle: false + # The messages to broadcast. + Messages: + - '%player% won the prize %reward%.' + # If the player has this permission, they don't get the broadcast. + Permission: 'your_permission' # Item the crate is in the GUI Item: "diamond" # The custom model data of the item, -1 is disabled.