From f9c61808bbf786666741c5c38a29ca63a76cc9a5 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 26 Jul 2023 01:02:07 +0200 Subject: [PATCH 1/4] Add Definitions for Luanalysis Signed-off-by: Chaoscaot --- SCRIPT.md | 7 ++ definitions.lua | 168 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 definitions.lua diff --git a/SCRIPT.md b/SCRIPT.md index b1557d62..9ab5fecd 100644 --- a/SCRIPT.md +++ b/SCRIPT.md @@ -4,6 +4,7 @@ * [SteamWar.de - Script System](#steamwarde---script-system) * [Einleitung](#einleitung) + * [Nutzung mit einer IDE](#nutzung-mit-einer-ide) * [Basis-Apis](#basis-apis) * [SteamWar.de-Api](#steamwarde-api) * [player](#player) @@ -43,6 +44,12 @@ Das Script System auf SteamWar.de basiert auf [Lua](https://www.lua.org/docs.html). Der Code wird einfach in ein Minecraft Buch geschrieben und kann mit einem Links-Klick ausgeführt werden. +## Nutzung mit einer IDE +Im Repository liegen [Lua-Definitionen](definitions.lua) für [Luanalysis](https://plugins.jetbrains.com/plugin/14698-luanalysis). +Diese können in der IDE genutzt werden, um die APIs zu nutzen. + +Einfach die `definitions.lua` in den selben Ordner wie das Script legen und die IDE sollte die APIs erkennen. + # Basis-Apis Es werden folgende Standard-Apis zur Verfügung gestellt: - [`math`](https://www.lua.org/manual/5.4/manual.html#6.7) diff --git a/definitions.lua b/definitions.lua new file mode 100644 index 00000000..c74de4da --- /dev/null +++ b/definitions.lua @@ -0,0 +1,168 @@ +--- +--- This file contains the definitions for the SteamWar.de script API. +--- It is used by the IDE to provide code completion and type checking. +--- Created by Chaoscaot +--- + +---@class inventory @define class inventory +---@field create fun(title: string, size: number): Inventory +inventory = {} + +---@alias InventoryClick 'LEFT' | 'SHIFT_LEFT' | 'RIGHT' | 'SHIFT_RIGHT' | 'MIDDLE' | 'NUMBER_KEY' + +---@shape Inventory +---@field item fun(slot: number, material: string, name: string, handler: fun(click: InventoryClick), lore?: string[], enchanted?: boolean, amount?: number: void) +---@field setCloseHandler fun(handler: fun(): void): void +---@field open fun(): void + +---@class Callable +---@overload fun(): T +---@overload fun(value: T): void + +---@class player +---@field name fun(): string +---@field chat fun(message: string...): void +---@field actionbar fun(message: string...): void +---@field x fun(value?: number): void | number +---@field y fun(value?: number): void | number +---@field z fun(value?: number): void | number +---@field yaw fun(value?: number): void | number +---@field pitch fun(value?: number): void | number +---@field sneaking fun(): boolean +---@field sprinting fun(): boolean +---@field slot fun(value?: number): void | number +---@field item fun(): string +---@field offHandItem fun(): string +---@field closeInventory fun(): void +player = {} + +---@class random +---@field nextInt fun(a?: number, b?: number): number +---@field nextDouble fun(a?: number, b?: number): number +---@field nextBool fun(): boolean +random = {} + +---@alias RegionType 'wg' | 'mwg' | 'as' | 'ws' | 'ws_inner' | 'ws_rumpf' | 'ws_rahmen' | 'spawn' + +---@class region +---@field name fun(): string +---@field type fun(): RegionType +---@field tnt tnt +---@field fire fun(): boolean +---@field freeze fun(): boolean +---@field protect fun(): boolean +---@field trace trace +---@field loader fun(): string +region = {} + +---@alias TNTMode 'ALLOW' | 'DENY' | 'ONLY_TB' + +---@class tnt +---@field mode fun(): TNTMode +---@field enabled fun(): boolean +---@field onlyTb fun(): boolean + +---@class trace +---@field active fun(): boolean +---@field auto fun(): boolean +---@field status fun(): string +---@field time fun(): number + +---@shape Position +---@field x number +---@field y number +---@field z number + +---@class server +---@field time fun(): string +---@field ticks fun(): number +---@field getBlockAt fun(position: Position): string +---@field setBlockAt fun(position: Position, material: string): void +---@field tps tps +server = {} + +---@class tps +---@field oneSecond fun(): number +---@field tenSecond fun(): number +---@field oneMinute fun(): number +---@field fiveMinute fun(): number +---@field tenMinute fun(): number +---@field current fun(): number +---@field limit fun(): number + +---@class storage +---@field global storageLib +---@field player storageLib +---@field region storageLib +storage = {} + +---@class storageLib +---@field get fun(key: string): any +---@field set fun(key: string, value: any): void + +---@shape Selection +---@field max Position +---@field min Position + +---@class _worldedit +---@field selection fun(pos?: Position[]): Selection | void +_worldedit = {} + +---@param msg string +---@param callback fun(value: string): void +---@return void +function input(msg, callback) end + +---@param ticks number +---@param callback fun(): void +---@return void +function delayed(ticks, callback) end + +---@param x number +---@param y number +---@param z number +---@return Position +function pos(x, y, z) return nil end + +function exec(...) end + +---@param obj any +---@return number +function length(obj) return 0 end + +---@param separator string +---@param table any[] +---@return string +function join(separator, table) return "" end + +---@class EventType +---@class events +---@field DoubleSwap EventType +---@field PlaceBlock EventType +---@field BreakBlock EventType +---@field RightClick EventType +---@field LeftClick EventType +---@field TNTSpawn EventType +---@field TNTExplode EventType +---@field TNTExplodeInBuild EventType +---@field SelfJoin EventType +---@field SelfLeave EventType +---@field DropItem EventType +---@field EntityDeath EventType +events = {} + + +---@param id EventType +---@param handler fun(params: any): void +---@return void +function event(id, handler) end + +---@param command string +---@param handler fun(params: string[]): void +---@return void +function command(command, handler) end + +---@param trigger string +---@param handler fun(pressed: boolean): void +---@return void +function hotkey(trigger, handler) end -- 2.39.5 From 040b25d60177d40e7a0597b601aeb5da12f3fbda Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 26 Jul 2023 01:04:33 +0200 Subject: [PATCH 2/4] Add Copyright Signed-off-by: Chaoscaot --- definitions.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/definitions.lua b/definitions.lua index c74de4da..ce875ecf 100644 --- a/definitions.lua +++ b/definitions.lua @@ -1,3 +1,20 @@ +-- This file is a part of the SteamWar software. +-- +-- Copyright (C) 2021 SteamWar.de-Serverteam +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU Affero General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Affero General Public License for more details. +-- +-- You should have received a copy of the GNU Affero General Public License +-- along with this program. If not, see . + --- --- This file contains the definitions for the SteamWar.de script API. --- It is used by the IDE to provide code completion and type checking. -- 2.39.5 From a1880a61e9c9a722fd1d41137017d9aa9716ef40 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 26 Jul 2023 11:11:12 +0200 Subject: [PATCH 3/4] Cleanup Defs Signed-off-by: Chaoscaot --- SCRIPT.md | 4 +- sw.def.lua | 317 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 319 insertions(+), 2 deletions(-) create mode 100644 sw.def.lua diff --git a/SCRIPT.md b/SCRIPT.md index 9ab5fecd..64e13fcd 100644 --- a/SCRIPT.md +++ b/SCRIPT.md @@ -45,10 +45,10 @@ Das Script System auf SteamWar.de basiert auf [Lua](https://www.lua.org/docs.htm Der Code wird einfach in ein Minecraft Buch geschrieben und kann mit einem Links-Klick ausgeführt werden. ## Nutzung mit einer IDE -Im Repository liegen [Lua-Definitionen](definitions.lua) für [Luanalysis](https://plugins.jetbrains.com/plugin/14698-luanalysis). +Im Repository liegen [Lua-Definitionen](sw.def.lua) für [Luanalysis](https://plugins.jetbrains.com/plugin/14698-luanalysis). Diese können in der IDE genutzt werden, um die APIs zu nutzen. -Einfach die `definitions.lua` in den selben Ordner wie das Script legen und die IDE sollte die APIs erkennen. +Einfach die `definitions.lua` in denselben Ordner wie das Script legen und die IDE sollte die APIs erkennen. # Basis-Apis Es werden folgende Standard-Apis zur Verfügung gestellt: diff --git a/sw.def.lua b/sw.def.lua new file mode 100644 index 00000000..e99073af --- /dev/null +++ b/sw.def.lua @@ -0,0 +1,317 @@ +-- This file is a part of the SteamWar software. +-- +-- Copyright (C) 2021 SteamWar.de-Serverteam +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU Affero General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Affero General Public License for more details. +-- +-- You should have received a copy of the GNU Affero General Public License +-- along with this program. If not, see . + +--- +--- This file contains the definitions for the SteamWar.de script API. +--- It is used by the IDE to provide code completion and type checking. +--- Created by Chaoscaot +--- + +inventory = {} + +---@param title string +---@param size number +---@return Inventory +function inventory.create(title, size) return nil end + +---@alias InventoryClick 'LEFT' | 'SHIFT_LEFT' | 'RIGHT' | 'SHIFT_RIGHT' | 'MIDDLE' | 'NUMBER_KEY' + +---@class Inventory +local Inventory = {} + +---@overload fun(slot: number, material: string, name: string, handler: fun(click: InventoryClick)): void +---@overload fun(slot: number, material: string, name: string, handler: fun(click: InventoryClick), lore: string[]): void +---@overload fun(slot: number, material: string, name: string, handler: fun(click: InventoryClick), lore: string[], enchanted: boolean): void +---@param slot number +---@param material string +---@param name string +---@param handler fun(click: InventoryClick): void +---@param lore string[] +---@param enchanted boolean +---@param amount number +---@return void +function Inventory.item(slot, material, name, handler, lore, enchanted, amount) end + +---@param handler fun(): void +---@return void +function Inventory.setCloseHandler(handler) end + +---@return void +function Inventory.open() end + +player = {} + +---@return string +---Get the name of the player. +function player.name() return "" end + +---@return void +function player.chat(...) end + +---@return void +---Send a message to the actionbar of the player. +function player.actionbar(...) end + +---@overload fun(): number +---@param newX number +function player.x(newX) end + +---@overload fun(): number +---@param newY number +function player.y(newY) end + +---@overload fun(): number +---@param newZ number +function player.z(newZ) end + +---@overload fun(): number +---@param newYaw number +function player.yaw(newYaw) end + +---@overload fun(): number +---@param newPitch number +function player.pitch(newPitch) end + +---@return boolean +function player.sneaking() return nil end + +---@return boolean +function player.sprinting() return nil end + +---@overload fun(): number +---@param newSlot number +function player.slot(newSlot) end + +---@return string +function player.item() return nil end + +---@return string +function player.offHandItem() return nil end + +---@return void +function player.closeInventory() end + +---@field nextBool fun(): boolean +random = {} + +---@overload fun(): number +---@overload fun(bound: number): number +---@param origin number +---@param bound number +---@return number +function random.nextInt(origin, bound) return nil end + +---@overload fun(): number +---@overload fun(bound: number): number +---@param origin number +---@param bound number +---@return number +function random.nextDouble(origin, bound) return nil end + +---@return boolean +function random.nextBool() return nil end + +---@alias RegionType 'wg' | 'mwg' | 'as' | 'ws' | 'ws_inner' | 'ws_rumpf' | 'ws_rahmen' | 'spawn' + +---@class region +---@field tnt tnt +---@field trace trace +region = {} + +---@return string +function region.name() return nil end + +---@return RegionType +function region.type() return nil end + +---@return boolean +function region.fire() return nil end + +---@return boolean +function region.freeze() return nil end + +---@return boolean +function region.protect() return nil end + +---@return string +function region.loader() return nil end + +---@alias TNTMode 'ALLOW' | 'DENY' | 'ONLY_TB' + +---@class tnt +local tnt = {} + +---@return TNTMode +function tnt.mode() return nil end + +---@return boolean +function tnt.enabled() return nil end + +---@return boolean +function tnt.onlyTb() return nil end + +---@class trace +local trace = {} + +---@return boolean +function trace.active() return nil end + +---@return boolean +function trace.auto() return nil end + +---@return string +function trace.status() return nil end + +---@return number +function trace.time() return nil end + +---@class Position +---@field x number +---@field y number +---@field z number + +---@class server +---@field tps tps +server = {} + +---@return string +function server.time() return nil end + +---@return number +function server.ticks() return nil end + +---@param position Position +---@return string +function getBlockAt(position) return nil end + +---@param position Position +---@param material string +---@return void +function setBlockAt(position, material) return nil end + +---@class tps +local tps = {} + +---@return number +function tps.oneSecond() return nil end + +---@return number +function tps.tenSecond() return nil end + +---@return number +function tps.oneMinute() return nil end + +---@return number +function tps.fiveMinute() return nil end + +---@return number +function tps.tenMinute() return nil end + +---@return number +function tps.current() return nil end + +---@return number +function tps.limit() return nil end + +---@class storage +---@field global storageLib +---@field player storageLib +---@field region storageLib +storage = {} + +---@class storageLib +local storageLib = {} + +---@param key string +---@return any +function storageLib.get(key) return nil end + +---@param key string +---@param value any +---@return void +function storageLib.set(key, value) end + +---@class Selection +---@field max Position +---@field min Position + +---@class _worldedit +_worldedit = {} + +---@overload fun(pos: Position[]): void +---@return Selection +function _worldedit.selection() return nil end + +---@param msg string +---@param callback fun(value: string): void +---@return void +function input(msg, callback) end + +---@param ticks number +---@param callback fun(): void +---@return void +function delayed(ticks, callback) end + +---@param x number +---@param y number +---@param z number +---@return Position +function pos(x, y, z) return nil end + +---@return void +function exec(...) end + +---@param obj any +---@return number +function length(obj) return 0 end + +---@param separator string +---@param table any[] +---@return string +function join(separator, table) return "" end + +---@class EventType +---@class events +---@field DoubleSwap EventType +---@field PlaceBlock EventType +---@field BreakBlock EventType +---@field RightClick EventType +---@field LeftClick EventType +---@field TNTSpawn EventType +---@field TNTExplode EventType +---@field TNTExplodeInBuild EventType +---@field SelfJoin EventType +---@field SelfLeave EventType +---@field DropItem EventType +---@field EntityDeath EventType +events = {} + + +---@param id EventType +---@param handler fun(params: any): void +---@return void +function event(id, handler) end + +---@param command string +---@param handler fun(params: string[]): void +---@return void +function command(command, handler) end + +---@param trigger string +---@param handler fun(pressed: boolean): void +---@return void +function hotkey(trigger, handler) end -- 2.39.5 From df882e3382040ba4e93efa5844f136adc4e09b1c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 26 Jul 2023 13:03:41 +0200 Subject: [PATCH 4/4] Fix Docs Signed-off-by: Chaoscaot --- SCRIPT.md | 2 +- definitions.lua | 185 ------------------------------------------------ 2 files changed, 1 insertion(+), 186 deletions(-) delete mode 100644 definitions.lua diff --git a/SCRIPT.md b/SCRIPT.md index 65dc4071..cccc88ab 100644 --- a/SCRIPT.md +++ b/SCRIPT.md @@ -48,7 +48,7 @@ Der Code wird einfach in ein Minecraft Buch geschrieben und kann mit einem Links Im Repository liegen [Lua-Definitionen](sw.def.lua) für [Luanalysis](https://plugins.jetbrains.com/plugin/14698-luanalysis). Diese können in der IDE genutzt werden, um die APIs zu nutzen. -Einfach die `definitions.lua` in denselben Ordner wie das Script legen und die IDE sollte die APIs erkennen. +Einfach die `sw.def.lua` in denselben Ordner wie das Script legen und die IDE sollte die APIs erkennen. # Basis-Apis Es werden folgende Standard-Apis zur Verfügung gestellt: diff --git a/definitions.lua b/definitions.lua deleted file mode 100644 index ce875ecf..00000000 --- a/definitions.lua +++ /dev/null @@ -1,185 +0,0 @@ --- This file is a part of the SteamWar software. --- --- Copyright (C) 2021 SteamWar.de-Serverteam --- --- This program is free software: you can redistribute it and/or modify --- it under the terms of the GNU Affero General Public License as published by --- the Free Software Foundation, either version 3 of the License, or --- (at your option) any later version. --- --- This program is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU Affero General Public License for more details. --- --- You should have received a copy of the GNU Affero General Public License --- along with this program. If not, see . - ---- ---- This file contains the definitions for the SteamWar.de script API. ---- It is used by the IDE to provide code completion and type checking. ---- Created by Chaoscaot ---- - ----@class inventory @define class inventory ----@field create fun(title: string, size: number): Inventory -inventory = {} - ----@alias InventoryClick 'LEFT' | 'SHIFT_LEFT' | 'RIGHT' | 'SHIFT_RIGHT' | 'MIDDLE' | 'NUMBER_KEY' - ----@shape Inventory ----@field item fun(slot: number, material: string, name: string, handler: fun(click: InventoryClick), lore?: string[], enchanted?: boolean, amount?: number: void) ----@field setCloseHandler fun(handler: fun(): void): void ----@field open fun(): void - ----@class Callable ----@overload fun(): T ----@overload fun(value: T): void - ----@class player ----@field name fun(): string ----@field chat fun(message: string...): void ----@field actionbar fun(message: string...): void ----@field x fun(value?: number): void | number ----@field y fun(value?: number): void | number ----@field z fun(value?: number): void | number ----@field yaw fun(value?: number): void | number ----@field pitch fun(value?: number): void | number ----@field sneaking fun(): boolean ----@field sprinting fun(): boolean ----@field slot fun(value?: number): void | number ----@field item fun(): string ----@field offHandItem fun(): string ----@field closeInventory fun(): void -player = {} - ----@class random ----@field nextInt fun(a?: number, b?: number): number ----@field nextDouble fun(a?: number, b?: number): number ----@field nextBool fun(): boolean -random = {} - ----@alias RegionType 'wg' | 'mwg' | 'as' | 'ws' | 'ws_inner' | 'ws_rumpf' | 'ws_rahmen' | 'spawn' - ----@class region ----@field name fun(): string ----@field type fun(): RegionType ----@field tnt tnt ----@field fire fun(): boolean ----@field freeze fun(): boolean ----@field protect fun(): boolean ----@field trace trace ----@field loader fun(): string -region = {} - ----@alias TNTMode 'ALLOW' | 'DENY' | 'ONLY_TB' - ----@class tnt ----@field mode fun(): TNTMode ----@field enabled fun(): boolean ----@field onlyTb fun(): boolean - ----@class trace ----@field active fun(): boolean ----@field auto fun(): boolean ----@field status fun(): string ----@field time fun(): number - ----@shape Position ----@field x number ----@field y number ----@field z number - ----@class server ----@field time fun(): string ----@field ticks fun(): number ----@field getBlockAt fun(position: Position): string ----@field setBlockAt fun(position: Position, material: string): void ----@field tps tps -server = {} - ----@class tps ----@field oneSecond fun(): number ----@field tenSecond fun(): number ----@field oneMinute fun(): number ----@field fiveMinute fun(): number ----@field tenMinute fun(): number ----@field current fun(): number ----@field limit fun(): number - ----@class storage ----@field global storageLib ----@field player storageLib ----@field region storageLib -storage = {} - ----@class storageLib ----@field get fun(key: string): any ----@field set fun(key: string, value: any): void - ----@shape Selection ----@field max Position ----@field min Position - ----@class _worldedit ----@field selection fun(pos?: Position[]): Selection | void -_worldedit = {} - ----@param msg string ----@param callback fun(value: string): void ----@return void -function input(msg, callback) end - ----@param ticks number ----@param callback fun(): void ----@return void -function delayed(ticks, callback) end - ----@param x number ----@param y number ----@param z number ----@return Position -function pos(x, y, z) return nil end - -function exec(...) end - ----@param obj any ----@return number -function length(obj) return 0 end - ----@param separator string ----@param table any[] ----@return string -function join(separator, table) return "" end - ----@class EventType ----@class events ----@field DoubleSwap EventType ----@field PlaceBlock EventType ----@field BreakBlock EventType ----@field RightClick EventType ----@field LeftClick EventType ----@field TNTSpawn EventType ----@field TNTExplode EventType ----@field TNTExplodeInBuild EventType ----@field SelfJoin EventType ----@field SelfLeave EventType ----@field DropItem EventType ----@field EntityDeath EventType -events = {} - - ----@param id EventType ----@param handler fun(params: any): void ----@return void -function event(id, handler) end - ----@param command string ----@param handler fun(params: string[]): void ----@return void -function command(command, handler) end - ----@param trigger string ----@param handler fun(pressed: boolean): void ----@return void -function hotkey(trigger, handler) end -- 2.39.5