mirror of
https://github.com/TotalFreedomMC/TF-PlotSquared.git
synced 2024-12-23 00:15:06 +00:00
Do placeholders better.
- Still allow parsing of placeholder if no plot is required and plot is null. - Properly check if the player is null before getting the plot, and if the plot is null - These were still issues before my initial "fix" city
This commit is contained in:
parent
5bd53436df
commit
ccb43d0661
1 changed files with 40 additions and 63 deletions
|
@ -69,7 +69,10 @@ public class Placeholders extends PlaceholderExpansion {
|
||||||
@Override
|
@Override
|
||||||
public String onPlaceholderRequest(Player p, String identifier) {
|
public String onPlaceholderRequest(Player p, String identifier) {
|
||||||
final PlotPlayer pl = PlotPlayer.get(p.getName());
|
final PlotPlayer pl = PlotPlayer.get(p.getName());
|
||||||
final Plot plot = pl.getCurrentPlot();
|
|
||||||
|
if (pl == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
if (identifier.startsWith("has_plot_")) {
|
if (identifier.startsWith("has_plot_")) {
|
||||||
if (identifier.split("has_plot_").length != 2)
|
if (identifier.split("has_plot_").length != 2)
|
||||||
|
@ -89,15 +92,35 @@ public class Placeholders extends PlaceholderExpansion {
|
||||||
return String.valueOf(pl.getPlotCount(identifier));
|
return String.valueOf(pl.getPlotCount(identifier));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (identifier) {
|
||||||
|
case "currentplot_world": {
|
||||||
|
return p.getWorld().getName();
|
||||||
|
}
|
||||||
|
case "has_plot": {
|
||||||
|
return (pl.getPlotCount() > 0) ?
|
||||||
|
PlaceholderAPIPlugin.booleanTrue() :
|
||||||
|
PlaceholderAPIPlugin.booleanFalse();
|
||||||
|
}
|
||||||
|
case "allowed_plot_count": {
|
||||||
|
return String.valueOf(pl.getAllowedPlots());
|
||||||
|
}
|
||||||
|
case "plot_count": {
|
||||||
|
return String.valueOf(pl.getPlotCount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Plot plot = pl.getCurrentPlot();
|
||||||
|
|
||||||
|
if (plot == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
switch (identifier) {
|
switch (identifier) {
|
||||||
case "currentplot_alias": {
|
case "currentplot_alias": {
|
||||||
return (pl.getCurrentPlot() != null) ? pl.getCurrentPlot().getAlias() : "";
|
return plot.getAlias();
|
||||||
}
|
}
|
||||||
case "currentplot_owner": {
|
case "currentplot_owner": {
|
||||||
if (pl.getCurrentPlot() == null) {
|
final Set<UUID> o = plot.getOwners();
|
||||||
return "";
|
|
||||||
}
|
|
||||||
final Set<UUID> o = pl.getCurrentPlot().getOwners();
|
|
||||||
if (o == null || o.isEmpty()) {
|
if (o == null || o.isEmpty()) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -114,94 +137,48 @@ public class Placeholders extends PlaceholderExpansion {
|
||||||
name = Bukkit.getOfflinePlayer(uid).getName();
|
name = Bukkit.getOfflinePlayer(uid).getName();
|
||||||
return name != null ? name : "unknown";
|
return name != null ? name : "unknown";
|
||||||
}
|
}
|
||||||
case "currentplot_world": {
|
|
||||||
return p.getWorld().getName();
|
|
||||||
}
|
|
||||||
case "has_plot": {
|
|
||||||
return (pl.getPlotCount() > 0) ?
|
|
||||||
PlaceholderAPIPlugin.booleanTrue() :
|
|
||||||
PlaceholderAPIPlugin.booleanFalse();
|
|
||||||
}
|
|
||||||
case "allowed_plot_count": {
|
|
||||||
return String.valueOf(pl.getAllowedPlots());
|
|
||||||
}
|
|
||||||
case "plot_count": {
|
|
||||||
return String.valueOf(pl.getPlotCount());
|
|
||||||
}
|
|
||||||
case "currentplot_members": {
|
case "currentplot_members": {
|
||||||
if (pl.getCurrentPlot() == null) {
|
if (plot.getMembers() == null && plot.getTrusted() == null) {
|
||||||
return "";
|
|
||||||
}
|
|
||||||
if (pl.getCurrentPlot().getMembers() == null
|
|
||||||
&& pl.getCurrentPlot().getTrusted() == null) {
|
|
||||||
return "0";
|
return "0";
|
||||||
}
|
}
|
||||||
return String.valueOf(
|
return String.valueOf(plot.getMembers().size() + plot.getTrusted().size());
|
||||||
pl.getCurrentPlot().getMembers().size() + pl.getCurrentPlot().getTrusted()
|
|
||||||
.size());
|
|
||||||
}
|
}
|
||||||
case "currentplot_members_added": {
|
case "currentplot_members_added": {
|
||||||
if (pl.getCurrentPlot() == null) {
|
if (plot.getMembers() == null) {
|
||||||
return "";
|
|
||||||
}
|
|
||||||
if (pl.getCurrentPlot().getMembers() == null) {
|
|
||||||
return "0";
|
return "0";
|
||||||
}
|
}
|
||||||
return String.valueOf(pl.getCurrentPlot().getMembers().size());
|
return String.valueOf(plot.getMembers().size());
|
||||||
}
|
}
|
||||||
case "currentplot_members_trusted": {
|
case "currentplot_members_trusted": {
|
||||||
if (pl.getCurrentPlot() == null) {
|
if (plot.getTrusted() == null) {
|
||||||
return "";
|
|
||||||
}
|
|
||||||
if (pl.getCurrentPlot().getTrusted() == null) {
|
|
||||||
return "0";
|
return "0";
|
||||||
}
|
}
|
||||||
return String.valueOf(plot.getTrusted().size());
|
return String.valueOf(plot.getTrusted().size());
|
||||||
}
|
}
|
||||||
case "currentplot_members_denied": {
|
case "currentplot_members_denied": {
|
||||||
if (pl.getCurrentPlot() == null) {
|
if (plot.getDenied() == null) {
|
||||||
return "";
|
|
||||||
}
|
|
||||||
if (pl.getCurrentPlot().getDenied() == null) {
|
|
||||||
return "0";
|
return "0";
|
||||||
}
|
}
|
||||||
return String.valueOf(pl.getCurrentPlot().getDenied().size());
|
return String.valueOf(plot.getDenied().size());
|
||||||
}
|
}
|
||||||
case "has_build_rights": {
|
case "has_build_rights": {
|
||||||
return (pl.getCurrentPlot() != null) ?
|
return plot.isAdded(pl.getUUID()) ?
|
||||||
((pl.getCurrentPlot().isAdded(pl.getUUID())) ?
|
PlaceholderAPIPlugin.booleanTrue() :
|
||||||
PlaceholderAPIPlugin.booleanTrue() :
|
PlaceholderAPIPlugin.booleanFalse();
|
||||||
PlaceholderAPIPlugin.booleanFalse()) :
|
|
||||||
"";
|
|
||||||
}
|
}
|
||||||
case "currentplot_x": {
|
case "currentplot_x": {
|
||||||
if (pl.getCurrentPlot() == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return String.valueOf(plot.getId().getX());
|
return String.valueOf(plot.getId().getX());
|
||||||
}
|
}
|
||||||
case "currentplot_y": {
|
case "currentplot_y": {
|
||||||
if (pl.getCurrentPlot() == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return String.valueOf(plot.getId().getY());
|
return String.valueOf(plot.getId().getY());
|
||||||
}
|
}
|
||||||
case "currentplot_xy": {
|
case "currentplot_xy": {
|
||||||
if (pl.getCurrentPlot() == null) {
|
return plot.getId().getX() + ";" + plot.getId().getY();
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return pl.getCurrentPlot().getId().getX() + ";" + pl.getCurrentPlot().getId().getY();
|
|
||||||
}
|
}
|
||||||
case "currentplot_rating": {
|
case "currentplot_rating": {
|
||||||
if (pl.getCurrentPlot() == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return String.valueOf(plot.getAverageRating());
|
return String.valueOf(plot.getAverageRating());
|
||||||
}
|
}
|
||||||
case "currentplot_biome": {
|
case "currentplot_biome": {
|
||||||
if (pl.getCurrentPlot() == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return plot.getBiomeSynchronous() + "";
|
return plot.getBiomeSynchronous() + "";
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue