Fix plot owner placeholder. Fixes PS-62.

This commit is contained in:
Alexander Söderberg 2020-07-09 16:38:46 +02:00
parent f2191cb731
commit e05d817482
No known key found for this signature in database
GPG Key ID: C0207FF7EA146678
2 changed files with 31 additions and 18 deletions

View File

@ -26,17 +26,16 @@
package com.plotsquared.bukkit.placeholder;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.util.MainUtil;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.Set;
import java.util.UUID;
public class Placeholders extends PlaceholderExpansion {
@ -117,23 +116,16 @@ public class Placeholders extends PlaceholderExpansion {
return plot.getAlias();
}
case "currentplot_owner": {
final Set<UUID> o = plot.getOwners();
if (o == null || o.isEmpty()) {
return "";
}
final UUID uid = (UUID) o.toArray()[0];
if (uid == null) {
final UUID plotOwner = plot.getOwnerAbs();
if (plotOwner == null) {
return "";
}
String name = PlotSquared.get().getImpromptuUUIDPipeline()
.getSingle(uid, Settings.UUID.BLOCKING_TIMEOUT);
try {
return MainUtil.getName(plotOwner, false);
} catch (final Exception ignored) {}
if (name != null) {
return name;
}
name = Bukkit.getOfflinePlayer(uid).getName();
final String name = Bukkit.getOfflinePlayer(plotOwner).getName();
return name != null ? name : "unknown";
}
case "currentplot_members": {

View File

@ -372,10 +372,21 @@ public class MainUtil {
/**
* Get the name from a UUID.
*
* @param owner
* @param owner Owner UUID
* @return The player's name, None, Everyone or Unknown
*/
@NotNull public static String getName(UUID owner) {
@NotNull public static String getName(@Nullable UUID owner) {
return getName(owner, true);
}
/**
* Get the name from a UUID.
*
* @param owner Owner UUID
* @param blocking Whether or not the operation can be blocking
* @return The player's name, None, Everyone or Unknown
*/
@NotNull public static String getName(@Nullable final UUID owner, final boolean blocking) {
if (owner == null) {
return Captions.NONE.getTranslated();
}
@ -385,7 +396,17 @@ public class MainUtil {
if (owner.equals(DBFunc.SERVER)) {
return Captions.SERVER.getTranslated();
}
String name = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(owner, Settings.UUID.BLOCKING_TIMEOUT);
final String name;
if (blocking) {
name = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(owner, Settings.UUID.BLOCKING_TIMEOUT);
} else {
final UUIDMapping uuidMapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(owner);
if (uuidMapping != null) {
name = uuidMapping.getUsername();
} else {
name = null;
}
}
if (name == null) {
return Captions.UNKNOWN.getTranslated();
}