Skip to content

Commit 5d18dcb

Browse files
committed
Fixed ChestSearch Chat Spam
1 parent ba78285 commit 5d18dcb

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();
@@ -1153,6 +1163,9 @@ public void removed()
11531163
{
11541164
try
11551165
{
1166+
if(chestSnapshotFinalized)
1167+
return;
1168+
chestSnapshotFinalized = true;
11561169
if(this.chestRecorder == null || this.menu == null)
11571170
return;
11581171
// Only finalize snapshot automatically if automatic mode is on
@@ -1211,29 +1224,36 @@ public void removed()
12111224
{
12121225
chestRecorder.recordFromStacksWithSlotOrder(serverIp, dimension,
12131226
fx, fy, fz, region, slotOrder, wurst$currentBounds());
1214-
// Notify player in chat that chest was recorded (on close)
1215-
try
1227+
if(!chestRecordedNotificationSent
1228+
&& wurst$shouldNotifyChestRecorded(serverIp, dimension, fx,
1229+
fy, fz))
12161230
{
1217-
String recordedMsg = "Chest recorded at position " + fx
1218-
+ "," + fy + "," + fz;
1219-
if(net.wurstclient.WurstClient.MC != null)
1231+
chestRecordedNotificationSent = true;
1232+
// Notify player in chat that chest was recorded (on close)
1233+
try
12201234
{
1221-
net.wurstclient.WurstClient.MC.execute(() -> {
1222-
try
1223-
{
1224-
if(net.wurstclient.WurstClient.MC.player != null)
1225-
net.wurstclient.WurstClient.MC.player
1226-
.displayClientMessage(
1227-
net.minecraft.network.chat.Component
1228-
.literal(recordedMsg),
1229-
false);
1230-
}catch(Throwable ignored)
1231-
{}
1232-
});
1235+
String recordedMsg = "Chest recorded at position " + fx
1236+
+ "," + fy + "," + fz;
1237+
if(net.wurstclient.WurstClient.MC != null)
1238+
{
1239+
net.wurstclient.WurstClient.MC.execute(() -> {
1240+
try
1241+
{
1242+
if(net.wurstclient.WurstClient.MC.player != null
1243+
&& net.wurstclient.WurstClient.MC.player.containerMenu == net.wurstclient.WurstClient.MC.player.inventoryMenu)
1244+
net.wurstclient.WurstClient.MC.player
1245+
.displayClientMessage(
1246+
net.minecraft.network.chat.Component
1247+
.literal(recordedMsg),
1248+
false);
1249+
}catch(Throwable ignored)
1250+
{}
1251+
});
1252+
}
1253+
}catch(Throwable ignored)
1254+
{
1255+
// ignore
12331256
}
1234-
}catch(Throwable ignored)
1235-
{
1236-
// ignore
12371257
}
12381258
// If loot export present, compare now and notify if mismatch
12391259
try
@@ -1655,4 +1675,20 @@ public void removed()
16551675
t.printStackTrace();
16561676
}
16571677
}
1678+
1679+
@Unique
1680+
private boolean wurst$shouldNotifyChestRecorded(String serverIp,
1681+
String dimension, int x, int y, int z)
1682+
{
1683+
String key = String.valueOf(serverIp) + "|" + String.valueOf(dimension)
1684+
+ "|" + x + "," + y + "," + z;
1685+
long now = System.currentTimeMillis();
1686+
if(key.equals(lastChestRecordedKey)
1687+
&& now - lastChestRecordedTimestamp < 500L)
1688+
return false;
1689+
1690+
lastChestRecordedKey = key;
1691+
lastChestRecordedTimestamp = now;
1692+
return true;
1693+
}
16581694
}

0 commit comments

Comments
 (0)