mirror of
https://github.com/BentoBoxWorld/Boxed.git
synced 2025-02-12 00:31:28 +01:00
Add two placeholders that list the number of advancements done for a box
%boxed_island_advancements% - the number of advancements for a particular user %boxed_visited_island_advancements% - the number of advancements based on where the user is located. If there is no box, the return value is "". Values are still given if the player is outside the protected area but inside the overall potential box size. Only advancements that were not automatically given are counted. https://github.com/BentoBoxWorld/Boxed/issues/20
This commit is contained in:
parent
163b324415
commit
4079f2bdc0
@ -53,6 +53,7 @@ public class Boxed extends GameModeAddon {
|
||||
private AdvancementsManager advManager;
|
||||
private DeleteGen delChunks;
|
||||
private ChunkGenerator netherChunkGenerator;
|
||||
private PlaceholdersManager phManager;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
@ -77,9 +78,6 @@ public class Boxed extends GameModeAddon {
|
||||
|
||||
adminCommand = new DefaultAdminCommand(this) {};
|
||||
|
||||
// Register listeners
|
||||
this.registerListener(new AdvancementListener(this));
|
||||
this.registerListener(new EnderPearlListener(this));
|
||||
}
|
||||
|
||||
private boolean isNoWGAPI() {
|
||||
@ -127,6 +125,15 @@ public class Boxed extends GameModeAddon {
|
||||
getPlugin().getFlagsManager().unregister(MOVE_BOX);
|
||||
}
|
||||
|
||||
// Register listeners
|
||||
this.registerListener(new AdvancementListener(this));
|
||||
this.registerListener(new EnderPearlListener(this));
|
||||
|
||||
// Register placeholders
|
||||
phManager = new PlaceholdersManager(this);
|
||||
getPlugin().getPlaceholdersManager().registerPlaceholder(this,"visited_island_advancements", phManager::getCountByLocation);
|
||||
getPlugin().getPlaceholdersManager().registerPlaceholder(this,"island_advancements", phManager::getCount);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
42
src/main/java/world/bentobox/boxed/PlaceholdersManager.java
Normal file
42
src/main/java/world/bentobox/boxed/PlaceholdersManager.java
Normal file
@ -0,0 +1,42 @@
|
||||
package world.bentobox.boxed;
|
||||
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
|
||||
/**
|
||||
* Handles place holders
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class PlaceholdersManager {
|
||||
|
||||
private final Boxed addon;
|
||||
|
||||
public PlaceholdersManager(Boxed addon) {
|
||||
this.addon = addon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get boxed advancement count
|
||||
* @param user owner or team member
|
||||
* @return string of advancement count
|
||||
*/
|
||||
public String getCount(User user) {
|
||||
if (user == null || user.getUniqueId() == null) return "";
|
||||
Island i = addon.getIslands().getIsland(addon.getOverWorld(), user);
|
||||
return i == null ? "" : String.valueOf(addon.getAdvManager().getIsland(i).getAdvancements().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the advancement count based on user's location
|
||||
* @param user user
|
||||
* @return string of advancement count
|
||||
*/
|
||||
public String getCountByLocation(User user) {
|
||||
if (user == null || user.getUniqueId() == null) return "";
|
||||
return addon.getIslands().getIslandAt(user.getLocation())
|
||||
.map(i -> String.valueOf(addon.getAdvManager().getIsland(i).getAdvancements().size())).orElse("");
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user