mirror of
https://github.com/BentoBoxWorld/Boxed.git
synced 2024-12-03 13:23:32 +01:00
Added option to broadcast advancement completion to online players.
This commit is contained in:
parent
fc7cef52c9
commit
1e65b76ccf
@ -54,6 +54,12 @@ public class Settings implements WorldSettings {
|
||||
@ConfigEntry(path = "boxed.command.default-action")
|
||||
private String defaultPlayerAction = "go";
|
||||
|
||||
/* Boxed */
|
||||
@ConfigComment("Announce advancements. We recommend you set the game rule `/gamerule announceAdvancements false`")
|
||||
@ConfigComment("but that blocks all new advancement announcements. This setting tells Boxed to broadcast new advancements.")
|
||||
@ConfigEntry(path = "boxed.broadcast-advancements")
|
||||
private boolean broadcastAdvancements;
|
||||
|
||||
/* WORLD */
|
||||
@ConfigComment("Friendly name for this world. Used in admin commands. Must be a single word")
|
||||
@ConfigEntry(path = "world.friendly-name")
|
||||
@ -1788,4 +1794,18 @@ public class Settings implements WorldSettings {
|
||||
public void setMakeNetherPortals(boolean makeNetherPortals) {
|
||||
this.makeNetherPortals = makeNetherPortals;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the broadcastAdvancements
|
||||
*/
|
||||
public boolean isBroadcastAdvancements() {
|
||||
return broadcastAdvancements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param broadcastAdvancements the broadcastAdvancements to set
|
||||
*/
|
||||
public void setBroadcastAdvancements(boolean broadcastAdvancements) {
|
||||
this.broadcastAdvancements = broadcastAdvancements;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import java.util.stream.StreamSupport;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.advancement.Advancement;
|
||||
@ -88,6 +89,12 @@ public class AdvancementListener implements Listener {
|
||||
// Sync
|
||||
grantAdv(u, addon.getAdvManager().getIsland(island).getAdvancements());
|
||||
});
|
||||
// Broadcast
|
||||
if (addon.getSettings().isBroadcastAdvancements()) {
|
||||
Bukkit.getOnlinePlayers().stream().filter(p -> p.hasPermission(Server.BROADCAST_CHANNEL_USERS))
|
||||
.map(User::getInstance)
|
||||
.forEach(u -> u.sendMessage("boxed.user-completed", TextVariables.NAME, user.getName(), TextVariables.DESCRIPTION, this.keyToString(u, key)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,13 +111,17 @@ public class AdvancementListener implements Listener {
|
||||
|
||||
private void informPlayer(User user, NamespacedKey key, int score) {
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1F, 2F);
|
||||
user.sendMessage("boxed.completed", TextVariables.NAME, keyToString(user, key));
|
||||
user.sendMessage("boxed.size-changed", TextVariables.NUMBER, String.valueOf(score));
|
||||
|
||||
}
|
||||
|
||||
private String keyToString(User user, NamespacedKey key) {
|
||||
String adv = user.getTranslationOrNothing("boxed.advancements." + key.toString());
|
||||
if (adv.isEmpty()) {
|
||||
adv = Util.prettifyText(key.getKey().substring(key.getKey().lastIndexOf("/") + 1, key.getKey().length()));
|
||||
}
|
||||
user.sendMessage("boxed.completed", TextVariables.NAME, adv);
|
||||
user.sendMessage("boxed.size-changed", TextVariables.NUMBER, String.valueOf(score));
|
||||
|
||||
return adv;
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,6 +15,9 @@ boxed:
|
||||
# Sub-command of main player command that will be run on each player command call.
|
||||
# By default it is sub-command 'go'.
|
||||
default-action: go
|
||||
# Announce advancements. We recommend you set the game rule `/gamerule announceAdvancements false`
|
||||
# but that blocks all new advancement announcements. This setting tells Boxed to broadcast new advancements.
|
||||
broadcast-advancements: false
|
||||
world:
|
||||
# Friendly name for this world. Used in admin commands. Must be a single word
|
||||
friendly-name: Boxed
|
||||
|
@ -4,6 +4,7 @@
|
||||
boxed:
|
||||
completed: '&a [name] completed!'
|
||||
size-changed: '&a Box size increased by [number]!'
|
||||
user-completed: '&a [name] completed [description]!'
|
||||
general:
|
||||
errors:
|
||||
no-island: '&c You do not have a box!'
|
||||
|
Loading…
Reference in New Issue
Block a user