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 2f38558
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 53 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: 16 additions & 8 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,22 @@ 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) {
broadcastTl(sender, (Predicate<IUser>) null, tlKey, args);
public void broadcastTl(final IUser sender, final String tlKey, final Object... args) {
broadcastTl(sender, null, false, tlKey, args);
}

@Override
public void broadcastTl(IUser sender, String permission, String tlKey, Object... args) {
broadcastTl(sender, u -> !u.isAuthorized(permission), tlKey, args);
public void broadcastTl(final IUser sender, final String permission, final String tlKey, final Object... args) {
broadcastTl(sender, u -> !u.isAuthorized(permission), false, 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 boolean parseKeywords, final String tlKey, final Object... args) {
if (sender != null && sender.isHidden()) {
return;
}
Expand All @@ -1182,7 +1182,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
27 changes: 16 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 @@ -152,24 +153,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
Expand Up @@ -83,7 +83,7 @@ public interface IEssentials extends Plugin {

void broadcastTl(IUser sender, String tlKey, Object... args);

void broadcastTl(IUser sender, Predicate<IUser> shouldExclude, String tlKey, Object... args);
void broadcastTl(IUser sender, Predicate<IUser> shouldExclude, boolean parseKeywords, String tlKey, Object... args);

void broadcastTl(IUser sender, String permission, String tlKey, Object... args);

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 @@ -2,21 +2,14 @@

import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.textreader.IText;
import com.earth2me.essentials.textreader.KeywordReplacer;
import com.earth2me.essentials.textreader.SimpleTextInput;
import com.earth2me.essentials.utils.FormatUtil;
import com.google.common.collect.Lists;
import net.ess3.api.TranslatableException;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.Player;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

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

public class Commandbroadcastworld extends EssentialsCommand {

public Commandbroadcastworld() {
Expand Down Expand Up @@ -50,7 +43,7 @@ public void run(final Server server, final CommandSource sender, final String co

final World world = ess.getWorld(args[0]);
if (world == null) {
throw new Exception(tl("invalidWorld"));
throw new TranslatableException("invalidWorld");
}
sendBroadcast(world, sender.getSender().getName(), getFinalArg(args, 1));
}
Expand All @@ -59,22 +52,7 @@ private void sendBroadcast(final World world, final String name, final String me
if (message.isEmpty()) {
throw new NotEnoughArgumentsException();
}
sendToWorld(world, tl("broadcast", FormatUtil.replaceFormat(message).replace("\\n", "\n"), name));
}

private void sendToWorld(final World world, final String message) {
IText broadcast = new SimpleTextInput(message);
final Collection<Player> players = ess.getOnlinePlayers();

for (final Player player : players) {
if (player.getWorld().equals(world)) {
final User user = ess.getUser(player);
broadcast = new KeywordReplacer(broadcast, new CommandSource(player), ess, false);
for (final String messageText : broadcast.getLines()) {
user.sendMessage(messageText);
}
}
}
ess.broadcastTl(null, u -> u.getBase().getWorld().equals(world), true, "broadcast", message, name);
}

@Override
Expand Down
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 2f38558

Please sign in to comment.