Skip to content

Commit 2f38558

Browse files
committed
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 i hate this i hate this i hate this i hate this i hate this i hate this
1 parent 17709e2 commit 2f38558

File tree

7 files changed

+40
-53
lines changed

7 files changed

+40
-53
lines changed

Essentials/src/main/java/com/earth2me/essentials/Console.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
import java.util.UUID;
1010

11-
import static com.earth2me.essentials.I18n.tl;
11+
import static com.earth2me.essentials.I18n.tlLiteral;
1212

1313
public final class Console implements IMessageRecipient {
1414
public static final String NAME = "Console";
15-
public static final String DISPLAY_NAME = tl("consoleName");
15+
public static final String DISPLAY_NAME = tlLiteral("consoleName");
1616
private static Console instance; // Set in essentials
1717

1818
private final IEssentials ess;

Essentials/src/main/java/com/earth2me/essentials/Essentials.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,22 +1153,22 @@ private int broadcastMessage(final IUser sender, final String permission, final
11531153
}
11541154

11551155
@Override
1156-
public void broadcastTl(String tlKey, Object... args) {
1157-
broadcastTl(null, tlKey, args);
1156+
public void broadcastTl(final String tlKey, final Object... args) {
1157+
broadcastTl(null, null, true, tlKey, args);
11581158
}
11591159

11601160
@Override
1161-
public void broadcastTl(IUser sender, String tlKey, Object... args) {
1162-
broadcastTl(sender, (Predicate<IUser>) null, tlKey, args);
1161+
public void broadcastTl(final IUser sender, final String tlKey, final Object... args) {
1162+
broadcastTl(sender, null, false, tlKey, args);
11631163
}
11641164

11651165
@Override
1166-
public void broadcastTl(IUser sender, String permission, String tlKey, Object... args) {
1167-
broadcastTl(sender, u -> !u.isAuthorized(permission), tlKey, args);
1166+
public void broadcastTl(final IUser sender, final String permission, final String tlKey, final Object... args) {
1167+
broadcastTl(sender, u -> !u.isAuthorized(permission), false, tlKey, args);
11681168
}
11691169

11701170
@Override
1171-
public void broadcastTl(IUser sender, Predicate<IUser> shouldExclude, String tlKey, Object... args) {
1171+
public void broadcastTl(final IUser sender, final Predicate<IUser> shouldExclude, final boolean parseKeywords, final String tlKey, final Object... args) {
11721172
if (sender != null && sender.isHidden()) {
11731173
return;
11741174
}
@@ -1182,7 +1182,15 @@ public void broadcastTl(IUser sender, Predicate<IUser> shouldExclude, String tlK
11821182
continue;
11831183
}
11841184

1185-
user.sendTl(tlKey, args);
1185+
final Object[] processedArgs;
1186+
// FUCK THIS STUPID BULLSHIT
1187+
if (parseKeywords) {
1188+
processedArgs = I18n.mutateArgs(args, s -> new KeywordReplacer(new SimpleTextInput(s), new CommandSource(user.getBase()), this, false).getLines().get(0));
1189+
} else {
1190+
processedArgs = args;
1191+
}
1192+
1193+
user.sendTl(tlKey, processedArgs);
11861194
}
11871195
}
11881196

Essentials/src/main/java/com/earth2me/essentials/I18n.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.MissingResourceException;
2424
import java.util.PropertyResourceBundle;
2525
import java.util.ResourceBundle;
26+
import java.util.function.Function;
2627
import java.util.logging.Level;
2728
import java.util.logging.Logger;
2829
import java.util.regex.Pattern;
@@ -152,24 +153,28 @@ public String format(final Locale locale, final String string, final Object... o
152153

153154
final Object[] processedArgs;
154155
if (miniMessage) {
155-
final Object[] args = new Object[objects.length];
156-
for (int i = 0; i < objects.length; i++) {
157-
final Object object = objects[i];
158-
// MessageFormat will format these itself, troll face.
159-
if (object instanceof Number || object instanceof Date) {
160-
args[i] = object;
161-
} else {
162-
args[i] = object != null ? MiniMessage.miniMessage().escapeTokens(object.toString()) : null;
163-
}
164-
}
165-
processedArgs = args;
156+
processedArgs = mutateArgs(objects, s -> MiniMessage.miniMessage().escapeTokens(s));
166157
} else {
167158
processedArgs = objects;
168159
}
169160

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

164+
public static Object[] mutateArgs(final Object[] objects, final Function<String, String> mutator) {
165+
final Object[] args = new Object[objects.length];
166+
for (int i = 0; i < objects.length; i++) {
167+
final Object object = objects[i];
168+
// MessageFormat will format these itself, troll face.
169+
if (object instanceof Number || object instanceof Date || object == null) {
170+
args[i] = object;
171+
continue;
172+
}
173+
args[i] = mutator.apply(object.toString());
174+
}
175+
return args;
176+
}
177+
173178
public void updateLocale(final String loc) {
174179
if (loc != null && !loc.isEmpty()) {
175180
currentLocale = getLocale(loc);

Essentials/src/main/java/com/earth2me/essentials/IEssentials.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public interface IEssentials extends Plugin {
8383

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

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

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

Essentials/src/main/java/com/earth2me/essentials/commands/Commandbroadcast.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.earth2me.essentials.commands;
22

33
import com.earth2me.essentials.CommandSource;
4-
import com.earth2me.essentials.textreader.KeywordReplacer;
5-
import com.earth2me.essentials.textreader.SimpleTextInput;
64
import com.earth2me.essentials.utils.FormatUtil;
75
import org.bukkit.Server;
86

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

20-
ess.broadcastTl("broadcast", new KeywordReplacer(new SimpleTextInput(FormatUtil.replaceFormat(getFinalArg(args, 0)).replace("\\n", "\n")), sender, ess).getLines().get(0), sender.getDisplayName());
18+
ess.broadcastTl("broadcast", FormatUtil.replaceFormat(getFinalArg(args, 0)).replace("\\n", "\n"), sender.getDisplayName());
2119
}
2220
}

Essentials/src/main/java/com/earth2me/essentials/commands/Commandbroadcastworld.java

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,14 @@
22

33
import com.earth2me.essentials.CommandSource;
44
import com.earth2me.essentials.User;
5-
import com.earth2me.essentials.textreader.IText;
6-
import com.earth2me.essentials.textreader.KeywordReplacer;
7-
import com.earth2me.essentials.textreader.SimpleTextInput;
8-
import com.earth2me.essentials.utils.FormatUtil;
95
import com.google.common.collect.Lists;
6+
import net.ess3.api.TranslatableException;
107
import org.bukkit.Server;
118
import org.bukkit.World;
12-
import org.bukkit.entity.Player;
139

14-
import java.util.Collection;
1510
import java.util.Collections;
1611
import java.util.List;
1712

18-
import static com.earth2me.essentials.I18n.tl;
19-
2013
public class Commandbroadcastworld extends EssentialsCommand {
2114

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

5144
final World world = ess.getWorld(args[0]);
5245
if (world == null) {
53-
throw new Exception(tl("invalidWorld"));
46+
throw new TranslatableException("invalidWorld");
5447
}
5548
sendBroadcast(world, sender.getSender().getName(), getFinalArg(args, 1));
5649
}
@@ -59,22 +52,7 @@ private void sendBroadcast(final World world, final String name, final String me
5952
if (message.isEmpty()) {
6053
throw new NotEnoughArgumentsException();
6154
}
62-
sendToWorld(world, tl("broadcast", FormatUtil.replaceFormat(message).replace("\\n", "\n"), name));
63-
}
64-
65-
private void sendToWorld(final World world, final String message) {
66-
IText broadcast = new SimpleTextInput(message);
67-
final Collection<Player> players = ess.getOnlinePlayers();
68-
69-
for (final Player player : players) {
70-
if (player.getWorld().equals(world)) {
71-
final User user = ess.getUser(player);
72-
broadcast = new KeywordReplacer(broadcast, new CommandSource(player), ess, false);
73-
for (final String messageText : broadcast.getLines()) {
74-
user.sendMessage(messageText);
75-
}
76-
}
77-
}
55+
ess.broadcastTl(null, u -> u.getBase().getWorld().equals(world), true, "broadcast", message, name);
7856
}
7957

8058
@Override

Essentials/src/main/java/com/earth2me/essentials/textreader/KeywordReplacer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import java.util.regex.Matcher;
3131
import java.util.regex.Pattern;
3232

33-
import static com.earth2me.essentials.I18n.tl;
34-
3533
//When adding a keyword here, you also need to add the implementation above
3634
enum KeywordType {
3735
PLAYER(KeywordCachable.CACHEABLE),
@@ -337,7 +335,7 @@ private String replaceLine(String line, final String fullMatch, final String[] m
337335
case COORDS:
338336
if (user != null) {
339337
final Location location = user.getLocation();
340-
replacer = tl("coordsKeyword", location.getBlockX(), location.getBlockY(), location.getBlockZ());
338+
replacer = user.playerTl("coordsKeyword", location.getBlockX(), location.getBlockY(), location.getBlockZ());
341339
}
342340
break;
343341
case TPS:

0 commit comments

Comments
 (0)