-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
122 additions
and
11 deletions.
There are no files selected for viewing
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
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
43 changes: 43 additions & 0 deletions
43
...a/me/hsgamer/topper/spigot/plugin/hook/miniplaceholders/MiniPlaceholderValueProvider.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package me.hsgamer.topper.spigot.plugin.hook.miniplaceholders; | ||
|
||
import io.github.miniplaceholders.api.MiniPlaceholders; | ||
import me.hsgamer.topper.spigot.plugin.TopperPlugin; | ||
import me.hsgamer.topper.spigot.plugin.holder.provider.NumberStringValueProvider; | ||
import net.kyori.adventure.text.Component; | ||
import net.kyori.adventure.text.minimessage.MiniMessage; | ||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; | ||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
public class MiniPlaceholderValueProvider extends NumberStringValueProvider { | ||
private final String placeholder; | ||
|
||
public MiniPlaceholderValueProvider(TopperPlugin plugin, Map<String, Object> map) { | ||
super(plugin, map); | ||
placeholder = Optional.ofNullable(map.get("placeholder")).map(Object::toString).orElse(""); | ||
} | ||
|
||
@Override | ||
protected String getDisplayName() { | ||
return placeholder; | ||
} | ||
|
||
@Override | ||
protected Optional<String> getString(UUID uuid) { | ||
Player player = plugin.getServer().getPlayer(uuid); | ||
if (player == null) { | ||
return Optional.empty(); | ||
} | ||
|
||
TagResolver resolver = MiniPlaceholders.getAudiencePlaceholders(player); | ||
|
||
Component component = MiniMessage.miniMessage().deserialize(placeholder, resolver); | ||
String parsed = PlainTextComponentSerializer.plainText().serialize(component).trim(); | ||
|
||
return Optional.of(parsed); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...main/java/me/hsgamer/topper/spigot/plugin/hook/miniplaceholders/MiniPlaceholdersHook.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package me.hsgamer.topper.spigot.plugin.hook.miniplaceholders; | ||
|
||
import io.github.miniplaceholders.api.Expansion; | ||
import io.github.miniplaceholders.api.utils.TagsUtils; | ||
import io.github.projectunified.minelib.plugin.base.Loadable; | ||
import me.hsgamer.topper.spigot.plugin.TopperPlugin; | ||
import me.hsgamer.topper.spigot.plugin.builder.ValueProviderBuilder; | ||
import me.hsgamer.topper.spigot.plugin.manager.TopQueryManager; | ||
import org.bukkit.entity.Player; | ||
|
||
public class MiniPlaceholdersHook implements Loadable { | ||
private final TopperPlugin plugin; | ||
private final Expansion expansion; | ||
|
||
public MiniPlaceholdersHook(TopperPlugin plugin) { | ||
this.plugin = plugin; | ||
this.expansion = Expansion.builder("topper") | ||
.filter(Player.class) | ||
.audiencePlaceholder("query", (audience, queue, ctx) -> { | ||
Player player = (Player) audience; | ||
String query = queue.popOr("You need to specify the query").value(); | ||
String result = plugin.get(TopQueryManager.class).get(player, query); | ||
if (result == null) { | ||
return TagsUtils.EMPTY_TAG; | ||
} else { | ||
return TagsUtils.staticTag(result); | ||
} | ||
}) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public void load() { | ||
plugin.get(ValueProviderBuilder.class).register(map -> new MiniPlaceholderValueProvider(plugin, map), "miniplaceholders"); | ||
} | ||
|
||
@Override | ||
public void enable() { | ||
expansion.register(); | ||
} | ||
|
||
@Override | ||
public void disable() { | ||
expansion.unregister(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../plugin/hook/papi/PlaceholderAPIHook.java → ...ok/placeholderapi/PlaceholderAPIHook.java
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
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
6 changes: 3 additions & 3 deletions
6
...in/hook/papi/TopPlaceholderExpansion.java → ...aceholderapi/TopPlaceholderExpansion.java
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
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
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