Skip to content

Instantly share code, notes, and snippets.

@mtbarr
Created September 8, 2021 03:16
Show Gist options
  • Save mtbarr/1f1844bd381255944d9a09c486f529fb to your computer and use it in GitHub Desktop.
Save mtbarr/1f1844bd381255944d9a09c486f529fb to your computer and use it in GitHub Desktop.
package io.github.sasuked.plugins.nametagsplugin.replacement;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import java.util.function.BiFunction;
public class PlaceholderBuilder {
private String author;
private String identifier;
private String version;
private BiFunction<String, OfflinePlayer, String> replacement;
public PlaceholderBuilder author(String author) {
this.author = author;
return this;
}
public PlaceholderBuilder identifier(String identifier) {
this.identifier = identifier;
return this;
}
public PlaceholderBuilder version(String version) {
this.version = version;
return this;
}
public PlaceholderBuilder replacement(BiFunction<String, OfflinePlayer, String> replacement) {
this.replacement = replacement;
return this;
}
public PlaceholderExpansion build() {
return new PlaceholderDefinition(this);
}
public String toString() {
return "Placeholder.PlaceholderBuilder(author=" + this.author + ", identifier=" + this.identifier + ", version=" + this.version + ", replacement=" + this.replacement + ")";
}
class PlaceholderDefinition extends PlaceholderExpansion {
private final PlaceholderBuilder placeholder;
public PlaceholderDefinition(io.github.sasuked.plugins.nametagsplugin.replacement.PlaceholderBuilder placeholder) {
this.placeholder = placeholder;
}
@Override
public @NotNull String getIdentifier() {
return placeholder.identifier;
}
@Override
public @NotNull String getAuthor() {
return placeholder.author;
}
@Override
public @NotNull String getVersion() {
return placeholder.version;
}
@Override
public String onRequest(OfflinePlayer player, @NotNull String params) {
return placeholder.replacement.apply(params, player);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment