Skip to content

Commit 58726fb

Browse files
AdrianOliva2JRoy
andauthored
Add option to use UUIDs over usernames in trade.log (#6252)
<!-- EssentialsX feature submission guide ==================================== NOTE: Failure to fill out this template properly may result in your PR being delayed or ignored without warning. NOTE: Don't type between any arrows in the template, as this text will be hidden. This includes this header block and any other explanation text blocks. Want to discuss your PR before submitting it? Join the EssentialsX Development server: https://discord.gg/CUN7qVb EssentialsX is GPL ------------------ By contributing to EssentialsX, you agree to license your code under the GNU General Public License version 3, which can be found at the link below: https://github.com/EssentialsX/Essentials/blob/2.x/LICENSE Instructions ------------ If you are submitting a new feature, please follow the following steps: 1. Fill out the template in full. This includes providing screenshots and a link to the original feature request. If there isn't an existing feature request, we strongly recommend opening a new feature request BEFORE opening your PR to implement it, as this allows us to review whether we're likely to accept your feature in advance, and also allows us to discuss possible implementations for the feature. If there is no associated feature request, your PR may be delayed or rejected without warning. You can open a new feature request by following this link: https://github.com/EssentialsX/Essentials/issues/new/choose 2. If you are fixing a performance issue, please use the "Bug fix" PR template instead. The "bug fix" template is better suited to performance issues. 3. Include a demonstration. If you are adding commands, please provide screenshots and/or a video demonstration of the feature. Similarly, if you are adding a new API, please include a link to example code that takes advantage of your proposed API. This will aid us in reviewing PRs and speed up the process significantly. --> ### Information <!-- Replace #nnnn with the number of the original issue. If this PR implements features from multiple issues, you should repeat the phrase "closes #nnnn" for each issue. --> This PR closes #6073. ### Details **Proposed feature:** <!-- Type a description of your proposed feature below this line. --> Add a setting to replace usernames with UUIDs in the trade.log file **Environments tested:** <!-- Type the OS you have used below. --> OS: Windows 11 Pro <!-- Type the JDK version (from java -version) you have used below. --> Java version: JDK 17 <!-- Put an "x" inside the boxes for the server software you have tested this bug fix on. If this feature does not apply to a server, strike through the server software using ~~strikethrough~~. If you have tested on other environments, add a new line with relevant details. --> - [X] Most recent Paper version (1.XX.Y, git-Paper-BUILD) - [ ] CraftBukkit/Spigot/Paper 1.12.2 - [ ] CraftBukkit 1.8.8 **Demonstration:** <!-- Below this block, include screenshots/log snippets from before and after as necessary. If you have created or used a test case plugin, please link to a download of the plugin, source code and exact version used where possible. --> **Before:** <img width="1299" height="33" alt="image" src="https://github.com/user-attachments/assets/6f34baf2-b5f5-46f6-adab-0ca0c0bf71c5" /> **After:** <img width="1346" height="18" alt="image" src="https://github.com/user-attachments/assets/672619ef-1215-4833-8320-e24bbb1c7ec0" /> **Command execution:** <img width="491" height="107" alt="image" src="https://github.com/user-attachments/assets/688efa80-3239-4bfe-8509-c998d3981637" /> --------- Co-authored-by: JRoy <10731363+JRoy@users.noreply.github.com>
1 parent 025ca48 commit 58726fb

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ public interface ISettings extends IConf {
184184

185185
boolean isEcoLogEnabled();
186186

187+
boolean isEcoLogUUIDEnabled();
188+
187189
boolean isEcoLogUpdateEnabled();
188190

189191
boolean realNamesOnList();

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public class Settings implements net.ess3.api.ISettings {
9292
private BigDecimal maxMoney = DEFAULT_MAX_MONEY;
9393
private BigDecimal minMoney = DEFAULT_MIN_MONEY;
9494
private boolean economyLog = false;
95+
private boolean economyLogUUID = false;
9596
// #easteregg
9697
private boolean economyLogUpdate = false;
9798
private boolean changeDisplayName = true;
@@ -904,6 +905,7 @@ public void reloadConfig() {
904905
permissionsLagWarning = _getPermissionsLagWarning();
905906
economyLagWarning = _getEconomyLagWarning();
906907
economyLog = _isEcoLogEnabled();
908+
economyLogUUID = _isEcoLogUUIDEnabled();
907909
economyLogUpdate = _isEcoLogUpdateEnabled();
908910
economyDisabled = _isEcoDisabled();
909911
allowSilentJoin = _allowSilentJoinQuit();
@@ -1175,6 +1177,14 @@ public boolean _isEcoLogEnabled() {
11751177
return config.getBoolean("economy-log-enabled", false);
11761178
}
11771179

1180+
public boolean _isEcoLogUUIDEnabled() {
1181+
return config.getBoolean("economy-log-uuids", false);
1182+
}
1183+
1184+
public boolean isEcoLogUUIDEnabled() {
1185+
return economyLogUUID;
1186+
}
1187+
11781188
@Override
11791189
public boolean isEcoLogUpdateEnabled() {
11801190
return economyLogUpdate;

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Date;
2121
import java.util.Locale;
2222
import java.util.Map;
23+
import java.util.UUID;
2324
import java.util.concurrent.CompletableFuture;
2425
import java.util.concurrent.ExecutionException;
2526
import java.util.logging.Level;
@@ -86,7 +87,14 @@ public static void log(final String type, final String subtype, final String eve
8687
sb.append(DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(new Date()));
8788
sb.append("\",\"");
8889
if (sender != null) {
89-
sb.append(sender);
90+
String senderIdentifier = sender;
91+
if (ess.getSettings().isEcoLogUUIDEnabled()) {
92+
final UUID uuid = ess.getUsers().getNameCache().get(sender);
93+
if (uuid != null) {
94+
senderIdentifier = uuid.toString();
95+
}
96+
}
97+
sb.append(senderIdentifier);
9098
}
9199
sb.append("\",");
92100
if (charge == null) {
@@ -112,7 +120,14 @@ public static void log(final String type, final String subtype, final String eve
112120
}
113121
sb.append(",\"");
114122
if (receiver != null) {
115-
sb.append(receiver);
123+
String receiverIdentifier = receiver;
124+
if (ess.getSettings().isEcoLogUUIDEnabled()) {
125+
final UUID uuid = ess.getUsers().getNameCache().get(receiver);
126+
if (uuid != null) {
127+
receiverIdentifier = uuid.toString();
128+
}
129+
}
130+
sb.append(receiverIdentifier);
116131
}
117132
sb.append("\",");
118133
if (pay == null) {
@@ -145,7 +160,7 @@ public static void log(final String type, final String subtype, final String eve
145160
sb.append(loc.getBlockY()).append(",");
146161
sb.append(loc.getBlockZ()).append(",");
147162
}
148-
163+
149164
if (endBalance == null) {
150165
sb.append(",");
151166
} else {

Essentials/src/main/resources/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,10 @@ min-money: -10000
863863
# Enable this to log all interactions with buy/sell/trade signs and the sell command.
864864
economy-log-enabled: false
865865

866+
# Enable this to replace usernames with UUIDs in the trade.log file.
867+
# If this is false, usernames will be used instead of UUIDs.
868+
economy-log-uuids: false
869+
866870
# Enable this to also log all transactions from other plugins through Vault.
867871
# This can cause the economy log to fill up quickly so it should only be enabled for testing purposes!
868872
economy-log-update-enabled: false

0 commit comments

Comments
 (0)