Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce PlaceholderAPI to Bukkit version #34

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bukkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ repositories {
name = 'sonatype'
url = 'https://oss.sonatype.org/content/groups/public/'
}
maven { url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/' }
}

dependencies {
implementation project(':common')

compileOnly 'org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT'
compileOnly 'me.clip:placeholderapi:2.9.+'
api 'net.kyori:adventure-platform-bukkit:4.3.0'
//compile files('libs/spigot-1.7.10-SNAPSHOT-b1657.jar')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.mineaurion.aurionchat.common.config.ConfigurationAdapter;
import com.mineaurion.aurionchat.common.logger.JavaPluginLogger;
import com.mineaurion.aurionchat.common.logger.PluginLogger;
import me.clip.placeholderapi.PlaceholderAPI;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
Expand All @@ -30,6 +31,8 @@ public AurionChat(JavaPlugin plugin){
public void onEnable(){
getlogger().info("AurionChat Initializing");
audiences = BukkitAudiences.create(plugin);
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI"))
((BukkitConfigurationAdapter) getConfigurationAdapter()).initPlaceholderApi();
this.enable();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.mineaurion.aurionchat.bukkit;

import me.clip.placeholderapi.expansion.PlaceholderExpansion;

public class AurionPlaceholderAPI extends PlaceholderExpansion {
private final AurionChat plugin;

public AurionPlaceholderAPI(AurionChat plugin) {
this.plugin = plugin;
}

@Override
public String getIdentifier() {
return "aurionchat";
}

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

@Override
public String getVersion() {
return "0.14.4";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@

import com.mineaurion.aurionchat.common.config.Channel;
import com.mineaurion.aurionchat.common.config.ConfigurationAdapter;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class BukkitConfigurationAdapter implements ConfigurationAdapter {

private final AurionChat plugin;
private final File file;
private YamlConfiguration configuration;
private @Nullable AurionPlaceholderAPI apapi;

public BukkitConfigurationAdapter(AurionChat plugin, File file){
this.plugin = plugin;
Expand Down Expand Up @@ -55,4 +60,17 @@ public Map<String, Channel> getChannels(){
}
return map;
}

@Override
public String wrapString(@Nullable UUID player, String str) {
return apapi == null || player == null
? ConfigurationAdapter.super.wrapString(player, str)
: apapi.onRequest(Bukkit.getOfflinePlayer(player), str);
}

public void initPlaceholderApi() {
plugin.getlogger().info("Hooking into PlaceholderAPI");
apapi = new AurionPlaceholderAPI(plugin);
PlaceholderAPI.registerExpansion(apapi);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mineaurion.aurionchat.bukkit.AurionChat;
import com.mineaurion.aurionchat.common.AurionChatPlayer;
import com.mineaurion.aurionchat.common.Utils;
import com.mineaurion.aurionchat.common.config.ConfigurationAdapter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -33,8 +34,9 @@ public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event){
}

String currentChannel = aurionChatPlayer.getCurrentChannel();
ConfigurationAdapter config = plugin.getConfigurationAdapter();
Component messageFormat = Utils.processMessage(
plugin.getConfigurationAdapter().getChannels().get(currentChannel).format,
config.wrapString(player.getUniqueId(), config.getChannels().get(currentChannel).format),
LegacyComponentSerializer.legacy('&').deserialize(event.getMessage()).asComponent(),
aurionChatPlayer,
plugin.getConfigurationAdapter().getChannels().get(currentChannel).urlMode
Expand Down
2 changes: 2 additions & 0 deletions bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ authors: [Yann151924]
website: https://mineaurion.com
depend:
- LuckPerms
softdepend:
- PlaceholderAPI
commands:
chat:
aliases: [ch, channel]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.mineaurion.aurionchat.common.config;

import com.mineaurion.aurionchat.common.AbstractAurionChat;
import com.mineaurion.aurionchat.common.Utils;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.*;

Expand All @@ -18,6 +20,10 @@ public interface ConfigurationAdapter {
//
Map<String, Channel> getChannels();

default String wrapString(@Nullable UUID player, String str) {
return str;
}

default Optional<String> getChannelByNameOrAlias(String search){
for(Map.Entry<String, Channel> entry: getChannels().entrySet()){
String name = entry.getKey();
Expand Down
Loading