Skip to content

Commit

Permalink
Create PlaceholderApiExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelillo15 committed Mar 19, 2024
1 parent 10325c8 commit 7b657e7
Showing 1 changed file with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.nookure.staff.paper.placeholder;

import com.google.inject.Inject;
import com.google.inject.Injector;
import com.nookure.staff.Constants;
import com.nookure.staff.api.placeholder.Placeholder;
import com.nookure.staff.api.placeholder.PlaceholderManager;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;
import java.util.stream.Stream;

public class PlaceholderApiExtension extends PlaceholderExpansion {
@Inject
private PlaceholderManager placeholderManager;
@Inject
private Injector in;
public static final String IDENTIFIER = "nkstaff";

@Override
public @NotNull String getIdentifier() {
return IDENTIFIER;
}

@Override
public @NotNull String getAuthor() {
return "Angelillo15";
}

@Override
public @NotNull String getVersion() {
return Constants.VERSION;
}

@Override
public boolean register() {
Stream.of(
ServerCountPlaceholder.class,
StaffCountPlaceholder.class,
StaffModePlaceholder.class,
VanishPlaceholder.class
).forEach(p -> placeholderManager.registerPlaceholder(in.getInstance(p)));

return super.register();
}

@Override
public String onPlaceholderRequest(Player player, @NotNull String params) {
Optional<Placeholder> placeholder = placeholderManager.getPlaceholder(params);

if (placeholder.isEmpty()) return "Not found";

return placeholder.get().onPlaceholderRequest(player, params);
}
}

0 comments on commit 7b657e7

Please sign in to comment.