Skip to content

Commit b7e33d9

Browse files
committed
Solve some Codacy issues
1 parent 401b2b8 commit b7e33d9

16 files changed

Lines changed: 37 additions & 38 deletions

File tree

__mocks__/@minecraft/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export const Container = class Container {
203203
return void 0
204204
})
205205
firstEmptySlot = vi.fn(() => {
206-
const i = this.#slots.findIndex(s => s === void 0)
206+
const i = this.#slots.indexOf(s => s === void 0)
207207
return i === -1 ? void 0 : i
208208
})
209209
firstItem = vi.fn(() => {
@@ -246,7 +246,7 @@ export const DimensionType = class DimensionType {
246246
export const DimensionTypes = { getAll: vi.fn(() => [new DimensionType("minecraft:overworld"), new DimensionType('minecraft:nether'), new DimensionType('minecraft:the_end')]) }
247247
export const TicksPerSecond = 20.0
248248
export const BlockVolume = class BlockVolume {}
249-
export const EntityItemComponent = class EntityItemComponent { static componentId = 'minecraft:item' }
249+
export const EntityItemComponent = class EntityItemComponent { get componentId() { return 'minecraft:item' } }
250250
export const StructureSaveMode = { Memory: 'Memory', World: 'World' }
251251

252252
export const system = {

__tests__/utils.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,9 @@ describe('portOldGameModeToNewUpdate', () => {
116116
['number', 0],
117117
['boolean', true],
118118
['object', {}],
119-
['undefined', void 0],
120-
['null', null]
119+
['undefined', void 0]
121120
])('throws when given a %s', (type, value) => {
122-
expect(() => portOldGameModeToNewUpdate(value)).toThrow()
121+
expect(() => portOldGameModeToNewUpdate(value)).toThrow(expect.objectContaining({ message: expect.stringContaining(type) }))
123122
})
124123
})
125124

packs/BP/scripts/classes/GameRuleCertifier.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class GameRuleCertifier {
66
}
77

88
static fixGameRules() {
9-
this.setGameRules(this.getGameRules());
9+
GameRuleCertifier.setGameRules(GameRuleCertifier.getGameRules());
1010
}
1111

1212
static setGameRules(newGameRules) {

packs/BP/scripts/classes/Understudies.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ class Understudies {
66
static understudies = [];
77

88
static onStartup() {
9-
this.#subscribeToEvents();
10-
this.#startProcessingPlayers();
9+
Understudies.#subscribeToEvents();
10+
Understudies.#startProcessingPlayers();
1111
}
1212

1313
static #subscribeToEvents() {
14-
world.afterEvents.entityDie.subscribe(Understudies.onEntityDie.bind(this));
15-
world.afterEvents.playerGameModeChange.subscribe(Understudies.onPlayerGameModeChange.bind(this));
14+
world.afterEvents.entityDie.subscribe(Understudies.onEntityDie.bind(Understudies));
15+
world.afterEvents.playerGameModeChange.subscribe(Understudies.onPlayerGameModeChange.bind(Understudies));
1616
}
1717

1818
static #startProcessingPlayers() {
1919
system.runInterval(() => {
20-
for (const understudy of this.understudies) {
20+
for (const understudy of Understudies.understudies) {
2121
if (understudy.isConnected())
2222
understudy.onConnectedTick();
2323
}
@@ -27,24 +27,24 @@ class Understudies {
2727
static onEntityDie(event) {
2828
if (event.deadEntity.typeId !== 'minecraft:player')
2929
return;
30-
const understudy = this.get(event.deadEntity?.name);
30+
const understudy = Understudies.get(event.deadEntity?.name);
3131
if (understudy !== void 0) {
3232
understudy.leave();
33-
this.remove(understudy);
33+
Understudies.remove(understudy);
3434
}
3535
}
3636

3737
static onPlayerGameModeChange(event) {
38-
const understudy = this.get(event.player?.name);
38+
const understudy = Understudies.get(event.player?.name);
3939
if (understudy !== void 0)
4040
understudy.savePlayerInfo();
4141
}
4242

4343
static create(name) {
44-
if (this.isOnline(name))
44+
if (Understudies.isOnline(name))
4545
throw new Error(`[Understudy] Player with name ${name} already exists.`);
4646
const understudy = new Understudy(name);
47-
this.understudies.push(understudy);
47+
Understudies.understudies.push(understudy);
4848
return understudy;
4949
}
5050

@@ -55,7 +55,7 @@ class Understudies {
5555
}
5656

5757
static get(name) {
58-
return this.understudies.find(p => p.name === name);
58+
return Understudies.understudies.find(p => p.name === name);
5959
}
6060

6161
static remove(understudy) {
@@ -68,35 +68,35 @@ class Understudies {
6868
const runner = system.runInterval(() => {
6969
if (!understudy.isConnected()) {
7070
system.clearRun(runner);
71-
const index = this.understudies.indexOf(understudy);
72-
this.understudies.splice(index, 1);
71+
const index = Understudies.understudies.indexOf(understudy);
72+
Understudies.understudies.splice(index, 1);
7373
}
7474
});
7575
}
7676

7777
static removeAll() {
78-
for (const understudy of [...this.understudies])
79-
this.remove(understudy);
78+
for (const understudy of [...Understudies.understudies])
79+
Understudies.remove(understudy);
8080
}
8181

8282

8383
static length() {
84-
return this.understudies.length;
84+
return Understudies.understudies.length;
8585
}
8686

8787
static setNametagPrefix(prefix) {
8888
world.setDynamicProperty('nametagPrefix', prefix);
8989
if (prefix === '') {
90-
for (const understudy of this.understudies)
90+
for (const understudy of Understudies.understudies)
9191
understudy.simulatedPlayer.nameTag = understudy.name;
9292
} else {
93-
for (const understudy of this.understudies)
93+
for (const understudy of Understudies.understudies)
9494
understudy.simulatedPlayer.nameTag = `[${prefix}§r] ${understudy.name}`;
9595
}
9696
}
9797

9898
static isOnline(name) {
99-
return this.get(name) !== void 0;
99+
return Understudies.get(name) !== void 0;
100100
}
101101

102102
static getNotOnlineMessage(name) {

packs/BP/scripts/classes/UnderstudyInventorySaver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import SRCItemDatabase from "../lib/SRCItemDatabase/ItemDatabase.js";
44
export class UnderstudyInventorySaver {
55
constructor(understudy) {
66
this.understudy = understudy;
7-
const tableName = 'bot_' + understudy.name.substr(0, 8);
7+
const tableName = `bot_${understudy.name.substr(0, 8)}`;
88
this.itemDatabase = new SRCItemDatabase(tableName);
99
this.inventoryDP = `${tableName}_inventory`;
1010
this.equippableDP = `${tableName}_equippable`;

packs/BP/scripts/commands/action.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class ActionCommand extends Command {
4545
});
4646
}
4747

48-
actionCommand(origin, playername, action, timingOption = TIMING_OPTIONS.ONCE, ticks) {
48+
actionCommand(_origin, playername, action, timingOption = TIMING_OPTIONS.ONCE, ticks) {
4949
const understudy = Understudies.get(playername);
5050
if (!understudy)
5151
return { status: CustomCommandStatus.Failure, message: Understudies.getNotOnlineMessage(playername) };

packs/BP/scripts/commands/claimprojectiles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class ClaimProjectilesCommand extends Command {
1515
});
1616
}
1717

18-
claimprojectilesCommand(origin, playername, radius = 25) {
18+
claimprojectilesCommand(_origin, playername, radius = 25) {
1919
const understudy = Understudies.get(playername);
2020
if (!understudy)
2121
return { status: CustomCommandStatus.Failure, message: Understudies.getNotOnlineMessage(playername) };

packs/BP/scripts/commands/inventory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class InventoryCommand extends Command {
1414
});
1515
}
1616

17-
inventoryCommand(origin, playername) {
17+
inventoryCommand(_origin, playername) {
1818
const understudy = Understudies.get(playername);
1919
if (!understudy)
2020
return { status: CustomCommandStatus.Failure, message: Understudies.getNotOnlineMessage(playername) };

packs/BP/scripts/commands/prefix.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class PrefixCommand extends Command {
1414
});
1515
}
1616

17-
prefixCommand(origin, prefix) {
17+
prefixCommand(_origin, prefix) {
1818
if (prefix === '-none') {
1919
system.run(() => Understudies.setNametagPrefix(''));
2020
return { status: CustomCommandStatus.Success, message: '§7Simplayer prefix removed.' };

packs/BP/scripts/commands/select.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class SelectCommand extends Command {
1717
});
1818
}
1919

20-
selectCommand(origin, playername, slotNumber) {
20+
selectCommand(_origin, playername, slotNumber) {
2121
const understudy = Understudies.get(playername);
2222
if (!understudy)
2323
return { status: CustomCommandStatus.Failure, message: Understudies.getNotOnlineMessage(playername) };

0 commit comments

Comments
 (0)