Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Commit

Permalink
1.1.0-stable
Browse files Browse the repository at this point in the history
  • Loading branch information
VoxlDevv committed Jul 19, 2023
1 parent 148c4e5 commit 520add4
Show file tree
Hide file tree
Showing 19 changed files with 324 additions and 11 deletions.
2 changes: 1 addition & 1 deletion scripts/main/@modules/handlers/command/Command.Class.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CommandClass {
* @param callback
*/
BuildCommand(registration, callback) {
const information = registration.extractJSON();
const information = registration._ToJSON();
this.registration.set(information.name, {
...information,
callback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ class CommandRegistration {
return this;
}
/**
* Extract to JSON
* Extract to JSON - You don't need this for creating custom command
*/
extractJSON() {
_ToJSON() {
return {
name: this.name,
description: this.description,
Expand Down
27 changes: 27 additions & 0 deletions scripts/main/@modules/handlers/entity/Player.Class.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,32 @@ class PlayerClass extends EntityClass {
getPlayerObjectFromName(target) {
return World.getOnlinePlayers().find((player) => player.name === target);
}
/**
* Get needed xp to next level
*/
needXpToLevelUp() {
return this.playerObject.totalXpNeededForNextLevel;
}
/**
* Get earned xp at current level
*/
xpEarned() {
return this.playerObject.xpEarnedAtCurrentLevel;
}
/**
* Get inventory component
*/
getInventoryComponent() {
return this.inventory;
}
/**
* Get raw component
*/
getRawPlayerComponent() {
return this.playerObject;
}
Query(query) {
return this.playerObject[query];
}
}
export { PlayerClass };
18 changes: 18 additions & 0 deletions scripts/main/plugins/Custom Commands/global/home/delhome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Command, CommandRegistration, Validation } from "../../../@modules";
import { HomeDB } from "./sethome";
const registration = new CommandRegistration()
.setName("delome")
.setDescription("Delete home")
.setAliases(["deletehome", "dhome"])
.setInputs({ 0: ["string"] })
.setUsage(["<homeName>"])
.setExample(["home myHome", "deletehome myHome", "dhome myHome"]);
Command.BuildCommand(registration, (interaction) => {
const { sender, inputs } = interaction;
const homeName = inputs.getInput(0);
if (Validation.isUndefined(homeName))
return sender.sendMessage("§cHome name cannot be empty");
const homeDBFrmt = `${sender.name}_${homeName}`;
if (!HomeDB.hasKey(homeDBFrmt))
return sender.sendMessage(`§cHome with name ${homeName} doesn't exist`);
});
25 changes: 25 additions & 0 deletions scripts/main/plugins/Custom Commands/global/home/home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { world } from "@minecraft/server";
import { Command, CommandRegistration, Validation } from "../../../@modules";
import { HomeDB } from "./sethome";
const registration = new CommandRegistration()
.setName("home")
.setDescription("Teleport to home")
.setInputs({ 0: ["string"] })
.setUsage(["<homeName>"])
.setExample(["home myHome"]);
Command.BuildCommand(registration, (interaction) => {
const { sender, inputs } = interaction;
const homeName = inputs.getInput(0);
if (Validation.isUndefined(homeName))
return sender.sendMessage("§cHome name cannot be empty");
const homeDBFrmt = `${sender.name}_${homeName}`;
if (!HomeDB.hasKey(homeDBFrmt))
return sender.sendMessage(`§cHome with name ${homeName} doesn't exist`);
const parsedHome = HomeDB.get(homeDBFrmt);
sender.teleport({
x: parsedHome.coordinate[0],
y: parsedHome.coordinate[1],
z: parsedHome.coordinate[2],
}, { dimension: world.getDimension(parsedHome.dimension) });
return sender.sendMessage(`§aSuccessfully teleported to home with name §e${homeName}`);
});
20 changes: 20 additions & 0 deletions scripts/main/plugins/Custom Commands/global/home/listhome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Command, CommandRegistration, Validation } from "../../../@modules";
import { HomeDB } from "./sethome";
const registration = new CommandRegistration()
.setName("listhome")
.setDescription("Get all home")
.setInputs({ 0: ["string"] })
.setUsage(["<homeName>"])
.setExample(["home myHome"]);
Command.BuildCommand(registration, (interaction) => {
const { sender, inputs } = interaction;
const homeName = inputs.getInput(0);
if (Validation.isUndefined(homeName))
return sender.sendMessage("§cHome name cannot be empty");
const findHome = HomeDB.find((home) => home.creator === sender.name);
return sender.sendMessage(`§b---- Home List ----\n\n${findHome.length === 0
? "§f# §7You don't have any home"
: findHome
.sort()
.map((home) => `§f# §7${home.name} - ${home.dimension}`)}`);
});
30 changes: 30 additions & 0 deletions scripts/main/plugins/Custom Commands/global/home/sethome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Command, CommandRegistration, Database, Validation, } from "../../../@modules";
const registration = new CommandRegistration()
.setName("sethome")
.setDescription("Sethome home")
.setAliases(["shome"])
.setInputs({ 0: ["string"] })
.setUsage(["<homeName>"])
.setExample(["sethome myHome", "shome myHome"]);
const HomeDB = new Database("HomeDB");
Command.BuildCommand(registration, (interaction) => {
const { sender, inputs } = interaction;
const homeName = inputs.getInput(0);
if (Validation.isUndefined(homeName))
return sender.sendMessage("§cHome name cannot be empty");
const homeDBFrmt = `${sender.name}_${homeName}`;
if (HomeDB.hasKey(homeDBFrmt))
return sender.sendMessage(`§eHome with name ${homeName} already exist`);
HomeDB.set(homeDBFrmt, {
name: homeName,
creator: sender.name,
coordinate: [
Math.floor(sender.location.x),
Math.floor(sender.location.y),
Math.floor(sender.location.z),
],
dimension: sender.dimension.id,
});
return sender.sendMessage(`§aSuccessfully set home with name §e${homeName} §aat coordinates §eX: ${Math.floor(sender.location.x)} Y: ${Math.floor(sender.location.x)} Z: ${Math.floor(sender.location.z)}`);
});
export { HomeDB };
7 changes: 6 additions & 1 deletion scripts/main/plugins/Custom Commands/system.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Information
// Information
import "./information/help";
import "./information/version";
// Global
import "./global/home/home";
import "./global/home/sethome";
import "./global/home/delhome";
import "./global/home/listhome";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type inputs = ["string", "boolean", "number", "playername"]

type SupportedInputs = inputs[number][]
11 changes: 11 additions & 0 deletions src/main/@modules/@types/handlers/entity/PlayerType.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type QueryName =
| "isClimbing"
| "isFalling"
| "isFlying"
| "isGliding"
| "isInWater"
| "isJumping"
| "isOnGround"
| "isSneaking"
| "isSprinting"
| "isSwimming";
2 changes: 1 addition & 1 deletion src/main/@modules/handlers/command/Command.Class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CommandClass {
registration: CommandRegistration,
callback: (arg: CommandBuild) => void
) {
const information = registration.extractJSON();
const information = registration._ToJSON();
this.registration.set(information.name, {
...information,
callback,
Expand Down
10 changes: 6 additions & 4 deletions src/main/@modules/handlers/command/CommandRegistration.Class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class CommandRegistration {
private aliases: string[];
private usage: string[];
private example: string[];
private inputs: { [key: number]: string[] };
private inputs: {
[key: number]: string[];
};

/**
* Command registration
Expand Down Expand Up @@ -91,15 +93,15 @@ class CommandRegistration {
/**
* Set command input
*/
setInputs(inputs: { [key: number]: string[] }) {
setInputs(inputs: { [key: number]: SupportedInputs }) {
Object.assign(this.inputs, inputs);
return this;
}

/**
* Extract to JSON
* Extract to JSON - You don't need this for creating custom command
*/
extractJSON() {
_ToJSON() {
return {
name: this.name,
description: this.description,
Expand Down
32 changes: 32 additions & 0 deletions src/main/@modules/handlers/entity/Player.Class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,38 @@ class PlayerClass extends EntityClass {
getPlayerObjectFromName(target: string): Player | undefined {
return World.getOnlinePlayers().find((player) => player.name === target);
}

/**
* Get needed xp to next level
*/
needXpToLevelUp(): number {
return this.playerObject.totalXpNeededForNextLevel;
}

/**
* Get earned xp at current level
*/
xpEarned(): number {
return this.playerObject.xpEarnedAtCurrentLevel;
}

/**
* Get inventory component
*/
getInventoryComponent(): EntityInventoryComponent {
return this.inventory;
}

/**
* Get raw component
*/
getRawPlayerComponent(): Player {
return this.playerObject;
}

Query(query: QueryName): boolean {
return this.playerObject[query];
}
}

export { PlayerClass };
2 changes: 1 addition & 1 deletion src/main/@modules/storages/Database.Class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class Database {
* Find data without key
* @param fn - Function
*/
find(fn: (value: any, key?: any, map?: Map<any, any>) => any): any {
find(fn: (value: any, key?: any, map?: Map<any, any>) => any): [] {
return this.RESTORED_DATA.find(fn);
}

Expand Down
23 changes: 23 additions & 0 deletions src/main/plugins/Custom Commands/global/home/delhome.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Command, CommandRegistration, Validation } from "../../../@modules";
import { HomeDB } from "./sethome";

const registration: CommandRegistration = new CommandRegistration()
.setName("delome")
.setDescription("Delete home")
.setAliases(["deletehome", "dhome"])
.setInputs({ 0: ["string"] })
.setUsage(["<homeName>"])
.setExample(["home myHome", "deletehome myHome", "dhome myHome"]);

Command.BuildCommand(registration, (interaction) => {
const { sender, inputs } = interaction;
const homeName = inputs.getInput(0) as any;

if (Validation.isUndefined(homeName))
return sender.sendMessage("§cHome name cannot be empty");

const homeDBFrmt = `${sender.name}_${homeName}`;

if (!HomeDB.hasKey(homeDBFrmt))
return sender.sendMessage(`§cHome with name ${homeName} doesn't exist`);
});
33 changes: 33 additions & 0 deletions src/main/plugins/Custom Commands/global/home/home.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { world } from "@minecraft/server";
import { Command, CommandRegistration, Validation } from "../../../@modules";
import { HomeDB } from "./sethome";

const registration: CommandRegistration = new CommandRegistration()
.setName("home")
.setDescription("Teleport to home")
.setInputs({ 0: ["string"] })
.setUsage(["<homeName>"])
.setExample(["home myHome"]);

Command.BuildCommand(registration, (interaction) => {
const { sender, inputs } = interaction;
const homeName = inputs.getInput(0) as any;

if (Validation.isUndefined(homeName))
return sender.sendMessage("§cHome name cannot be empty");

const homeDBFrmt = `${sender.name}_${homeName}`;
if (!HomeDB.hasKey(homeDBFrmt))
return sender.sendMessage(`§cHome with name ${homeName} doesn't exist`);

const parsedHome = HomeDB.get(homeDBFrmt);
sender.teleport(
{
x: parsedHome.coordinate[0],
y: parsedHome.coordinate[1],
z: parsedHome.coordinate[2],
},
{ dimension: world.getDimension(parsedHome.dimension) }
);
return sender.sendMessage(`§aSuccessfully teleported to home with name §e${homeName}`)
});
32 changes: 32 additions & 0 deletions src/main/plugins/Custom Commands/global/home/listhome.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { world } from "@minecraft/server";
import { Command, CommandRegistration, Validation } from "../../../@modules";
import { HomeDB } from "./sethome";

const registration: CommandRegistration = new CommandRegistration()
.setName("listhome")
.setDescription("Get all home")
.setInputs({ 0: ["string"] })
.setUsage(["<homeName>"])
.setExample(["home myHome"]);

Command.BuildCommand(registration, (interaction) => {
const { sender, inputs } = interaction;
const homeName = inputs.getInput(0) as any;

if (Validation.isUndefined(homeName))
return sender.sendMessage("§cHome name cannot be empty");

const findHome = HomeDB.find((home) => home.creator === sender.name);
return sender.sendMessage(
`§b---- Home List ----\n\n${
findHome.length === 0
? "§f# §7You don't have any home"
: findHome
.sort()
.map(
(home: { name: string; dimension: string }) =>
`§f# §7${home.name} - ${home.dimension}`
)
}`
);
});
Loading

0 comments on commit 520add4

Please sign in to comment.