Created
September 8, 2021 03:16
-
-
Save mtbarr/1f1844bd381255944d9a09c486f529fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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