Skip to content

Commit

Permalink
Format the code
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlaubb committed Dec 8, 2024
1 parent 7343a0c commit 471e3f6
Show file tree
Hide file tree
Showing 100 changed files with 10,093 additions and 1,789 deletions.
2 changes: 1 addition & 1 deletion Matrix_BP/entities/inv_container.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@
}
}
}
}
}
378 changes: 185 additions & 193 deletions Matrix_BP/entities/player.json

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions Matrix_BP/src/assets/inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export { projectPlayerInventory, initializeInventorySync };
import { world, system, EquipmentSlot, Player, ItemStack, Entity } from "@minecraft/server";
function fetchInventory(entity: Entity): ItemStack[] {
const container = entity.getComponent("inventory")!.container!;
let inventory = Array.from({ length: container.size }, (_, i) => container.getItem(i)).map(item => item ?? { typeId: "air", amount: 0 } as unknown as ItemStack);
let inventory = Array.from({ length: container.size }, (_, i) => container.getItem(i)).map((item) => item ?? ({ typeId: "air", amount: 0 } as unknown as ItemStack));
return entity instanceof Player ? inventory.slice(9).concat(inventory.slice(0, 9)) : inventory;
}
function stringifyInventory(inventory: ItemStack[]): string {
Expand All @@ -17,7 +17,13 @@ function stringifyInventory(inventory: ItemStack[]): string {
}
function fetchPlayerEquipments(player: Player): ItemStack[] {
const equipment = player.getComponent("equippable")!;
return [equipment.getEquipment(EquipmentSlot.Head), equipment.getEquipment(EquipmentSlot.Chest), equipment.getEquipment(EquipmentSlot.Legs), equipment.getEquipment(EquipmentSlot.Feet), equipment.getEquipment(EquipmentSlot.Offhand)] as unknown as ItemStack[];
return [
equipment.getEquipment(EquipmentSlot.Head),
equipment.getEquipment(EquipmentSlot.Chest),
equipment.getEquipment(EquipmentSlot.Legs),
equipment.getEquipment(EquipmentSlot.Feet),
equipment.getEquipment(EquipmentSlot.Offhand),
] as unknown as ItemStack[];
}
function transformEquipmentStatsToString(equipment: ItemStack[]): string {
return equipment
Expand Down Expand Up @@ -139,11 +145,11 @@ function pushChange(entityProjector: Entity, target: Player) {
}
}

function initializeInventorySync () {
function initializeInventorySync() {
system.runInterval(() => {
const inventoryViewerEntities = getInventoryViewerEntities("minecraft:overworld").concat(getInventoryViewerEntities("minecraft:nether")).concat(getInventoryViewerEntities("minecraft:the_end"));
inventoryViewerEntities.forEach((entity) => {
checkSync(entity);
});
}, 1);
}
}
6 changes: 3 additions & 3 deletions Matrix_BP/src/matrixAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ class Module {
}
system.runTimeout(() => {
if (player?.isValid()) player.sendMessage(rawtextTranslate("ad.running", Module.discordInviteLink));
let obj = world.scoreboard.getObjective('matrix:script-online');
let obj = world.scoreboard.getObjective("matrix:script-online");
if (!obj) {
obj = world.scoreboard.addObjective('matrix:script-online', 'Made by jasonlaubb');
obj.setScore('is_enabled', -1);
obj = world.scoreboard.addObjective("matrix:script-online", "Made by jasonlaubb");
obj.setScore("is_enabled", -1);
}
}, 200);
});
Expand Down
83 changes: 38 additions & 45 deletions Matrix_BP/src/program/command/confgui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ function selector(player: Player, path: string[]) {
return entries as [string, string];
});

const selectform = new ActionFormData().title(rawtextTranslate("ui.config.selector")).body(
fastText()
.addTran("ui.config.loc", path.join("/"))
.build()
);
const selectform = new ActionFormData().title(rawtextTranslate("ui.config.selector")).body(fastText().addTran("ui.config.loc", path.join("/")).build());

for (const [key, value] of lulka) {
selectform.button(`§g§l${key}§r\n§8${value}§r`);
Expand All @@ -50,46 +46,43 @@ function selector(player: Player, path: string[]) {
});
}
async function editor(player: Player, path: string[]) {
const type = typeof Config.get(path)!;
const form = new ModalFormData().title(rawtextTranslate("ui.config.editor"));
switch (type) {
case "string": {
form.textField(rawtextTranslate("ui.config.value"), "string");
break;
}
case "number": {
form.textField(rawtextTranslate("ui.config.value"), "number");
break;
}
case "boolean": {
form.dropdown(rawtextTranslate("ui.config.value"), ["FALSE (0)","TRUE (1)"]);
break;
}
default: {
throw new Error("Type Error: Undefined case");
}
}
//@ts-expect-error
form.show(player).then((data) => {
if (data.canceled) return;
const value = data.formValues![0];
// Run the config set command.
player.runChatCommand(`set ${path.join("/")} "${value}"`);
});
const type = typeof Config.get(path)!;
const form = new ModalFormData().title(rawtextTranslate("ui.config.editor"));
switch (type) {
case "string": {
form.textField(rawtextTranslate("ui.config.value"), "string");
break;
}
case "number": {
form.textField(rawtextTranslate("ui.config.value"), "number");
break;
}
case "boolean": {
form.dropdown(rawtextTranslate("ui.config.value"), ["FALSE (0)", "TRUE (1)"]);
break;
}
default: {
throw new Error("Type Error: Undefined case");
}
}
//@ts-expect-error
form.show(player).then((data) => {
if (data.canceled) return;
const value = data.formValues![0];
// Run the config set command.
player.runChatCommand(`set ${path.join("/")} "${value}"`);
});
}

new Command()
.setName("confgui")
.setMinPermissionLevel(4)
.setDescription(rawtextTranslate("command.confgui.description"))
.onExecute(async (player) => {
player.sendMessage(fastText().addText("§bMatrix§a+ §7> §g").addTran("ui.closechat").build());
const form = new ActionFormData()
.title(rawtextTranslate("ui.config.title"))
.body(rawtextTranslate("ui.config.body"))
.button(rawtextTranslate("ui.config.button"));
const result = await waitShowActionForm(form, player);
if (!result || result.canceled) return;
configUI(player).catch((e) => Command.sendErrorToPlayer(player, e));
})
.register();
.setName("confgui")
.setMinPermissionLevel(4)
.setDescription(rawtextTranslate("command.confgui.description"))
.onExecute(async (player) => {
player.sendMessage(fastText().addText("§bMatrix§a+ §7> §g").addTran("ui.closechat").build());
const form = new ActionFormData().title(rawtextTranslate("ui.config.title")).body(rawtextTranslate("ui.config.body")).button(rawtextTranslate("ui.config.button"));
const result = await waitShowActionForm(form, player);
if (!result || result.canceled) return;
configUI(player).catch((e) => Command.sendErrorToPlayer(player, e));
})
.register();
22 changes: 11 additions & 11 deletions Matrix_BP/src/program/command/invsee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { Command } from "../../matrixAPI";
import { fastText, rawtextTranslate } from "../../util/rawtext";
Inv.initializeInventorySync();
new Command()
.setName("invsee")
.setMinPermissionLevel(2)
.setDescription(rawtextTranslate("command.invsee.description"))
.addOption(rawtextTranslate("command.moderation.target"), rawtextTranslate("command.moderation.target.description"), "player", undefined, false)
.onExecute(async (player, player2) => {
const target = player2 as Player;
if (target.id === player.id) return player.sendMessage(fastText().addText("§bMatrix§a+ §7> §c").addTran("command.invsee.self").build());
if (!player.hasTag("riding")) Inv.projectPlayerInventory(target, player);
player.sendMessage(fastText().addText("§bMatrix§a+ §7> §g").addTran("command.invsee.notice").build());
})
.register();
.setName("invsee")
.setMinPermissionLevel(2)
.setDescription(rawtextTranslate("command.invsee.description"))
.addOption(rawtextTranslate("command.moderation.target"), rawtextTranslate("command.moderation.target.description"), "player", undefined, false)
.onExecute(async (player, player2) => {
const target = player2 as Player;
if (target.id === player.id) return player.sendMessage(fastText().addText("§bMatrix§a+ §7> §c").addTran("command.invsee.self").build());
if (!player.hasTag("riding")) Inv.projectPlayerInventory(target, player);
player.sendMessage(fastText().addText("§bMatrix§a+ §7> §g").addTran("command.invsee.notice").build());
})
.register();
Loading

0 comments on commit 471e3f6

Please sign in to comment.