Comments (10)
@codehz What about
void teleport_to_player(CommandOriginHelper&/Helper class for access to BDS CommandOrigin/ origin,CustomCommandResult& res,ServerPlayer* sp){
//origin.getPlayer returns ServerPlayer*
if(!origin.isPlayer()){
res.error();
res<<"error "<<123<<origin.getName(); //overloaded << operator
}
}
BDLCMDRegistry::registerCommand("tpa",overload1/*Infer arguments automatically */,overload2,if_no_overload_found_handler);
from bdlauncher.
@codehz and could you please show how to register a command with enum?
like /tpa {accept,deny},etc.
from bdlauncher.
to register enum:
enum class MyEnum: int {A, B};
auto test = BDLCommandRegistry::newEnum<MyEnum>("test");
test.add("A", MyEnum::A);
test.add("B", MyEnum::B);
dynamic enum:
// in global scope
static auto test = BDLCommandRegistry::newDynamicEnum<decltype("test_dynamic"_dynenum)>(); // use gcc extension to generate type from string
// in some function
test.set({"A", "B"});
test.clear();
test.add("C");
and a better command register method:
auto command = BDLCommandRegistry::newCommand("command");
command.add(impl_01);
command.add(impl_02);
command.set_fallback(if_no_overload_found_handler); // I'm not sure if it can be implemented...
from bdlauncher.
maybe we should use codegen insteads of just template meta programming...
or the argument name cannot be inferred from function..
(and optional argument)
from bdlauncher.
@codehz yeah,you're right.
I wonder whether overload will be called,if no suitable overload is found.
like this.
/tpa <{to,from}:enum> name:player
/tpa fallback:string <--- will be called when "/tpa wrong usage xxxx"
from bdlauncher.
BTW, the command parsing is happened in server side.. so the malformed command expression would be able to detect in server side and rerouting to fallback handler.. seems pointless..
from bdlauncher.
@codehz using mojang command overload api seems like a morr complex way to solve problem(need to generate class and vtable dynamically(or need a codegen),need to reverse-engineer more api).
Use a simple lexer with overload support maybe a better choice?
Maybe we can use tricks to make client show overloads,like multi-line command description.(hadnt tested)
from bdlauncher.
@codehz I dont know if duplicated availableCommandsPacket with only one command works well.(it means sending overloads of a mod
commands after server sent previous availableCommandsPacket to client )
Modifing availableCommandsPacket::write seems like a difficult job.
from bdlauncher.
void tpa_to_impl(...,ServerPlayer* sp,int xx){
}
CommandBase cmd("tpa");
cmd.overload("to <dest:player> <testval:int>",tpa_to_impl);//use template like overload(string_view,void(*)(...,T ,T2) to determine how many arguments need to be parsed(in base.h) and base.so just exports regCommand0(sview,void *function),regCommand1...,etc..
and lexer parses overload,and do some preparations(convert string to int,ServerPlayer*,etc)
and use (void(*)(...,void*,void*))callback(arg0,arg1,argx)
CONS :
1.assume that all arguments are 64bits long.(so passing string_view and const string(abi:cxx11) cant work?(because string_view uses two registers).And float cant work ad well(because it uses %xmm0 register) )
2.use a lot of else
if to make right calls(right counts of arguments)
from bdlauncher.
alternative concept: for codegen
// header (.h)
struct Teleport : CustomCommandDescription {
static constexpr auto name = "teleport";
static constexpr auto permission = CommandPermission::OP;
// any name
void impl_01(ServerPlayer *target); // generate `teleport <target: player>`
// use std::optional for optional argument
void impl_02(Vec3 pos, std::optional<int> angle); // generate `teleport <pos: position> [angle: int]`
// use enum
void impl_03(MyEnum target); // generate `teleport <target: my_enum>`
};
extern "C" {
BDL_EXPORT int mod_register_command(CommandRegistry *); // codegen
}
// impl (.cpp)
void Teleport::impl_01(ServerPlayer *target) {}
....
from bdlauncher.
Related Issues (20)
- TODO:code cleanup
- TODO: a better logging system HOT 2
- Switch to XUID HOT 4
- 这是什么问题 HOT 23
- TODO upgrade to bedrock_server 1.14.20.1 HOT 2
- 使用Custom Map时出错 HOT 1
- Error with running Makefile HOT 3
- Changed max homes on an existing server=crash HOT 2
- TODO List
- Add Serverlist Voting Service support
- ERROR
- ERROR
- ERROR HOT 2
- Add more dupe blocks.
- Installing Error HOT 5
- 卖领地价格计算错误
- [Idea] A Chinese language version
- Optimization: Improved command descriptions and minor modifications
- Optimization: Improved command descriptions and minor modifications HOT 4
- [Question] open a sub menu with menuitem. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bdlauncher.