Skip to content

Commit 5358a85

Browse files
committed
last sonarqube
1 parent 76bbe75 commit 5358a85

13 files changed

+158
-131
lines changed

src/main/java/net/jasper/mod/automation/PlayerRecorder.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
*/
4444
public class PlayerRecorder {
4545

46-
public static Recording record = new Recording(null);
46+
public static Recording recording = new Recording(null);
4747
public static NativeImageBackedTexture thumbnailTexture = null;
4848
public static final Identifier THUMBNAIL_TEXTURE_IDENTIFIER = Identifier.of(PlayerautomaClient.MOD_ID, "current_recording_thumbnail");
4949

@@ -72,7 +72,7 @@ public class PlayerRecorder {
7272
@SuppressWarnings("java:S3776")
7373
public static void register() {
7474
// Always reset the PlayerRecorder if a Join event happens could be breaking the mod. Therefor leave it out now.
75-
// ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> PlayerRecorder.reset());
75+
// ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> PlayerRecorder.reset()); NOSONAR
7676

7777
// Register Task-Queues
7878
tasks.register("playerActions");
@@ -120,7 +120,7 @@ public static void register() {
120120
lastVillagerTradeMade.poll(),
121121
lastEnchantmentMade.poll()
122122
);
123-
record.add(newEntry);
123+
recording.add(newEntry);
124124
});
125125
}
126126

@@ -153,7 +153,7 @@ public static void startRecord() {
153153
if (Boolean.TRUE.equals(PlayerautomaOptionsScreen.saveThumbnailsWithRecording.getValue())) {
154154
ThumbnailHelpers.create((thumbnail, nativeImage) -> {
155155
if (thumbnail != null) {
156-
record.thumbnail = thumbnail;
156+
recording.thumbnail = thumbnail;
157157
thumbnailTexture = new NativeImageBackedTexture(() -> "test", nativeImage);
158158
// Destroy old texture and register new
159159
MinecraftClient.getInstance().getTextureManager().destroyTexture(THUMBNAIL_TEXTURE_IDENTIFIER);
@@ -185,7 +185,7 @@ public static void stopRecord() {
185185
}
186186

187187
public static void clearRecord() {
188-
record.clear();
188+
recording.clear();
189189
thumbnailTexture = null;
190190
MinecraftClient.getInstance().getTextureManager().destroyTexture(THUMBNAIL_TEXTURE_IDENTIFIER);
191191
}
@@ -223,24 +223,22 @@ public static void startReplay(int loopCount) {
223223
* if looped is true and count is negative loop indefinitely
224224
* if looped is true and count is positive loop for that amount
225225
*/
226-
@SuppressWarnings("java:S3776")
226+
@SuppressWarnings({"java:S3776", "java:S6541"})
227227
private static void startReplay(boolean looped, int loopCount) {
228228
if (state.isRecording() || state.isPausedRecording()) {
229229
ClientHelpers.writeToActionBar(Text.translatable("playerautoma.messages.error.cannotStartReplayWhileRecording"));
230230
return;
231231
}
232232

233-
if (record.isEmpty()) {
233+
if (recording.isEmpty()) {
234234
ClientHelpers.writeToActionBar(Text.translatable("playerautoma.messages.error.startEmptyRecording"));
235235
return;
236236
}
237237

238-
if (state.isAny(RECORDING, REPLAYING)) {
239-
// if state is replaying and has no tasks its looped therefore just continue and if not return
240-
if (!(state.isReplaying() && tasks.isEmpty())) {
241-
ClientHelpers.writeToActionBar(Text.translatable("playerautoma.messages.error.cannotStartReplayWhileReplaying"));
242-
return;
243-
}
238+
// if state is replaying and has no tasks its looped therefore just continue and if not return
239+
if (state.isAny(RECORDING, REPLAYING) && !(state.isReplaying() && tasks.isEmpty())) {
240+
ClientHelpers.writeToActionBar(Text.translatable("playerautoma.messages.error.cannotStartReplayWhileReplaying"));
241+
return;
244242
}
245243

246244
// If menu prevention is activated enable it by default if not already enabled
@@ -263,11 +261,11 @@ private static void startReplay(boolean looped, int loopCount) {
263261
boolean isRelative = !PlayerautomaOptionsScreen.useDefaultDirectionOption.getValue();
264262

265263
// Get first RecordEntry Looking direction to calculate difference
266-
LookingDirection l = record.entries.getFirst().lookingDirection();
264+
LookingDirection l = recording.getEntries().getFirst().lookingDirection();
267265
float pitchDiff = isRelative ? l.pitch() - client.player.getPitch() : 0;
268266
float yawDiff = isRelative ? l.yaw() - client.player.getYaw() : 0;
269267

270-
for (Recording.RecordEntry entry : record.entries) {
268+
for (Recording.RecordEntry entry : recording.getEntries()) {
271269
// Get all data for current record tick (i) to replay
272270
List<String> keysPressed = entry.keysPressed();
273271
Map<String, Integer> timesPressed = entry.timesPressed();
@@ -398,7 +396,7 @@ public static void startLoop() {
398396
return;
399397
}
400398

401-
if (record.isEmpty()) {
399+
if (recording.isEmpty()) {
402400
ClientHelpers.writeToActionBar(Text.translatable("playerautoma.messages.error.startEmptyRecording"));
403401
return;
404402
}
@@ -409,7 +407,7 @@ public static void startLoop() {
409407

410408

411409
public static void togglePauseReplay() {
412-
if (!state.isAny(REPLAYING, PAUSED_REPLAY) || record.isEmpty()) {
410+
if (!state.isAny(REPLAYING, PAUSED_REPLAY) || recording.isEmpty()) {
413411
ClientHelpers.writeToActionBar(Text.translatable("playerautoma.messages.error.cannotTogglePauseReplayWhileInvalidState"));
414412
return;
415413

@@ -430,7 +428,7 @@ public static void togglePauseReplay() {
430428

431429

432430
public static void togglePauseRecord() {
433-
if (!state.isAny(RECORDING, PAUSED_RECORDING) || record.isEmpty()) {
431+
if (!state.isAny(RECORDING, PAUSED_RECORDING) || recording.isEmpty()) {
434432
ClientHelpers.writeToActionBar(Text.translatable("playerautoma.messages.error.cannotTogglePauseRecordingWhileInvalidState"));
435433
return;
436434
}
@@ -483,14 +481,14 @@ public static void stopReplay() {
483481

484482

485483
public static void storeRecord(String name) {
486-
if (record.isEmpty()) {
484+
if (recording.isEmpty()) {
487485
ClientHelpers.writeToActionBar(Text.translatable("playerautoma.messages.error.cannotStoreEmpty"));
488486
return;
489487
} else if (state.isAny(RECORDING, REPLAYING)) {
490488
ClientHelpers.writeToActionBar(Text.translatable("playerautoma.messages.error.cannotStoreDueToState"));
491489
return;
492490
}
493-
boolean success = IOHelpers.storeRecordingFile(record, new File(PLAYERAUTOMA_RECORDING_PATH), name);
491+
boolean success = IOHelpers.storeRecordingFile(recording, new File(PLAYERAUTOMA_RECORDING_PATH), name);
494492
Text feedback = success ? Text.translatable("playerautoma.messages.storedRecording") : Text.translatable("playerautoma.messages.error.storeFailed");
495493
ClientHelpers.writeToActionBar(feedback);
496494
}
@@ -509,7 +507,7 @@ public static void loadRecord(File selected) {
509507
// Do not load async as we ant the result as fast as possible
510508
Recording r = IOHelpers.loadRecordingFile(new File(PLAYERAUTOMA_RECORDING_PATH), selected);
511509
if (r.isEmpty()) ClientHelpers.writeToActionBar(Text.translatable("playerautoma.messages.error.loadFailed"));
512-
else record = r;
510+
else recording = r;
513511

514512
// Destroy old texture, register new one if present
515513
MinecraftClient.getInstance().getTextureManager().destroyTexture(THUMBNAIL_TEXTURE_IDENTIFIER);

src/main/java/net/jasper/mod/automation/QuickSlots.java

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
@NoArgsConstructor(access = AccessLevel.PRIVATE)
2828
public class QuickSlots {
2929

30-
public static final int QUICKSLOTS_N = 9;
30+
public static final int SLOTS_AMOUNT = 9;
3131

32-
public static final Recording[] QUICKSLOTS = new Recording[QUICKSLOTS_N];
33-
public static final String[] QUICKSLOT_FILE_NAMES = {
32+
public static final Recording[] SLOTS = new Recording[SLOTS_AMOUNT];
33+
public static final String[] SLOT_FILE_NAMES = {
3434
"quickslot_1.rec",
3535
"quickslot_2.rec",
3636
"quickslot_3.rec",
@@ -43,26 +43,26 @@ public class QuickSlots {
4343
};
4444

4545
// KeyBinding State
46-
private static final int[] storeCooldowns = new int[QUICKSLOTS_N];
47-
private static final int[] loadCooldowns = new int[QUICKSLOTS_N];
48-
private static final boolean[] CTRLPressed = new boolean[QUICKSLOTS_N];
49-
private static final boolean[] ALTPressed = new boolean[QUICKSLOTS_N];
46+
private static final int[] storeCooldowns = new int[SLOTS_AMOUNT];
47+
private static final int[] loadCooldowns = new int[SLOTS_AMOUNT];
48+
private static final boolean[] CTRLPressed = new boolean[SLOTS_AMOUNT];
49+
private static final boolean[] ALTPressed = new boolean[SLOTS_AMOUNT];
5050
private static final int COOLDOWN = 5;
5151

5252
private static void store(int slot, Recording recording) {
53-
if (slot < 0 || slot >= QUICKSLOTS_N) {
53+
if (slot < 0 || slot >= SLOTS_AMOUNT) {
5454
return;
5555
}
5656

57-
QUICKSLOTS[slot] = recording;
58-
NativeImageBackedTexture texture = recording.thumbnail != null ? new NativeImageBackedTexture(() -> QUICKSLOT_FILE_NAMES[slot], recording.thumbnail.toNativeImage()) : null;
57+
SLOTS[slot] = recording;
58+
NativeImageBackedTexture texture = recording.thumbnail != null ? new NativeImageBackedTexture(() -> SLOT_FILE_NAMES[slot], recording.thumbnail.toNativeImage()) : null;
5959
updateQuickSlotTexture(slot, texture);
6060
// I assume that this doesn't fail, and therefore I don't check a return value i created to check this fails ...
61-
IOHelpers.storeRecordingFile(QUICKSLOTS[slot], new File(PLAYERAUTOMA_QUICKSLOT_PATH), QUICKSLOT_FILE_NAMES[slot], IOHelpers.RecordingFileTypes.REC, true);
61+
IOHelpers.storeRecordingFile(SLOTS[slot], new File(PLAYERAUTOMA_QUICKSLOT_PATH), SLOT_FILE_NAMES[slot], IOHelpers.RecordingFileTypes.REC, true);
6262
}
6363

6464
private static Recording load(int slot) {
65-
return QUICKSLOTS[slot];
65+
return SLOTS[slot];
6666
}
6767

6868
public static final Identifier[] THUMBNAIL_IDENTIFIER;
@@ -81,7 +81,7 @@ private static Recording load(int slot) {
8181
Identifier.of(PlayerautomaClient.MOD_ID, "quickslot_8"),
8282
Identifier.of(PlayerautomaClient.MOD_ID, "quickslot_9"),
8383
};
84-
Arrays.fill(QUICKSLOTS, new Recording(null));
84+
Arrays.fill(SLOTS, new Recording(null));
8585
Arrays.fill(ALTPressed, false);
8686
Arrays.fill(CTRLPressed, false);
8787
Arrays.fill(storeCooldowns, 0);
@@ -90,19 +90,19 @@ private static Recording load(int slot) {
9090

9191
public static void clearQuickSlot() {
9292
ClientHelpers.writeToActionBar(Text.translatable("playerautoma.messages.clearedAllQuickSlot"));
93-
for (int i = 0; i < QUICKSLOTS_N; i++) {
94-
QUICKSLOTS[i].clear();
93+
for (int i = 0; i < SLOTS_AMOUNT; i++) {
94+
SLOTS[i].clear();
9595
// Clear file and thumbnail texture
96-
store(i, QUICKSLOTS[i]);
96+
store(i, SLOTS[i]);
9797
ClientHelpers.writeToActionBar(Text.translatable("playerautoma.messages.clearedAllQuickSlot"));
9898
}
9999
}
100100

101101
public static void clearQuickSlot(int slot) {
102-
if (slot >= 0 && slot <= QUICKSLOTS_N) {
103-
QUICKSLOTS[slot].clear();
102+
if (slot >= 0 && slot <= SLOTS_AMOUNT) {
103+
SLOTS[slot].clear();
104104
// Clear file and thumbnail texture
105-
store(slot, QUICKSLOTS[slot]);
105+
store(slot, SLOTS[slot]);
106106
ClientHelpers.writeToActionBar(Text.translatable("playerautoma.messages.clearedOneQuickSlot").append(" " + (slot + 1)));
107107
}
108108
}
@@ -135,7 +135,7 @@ private static void consumeKeyPress(KeyBinding key, int limit) {
135135
}
136136

137137
public static void updateQuickSlotTexture(int slot, NativeImageBackedTexture texture) {
138-
if (slot < 0 || slot >= QUICKSLOTS_N) {
138+
if (slot < 0 || slot >= SLOTS_AMOUNT) {
139139
return;
140140
}
141141

@@ -147,7 +147,7 @@ public static void updateQuickSlotTexture(int slot, NativeImageBackedTexture tex
147147
}
148148

149149
public static void loadRecording(int slot) {
150-
if (slot < 0 || slot >= QUICKSLOTS_N) {
150+
if (slot < 0 || slot >= SLOTS_AMOUNT) {
151151
return;
152152
}
153153

@@ -161,45 +161,45 @@ public static void loadRecording(int slot) {
161161
return;
162162
}
163163

164-
PlayerRecorder.record = r;
164+
PlayerRecorder.recording = r;
165165
// Destroy old texture, register new one if present
166166
MinecraftClient.getInstance().getTextureManager().destroyTexture(PlayerRecorder.THUMBNAIL_TEXTURE_IDENTIFIER);
167167
if (r.thumbnail != null) {
168-
PlayerRecorder.thumbnailTexture = new NativeImageBackedTexture(() -> QUICKSLOT_FILE_NAMES[slot], r.thumbnail.toNativeImage());
168+
PlayerRecorder.thumbnailTexture = new NativeImageBackedTexture(() -> SLOT_FILE_NAMES[slot], r.thumbnail.toNativeImage());
169169
MinecraftClient.getInstance().getTextureManager().registerTexture(PlayerRecorder.THUMBNAIL_TEXTURE_IDENTIFIER, PlayerRecorder.thumbnailTexture);
170170
}
171171

172172
ClientHelpers.writeToActionBar(Text.translatable("playerautoma.messages.loadQuickslot").append(Text.of("" + (slot + 1))));
173173
}
174174

175175
public static void storeRecording(int slot) {
176-
if (slot < 0 || slot >= QUICKSLOTS_N) {
176+
if (slot < 0 || slot >= SLOTS_AMOUNT) {
177177
return;
178178
}
179179

180180
// Check if store operation can be done
181181
if (PlayerRecorder.state != PlayerRecorder.State.IDLE) {
182182
ClientHelpers.writeToActionBar(Text.translatable("playerautoma.messages.error.cannotStoreDueToState"));
183183
return;
184-
} else if (PlayerRecorder.record == null || PlayerRecorder.record.isEmpty()) {
184+
} else if (PlayerRecorder.recording == null || PlayerRecorder.recording.isEmpty()) {
185185
ClientHelpers.writeToActionBar(Text.translatable("playerautoma.messages.error.cannotStoreEmpty"));
186186
return;
187187
}
188188

189189
// Store quickslots to file to be persistent in store
190-
store(slot, PlayerRecorder.record.copy());
190+
store(slot, PlayerRecorder.recording.copy());
191191
ClientHelpers.writeToActionBar(Text.translatable("playerautoma.messages.storeQuickslot").append(Text.of("" + (slot + 1))));
192192
}
193193

194194
@SuppressWarnings("java:S3776")
195195
public static void register() {
196196
// Load persistent quickslots.
197-
for (int i = 0; i < QUICKSLOTS_N; i++) {
198-
Recording r = IOHelpers.loadRecordingFile(new File(PLAYERAUTOMA_QUICKSLOT_PATH), new File(QUICKSLOT_FILE_NAMES[i]));
199-
QUICKSLOTS[i] = r;
197+
for (int i = 0; i < SLOTS_AMOUNT; i++) {
198+
Recording r = IOHelpers.loadRecordingFile(new File(PLAYERAUTOMA_QUICKSLOT_PATH), new File(SLOT_FILE_NAMES[i]));
199+
SLOTS[i] = r;
200200
if (r.thumbnail != null) {
201201
int finalI = i;
202-
MinecraftClient.getInstance().getTextureManager().registerTexture(THUMBNAIL_IDENTIFIER[i], new NativeImageBackedTexture(() -> QUICKSLOT_FILE_NAMES[finalI], r.thumbnail.toNativeImage()));
202+
MinecraftClient.getInstance().getTextureManager().registerTexture(THUMBNAIL_IDENTIFIER[i], new NativeImageBackedTexture(() -> SLOT_FILE_NAMES[finalI], r.thumbnail.toNativeImage()));
203203
}
204204
}
205205

@@ -245,11 +245,11 @@ public static void register() {
245245
});
246246
}
247247

248-
private static boolean CTRLPressed(long handle) {
248+
private static boolean CTRLPressed(long handle) { // NOSONAR
249249
return InputUtil.isKeyPressed(handle, GLFW.GLFW_KEY_LEFT_CONTROL) || InputUtil.isKeyPressed(handle, GLFW.GLFW_KEY_RIGHT_CONTROL);
250250
}
251251

252-
private static boolean ALTPressed(long handle) {
252+
private static boolean ALTPressed(long handle) { // NOSONAR
253253
return InputUtil.isKeyPressed(handle, GLFW.GLFW_KEY_LEFT_ALT) || InputUtil.isKeyPressed(handle, GLFW.GLFW_KEY_RIGHT_ALT);
254254
}
255255
}

src/main/java/net/jasper/mod/gui/PlayerautomaHUD.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,6 @@ private static void render(DrawContext context, RenderTickCounter tickCounter) {
167167

168168
public static void register() {
169169
HudLayerRegistrationCallback.EVENT.register(layeredDrawerWrapper ->
170-
layeredDrawerWrapper.attachLayerAfter(IdentifiedLayer.HOTBAR_AND_BARS, PLAYERAUTOMA_HUD_LAYER, PlayerautomaHUD::render)); ;
170+
layeredDrawerWrapper.attachLayerAfter(IdentifiedLayer.HOTBAR_AND_BARS, PLAYERAUTOMA_HUD_LAYER, PlayerautomaHUD::render));
171171
}
172172
}

0 commit comments

Comments
 (0)