mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 07:06:44 +01:00
Never return null in Placeholder. Also slight cleanup.
This commit is contained in:
parent
73dae7842d
commit
0fa99d7940
@ -200,7 +200,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||||
new Placeholders(this).register();
|
new Placeholders().register();
|
||||||
if (Settings.Enabled_Components.EXTERNAL_PLACEHOLDERS) {
|
if (Settings.Enabled_Components.EXTERNAL_PLACEHOLDERS) {
|
||||||
ChatFormatter.formatters.add(new PlaceholderFormatter());
|
ChatFormatter.formatters.add(new PlaceholderFormatter());
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.bukkit.placeholder;
|
package com.plotsquared.bukkit.placeholder;
|
||||||
|
|
||||||
import com.plotsquared.bukkit.BukkitMain;
|
|
||||||
import com.plotsquared.core.plot.Plot;
|
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
|
import com.plotsquared.core.plot.Plot;
|
||||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
@ -39,7 +38,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class Placeholders extends PlaceholderExpansion {
|
public class Placeholders extends PlaceholderExpansion {
|
||||||
|
|
||||||
public Placeholders(BukkitMain plugin) {
|
public Placeholders() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -64,26 +63,27 @@ public class Placeholders extends PlaceholderExpansion {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getVersion() {
|
public String getVersion() {
|
||||||
return "2.3";
|
return "2.4";
|
||||||
}
|
}
|
||||||
|
|
||||||
@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();
|
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) return null;
|
if (identifier.split("has_plot_").length != 2)
|
||||||
|
return "";
|
||||||
|
|
||||||
identifier = identifier.split("has_plot_")[1];
|
identifier = identifier.split("has_plot_")[1];
|
||||||
return pl.getPlotCount(identifier) > 0 ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse();
|
return pl.getPlotCount(identifier) > 0 ?
|
||||||
|
PlaceholderAPIPlugin.booleanTrue() :
|
||||||
|
PlaceholderAPIPlugin.booleanFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (identifier.startsWith("plot_count_")) {
|
if (identifier.startsWith("plot_count_")) {
|
||||||
if (identifier.split("plot_count_").length != 2) return null;
|
if (identifier.split("plot_count_").length != 2)
|
||||||
|
return "";
|
||||||
|
|
||||||
identifier = identifier.split("plot_count_")[1];
|
identifier = identifier.split("plot_count_")[1];
|
||||||
return String.valueOf(pl.getPlotCount(identifier));
|
return String.valueOf(pl.getPlotCount(identifier));
|
||||||
@ -106,13 +106,20 @@ public class Placeholders extends PlaceholderExpansion {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
final String name = UUIDHandler.getName(uid);
|
final String name = UUIDHandler.getName(uid);
|
||||||
return (name != null) ? name : ((Bukkit.getOfflinePlayer(uid) != null) ? Bukkit.getOfflinePlayer(uid).getName() : "unknown");
|
|
||||||
|
return (name != null) ?
|
||||||
|
name :
|
||||||
|
((Bukkit.getOfflinePlayer(uid).getName() != null) ?
|
||||||
|
Bukkit.getOfflinePlayer(uid).getName() :
|
||||||
|
"unknown");
|
||||||
}
|
}
|
||||||
case "currentplot_world": {
|
case "currentplot_world": {
|
||||||
return p.getWorld().getName();
|
return p.getWorld().getName();
|
||||||
}
|
}
|
||||||
case "has_plot": {
|
case "has_plot": {
|
||||||
return (pl.getPlotCount() > 0) ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse();
|
return (pl.getPlotCount() > 0) ?
|
||||||
|
PlaceholderAPIPlugin.booleanTrue() :
|
||||||
|
PlaceholderAPIPlugin.booleanFalse();
|
||||||
}
|
}
|
||||||
case "allowed_plot_count": {
|
case "allowed_plot_count": {
|
||||||
return String.valueOf(pl.getAllowedPlots());
|
return String.valueOf(pl.getAllowedPlots());
|
||||||
@ -124,10 +131,13 @@ public class Placeholders extends PlaceholderExpansion {
|
|||||||
if (pl.getCurrentPlot() == null) {
|
if (pl.getCurrentPlot() == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
if (pl.getCurrentPlot().getMembers() == null && pl.getCurrentPlot().getTrusted() == null) {
|
if (pl.getCurrentPlot().getMembers() == null
|
||||||
|
&& pl.getCurrentPlot().getTrusted() == null) {
|
||||||
return "0";
|
return "0";
|
||||||
}
|
}
|
||||||
return String.valueOf(pl.getCurrentPlot().getMembers().size() + pl.getCurrentPlot().getTrusted().size());
|
return String.valueOf(
|
||||||
|
pl.getCurrentPlot().getMembers().size() + pl.getCurrentPlot().getTrusted()
|
||||||
|
.size());
|
||||||
}
|
}
|
||||||
case "currentplot_members_added": {
|
case "currentplot_members_added": {
|
||||||
if (pl.getCurrentPlot() == null) {
|
if (pl.getCurrentPlot() == null) {
|
||||||
@ -157,25 +167,29 @@ public class Placeholders extends PlaceholderExpansion {
|
|||||||
return String.valueOf(pl.getCurrentPlot().getDenied().size());
|
return String.valueOf(pl.getCurrentPlot().getDenied().size());
|
||||||
}
|
}
|
||||||
case "has_build_rights": {
|
case "has_build_rights": {
|
||||||
return (pl.getCurrentPlot() != null) ? ((pl.getCurrentPlot().isAdded(pl.getUUID())) ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse()) : "";
|
return (pl.getCurrentPlot() != null) ?
|
||||||
|
((pl.getCurrentPlot().isAdded(pl.getUUID())) ?
|
||||||
|
PlaceholderAPIPlugin.booleanTrue() :
|
||||||
|
PlaceholderAPIPlugin.booleanFalse()) :
|
||||||
|
"";
|
||||||
}
|
}
|
||||||
case "currentplot_x": {
|
case "currentplot_x": {
|
||||||
if (pl.getCurrentPlot() == null) {
|
if (pl.getCurrentPlot() == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return String.valueOf(plot.getId().x);
|
return String.valueOf(plot.getId().getX());
|
||||||
}
|
}
|
||||||
case "currentplot_y": {
|
case "currentplot_y": {
|
||||||
if (pl.getCurrentPlot() == null) {
|
if (pl.getCurrentPlot() == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return String.valueOf(plot.getId().y);
|
return String.valueOf(plot.getId().getY());
|
||||||
}
|
}
|
||||||
case "currentplot_xy": {
|
case "currentplot_xy": {
|
||||||
if (pl.getCurrentPlot() == null) {
|
if (pl.getCurrentPlot() == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return pl.getCurrentPlot().getId().x + ";" + pl.getCurrentPlot().getId().y;
|
return pl.getCurrentPlot().getId().getX() + ";" + pl.getCurrentPlot().getId().getY();
|
||||||
}
|
}
|
||||||
case "currentplot_rating": {
|
case "currentplot_rating": {
|
||||||
if (pl.getCurrentPlot() == null) {
|
if (pl.getCurrentPlot() == null) {
|
||||||
@ -192,6 +206,6 @@ public class Placeholders extends PlaceholderExpansion {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return null;
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user