Skip to content

Commit

Permalink
- Add support for PlaceholderAPI's placeholders in the chatconfig.yml's
Browse files Browse the repository at this point in the history
channel_format lines.
  • Loading branch information
LlmDl committed Oct 14, 2019
1 parent 475e26d commit d038dd6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
<id>github-Towny</id>
<url>https://maven.pkg.github.com/TownyAdvanced/Towny</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -87,6 +91,12 @@
<version>3.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.4</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
3 changes: 2 additions & 1 deletion resources/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,5 @@ v0.57:
- New ChatConfig option: chat_colour.nomad
- Default: &f
- You can now set the {townycolour} for players without a town.
- Fix missing space following the title in {townyprefix} (when there is no mayor/king prefix present.)
- Fix missing space following the title in {townyprefix} (when there is no mayor/king prefix present.)
- Add support for PlaceholderAPI's placeholders in the chatconfig.yml's Channel_format lines.
2 changes: 1 addition & 1 deletion resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ website: http://towny.palmergames.com/towny/townychat/
description: >
TownyChat plugin which hooks into Towny.
softdepend: [Towny, CraftIRC]
softdepend: [Towny, CraftIRC, PlaceholderAPI]

############################################################
# +------------------------------------------------------+ #
Expand Down
8 changes: 7 additions & 1 deletion src/com/palmergames/bukkit/TownyChat/Chat.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public class Chat extends JavaPlugin {
protected PluginManager pm;
private Towny towny = null;
private DynmapAPI dynMap = null;


public static boolean usingPlaceholderAPI = false;
boolean chatConfigError = false;
boolean channelsConfigError = false;

Expand Down Expand Up @@ -120,6 +121,11 @@ private void checkPlugins() {
if (test != null) {
dynMap = (DynmapAPI) test;
}

test = pm.getPlugin("PlaceholderAPI");
if (test != null) {
usingPlaceholderAPI = true;
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.TownyUniverse;
import com.palmergames.bukkit.util.Colors;

import me.clip.placeholderapi.PlaceholderAPI;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent;
Expand Down Expand Up @@ -103,14 +106,15 @@ public void chatProcess(AsyncPlayerChatEvent event) {
recipients = new HashSet<>(findRecipients(player, new ArrayList<>(event.getRecipients())));
break;
}

/*
* Perform all replace functions on this format
*/
//if (ChatSettings.isModify_chat())
event.setFormat(Format.replace("{channelTag}", getChannelTag()).replace("{msgcolour}", getMessageColour()));
//else
// event.setFormat(event.getFormat().replace("{channelTag}", getChannelTag()).replace("{msgcolour}", getMessageColour()));
if (Chat.usingPlaceholderAPI) {
Format = PlaceholderAPI.setPlaceholders(player, Format);
}

event.setFormat(Format.replace("{channelTag}", getChannelTag()).replace("{msgcolour}", getMessageColour()));

LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
event.setFormat(TownyChatFormatter.getChatFormat(chatEvent));
Expand Down

0 comments on commit d038dd6

Please sign in to comment.