Add PlaceholderAPI support.

This commit is contained in:
cnaude 2016-09-03 09:16:54 -07:00
parent 1bc82b84e1
commit 9543e665ab
3 changed files with 26 additions and 7 deletions

View File

@ -16,6 +16,7 @@
*/
package com.cnaude.purpleirc.Hooks;
import com.cnaude.purpleirc.PurpleIRC;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.entity.Player;
@ -24,11 +25,24 @@ import org.bukkit.entity.Player;
* @author Chris Naude
*/
public class PlaceholderApiHook {
private final PurpleIRC plugin;
/**
*
* @param plugin the PurpleIRC plugin
*/
public PlaceholderApiHook(PurpleIRC plugin) {
this.plugin = plugin;
}
public String setPlaceholders(Player player, String message) {
String m = message;
plugin.logDebug("[setPlaceholders: before] " + m);
if (player != null && message != null) {
return PlaceholderAPI.setPlaceholders(player, message);
m = PlaceholderAPI.setPlaceholders(player, message);
}
return "";
plugin.logDebug("[setPlaceholders: after] " + m);
return m;
}
}

View File

@ -1741,7 +1741,7 @@ public class PurpleIRC extends JavaPlugin {
}
if (isPluginEnabled(PL_PLACEHOLDERAPI)) {
hookList.add(hookFormat(PL_PLACEHOLDERAPI, true));
placeholderApiHook = new PlaceholderApiHook();
placeholderApiHook = new PlaceholderApiHook(this);
} else {
hookList.add(hookFormat(PL_PLACEHOLDERAPI, false));
}

View File

@ -199,8 +199,8 @@ public class ChatTokenizer {
.replace("%MESSAGE%", message)
.replace("%CHANNEL%", channel.getName()));
}
/**
/**
* Normal IRC to game chat tokenizer
*
* @param ircBot
@ -890,6 +890,11 @@ public class ChatTokenizer {
}
}
plugin.logDebug("[P]Raw message: " + message);
if (plugin.placeholderApiHook != null) {
message = plugin.placeholderApiHook.setPlaceholders(player, message);
}
return message.replace("%DISPLAYNAME%", displayName)
.replace("%UUID%", uuid.toString())
.replace("%JOBS%", job)
@ -976,10 +981,10 @@ public class ChatTokenizer {
}
}
}
if (plugin.placeholderApiHook != null) {
message = plugin.placeholderApiHook.setPlaceholders(player, message);
}
}
plugin.logDebug("[S]Raw message: " + message);
return message.replace("%DISPLAYNAME%", displayName)