Skip to content

Commit 98b8898

Browse files
committed
Fixed ChestSearch Chat Spam
1 parent 6abd539 commit 98b8898

File tree

1 file changed

+56
-20
lines changed

1 file changed

+56
-20
lines changed

src/main/java/net/wurstclient/mixin/GenericContainerScreenMixin.java

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ public abstract class GenericContainerScreenMixin
8181
private String lastRecordMessage = null;
8282
@Unique
8383
private long lastRecordUntilMs = 0L;
84+
@Unique
85+
private boolean chestRecordedNotificationSent = false;
86+
@Unique
87+
private boolean chestSnapshotFinalized = false;
88+
@Unique
89+
private static String lastChestRecordedKey = null;
90+
@Unique
91+
private static long lastChestRecordedTimestamp = 0L;
8492

8593
public GenericContainerScreenMixin(WurstClient wurst, ChestMenu container,
8694
Inventory playerInventory, Component name)
@@ -92,6 +100,8 @@ public GenericContainerScreenMixin(WurstClient wurst, ChestMenu container,
92100
public void init()
93101
{
94102
super.init();
103+
chestRecordedNotificationSent = false;
104+
chestSnapshotFinalized = false;
95105
if(!WurstClient.INSTANCE.isEnabled())
96106
return;
97107
final ChestSearchHack chestSearchHack = wurst$getChestSearchHack();
@@ -1154,6 +1164,9 @@ public void removed()
11541164
{
11551165
try
11561166
{
1167+
if(chestSnapshotFinalized)
1168+
return;
1169+
chestSnapshotFinalized = true;
11571170
if(this.chestRecorder == null || this.menu == null)
11581171
return;
11591172
// Only finalize snapshot automatically if automatic mode is on
@@ -1212,29 +1225,36 @@ public void removed()
12121225
{
12131226
chestRecorder.recordFromStacksWithSlotOrder(serverIp, dimension,
12141227
fx, fy, fz, region, slotOrder, wurst$currentBounds());
1215-
// Notify player in chat that chest was recorded (on close)
1216-
try
1228+
if(!chestRecordedNotificationSent
1229+
&& wurst$shouldNotifyChestRecorded(serverIp, dimension, fx,
1230+
fy, fz))
12171231
{
1218-
String recordedMsg = "Chest recorded at position " + fx
1219-
+ "," + fy + "," + fz;
1220-
if(net.wurstclient.WurstClient.MC != null)
1232+
chestRecordedNotificationSent = true;
1233+
// Notify player in chat that chest was recorded (on close)
1234+
try
12211235
{
1222-
net.wurstclient.WurstClient.MC.execute(() -> {
1223-
try
1224-
{
1225-
if(net.wurstclient.WurstClient.MC.player != null)
1226-
net.wurstclient.WurstClient.MC.player
1227-
.displayClientMessage(
1228-
net.minecraft.network.chat.Component
1229-
.literal(recordedMsg),
1230-
false);
1231-
}catch(Throwable ignored)
1232-
{}
1233-
});
1236+
String recordedMsg = "Chest recorded at position " + fx
1237+
+ "," + fy + "," + fz;
1238+
if(net.wurstclient.WurstClient.MC != null)
1239+
{
1240+
net.wurstclient.WurstClient.MC.execute(() -> {
1241+
try
1242+
{
1243+
if(net.wurstclient.WurstClient.MC.player != null
1244+
&& net.wurstclient.WurstClient.MC.player.containerMenu == net.wurstclient.WurstClient.MC.player.inventoryMenu)
1245+
net.wurstclient.WurstClient.MC.player
1246+
.displayClientMessage(
1247+
net.minecraft.network.chat.Component
1248+
.literal(recordedMsg),
1249+
false);
1250+
}catch(Throwable ignored)
1251+
{}
1252+
});
1253+
}
1254+
}catch(Throwable ignored)
1255+
{
1256+
// ignore
12341257
}
1235-
}catch(Throwable ignored)
1236-
{
1237-
// ignore
12381258
}
12391259
// If loot export present, compare now and notify if mismatch
12401260
try
@@ -1656,4 +1676,20 @@ public void removed()
16561676
t.printStackTrace();
16571677
}
16581678
}
1679+
1680+
@Unique
1681+
private boolean wurst$shouldNotifyChestRecorded(String serverIp,
1682+
String dimension, int x, int y, int z)
1683+
{
1684+
String key = String.valueOf(serverIp) + "|" + String.valueOf(dimension)
1685+
+ "|" + x + "," + y + "," + z;
1686+
long now = System.currentTimeMillis();
1687+
if(key.equals(lastChestRecordedKey)
1688+
&& now - lastChestRecordedTimestamp < 500L)
1689+
return false;
1690+
1691+
lastChestRecordedKey = key;
1692+
lastChestRecordedTimestamp = now;
1693+
return true;
1694+
}
16591695
}

0 commit comments

Comments
 (0)