use of com.plotsquared.core.plot.flag.GlobalFlagContainer in project PlotSquared by IntellectualSites.
the class PlaceholderRegistry method registerDefault.
private void registerDefault() {
final GlobalFlagContainer globalFlagContainer = GlobalFlagContainer.getInstance();
for (final PlotFlag<?, ?> flag : globalFlagContainer.getRecognizedPlotFlags()) {
this.registerPlaceholder(new PlotFlagPlaceholder(flag, true));
this.registerPlaceholder(new PlotFlagPlaceholder(flag, false));
}
GlobalFlagContainer.getInstance().subscribe((flag, type) -> {
this.registerPlaceholder(new PlotFlagPlaceholder(flag, true));
this.registerPlaceholder(new PlotFlagPlaceholder(flag, false));
});
this.createPlaceholder("world_name", player -> player.getLocation().getWorldName());
this.createPlaceholder("has_plot", player -> player.getPlotCount() > 0 ? "true" : "false");
this.createPlaceholder("allowed_plot_count", (player) -> {
if (player.getAllowedPlots() >= Integer.MAX_VALUE) {
// Beautifies cases with '*' permission
return legacyComponent(TranslatableCaption.of("info.infinite"), player);
}
return Integer.toString(player.getAllowedPlots());
});
this.createPlaceholder("plot_count", player -> Integer.toString(player.getPlotCount()));
this.createPlaceholder("currentplot_alias", (player, plot) -> {
if (plot.getAlias().isEmpty()) {
return legacyComponent(TranslatableCaption.of("info.none"), player);
}
return plot.getAlias();
});
this.createPlaceholder("currentplot_owner", (player, plot) -> {
final UUID plotOwner = plot.getOwnerAbs();
if (plotOwner == null) {
return legacyComponent(TranslatableCaption.of("generic.generic_unowned"), player);
}
try {
return PlayerManager.resolveName(plotOwner, false).getComponent(player);
} catch (final Exception ignored) {
}
return legacyComponent(TranslatableCaption.of("info.unknown"), player);
});
this.createPlaceholder("currentplot_members", (player, plot) -> {
if (plot.getMembers().isEmpty() && plot.getTrusted().isEmpty()) {
return legacyComponent(TranslatableCaption.of("info.none"), player);
}
return String.valueOf(plot.getMembers().size() + plot.getTrusted().size());
});
this.createPlaceholder("currentplot_members_added", (player, plot) -> {
if (plot.getMembers().isEmpty()) {
return legacyComponent(TranslatableCaption.of("info.none"), player);
}
return String.valueOf(plot.getMembers().size());
});
this.createPlaceholder("currentplot_members_trusted", (player, plot) -> {
if (plot.getTrusted().isEmpty()) {
return legacyComponent(TranslatableCaption.of("info.none"), player);
}
return String.valueOf(plot.getTrusted().size());
});
this.createPlaceholder("currentplot_members_denied", (player, plot) -> {
if (plot.getDenied().isEmpty()) {
return legacyComponent(TranslatableCaption.of("info.none"), player);
}
return String.valueOf(plot.getDenied().size());
});
this.createPlaceholder("currentplot_members_trusted_list", (player, plot) -> {
if (plot.getTrusted().isEmpty()) {
return legacyComponent(TranslatableCaption.of("info.none"), player);
}
return PlotSquared.platform().toLegacyPlatformString(PlayerManager.getPlayerList(plot.getTrusted(), player));
});
this.createPlaceholder("currentplot_members_added_list", (player, plot) -> {
if (plot.getMembers().isEmpty()) {
return legacyComponent(TranslatableCaption.of("info.none"), player);
}
return PlotSquared.platform().toLegacyPlatformString(PlayerManager.getPlayerList(plot.getMembers(), player));
});
this.createPlaceholder("currentplot_members_denied_list", (player, plot) -> {
if (plot.getDenied().isEmpty()) {
return legacyComponent(TranslatableCaption.of("info.none"), player);
}
return PlotSquared.platform().toLegacyPlatformString(PlayerManager.getPlayerList(plot.getDenied(), player));
});
this.createPlaceholder("currentplot_creationdate", (player, plot) -> {
if (plot.getTimestamp() == 0) {
return legacyComponent(TranslatableCaption.of("info.unknown"), player);
}
long creationDate = plot.getTimestamp();
SimpleDateFormat sdf = new SimpleDateFormat(Settings.Timeformat.DATE_FORMAT);
sdf.setTimeZone(TimeZone.getTimeZone(Settings.Timeformat.TIME_ZONE));
return sdf.format(creationDate);
});
this.createPlaceholder("currentplot_can_build", (player, plot) -> plot.isAdded(player.getUUID()) ? "true" : "false");
this.createPlaceholder("currentplot_x", (player, plot) -> Integer.toString(plot.getId().getX()));
this.createPlaceholder("currentplot_y", (player, plot) -> Integer.toString(plot.getId().getY()));
this.createPlaceholder("currentplot_xy", (player, plot) -> plot.getId().toString());
this.createPlaceholder("currentplot_rating", (player, plot) -> {
if (Double.isNaN(plot.getAverageRating())) {
return legacyComponent(TranslatableCaption.of("placeholder.nan"), player);
}
BigDecimal roundRating = BigDecimal.valueOf(plot.getAverageRating()).setScale(2, RoundingMode.HALF_UP);
if (!Settings.General.SCIENTIFIC) {
return String.valueOf(roundRating);
} else {
return Double.toString(plot.getAverageRating());
}
});
this.createPlaceholder("currentplot_biome", (player, plot) -> plot.getBiomeSynchronous().toString());
}
Aggregations