-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { IntegerEnum } from "@serenityjs/command"; | ||
|
||
import { ItemEnum, TargetEnum } from "../enums"; | ||
import { ItemStack } from "../../item"; | ||
|
||
import type { ItemIdentifier } from "@serenityjs/item"; | ||
import type { World } from "../../world"; | ||
|
||
const register = (world: World) => { | ||
// Register the setblock command | ||
world.commands.register( | ||
"give", | ||
"Gives an item to a player", | ||
(_, parameters) => { | ||
// Get the result of the item, amount, and metadata | ||
const itemIdentifier = parameters.item.result as ItemIdentifier; | ||
const amount = parameters.amount?.result ?? 1; | ||
const metadata = parameters.metadata?.result ?? 0; | ||
|
||
// Create a new item stack | ||
const itemStack = new ItemStack(itemIdentifier, amount, metadata); | ||
|
||
// Loop through the targets | ||
for (const target of parameters.target.result) { | ||
// Check if the target is an entity | ||
if (!target.isPlayer()) continue; | ||
|
||
// Get the player's inventory | ||
const { container } = target.getComponent("minecraft:inventory"); | ||
|
||
// Add the item to the player's inventory | ||
container.addItem(itemStack); | ||
} | ||
|
||
// Send the success message | ||
return { | ||
message: `Successfully gave x${amount} ${itemIdentifier} to ${parameters.target.result.length} players.` | ||
}; | ||
}, | ||
{ | ||
target: TargetEnum, | ||
item: ItemEnum, | ||
amount: [IntegerEnum, true], | ||
metadata: [IntegerEnum, true] | ||
} | ||
); | ||
}; | ||
|
||
export default register; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import GAMEMODE from "./gamemode"; | ||
import SETBLOCK from "./setblock"; | ||
import GIVE from "./give"; | ||
|
||
// Define all admin commands | ||
const ADMIN_COMMANDS = [GAMEMODE, SETBLOCK]; | ||
const ADMIN_COMMANDS = [GAMEMODE, SETBLOCK, GIVE]; | ||
|
||
export { ADMIN_COMMANDS }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./target"; | ||
export * from "./gamemode"; | ||
export * from "./block"; | ||
export * from "./item"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ItemType } from "@serenityjs/item"; | ||
import { CustomEnum } from "@serenityjs/command"; | ||
|
||
const identifiers = ItemType.getAll().map((item) => item.identifier); | ||
|
||
class ItemEnum extends CustomEnum { | ||
public static readonly name = "block"; | ||
public static readonly options = identifiers; | ||
} | ||
|
||
export { ItemEnum }; |