throttle no explicit subchannel warning

This commit is contained in:
Glease committed 2022-09-02 15:45:13 +08:00
1 parent adc91bb1dd
commit 9b318f68fb
5 files changed
+131 -2

No files matched your search

@@ -0,0 +1,30 @@
package com.gtnewhorizon.structurelib.structure;
class ChatThrottleKey {
static class NoExplicitChannel {
private static final int hashOffset = NoExplicitChannel.class.hashCode();
private final String subchannel;
public NoExplicitChannel(String subchannel) {
this.subchannel = subchannel;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof NoExplicitChannel)) return false;
NoExplicitChannel that = (NoExplicitChannel) o;
return subchannel.equals(that.subchannel);
}
@Override
public int hashCode() {
// as this one will be placed within a map along with instances of different classes, it'd be best to add
// an offset based off class type to avoid collision
return subchannel.hashCode() + hashOffset;
}
}
}
@@ -2706,12 +2706,18 @@ public class StructureUtility {
}
private void warnNoExplicitSubChannel(EntityPlayer currentPlayer) {
currentPlayer.addChatComponentMessage(
new ChatComponentTranslation("structurelib.autoplace.warning.no_explicit_channel", channel));
// throttle this warning a bit.
// I'm sure we can finish a check/autoplace round within 100 milliseconds.
StructureLibAPI.addThrottledChat(
new ChatThrottleKey.NoExplicitChannel(channel),
currentPlayer,
new ChatComponentTranslation("structurelib.autoplace.warning.no_explicit_channel", channel),
(short) 100);
}
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
// I hope a CREATIVE player know what he is doing...
// no warning for yah
return backing.placeBlock(t, world, x, y, z, ChannelDataAccessor.withChannel(trigger, channel));
}