-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04faa7f
commit 9774a59
Showing
5 changed files
with
111 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/main/java/world/bentobox/topblock/PlaceholderManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package world.bentobox.topblock; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
|
||
import org.eclipse.jdt.annotation.NonNull; | ||
|
||
import world.bentobox.bentobox.BentoBox; | ||
import world.bentobox.bentobox.api.addons.GameModeAddon; | ||
import world.bentobox.bentobox.managers.PlaceholdersManager; | ||
import world.bentobox.bentobox.managers.RanksManager; | ||
import world.bentobox.topblock.TopBlockManager.TopTenData; | ||
|
||
/** | ||
* Handles TopBlock placeholders | ||
* @author tastybento | ||
* | ||
*/ | ||
public class PlaceholderManager { | ||
|
||
private final TopBlock addon; | ||
private final BentoBox plugin; | ||
|
||
public PlaceholderManager(TopBlock addon) { | ||
this.addon = addon; | ||
this.plugin = addon.getPlugin(); | ||
|
||
} | ||
|
||
protected void registerPlaceholders(GameModeAddon gm) { | ||
if (plugin.getPlaceholdersManager() == null) return; | ||
PlaceholdersManager bpm = plugin.getPlaceholdersManager(); | ||
@NonNull List<TopTenData> rList = addon.getManager().getTopTen(TopBlock.TEN); | ||
// Register Top Ten Placeholders | ||
for (int i = 0; i < TopBlock.TEN; i++) { | ||
TopTenData r = i < rList.size() ? rList.get(i) : null; | ||
int rank = i + 1; | ||
// Name of island owner | ||
bpm.registerPlaceholder(gm, "island_player_name_top_" + rank, u -> r == null ? "" : getPlayerName(r)); | ||
// Name of island team members | ||
bpm.registerPlaceholder(gm, "island_member_names_top_" + rank, u -> r == null ? "" : getMemberNames(r)); | ||
// Name of the phase they have reached | ||
bpm.registerPlaceholder(gm, "island_phase_name_top_" + rank, u -> r == null ? "" : r.phaseName()); | ||
// Phase Number | ||
bpm.registerPlaceholder(gm, "island_phase_number_top_" + rank, u -> r == null ? "" : getPhaseNumber(r)); | ||
// Block Count | ||
bpm.registerPlaceholder(gm, "island_count_top_" + rank, u -> r == null ? "" : String.valueOf(r.blockNumber())); | ||
// Lifetime count | ||
bpm.registerPlaceholder(gm, "island_lifetime_top_" + rank, u -> r == null ? "" : String.valueOf(r.lifetime())); | ||
} | ||
} | ||
|
||
/** | ||
* Gets a comma separated string of island member names | ||
* @param r Top ten entry | ||
* @return comma separated string of island member names | ||
*/ | ||
String getMemberNames(TopTenData r) { | ||
// Sort members by rank | ||
return r.island().getMembers().entrySet().stream() | ||
.filter(e -> e.getValue() >= RanksManager.MEMBER_RANK) | ||
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue())) | ||
.map(Map.Entry::getKey) | ||
.map(addon.getPlayers()::getName) | ||
.collect(Collectors.joining(",")); | ||
} | ||
|
||
private String getPlayerName(TopTenData r) { | ||
UUID owner = r.island().getOwner(); | ||
if (owner == null) return ""; | ||
return Objects.requireNonNull(addon.getPlayers().getName(owner), ""); | ||
} | ||
|
||
private String getPhaseNumber(TopTenData r) { | ||
long c = addon.getaOneBlock().getOneBlockManager().getBlockProbs().entrySet().stream() | ||
.filter(en -> en.getKey() < r.blockNumber()).count(); | ||
return String.valueOf(c); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters