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")
|
@ConfigEntry(path = "boxed.command.default-action")
|
||||||
private String defaultPlayerAction = "go";
|
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 */
|
/* WORLD */
|
||||||
@ConfigComment("Friendly name for this world. Used in admin commands. Must be a single word")
|
@ConfigComment("Friendly name for this world. Used in admin commands. Must be a single word")
|
||||||
@ConfigEntry(path = "world.friendly-name")
|
@ConfigEntry(path = "world.friendly-name")
|
||||||
@ -1788,4 +1794,18 @@ public class Settings implements WorldSettings {
|
|||||||
public void setMakeNetherPortals(boolean makeNetherPortals) {
|
public void setMakeNetherPortals(boolean makeNetherPortals) {
|
||||||
this.makeNetherPortals = 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.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.Server;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.Statistic;
|
import org.bukkit.Statistic;
|
||||||
import org.bukkit.advancement.Advancement;
|
import org.bukkit.advancement.Advancement;
|
||||||
@ -88,8 +89,14 @@ public class AdvancementListener implements Listener {
|
|||||||
// Sync
|
// Sync
|
||||||
grantAdv(u, addon.getAdvManager().getIsland(island).getAdvancements());
|
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)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synchronize the player's advancements to that of the island.
|
* Synchronize the player's advancements to that of the island.
|
||||||
* Player's advancements should be cleared before calling this othewise they will get add the island ones as well.
|
* Player's advancements should be cleared before calling this othewise they will get add the island ones as well.
|
||||||
@ -104,13 +111,17 @@ public class AdvancementListener implements Listener {
|
|||||||
|
|
||||||
private void informPlayer(User user, NamespacedKey key, int score) {
|
private void informPlayer(User user, NamespacedKey key, int score) {
|
||||||
user.getPlayer().playSound(user.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1F, 2F);
|
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());
|
String adv = user.getTranslationOrNothing("boxed.advancements." + key.toString());
|
||||||
if (adv.isEmpty()) {
|
if (adv.isEmpty()) {
|
||||||
adv = Util.prettifyText(key.getKey().substring(key.getKey().lastIndexOf("/") + 1, key.getKey().length()));
|
adv = Util.prettifyText(key.getKey().substring(key.getKey().lastIndexOf("/") + 1, key.getKey().length()));
|
||||||
}
|
}
|
||||||
user.sendMessage("boxed.completed", TextVariables.NAME, adv);
|
return adv;
|
||||||
user.sendMessage("boxed.size-changed", TextVariables.NUMBER, String.valueOf(score));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,6 +15,9 @@ boxed:
|
|||||||
# Sub-command of main player command that will be run on each player command call.
|
# Sub-command of main player command that will be run on each player command call.
|
||||||
# By default it is sub-command 'go'.
|
# By default it is sub-command 'go'.
|
||||||
default-action: 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:
|
world:
|
||||||
# Friendly name for this world. Used in admin commands. Must be a single word
|
# Friendly name for this world. Used in admin commands. Must be a single word
|
||||||
friendly-name: Boxed
|
friendly-name: Boxed
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
boxed:
|
boxed:
|
||||||
completed: '&a [name] completed!'
|
completed: '&a [name] completed!'
|
||||||
size-changed: '&a Box size increased by [number]!'
|
size-changed: '&a Box size increased by [number]!'
|
||||||
|
user-completed: '&a [name] completed [description]!'
|
||||||
general:
|
general:
|
||||||
errors:
|
errors:
|
||||||
no-island: '&c You do not have a box!'
|
no-island: '&c You do not have a box!'
|
||||||
|
Loading…
Reference in New Issue
Block a user