mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-14 11:24:44 +02:00
Initial annotation usage cleanup + EditorConfig
This commit is contained in:
@ -34,8 +34,7 @@ import com.plotsquared.core.util.placeholders.Placeholder;
|
||||
import com.plotsquared.core.util.placeholders.PlaceholderRegistry;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* Placeholder support for MVdWPlaceholderAPI
|
||||
@ -46,7 +45,10 @@ public class MVdWPlaceholders {
|
||||
private final Plugin plugin;
|
||||
private final PlaceholderRegistry registry;
|
||||
|
||||
public MVdWPlaceholders(@Nonnull final Plugin plugin, @Nonnull final PlaceholderRegistry registry) {
|
||||
public MVdWPlaceholders(
|
||||
final @NonNull Plugin plugin,
|
||||
final @NonNull PlaceholderRegistry registry
|
||||
) {
|
||||
this.plugin = plugin;
|
||||
this.registry = registry;
|
||||
for (final Placeholder placeholder : registry.getPlaceholders()) {
|
||||
@ -55,19 +57,24 @@ public class MVdWPlaceholders {
|
||||
PlotSquared.get().getEventDispatcher().registerListener(this);
|
||||
}
|
||||
|
||||
@Subscribe public void onNewPlaceholder(@Nonnull final PlaceholderRegistry.PlaceholderAddedEvent event) {
|
||||
@Subscribe
|
||||
public void onNewPlaceholder(final PlaceholderRegistry.@NonNull PlaceholderAddedEvent event) {
|
||||
this.addPlaceholder(event.getPlaceholder());
|
||||
}
|
||||
|
||||
private void addPlaceholder(@Nonnull final Placeholder placeholder) {
|
||||
PlaceholderAPI.registerPlaceholder(plugin, PREFIX + String.format("%s", placeholder.getKey()), placeholderReplaceEvent -> {
|
||||
if (!placeholderReplaceEvent.isOnline() || placeholderReplaceEvent.getPlayer() == null) {
|
||||
return "";
|
||||
}
|
||||
final PlotPlayer<Player> player = BukkitUtil.adapt(placeholderReplaceEvent.getPlayer());
|
||||
String key = placeholderReplaceEvent.getPlaceholder().substring(PREFIX.length());
|
||||
return registry.getPlaceholderValue(key, player);
|
||||
});
|
||||
private void addPlaceholder(final @NonNull Placeholder placeholder) {
|
||||
PlaceholderAPI.registerPlaceholder(
|
||||
plugin,
|
||||
PREFIX + String.format("%s", placeholder.getKey()),
|
||||
placeholderReplaceEvent -> {
|
||||
if (!placeholderReplaceEvent.isOnline() || placeholderReplaceEvent.getPlayer() == null) {
|
||||
return "";
|
||||
}
|
||||
final PlotPlayer<Player> player = BukkitUtil.adapt(placeholderReplaceEvent.getPlayer());
|
||||
String key = placeholderReplaceEvent.getPlaceholder().substring(PREFIX.length());
|
||||
return registry.getPlaceholderValue(key, player);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,27 +36,33 @@ public class PAPIPlaceholders extends PlaceholderExpansion {
|
||||
public PAPIPlaceholders() {
|
||||
}
|
||||
|
||||
@Override public boolean persist() {
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public boolean canRegister() {
|
||||
@Override
|
||||
public boolean canRegister() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public String getAuthor() {
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "IntellectualSites";
|
||||
}
|
||||
|
||||
@Override public String getIdentifier() {
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "plotsquared";
|
||||
}
|
||||
|
||||
@Override public String getVersion() {
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "3";
|
||||
}
|
||||
|
||||
@Override public String onPlaceholderRequest(Player p, String identifier) {
|
||||
@Override
|
||||
public String onPlaceholderRequest(Player p, String identifier) {
|
||||
final PlotPlayer<?> pl = PlotSquared.platform().playerManager().getPlayerIfExists(p.getUniqueId());
|
||||
|
||||
if (pl == null) {
|
||||
@ -66,18 +72,20 @@ public class PAPIPlaceholders extends PlaceholderExpansion {
|
||||
// PAPI specific ones that don't translate well over into other placeholder APIs
|
||||
if (identifier.startsWith("has_plot_")) {
|
||||
identifier = identifier.substring("has_plot_".length());
|
||||
if (identifier.isEmpty())
|
||||
if (identifier.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return pl.getPlotCount(identifier) > 0 ?
|
||||
PlaceholderAPIPlugin.booleanTrue() :
|
||||
PlaceholderAPIPlugin.booleanFalse();
|
||||
PlaceholderAPIPlugin.booleanTrue() :
|
||||
PlaceholderAPIPlugin.booleanFalse();
|
||||
}
|
||||
|
||||
if (identifier.startsWith("plot_count_")) {
|
||||
identifier = identifier.substring("plot_count_".length());
|
||||
if (identifier.isEmpty())
|
||||
if (identifier.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return String.valueOf(pl.getPlotCount(identifier));
|
||||
}
|
||||
|
@ -30,12 +30,12 @@ import com.plotsquared.core.configuration.caption.ChatFormatter;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class PlaceholderFormatter implements ChatFormatter {
|
||||
|
||||
@Override public void format(@Nonnull final ChatContext context) {
|
||||
@Override
|
||||
public void format(final @NonNull ChatContext context) {
|
||||
final PlotPlayer<?> recipient = context.getRecipient();
|
||||
if (recipient instanceof BukkitPlayer) {
|
||||
if (context.isRawOutput()) {
|
||||
|
Reference in New Issue
Block a user