Skip to content

Commit f78cb1b

Browse files
committed
Refactor: spam "final" keyword
1 parent 6d3a345 commit f78cb1b

5 files changed

Lines changed: 48 additions & 55 deletions

File tree

src/main/java/net/evmodder/evmod/apis/ClickUtils.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public record InvAction(int slot, int button, ActionType action){
3434
@Override public InvAction clone(){return new InvAction(slot, button, action);}
3535
}
3636

37-
private static int MAX_CLICKS; public static int getMaxClicks(){return MAX_CLICKS;}
37+
private static int MAX_CLICKS; public static final int getMaxClicks(){return MAX_CLICKS;}
3838
private static int[] tickDurationArr;
3939
private static int tickDurIndex, sumClicksInDuration;
4040
private static long lastTick;
@@ -43,9 +43,9 @@ public record InvAction(int slot, int button, ActionType action){
4343
public static long TICK_DURATION = 51l; // In millis
4444

4545
private static boolean thisClickIsBotted;
46-
public static boolean isThisClickBotted(/*MixinClientPlayerInteractionManager.Friend friend*/){return thisClickIsBotted;}
46+
public static final boolean isThisClickBotted(/*MixinClientPlayerInteractionManager.Friend friend*/){return thisClickIsBotted;}
4747

48-
public static void refreshLimits(final int MAX_CLICKS, int FOR_TICKS){
48+
public static final void refreshLimits(final int MAX_CLICKS, int FOR_TICKS){
4949
if(clickOpOngoing){
5050
Main.LOGGER.error("ClickUtils.refreshLimits() called DURING AN ACTIVE CLICK-OPERATION!! May cause crash or incorrect result");
5151
}
@@ -74,7 +74,7 @@ public static void refreshLimits(final int MAX_CLICKS, int FOR_TICKS){
7474
// return serverInfo == null ? 0 : serverInfo.ping;
7575
// }
7676

77-
private static void updateAvailableClicks(){
77+
private static final void updateAvailableClicks(){
7878
final long curTick = System.currentTimeMillis()/TICK_DURATION;
7979
if(curTick != lastTick){
8080
// final long pingTicks = (long)Math.ceil(getPing()/(double)TICK_DURATION);
@@ -91,14 +91,14 @@ private static void updateAvailableClicks(){
9191
}
9292
}
9393
}
94-
public static int calcAvailableClicks(){
94+
public static final int calcAvailableClicks(){
9595
if(tickDurationArr == null) return MAX_CLICKS;
9696
synchronized(tickDurationArr){
9797
updateAvailableClicks();
9898
return MAX_CLICKS - sumClicksInDuration;
9999
}
100100
}
101-
public static boolean addClick(/*SlotActionType type*/){ // friend MixinClientPlayerInteractionManager?
101+
public static final boolean addClick(/*SlotActionType type*/){ // friend MixinClientPlayerInteractionManager?
102102
// assert type != null; // unused
103103

104104
synchronized(tickDurationArr){
@@ -111,22 +111,22 @@ public static boolean addClick(/*SlotActionType type*/){ // friend MixinClientPl
111111
}
112112
}
113113

114-
private static void adjustTickRate(long msPerTick){
114+
private static final void adjustTickRate(final long msPerTick){
115115
// If TPS is degrading, don't clear old tick data (this isn't a perfect solution by any means)
116116
if(msPerTick > TICK_DURATION) lastTick = System.currentTimeMillis()/TICK_DURATION;
117117
else calcAvailableClicks();
118118
TICK_DURATION = msPerTick;
119119
lastTick = System.currentTimeMillis()/TICK_DURATION;
120120
}
121121

122-
private static int calcRemainingTicks(int clicksToExecute){
122+
private static final int calcRemainingTicks(int clicksToExecute){
123123
synchronized(tickDurationArr){
124124
updateAvailableClicks();
125125
final int availableNow = MAX_CLICKS - sumClicksInDuration;
126126
if(availableNow >= clicksToExecute) return 0;
127127
clicksToExecute -= availableNow;
128128
tickDurationArr[tickDurIndex] += availableNow;
129-
129+
130130
int ticksIntoFuture;
131131
for(ticksIntoFuture = 1; clicksToExecute > 0; ++ticksIntoFuture){
132132
clicksToExecute -= tickDurationArr[(tickDurIndex + ticksIntoFuture) % tickDurationArr.length];
@@ -137,7 +137,7 @@ private static int calcRemainingTicks(int clicksToExecute){
137137
}
138138

139139
private static final Pattern tpsPattern = Pattern.compile("(\\d{1,2}(?:\\.\\d+))\\s?tps", Pattern.CASE_INSENSITIVE);
140-
private static long /*getTPS*/getMillisPerTick(MinecraftClient client){
140+
private static final long /*getTPS*/getMillisPerTick(MinecraftClient client){
141141
// Alternative: client.getNetworkHandler().onPlayerListHeader(PlayerListHeaderS2CPacket plhp)
142142

143143
final AccessorPlayerListHud playerListHudAccessor = (AccessorPlayerListHud)client.inGameHud.getPlayerListHud();
@@ -156,8 +156,8 @@ private static int calcRemainingTicks(int clicksToExecute){
156156

157157
private static boolean clickOpOngoing/*, waitedForClicks*/;
158158
private static int estimatedMsLeft;
159-
public static boolean hasOngoingClicks(){return clickOpOngoing;}
160-
public static void executeClicks(Function<InvAction, Boolean> canProceed, Runnable onComplete, Queue<InvAction> clicks){
159+
public static final boolean hasOngoingClicks(){return clickOpOngoing;}
160+
public static final void executeClicks(final Function<InvAction, Boolean> canProceed, final Runnable onComplete, final Queue<InvAction> clicks){
161161
if(clicks.isEmpty()){
162162
Main.LOGGER.warn("executeClicks() called with an empty ClickEvent list");
163163
onComplete.run();
@@ -183,14 +183,14 @@ public static void executeClicks(Function<InvAction, Boolean> canProceed, Runnab
183183
estimatedMsLeft = Integer.MAX_VALUE;
184184

185185
new Timer().schedule(new TimerTask(){
186-
private void stopTask(){
186+
private final void stopTask(){
187187
synchronized(tickDurationArr){
188188
cancel();
189189
clickOpOngoing=false;
190190
onComplete.run();
191191
}
192192
}
193-
@Override public void run(){
193+
@Override public final void run(){
194194
if(client.player == null){
195195
Main.LOGGER.error("executeClicks() failed due to null player! num clicks in arr: "+sumClicksInDuration);
196196
stopTask(); return;
@@ -211,7 +211,7 @@ private void stopTask(){
211211
Main.LOGGER.error("executeClicks() lost available click mid-op, seemingly due to click(s) occuring during check of canProceed()!");
212212
break;
213213
}
214-
InvAction click = clicks.remove();
214+
final InvAction click = clicks.remove();
215215
try{
216216
// Main.LOGGER.info("Executing click: "+click.slot+","+click.button+","+click.action+" | available="+calcAvailableClicks());
217217
thisClickIsBotted = true;
@@ -253,11 +253,11 @@ private void stopTask(){
253253
}
254254
}, 0l, 23l);//51l = just over a tick, 23l=just under half a tick
255255
}
256-
public static void executeClicks(Function<InvAction, Boolean> canProceed, Runnable onComplete, InvAction... clicks){
256+
public static final void executeClicks(final Function<InvAction, Boolean> canProceed, final Runnable onComplete, final InvAction... clicks){
257257
executeClicks(canProceed, onComplete, new ArrayDeque<>(List.of(clicks)));
258258
}
259259

260-
public static void executeClicksLEGACY(
260+
public static final void executeClicksLEGACY(
261261
MinecraftClient client,
262262
Queue<InvAction> clicks, final int MILLIS_BETWEEN_CLICKS, final int MAX_CLICKS_PER_SECOND,
263263
Function<InvAction, Boolean> canProceed, Runnable onComplete)

src/main/java/net/evmodder/evmod/apis/EpearlActivator.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import net.minecraft.util.shape.VoxelShape;
2323
import net.minecraft.world.RaycastContext;
2424

25-
public class EpearlActivator{
25+
public final class EpearlActivator{
2626
private final EpearlLookupFabric epearlLookup;
2727
private final int REACH = 10;
2828
private final boolean msgFailureFeedback = true;
@@ -31,7 +31,7 @@ public class EpearlActivator{
3131

3232
public EpearlActivator(EpearlLookupFabric epl){epearlLookup = epl;}
3333

34-
public boolean hasLineOfSight(MinecraftClient client, Vec3d from, Vec3d to){
34+
private final boolean hasLineOfSight(MinecraftClient client, Vec3d from, Vec3d to){
3535
return client.world.raycast(
3636
new RaycastContext(from, to, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, client.player))
3737
.getType() == HitResult.Type.MISS;
@@ -43,7 +43,7 @@ public boolean hasLineOfSight(MinecraftClient client, Vec3d from, Vec3d to){
4343
* squared distance to that hit vector, and whether or not there is line of
4444
* sight to that hit vector.
4545
*/
46-
public BlockHitResult getHitResult(MinecraftClient client, BlockPos pos){
46+
private final BlockHitResult getHitResult(MinecraftClient client, BlockPos pos){
4747
Vec3d eyes = client.player.getEyePos();
4848
Direction[] sides = Direction.values();
4949

@@ -78,7 +78,7 @@ public BlockHitResult getHitResult(MinecraftClient client, BlockPos pos){
7878
return new BlockHitResult(hitVecs[bestSide], sides[bestSide], pos, /*insideBlock=*/false);
7979
}
8080

81-
private BlockPos findNearestPearlWithOwnerName(MinecraftClient client, String name){
81+
private final BlockPos findNearestPearlWithOwnerName(MinecraftClient client, String name){
8282
final Vec3d playerPos = client.player.getPos();
8383
double closestDistSq = Double.MAX_VALUE;
8484
Vec3d closestPos = null;
@@ -91,7 +91,7 @@ private BlockPos findNearestPearlWithOwnerName(MinecraftClient client, String na
9191
}
9292
return BlockPos.ofFloored(closestPos);
9393
}
94-
private BlockPos findSignWithName(MinecraftClient client, String name){
94+
private final BlockPos findSignWithName(MinecraftClient client, String name){
9595
final BlockPos playerPos = client.player.getBlockPos();
9696
for(BlockPos pos : BlockPos.iterateOutwards(playerPos, REACH, REACH, REACH)){
9797
if(client.world.getBlockEntity(pos) instanceof SignBlockEntity sbe &&
@@ -106,7 +106,7 @@ private BlockPos findSignWithName(MinecraftClient client, String name){
106106
}
107107
return null;
108108
}
109-
private final boolean isClickableTrigger(BlockState bs){
109+
private final boolean isClickableTrigger(final BlockState bs){
110110
return bs.getBlock() instanceof NoteBlock || bs.isIn(BlockTags.BUTTONS) || bs.isIn(BlockTags.WOODEN_TRAPDOORS);
111111
}
112112
private final BlockPos findNearestTrigger(MinecraftClient client, BlockPos startPos){
@@ -124,7 +124,7 @@ private final BlockPos findNearestTrigger(MinecraftClient client, BlockPos start
124124
return buttonPos;
125125
}
126126

127-
private void sendFeedback(MinecraftClient client, final String who, final String msg){
127+
private final void sendFeedback(MinecraftClient client, final String who, final String msg){
128128
if(!msgFailureFeedback) return;
129129
if(msgCooldown > 0){
130130
final long currTs = System.currentTimeMillis();
@@ -134,7 +134,7 @@ private void sendFeedback(MinecraftClient client, final String who, final String
134134
client.getNetworkHandler().sendChatCommand("w "+who+" "+msg);
135135
}
136136

137-
public void triggerPearl(final String who){
137+
public final void triggerPearl(final String who){
138138
MinecraftClient client = MinecraftClient.getInstance();
139139
BlockPos signPos = findSignWithName(client, who);
140140
if(signPos == null && (signPos=findNearestPearlWithOwnerName(client, who)) == null){

src/main/java/net/evmodder/evmod/apis/InvUtils.java

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

99
public final class InvUtils{
1010
public static final Stream<ItemStack> getAllNestedItems(ItemStack item){
11-
BundleContentsComponent contents = item.get(DataComponentTypes.BUNDLE_CONTENTS);
11+
final BundleContentsComponent contents = item.get(DataComponentTypes.BUNDLE_CONTENTS);
1212
if(contents != null) return getAllNestedItems(contents.stream()/*.sequential()*/);
13-
ContainerComponent container = item.get(DataComponentTypes.CONTAINER);
13+
final ContainerComponent container = item.get(DataComponentTypes.CONTAINER);
1414
if(container != null) return getAllNestedItems(container.streamNonEmpty()/*.sequential()*/);
1515
return Stream.of(item);
1616
}
1717
public static final Stream<ItemStack> getAllNestedItems(Stream<ItemStack> items){
1818
return items.flatMap(InvUtils::getAllNestedItems);
1919
}
2020
public static final Stream<ItemStack> getAllNestedItemsExcludingBundles(ItemStack item){
21-
ContainerComponent container = item.get(DataComponentTypes.CONTAINER);
21+
final ContainerComponent container = item.get(DataComponentTypes.CONTAINER);
2222
if(container != null) return getAllNestedItemsExcludingBundles(container.streamNonEmpty());
2323
return Stream.of(item);
2424
}

src/main/java/net/evmodder/evmod/apis/NewMapNotifier.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ public final class NewMapNotifier{
1616
private static long lastNewMapColorsId;
1717
private static boolean notifyInChat = true;
1818

19-
public static final void call(ItemFrameEntity ife, UUID colorsId){ // Called by UpdateItemFrameHighlights
19+
public static final void call(final ItemFrameEntity ife, final UUID colorsId){ // Called by UpdateItemFrameContents
2020
if(ife.getId() != lastNewMapIfeId && colorsId.getMostSignificantBits() == lastNewMapColorsId) return;
2121
if(System.currentTimeMillis() - lastNewMapNotify < mapNotifyCooldown) return;
2222

23-
boolean isFar = ife.getBlockPos().getSquaredDistance(0, 0, 0) > 20_000d*20_000d;
24-
int x = ife.getBlockX(), z = ife.getBlockZ();
25-
String pos = (isFar ? ".."+Math.abs(x%1000) : x)+" "+ife.getBlockY()+" "+(isFar ? ".."+Math.abs(z%1000) : z);
23+
final boolean isFar = ife.getBlockPos().getSquaredDistance(0, 0, 0) > 20_000d*20_000d;
24+
final int x = ife.getBlockX(), z = ife.getBlockZ();
25+
final String pos = (isFar ? ".."+Math.abs(x%1000) : x)+" "+ife.getBlockY()+" "+(isFar ? ".."+Math.abs(z%1000) : z);
2626

27-
int color = Configs.Visuals.MAP_COLOR_NOT_IN_GROUP.getIntegerValue();
27+
final int color = Configs.Visuals.MAP_COLOR_NOT_IN_GROUP.getIntegerValue();
2828
MinecraftClient.getInstance().player.sendMessage(Text.literal("New mapart: "+pos).withColor(color), true);
2929

3030
if(colorsId.getMostSignificantBits() != lastNewMapColorsId){

src/main/java/net/evmodder/evmod/apis/RemoteServerSender.java

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,46 +35,41 @@ private final void resolveAddress(){
3535
catch(UnknownHostException e){LOGGER.warn("Server not found: "+REMOTE_ADDR);}
3636
}
3737

38-
public final void setConnectionDetails(String addr, int port, int clientId, String clientKey){
38+
public final void setConnectionDetails(final String addr, final int port, final int clientId, final String clientKey){
3939
REMOTE_ADDR = addr; resolveAddress();
4040
PORT = port;
4141
CLIENT_ID = clientId;
4242
CLIENT_KEY = clientKey;
4343
}
4444

45-
public RemoteServerSender(Logger logger, Supplier<Integer> serverAddrGetter){
45+
public RemoteServerSender(final Logger logger, final Supplier<Integer> serverAddrGetter){
4646
LOGGER = logger;
47-
// REMOTE_ADDR = addr; resolveAddress();
48-
// PORT = port;
4947
CURR_SERVER_HASHCODE = serverAddrGetter;
5048

5149
tcpPackets = new LinkedList<>();
5250
udpPackets = new LinkedList<>();
5351
tcpReceivers = new LinkedList<>();
5452
udpReceivers = new LinkedList<>();
55-
56-
// CLIENT_ID = clientId;
57-
// CLIENT_KEY = clientKey;
5853
}
5954

6055
// Returns a `4+message.length+16`-byte packet
6156
private final byte[] packageAndEncryptMessage(final Command command, final byte[/*16*n*/] message){
62-
ByteBuffer bb1 = ByteBuffer.allocate(16+message.length);
57+
final ByteBuffer bb1 = ByteBuffer.allocate(16+message.length);
6358
bb1.putInt(CLIENT_ID);
6459
bb1.putInt(command.ordinal());
6560
final int addressCode = CURR_SERVER_HASHCODE.get();
6661
bb1.putInt(addressCode);
6762
bb1.putInt((int)System.currentTimeMillis());//Truncate, since we assume ping < Integer.MAX anyway
6863
bb1.put(message);
69-
byte[] encryptedMessage = PacketHelper.encrypt(bb1.array(), CLIENT_KEY);
64+
final byte[] encryptedMessage = PacketHelper.encrypt(bb1.array(), CLIENT_KEY);
7065

71-
ByteBuffer bb2 = ByteBuffer.allocate(4+encryptedMessage.length);
66+
final ByteBuffer bb2 = ByteBuffer.allocate(4+encryptedMessage.length);
7267
bb2.putInt(CLIENT_ID);
7368
bb2.put(encryptedMessage);
7469
return bb2.array();
7570
}
7671

77-
private final String formatTimeMillis(long latency){
72+
private final String formatTimeMillis(final long latency){
7873
// Output: 2s734ms
7974
// return TextUtils.formatTime(latency, false, "", 2, new long[]{1000, 1}, new char[]{'s', ' '}).stripTrailing()+"ms";
8075
// Output: 2734ms
@@ -105,18 +100,16 @@ private final void sendPacketSequence(final boolean udp, final long timeout){
105100
public final void sendBotMessage(final Command command, final boolean udp, final long timeout, final byte[] message, final MessageReceiver recv){
106101
final byte[] packet = packageAndEncryptMessage(command, message);
107102
if(addrResolved == null) resolveAddress();
108-
if(addrResolved == null) LOGGER.warn("RemoteSender address could not be resolved!: "+REMOTE_ADDR);
109-
else{
110-
LOGGER.warn("RMS: queuingPacket for cmd: "+command+", len="+packet.length);
111-
final LinkedList<byte[]> packetList = (udp ? udpPackets : tcpPackets);
112-
final LinkedList<MessageReceiver> recvList = (udp ? udpReceivers : tcpReceivers);
113-
synchronized(packetList){
114-
packetList.add(packet);
115-
recvList.add(recv);
116-
if(packetList.size() == 1) sendPacketSequence(udp, timeout);
117-
}
118-
resolveAddress();
103+
if(addrResolved == null){LOGGER.warn("RemoteSender address could not be resolved!: "+REMOTE_ADDR); return;}
104+
LOGGER.warn("RMS: queuingPacket for cmd: "+command+", len="+packet.length);
105+
final LinkedList<byte[]> packetList = (udp ? udpPackets : tcpPackets);
106+
final LinkedList<MessageReceiver> recvList = (udp ? udpReceivers : tcpReceivers);
107+
synchronized(packetList){
108+
packetList.add(packet);
109+
recvList.add(recv);
110+
if(packetList.size() == 1) sendPacketSequence(udp, timeout);
119111
}
112+
resolveAddress();
120113
}
121114

122115
public final static void main(String... args) throws IOException{

0 commit comments

Comments
 (0)