Skip to content

Commit

Permalink
i hate this i hate this i hate this i hate this i hate this i hate th…
Browse files Browse the repository at this point in the history
…is i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this i hate this
  • Loading branch information
JRoy committed Dec 28, 2021
1 parent 17709e2 commit 8c538dc
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Essentials/src/main/java/com/earth2me/essentials/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

import java.util.UUID;

import static com.earth2me.essentials.I18n.tl;
import static com.earth2me.essentials.I18n.tlLiteral;

public final class Console implements IMessageRecipient {
public static final String NAME = "Console";
public static final String DISPLAY_NAME = tl("consoleName");
public static final String DISPLAY_NAME = tlLiteral("consoleName");
private static Console instance; // Set in essentials

private final IEssentials ess;
Expand Down
24 changes: 18 additions & 6 deletions Essentials/src/main/java/com/earth2me/essentials/Essentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -1153,22 +1153,26 @@ private int broadcastMessage(final IUser sender, final String permission, final
}

@Override
public void broadcastTl(String tlKey, Object... args) {
broadcastTl(null, tlKey, args);
public void broadcastTl(final String tlKey, final Object... args) {
broadcastTl(null, null, true, tlKey, args);
}

@Override
public void broadcastTl(IUser sender, String tlKey, Object... args) {
public void broadcastTl(final IUser sender, final String tlKey, final Object... args) {
broadcastTl(sender, (Predicate<IUser>) null, tlKey, args);
}

@Override
public void broadcastTl(IUser sender, String permission, String tlKey, Object... args) {
public void broadcastTl(final IUser sender, final String permission, final String tlKey, final Object... args) {
broadcastTl(sender, u -> !u.isAuthorized(permission), tlKey, args);
}

@Override
public void broadcastTl(IUser sender, Predicate<IUser> shouldExclude, String tlKey, Object... args) {
public void broadcastTl(final IUser sender, final Predicate<IUser> shouldExclude, final String tlKey, final Object... args) {
broadcastTl(sender, shouldExclude, false, tlKey, args);
}

private void broadcastTl(IUser sender, Predicate<IUser> shouldExclude, boolean parseKeywords, String tlKey, Object... args) {
if (sender != null && sender.isHidden()) {
return;
}
Expand All @@ -1182,7 +1186,15 @@ public void broadcastTl(IUser sender, Predicate<IUser> shouldExclude, String tlK
continue;
}

user.sendTl(tlKey, args);
final Object[] processedArgs;
// FUCK THIS STUPID BULLSHIT
if (parseKeywords) {
processedArgs = I18n.mutateArgs(args, s -> new KeywordReplacer(new SimpleTextInput(s), new CommandSource(user.getBase()), this, false).getLines().get(0));
} else {
processedArgs = args;
}

user.sendTl(tlKey, processedArgs);
}
}

Expand Down
29 changes: 18 additions & 11 deletions Essentials/src/main/java/com/earth2me/essentials/I18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.MissingResourceException;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -55,9 +56,11 @@ public I18n(final IEssentials ess) {
localeBundle = defaultBundle;
}

/*
public static String tl(final String string, final Object... objects) {
return tlLiteral(string, objects);
}
*/

public static String tlLiteral(final String string, final Object... objects) {
if (instance == null) {
Expand Down Expand Up @@ -152,24 +155,28 @@ public String format(final Locale locale, final String string, final Object... o

final Object[] processedArgs;
if (miniMessage) {
final Object[] args = new Object[objects.length];
for (int i = 0; i < objects.length; i++) {
final Object object = objects[i];
// MessageFormat will format these itself, troll face.
if (object instanceof Number || object instanceof Date) {
args[i] = object;
} else {
args[i] = object != null ? MiniMessage.miniMessage().escapeTokens(object.toString()) : null;
}
}
processedArgs = args;
processedArgs = mutateArgs(objects, s -> MiniMessage.miniMessage().escapeTokens(s));
} else {
processedArgs = objects;
}

return messageFormat.format(processedArgs).replace(' ', ' '); // replace nbsp with a space
}

public static Object[] mutateArgs(final Object[] objects, final Function<String, String> mutator) {
final Object[] args = new Object[objects.length];
for (int i = 0; i < objects.length; i++) {
final Object object = objects[i];
// MessageFormat will format these itself, troll face.
if (object instanceof Number || object instanceof Date || object == null) {
args[i] = object;
continue;
}
args[i] = mutator.apply(object.toString());
}
return args;
}

public void updateLocale(final String loc) {
if (loc != null && !loc.isEmpty()) {
currentLocale = getLocale(loc);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.earth2me.essentials.commands;

import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.textreader.KeywordReplacer;
import com.earth2me.essentials.textreader.SimpleTextInput;
import com.earth2me.essentials.utils.FormatUtil;
import org.bukkit.Server;

Expand All @@ -17,6 +15,6 @@ public void run(final Server server, final CommandSource sender, final String co
throw new NotEnoughArgumentsException();
}

ess.broadcastTl("broadcast", new KeywordReplacer(new SimpleTextInput(FormatUtil.replaceFormat(getFinalArg(args, 0)).replace("\\n", "\n")), sender, ess).getLines().get(0), sender.getDisplayName());
ess.broadcastTl("broadcast", FormatUtil.replaceFormat(getFinalArg(args, 0)).replace("\\n", "\n"), sender.getDisplayName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.earth2me.essentials.I18n.tl;

//When adding a keyword here, you also need to add the implementation above
enum KeywordType {
PLAYER(KeywordCachable.CACHEABLE),
Expand Down Expand Up @@ -337,7 +335,7 @@ private String replaceLine(String line, final String fullMatch, final String[] m
case COORDS:
if (user != null) {
final Location location = user.getLocation();
replacer = tl("coordsKeyword", location.getBlockX(), location.getBlockY(), location.getBlockZ());
replacer = user.playerTl("coordsKeyword", location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
break;
case TPS:
Expand Down

0 comments on commit 8c538dc

Please sign in to comment.