Server authority
This commit is contained in:
+3
-28
@@ -3,7 +3,6 @@ import { canvas, draw_rect, draw_text, measure_text } from "$/client/renderer/mo
|
||||
import { InputManager } from "../input_manager.ts";
|
||||
import { ClientWorld } from "../client_world.ts";
|
||||
import { PlayerComponent } from "../player.ts";
|
||||
import { ItemStack } from "../inventory.ts";
|
||||
import { MAX_CHAT_LENGTH } from "$/common/protocol.ts";
|
||||
import { render_chat_log } from "../systems/rendering/network.ts";
|
||||
|
||||
@@ -102,14 +101,9 @@ export class GuiChat extends GuiScreen {
|
||||
override on_close(): void {}
|
||||
|
||||
submit() {
|
||||
if (this.text_typed.startsWith("/")) {
|
||||
this.command();
|
||||
} else if (this.text_typed.trim().length > 0) {
|
||||
if (this.world.connection) {
|
||||
this.world.connection.send({ type: "chat", text: this.text_typed });
|
||||
} else {
|
||||
this.world.add_chat(this.text_typed);
|
||||
}
|
||||
// commands like /give run on the server too
|
||||
if (this.text_typed.trim().length > 0) {
|
||||
this.world.connection.send({ type: "chat", text: this.text_typed });
|
||||
}
|
||||
this.text_typed = "";
|
||||
|
||||
@@ -119,23 +113,4 @@ export class GuiChat extends GuiScreen {
|
||||
player_component.pop_screen();
|
||||
}
|
||||
}
|
||||
|
||||
command() {
|
||||
if (this.text_typed.startsWith("/give")) {
|
||||
let [_, item_id, quantity] = this.text_typed.split(" ");
|
||||
|
||||
if (!item_id.includes(":")) {
|
||||
item_id = `bworld:${item_id}`;
|
||||
}
|
||||
if (quantity === undefined) {
|
||||
quantity = "1";
|
||||
}
|
||||
|
||||
const [player] = this.world.get_tag("player")!;
|
||||
const player_component = player.get(PlayerComponent);
|
||||
if (player_component) {
|
||||
player_component.player_inventory.container.add_item(new ItemStack(item_id, Number(quantity)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user