Skip to content

Commit

Permalink
Fixed session removal ingame;
Browse files Browse the repository at this point in the history
Disabled tools system for non-worldedit users
  • Loading branch information
SIsilicon committed Mar 3, 2024
1 parent 6328aa3 commit 351b37c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
23 changes: 7 additions & 16 deletions src/library/Minecraft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,14 @@ class ServerBuild extends ServerBuilder {
* Emit to 'worldInitialize' event listener
*/
afterEvents.worldInitialize.subscribe((data) => this.emit("worldInitialize", data));
/**
* Emit to 'playerChangeDimension' event listener
*/
afterEvents.playerDimensionChange.subscribe((data) => this.emit("playerChangeDimension", { player: data.player, dimension: data.player.dimension }));

let worldLoaded = false,
tickCount = 0,
prevTime = Date.now();
const playerDimensions = new Map<string, string>();
let worldLoaded = false;
let tickCount = 0;
let prevTime = Date.now();
system.runInterval(() => {
tickCount++;
if (!worldLoaded && world.getAllPlayers().length) {
Expand All @@ -149,18 +152,6 @@ class ServerBuild extends ServerBuilder {
worldLoaded = true;
}

for (const player of world.getPlayers()) {
const oldDimension = playerDimensions.get(player.name);
const newDimension = player.dimension.id;

if (oldDimension && oldDimension != newDimension) {
this.emit("playerChangeDimension", {
player: player,
dimension: player.dimension,
});
}
playerDimensions.set(player.name, newDimension);
}
this.emit("tick", {
currentTick: tickCount,
deltaTime: Date.now() - prevTime,
Expand Down
5 changes: 2 additions & 3 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ Server.on("tick", () => {
if (hasWorldEdit(builder)) {
getSession(builder);
} else {
removeBuilder(builder.name);
removeBuilder(builder.id);
contentLog.log(`${builder.name} has been revoked of their worldedit permissions.`);
print("worldedit.permission.revoked", builder);
continue;
}
}
});
Expand All @@ -105,7 +104,7 @@ function removeBuilder(player: string) {
do {
i = activeBuilders.findIndex((p) => {
try {
return p.name == player;
return p.id == player;
} catch (e) {
return true;
}
Expand Down
6 changes: 1 addition & 5 deletions src/server/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ export class PlayerSession {
this.selection = new Selection(player);
this.drawOutlines = config.drawOutlines;
this.gradients = new Database<gradients>("gradients", player, (k, v) => {
if (k === "patterns")
return (<string[]>v).map((v) => {
console.warn(v);
return new Pattern(v);
});
if (k === "patterns") return (<string[]>v).map((v) => new Pattern(v));
return v;
});

Expand Down
12 changes: 7 additions & 5 deletions src/server/tools/tool_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ class ToolBuilder {

constructor() {
Server.on("itemUseBefore", (ev) => {
if (ev.source.typeId != "minecraft:player" || !ev.itemStack) return;
this.onItemUse(ev.itemStack, ev.source as Player, ev);
if (!ev.itemStack || !hasSession(ev.source.id)) return;
console.warn(hasSession(ev.source.id));
this.onItemUse(ev.itemStack, ev.source, ev);
});

Server.on("itemUseOnBefore", (ev) => {
if (ev.source.typeId != "minecraft:player" || !ev.itemStack) return;
if (!ev.itemStack || !hasSession(ev.source.id)) return;
this.onItemUse(ev.itemStack, ev.source as Player, ev, Vector.from(ev.block));
});

Expand All @@ -36,12 +37,12 @@ class ToolBuilder {
});

Server.on("blockBreak", (ev) => {
if (!ev.itemStack) return;
if (!ev.itemStack || !hasSession(ev.player.id)) return;
this.onBlockBreak(ev.itemStack, ev.player, ev, Vector.from(ev.block));
});

Server.on("blockHit", (ev) => {
if (ev.damagingEntity.typeId != "minecraft:player") return;
if (ev.damagingEntity.typeId != "minecraft:player" || !hasSession(ev.damagingEntity.id)) return;
const item = Server.player.getHeldItem(ev.damagingEntity as Player);
if (!item) return;
this.onBlockHit(item, ev.damagingEntity as Player, ev, Vector.from(ev.hitBlock));
Expand All @@ -50,6 +51,7 @@ class ToolBuilder {
new Thread().start(function* (self: ToolBuilder) {
while (true) {
for (const player of world.getPlayers()) {
if (!hasSession(player.id)) return;
try {
const item = Server.player.getHeldItem(player);
if (item) {
Expand Down

0 comments on commit 351b37c

Please sign in to comment.