├── .gitignore ├── README.md ├── src ├── stairs.ts └── main.ts ├── package.json ├── tsconfig.json ├── plugin.yml └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /dist 3 | .DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # example-plugin 2 | 3 | This is an example of a Minecraft plugin written in JavaScript. 4 | 5 | ### Setting up 6 | 7 | Run `npm install` to make sure all needed dependencies are installed. 8 | 9 | ### Building a JAR file 10 | 11 | ```sh 12 | npm run build 13 | ``` 14 | 15 | The JAR file will be put into `dist/ExamplePlugin.jar` in your project. 16 | -------------------------------------------------------------------------------- /src/stairs.ts: -------------------------------------------------------------------------------- 1 | export function buildStairs(loc: org.bukkit.Location, count: number, material: org.bukkit.Material) { 2 | for (let i = 0; i < count; i++) { 3 | for (let x = -4; x <= 4; x++) { 4 | loc.getWorld()?.getBlockAt(loc.getBlockX() + x, loc.getBlockY(), loc.getBlockZ()).setType(material); 5 | } 6 | loc.add(0, 1, -1); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-plugin", 3 | "version": "1.0.0", 4 | "description": "", 5 | "scripts": { 6 | "build": "crx build -o ./dist/ExamplePlugin.jar", 7 | "serve": "crx run", 8 | "clean": "rm -rf ./dist" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "MIT", 13 | "dependencies": { 14 | "@customrealms/core": "2.0.19" 15 | }, 16 | "devDependencies": { 17 | "@customrealms/cli": "2.0.9", 18 | "tslib": "2.3.1", 19 | "typescript": "4.4.4" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "strict": true, 5 | "outDir": "./dist", 6 | "sourceMap": false, 7 | "declaration": false, 8 | "module": "esnext", 9 | "moduleResolution": "node", 10 | "emitDecoratorMetadata": true, 11 | "resolveJsonModule": true, 12 | "experimentalDecorators": true, 13 | "esModuleInterop": true, 14 | "allowSyntheticDefaultImports": true, 15 | "importHelpers": true, 16 | "target": "ES6", 17 | "typeRoots": [ 18 | "node_modules/@types" 19 | ], 20 | "lib": [ 21 | "es2018", 22 | "dom", 23 | ] 24 | }, 25 | "include": [ 26 | "src/**/*.ts" 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /plugin.yml: -------------------------------------------------------------------------------- 1 | name: ExamplePlugin 2 | main: ./src/main.ts 3 | 4 | commands: 5 | gmsp: 6 | description: Set your gamemode to spectator 7 | permission: exampleplugin.gmsp 8 | gms: 9 | description: Set your gamemode to survival 10 | permission: exampleplugin.gms 11 | gmc: 12 | description: Set your gamemode to creative 13 | permission: exampleplugin.gmc 14 | stairs: 15 | kit: 16 | description: Get a kit of diamond gear 17 | invsee: 18 | description: View the inventory of another player 19 | nether: 20 | description: Teleport to the nether 21 | 22 | permissions: 23 | exampleplugin.*: 24 | description: Gives access to all ExamplePlugin commands 25 | default: op 26 | children: 27 | exampleplugin.gmsp: 28 | description: Allows the player to use the /gmsp command 29 | exampleplugin.gms: 30 | description: Allows the player to use the /gms command 31 | exampleplugin.gmc: 32 | description: Allows the player to use the /gmc command 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 CustomRealms 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { Bukkit, ServerCommands, ServerEvents } from '@customrealms/core'; 2 | import { buildStairs } from './stairs'; 3 | 4 | const ChatColor = org.bukkit.ChatColor; 5 | 6 | ServerEvents.register(org.bukkit.event.player.PlayerJoinEvent, event => { 7 | const player = event.getPlayer(); 8 | event.setJoinMessage(`${ChatColor.BOLD}${ChatColor.GRAY}[${ChatColor.GREEN}+${ChatColor.GRAY}]${ChatColor.RESET} ${player.getName()}`); 9 | }); 10 | 11 | ServerEvents.register(org.bukkit.event.player.PlayerInteractEvent, event => { 12 | const targetBlock = event.getPlayer().getTargetBlockExact(1000); 13 | if (!targetBlock) return; 14 | const location = targetBlock.getLocation(); 15 | location.getWorld()?.strikeLightning(location); 16 | }); 17 | 18 | // Register two commands for changing the player's game mode. 19 | ServerCommands.register('/gmc', (sender, call) => { 20 | const player = call.getPlayer()!; 21 | if (!player.hasPermission('exampleplugin.gmc')) { 22 | player.sendMessage('You do not have permission to use this command'); 23 | return; 24 | } 25 | player.setGameMode(org.bukkit.GameMode.CREATIVE); 26 | }); 27 | ServerCommands.register('/gms', (sender, call) => { 28 | const player = call.getPlayer()!; 29 | player.setGameMode(org.bukkit.GameMode.SURVIVAL); 30 | }); 31 | ServerCommands.register('/gmsp', (sender, call) => { 32 | const player = call.getPlayer()!; 33 | player.setGameMode(org.bukkit.GameMode.SPECTATOR); 34 | }); 35 | 36 | ServerCommands.register('/stairs {#:count} {S:material}', (sender, call) => { 37 | const player = call.getPlayer()!; 38 | const count = call.getNumericPlaceholder('count')!; 39 | const material = org.bukkit.Material.matchMaterial(call.getPlaceholder('material')!); 40 | if (!material || !material.isBlock()) { 41 | player.sendMessage('Invalid material'); 42 | return; 43 | } 44 | 45 | buildStairs(player.getLocation(), count, material); 46 | }); 47 | 48 | ServerCommands.register('/kit', (sender, call) => { 49 | const player = call.getPlayer()!; 50 | const inventory = Bukkit.createInventory(player, org.bukkit.event.inventory.InventoryType.CHEST); 51 | const materials = [ 52 | org.bukkit.Material.DIAMOND_SWORD, 53 | org.bukkit.Material.DIAMOND_CHESTPLATE, 54 | org.bukkit.Material.DIAMOND_HELMET, 55 | org.bukkit.Material.DIAMOND_LEGGINGS, 56 | org.bukkit.Material.DIAMOND_BOOTS, 57 | ]; 58 | for (const material of materials) { 59 | inventory.addItem(new org.bukkit.inventory.ItemStack(material)); 60 | } 61 | player.openInventory(inventory); 62 | }); 63 | 64 | ServerCommands.register('/invsee {P:player}', (sender, call) => { 65 | const player = call.getPlayer()!; 66 | const target = call.getPlayerPlaceholder('player'); 67 | if (!target) { 68 | player.sendMessage('Invalid player'); 69 | return; 70 | } 71 | 72 | const inventory = target.getInventory(); 73 | player.openInventory(inventory); 74 | }); 75 | 76 | ServerCommands.register('/nether', (sender, call) => { 77 | const player = call.getPlayer()!; 78 | const loc = Bukkit.getWorld('world_nether')?.getSpawnLocation(); 79 | if (!loc) return; 80 | player.teleport(loc); 81 | }); 82 | --------------------------------------------------------------------------------