Bring back PAPI placeholders and raw colour formatting

This commit is contained in:
Alexander Söderberg 2020-07-21 13:05:40 +02:00
parent 335cf5d2e9
commit 186a810bf6
No known key found for this signature in database
GPG Key ID: C0207FF7EA146678
45 changed files with 123 additions and 121 deletions

View File

@ -48,7 +48,6 @@ import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.bukkit.util.BukkitWorld;
import com.plotsquared.bukkit.util.SetGenCB;
import com.plotsquared.bukkit.util.UpdateUtility;
import com.plotsquared.bukkit.util.task.BukkitTaskManager;
import com.plotsquared.bukkit.util.task.PaperTimeConverter;
import com.plotsquared.bukkit.util.task.SpigotTimeConverter;
import com.plotsquared.bukkit.uuid.BungeePermsUUIDService;
@ -64,7 +63,7 @@ import com.plotsquared.core.backup.BackupManager;
import com.plotsquared.core.command.WE_Anywhere;
import com.plotsquared.core.components.ComponentPresetManager;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ChatFormatter;
import com.plotsquared.core.configuration.caption.ChatFormatter;
import com.plotsquared.core.configuration.ConfigurationNode;
import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.ConfigurationUtil;

View File

@ -26,15 +26,17 @@
package com.plotsquared.bukkit.placeholder;
import com.plotsquared.bukkit.player.BukkitPlayer;
import com.plotsquared.core.configuration.ChatFormatter;
import com.plotsquared.core.configuration.caption.ChatFormatter;
import com.plotsquared.core.player.PlotPlayer;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.entity.Player;
import javax.annotation.Nonnull;
public class PlaceholderFormatter implements ChatFormatter {
@Override public void format(final ChatContext context) {
final PlotPlayer recipient = context.getRecipient();
@Override public void format(@Nonnull final ChatContext context) {
final PlotPlayer<?> recipient = context.getRecipient();
if (recipient instanceof BukkitPlayer) {
if (context.isRawOutput()) {
context.setMessage(context.getMessage().replace('%', '\u2010'));

View File

@ -31,7 +31,7 @@ import com.plotsquared.bukkit.BukkitPlatform;
import com.plotsquared.bukkit.player.BukkitPlayer;
import com.plotsquared.bukkit.player.BukkitPlayerManager;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.caption.LocaleHolder;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlotPlayer;

View File

@ -25,7 +25,7 @@
*/
package com.plotsquared.core;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlotPlayer;

View File

@ -29,7 +29,7 @@ import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;
import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.TranslatableCaption;

View File

@ -27,7 +27,7 @@ package com.plotsquared.core.command;
import com.google.common.primitives.Ints;
import com.google.inject.Inject;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.TranslatableCaption;

View File

@ -25,9 +25,9 @@
*/
package com.plotsquared.core.command;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.StaticCaption;
import com.plotsquared.core.configuration.caption.StaticCaption;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.util.MainUtil;

View File

@ -25,7 +25,7 @@
*/
package com.plotsquared.core.command;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import net.kyori.adventure.text.minimessage.Template;
import javax.annotation.Nonnull;

View File

@ -25,7 +25,7 @@
*/
package com.plotsquared.core.command;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.caption.LocaleHolder;

View File

@ -26,7 +26,7 @@
package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.TranslatableCaption;

View File

@ -27,7 +27,7 @@ package com.plotsquared.core.command;
import com.google.common.primitives.Ints;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.player.PlotPlayer;

View File

@ -25,8 +25,8 @@
*/
package com.plotsquared.core.command;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.StaticCaption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.caption.StaticCaption;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import javax.annotation.Nonnull;

View File

@ -27,7 +27,7 @@ package com.plotsquared.core.command;
import com.google.inject.Inject;
import com.plotsquared.core.backup.BackupManager;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.TranslatableCaption;

View File

@ -25,7 +25,7 @@
*/
package com.plotsquared.core.command;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.location.Location;

View File

@ -26,6 +26,7 @@
package com.plotsquared.core.configuration;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.util.StringMan;

View File

@ -23,7 +23,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.configuration;
package com.plotsquared.core.configuration.caption;
import com.plotsquared.core.configuration.caption.LocaleHolder;

View File

@ -23,37 +23,46 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.configuration;
package com.plotsquared.core.configuration.caption;
import com.plotsquared.core.player.PlotPlayer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class CaptionUtility {
public static String formatRaw(PlotPlayer recipient, String message, Object... args) {
/**
* Format a chat message but keep the formatting keys
*
* @param recipient Message recipient
* @param message Message
* @return Formatted message
*/
public static String formatRaw(PlotPlayer<?> recipient, String message) {
final ChatFormatter.ChatContext chatContext =
new ChatFormatter.ChatContext(recipient, message, args, true);
new ChatFormatter.ChatContext(recipient, message, true);
for (final ChatFormatter chatFormatter : ChatFormatter.formatters) {
chatFormatter.format(chatContext);
}
return chatContext.getMessage();
}
public static String format(PlotPlayer recipient, String message, Object... args) {
/**
* Format a chat message
*
* @param recipient Message recipient
* @param message Message
* @return Formatted message
*/
public static String format(@Nullable final PlotPlayer<?> recipient,
@Nonnull final String message) {
final ChatFormatter.ChatContext chatContext =
new ChatFormatter.ChatContext(recipient, message, args, false);
new ChatFormatter.ChatContext(recipient, message, false);
for (final ChatFormatter chatFormatter : ChatFormatter.formatters) {
chatFormatter.format(chatContext);
}
return chatContext.getMessage();
}
public static String format(PlotPlayer recipient, Caption caption, Object... args) {
if (caption.usePrefix() && caption.getTranslated().length() > 0) {
return Captions.PREFIX.getTranslated() + format(recipient, caption.getTranslated(),
args);
} else {
return format(recipient, caption.getTranslated(), args);
}
}
}

View File

@ -23,10 +23,12 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.configuration;
package com.plotsquared.core.configuration.caption;
import com.plotsquared.core.player.PlotPlayer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -34,43 +36,71 @@ import java.util.Collections;
@FunctionalInterface
public interface ChatFormatter {
Collection<ChatFormatter> formatters =
new ArrayList<>(Collections.singletonList(new PlotSquaredChatFormatter()));
Collection<ChatFormatter> formatters = new ArrayList<>(Collections.singletonList(new PlotSquaredChatFormatter()));
void format(ChatContext context);
/**
* Format a message using all registered formatters
*
* @param context Message to format
*/
void format(@Nonnull ChatContext context);
final class ChatContext {
private final PlotPlayer<?> recipient;
private String message;
private final Object[] args;
;
private final boolean rawOutput;
public ChatContext(final PlotPlayer<?> recipient, final String message, final Object[] args,
/**
* Create a new chat context
*
* @param recipient Message recipient
* @param message Message
* @param rawOutput Whether or not formatting keys should be included in the
* final message
*/
public ChatContext(@Nullable final PlotPlayer<?> recipient, @Nonnull final String message,
final boolean rawOutput) {
this.recipient = recipient;
this.message = message;
this.args = args;
this.rawOutput = rawOutput;
}
public PlotPlayer<?> getRecipient() {
/**
* Get the message recipient
*
* @return Recipient
*/
@Nullable public PlotPlayer<?> getRecipient() {
return this.recipient;
}
public String getMessage() {
/**
* Get the message stored in the context
*
* @return Stored message
*/
@Nonnull public String getMessage() {
return this.message;
}
public Object[] getArgs() {
return this.args;
}
/**
* Whether or not the output should escape
* any formatting keys
*
* @return True if raw output is to be used
*/
public boolean isRawOutput() {
return this.rawOutput;
}
public void setMessage(String message) {
/**
* Set the new message
*
* @param message Message
*/
public void setMessage(@Nonnull final String message) {
this.message = message;
}
}

View File

@ -25,12 +25,10 @@
*/
package com.plotsquared.core.configuration.caption;
import com.plotsquared.core.configuration.Caption;
import javax.annotation.Nonnull;
/**
* A {@link com.plotsquared.core.configuration.Caption} that can be identified by a key
* A {@link Caption} that can be identified by a key
*/
public interface KeyedCaption extends Caption {

View File

@ -23,39 +23,17 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.configuration;
package com.plotsquared.core.configuration.caption;
import com.plotsquared.core.util.StringMan;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.annotation.Nonnull;
public class PlotSquaredChatFormatter implements ChatFormatter {
@Override public void format(final ChatContext context) {
@Override public void format(@Nonnull final ChatContext context) {
if (context.isRawOutput()) {
context.setMessage(
context.getMessage().replace('&', '\u2020').replace('\u00A7', '\u2030'));
}
if (context.getArgs().length == 0) {
return;
}
final Map<String, String> map = new LinkedHashMap<>();
for (int i = context.getArgs().length - 1; i >= 0; i--) {
String arg = "" + context.getArgs()[i];
if (arg.isEmpty()) {
map.put("%s" + i, "");
} else {
if (!context.isRawOutput()) {
arg = Captions.color(arg);
}
map.put("%s" + i, arg);
}
if (i == 0) {
map.put("%s", arg);
}
}
context.setMessage(StringMan.replaceFromMap(context.getMessage(), map));
}
}

View File

@ -23,10 +23,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.configuration;
package com.plotsquared.core.configuration.caption;
import com.google.common.base.Preconditions;
import com.plotsquared.core.configuration.caption.LocaleHolder;
import javax.annotation.Nonnull;
@ -34,10 +33,7 @@ public final class StaticCaption implements Caption {
private final String value;
/**
* @deprecated Use {@link #of(String)}
*/
@Deprecated public StaticCaption(final String value) {
private StaticCaption(final String value) {
this.value = value;
}

View File

@ -25,7 +25,6 @@
*/
package com.plotsquared.core.configuration.caption;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.util.MainUtil;
import net.kyori.adventure.text.minimessage.MiniMessage;

View File

@ -28,7 +28,7 @@ package com.plotsquared.core.player;
import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.command.RequiredType;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.events.TeleportCause;

View File

@ -30,10 +30,11 @@ import com.google.common.base.Preconditions;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.command.CommandCaller;
import com.plotsquared.core.command.RequiredType;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.CaptionMap;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.configuration.caption.LocaleHolder;
import com.plotsquared.core.configuration.caption.Templates;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
@ -799,6 +800,10 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer,
if (message.isEmpty()) {
return;
}
// Replace placeholders, etc
message = CaptionUtility.format(this, message).
/* Magic replacement characters */
replace('\u2010', '%').replace('\u2020', '&').replace('\u2030', '&');
// Create the template list, and add the prefix as a replacement
final List<Template> templates = Arrays.asList(replacements);
templates.add(Templates.of(this, "prefix", TranslatableCaption.of("core.prefix")));

View File

@ -31,7 +31,7 @@ import com.google.common.collect.Sets;
import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.command.Like;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationUtil;
import com.plotsquared.core.configuration.Settings;

View File

@ -29,7 +29,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.plotsquared.core.collection.QuadMap;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationNode;
import com.plotsquared.core.configuration.ConfigurationSection;

View File

@ -25,7 +25,7 @@
*/
package com.plotsquared.core.plot;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.Captions;
import javax.annotation.Nonnull;

View File

@ -27,7 +27,7 @@ package com.plotsquared.core.plot.comment;
import com.google.common.annotations.Beta;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.StaticCaption;
import com.plotsquared.core.configuration.caption.StaticCaption;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;

View File

@ -25,8 +25,8 @@
*/
package com.plotsquared.core.plot.flag;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.caption.CaptionUtility;
public class FlagParseException extends Exception {

View File

@ -26,7 +26,7 @@
package com.plotsquared.core.plot.flag;
import com.google.common.base.Preconditions;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.Captions;
import javax.annotation.Nonnull;

View File

@ -25,7 +25,7 @@
*/
package com.plotsquared.core.plot.flag.types;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.FlagParseException;
import com.plotsquared.core.util.BlockUtil;

View File

@ -25,7 +25,7 @@
*/
package com.plotsquared.core.plot.flag.types;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.FlagParseException;
import com.plotsquared.core.plot.flag.PlotFlag;

View File

@ -25,7 +25,7 @@
*/
package com.plotsquared.core.plot.flag.types;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.FlagParseException;

View File

@ -25,7 +25,7 @@
*/
package com.plotsquared.core.plot.flag.types;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.FlagParseException;

View File

@ -25,7 +25,7 @@
*/
package com.plotsquared.core.plot.flag.types;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.util.StringMan;

View File

@ -25,7 +25,7 @@
*/
package com.plotsquared.core.plot.flag.types;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.FlagParseException;

View File

@ -25,7 +25,7 @@
*/
package com.plotsquared.core.plot.flag.types;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import javax.annotation.Nonnull;

View File

@ -25,7 +25,7 @@
*/
package com.plotsquared.core.plot.flag.types;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.FlagParseException;
import com.plotsquared.core.plot.flag.PlotFlag;

View File

@ -25,7 +25,7 @@
*/
package com.plotsquared.core.plot.flag.types;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.FlagParseException;
import com.plotsquared.core.plot.flag.PlotFlag;

View File

@ -26,7 +26,7 @@
package com.plotsquared.core.setup;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.generator.GeneratorWrapper;

View File

@ -26,7 +26,7 @@
package com.plotsquared.core.util;
import com.google.common.eventbus.EventBus;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.events.PlayerAutoPlotEvent;

View File

@ -26,7 +26,7 @@
package com.plotsquared.core.util;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.caption.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.player.ConsolePlayer;

View File

@ -25,24 +25,9 @@
*/
package com.plotsquared.core.util;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.command.Like;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.ConsolePlayer;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.util.task.TaskManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
/**
* plot functions
* @deprecated Do not use

View File

@ -25,7 +25,7 @@
*/
package com.plotsquared.core.util;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import javax.annotation.Nonnull;
import java.lang.reflect.Array;

View File

@ -26,7 +26,7 @@
package com.plotsquared.core.util;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.Caption;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;