mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 02:04:44 +02:00
Allow all messages to be formatted by external formatters and add PAPI support
This commit is contained in:
@ -7,6 +7,7 @@ import com.github.intellectualsites.plotsquared.bukkit.listeners.PlayerEvents;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.PlotPlusListener;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.SingleWorldListener;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.WorldEvents;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.placeholders.PlaceholderFormatter;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.placeholders.Placeholders;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitChatManager;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitChunkManager;
|
||||
@ -31,6 +32,7 @@ import com.github.intellectualsites.plotsquared.configuration.ConfigurationSecti
|
||||
import com.github.intellectualsites.plotsquared.plot.IPlotMain;
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.ChatFormatter;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper;
|
||||
@ -160,6 +162,9 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
new Placeholders(this).register();
|
||||
if (Settings.Enabled_Components.EXTERNAL_PLACEHOLDERS) {
|
||||
ChatFormatter.formatters.add(new PlaceholderFormatter());
|
||||
}
|
||||
PlotSquared.log(Captions.PREFIX + "&6PlaceholderAPI found! Hook activated.");
|
||||
} else {
|
||||
PlotSquared.log(Captions.PREFIX + "&6PlaceholderAPI is not in use. Hook deactivated.");
|
||||
|
@ -187,7 +187,9 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
return this.player.isPermissionSet(permission);
|
||||
}
|
||||
|
||||
@Override public void sendMessage(final String message) {
|
||||
@Override public void sendMessage(String message) {
|
||||
message = message.replace('\u2010', '%')
|
||||
.replace('\u2020', '&').replace('\u2030', '&');
|
||||
if (!StringMan.isEqual(this.getMeta("lastMessage"), message) || (
|
||||
System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) {
|
||||
setMeta("lastMessage", message);
|
||||
|
@ -0,0 +1,23 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.placeholders;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.ChatFormatter;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlaceholderFormatter implements ChatFormatter {
|
||||
|
||||
@Override public void format(final ChatContext context) {
|
||||
final PlotPlayer recipient = context.getRecipient();
|
||||
if (recipient instanceof BukkitPlayer) {
|
||||
if (context.isRawOutput()) {
|
||||
context.setMessage(context.getMessage().replace('%', '\u2010'));
|
||||
} else {
|
||||
final Player player = ((BukkitPlayer) recipient).player;
|
||||
context.setMessage(PlaceholderAPI.setPlaceholders(player, context.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user