Skip to content

Commit

Permalink
Fix eslint errors and warnings (and more) (#227)
Browse files Browse the repository at this point in the history
* eslint and hit action fix

* rename

* more fixes

* fix waterlogging

* consistency

* even more fixes
  • Loading branch information
CrackedMatter authored Feb 6, 2024
1 parent 333401a commit fa8d90f
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 56 deletions.
1 change: 1 addition & 0 deletions src/library/classes/databaseBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-types */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Entity, World, world } from "@minecraft/server";
import { Server } from "./serverBuilder.js";
Expand Down
10 changes: 5 additions & 5 deletions src/library/classes/uiFormBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class MenuContext<T extends {}> implements MenuContextType<T> {

goto(menu?: UIFormName) {
if (menu && this.stack[this.stack.length - 1] === "$___confirmMenu___") {
throw Error("Can't go to another form from a confirmation menu!");
throw Error("Can't go to another form from a confirmation menu!");
}
this._goto(menu);
}
Expand All @@ -203,10 +203,10 @@ class MenuContext<T extends {}> implements MenuContextType<T> {
confirm(title: string, message: string, yes: UIAction<T, void>, no?: UIAction<T, void>) {
this.stack.push("$___confirmMenu___");
const form = new MessageUIForm({
title,
message,
button1: { text: "No", action: no ?? ((ctx) => ctx.back()) },
button2: { text: "Yes", action: yes },
title,
message,
button1: { text: "No", action: no ?? ((ctx) => ctx.back()) },
button2: { text: "Yes", action: yes },
});
form.enter(this.player, this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/commands/utilities/drain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ registerCommand(registerInformation, function* (session, builder, args) {
for (const loc of blocks) {
const block = dimension.getBlock(loc);
if (drainWaterLogged && !block.typeId.match(fluidMatch)) {
block.isWaterlogged = false;
block.setWaterlogged(false);
} else {
block.setPermutation(air);
}
Expand Down
4 changes: 2 additions & 2 deletions src/server/modules/biome_data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dimension, Vector3, world, Entity, DataDrivenEntityTriggerBeforeEvent, DataDrivenEntityTriggerAfterEvent } from "@minecraft/server";
import { Dimension, Vector3, world, Entity } from "@minecraft/server";
import { commandSyntaxError, contentLog, CustomArgType, Database, Vector } from "@notbeer-api";
import { EventEmitter } from "library/classes/eventEmitter.js";
import { locToString, wrap } from "../util.js";
Expand Down Expand Up @@ -157,7 +157,7 @@ class BiomeDetector extends EventEmitter implements PooledResource {
reject(err);
}

const onEvent = (ev: DataDrivenEntityTriggerAfterEvent) => {
const onEvent = () => {
try {
const biomeId = biomeScores.getScore(this.entity.scoreboardIdentity);
this.entity.triggerEvent("wedit:despawn");
Expand Down
2 changes: 1 addition & 1 deletion src/server/modules/selection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { regionBounds, regionVolume, Vector } from "@notbeer-api";
import { MolangVariableMap, Player, system } from "@minecraft/server";
import { Player, system } from "@minecraft/server";
import { Shape, shapeGenOptions } from "../shapes/base_shape.js";
import { SphereShape } from "../shapes/sphere.js";
import { CuboidShape } from "../shapes/cuboid.js";
Expand Down
2 changes: 1 addition & 1 deletion src/server/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class PlayerSession {
});
return v;
});

if (!this.getTools().length) {
this.bindTool("selection_wand", config.wandItem);
this.bindTool("navigation_wand", config.navWandItem);
Expand Down
6 changes: 3 additions & 3 deletions src/server/shapes/base_shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export abstract class Shape {
* @return True if a block should be generated; false otherwise
*/
protected abstract inShape(relLoc: Vector, genVars: shapeGenVars): boolean;

/**
* Generates a list of particles that when displayed, shows the shape.
*/
Expand Down Expand Up @@ -112,8 +112,8 @@ export abstract class Shape {
protected drawCircle(center: Vector, radius: number, axis: "x"|"y"|"z"): [string, Vector][] {
const [rotate, vec]: [typeof Vector.prototype.rotateX, Vector] =
axis === "x" ? [Vector.prototype.rotateX, new Vector(0, 1, 0)] :
axis === "y" ? [Vector.prototype.rotateY, new Vector(1, 0, 0)] :
[Vector.prototype.rotateZ, new Vector(0, 1, 0)];
axis === "y" ? [Vector.prototype.rotateY, new Vector(1, 0, 0)] :
[Vector.prototype.rotateZ, new Vector(0, 1, 0)];
const resolution = snap(Math.min(radius * 2*Math.PI, 36), 4);

const points: [string, Vector][] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/server/shapes/cuboid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class CuboidShape extends Shape {
public getYRange() {
return <[number, number]>[0, this.size[1] - 1];
}

public getOutline(loc: Vector) {
const min = loc;
const max = loc.add(this.size);
Expand Down
2 changes: 1 addition & 1 deletion src/server/shapes/cylinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class CylinderShape extends Shape {
locWithOffset.add([maxRadius, 0, 0]), locWithOffset.add([maxRadius, this.height, 0]),
locWithOffset.add([0, 0, -maxRadius]), locWithOffset.add([0, this.height, -maxRadius]),
locWithOffset.add([0, 0, maxRadius]), locWithOffset.add([0, this.height, maxRadius]),
]
];
const edges: [number, number][] = [[0, 1], [2, 3], [4, 5], [6, 7]];
return [
...this.drawCircle(loc.sub([0, 0.5, 0]), maxRadius, "y"),
Expand Down
2 changes: 1 addition & 1 deletion src/server/shapes/pyramid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class PyramidShape extends Shape {
throw new Error("getYRange not implemented!");
return null;
}

public getOutline(loc: Vector) {
const vertices = [
loc.add([-this.size + 1, 0, -this.size + 1]),
Expand Down
12 changes: 6 additions & 6 deletions src/server/tools/base_tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export abstract class Tool {
*/
readonly drop: (self: Tool, player: Player, session: PlayerSession) => void | Generator<unknown, void>;
/**
* The function that's called every tick the tool is held.
*/
readonly tick: (self: Tool, player: Player, session: PlayerSession, tick: number) => Generator<unknown>;
/**
* The function that's called when the tool stops being held.
*/
* The function that's called when the tool stops being held.
*/
readonly stopHold: (self: Tool, player: Player, session: PlayerSession) => void | Generator<unknown, void>;
/**
* The function that's called every tick the tool is held.
*/
readonly tick: (self: Tool, player: Player, session: PlayerSession, tick: number) => void | Generator<unknown, void>;
/**
* The permission required for the tool to be used.
*/
Expand Down
33 changes: 16 additions & 17 deletions src/server/tools/generation_tools.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dimension, Player, Vector3, system } from "@minecraft/server";
import { Player, Vector3, system } from "@minecraft/server";
import { PlayerUtil } from "@modules/player_util";
import { RawText, Server, Vector, regionBounds } from "@notbeer-api";
import { generateLine } from "server/commands/region/line";
Expand All @@ -10,12 +10,11 @@ import { Jobs } from "@modules/jobs";
import { SphereShape } from "server/shapes/sphere";
import { CylinderShape } from "server/shapes/cylinder";
import { PyramidShape } from "server/shapes/pyramid";
import { Shape } from "server/shapes/base_shape";

function trySpawnParticle(player: Player, type: string, location: Vector3) {
try {
player.spawnParticle(type, location);
} catch {}
} catch { /* pass */ }
}

abstract class GeneratorTool extends Tool {
Expand All @@ -33,7 +32,7 @@ abstract class GeneratorTool extends Tool {
return true;
}
return false;
};
}

protected baseTick(player: Player, session: PlayerSession) {
if (system.currentTick % 5 !== 0 || !this.posStart.has(session) || !session.drawOutlines || this.posStart.get(session)[1] !== player.dimension.id) {
Expand Down Expand Up @@ -62,7 +61,7 @@ abstract class GeneratorTool extends Tool {
stopHold = function (self: GeneratorTool, _: Player, session: PlayerSession) {
self.posStart.delete(session);
};

drop = function (self: GeneratorTool, _: Player, session: PlayerSession) {
self.posStart.delete(session);
};
Expand All @@ -73,7 +72,7 @@ class DrawLineTool extends GeneratorTool {

commonUse = function* (self: DrawLineTool, player: Player, session: PlayerSession, loc?: Vector) {
if (self.baseUse(player, session, loc)) return;

const pos1 = self.getFirstPos(session);
const pos2 = self.traceForPos(player);
const [start, end] = regionBounds([pos1, pos2]);
Expand Down Expand Up @@ -109,7 +108,7 @@ class DrawLineTool extends GeneratorTool {
print(RawText.translate("commands.blocks.wedit:created").with(`${count}`), player, true);
};

tick = function* (self: DrawLineTool, player: Player, session: PlayerSession) {
tick = function (self: DrawLineTool, player: Player, session: PlayerSession) {
if (self.baseTick(player, session)) return;

let lineStart = self.getFirstPos(session);
Expand All @@ -135,7 +134,7 @@ class DrawLineTool extends GeneratorTool {
trySpawnParticle(player, "wedit:selection_draw", Vector.add(p, [1, 1, 1]));
});
};

useOn = this.commonUse;
use = this.commonUse;
}
Expand All @@ -157,11 +156,11 @@ class DrawSphereTool extends GeneratorTool {
const job = Jobs.startJob(session, 2, sphereShape.getRegion(center));
const count = yield* Jobs.perform(job, sphereShape.generate(center, pattern, null, session));
Jobs.finishJob(job);

print(RawText.translate("commands.blocks.wedit:created").with(`${count}`), player, true);
};

tick = function* (self: DrawSphereTool, player: Player, session: PlayerSession) {
tick = function (self: DrawSphereTool, player: Player, session: PlayerSession) {
if (self.baseTick(player, session)) return;

const center = self.getFirstPos(session);
Expand All @@ -182,7 +181,7 @@ class DrawSphereTool extends GeneratorTool {
}
}
};

useOn = this.commonUse;
use = this.commonUse;
}
Expand All @@ -202,19 +201,19 @@ class DrawCylinderTool extends GeneratorTool {
const job = Jobs.startJob(session, 2, shape.getRegion(center));
const count = yield* Jobs.perform(job, shape.generate(center, pattern, null, session));
Jobs.finishJob(job);

print(RawText.translate("commands.blocks.wedit:created").with(`${count}`), player, true);
};

tick = function* (self: DrawCylinderTool, player: Player, session: PlayerSession) {
tick = function (self: DrawCylinderTool, player: Player, session: PlayerSession) {
if (self.baseTick(player, session)) return;

const [shape, loc] = self.getShape(player, session);
for (const particle of shape.getOutline(loc)) {
trySpawnParticle(player, ...particle);
}
};

getShape(player: Player, session: PlayerSession): [CylinderShape, Vector] {
const center = this.getFirstPos(session).clone();
const pos2 = this.traceForPos(player);
Expand Down Expand Up @@ -246,19 +245,19 @@ class DrawPyramidTool extends GeneratorTool {
const job = Jobs.startJob(session, 2, shape.getRegion(center));
const count = yield* Jobs.perform(job, shape.generate(center, pattern, null, session));
Jobs.finishJob(job);

print(RawText.translate("commands.blocks.wedit:created").with(`${count}`), player, true);
};

tick = function* (self: DrawPyramidTool, player: Player, session: PlayerSession) {
tick = function (self: DrawPyramidTool, player: Player, session: PlayerSession) {
if (self.baseTick(player, session)) return;

const [shape, loc] = self.getShape(player, session);
for (const particle of shape.getOutline(loc)) {
trySpawnParticle(player, ...particle);
}
};

getShape(player: Player, session: PlayerSession): [PyramidShape, Vector] {
const center = this.getFirstPos(session).clone();
const pos2 = this.traceForPos(player);
Expand Down
10 changes: 5 additions & 5 deletions src/server/tools/region_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Tools } from "./tool_manager";
class SelectionFillTool extends Tool {
permission = "worldedit.region.replace";

use = function (_: Tool, player: Player, session: PlayerSession) {
use = function (self: Tool, player: Player, session: PlayerSession) {
if (player.isSneaking) {
Server.uiForms.show("$selectRegionMode", player);
} else {
Expand All @@ -20,11 +20,11 @@ class SelectionFillTool extends Tool {
};
}
Tools.register(SelectionFillTool, "selection_fill", "wedit:selection_fill");

class SelectionWallTool extends Tool {
permission = "worldedit.region.walls";

use = function (_t: Tool, player: Player, _s: PlayerSession) {
use = function (self: Tool, player: Player) {
if (player.isSneaking) {
Server.uiForms.show("$selectRegionMode", player);
} else {
Expand All @@ -37,7 +37,7 @@ Tools.register(SelectionWallTool, "selection_wall", "wedit:selection_wall");
class SelectionOutlineTool extends Tool {
permission = "worldedit.region.faces";

use = function (_t: Tool, player: Player, _s: PlayerSession) {
use = function (self: Tool, player: Player) {
if (player.isSneaking) {
Server.uiForms.show("$selectRegionMode", player);
} else {
Expand All @@ -50,7 +50,7 @@ Tools.register(SelectionOutlineTool, "selection_outline", "wedit:selection_outli
class SelectionHollowTool extends Tool {
permission = "worldedit.region.hollow";

use = function (_t: Tool, player: Player, _s: PlayerSession) {
use = function (self: Tool, player: Player) {
if (player.isSneaking) {
Server.uiForms.show("$selectRegionMode", player);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/server/tools/selection_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SelectionTool extends Tool {
break = function (self: Tool, player: Player, session: PlayerSession, loc: Vector3) {
Server.command.callCommand(player, "pos1", [`${loc.x}`, `${loc.y}`, `${loc.z}`]);
};
drop = function (self: Tool, player: Player, session: PlayerSession) {
drop = function (self: Tool, player: Player) {
Server.command.callCommand(player, "desel");
};
}
Expand All @@ -26,7 +26,7 @@ class FarSelectionTool extends Tool {
break = function (self: Tool, player: Player) {
Server.command.callCommand(player, "hpos1");
};
drop = function (self: Tool, player: Player, session: PlayerSession) {
drop = function (self: Tool, player: Player) {
Server.command.callCommand(player, "desel");
};
}
Expand Down
12 changes: 6 additions & 6 deletions src/server/tools/tool_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ToolBuilder {
const player = entity.dimension.getPlayers({ closest: 1, location: entity.location, maxDistance: 2 })[0];
if (player) this.onItemDrop(entity.getComponent("item").itemStack, player);
});

Server.on("blockBreak", ev => {
if (!ev.itemStack) return;
this.onBlockBreak(ev.itemStack, ev.player, ev, Vector.from(ev.block));
Expand Down Expand Up @@ -247,9 +247,9 @@ class ToolBuilder {
} else {
return;
}
tool.process(getSession(player), ToolAction.HIT);
tool.process(getSession(player), ToolAction.HIT, loc);
}

private onItemDrop(item: ItemStack, player: Player) {
if (this.disabled.includes(player.id) || !hasSession(player.id)) {
return;
Expand Down Expand Up @@ -287,11 +287,11 @@ class ToolBuilder {
});
this.bindings.set(playerId, database);
}

private stopHolding(player: Player) {
if (this.prevHeldTool.has(player)) {
this.prevHeldTool.get(player)?.process(getSession(player), ToolAction.STOP_HOLD);
this.prevHeldTool.delete(player);
this.prevHeldTool.get(player)?.process(getSession(player), ToolAction.STOP_HOLD);
this.prevHeldTool.delete(player);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/server/ui/config_menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ Server.uiForms.register<ConfigContext>("$gradientInfo", {
},
{
text: "%worldedit.config.gradient.remove",
action: (ctx) =>
action: (ctx) =>
ctx.confirm("$worldedit.config.confirm", "%worldedit.config.confirm.delete", (ctx, player) => {
getSession(player).deleteGradient(ctx.getData("currentGradient"));
})
Expand Down Expand Up @@ -299,7 +299,7 @@ Server.uiForms.register<ConfigContext>("$confirmGradientSelection", {
} else {
s = "x"; t = "z"; u = "y";
}

for (let i = min[u]; i <= max[u]; i++) {
const pattern = new Pattern();
for (let j = min[s]; j <= max[s]; j++) {
Expand All @@ -309,7 +309,7 @@ Server.uiForms.register<ConfigContext>("$confirmGradientSelection", {
}
patterns.push(pattern);
}

session.createGradient(id, dither, patterns);
ctx.returnto("$gradients");
}
Expand Down
Loading

0 comments on commit fa8d90f

Please sign in to comment.