Compare commits

...

283 Commits

Author SHA1 Message Date
MiaoWoo 5f0c3bbdd4 feat: backup plugins
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-20 16:40:34 +08:00
MiaoWoo bf3638dda0 feat: complate database & web
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-20 16:39:03 +08:00
MiaoWoo 842335edbe feat: add amqp & web interface
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-20 16:38:14 +08:00
MiaoWoo f573d0c758 feat: support loader & scanner
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-17 18:39:24 +08:00
MiaoWoo 13b04a904e feat: add exit hook
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-17 18:36:25 +08:00
MiaoWoo 2c1eea5bc1 feat: add web package
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-17 18:34:20 +08:00
MiaoWoo 8a07e85fda feat: support Autowired and JSClass inject
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-17 18:34:01 +08:00
MiaoWoo 32db0bba56 feat: add thread pool factory
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-17 18:28:12 +08:00
MiaoWoo b417d8ff08 feat: add amqp package
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-17 18:27:36 +08:00
MiaoWoo 6fd7038ffe feat: backup miao spring plugin
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-17 16:11:47 +08:00
MiaoWoo 321b21a947 feat: add spring-beans type
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-17 14:37:04 +08:00
MiaoWoo 0ae7346678 feat: add rabbitmq type & move spring-amqp type
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-03 18:51:07 +08:00
MiaoWoo 7114876046 feat: add spring amqp & spring rabbit type
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-03 18:04:46 +08:00
MiaoWoo 01fcc1337a feat: add MiaoSpring
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-02 18:12:37 +08:00
MiaoWoo 476f7acc39 feat: update import type
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-02 18:12:05 +08:00
MiaoWoo 5b11be11da feat: add log history
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-02 18:11:45 +08:00
MiaoWoo 80c6b123c1 feat: optimize type file generate
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-02 18:06:15 +08:00
MiaoWoo a7a40b374b feat: add scope login script
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-02 18:03:22 +08:00
MiaoWoo 9888f908e9 feat: add nocolor stack
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-02 18:02:49 +08:00
MiaoWoo 73ada5fd17 feat: add node-shim & move plugin interface
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-02 18:01:56 +08:00
MiaoWoo 79f151de5c feat: add @ccms/database
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-02 18:00:26 +08:00
MiaoWoo 16fcbfa69c feat: complate server & update spring
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-02 17:50:47 +08:00
MiaoWoo 7e1111470c feat: update console
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-02 17:15:54 +08:00
MiaoWoo d407631072 feat: add spring java and ts type compatible
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-02 14:50:36 +08:00
MiaoWoo 4d7b27188a feat: add bungee java and ts type compatible
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-02 14:31:32 +08:00
MiaoWoo 7bd8302b24 feat: add jdk java and ts type compatible
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-02 13:11:26 +08:00
MiaoWoo b065bcd843 feat: update bungee type file
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-02 12:27:03 +08:00
MiaoWoo c8a31b6d5a feat: update sponge type file
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-02 12:06:44 +08:00
MiaoWoo 75492c77e8 feat: update jdk type file
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-02 11:49:27 +08:00
MiaoWoo 8dbbb369b2 feat: add spring-context file
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-02 11:46:44 +08:00
MiaoWoo 24ba6bd353 feat: update exists spring type file
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-02 11:46:08 +08:00
MiaoWoo a02bd6dc95 fix: nukkit type error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-01 15:37:23 +08:00
MiaoWoo 21cf867f43 feat: fix sponge type error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-01 15:36:07 +08:00
MiaoWoo 4290d1132e fix: error bukkit type
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-01 15:34:21 +08:00
MiaoWoo 1ed5dd1d24 fix: array Type error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-06-01 14:52:10 +08:00
MiaoWoo d751dc8614 feat: add spring type
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-31 18:34:51 +08:00
MiaoWoo c45bbb9821 feat: compatible brower behavior
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-30 10:43:33 +08:00
MiaoWoo c9ca4ffd39 fix: websocket session send synchronized
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-30 10:18:01 +08:00
MiaoWoo 5943d6882f feat: add timcat ts type
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-30 10:16:50 +08:00
MiaoWoo d24d0d39a1 feat: update jdk ts type
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-30 10:16:20 +08:00
MiaoWoo 95cd8c4889 feat: modify ws on Message params
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-26 18:48:46 +08:00
MiaoWoo 78fcbbe9a5 feat: add javax.sql type
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-26 16:35:51 +08:00
MiaoWoo baa6e95222 v0.7.0 2020-05-26 16:04:34 +08:00
MiaoWoo 3a045bd335 feat: support spring
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-26 15:55:40 +08:00
MiaoWoo dd28d9fae5 feat: update docs
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-26 15:54:56 +08:00
MiaoWoo 72bd6b4c9c feat: add spring support
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-26 15:53:41 +08:00
MiaoWoo 58478116c6 feat: support tomcat websocket
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-26 15:45:40 +08:00
MiaoWoo d29efb2332 fix: typings can't ignore 2020-05-26 15:38:13 +08:00
MiaoWoo 0899276530 v0.6.7 2020-05-15 18:24:24 +08:00
MiaoWoo 5c3ed4e36d feat: add npm publish script 2020-05-15 16:50:12 +08:00
MiaoWoo b926951656 feat: link .npmignore file 2020-05-15 16:46:47 +08:00
MiaoWoo b47acf69ea v0.6.6 2020-05-15 16:20:21 +08:00
MiaoWoo 63aef1fe60 feat: support nukkit getRootLogger
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-15 16:10:55 +08:00
MiaoWoo 541a3bb96b feat: support bungee log forward
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-15 15:49:23 +08:00
MiaoWoo 873964575b feat: support get root Logger
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-15 15:48:38 +08:00
MiaoWoo 54af491399 feat: add token check
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-15 14:29:13 +08:00
MiaoWoo 43d9b97347 feat: support config auto save
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-15 14:28:40 +08:00
MiaoWoo 25aef3ed62 feat: support token check & compatible more server
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-14 19:05:07 +08:00
MiaoWoo c622abecda feat: optimize import
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-14 19:04:19 +08:00
MiaoWoo f527c225fe feat: support handshark & boardcast
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-14 19:03:41 +08:00
MiaoWoo 26eceac330 feat: update dep version
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-14 09:56:13 +08:00
MiaoWoo f5702c5080 feat: support log forward to client
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-13 18:42:41 +08:00
MiaoWoo 101f152da7 feat: complate upgrade
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-13 18:42:05 +08:00
MiaoWoo 97db272041 feat: add global eventCenter & static console source map
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-13 18:41:05 +08:00
MiaoWoo a5ca0c2346 v0.6.5 2020-05-12 14:35:26 +08:00
MiaoWoo aab94fe5ea feat: optimize framework
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-12 14:22:31 +08:00
MiaoWoo d3d7a9cdbf feat: complate deploy access check
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-12 00:07:05 +08:00
MiaoWoo 9dee4b3a60 feat: ignore if trace.fileName is empty
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-11 22:13:31 +08:00
MiaoWoo f1863c3b39 feat: add node shim
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-11 22:13:03 +08:00
MiaoWoo 0120e84f3f v0.6.4 2020-05-11 17:52:13 +08:00
MiaoWoo 00130f549c feat: add npmignore
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-11 17:46:57 +08:00
MiaoWoo fafcd09cc1 v0.6.3 2020-05-11 17:32:02 +08:00
MiaoWoo 2bd8f0c5ff feat: support address arg
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-11 17:24:26 +08:00
MiaoWoo 695a490296 feat: support online load plugin
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-11 17:22:45 +08:00
MiaoWoo 1a546470a5 feat: support blockly online debug
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-11 17:22:15 +08:00
MiaoWoo e68c17576a feat: compatible blockly plugin
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-11 17:20:50 +08:00
MiaoWoo eaee2f9c91 feat: add i18n load tip
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-11 17:19:44 +08:00
MiaoWoo 3596fc0804 feat: ignore jar:file stack info
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-10 16:25:04 +08:00
MiaoWoo 5e89872477 feat: add incremental compiler config
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-10 16:24:19 +08:00
MiaoWoo c12670bd9e remove: plugins public file 2020-05-08 18:42:17 +08:00
MiaoWoo b9ef3f2e33 feat: support basic plugin... 2020-05-08 18:41:56 +08:00
MiaoWoo 4b3176e98e feat: update init command... 2020-05-08 10:11:30 +08:00
MiaoWoo 4922f6a39d feat: update gitpod init command... 2020-05-08 10:05:47 +08:00
MiaoWoo 195c84e1ae feat: add gitpod config... 2020-05-08 09:53:18 +08:00
MiaoWoo 7d63a57991 feat: complate deploy feature 2020-05-08 00:50:30 +08:00
MiaoWoo 1931391cba v0.6.2 2020-05-07 18:38:28 +08:00
MiaoWoo 2dda9bd0fc fix: reload & download error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-07 18:33:10 +08:00
MiaoWoo 937b24ecda v0.6.1 2020-05-07 17:18:38 +08:00
MiaoWoo c9eff3dae4 feat: update docs & MSPM
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-07 17:13:48 +08:00
MiaoWoo 098a4f8557 feat: support source map & reload
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-07 17:12:15 +08:00
MiaoWoo 8566c6a883 v0.6.0 2020-05-03 00:15:06 +08:00
MiaoWoo 0584ec9d85 refactor: rename scope to @ccms
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-03 00:14:47 +08:00
MiaoWoo 87f197fe06 v0.5.0 2020-04-26 10:24:49 +08:00
MiaoWoo 860946a44b feat: merge stage exec & catch error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-04-26 10:19:44 +08:00
MiaoWoo f40eddd5e3 feat: update plugin & websocket
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-04-24 16:42:36 +08:00
MiaoWoo b67474f7ff feat: support stage decorators and remove space plugin floder
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-04-24 15:38:00 +08:00
MiaoWoo 8e5588ca23 fix: netty inject error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-04-24 13:05:46 +08:00
MiaoWoo acbeda9659 feat: support base64 source map
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-04-24 13:04:45 +08:00
MiaoWoo a4c549d446 feat: update MiaoConsole
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-04-07 13:39:35 +08:00
MiaoWoo c311d3fdb1 v0.4.2 2020-04-07 13:39:50 +08:00
MiaoWoo 1c29a059d9 feat: add 1.8.8 reflect & export io namespace
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-04-07 13:31:20 +08:00
MiaoWoo d22b72f10a feat: console执行异常只打印一次
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-04-03 13:32:54 +08:00
MiaoWoo e74cfda86b feat: cancel all task when disable engine
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-04-03 11:36:06 +08:00
MiaoWoo 24fe3b9026 feat: use module export
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-04-01 17:53:12 +08:00
MiaoWoo ee9ae408ec feat: add internal node moudle punycode
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-04-01 14:39:00 +08:00
MiaoWoo d679915062 feat: merge decorators meta interface
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-04-01 11:08:57 +08:00
MiaoWoo eaa11ac89e feat: add pipeline reflect
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-04-01 11:08:15 +08:00
MiaoWoo 5ddfb1c40f upgrade: js-yaml version
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-31 16:16:13 +08:00
MiaoWoo da68821a1f v0.4.1 2020-03-31 16:16:40 +08:00
MiaoWoo ec65d00f28 fix: disable server error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-31 14:53:23 +08:00
MiaoWoo a2c3eff622 feat: add new nodejs modules
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-31 14:51:44 +08:00
MiaoWoo 8d2422fd64 feat: update plugins
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-30 18:49:19 +08:00
MiaoWoo 9bc6cc1ff2 feat: instance i18n object
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-30 18:49:08 +08:00
MiaoWoo 6fc3592536 v0.4.0 2020-03-25 13:54:45 +08:00
MiaoWoo 49b96b3ac4 feat: export error handle & merge config
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-24 18:30:50 +08:00
MiaoWoo 73b9c2f163 feat: add api doc
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-24 17:59:18 +08:00
MiaoWoo f5a7a269e4 fix: sourceMap sometime error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-24 15:02:20 +08:00
MiaoWoo 662e70b72c fix: ack callback call twice
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-24 14:52:50 +08:00
MiaoWoo b71ce1b24d feat: optimize framework add error catch(only log)
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-24 13:27:11 +08:00
MiaoWoo 1ea8966f26 style: change error color
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-24 13:26:15 +08:00
MiaoWoo 0ed3f1fbd5 feat: complate sockt.io server
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-23 18:33:12 +08:00
MiaoWoo f4b461409b feat: add adapter and socket
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-23 00:58:53 +08:00
MiaoWoo ace2c48ae2 feat: tracatch plugin build
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-21 15:48:45 +08:00
MiaoWoo 39861b2c46 feat: add nodejs package
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-21 15:47:59 +08:00
MiaoWoo 6c9ea9fb74 feat: complate socket.io base framework
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-21 15:47:42 +08:00
MiaoWoo 15f09abce0 v0.3.2 2020-03-18 11:19:08 +08:00
MiaoWoo eb832a0830 fix: source map print error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-18 11:15:49 +08:00
MiaoWoo 1d35c836fc refactor: move docs to MiaoDocs
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-10 13:19:48 +08:00
MiaoWoo e53f2cea76 update: README
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-04 02:23:37 +08:00
MiaoWoo 1395865d8a feat: modify stage order
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-04 02:11:55 +08:00
MiaoWoo bae5355c1b feat: update readme and fix container package error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-04 02:04:35 +08:00
MiaoWoo 41d2edc719 feat: add docs package
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-04 02:04:02 +08:00
MiaoWoo d608e2c066 v0.3.1 2020-03-03 01:14:22 +08:00
MiaoWoo e7c22b5961 feat: public types package
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-03 01:11:49 +08:00
MiaoWoo 18b46cdcc7 feat: complate spiget and forgesvc api
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-02 22:40:18 +08:00
MiaoWoo d057fd5464 feat: update readme
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-02 22:38:34 +08:00
MiaoWoo 247c566219 feat: update MCBBS.MD
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-02 22:37:08 +08:00
MiaoWoo ed9fec281c feat: add error handle
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-02 22:28:27 +08:00
MiaoWoo 15197355c5 feat: merge type defiend
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-02 22:29:29 +08:00
MiaoWoo 988bb3b914 remove: manager package
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-02 21:00:54 +08:00
MiaoWoo 47048a5b1b feat: add complate function
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-02 00:32:07 +08:00
MiaoWoo b3539d419e feat: optimize types ref
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-01 20:28:16 +08:00
MiaoWoo c10247e241 fix: Dependency cycles
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-01 19:37:34 +08:00
MiaoWoo 553632e6ba feat: add i18n to ployfill
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-01 17:01:27 +08:00
MiaoWoo 6b7a729e65 feat: add NativePluginManager
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-03-01 15:19:43 +08:00
MiaoWoo 488eecba07 feat: add download and getPluginsFolder
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-29 22:28:43 +08:00
MiaoWoo ce431aded4 feat: upgrade typescript
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-29 18:21:02 +08:00
MiaoWoo 525fde9f51 feat: add command error i18n
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-29 00:44:11 +08:00
MiaoWoo ca11db68a6 feat: add normal env task
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-27 18:20:45 +08:00
MiaoWoo 3f475a7dc1 feat: MiaoConsole exclude nukkit
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-27 18:15:33 +08:00
MiaoWoo e7d44af48c feat: channel add ext data
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-27 18:14:17 +08:00
MiaoWoo 0b416adfd2 feat: add nukkit example
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-27 17:59:06 +08:00
MiaoWoo 429cece606 fix: servers check error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-27 17:57:29 +08:00
MiaoWoo c34b744994 v0.3.0 2020-02-27 12:27:19 +08:00
MiaoWoo 4d64a5d264 feat: optimize code
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-27 12:26:04 +08:00
MiaoWoo 13c0584749 feat: improve i18n scope
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-27 12:11:18 +08:00
MiaoWoo f5f50d0dd6 feat: support i18n translate
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-27 01:58:23 +08:00
MiaoWoo 0176cabd41 feat: add package i18n
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-27 01:57:44 +08:00
MiaoWoo a3f8451842 feat: remove async check
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-26 10:43:47 +08:00
MiaoWoo 9ea4a067f1 feat: unmanaged baseEventDir
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-26 10:36:30 +08:00
MiaoWoo 3143851969 feat: use inversify autoProvide inject
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-26 10:15:33 +08:00
MiaoWoo 7e4c44eadd feat: exclude async event monitor
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-25 23:32:12 +08:00
MiaoWoo e323467ed8 fix: event execute class type error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-25 23:15:39 +08:00
MiaoWoo eba21c08dc fix: nukkit unregister event error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-25 18:25:16 +08:00
MiaoWoo a872172fff feat: use new channel service
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-24 18:36:32 +08:00
MiaoWoo c996fa6873 feat: add channel support for bungee bukkit sponge
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-24 18:36:08 +08:00
MiaoWoo 8616c3fe22 feat: update ignore file
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-24 16:35:19 +08:00
MiaoWoo 407de98468 v0.2.1 2020-02-24 16:27:49 +08:00
MiaoWoo c13668dbe2 feat: add nukkit support
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-24 16:25:54 +08:00
MiaoWoo a0b334b151 feat: add config support
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-24 16:25:38 +08:00
MiaoWoo d7e8b05573 feat: inject config folder
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-24 16:25:16 +08:00
MiaoWoo 9fd4b51d98 feat: add config support
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-24 16:24:36 +08:00
MiaoWoo 246867b999 feat: update typescript version
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-24 15:28:47 +08:00
MiaoWoo 381ea25b46 feat: add nukkit support
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-24 04:02:29 +08:00
MiaoWoo 6d81a72106 feat: add nukkit package 2020-02-24 04:01:39 +08:00
MiaoWoo f20171f898 feat: add nukkit type defiend 2020-02-24 02:54:05 +08:00
MiaoWoo eaf491f74d v0.2.0 2020-02-24 00:21:48 +08:00
MiaoWoo 49f886c5ba feat: set manager and client to private
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-24 00:19:13 +08:00
MiaoWoo 3cf83023eb feat: update plugins
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-24 00:13:19 +08:00
MiaoWoo 9f64f89222 feat: add config decorator bate
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-24 00:12:32 +08:00
MiaoWoo bdecc96fcf feat: update mcbbs file
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-24 00:11:46 +08:00
MiaoWoo f660b4a4f8 feat: add auto respawn support
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-23 22:35:05 +08:00
MiaoWoo e8d41e8a43 fix: some bug at xhr and console
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-23 22:33:51 +08:00
MiaoWoo d9e2b50953 feat: channelRead0 处理逻辑移动到业务线程
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-19 19:46:50 +08:00
MiaoWoo 93c83cac94 feat: update main script
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-19 19:03:09 +08:00
MiaoWoo b506d06173 feat: add source map support
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-19 19:00:26 +08:00
MiaoWoo 8d81d6938e feat: add mc console client package
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-19 18:59:02 +08:00
MiaoWoo d90264194c feat: remove script npx
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-19 18:56:02 +08:00
MiaoWoo cc96519e80 feat: update example plugin
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-15 19:40:25 +08:00
MiaoWoo 982e14953c feat: add source map support(only local)
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-15 19:39:45 +08:00
MiaoWoo b0409c46ba feat: enable sourceMap
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-15 18:49:18 +08:00
MiaoWoo fb3eb9704f feat: update dependencies version
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-15 18:48:46 +08:00
MiaoWoo effa43d42f fix: bungee servers forEach error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-14 04:03:25 +08:00
MiaoWoo 06684939bc fix: bungee unregister error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-14 04:02:37 +08:00
MiaoWoo 9eb052addb feat: chat compatible catserver
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-14 04:02:18 +08:00
MiaoWoo 9acd824656 feat: add bungee tab complate
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-09 22:07:00 +08:00
MiaoWoo 61195accc9 feat: add core-js
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-09 22:06:45 +08:00
MiaoWoo 568f723c06 feat: rename plugin
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-08 17:07:56 +08:00
MiaoWoo bca12d6f02 fix: compile error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-02 01:58:07 +08:00
MiaoWoo 9b3d76b6dd feat: use dom types and set Proxy global
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-02 01:56:45 +08:00
MiaoWoo 84d9eb8881 feat: update Proxy handle and optimize core index
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-01 03:37:56 +08:00
MiaoWoo 6b4d0cc64c feat: update Readme
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-01 02:54:03 +08:00
MiaoWoo 1d783ebd1f feat: add websocket package
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-01 02:47:39 +08:00
MiaoWoo 87ac658a22 feat: add plugin stage log
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-01 02:46:55 +08:00
MiaoWoo b793ec192f feat: move type bind and export impl function
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-01 02:46:06 +08:00
MiaoWoo 606bbb3991 feat: move global declare to @ms/ployfill
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-02-01 02:44:23 +08:00
MiaoWoo cacde0627b feat: complete cross server
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-17 17:48:23 +08:00
MiaoWoo 6f5254497f feat: optimize code
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-17 17:47:38 +08:00
MiaoWoo 2639fbd818 fix: sponge task callSyncMethod
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-17 17:45:39 +08:00
MiaoWoo 93997cd695 feat: optimiz plugin system
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-17 17:45:13 +08:00
MiaoWoo 268f5d2837 feat: add tellraw string
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-17 17:44:08 +08:00
MiaoWoo 5642a93974 feat: update server filter
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-17 17:43:45 +08:00
MiaoWoo 85fe0cf87a feat: plugin & cmd add server check
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-17 11:11:20 +08:00
MiaoWoo f4ea32862f feat: use inject container
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-17 11:10:30 +08:00
MiaoWoo eaf1456771 fix: bungee event error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-17 11:09:16 +08:00
MiaoWoo 9546881691 feat: add callSyncMethod
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-17 11:08:51 +08:00
MiaoWoo 94ebbf3cba fix: with error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-17 11:08:10 +08:00
MiaoWoo 9e650aa203 feat: add plugin controller
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-16 17:28:10 +08:00
MiaoWoo 7ce0705d41 feat: update plugins
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-16 17:27:24 +08:00
MiaoWoo 106e429a3f feat: add bungee support
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-16 17:26:31 +08:00
MiaoWoo 05d12b347a feat: complete event and dispatch command
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-16 17:19:10 +08:00
MiaoWoo 7bf5f53afd feat: add tellraw & Proxy utils
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-15 18:38:22 +08:00
MiaoWoo e4bb878648 feat: formatting code & remove chinese
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-15 16:48:18 +08:00
MiaoWoo d724feaec0 feat: completion base func
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-15 16:44:14 +08:00
MiaoWoo 9cb614bebd feat: add bungee package
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-15 16:43:00 +08:00
MiaoWoo 7d6269b2d3 feat: delombok and regenerate d.ts
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-15 16:42:15 +08:00
MiaoWoo eae0ff2c1e feat: update bungee type file
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-15 01:02:08 +08:00
MiaoWoo 093a3dda00 feat: add server module
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-14 17:44:20 +08:00
MiaoWoo 93ec202894 feat: add bungee typings
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-14 17:40:28 +08:00
MiaoWoo a780467d87 feat: support multi code page
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-13 15:28:25 +08:00
MiaoWoo 0102b172f3 feat: upgrade version
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-01-08 09:48:37 +08:00
MiaoWoo 64111732fb feat: update websocket server
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-11-10 10:11:13 +08:00
MiaoWoo ffa62ee243 feat: update gitignore 2019-11-09 18:35:26 +08:00
MiaoWoo bd9af562f2 feat: add jdk support 2019-11-09 18:34:54 +08:00
MiaoWoo 59108bab27 feat: update type defiend 2019-11-07 16:40:27 +08:00
MiaoWoo 6258ae83d0 feat: add bukkit sponge jdk type 2019-11-07 15:13:28 +08:00
MiaoWoo 9fa3ed704a feat: move type def to other package 2019-11-07 15:02:05 +08:00
MiaoWoo a76858d626 feat: add illegal plugin check
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-11-05 17:03:49 +08:00
MiaoWoo 55a6b33110 feat: support async task
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-11-05 17:02:58 +08:00
MiaoWoo b87b94aade feat: update plugin register
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-11-04 20:28:52 +08:00
MiaoWoo 4110ed2c20 feat: update config and add XHR
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-11-04 20:26:22 +08:00
MiaoWoo 3cbc101eff fix: command remove error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-11-04 20:21:31 +08:00
MiaoWoo 221b821085 feat: add xhr
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-11-04 20:20:08 +08:00
MiaoWoo 7331cfaa55 refactor: update http use XHR
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-11-04 20:19:50 +08:00
MiaoWoo 40d020ef67 feat: add server interface
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-11-04 20:18:30 +08:00
MiaoWoo eea2a225e8 feat: complate websocket plugin 2019-10-30 20:45:59 +08:00
MiaoWoo 48f7f0fdbb feat: update ignore file
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-10-29 15:38:55 +08:00
MiaoWoo 99ed76f9bb style: format file
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-27 18:40:35 +08:00
MiaoWoo 7f21fa67ee feat: share decorators container
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-27 18:39:40 +08:00
MiaoWoo 8584709828 feat: add XMLHttpRequest
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-27 18:39:03 +08:00
MiaoWoo d1f58e7482 feat: supoort mod server scan event
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-27 09:49:45 +08:00
MiaoWoo 1bd35aef6d fix: type instance error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-25 10:10:35 +08:00
MiaoWoo fdf1088564 fix: not exist type mapping
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-25 10:10:22 +08:00
MiaoWoo 7bb4d1f6a3 feat: add sponge typings
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-25 09:55:00 +08:00
MiaoWoo b8c3d0d19d feat: add type extend and interface
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-24 17:20:18 +08:00
MiaoWoo a616a07553 feat: update type defiend
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-24 15:02:03 +08:00
MiaoWoo 781524f83e v0.1.1 2019-09-24 10:15:06 +08:00
MiaoWoo c7a812c003 feat: split test plugin
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-24 10:12:57 +08:00
MiaoWoo 325f2c8cf9 feat: modify import to reference type
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-24 10:12:40 +08:00
MiaoWoo 562e2d0017 v0.1.0 2019-09-23 00:41:04 +08:00
MiaoWoo b7871e8d33 feat: update registry in every package
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-23 00:39:13 +08:00
MiaoWoo 060cffd8e7 feat: add cli sh and add hosted url in package.json
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-23 00:34:38 +08:00
MiaoWoo 4b1fb07cc9 feat: update deps
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-23 00:19:43 +08:00
MiaoWoo 0931d69188 feat: add example plugins
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-22 23:31:52 +08:00
MiaoWoo 7d33368ebd feat: add hello world plugin
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-22 18:02:59 +08:00
MiaoWoo c95fc5fcff doc: add jsdoc
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-22 18:02:28 +08:00
MiaoWoo a7479f60c8 fix: bukkit task error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-22 18:01:50 +08:00
MiaoWoo ac75356778 feat: add start time
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-22 18:01:35 +08:00
MiaoWoo 7f32382dbc feat: modify sponge event mapping handle
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-22 18:01:13 +08:00
MiaoWoo b3c2def36d feat: add remove plugin on disable
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-22 18:00:18 +08:00
MiaoWoo 1ea93dfb9f feat: add build:plugins
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-22 17:59:25 +08:00
MiaoWoo e5ffa70ed9 feat: add readme and update ts config
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-21 15:06:17 +08:00
MiaoWoo 2a60b36e23 feat: support multi stage load
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-21 15:05:37 +08:00
MiaoWoo c4c2c0ab0f feat: complate command event and task
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-21 15:04:47 +08:00
MiaoWoo bf5628a646 feat: add task and optimize command
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-21 15:04:25 +08:00
MiaoWoo 13e9f0a5af feat: update command and complate task
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-21 14:58:00 +08:00
MiaoWoo cdd5f2d250 fix: command registry error
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-20 09:09:29 +08:00
MiaoWoo dfd7182008 feat: add build script
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-19 19:00:35 +08:00
MiaoWoo 533859808f feat: complate event and command module
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-19 18:59:32 +08:00
MiaoWoo 15cea1dfc8 feat: optimize api
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-19 18:59:00 +08:00
MiaoWoo dfa43d58f0 feat: complete event module fix tab completer 2019-09-19 18:58:01 +08:00
MiaoWoo 2bf239d8ea feat: add bukkit class type
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-12 17:54:17 +08:00
MiaoWoo cbe87cc378 feat: add plugins packages and add Test Plugin
Signed-off-by: MiaoWoo <admin@yumc.pw>
2019-09-10 17:22:56 +08:00
237 changed files with 13972 additions and 1105 deletions

4
.gitignore vendored
View File

@ -1,4 +1,8 @@
.vscode
.theia
node_modules
dist
package-lock.json
yarn.lock
packages/nashorn/docs
!packages/types/dist

10
.gitpod.Dockerfile vendored Normal file
View File

@ -0,0 +1,10 @@
FROM gitpod/workspace-full
USER gitpod
# Install custom tools, runtime, etc. using apt-get
# For example, the command below would install "bastet" - a command line tetris clone:
#
# RUN sudo apt-get -q update && # sudo apt-get install -yq bastet && # sudo rm -rf /var/lib/apt/lists/*
#
# More information: https://www.gitpod.io/docs/config-docker/

5
.gitpod.yml Normal file
View File

@ -0,0 +1,5 @@
tasks:
- init: yarn && yarn bs && yarn build
command: yarn watch
# image:
# file: .gitpod.Dockerfile

23
.npmignore Normal file
View File

@ -0,0 +1,23 @@
test
typings
bundled
build
coverage
docs
wiki
gulpfile.js
bower.json
karma.conf.js
tsconfig.json
typings.json
CONTRIBUTING.md
ISSUE_TEMPLATE.md
PULL_REQUEST_TEMPLATE.md
tslint.json
wallaby.js
.travis.yml
.gitignore
.vscode
.theia
type_definitions
tsconfig.tsbuildinfo

34
README.MD Normal file
View File

@ -0,0 +1,34 @@
# MiaoScript implement
## MiaoScript JS 实现
项目 由 TypeScript 进行编写 然后编译至 `es5` 用于兼容 Java8 的 `Nashorn`
### Project Path
```txt
└─packages
├─api 全平台兼容的接口
├─core 核心代码 用于引导加载
├─common 公共类库代码 例如 http reflect 模块
├─client NodeJS的Minecraft客户端 用于调试插件
├─container IOC容器 用于注入具体实现
├─ployfill Nashorn 的一些自定义增强
├─nashorn Nashorn 的类型定义
├─bungee BungeeCordAPI内部实现
├─bukkit BukkitAPI内部实现
├─sponge SpongeAPI内部实现
├─nukkit NukkitAPI内部实现
├─plugin 插件管理器
├─websocket Netty的WebSocket注入
├─type Java的类型定义
| ├─bungee BungeeCord类型定义
| ├─bukkit Bukkit类型定义
| ├─sponge Sponge类型定义
| └─nukkit Nukkit类型定义
└─plugins 这里当然是插件啦
├─bungee 只兼容BungeeCord的插件
├─bukkit 只兼容Bukkit的插件
├─sponge 只兼容Sponge的插件
└─nukkit 只兼容Nukkit的插件
```

11
doc/MCBBS.MD Normal file
View File

@ -0,0 +1,11 @@
- 构建状态 [![Build Status](https://ci.yumc.pw/job/Minecraft/job/MiaoScript/badge/icon?style=flat-square)](https://ci.yumc.pw/job/Minecraft/job/MiaoScript/)
- 当前版本 ![Build Status](https://ci.yumc.pw/job/Minecraft/job/MiaoScript/badge/icon?style=flat-square&subject=VERSION&status=0.1.0beta&color=darkturquoise)
- 下载地址 [![Build Status](https://ci.yumc.pw/job/Minecraft/job/MiaoScript/badge/icon?style=flat-square&subject=MiaoScript&status=DOWNLOAD&color=darkgreen)](http://w.yumc.pw/free.html#MiaoScript-download)
- 更新日志 [![Build Status](https://ci.yumc.pw/job/Minecraft/job/MiaoScript/badge/icon?style=flat-square&subject=MiaoScript&status=CHANGELOG&color=green)](https://docs.yumc.pw/MiaoScript/CHANGELOG.html)
- 安装文档 [![Build Status](https://ci.yumc.pw/job/Minecraft/job/MiaoScript/badge/icon?style=flat-square&subject=MiaoScript&status=MiaoDoc%20USER&color=red)](https://docs.yumc.pw/MiaoScript/1-user/1.1-check-env.html)
- 开发文档 [![Build Status](https://ci.yumc.pw/job/Minecraft/job/MiaoScript/badge/icon?style=flat-square&subject=MiaoScript&status=MiaoDoc%20DEVELOP&color=darkred)](https://docs.yumc.pw/MiaoScript/2-develop/1.1-check-env.html)
- 兼容服务端 Spigot CatServer Sponge BungeeCord Nukkit(没错 他还兼容Nukkit)
### 腐竹版本(开发中)
- 先上几张图

View File

@ -1,5 +1,5 @@
{
"version": "0.0.0",
"version": "0.7.0",
"useWorkspaces": true,
"npmClient": "yarn",
"packages": [
@ -13,4 +13,4 @@
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
}
}
}
}

View File

@ -6,15 +6,20 @@
"author": "MiaoWoo <admin@yumc.pw>",
"license": "MIT",
"scripts": {
"clean": "npx lerna run clean",
"watch": "npx lerna run watch --parallel",
"build": "npx lerna run build",
"lp": "npx lerna publish"
"bs": "lerna bootstrap",
"clean": "lerna run clean",
"watch": "lerna run watch --parallel",
"build": "lerna run build --scope=\"@ccms/!(plugins)\"",
"build:plugins": "lerna run build --scope=\"@ccms/plugins\"",
"ug": "yarn upgrade-interactive --latest",
"np": "lerna exec \"npm publish --registry https://registry.npmjs.org\" --scope=\"@ccms/!(client|plugins)\"",
"lsp": "npm login --registry=https://registry.npmjs.org --scope=@ccms",
"lp": "lerna publish"
},
"workspaces": [
"packages/*"
],
"devDependencies": {
"lerna": "^3.16.4"
"lerna": "^3.21.0"
}
}

1
packages/amqp/.npmignore Symbolic link
View File

@ -0,0 +1 @@
../../.npmignore

View File

@ -0,0 +1,32 @@
{
"name": "@ccms/amqp",
"version": "0.7.0",
"description": "MiaoScript amqp package",
"keywords": [
"miaoscript",
"minecraft",
"bukkit",
"sponge"
],
"author": "MiaoWoo <admin@yumc.pw>",
"homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC",
"main": "dist/index.js",
"scripts": {
"clean": "rimraf dist",
"watch": "tsc --watch",
"build": "yarn clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1"
},
"dependencies": {
"@ccms/api": "^0.7.0",
"@ccms/nashorn": "^0.7.0",
"@ccms/common": "^0.7.0",
"@ccms/container": "^0.7.0"
},
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.9.2"
}
}

View File

@ -0,0 +1,14 @@
import { ConnectionFactoryAdapter } from "./connection"
import { RabbitTemplateAdapter } from "./template"
export const RabbitAdmin = Java.type('org.springframework.amqp.rabbit.core.RabbitAdmin')
export class RabbitAdminAdapter {
private _Handler: org.springframework.amqp.rabbit.core.RabbitAdmin
constructor(config: RabbitTemplateAdapter | org.springframework.amqp.rabbit.core.RabbitTemplate | ConnectionFactoryAdapter | org.springframework.amqp.rabbit.connection.ConnectionFactory) {
this._Handler = new RabbitAdmin((config instanceof RabbitTemplateAdapter || config instanceof ConnectionFactoryAdapter) ? config.getHandler() : config)
}
getHandler(): org.springframework.amqp.rabbit.core.RabbitAdmin {
return this._Handler
}
}

View File

@ -0,0 +1,30 @@
export const ConfirmCallback = Java.type('org.springframework.amqp.rabbit.core.RabbitTemplate.ConfirmCallback')
export const ReturnCallback = Java.type('org.springframework.amqp.rabbit.core.RabbitTemplate.ReturnCallback')
export abstract class ConfirmCallbackAdapter {
private _Handler: org.springframework.amqp.rabbit.core.RabbitTemplate.ConfirmCallback
constructor() {
let ConfirmCallbackImpl = Java.extend(ReturnCallback, {
confirm: (correlationData: org.springframework.amqp.rabbit.connection.CorrelationData, ack: boolean, cause: string) => this.confirm(correlationData, ack, cause)
})
this._Handler = new ConfirmCallbackImpl()
}
abstract confirm(correlationData: org.springframework.amqp.rabbit.connection.CorrelationData, ack: boolean, cause: string)
getHandler() {
return this._Handler
}
}
export abstract class ReturnCallbackAdapter {
private _Handler: org.springframework.amqp.rabbit.core.RabbitTemplate.ReturnCallback
constructor() {
let ReturnCallbackImpl = Java.extend(ReturnCallback, {
returnedMessage: (message: org.springframework.amqp.core.Message, replyCode: number, replyText: string, exchange: string, routingKey: string) => this.returnedMessage(message, replyCode, replyText, exchange, routingKey)
})
this._Handler = new ReturnCallbackImpl()
}
abstract returnedMessage(message: org.springframework.amqp.core.Message, replyCode: number, replyText: string, exchange: string, routingKey: string)
getHandler() {
return this._Handler
}
}

View File

@ -0,0 +1,31 @@
import threadPool from '@ccms/common/dist/thread-pool'
export const ConnectionFactory = Java.type('org.springframework.amqp.rabbit.connection.ConnectionFactory')
const CachingConnectionFactory = Java.type('org.springframework.amqp.rabbit.connection.CachingConnectionFactory')
interface ConnectionConfig {
url: string,
username?: string,
password?: string,
publisherConfirms?: boolean
cacheSize?: number
}
export class ConnectionFactoryAdapter {
private _Handler: org.springframework.amqp.rabbit.connection.CachingConnectionFactory
constructor(config: ConnectionConfig) {
if (!config.url) { throw new Error('Connection UrI Can\'t be undefiend!') }
config = { publisherConfirms: true, cacheSize: 50, ...config }
this._Handler = new CachingConnectionFactory(new java.net.URI(config.url))
config.username && this._Handler.setUsername(config.username)
config.password && this._Handler.setPassword(config.password)
this._Handler.setPublisherConfirms(config.publisherConfirms)
this._Handler.setExecutor(threadPool.create({
groupName: '@ccms/amqp-rabbit'
}))
this._Handler.setChannelCacheSize(config.cacheSize)
}
getHandler() {
return this._Handler
}
}

View File

@ -0,0 +1,30 @@
import { ConnectionFactoryAdapter, ConnectionFactory } from "./connection"
import { ChannelAwareMessageListenerAdapter, ChannelAwareMessageListener } from "./listener"
export const SimpleMessageListenerContainer = org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer
export const AcknowledgeMode = org.springframework.amqp.core.AcknowledgeMode
interface ContainerConfig {
connectionFactory: ConnectionFactoryAdapter | typeof ConnectionFactory
queueNames: string[]
messageListener: ChannelAwareMessageListenerAdapter | typeof ChannelAwareMessageListener
maxConcurrentConsumers?: number
concurrentConsumers?: number
acknowledgeMode?: org.springframework.amqp.core.AcknowledgeMode
}
export class MessageListenerContainerAdapter {
private _Handler: org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer
constructor(config: ContainerConfig) {
config = { concurrentConsumers: 5, maxConcurrentConsumers: 10, acknowledgeMode: AcknowledgeMode.AUTO, ...config }
this._Handler = new SimpleMessageListenerContainer(config.connectionFactory instanceof ConnectionFactoryAdapter ? config.connectionFactory.getHandler() : config.connectionFactory)
//@ts-ignore
this._Handler.setQueueNames(config.queueNames)
this._Handler.setMaxConcurrentConsumers(config.maxConcurrentConsumers)
this._Handler.setConcurrentConsumers(config.concurrentConsumers)
this._Handler.setAcknowledgeMode(config.acknowledgeMode)
this._Handler.setMessageListener(config.messageListener instanceof ChannelAwareMessageListenerAdapter ? config.messageListener.getHandler() : config.messageListener)
}
getHandler() {
return this._Handler
}
}

View File

@ -0,0 +1,37 @@
const JavaString = Java.type('java.lang.String')
const MessageProperties = org.springframework.amqp.core.MessageProperties
const Message = org.springframework.amqp.core.Message
export const MessageConverter = Java.type('org.springframework.amqp.support.converter.MessageConverter')
export class MessageConverterAdapter {
private _Handler: org.springframework.amqp.support.converter.MessageConverter
constructor() {
var MessageConverterImpl = Java.extend(MessageConverter, {
toMessage: (object: any, messageProperties: org.springframework.amqp.core.MessageProperties) => this.toMessage(object, messageProperties),
fromMessage: (message: org.springframework.amqp.core.Message) => this.fromMessage(message)
})
this._Handler = new MessageConverterImpl()
}
toMessage(object: any, messageProperties: org.springframework.amqp.core.MessageProperties) {
if (typeof object == "string") {
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN)
return new Message(new JavaString(object).getBytes(), messageProperties)
} else {
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_JSON)
return new Message(new JavaString(JSON.stringify(object)).getBytes(), messageProperties)
}
}
fromMessage(message: org.springframework.amqp.core.Message) {
if (message.getMessageProperties().getContentType() == MessageProperties.CONTENT_TYPE_TEXT_PLAIN) {
return new JavaString(message.getBody(), message.getMessageProperties().getContentEncoding())
}
if (message.getMessageProperties().getContentType() == MessageProperties.CONTENT_TYPE_JSON) {
return JSON.parse(new JavaString(message.getBody(), message.getMessageProperties().getContentEncoding()))
}
return message
}
getHandler() {
return this._Handler
}
}

View File

@ -0,0 +1,7 @@
export * from './admin'
export * from './callback'
export * from './connection'
export * from './container'
export * from './converter'
export * from './listener'
export * from './template'

View File

@ -0,0 +1,49 @@
const JavaString = Java.type('java.lang.String')
export const MessageProperties = org.springframework.amqp.core.MessageProperties
export const ChannelAwareMessageListener = Java.type('org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener')
export const AmqpRejectAndDontRequeueException = org.springframework.amqp.AmqpRejectAndDontRequeueException
export const Channel: com.rabbitmq.client.Channel = Java.type('com.rabbitmq.client.Channel')
export const Message = org.springframework.amqp.core.Message
export type MessageHandler<T> = (content: T, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel) => any
export abstract class ChannelAwareMessageListenerAdapter<T = any> {
private _Handler: org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener
constructor(manual: boolean = false) {
let ChannelAwareMessageListenerImpl = Java.extend(ChannelAwareMessageListener, {
onMessage: (message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel) => {
let content = new JavaString(message.getBody(), message.getMessageProperties().getContentEncoding() || "UTF-8")
try {
if (message.getMessageProperties().getContentType() == MessageProperties.CONTENT_TYPE_JSON) {
content = JSON.parse(content)
}
} catch (error) {
if (manual) {
channel.basicReject(message.getMessageProperties().getDeliveryTag(), true)
} else {
throw new AmqpRejectAndDontRequeueException(`${error}`, error)
}
}
manual ? this.manualOnMessage(content, message, channel) : this.onMessage(content, message, channel)
}
})
this._Handler = new ChannelAwareMessageListenerImpl()
}
abstract onMessage(content: T, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel): any
onError(error: Error, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel): any { }
getHandler() {
return this._Handler
}
private manualOnMessage(content: T, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel) {
let deliveryTag = message.getMessageProperties().getDeliveryTag()
try {
if (this.onMessage(content, message, channel)) {
channel.basicAck(deliveryTag, false)
} else if (message.getMessageProperties().getRedelivered()) {
channel.basicReject(deliveryTag, true)
} else {
channel.basicNack(deliveryTag, false, true)
}
} catch (error) {
channel.basicReject(deliveryTag, this.onError(error, message, channel))
}
}
}

View File

@ -0,0 +1,27 @@
import { MessageConverterAdapter } from "./converter"
import { ConnectionFactoryAdapter } from "./connection"
import { ConfirmCallbackAdapter, ReturnCallbackAdapter } from "./callback"
export const RabbitTemplate = Java.type('org.springframework.amqp.rabbit.core.RabbitTemplate')
interface TemplateConfig {
connectionFactory: ConnectionFactoryAdapter | org.springframework.amqp.rabbit.connection.ConnectionFactory
confirmCallback?: ConfirmCallbackAdapter
returnCallback?: ReturnCallbackAdapter
messageConverter?: MessageConverterAdapter
}
export class RabbitTemplateAdapter {
private _Handler: org.springframework.amqp.rabbit.core.RabbitTemplate
constructor(config: TemplateConfig) {
config = { messageConverter: new MessageConverterAdapter(), ...config }
console.debug(JSON.stringify(config))
this._Handler = new RabbitTemplate(config.connectionFactory instanceof ConnectionFactoryAdapter ? config.connectionFactory.getHandler() : config.connectionFactory)
config.returnCallback && this._Handler.setReturnCallback(config.returnCallback.getHandler())
config.confirmCallback && this._Handler.setConfirmCallback(config.confirmCallback.getHandler())
config.messageConverter && this._Handler.setMessageConverter(config.messageConverter.getHandler())
}
getHandler() {
return this._Handler
}
}

View File

@ -0,0 +1,90 @@
import { JSClass } from "@ccms/container"
import { RabbitAdminAdapter, MessageListenerContainerAdapter, AcknowledgeMode, MessageHandler, ChannelAwareMessageListenerAdapter } from "./adapter"
const RabbitAdmin = Java.type('org.springframework.amqp.rabbit.core.RabbitAdmin')
export class AmqpAdmin {
@JSClass('org.springframework.amqp.core.TopicExchange')
private TopicExchange: typeof org.springframework.amqp.core.TopicExchange
@JSClass('org.springframework.amqp.core.Queue')
private Queue: typeof org.springframework.amqp.core.Queue
@JSClass('org.springframework.amqp.core.Binding')
private Binding: typeof org.springframework.amqp.core.Binding
@JSClass('org.springframework.amqp.core.Binding.DestinationType')
private DestinationType: typeof org.springframework.amqp.core.Binding.DestinationType
private amqpAdmin: org.springframework.amqp.rabbit.core.RabbitAdmin
constructor(amqpAdmin: org.springframework.amqp.rabbit.core.RabbitAdmin | any) {
if (amqpAdmin instanceof RabbitAdmin) {
this.amqpAdmin = amqpAdmin
} else if (amqpAdmin instanceof RabbitAdminAdapter) {
this.amqpAdmin = amqpAdmin.getHandler()
} else {
this.amqpAdmin = new RabbitAdminAdapter(amqpAdmin).getHandler()
}
}
getHandler() {
return this.amqpAdmin
}
getQueueProperties(name: string) {
return this.amqpAdmin.getQueueProperties(name)
}
declareExchange(name: string) {
let exchange = new this.TopicExchange(name, true, false)
this.amqpAdmin.declareExchange(exchange)
return this
}
declareQueue(name: string) {
let queue = new this.Queue(name, true)
this.amqpAdmin.declareQueue(queue)
return this
}
declareBinding(queue: string, exchange: string, routerKey: string, argument: any = null) {
let binding = new this.Binding(queue, this.DestinationType.QUEUE, exchange, routerKey, argument)
this.amqpAdmin.declareBinding(binding)
return this
}
declareQueueAndBindExchange(queue: string, exchange: string, routerKey: string) {
return this.declareQueue(queue).declareExchange(exchange).declareBinding(queue, exchange, routerKey)
}
createContainer<T>(queue: string, listener: MessageHandler<T>, acknowledgeMode = AcknowledgeMode.AUTO) {
let connection = this.amqpAdmin.getRabbitTemplate().getConnectionFactory()
return new MessageListenerContainerAdapter({
connectionFactory: connection,
queueNames: [queue],
messageListener: new SimpleMessageHandler(listener),
acknowledgeMode: acknowledgeMode
}).getHandler()
}
send()
send() {
}
getTemplate() {
return this.amqpAdmin.getRabbitTemplate()
}
close() {
this.getTemplate().stop()
}
}
export class SimpleMessageHandler extends ChannelAwareMessageListenerAdapter {
constructor(private handler: MessageHandler<any>) {
super()
}
onMessage(content: any, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel) {
return this.handler(content, message, channel)
}
}

View File

@ -0,0 +1,3 @@
export const METADATA_KEY = {
}

View File

@ -0,0 +1,34 @@
/// <reference types="@ccms/nashorn" />
/// <reference types="@ccms/types/dist/typings/jdk" />
/// <reference types="@ccms/types/dist/typings/spring" />
/// <reference types="@ccms/types/dist/typings/spring/amqp" />
/// <reference types="@ccms/types/dist/typings/rabbitmq" />
import { amqp } from '@ccms/api'
import { getContainer, reduceMetadata } from '@ccms/container'
function init() {
const beanFactory = base.getInstance().getAutowireCapableBeanFactory()
getContainer().bind(amqp.rabbit.Template).toDynamicValue((ctx) => {
let metadata = reduceMetadata(ctx)
if (!metadata.named) {
return beanFactory.getBean('rabbitTemplate')
} else {
return beanFactory.getBean(`${metadata.named}-rabbitTemplate`)
}
})
getContainer().bind(amqp.rabbit.Admin).toDynamicValue((ctx) => {
let metadata = reduceMetadata(ctx)
if (!metadata.named) {
return beanFactory.getBean('rabbitAdmin')
} else {
return beanFactory.getBean(`${metadata.named}-rabbitAdmin`)
}
})
}
init()
export * from './admin'
export * from './adapter'
export * from './manager'
export * from './constants'

View File

@ -0,0 +1,5 @@
export class AmqpListener {
constructor() {
}
}

View File

@ -0,0 +1,18 @@
import { amqp } from "@ccms/api"
import { provideSingleton } from "@ccms/container"
import { ConnectionFactoryAdapter, RabbitTemplateAdapter, RabbitAdminAdapter } from "./adapter"
import { AmqpAdmin } from "./admin"
@provideSingleton(amqp.Manager)
export class AmqpManager {
createConnection(url: string, username: string, password: string) {
return new ConnectionFactoryAdapter({ url, username, password })
}
createTemplate(adapter: ConnectionFactoryAdapter) {
return new RabbitTemplateAdapter({ connectionFactory: adapter })
}
createAdmin(adapter: RabbitTemplateAdapter | ConnectionFactoryAdapter) {
return new AmqpAdmin(new RabbitAdminAdapter(adapter))
}
}

View File

@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "src",
"outDir": "dist"
}
}

View File

@ -1,4 +0,0 @@
/node_modules
/dist
/package-lock.json
/yarn.lock

View File

@ -1,22 +0,0 @@
src
test
typings
bundled
build
coverage
docs
wiki
gulpfile.js
bower.json
karma.conf.js
tsconfig.json
typings.json
CONTRIBUTING.md
ISSUE_TEMPLATE.md
PULL_REQUEST_TEMPLATE.md
tslint.json
wallaby.js
.travis.yml
.gitignore
.vscode
type_definitions

1
packages/api/.npmignore Symbolic link
View File

@ -0,0 +1 @@
../../.npmignore

View File

@ -1,6 +1,6 @@
{
"name": "@ms/api",
"version": "0.0.0",
"name": "@ccms/api",
"version": "0.7.0",
"description": "MiaoScript api package",
"keywords": [
"miaoscript",
@ -12,22 +12,23 @@
"homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC",
"main": "dist/index.js",
"publishConfig": {
"registry": "https://repo.yumc.pw/repository/npm/"
},
"scripts": {
"clean": "rimraf dist",
"watch": "npx tsc --watch",
"build": "yarn clean && npx tsc",
"watch": "tsc --watch",
"build": "yarn clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1"
},
"dependencies": {
"@ms/common": "^0.0.0",
"@ms/container": "^0.0.0"
"@ccms/container": "^0.7.0",
"@ccms/ployfill": "^0.7.0",
"@ccms/common": "^0.7.0",
"base64-js": "^1.3.1",
"source-map-builder": "^0.0.7"
},
"devDependencies": {
"@types/base64-js": "^1.2.5",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.0",
"typescript": "^3.6.2"
"rimraf": "^3.0.2",
"typescript": "^3.9.2"
}
}

View File

@ -0,0 +1,66 @@
import { injectable } from "@ccms/container";
export namespace channel {
/**
* handle plugin message
* @param data byte[]
*/
export type ChannelListener = (data: any, exts?: any) => void
@injectable()
export abstract class Channel {
private listenerMap = [];
/**
*
* @param plugin
* @param channel
* @param exec
*/
listen(plugin: any, channel: string, exec: ChannelListener) {
if (!plugin || !plugin.description || !plugin.description.name) throw new TypeError('Plugin can\'t be undefiend!');
let name = plugin.description.name;
let listener = this.register(channel, exec)
if (!this.listenerMap[name]) this.listenerMap[name] = [];
let offExec = () => {
this.unregister(channel, listener);
console.debug(`[${name}] unregister channel ${channel}`);
};
var off = {
channel,
listener,
off: offExec
};
this.listenerMap[name].push(off);
console.debug(`[${name}] register channel ${channel} => ${exec.name || '[anonymous]'}`);
return off;
}
/**
*
* @param plugin
*/
disable(plugin: any) {
var channelCache = this.listenerMap[plugin.description.name];
if (channelCache) {
channelCache.forEach(t => t.off());
delete this.listenerMap[plugin.description.name];
}
}
/**
* Send Channel Message
* @param player recover target
* @param channel ChannelName
* @param data byte[]
*/
abstract send(player: any, channel: string, data: any)
/**
* register channel
* @param channel ChannelName
*/
abstract register(channel: string, listener: ChannelListener): any
/**
* unregister channel
* @param channel ChannelName
*/
abstract unregister(channel: string, listener?: any): void
}
}

View File

@ -1,25 +1,79 @@
import { injectable } from "@ms/container";
import i18n from '@ccms/i18n'
import { injectable } from "@ccms/container"
import { plugin } from './interfaces'
export namespace command {
@injectable()
export abstract class Command {
on(plugin: any, name: string, exec: { cmd: Function, tab?: Function }) {
var cmd = this.create(plugin, { name: name });
console.debug(`插件 ${plugin.description.name} 创建命令 ${name}(${cmd})...`)
/**
*
* @param plugin
* @param name
* @param exec
*/
on(plugin: plugin.Plugin, name: string, exec: { cmd: Function, tab?: Function }) {
var cmd = this.create(plugin, name)
if (!cmd) { throw Error("") }
console.debug(i18n.translate("ms.api.command.register", { plugin: plugin.description.name, name, cmd }))
if (exec.cmd && typeof exec.cmd === "function") {
this.onCommand(plugin, cmd, exec.cmd)
} else {
throw Error("CommandExec Must be a function... Input: " + exec.cmd)
throw Error(i18n.translate("ms.api.command.register.input.error", { exec: exec.cmd }))
}
if (exec.tab && typeof exec.tab === "function") {
this.onTabComplete(plugin, cmd, exec.tab)
}
}
/**
* Create Server Command Object
*
* @param plugin
* @param name
*/
abstract create(plugin: object, opts: { name: string });
abstract onCommand(plugin: object, command: any, opts: { name: string });
abstract onTabComplete(plugin: object, command: any, opts: { name: string });
off(plugin: plugin.Plugin, name: string) {
console.debug(i18n.translate("ms.api.command.unregister", { plugin: plugin.description.name, name }))
this.remove(plugin, name)
}
protected abstract create(plugin: plugin.Plugin, command: string): any
protected abstract remove(plugin: plugin.Plugin, command: string): void
protected abstract onCommand(plugin: plugin.Plugin, command: any, executor: Function)
protected abstract onTabComplete(plugin: plugin.Plugin, command: any, tabCompleter: Function)
protected setExecutor(plugin: plugin.Plugin, command: any, executor: Function) {
return (sender: any, _: any, command: string, args: string[]) => {
try {
return executor(sender, command, Java.from(args))
} catch (ex) {
console.i18n("ms.api.command.execute.error", { player: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex })
console.ex(ex)
if (sender.name != 'CONSOLE') {
console.sender(sender, [i18n.translate("ms.api.command.execute.error", { player: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex }), ...console.stack(ex)])
}
return true
}
}
}
protected setTabCompleter(plugin: plugin.Plugin, command: any, tabCompleter: Function) {
return (sender: any, _: any, command: string, args: string[]) => {
try {
var token = args[args.length - 1]
var complete = tabCompleter(sender, command, Java.from(args)) || []
return this.copyPartialMatches(complete, token)
} catch (ex) {
console.i18n("ms.api.command.tab.completer.error", { sender: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex })
console.ex(ex)
console.sender(sender, [i18n.translate("ms.api.command.tab.completer.error", { sender: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex }), ...console.stack(ex)])
return []
}
}
}
protected copyPartialMatches(complete: string[], token: string, array: string[] = []): string[] {
if (!token) { return complete }
complete.forEach(function (e) {
if (typeof e === "string" && e.toLowerCase().startsWith(token.toLowerCase())) {
array.push(e)
}
})
return array
}
}
}

View File

@ -1,148 +1,228 @@
let Arrays = Java.type('java.util.Arrays');
let Level = Java.type('java.util.logging.Level');
let ignoreLogPrefix = ['java.', 'net.minecraft.', 'org.bukkit.', 'jdk.nashorn.'];
import i18m from '@ccms/i18n'
import { SourceMapBuilder } from 'source-map-builder'
import * as base64 from 'base64-js'
const Arrays = Java.type('java.util.Arrays')
const Level = Java.type('java.util.logging.Level')
const Paths = Java.type('java.nio.file.Paths')
const ignoreLogPrefix = ['java.', 'javax.', 'sun.', 'net.minecraft.', 'org.bukkit.', 'jdk.nashorn.', 'io.netty.', 'org.spongepowered.', 'org.apache', 'org.springframework']
enum LogLevel {
ALL,
TRACE,
DEBUG,
INFO,
WARN,
ERROR,
FATAL,
OFF
}
export class MiaoScriptConsole implements Console {
Console: NodeJS.ConsoleConstructor;
Console: NodeJS.ConsoleConstructor
private _name: string = '';
private static sourceMaps: { [key: string]: SourceMapBuilder } = {}
private static sourceFileMaps: { [key: string]: string } = {}
private _name: string = ''
private _level: LogLevel = LogLevel.INFO
protected logger: any;
protected prefix: string = '§6[§bMiaoScript§6]§r ';
protected logger: any
protected prefix: string = '§6[§bMiaoScript§6]§r '
constructor(name?: string) {
this.name = name;
this.logger = global.logger;
this.name = name
this.logger = global.logger
if (global.debug) {
this._level = LogLevel.DEBUG
}
if (global.level?.toUpperCase() === "TRACE") {
this._level = LogLevel.TRACE
}
}
get name() {
return this._name;
return this._name
}
set name(name: string) {
if (name) {
this._name = `[${name}] `;
this._name = `[${name}] `
// noinspection JSUnusedGlobalSymbols
this.prefix = `§6[§cMS§6][§b${name}§6]§r `;
this.prefix = `§6[§cMS§6][§b${name}§6]§r `
}
}
log(...args): void {
this.logger.info(this.name + args.join(' '));
log(...args: any[]): void {
this.logger.info(this.name + args.join(' '))
}
info(...args) {
this.logger.info(this.name + args.join(' '));
};
warn(...args) {
this.logger.warning(this.name + args.join(' '));
};
error(...args) {
this.logger.log(Level.SEVERE, this.name + args.join(' '));
};
debug(...args) {
info(...args: any[]) {
this.logger.info(this.name + args.join(' '))
}
warn(...args: any[]) {
this.logger.warning(this.name + args.join(' '))
}
error(...args: any[]) {
this.logger.log(Level.SEVERE, this.name + args.join(' '))
}
debug(...args: any[]) {
if (global.debug) {
this.logger.info(this.name + '[DEBUG] ' + args.join(' '));
this.logger.info(this.name + '[DEBUG] ' + args.join(' '))
}
};
}
trace(...args: any[]): void {
if (this._level <= LogLevel.TRACE) {
this.logger.info(this.name + '[TRACE] ' + args.join(' '))
}
}
sender(...args) {
this.info(args)
}
console(...args) {
this.info(args)
}
i18n(name: string, param?: { [key: string]: any }) {
this.console(i18m.translate(name, param))
}
object(obj) {
for (var i in obj) {
this.logger(i, '=>', obj[i])
for (const i in obj) {
this.info(i, '=>', obj[i])
}
};
}
ex(ex: Error) {
this.stack(ex).forEach(line => this.console(line))
};
stack(ex: Error | any): string[] {
var stack = ex.getStackTrace();
var cache = ['§4' + ex];
if (stack.class) {
stack = Arrays.asList(stack)
}
stack.forEach(function(trace) {
if (trace.className.startsWith('<')) {
var fileName = trace.fileName
if (fileName.startsWith(root)) { fileName = fileName.split(root)[1] }
if (fileName.startsWith('/runtime')) { fileName = fileName.split('/runtime')[1] }
cache.push(` §e->§c ${fileName} => §4${trace.methodName}:${trace.lineNumber}`)
} else {
var className = trace.className;
if (className.startsWith('jdk.nashorn.internal.scripts')) {
className = className.substr(className.lastIndexOf('$') + 1)
} else {
for (var prefix in ignoreLogPrefix) {
if (className.startsWith(ignoreLogPrefix[prefix])) {
return;
}
readSourceMap(fileName: string, lineNumber: number) {
try {
if (fileName.endsWith('js')) {
if (MiaoScriptConsole.sourceMaps[fileName] === undefined) {
MiaoScriptConsole.sourceMaps[fileName] = null
let sourceLine = base.read(fileName).split('\n')
let lastLine = sourceLine[sourceLine.length - 1]
if (lastLine.startsWith('//# sourceMappingURL=')) {
let sourceContent = null
let sourceMappingURL = lastLine.split('sourceMappingURL=', 2)[1]
if (sourceMappingURL.startsWith('data:application/jsonbase64,')) {
sourceContent = String.fromCharCode(...Array.from(base64.toByteArray(sourceMappingURL.split(',', 2)[1])))
} else if (sourceMappingURL.startsWith('http')) {
// TODO
} else {
let file = Paths.get(Paths.get(fileName, '..', sourceMappingURL).toFile().getCanonicalPath()).toFile()
if (file.exists()) { sourceContent = base.read(file) }
}
if (sourceContent) {
MiaoScriptConsole.sourceMaps[fileName] = new SourceMapBuilder(JSON.parse(sourceContent))
MiaoScriptConsole.sourceFileMaps[fileName] = Paths.get(fileName, '..', MiaoScriptConsole.sourceMaps[fileName].sources[0]).toFile().getCanonicalPath()
}
}
}
cache.push(` §e->§c ${className}.${trace.methodName}(§4${trace.fileName}:${trace.lineNumber}§c)`);
if (MiaoScriptConsole.sourceMaps[fileName]) {
let sourceMapping = MiaoScriptConsole.sourceMaps[fileName].getSource(lineNumber, 25, true, true)
fileName = MiaoScriptConsole.sourceFileMaps[fileName]
if (sourceMapping && lineNumber != sourceMapping.mapping.sourceLine) { lineNumber = sourceMapping.mapping.sourceLine }
}
}
});
return cache;
} catch (error) {
console.debug('search source map', fileName, 'line', lineNumber, 'error:', error)
}
return {
fileName,
lineNumber
}
}
stack(ex: Error, color: boolean = true): string[] {
let stack = ex.getStackTrace()
let cache = [(color ? '§c' : '') + ex]
//@ts-ignore
if (stack.class) {
stack = Arrays.asList(stack)
}
stack.forEach(trace => {
if (!trace.fileName || trace.fileName.startsWith('jar:file:') || trace.fileName.startsWith('file:')) { return }
if (trace.className.startsWith('<')) {
let { fileName, lineNumber } = this.readSourceMap(trace.fileName, trace.lineNumber)
if (fileName.startsWith(root)) { fileName = fileName.split(root)[1] }
if (color) {
cache.push(` §e->§c ${fileName}:${lineNumber} => §4${trace.methodName}`)
} else {
cache.push(` -> ${fileName}:${lineNumber} => ${trace.methodName}`)
}
} else {
let className = trace.className
var fileName = trace.fileName as string
if (className.startsWith('jdk.nashorn.internal.scripts')) {
className = className.substr(className.lastIndexOf('$') + 1)
var { fileName, lineNumber } = this.readSourceMap(trace.fileName, trace.lineNumber)
if (fileName.startsWith(root)) { fileName = fileName.split(root)[1] }
} else {
for (let prefix in ignoreLogPrefix) {
if (className.startsWith(ignoreLogPrefix[prefix])) {
return
}
}
}
if (color) {
cache.push(` §e->§c ${className}.${trace.methodName}(§4${fileName}:${lineNumber}§c)`)
} else {
cache.push(` -> ${className}.${trace.methodName}(${fileName}:${lineNumber})`)
}
}
})
return cache
}
assert(value: any, message?: string, ...optionalParams: any[]): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
clear(): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
count(label?: string): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
countReset(label?: string): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
dir(obj: any, options?: NodeJS.InspectOptions): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
dirxml(...data: any[]): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
group(...label: any[]): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
groupCollapsed(...label: any[]): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
groupEnd(): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
table(tabularData: any, properties?: string[]): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
time(label?: string): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
timeEnd(label?: string): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
timeLog(label?: string, ...data: any[]): void {
throw new Error("Method not implemented.");
}
trace(message?: any, ...optionalParams: any[]): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
markTimeline(label?: string): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
profile(label?: string): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
profileEnd(label?: string): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
timeStamp(label?: string): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
timeline(label?: string): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
timelineEnd(label?: string): void {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
}

View File

@ -0,0 +1,17 @@
export namespace constants {
export namespace Reflect {
export const Method = {
getServerConnection: [/*spigot 1.8.8*/'aq',/*spigot 1.12.2*/ 'an', /*spigot 1.14.4+*/'getServerConnection', /*catserver 1.12.2*/'func_147137_ag']
}
export const Field = {
listeningChannels: [/*spigot 1.8.8-1.12.2*/'g', /*spigot 1.14.4*/'f', /*spigot 1.15.2+*/'listeningChannels', /*catserver 1.12.2*/'field_151274_e']
}
}
export enum ServerType {
Bukkit = 'bukkit',
Sponge = 'sponge',
Nukkit = 'nukkit',
Bungee = 'bungee',
Spring = 'spring'
}
}

View File

@ -1,128 +1,143 @@
'use strict';
/**
* MiaoScript Event
*/
import '@ms/core'
import '@ms/nashorn'
import { injectable } from '@ms/container'
import i18n from '@ccms/i18n'
import { injectable, unmanaged } from '@ccms/container'
const Thread = Java.type("java.lang.Thread");
const Thread = Java.type('java.lang.Thread');
export namespace event {
/**
*
*/
export enum EventPriority {
LOWEST = "LOWEST",
LOW = "LOW",
NORMAL = "NORMAL",
HIGH = "HIGH",
HIGHEST = "HIGHEST",
MONITOR = "MONITOR",
}
@injectable()
export abstract class Event {
// export EventPriority to blockly
public EventPriority = EventPriority;
private mapEvent = [];
private listenerMap = [];
private baseEventDir = '';
constructor(baseEventDir: string) {
protected baseEventDir = '';
constructor(@unmanaged() baseEventDir: string) {
this.baseEventDir = baseEventDir;
}
/**
* org.bukkit.event
* org.bukkit.event.player.PlayerLoginEvent => playerloginevent
* abstract event map function
* ig: org.bukkit.event.player.PlayerLoginEvent => playerloginevent
* org.spongepowered.api.event.game.GameRegistryEvent.Register => gameregistryevent$register
*/
mapEventName() {
if (this.baseEventDir === "") {
throw new Error("事件基础包名为空 无法进行事件映射!");
}
var count = 0;
var dirs = Thread.currentThread().getContextClassLoader().getResources(this.baseEventDir);
while (dirs.hasMoreElements()) {
var url = dirs.nextElement();
var protocol = url.protocol;
if (protocol === "jar") {
// noinspection JSUnresolvedVariable
var jar = url.openConnection().jarFile;
var entries = jar.entries();
while (entries.hasMoreElements()) {
var entry = entries.nextElement();
var name = entry.name;
// 以 org/bukkit/event 开头 并且以 .class 结尾
if (name.startsWith(this.baseEventDir) && name.endsWith(".class")) {
var i = name.replaceAll('/', '.');
try {
var clz = base.getClass(i.substring(0, i.length - 6));
// 继承于 org.bukkit.event.Event 访问符为Public
if (this.isValidEvent(clz)) {
var simpleName = this.class2Name(clz).toLowerCase();
console.debug(`Mapping Event [${clz.canonicalName}] => ${simpleName}`);
this.mapEvent[simpleName] = clz;
count++;
}
} catch (ex) {
//ignore already loaded class
}
if (this.baseEventDir === "") { throw new Error(i18n.translate('ms.api.event.empty.event.dir')); }
let count = 0;
let jar = this.getJarFile(this.baseEventDir);
let entries = jar.entries();
while (entries.hasMoreElements()) {
let entry = entries.nextElement();
let name = entry.name;
if (name.startsWith(this.baseEventDir) && name.endsWith(".class")) {
// replace name to qualifiedName
let qualifiedName = name.replaceAll('/', '.');
try {
let clazz = base.getClass(qualifiedName.substring(0, qualifiedName.length - 6));
if (this.isValidEvent(clazz)) {
let simpleName = this.class2Name(clazz).toLowerCase();
console.trace(i18n.translate("ms.api.event.mapping", { canonicalName: clazz.canonicalName, simpleName }));
this.mapEvent[simpleName] = clazz;
count++;
}
} catch (ex) {
//ignore already loaded class
}
}
}
return count;
};
}
class2Name(clazz) {
getJarFile(resource: string, loader?: any) {
let dirs = (loader || Thread.currentThread().getContextClassLoader()).getResources(resource);
if (dirs.hasMoreElements()) {
let url = dirs.nextElement();
if (url.protocol === "jar") { return url.openConnection().jarFile; }
}
throw new Error(i18n.translate("ms.api.event.resource.not.found", { resource }))
}
class2Name(clazz: any) {
return clazz.simpleName;
};
}
name2Class(name, event) {
var eventCls = this.mapEvent[event.toLowerCase()] || this.mapEvent[event.toLowerCase() + 'event'];
name2Class(name: any, event: string) {
let eventCls = this.mapEvent[event.toLowerCase()] || this.mapEvent[event.toLowerCase() + 'event'];
if (!eventCls) {
try {
eventCls = base.getClass(eventCls);
this.mapEvent[event] = eventCls;
} catch (ex) {
console.console(`§6插件 §b${name} §6注册事件 §c${event} §6失败 §4事件未找到!`);
console.ex(new Error(`插件 ${name} 注册事件 ${event} 失败 事件未找到!`));
console.i18n("ms.api.event.not.found", { name, event })
return;
}
}
return eventCls;
};
}
execute(name, exec, eventCls) {
return (...args) => {
return (...args: any[]) => {
try {
var time = new Date().getTime()
exec(args[args.length - 1]);
var cost = new Date().getTime() - time;
if (cost > 20) {
console.console(`§c注意! §6插件 §b${name} §6处理 §d${this.class2Name(eventCls)} §6事件 §c耗时 §4${cost}ms !`)
let event = args[args.length - 1];
if (eventCls.isAssignableFrom(event.getClass())) {
let time = Date.now()
exec(event);
let cost = Date.now() - time;
if (cost > 20) {
console.i18n("ms.api.event.execute.slow", { name, event: this.class2Name(eventCls), cost })
}
}
} catch (ex) {
console.console(`§6插件 §b${name} §6处理 §d${this.class2Name(eventCls)} §6事件时发生异常 §4${ex}`);
console.i18n("ms.api.event.execute.error", { name, event: this.class2Name(eventCls), ex })
console.ex(ex);
}
};
};
}
}
/**
*
* @param jsp
* @param event
* @param plugin {any}
* @param event {string}
* @param exec {function}
* @param priority [LOWEST,LOW,NORMAL,HIGH,HIGHEST,MONITOR]
* @param priority {string} [LOWEST,LOW,NORMAL,HIGH,HIGHEST,MONITOR]
* @param ignoreCancel
*/
listen(jsp, event, exec, priority, ignoreCancel) {
if (!jsp || !jsp.description || !jsp.description.name) throw new TypeError('插件名称为空 请检查传入参数!');
var name = jsp.description.name;
listen(plugin: any, event: string, exec: (event: any) => void, priority: EventPriority = EventPriority.NORMAL, ignoreCancel = false) {
if (!plugin || !plugin.description || !plugin.description.name) throw new TypeError(i18n.translate("ms.api.event.listen.plugin.name.empty"));
var name = plugin.description.name;
var eventCls = this.name2Class(name, event);
if (!eventCls) { return; }
if (typeof priority === 'boolean') {
ignoreCancel = priority;
priority = 'NORMAL';
priority = EventPriority.NORMAL;
}
priority = priority || 'NORMAL';
priority = priority || EventPriority.NORMAL;
ignoreCancel = ignoreCancel || false;
// noinspection JSUnusedGlobalSymbols
var listener = this.register(eventCls, this.execute(name, exec, eventCls), priority, ignoreCancel);
var listenerMap = this.listenerMap;
// 添加到缓存 用于关闭插件的时候关闭事件
// add to cache Be used for close plugin to close event
if (!listenerMap[name]) listenerMap[name] = [];
var offExec = () => {
this.unregister(eventCls, listener);
console.debug(`插件 ${name} 注销事件 ${this.class2Name(eventCls)}`);
console.debug(i18n.translate("ms.api.event.unregister", { name, event: this.class2Name(eventCls) }));
};
var off = {
event: eventCls,
@ -131,10 +146,14 @@ export namespace event {
};
listenerMap[name].push(off);
// noinspection JSUnresolvedVariable
console.debug(`插件 ${name} 注册事件 ${this.class2Name(eventCls)} => ${exec.name || '匿名方法'}`);
console.debug(i18n.translate("ms.api.event.register", { name, event: this.class2Name(eventCls) }));
return off;
}
/**
*
* @param plugin
*/
disable(plugin: any) {
var eventCache = this.listenerMap[plugin.description.name];
if (eventCache) {
@ -143,8 +162,24 @@ export namespace event {
}
}
/**
*
* @param clazz
*/
abstract isValidEvent(clazz: any): boolean;
/**
*
* @param eventCls
* @param exec
* @param priority
* @param ignoreCancel
*/
abstract register(eventCls: any, exec: Function, priority: any, ignoreCancel: boolean): any;
/**
*
* @param event
* @param listener
*/
abstract unregister(event: any, listener: any): void;
}
}

View File

@ -1,6 +1,8 @@
import './typings/global'
import "@ccms/nashorn"
export * from './task'
export * from './event'
export * from './console'
export * from './channel'
export * from './command'
export * from './constants'
export * from './interfaces'

View File

@ -0,0 +1,7 @@
export namespace amqp {
export const Manager = Symbol('AmqpManager')
export namespace rabbit {
export const Admin = Symbol('RabbitAdmin')
export const Template = Symbol('RabbitTemplate')
}
}

View File

@ -0,0 +1,5 @@
export namespace database {
export const DataBaseManager = Symbol("DataBaseManager");
export const DataSource = Symbol("DataSource");
export const DataBase = Symbol("DataBase");
}

View File

@ -1,2 +1,5 @@
export * from './web'
export * from './amqp'
export * from './plugin'
export * from './server'
export * from './database'

View File

@ -1,25 +1,148 @@
import { Container } from "inversify";
export namespace plugin {
/**
* MiaoScript Plugin
*/
export const Plugin = Symbol("Plugin");
export const Plugin = Symbol("Plugin")
/**
* MiaoScript Plugin Folder
*/
export const PluginFolder = Symbol("PluginFolder")
/**
* Runtime Plugin Instance
*/
export const PluginInstance = Symbol("PluginInstance");
export const PluginInstance = Symbol("PluginInstance")
/**
* MiaoScript Plugin Manager
* MiaoScript Plugin Manager Symbol
*/
export const PluginManager = Symbol("PluginManager");
export const PluginManager = Symbol("PluginManager")
/**
* MiaoScript Plugin Manager
* MiaoScript Plugin Manager Interface
*/
export interface PluginManager {
scan(folder: string): void;
load(container: Container): void;
enable(): void;
disable(): void;
scan(folder: string): void
build(): void
loadFromFile(file: string, scanner?: plugin.PluginScanner): Plugin
load(...args: any[]): void
enable(...args: any[]): void
disable(...args: any[]): void
reload(...args: any[]): void
getPlugin(name: string): plugin.Plugin
getPlugins(): Map<string, plugin.Plugin>
}
export const PluginScanner = Symbol("PluginScanner")
/**
*
*/
export interface PluginScanner {
/**
*
*/
type: string
/**
*
* @param target
*/
scan(target: any): string[]
/**
*
* @param target
*/
load(target: any): any
}
export const PluginLoader = Symbol("PluginLoader")
/**
*
*/
export interface PluginLoader {
/**
*
*/
type: string
/**
*
* @param target
* @param result
*/
require(target: any, result: any): PluginMetadata
/**
*
* @param metadata
*/
build(metadata: any): Plugin
/**
* Load
* @param plugin
*/
load(plugin: Plugin): void
/**
* Enable
* @param plugin
*/
enable(plugin: Plugin): void
/**
* Disable
* @param plugin
*/
disable(plugin: Plugin): void
/**
* Reload
* @param plugin
*/
reload(plugin: Plugin): void
}
export interface Plugin {
description: PluginMetadata
logger: Console
load(): void
enable(): void
disable(): void
}
export interface BaseMetadata {
/**
*
*/
name?: string
/**
*
*/
servers?: string[]
}
export interface PluginMetadata extends BaseMetadata {
/**
*
*/
name: string
/**
*
*/
prefix?: string
/**
*
*/
version: string
/**
*
*/
author: string | string[]
/**
* __filename
*/
source: string
/**
* ioc MiaoScript
*/
type?: string
/**
*
*/
scanner?: PluginScanner
/**
*
*/
loader?: PluginLoader
/**
*
*/
target?: any
}
}

View File

@ -1,4 +0,0 @@
export namespace server {
export const ServerType = Symbol("ServerType");
export const Console = Symbol("Console");
}

View File

@ -0,0 +1,143 @@
import * as reflect from '@ccms/common/dist/reflect'
import { injectable } from '@ccms/container'
import { NativePluginManager } from './native_plugin'
import { constants } from '../../constants'
export namespace server {
/**
* Runtime ServerType
*/
export const ServerType = Symbol("ServerType")
/**
* Runtime Console
*/
export const Console = Symbol("Console")
/**
* MiaoScript Server
*/
export const Server = Symbol("Server")
/**
* Runtime Server Instance
*/
export const ServerInstance = Symbol("ServerInstance")
/**
* MiaoScript Server
*/
export interface Server {
getVersion(): string
getPlayer(name: string): any
getOnlinePlayers(): any[]
getConsoleSender(): any
getService(service: string): any
dispatchCommand(sender: string | any, command: string): boolean
dispatchConsoleCommand(command: string): boolean
getPluginsFolder(): string
getNativePluginManager(): NativePluginManager
getDedicatedServer?(): any
getNettyPipeline(): any
getRootLogger(): any
sendJson(sender: string | any, json: object | string): void
tabComplete?(sender: string | any, input: string, index?: number): string[]
}
@injectable()
export abstract class ReflectServer implements server.Server {
protected pipeline: any
protected rootLogger: any
constructor() {
this.reflect()
}
getVersion(): string {
throw new Error("Method not implemented.")
}
getPlayer(name: string) {
throw new Error("Method not implemented.")
}
getOnlinePlayers(): any[] {
throw new Error("Method not implemented.")
}
getConsoleSender() {
throw new Error("Method not implemented.")
}
getService(service: string) {
throw new Error("Method not implemented.")
}
dispatchCommand(sender: any, command: string): boolean {
throw new Error("Method not implemented.")
}
dispatchConsoleCommand(command: string): boolean {
throw new Error("Method not implemented.")
}
getPluginsFolder(): string {
throw new Error("Method not implemented.")
}
getNativePluginManager(): NativePluginManager {
throw new Error("Method not implemented.")
}
getDedicatedServer() {
throw new Error("Method not implemented.")
}
getNettyPipeline() {
throw new Error("Method not implemented.")
}
getRootLogger() {
throw new Error("Method not implemented.")
}
sendJson(sender: any, json: string | object): void {
throw new Error("Method not implemented.")
}
tabComplete?(sender: any, input: string, index?: number): string[] {
throw new Error("Method not implemented.")
}
protected reflect() {
try {
let consoleServer = this.getDedicatedServer()
this.reflectPipeline(consoleServer)
this.reflectRootLogger(consoleServer)
} catch (error) {
console.error('Error When Reflect MinecraftServer!', error)
console.ex(error)
}
}
protected reflectPipeline(consoleServer: any) {
let connection: any
let promise: any
for (const method of constants.Reflect.Method.getServerConnection) {
try {
connection = reflect.on(consoleServer).call(method).get()
if (connection.class.name.indexOf('ServerConnection') !== -1
|| connection.class.name.indexOf('NetworkSystem') !== -1) { break }
connection = undefined
} catch (error) { }
}
if (!connection) { console.error("Can't found ServerConnection!"); return }
for (const field of constants.Reflect.Field.listeningChannels) {
try {
promise = reflect.on(connection).get(field).get().get(0)
if (promise.class.name.indexOf('Promise') !== -1) { break }
promise = undefined
} catch (error) { }
}
if (!promise) { console.error("Can't found listeningChannels!"); return }
this.pipeline = reflect.on(promise).get('channel').get().pipeline()
}
protected reflectRootLogger(consoleServer: any) {
try {
this.rootLogger = reflect.on(consoleServer).get('LOGGER').get().parent
} catch (error) {
try { this.rootLogger = reflect.on(consoleServer).get(0).get().parent } catch (error) { }
}
if (this.rootLogger && this.rootLogger.class.name.indexOf('Logger') === -1) {
console.error('Error Logger Class: ' + this.rootLogger.class.name)
this.rootLogger = undefined
}
// get root logger
for (let index = 0; index < 5 && this.rootLogger.parent; index++) {
this.rootLogger = this.rootLogger.parent
}
if (!this.rootLogger) { console.error("Can't found rootLogger!") }
}
}
}

View File

@ -0,0 +1,6 @@
export interface NativePluginManager {
load(name: string): boolean;
unload(name: string): boolean;
reload(name: string): boolean;
delete(name: string): boolean;
}

View File

@ -0,0 +1,3 @@
export namespace web {
export const Server = Symbol('Server')
}

82
packages/api/src/task.ts Normal file
View File

@ -0,0 +1,82 @@
export namespace task {
export const TaskManager = Symbol('TaskManager')
export interface TaskManager {
/**
*
* @param func
*/
create(func: Function): task.Task;
/**
* 线
* @param func
*/
callSyncMethod(func: Function): any;
/**
*
*/
disable();
}
/**
*
*/
export abstract class Task {
protected plugin: any;
protected func: Function;
protected isAsync: boolean = false;
protected laterTime: number = 0;
protected interval: number = 0;
constructor(plugin: any, func: Function) {
this.plugin = plugin;
this.func = func;
}
/**
*
* @param isAsync
*/
async(isAsync: boolean = true): task.Task {
this.isAsync = isAsync;
return this;
}
/**
*
* @param tick Tick
*/
later(tick: number): task.Task {
this.laterTime = tick;
return this;
}
/**
*
* @param tick Tick
*/
timer(tick: number): task.Task {
this.interval = tick;
return this;
}
protected run(...args: any[]): void {
try {
this.func(...args);
} catch (ex) {
console.console('§4插件执行任务时发生错误', ex)
console.ex(ex);
}
}
/**
*
* @param args
*/
abstract submit(...args: any[]): Cancelable;
}
/**
*
*/
export interface Cancelable {
cancel(): boolean;
}
}

View File

@ -1,24 +0,0 @@
declare global {
namespace NodeJS {
interface Global {
logger: any;
debug: boolean;
noop: Function;
console: Console;
}
}
var root: string;
var base: Core;
var ScriptEngineContextHolder: any;
function engineLoad(str: string): any;
interface Core {
getClass(name: String);
}
interface Console {
ex(err: Error): void;
stack(err: Error): string[];
sender(...args: any): void;
console(...args: any): void;
}
}
export { }

View File

@ -1,13 +0,0 @@
export interface CommandInfo {
aliases: string[];
description: string;
}
export interface PluginInfo {
description: PluginDescription;
}
export interface PluginDescription {
name: string;
version: string;
author: string;
commands: { [key: string]: CommandInfo };
}

View File

@ -1,4 +0,0 @@
/node_modules
/dist
/package-lock.json
/yarn.lock

View File

@ -1,22 +0,0 @@
src
test
typings
bundled
build
coverage
docs
wiki
gulpfile.js
bower.json
karma.conf.js
tsconfig.json
typings.json
CONTRIBUTING.md
ISSUE_TEMPLATE.md
PULL_REQUEST_TEMPLATE.md
tslint.json
wallaby.js
.travis.yml
.gitignore
.vscode
type_definitions

1
packages/bukkit/.npmignore Symbolic link
View File

@ -0,0 +1 @@
../../.npmignore

View File

@ -1,7 +1,7 @@
{
"name": "@ms/bukkit",
"version": "0.0.0",
"description": "MiaoScript api package",
"name": "@ccms/bukkit",
"version": "0.7.0",
"description": "MiaoScript bukkit package",
"keywords": [
"miaoscript",
"minecraft",
@ -12,23 +12,20 @@
"homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC",
"main": "dist/index.js",
"publishConfig": {
"registry": "https://repo.yumc.pw/repository/npm/"
},
"scripts": {
"clean": "rimraf dist",
"watch": "npx tsc --watch",
"build": "yarn clean && npx tsc",
"watch": "tsc --watch",
"build": "yarn clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1"
},
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.0",
"typescript": "^3.6.2"
"rimraf": "^3.0.2",
"typescript": "^3.9.2"
},
"dependencies": {
"@ms/api": "^0.0.0",
"@ms/common": "^0.0.0",
"@ms/container": "^0.0.0"
"@ccms/api": "^0.7.0",
"@ccms/common": "^0.7.0",
"@ccms/container": "^0.7.0"
}
}

View File

@ -0,0 +1,28 @@
import { channel, plugin } from '@ccms/api'
import { inject, provideSingleton } from '@ccms/container'
const Bukkit = org.bukkit.Bukkit
const PluginMessageListener = Java.type("org.bukkit.plugin.messaging.PluginMessageListener")
const Messenger = Bukkit.getMessenger()
@provideSingleton(channel.Channel)
export class BukkitChannel extends channel.Channel {
@inject(plugin.PluginInstance)
private pluginInstance: any;
send(player: any, channel: string, data: any) {
player.sendPluginMessage(this.pluginInstance, channel, data);
}
register(channel: string, listener: channel.ChannelListener) {
Messenger.registerIncomingPluginChannel(this.pluginInstance, channel, new PluginMessageListener({
onPluginMessageReceived: (/**String */ channel, /**Player */ player, /**byte[] */data) => {
listener(data, { channel, player, data })
}
}));
Messenger.registerOutgoingPluginChannel(this.pluginInstance, channel);
}
unregister(channel: string, listener: any) {
Messenger.unregisterIncomingPluginChannel(this.pluginInstance, channel)
Messenger.unregisterOutgoingPluginChannel(this.pluginInstance, channel)
}
}

View File

@ -1,16 +1,15 @@
import '@ms/nashorn'
import '@ccms/nashorn'
import { command, plugin } from '@ms/api'
import * as reflect from '@ms/common/dist/reflect'
import { injectable, postConstruct, inject } from '@ms/container'
import { command, plugin } from '@ccms/api'
import * as reflect from '@ccms/common/dist/reflect'
import { provideSingleton, postConstruct, inject } from '@ccms/container'
let Bukkit = Java.type("org.bukkit.Bukkit");
let Arrays = Java.type('java.util.Arrays');
let Bukkit = org.bukkit.Bukkit;
let TabCompleter = Java.type('org.bukkit.command.TabCompleter');
let PluginCommand = Java.type('org.bukkit.command.PluginCommand');
let CommandExecutor = Java.type('org.bukkit.command.CommandExecutor');
@injectable()
@provideSingleton(command.Command)
export class BukkitCommand extends command.Command {
@inject(plugin.PluginInstance)
private pluginInstance: any
@ -18,75 +17,31 @@ export class BukkitCommand extends command.Command {
@postConstruct()
init() {
this.commandMap = reflect.on(Bukkit.pluginManager).get('commandMap').get();
this.commandMap = reflect.on(Bukkit.getPluginManager()).get('commandMap').get();
}
enable(jsp) {
var commands = jsp.description.commands;
if (commands) {
var pluginCommands = [];
for (var name in commands) {
var command = commands[name];
if (typeof command !== 'object') continue;
command.name = name;
var newCmd = this.create(jsp, command);
if (command.description) newCmd.setDescription(command.description);
if (command.usage) newCmd.setUsage(command.usage);
if (command.aliases) newCmd.setAliases(Arrays.asList(command.aliases));
if (command.permission) newCmd.setPermission(command.permission);
if (command['permission-message']) newCmd.setPermissionMessage(command['permission-message']);
pluginCommands.push(newCmd);
console.debug(`插件 ${jsp.description.name} 注册命令 ${name} ...`);
}
this.commandMap.registerAll(jsp.description.name, Arrays.asList(pluginCommands));
}
}
disable(jsp) {
var commands = jsp.description.commands;
if (commands) {
for (var name in commands) {
//TODO 删除插件命令
}
}
}
create(jsp, command) {
var cmd = this.commandMap.getCommand(command.name)
create(plugin: any, command: string) {
var cmd = this.commandMap.getCommand(command)
if (cmd && cmd instanceof PluginCommand) { return cmd };
cmd = reflect.on(PluginCommand).create(command.name, this.pluginInstance).get();
this.commandMap.register(jsp.description.name, cmd);
cmd = reflect.on(PluginCommand).create(command, this.pluginInstance).get();
this.commandMap.register(plugin.description.name, cmd);
return cmd;
}
onCommand(jsp, c, cmd) {
remove(plugin: any, command: string) {
var cmd = this.commandMap.getCommand(command)
if (cmd && cmd instanceof PluginCommand) {
cmd.unregister(this.commandMap);
}
}
onCommand(plugin: any, command: any, executor: Function) {
// 必须指定需要实现的接口类型 否则MOD服会报错
c.setExecutor(new CommandExecutor({
onCommand: function(sender, _, command, args) {
try {
return cmd(sender, command, Java.from(args));
} catch (ex) {
console.console(`§6玩家 §a${sender.name} §6执行 §b${jsp.description.name} §6插件 §d${command} ${Java.from(args).join(' ')} §6命令时发生异常 §4${ex}`);
console.ex(ex);
}
}
command.setExecutor(new CommandExecutor({
onCommand: super.setExecutor(plugin, command, executor)
}));
}
onTabComplete(jsp, c, tab) {
onTabComplete(plugin: any, command: any, tabCompleter: Function) {
// 必须指定需要实现的接口类型 否则MOD服会报错
// noinspection JSUnusedGlobalSymbols
c.setTabCompleter(new TabCompleter({
onTabComplete: function(sender, _, command, args) {
try {
var token = args[args.length - 1];
var complete = tab(sender, command, Java.from(args)) || [];
return Arrays.asList(complete.copyPartialMatches(token, []));
} catch (ex) {
console.console(`§6玩家 §a${sender.name} §6执行 §b${jsp.description.name} §6插件 §d${command} ${Java.from(args).join(' ')} §6补全时发生异常 §4${ex}`);
console.ex(ex);
}
}
command.setTabCompleter(new TabCompleter({
onTabComplete: super.setTabCompleter(plugin, command, tabCompleter)
}));
}
}
}

View File

@ -1,21 +1,20 @@
import { MiaoScriptConsole } from '@ms/api'
import { MiaoScriptConsole } from '@ccms/api'
let Bukkit = Java.type("org.bukkit.Bukkit");
let CommandSender = Java.type("org.bukkit.command.CommandSender");
let Bukkit = org.bukkit.Bukkit;
export class BukkitConsole extends MiaoScriptConsole {
sender(sender, ...args) {
if (!(sender instanceof CommandSender)) {
this.error("第一个参数未实现 org.bukkit.command.CommandSender 无法发送消息!")
if (!(sender instanceof Java.type('org.bukkit.command.CommandSender'))) {
this.error(`First parameter ${sender} not instanceof org.bukkit.command.CommandSender can't send message!`)
return;
}
if (args[0].toString() === "[object Array]") {
if (Object.prototype.toString.call(args[0]) === "[object Array]") {
args[0].forEach(line => sender.sendMessage(this.prefix + line))
} else {
sender.sendMessage(this.prefix + args.join(' '));
}
}
console(...args): void {
this.sender(Bukkit.consoleSender, args.join(' '));
console(...args: string[]): void {
this.sender(Bukkit.getConsoleSender(), args.join(' '));
}
}

View File

@ -0,0 +1,114 @@
/*global Java, base, module, exports, require*/
var nmsChatSerializerClass;
var nmsChatSerializerMethod;
var packetTypeConstructor;
var nmsChatMessageTypeClass;
var chatMessageTypes;
var RemapUtils;
var playerConnectionFieldName;
var sendPacketMethod;
var downgrade = false;
/**
* NMS
*/
//@ts-ignore
var nmsVersion = org.bukkit.Bukkit.server.class.name.split('.')[3];
/**
* NMS
*/
function nmsCls(name) {
return base.getClass(['net.minecraft.server', nmsVersion, name].join('.'))
}
function remapMethod(clazz: any, origin: string, test: string, params) {
try {
return clazz.getMethod(origin, params)
} catch (ex) {
if (RemapUtils) {
return clazz.getMethod(RemapUtils.mapMethod(clazz, origin, params), params)
} else {
return clazz.getMethod(test, params)
}
}
}
function remapFieldName(clazz: any, origin: string, test: string) {
try {
return clazz.getField(origin)
} catch (ex) {
if (RemapUtils) {
return clazz.getField(RemapUtils.mapFieldName(clazz, origin))
} else {
return clazz.getField(test)
}
}
}
function init() {
try {
RemapUtils = Java.type('catserver.server.remapper.RemapUtils');
} catch (ex) {
}
nmsChatSerializerClass = nmsCls(nmsVersion.split("_")[1] > 7 ? "IChatBaseComponent$ChatSerializer" : "ChatSerializer");
nmsChatSerializerMethod = remapMethod(nmsChatSerializerClass, 'a', 'func_150699_a', base.getClass('java.lang.String'))
var packetTypeClass = nmsCls("PacketPlayOutChat");
Java.from(packetTypeClass.constructors).forEach(function(c) {
if (c.parameterTypes.length === 2) {
packetTypeConstructor = c
}
});
nmsChatMessageTypeClass = packetTypeConstructor.parameterTypes[1];
if (nmsChatMessageTypeClass.isEnum()) {
chatMessageTypes = nmsChatMessageTypeClass.getEnumConstants();
} else {
switch (nmsChatMessageTypeClass.name) {
case "int":
//@ts-ignore
nmsChatMessageTypeClass = java.lang.Integer;
break;
case "byte":
//@ts-ignore
nmsChatMessageTypeClass = java.lang.Byte;
break;
}
}
var entityPlayerClass = nmsCls('EntityPlayer');
var packetClass = nmsCls('Packet');
var playerConnectionField = remapFieldName(entityPlayerClass, 'playerConnection', 'field_71135_a')
playerConnectionFieldName = playerConnectionField.getName()
sendPacketMethod = remapMethod(playerConnectionField.getType(), 'sendPacket', 'func_179290_a', packetClass)
}
function json(sender, json) {
if (downgrade) {
return '/tellraw ' + sender.name + ' ' + json
} else {
send(sender, json, 0);
return false;
}
}
function send(sender, json, type) {
//@ts-ignore
sendPacket(sender, packetTypeConstructor.newInstance(nmsChatSerializerMethod.invoke(null, json), chatMessageTypes == null ? nmsChatMessageTypeClass.valueOf(java.lang.String.valueOf(type)) : chatMessageTypes[type]))
}
function sendPacket(player, p) {
sendPacketMethod.invoke(player.handle[playerConnectionFieldName], p)
}
try {
init();
} catch (ex) {
org.bukkit.Bukkit.getConsoleSender().sendMessage(`§6[§cMS§6][§bbukkit§6][§achat§6] §cNMS Inject Error §4${ex} §cDowngrade to Command Mode...`)
downgrade = true;
}
let chat = {
json
}
export default chat

View File

@ -0,0 +1,48 @@
import { event, plugin } from '@ccms/api'
import { inject, provideSingleton } from '@ccms/container';
import * as reflect from '@ccms/common/dist/reflect'
const Bukkit = Java.type("org.bukkit.Bukkit");
const Event = Java.type("org.bukkit.event.Event");
const Modifier = Java.type("java.lang.reflect.Modifier");
const Listener = Java.type("org.bukkit.event.Listener");
const EventPriority = Java.type("org.bukkit.event.EventPriority");
const EventExecutor = Java.type("org.bukkit.plugin.EventExecutor");
@provideSingleton(event.Event)
export class BukkitEvent extends event.Event {
@inject(plugin.PluginInstance)
private pluginInstance: any
constructor() {
super('org/bukkit/event');
}
getJarFile(resource: string) {
return super.getJarFile('org/bukkit/Bukkit.class', Bukkit.class.classLoader)
}
isValidEvent(clazz: any): boolean {
// 继承于 org.bukkit.event.Event
return Event.class.isAssignableFrom(clazz) &&
// 访问符为Public
Modifier.isPublic(clazz.getModifiers()) &&
// 不是抽象类
!Modifier.isAbstract(clazz.getModifiers());
}
register(eventCls: any, exec: Function, priority: event.EventPriority, ignoreCancel: boolean) {
let listener = new Listener({});
Bukkit.pluginManager.registerEvent(
eventCls,
listener,
EventPriority[priority],
new EventExecutor({
execute: exec
}),
this.pluginInstance,
ignoreCancel);
return listener;
}
unregister(event: any, listener: any): void {
reflect.on(event).call('getHandlerList').get().unregister(listener);
}
}

View File

@ -1,14 +1,15 @@
import { server, plugin, command } from '@ms/api'
import { DefaultContainer as container } from '@ms/container'
/// <reference types="@ccms/types/dist/typings/bukkit" />
import { BukkitConsole } from './console'
import { BukkitCommand } from './command';
import { server } from '@ccms/api'
import { Container } from '@ccms/container'
let BukkitServerType = 'bukkit';
let Bukkit = Java.type("org.bukkit.Bukkit");
import { BukkitConsole } from './console';
import './event';
import './server';
import './command';
import './channel';
import './task';
container.bind(server.Console).toConstantValue(BukkitConsole);
container.bind(server.ServerType).toConstantValue(BukkitServerType);
container.bind(plugin.PluginInstance).toConstantValue(Bukkit.pluginManager.getPlugin('MiaoScript'));
container.bind(command.Command).to(BukkitCommand).inSingletonScope();
export default function BukkitImpl(container: Container) {
container.bind(server.Console).toConstantValue(BukkitConsole);
}

View File

@ -0,0 +1,66 @@
import { server, constants } from '@ccms/api'
import { provideSingleton } from '@ccms/container';
import * as reflect from '@ccms/common/dist/reflect'
import chat from './enhance/chat'
let Bukkit = org.bukkit.Bukkit;
@provideSingleton(server.Server)
export class BukkitServer extends server.ReflectServer {
private pluginsFolder: string;
constructor() {
super();
this.pluginsFolder = Bukkit.getUpdateFolderFile().getParentFile().getCanonicalPath();
}
getPlayer(name: string) {
return Bukkit.getPlayer(name)
}
getVersion(): string {
return Bukkit.getVersion()
}
getOnlinePlayers() {
return Bukkit.getOnlinePlayers() as unknown as any[]
}
getConsoleSender() {
return Bukkit.getConsoleSender()
}
getService(service: string) {
return Bukkit.getServicesManager().getRegistration(base.getClass(service))?.getProvider()
}
dispatchCommand(sender: string | any, command: string): boolean {
if (typeof sender === 'string') {
sender = this.getPlayer(sender)
}
return Bukkit.dispatchCommand(sender, command)
}
dispatchConsoleCommand(command: string): boolean {
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command)
}
getPluginsFolder(): string {
return this.pluginsFolder;
}
getNativePluginManager() {
return Bukkit.getPluginManager() as any;
}
getDedicatedServer() {
return reflect.on(Bukkit.getServer()).get('console').get()
}
getNettyPipeline() {
return this.pipeline;
}
getRootLogger() {
return this.rootLogger;
}
sendJson(sender: string | any, json: object | string): void {
if (typeof sender === "string") {
sender = this.getPlayer(sender)
}
let result = chat.json(sender, json)
if (result !== false) {
this.dispatchConsoleCommand(result)
}
}
}

View File

@ -0,0 +1,35 @@
import { task, plugin } from '@ccms/api'
import { inject, provideSingleton } from '@ccms/container';
const Bukkit = Java.type('org.bukkit.Bukkit');
const BukkitRunnable = Java.type('org.bukkit.scheduler.BukkitRunnable');
const Callable = Java.type('java.util.concurrent.Callable')
@provideSingleton(task.TaskManager)
export class BukkitTaskManager implements task.TaskManager {
@inject(plugin.PluginInstance)
private pluginInstance: any;
create(func: Function): task.Task {
if (Object.prototype.toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !'); };
return new BukkitTask(this.pluginInstance, func);
}
callSyncMethod(func: Function): any {
return Bukkit.getScheduler().callSyncMethod(this.pluginInstance, new Callable({ call: () => func() })).get()
}
disable() {
Bukkit.getScheduler().cancelTasks(this.pluginInstance);
}
}
export class BukkitTask extends task.Task {
submit(...args: any[]): task.Cancelable {
let run = new BukkitRunnable({ run: () => this.run(...args) })
let funcName = `runTask${this.interval ? 'Timer' : 'Later'}${this.isAsync ? 'Asynchronously' : ''}`
if (this.interval) {
return run[funcName](this.plugin, this.laterTime, this.interval)
} else {
return run[funcName](this.plugin, this.laterTime)
}
}
}

1
packages/bungee/.npmignore Symbolic link
View File

@ -0,0 +1 @@
../../.npmignore

View File

@ -0,0 +1,31 @@
{
"name": "@ccms/bungee",
"version": "0.7.0",
"description": "MiaoScript bungee package",
"keywords": [
"miaoscript",
"minecraft",
"bukkit",
"sponge"
],
"author": "MiaoWoo <admin@yumc.pw>",
"homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC",
"main": "dist/index.js",
"scripts": {
"clean": "rimraf dist",
"watch": "tsc --watch",
"build": "yarn clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1"
},
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.9.2"
},
"dependencies": {
"@ccms/api": "^0.7.0",
"@ccms/common": "^0.7.0",
"@ccms/container": "^0.7.0"
}
}

View File

@ -0,0 +1,25 @@
import { channel, event } from '@ccms/api'
import { provideSingleton, inject } from '@ccms/container'
const Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy()
@provideSingleton(channel.Channel)
export class BungeeChannel extends channel.Channel {
@inject(event.Event)
private eventManager: event.Event;
send(player: any, channel: string, data: any) {
throw new Error("Method not implemented.");
}
register(channel: string, listener: channel.ChannelListener) {
Bungee.registerChannel(channel);
// console.console('§6[§eWARN§6] §eMiaoScript channel in BungeeCord only register. you need self hanler PluginMessageEvent!')
return this.eventManager.listen({ description: { name: channel } }, "PluginMessageEvent", (event: net.md_5.bungee.api.event.PluginMessageEvent) => {
listener(event.getData(), event)
})
}
unregister(channel: string, listener: any) {
Bungee.unregisterChannel(channel);
listener.off();
}
}

View File

@ -0,0 +1,65 @@
import { command, plugin } from "@ccms/api";
import { inject, provideSingleton } from "@ccms/container";
const Arrays = Java.type('java.util.Arrays')
const Command = Java.extend(Java.type('net.md_5.bungee.api.plugin.Command'), Java.type('net.md_5.bungee.api.plugin.TabExecutor'));
const createCommand = eval(`
function(cls, name, exec, tab){
return new cls(name) {
execute: exec,
onTabComplete: tab
}
}
`)
@provideSingleton(command.Command)
export class BungeeCommand extends command.Command {
@inject(plugin.PluginInstance)
private pluginInstance: any;
private pluginManager: net.md_5.bungee.api.plugin.PluginManager = base.getInstance().getProxy().getPluginManager();
private commandMapping: any[] = [];
create(plugin: any, command: string) {
let commandKey = this.getCommandKey(plugin, command);
let commandCallable = new SimpleCommand(command);
this.pluginManager.registerCommand(this.pluginInstance, commandCallable.callable)
this.commandMapping[commandKey] = commandCallable.callable;
return commandCallable;
}
remove(plugin: any, command: string) {
var commandKey = this.getCommandKey(plugin, command);
if (this.commandMapping[commandKey]) {
this.pluginManager.unregisterCommand(this.commandMapping[commandKey])
delete this.commandMapping[commandKey];
}
}
onCommand(plugin: any, command: any, executor: Function) {
command.setExecutor(super.setExecutor(plugin, command, executor));
}
onTabComplete(plugin: any, command: any, tabCompleter: Function) {
command.setTabComplete(super.setTabCompleter(plugin, command, tabCompleter))
}
private getCommandKey(plugin: any, command: string) {
return plugin.description.name.toLowerCase() + ":" + command;
}
}
class SimpleCommand {
public callable: any;
private name: string;
private executor: Function;
private tabComplete: Function = () => [];
constructor(command: string) {
this.name = command;
this.callable = createCommand(Command, command,
(sender, args) => this.executor(sender, '', command, args),
(sender, args) => Arrays.asList(this.tabComplete(sender, '', command, args))
);
}
setExecutor = (executor: Function) => this.executor = executor;
setTabComplete = (tabComplete: Function) => this.tabComplete = tabComplete;
toString = () => `Bungee SimpleCommand(${this.name})`
}

View File

@ -0,0 +1,27 @@
import '@ccms/nashorn'
import { plugin, MiaoScriptConsole } from '@ccms/api'
import { inject, injectable } from "@ccms/container";
let CommandSender = Java.type("net.md_5.bungee.api.CommandSender")
@injectable()
export class BungeeConsole extends MiaoScriptConsole {
@inject(plugin.PluginInstance)
private pluginInstance: any
private proxyServer: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy();
sender(sender, ...args) {
if (!(sender instanceof CommandSender)) {
this.error('第一个参数未实现 net.md_5.bungee.api.CommandSender 无法发送消息!')
return
}
if (Object.prototype.toString.call(args[0]) === '[object Array]') {
args[0].forEach(line => sender.sendMessage(this.prefix + line))
} else {
sender.sendMessage(this.prefix + args.join(' '));
}
}
console(...args): void {
this.sender(this.proxyServer.getConsole(), args.join(' '));
}
}

View File

@ -0,0 +1,117 @@
import { event } from '@ccms/api'
import { provideSingleton, postConstruct } from '@ccms/container'
import * as reflect from '@ccms/common/dist/reflect'
const Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy();
const Event = Java.type("net.md_5.bungee.api.plugin.Event");
const Modifier = Java.type("java.lang.reflect.Modifier");
const ProxyClass = Java.type(base.getProxyClass().name);
const ProxyMethod = reflect.on(base.getProxyClass()).method("method");
const HashMap = Java.type('java.util.HashMap');
const ReflectMethodArray = Java.type('java.lang.reflect.Method[]');
const Byte = Java.type('java.lang.Byte');
const EventPriority = [];
EventPriority[event.EventPriority.LOWEST] = Byte.valueOf(-64);
EventPriority[event.EventPriority.LOW] = -Byte.valueOf(32);
EventPriority[event.EventPriority.NORMAL] = Byte.valueOf(0);
EventPriority[event.EventPriority.HIGH] = Byte.valueOf(32);
EventPriority[event.EventPriority.HIGHEST] = Byte.valueOf(64);
/**
* Bungee Event Impl
*/
@provideSingleton(event.Event)
export class BungeeEvent extends event.Event {
private pluginManager = Bungee.getPluginManager()
// EventBus
private eventBus: any;
// private final Lock lock = new ReentrantLock();
private lock: any;
// private final Map<Class<?>, Map<Byte, Map<Object, Method[]>>> byListenerAndPriority = new HashMap<>();
private byListenerAndPriority: any;
// bakeHandlers(Class<?> eventClass)
private bakeHandlers: any;
constructor() {
super('net/md_5/bungee/api/event');
}
@postConstruct()
init() {
this.eventBus = reflect.on(this.pluginManager).get('eventBus').get();
this.lock = reflect.on(this.eventBus).get('lock').get()
this.byListenerAndPriority = reflect.on(this.eventBus).get('byListenerAndPriority').get();
this.bakeHandlers = reflect.accessible(reflect.on(this.eventBus).method("bakeHandlers"));
}
isValidEvent(clazz: any): boolean {
//继承于 net.md_5.bungee.api.plugin.Event
return Event.class.isAssignableFrom(clazz) &&
// 访问符为Public
Modifier.isPublic(clazz.getModifiers()) &&
// 不是抽象类
!Modifier.isAbstract(clazz.getModifiers());
}
register(eventCls: any, exec: Function, priority: event.EventPriority = event.EventPriority.NORMAL, ignoreCancel: boolean = true) {
this.lock.lock()
try {
// private final Map<类, Map<优先级, Map<监听器, 方法[]>>> byListenerAndPriority = new HashMap<>();
// this.byListenerAndPriority.put(eventCls)
// Map<优先级, Map<监听器, 方法[]>>
let prioritiesMap = this.byListenerAndPriority.get(eventCls);
if (prioritiesMap == null) {
prioritiesMap = new HashMap();
this.byListenerAndPriority.put(eventCls, prioritiesMap);
}
// Map<监听器, 方法[]>
let currentPriorityMap = prioritiesMap.get(EventPriority[priority]);
if (currentPriorityMap == null) {
currentPriorityMap = new HashMap();
prioritiesMap.put(EventPriority[priority], currentPriorityMap);
}
let listener = new ProxyClass(ScriptEngineContextHolder.getEngine(), "exec(args)", { exec, priority: EventPriority[priority] })
// 方法[]
let methods = new ReflectMethodArray(1);
methods[0] = ProxyMethod;
currentPriorityMap.put(listener, methods);
this.bakeHandlers.invoke(this.eventBus, eventCls);
return listener;
} catch (ex) {
console.ex(ex)
} finally {
this.lock.unlock()
}
}
unregister(eventCls: any, listener: any): void {
this.lock.lock()
try {
// private final Map<类, Map<优先级, Map<监听器, 方法[]>>> byListenerAndPriority = new HashMap<>();
// Map<优先级, Map<监听器, 方法[]>>
let prioritiesMap = this.byListenerAndPriority.get(eventCls);
if (prioritiesMap != null) {
let bindings = reflect.on(listener).get("bindings").get();
let priority = bindings["priority"];
// Map<监听器, 方法[]>
let currentPriorityMap = prioritiesMap.get(priority);
if (currentPriorityMap != null) {
currentPriorityMap.remove(listener);
if (currentPriorityMap.isEmpty()) {
prioritiesMap.remove(priority);
}
}
if (prioritiesMap.isEmpty()) {
this.byListenerAndPriority.remove(eventCls);
}
this.bakeHandlers.invoke(this.eventBus, eventCls);
}
} catch (ex) {
console.ex(ex)
} finally {
this.lock.unlock()
}
}
}

View File

@ -0,0 +1,15 @@
/// <reference types="@ccms/types/dist/typings/bungee" />
import { server } from '@ccms/api'
import { Container } from '@ccms/container'
import { BungeeConsole } from './console';
import './event';
import './server';
import './command';
import './channel';
import './task';
export default function BungeeImpl(container: Container) {
container.bind(server.Console).toConstantValue(BungeeConsole);
}

View File

@ -0,0 +1,85 @@
import { server, task } from '@ccms/api'
import { provideSingleton, inject, postConstruct } from '@ccms/container'
import * as reflect from '@ccms/common/dist/reflect'
let Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy();
@provideSingleton(server.Server)
export class BungeeServer implements server.Server {
private pluginsFolder: string;
private pipeline: any;
private rootLogger: any;
@inject(task.TaskManager)
private task: task.TaskManager
constructor() {
this.pluginsFolder = Bungee.getPluginsFolder().getCanonicalPath();
}
@postConstruct()
initialize() {
let count = 0;
let wait = this.task.create(() => {
try {
// @ts-ignore
this.pipeline = reflect.on(base.getInstance().getProxy()).get('listeners').get().toArray()[0].pipeline()
wait.cancel();
} catch (ex) {
count++
if (count > 50) {
console.error('Reflect BungeeCord netty channel pipeline error time > 50times. Err: ' + ex)
wait.cancel()
} else {
console.warn('Wait BungeeCord start ready to get netty channel pipeline. Err: ' + ex)
}
}
}).later(10).timer(20).submit()
try {
this.rootLogger = Bungee.getLogger()
} catch (error) {
console.error("Can't found rootLogger!")
}
}
getPlayer(name: string) {
return Bungee.getPlayer(name);
}
getVersion(): string {
return Bungee.getVersion()
}
getOnlinePlayers() {
return Bungee.getPlayers()
}
getConsoleSender() {
return Bungee.getConsole()
}
getService(service: string) {
throw new Error("Method not implemented.");
}
dispatchCommand(sender: string | any, command: string): boolean {
if (typeof sender === 'string') {
sender = this.getPlayer(sender)
}
return Bungee.getPluginManager().dispatchCommand(sender, command)
}
dispatchConsoleCommand(command: string): boolean {
return Bungee.getPluginManager().dispatchCommand(Bungee.getConsole(), command)
}
getPluginsFolder(): string {
return this.pluginsFolder;
}
getNativePluginManager() {
return Bungee.getPluginManager() as any
}
getNettyPipeline() {
return this.pipeline;
}
getRootLogger() {
return this.rootLogger;
}
sendJson(sender: string | any, json: string): void {
throw new Error("Method not implemented.");
}
}

View File

@ -0,0 +1,36 @@
import { task, plugin } from '@ccms/api'
import { inject, provideSingleton } from '@ccms/container';
var Runnable = Java.type('java.lang.Runnable')
let TimeUnit = Java.type('java.util.concurrent.TimeUnit')
@provideSingleton(task.TaskManager)
export class BungeeTaskManager implements task.TaskManager {
@inject(plugin.PluginInstance)
private pluginInstance: any;
create(func: Function): task.Task {
if (Object.prototype.toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !'); };
return new BungeeTask(this.pluginInstance, func);
}
callSyncMethod(func: Function): any {
return func();
}
disable() {
this.pluginInstance.getProxy().getScheduler().cancel(this.pluginInstance)
}
}
export class BungeeTask extends task.Task {
submit(...args: any[]): task.Cancelable {
let run = new Runnable({ run: () => this.run(...args) })
if (this.isAsync) {
return this.plugin.getProxy().getScheduler().runAsync(this.plugin, run)
}
if (this.interval) {
return this.plugin.getProxy().getScheduler().schedule(this.plugin, run, this.laterTime * 50, this.interval * 50, TimeUnit.MILLISECONDS)
} else {
return this.plugin.getProxy().getScheduler().schedule(this.plugin, run, this.laterTime * 50, TimeUnit.MILLISECONDS)
}
}
}

View File

@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "src",
"outDir": "dist",
"allowJs": true
}
}

1
packages/client/.npmignore Symbolic link
View File

@ -0,0 +1 @@
../../.npmignore

View File

@ -0,0 +1,31 @@
{
"private": true,
"name": "@ccms/client",
"version": "0.7.0",
"description": "MiaoScript client package",
"keywords": [
"miaoscript",
"minecraft",
"bukkit",
"sponge"
],
"author": "MiaoWoo <admin@yumc.pw>",
"homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC",
"main": "dist/index.js",
"scripts": {
"dev": "ts-node-dev --respawn --debounce=1500 src/index.ts",
"clean": "rimraf dist",
"watch": "tsc --watch",
"build": "yarn clean && tsc",
"start": "node dist/index.js",
"test": "echo \"Error: run tests from root\" && exit 1"
},
"dependencies": {
"minecraft-protocol": "^1.11.0"
},
"devDependencies": {
"rimraf": "^3.0.2",
"typescript": "^3.9.2"
}
}

View File

@ -0,0 +1,101 @@
class MessagePart {
text: string
color: string
clickEvent: MessagePartEvent
hoverEvent: MessagePartEvent
translate: string
with: MessagePart[]
extra: MessagePart[]
}
class MessagePartEvent {
action: string
value: string
}
var colorMap = []
colorMap['0'] = '38;5;0'
colorMap['1'] = '38;5;4'
colorMap['2'] = '38;5;2'
colorMap['3'] = '38;5;6'
colorMap['4'] = '38;5;1'
colorMap['5'] = '38;5;5'
colorMap['6'] = '38;5;3'
colorMap['7'] = '38;5;7'
colorMap['8'] = '38;5;8'
colorMap['9'] = '38;5;12'
colorMap['a'] = '38;5;10'
colorMap['b'] = '38;5;14'
colorMap['c'] = '38;5;9'
colorMap['d'] = '38;5;13'
colorMap['e'] = '38;5;11'
colorMap['f'] = '38;5;15'
colorMap['r'] = '0'
colorMap['l'] = '1'
colorMap['n'] = '4'
var regexMap = []
for (const c in colorMap) {
regexMap[colorMap[c]] = new RegExp(`§${c}`, "g")
}
function mcColor2ANSI(str) {
for (const regex in regexMap) {
str = str.replace(regexMap[regex], `\u001b[${regex}m`)
}
return str;
}
let jsonColorMap = {
"black": '0',
"dark_blue": '1',
"dark_green": '2',
"dark_aqua": '3',
"dark_red": '4',
"dark_purple": '5',
"gold": '6',
"gray": '7',
"dark_gray": '8',
"blue": '9',
"green": 'a',
"aqua": 'b',
"red": 'c',
"light_purple": 'd',
"yellow": 'e',
"white": 'f',
"obfuscated": 'k',
"bold": 'l',
"strikethrough": 'm',
"underline": 'n',
"italic": 'o',
"reset": 'r',
};
function json2text(json: MessagePart): string {
let temp = "";
if (json.color) {
temp += `§${jsonColorMap[json.color]}`
}
temp += json.text || json.translate || ''
if (json.extra) {
json.extra.forEach((ext) => {
temp += json2text(ext)
})
}
return temp += '§r'
}
function $(input: any) {
if (typeof input === "string") {
input = JSON.parse(input)
}
input = json2text(input) + '§r'
if (input.startsWith('§卐')) {
input = input.substring(2)
}
return mcColor2ANSI(input)
}
export {
json2text,
mcColor2ANSI,
$
}

View File

@ -0,0 +1,27 @@
import { $ } from './color'
export function attachEvents(client) {
client.on('chat', (packet) => {
// Listen for chat messages and echo them back.
var jsonMsg = JSON.parse(packet.message);
console.log($(jsonMsg))
})
client.on('state', (newState, oldState) => {
console.log('Client Change State', oldState, 'to', newState)
let targetServer = process.argv[3]
if (newState == "play" && targetServer) {
setTimeout(() => {
client.write('chat', {
message: '/server ' + targetServer
})
}, 3000)
}
})
client.on('update_health', (packet) => {
if (packet.health <= 0) {
console.log("Player Dead Auto Respawn...")
client.write('client_command', { payload: 0 })
} else if (packet.health > 0) {
}
})
}

View File

@ -0,0 +1,14 @@
export function attachForge(client) {
client.on('custom_payload', function(packet) {
if (packet.channel === 'FML|HS') {
client.write('custom_payload', {
channel: 'FML|HS',
data: Buffer.of(0x01, 0x02)
});
client.write('custom_payload', {
channel: 'FML|HS',
data: Buffer.of(0x02, 0x00)
});
}
});
}

View File

@ -0,0 +1,80 @@
import { createInterface } from 'readline'
import { createClient } from 'minecraft-protocol'
import { attachForge } from './forge'
import { attachEvents } from './event'
let username = process.argv[2] || 'Mr_jtb'
let version = process.argv[3] || '1.12.2'
let address = process.argv[4] || '192.168.2.5:25577'
let realAddress = address.split(":");
let client = createConnection(realAddress[0], parseInt(realAddress[1] || "25565"), username)
function createConnection(host: string, port: number, username: string) {
let client = createClient({
version,
host,
port,
username,
skipValidation: true
})
attachForge(client)
attachEvents(client)
return client;
}
client.on('error', (error) => {
console.log("Client Error", error)
})
client.on('end', (resone) => {
console.log("Client End Resone:", resone)
client = createConnection('192.168.2.5', 25577, username)
})
const rl = createInterface({
input: process.stdin,
output: process.stdout,
completer: (line, func) => {
let args = line.split(' ')
let comp = args[args.length - 1]
client.once('tab_complete', (msg) => {
let mcts = msg.matches.filter(s => s)
func(null, [mcts, comp])
})
client.write('tab_complete', {
text: line
})
},
terminal: true,
prompt: ''
})
rl.on('line', function (line) {
switch (line) {
case "":
break;
case "eval":
break;
case "write":
break;
case "/respawn":
client.write('client_command', { payload: 0 })
break;
case "//reco":
client.end("")
client = createConnection('192.168.2.5', 25577, username)
break;
case "//quit":
console.info('Disconnected')
client.end("")
break;
case "//end":
console.info('Forcibly ended client')
process.exit(0)
default:
client.write('chat', { message: line })
}
rl.prompt()
})

View File

@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "src",
"outDir": "dist"
}
}

View File

@ -1,4 +0,0 @@
/node_modules
/dist
/package-lock.json
/yarn.lock

View File

@ -1,22 +0,0 @@
src
test
typings
bundled
build
coverage
docs
wiki
gulpfile.js
bower.json
karma.conf.js
tsconfig.json
typings.json
CONTRIBUTING.md
ISSUE_TEMPLATE.md
PULL_REQUEST_TEMPLATE.md
tslint.json
wallaby.js
.travis.yml
.gitignore
.vscode
type_definitions

1
packages/common/.npmignore Symbolic link
View File

@ -0,0 +1 @@
../../.npmignore

View File

@ -1,6 +1,6 @@
{
"name": "@ms/common",
"version": "0.0.0",
"name": "@ccms/common",
"version": "0.7.0",
"description": "MiaoScript api package",
"keywords": [
"miaoscript",
@ -12,21 +12,19 @@
"homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC",
"main": "dist/index.js",
"publishConfig": {
"registry": "https://repo.yumc.pw/repository/npm/"
},
"scripts": {
"clean": "rimraf dist",
"watch": "npx tsc --watch",
"build": "yarn clean && npx tsc",
"watch": "tsc --watch",
"build": "yarn clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1"
},
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.0",
"typescript": "^3.6.2"
"rimraf": "^3.0.2",
"typescript": "^3.9.2"
},
"dependencies": {
"@ms/nashorn": "^0.0.0"
}
"@ccms/nashorn": "^0.7.0"
},
"gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027"
}

View File

@ -1,4 +1,4 @@
import '@ms/nashorn'
import '@ccms/nashorn'
/*global Java, base, module, exports, require, __FILE__*/
const Path = Java.type("java.nio.file.Path");
@ -12,8 +12,8 @@ const StandardCopyOption = Java.type("java.nio.file.StandardCopyOption");
/**
*
*/
export function concat() {
return Array.prototype.join.call(arguments, separatorChar);
export function concat(...args: string[]) {
return args.join(separatorChar);
}
/**
@ -23,12 +23,10 @@ export function concat() {
* @returns {*}
*/
export function file(...opts: any[]): any {
if (!arguments[0]) {
console.warn("文件名称不得为 undefined 或者 null !");
}
switch (arguments.length) {
if (!opts[0]) { throw new Error("文件名称不得为 undefined 或者 null !") }
switch (opts.length) {
case 1:
var f = arguments[0];
var f = opts[0];
if (f instanceof File) {
return f;
}
@ -40,7 +38,7 @@ export function file(...opts: any[]): any {
}
break;
default:
return new File(file(arguments[0]), arguments[1]);
return new File(file(opts[0]), opts[1]);
}
}
@ -48,7 +46,7 @@ export function file(...opts: any[]): any {
*
* @param path
*/
export function mkdirs(path) {
export function mkdirs(path: any) {
// noinspection JSUnresolvedVariable
file(path).parentFile.mkdirs();
}
@ -57,7 +55,7 @@ export function mkdirs(path) {
*
* @param file
*/
export function create(path) {
export function create(path: any) {
var f = file(path);
if (!f.exists()) {
mkdirs(f);
@ -70,7 +68,7 @@ export function create(path) {
* @param file
* @returns {*}
*/
export function path(f) {
export function path(f: any) {
return file(f).canonicalPath;
}
@ -80,7 +78,7 @@ export function path(f) {
* @param target
* @param override
*/
export function copy(inputStream, target, override) {
export function copy(inputStream: any, target: any, override: any) {
Files.copy(inputStream, target.toPath(), StandardCopyOption[override ? 'REPLACE_EXISTING' : 'ATOMIC_MOVE']);
}
@ -143,7 +141,7 @@ export function del(file) {
return;
}
if (file.isDirectory()) {
Files.list(file.toPath()).collect(Collector.toList()).forEach(function(f) {
Files.list(file.toPath()).collect(Collector.toList()).forEach(function (f) {
del(f);
})
}

View File

@ -1,155 +1,54 @@
'use strict';
/**
* HTTP
* Created by on 2017/2/9 0009.
*/
const URL = Java.type('java.net.URL')
const Paths = Java.type('java.nio.file.Paths');
const Files = Java.type('java.nio.file.Files');
const StandardCopyOption = Java.type('java.nio.file.StandardCopyOption');
/*global Java, base, module, exports, require, __FILE__*/
export type Method =
| 'get' | 'GET'
| 'delete' | 'DELETE'
| 'head' | 'HEAD'
| 'options' | 'OPTIONS'
| 'post' | 'POST'
| 'put' | 'PUT'
| 'patch' | 'PATCH'
var URL = Java.type("java.net.URL");
var UUID = Java.type("java.util.UUID");
var System = Java.type("java.lang.System");
var Files = Java.type("java.nio.file.Files");
var Paths = Java.type("java.nio.file.Paths");
var JavaString = Java.type("java.lang.String");
var SecureRandom = Java.type("java.security.SecureRandom");
var SSLContext = Java.type("javax.net.ssl.SSLContext");
var HttpsURLConnection = Java.type("javax.net.ssl.HttpsURLConnection");
var HostnameVerifier = Java.type("javax.net.ssl.HostnameVerifier");
var X509TrustManager = Java.type("javax.net.ssl.X509TrustManager");
// noinspection JSUnusedGlobalSymbols,JSUnusedLocalSymbols
var TrustAnyHostnameVerifier = new HostnameVerifier({
verify: function(hostname, session) {
return true;
}
});
var SSLSocketFactory = function initSSLSocketFactory() {
var sslContext = SSLContext.getInstance("TLS");
// noinspection JSUnusedGlobalSymbols
sslContext.init(null, [new X509TrustManager({
getAcceptedIssuers: function() {
return null;
},
checkClientTrusted: function(chain, authType) {
},
checkServerTrusted: function(chain, authType) {
}
})], new SecureRandom());
return sslContext.getSocketFactory();
}();
var config = {
Charset: 'UTF-8',
ConnectTimeout: 10000,
ReadTimeout: 10000,
Debug: false
};
function open(url, method, header) {
// conn.setRequestProperty
var conn = new URL(url).openConnection();
if (conn instanceof HttpsURLConnection) {
conn.setHostnameVerifier(TrustAnyHostnameVerifier);
conn.setSSLSocketFactory(SSLSocketFactory);
}
conn.setRequestMethod(method);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setConnectTimeout(config.ConnectTimeout);
conn.setReadTimeout(config.ReadTimeout);
if (header) {
for (var key in header) {
// noinspection JSUnfilteredForInLoop
conn.setRequestProperty(key, header[key]);
}
}
return conn;
interface RequestConfig {
url?: string;
method?: Method;
headers?: { [key: string]: string };
params?: { [key: string]: string };
data?: any;
}
function buildUrl(url, params) {
if (params && Object.keys(params).length > 0) {
var queryStart = url.indexOf('?');
if (queryStart === -1) {
url += '?';
}
return url += object2URLSearchParams(params);
function request(config: RequestConfig) {
// @ts-ignore
let xhr = new XMLHttpRequest();
xhr.open(config.method, config.url, false);
for (const header in config.headers) {
xhr.setRequestHeader(header, config.headers[header]);
}
return url;
xhr.send(typeof config.data === "string" ? config.data : JSON.stringify(config.data));
if ((xhr.getResponseHeader("Content-Type") + '').indexOf('application/json') != -1) {
xhr.responseType = "json"
}
return xhr.get();
}
function request(config) {
var conn = open(buildUrl(config.url, config.query), config.method, config.header);
try {
conn.connect();
var data = config.data;
if (data) {
var out = conn.getOutputStream();
if (typeof data === "object") {
var type = config.header['Content-Type'];
switch (type) {
case "application/x-www-form-urlencoded":
data = object2URLSearchParams(data);
break;
default:
data = JSON.stringify(data)
}
}
out.write(new JavaString(data).getBytes(config.Charset));
out.flush();
out.close();
}
return response(conn);
} finally {
conn.disconnect();
function download(url: string, target: string) {
console.debug(`Start Download file ${target} from ${url}....`)
Files.copy(new URL(url).openStream(), Paths.get(target), StandardCopyOption.REPLACE_EXISTING);
console.debug(`File ${target} Download Complate...`)
}
function _proxy(method: Method) {
return function (url: string, data?: any, config?: RequestConfig) {
return request({ url, method, data, ...config });
}
}
function response(conn) {
var temp = Paths.get(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
Files.copy(conn.getInputStream(), temp);
var result = new JavaString(Files.readAllBytes(temp), config.Charset);
var tempFile = temp.toFile();
tempFile.delete() || tempFile.deleteOnExit();
return result;
export default {
get: _proxy('GET'),
post: _proxy('POST'),
request,
download
}
function object2URLSearchParams(params) {
var temp: string[] = [];
for (var key in params) {
temp.push(`${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
}
return temp.join('&')
}
var http = {
config: config,
request: request
};
['GET', 'DELETE', 'HEAD', 'OPTIONS'].forEach(function(method) {
http[method.toLowerCase()] = function __likeGet__(url, data, config = {}) {
return this.request({
...config,
url: url,
method: method,
query: data
});
}
});
['POST', 'PUT', 'PATCH'].forEach(function(method) {
http[method.toLowerCase()] = function __likePost__(url, data, config) {
return this.request({
...config,
url: url,
method: method,
data: data
});
}
});
export = http;

View File

@ -1,186 +1,204 @@
import '@ms/core'
/// <reference types="@ccms/types/dist/typings/jdk" />
/**
*
* Created by on 2017/2/9 0009.
* Created by MiaoWoo on 2017/2/9 0009.
*/
var JavaClass = Java.type('java.lang.Class');
var JavaObject = Java.type('java.lang.Object')
var NoSuchFieldException = Java.type('java.lang.NoSuchFieldException');
var methodCache = [];
const JavaClass = Java.type('java.lang.Class')
const JavaObject = Java.type('java.lang.Object')
const NoSuchFieldException = Java.type('java.lang.NoSuchFieldException')
const methodCache = []
class Reflect {
private obj: any;
private class: any
private obj: java.lang.Object
private class: java.lang.Class
constructor(obj: any) {
// if (obj === undefined || obj === null) { throw Error(`reflect object can't be ${obj}!`) }
if (obj instanceof JavaClass) {
this.obj = null;
this.class = obj;
this.obj = null
this.class = obj
} else {
this.obj = obj;
this.class = obj.class;
this.obj = obj
if (obj !== null && obj !== undefined && obj.class) {
this.class = obj.class
}
}
}
method(...args: any[]) {
return declaredMethod(this.class, args[0], types(args.slice(1)));
method(name: string, ...args: any[]) {
return declaredMethod(this.class, name, args)
}
methods() {
return Java.from(declaredMethods(this.class));
return Java.from(declaredMethods(this.class))
}
field(name) {
field(name: string | java.lang.String): Reflect {
try {
// Try getting a public field
var field = this.class.field(name);
return on(field.get(this.obj));
let field = this.class.getField(name)
return on(field.get(this.obj))
} catch (ex) {
// Try again, getting a non-public field
return on(accessible(declaredField(this.class, name)).get(this.obj));
return on(accessible(declaredField(this.class, name)).get(this.obj))
}
};
fields(declared) {
return Java.from(declared ? this.class.declaredFields : this.class.fields);
}
values(declared) {
var cache = {};
var feds = declared ? this.class.declaredFields : this.class.fields;
Java.from(feds).forEach(function(fed) {
cache[fed.name] = this.field(fed.name).get();
}.bind(this))
return cache;
fields(declared = false): java.lang.reflect.Field[] {
return Java.from(declared ? this.class.getDeclaredFields() : this.class.getFields())
}
call(...args) {
var params = args.slice(1);
var method = declaredMethod(this.class, args[0], types(params));
return on(method.invoke(this.get(), params));
};
values(declared = false) {
return this.fields(declared).reduce((cache, field) => { return cache[field.getName()] = this.field(field.getName()).get() }, {}) as any
}
get(...args) {
return args.length === 1 ? this.field(args[0]) : this.obj;
};
call(...args: any[]): Reflect {
let params = args.slice(1)
let method = accessible(declaredMethod(this.class, args[0], ...types(params)))
let result = method.invoke(this.get(), params)
return result && on(result)
}
// noinspection JSUnusedGlobalSymbols
set(name, value) {
accessible(declaredField(this.class, name)).set(this.obj, value);
return this;
};
get(): any
get(index: number, declared?: boolean): Reflect
get(prop: string): Reflect
get(param?: string | number, declared: boolean = true): Reflect | any {
if (param == undefined || param == null) return this.obj
if (typeof param == "number") {
return on(accessible(this.fields(declared)[param]).get(this.obj))
}
if (typeof param == "string") {
return this.field(param)
}
}
create(...args) {
return on(declaredConstructor(this.class, args).newInstance(args));
};
set(name: any, value: any): Reflect {
accessible(declaredField(this.class, name)).set(this.obj, value)
return this
}
create(...args): Reflect {
return on(declaredConstructor(this.class, args).newInstance(args))
}
}
/**
* Get an array of types for an array of objects
*/
function types(values, def?) {
function types(values: any[], def?: any) {
if (values === null) {
return [];
return []
}
var result = [];
values.forEach(t => result.push((t || def) ? JavaObject.class : t instanceof JavaClass ? t : t.class));
return result;
let result: java.lang.Class[] = []
values.forEach(t => result.push((t || def) ? JavaObject.class : t instanceof JavaClass ? t : t.class))
return result
}
function accessible(accessible) {
function accessible<T extends java.lang.reflect.AccessibleObject>(accessible: T): T {
if (accessible === null) {
return null;
return null
}
if (!accessible.isAccessible()) {
accessible.setAccessible(true);
accessible.setAccessible(true)
}
return accessible;
return accessible
}
function declaredConstructor(clazz, param) {
var constructor;
let constructor
try {
constructor = clazz.getDeclaredConstructor(types(param));
constructor = clazz.getDeclaredConstructor(types(param))
} catch (ex) {
try {
constructor = clazz.getDeclaredConstructor(types(param, true));
constructor = clazz.getDeclaredConstructor(types(param, true))
} catch (ex) {
constructor = clazz.getDeclaredConstructors()[0];
constructor = clazz.getDeclaredConstructors()[0]
}
}
return accessible(constructor);
return accessible(constructor)
}
function declaredField(clazz, name) {
var field = null;
function declaredField(clazz: java.lang.Class, name: string | java.lang.String) {
if (!clazz) { throw Error(`target class can't be ${clazz}!`) }
let target = clazz
let field = null
// noinspection JSUnresolvedVariable
while (clazz !== JavaObject.class) {
while (target !== JavaObject.class) {
try {
field = clazz.getDeclaredField(name);
if (field !== null) {
break;
}
field = target.getDeclaredField(name)
if (field !== null) { break }
} catch (e) {
clazz = clazz.getSuperclass();
if (target === undefined) { break }
target = target.getSuperclass()
}
}
if (field === null) {
throw new NoSuchFieldException(name + " is not found in " + clazz.name);
throw new NoSuchFieldException(name + " is not found in " + clazz.getName())
}
return field;
return field
}
function declaredMethod(clazz, name, clazzs) {
var key = clazz.name + '.' + name + ':' + (clazzs || []).join(':');
function declaredMethod(clazz: java.lang.Class, name: string, ...clazzs: any[]): java.lang.reflect.Method {
let key = clazz.getName() + '.' + name + ':' + (clazzs || []).join(':')
if (!methodCache[key]) {
try {
methodCache[key] = clazz.getMethod(name, clazzs);
methodCache[key] = clazz.getMethod(name, clazzs as any)
} catch (ex) {
methodCache[key] = clazz.getDeclaredMethod(name, clazzs);
try {
methodCache[key] = clazz.getDeclaredMethod(name, clazzs as any)
} catch (ex) {
for (const m of Java.from(declaredMethods(clazz))) {
if (m.name == name) {
methodCache[key] = m
break
}
}
}
}
}
return methodCache[key];
return methodCache[key]
}
function declaredMethods(clazz) {
return clazz.declaredMethods;
return clazz.declaredMethods
}
var classMethodsCache = [];
let classMethodsCache: any[] = []
function mapToObject(javaObj) {
if (!javaObj || !javaObj.class) { throw new TypeError(`参数 ${javaObj} 不是一个Java对象!`) }
var target = {};
getJavaObjectMethods(javaObj).forEach(t => mapMethod(target, javaObj, t));
return target;
let target = {}
getJavaObjectMethods(javaObj).forEach(t => mapMethod(target, javaObj, t))
return target
}
function getJavaObjectMethods(javaObj) {
var className = javaObj.class.name;
let className = javaObj.class.name
if (!classMethodsCache[className]) {
var names = [];
var methods = javaObj.class.methods;
for (var i in methods) {
names.push(methods[i].name);
let names: any[] = []
let methods = javaObj.class.methods
for (let i in methods) {
names.push(methods[i].name)
}
classMethodsCache[className] = names;
classMethodsCache[className] = names
}
return classMethodsCache[className];
return classMethodsCache[className]
}
function mapMethod(target, source, name) {
target[name] = function __SimpleDynamicMethod__(...args) {
if (args.length > 0) {
return source[name](args);
return source[name](args)
} else {
return source[name]();
return source[name]()
}
};
}
}
function on(obj) {
if (!obj || !obj.class) { throw new TypeError(`参数 ${obj} 不是一个Java对象!`) }
return new Reflect(obj);
// if (!obj || !obj.class) { throw new TypeError(`参数 ${obj} 不是一个Java对象!`) }
return new Reflect(obj)
}
export = {
@ -188,4 +206,4 @@ export = {
accessible,
declaredMethods,
mapToObject
};
}

View File

@ -0,0 +1,109 @@
class ChatMessagePart {
private internal: any = {}
get text() {
return this.internal.text
}
set text(text: string) {
this.internal.text = text
}
click(action: string, value: string) {
this.internal.clickEvent = { action, value }
}
hover(action: string, value: string) {
this.internal.hoverEvent = { action, value }
}
convert() {
return this.internal;
}
}
class Tellraw {
static duplicateChar = '§卐'
static create() {
return new Tellraw().then(Tellraw.duplicateChar);
}
private cache: string = '';
private parts = [new ChatMessagePart()];
then(part: ChatMessagePart | string) {
if (typeof part === "string") {
var newPart = new ChatMessagePart();
newPart.text = part
this.then(newPart);
return this;
}
var last = this.latest();
if (!last.text) {
last.text = part.text;
} else {
this.parts.push(part);
}
this.cache = null;
}
text(text: string) {
this.latest().text = text;
return this;
}
tip(text: string) {
this.latest().hover("show_text", text);
return this;
}
item(text: string) {
this.latest().hover("show_item", text);
return this;
}
command(command: string) {
this.latest().click("run_command", command);
return this;
}
suggest(url: string) {
this.latest().click("suggest_command", url);
return this;
}
file(path: string) {
this.latest().click("open_file", path);
return this;
}
link(url: string) {
this.latest().click("open_url", url);
return this;
}
latest() {
return this.parts[this.parts.length - 1];
}
json() {
if (!this.cache) {
var temp = [];
this.parts.forEach(t => {
temp.push(t.convert());
});
this.cache = JSON.stringify(temp);
console.trace(this.cache);
}
return this.cache;
}
string() {
var temp = '';
this.parts.forEach(t => {
temp += t.text
});
return temp;
}
}
export default Tellraw

View File

@ -1,25 +1,30 @@
function Template(tpl: string) {
var match: RegExpExecArray;
var code = ['var r=[];'];
var re = /\{\{\s*([a-zA-Z\.\_0-9()]+)\s*\}\}/m;
function addLine(text: string) {
code.push('r.push(\'' + text.replace(/\'/g, '\\\'').replace(/\n/g, '\\n').replace(/\r/g, '\\r') + '\');');
};
while (match = re.exec(tpl)) {
if (match.index > 0) {
addLine(tpl.slice(0, match.index));
class Template {
private renderFunc: Function;
constructor(tpl: string) {
var match: RegExpExecArray;
var code = ['var r=[];'];
var re = /\{\{\s*([a-zA-Z\.\_0-9()]+)\s*\}\}/m;
while (match = re.exec(tpl)) {
if (match.index > 0) {
this.addLine(code, tpl.slice(0, match.index));
}
code.push('r.push(this.' + match[1] + ');');
tpl = tpl.substring(match.index + match[0].length);
}
code.push('r.push(this.' + match[1] + ');');
tpl = tpl.substring(match.index + match[0].length);
this.addLine(code, tpl);
code.push('return r.join(\'\');');
// 创建函数:
this.renderFunc = new Function(code.join('\n'));
}
addLine(code: string[], text: string) {
code.push('r.push(\'' + text.replace(/\'/g, '\\\'').replace(/\n/g, '\\n').replace(/\r/g, '\\r') + '\');');
}
addLine(tpl);
code.push('return r.join(\'\');');
// 创建函数:
var fn = new Function(code.join('\n'));
// 用render()调用函数并绑定this参数
this.render = function(model) {
return fn.apply(model);
};
render(model: object) {
return this.renderFunc.apply(model);
}
}
export = {

View File

@ -1,4 +1,4 @@
import '@ms/nashorn'
import '@ccms/nashorn'
let Files = Java.type("java.nio.file.Files");
let Paths = Java.type("java.nio.file.Paths");

View File

@ -0,0 +1,32 @@
const Thread = Java.type('java.lang.Thread')
const ThreadGroup = Java.type("java.lang.ThreadGroup")
const AtomicInteger = Java.type("java.util.concurrent.atomic.AtomicInteger")
const ThreadPoolExecutor = Java.type('java.util.concurrent.ThreadPoolExecutor')
const LinkedBlockingQueue = Java.type("java.util.concurrent.LinkedBlockingQueue")
interface ThreadPoolConfig {
corePoolSize?: number
maximumPoolSize?: number
keepAliveTime?: number
workQueueSize?: number
groupName: string
}
export default {
create(config: ThreadPoolConfig): java.util.concurrent.ThreadPoolExecutor {
let threadCount = new AtomicInteger(0)
config = {
corePoolSize: 10,
maximumPoolSize: 100,
keepAliveTime: 60,
workQueueSize: 500,
...config
}
return new ThreadPoolExecutor(
config.corePoolSize, config.maximumPoolSize, config.keepAliveTime, Packages.java.util.concurrent.TimeUnit.SECONDS,
new LinkedBlockingQueue(config.workQueueSize),
(run: any) => new Thread(new ThreadGroup(config.groupName), run, config.groupName + "-" + threadCount.incrementAndGet()),
new ThreadPoolExecutor.CallerRunsPolicy()
)
}
}

View File

@ -2,7 +2,6 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "src",
"outDir": "dist",
"declaration": true
"outDir": "dist"
}
}

1
packages/compile/.npmignore Symbolic link
View File

@ -0,0 +1 @@
../../.npmignore

View File

@ -0,0 +1,26 @@
{
"name": "@ccms/compile",
"version": "0.7.0",
"description": "MiaoScript compile package",
"keywords": [
"miaoscript",
"minecraft",
"bukkit",
"sponge"
],
"author": "MiaoWoo <admin@yumc.pw>",
"homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC",
"main": "dist/index.js",
"scripts": {
"clean": "rimraf dist",
"watch": "tsc --watch",
"build": "yarn clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1"
},
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^3.9.2"
}
}

View File

@ -0,0 +1,5 @@
import * as ts from 'typescript'
let scan = ts.createScanner(ts.ScriptTarget.ES5, true, ts.LanguageVariant.Standard)
scan.setText('let a = 1')
scan.tryScan(() => { })

View File

@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "src",
"outDir": "dist"
}
}

View File

@ -1,4 +0,0 @@
/node_modules
/dist
/package-lock.json
/yarn.lock

View File

@ -1,22 +0,0 @@
src
test
typings
bundled
build
coverage
docs
wiki
gulpfile.js
bower.json
karma.conf.js
tsconfig.json
typings.json
CONTRIBUTING.md
ISSUE_TEMPLATE.md
PULL_REQUEST_TEMPLATE.md
tslint.json
wallaby.js
.travis.yml
.gitignore
.vscode
type_definitions

View File

@ -0,0 +1 @@
../../.npmignore

View File

@ -1,6 +1,6 @@
{
"name": "@ms/container",
"version": "0.0.0",
"name": "@ccms/container",
"version": "0.7.0",
"description": "MiaoScript container package",
"keywords": [
"miaoscript",
@ -12,21 +12,20 @@
"homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC",
"main": "dist/index.js",
"publishConfig": {
"registry": "https://repo.yumc.pw/repository/npm/"
},
"scripts": {
"clean": "rimraf dist",
"watch": "npx tsc --watch",
"build": "yarn clean && npx tsc",
"watch": "tsc --watch",
"build": "yarn clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1"
},
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.0",
"typescript": "^3.6.2"
"rimraf": "^3.0.2",
"typescript": "^3.9.2"
},
"dependencies": {
"inversify-binding-decorators": "^4.0.0"
"inversify": "^5.0.1",
"inversify-binding-decorators": "^4.0.0",
"@ccms/nashorn": "^0.7.0"
}
}

View File

@ -0,0 +1,7 @@
export namespace ioc {
export const Autowired = Symbol('Autowired')
export const Resource = Symbol('Resource')
export const JavaClass = Symbol('JavaClass')
export const JavaInstance = Symbol('JavaInstance')
export const JavaStaticClass = Symbol('JavaStaticClass')
}

View File

@ -1,9 +1,9 @@
import { interfaces, Container } from "inversify";
import { interfaces, Container } from "inversify"
let _container: Container;
let _container: Container
const CONTAINER = Symbol.for("@ms/ioc:Container");
const INJECTION = Symbol.for("INJECTION");
const ContainerInstance = Symbol.for("@ccms/ioc:Container")
const INJECTION = Symbol.for("INJECTION")
function _proxyGetter(
proto: any,
@ -11,19 +11,19 @@ function _proxyGetter(
resolve: () => any,
doCache: boolean
) {
function getter() {
function getter(this: object) {
if (doCache && !Reflect.hasMetadata(INJECTION, this, key)) {
Reflect.defineMetadata(INJECTION, resolve(), this, key);
Reflect.defineMetadata(INJECTION, resolve(), this, key)
}
if (Reflect.hasMetadata(INJECTION, this, key)) {
return Reflect.getMetadata(INJECTION, this, key);
return Reflect.getMetadata(INJECTION, this, key)
} else {
return resolve();
return resolve()
}
}
function setter(newVal: any) {
Reflect.defineMetadata(INJECTION, newVal, this, key);
function setter(this: object, newVal: any) {
Reflect.defineMetadata(INJECTION, newVal, this, key)
}
Object.defineProperty(proto, key, {
@ -31,63 +31,63 @@ function _proxyGetter(
enumerable: true,
get: getter,
set: setter
});
})
}
function initContainer(container: Container) {
Reflect.defineMetadata(CONTAINER, container, Reflect);
_container = container;
Reflect.defineMetadata(ContainerInstance, container, Reflect)
return _container = container
}
function getContainer(): Container {
return _container || Reflect.getMetadata(CONTAINER, Reflect)
return _container || initContainer(new Container())
}
function makePropertyInjectDecorator(doCache: boolean) {
return function(serviceIdentifier: interfaces.ServiceIdentifier<any>) {
return function(proto: any, key: string): void {
return function (serviceIdentifier: interfaces.ServiceIdentifier<any>) {
return function (proto: any, key: string): void {
let resolve = () => {
return getContainer().get(serviceIdentifier);
};
_proxyGetter(proto, key, resolve, doCache);
};
};
return getContainer().get(serviceIdentifier)
}
_proxyGetter(proto, key, resolve, doCache)
}
}
}
function makePropertyInjectNamedDecorator(doCache: boolean) {
return function(serviceIdentifier: interfaces.ServiceIdentifier<any>, named: string) {
return function(proto: any, key: string): void {
return function (serviceIdentifier: interfaces.ServiceIdentifier<any>, named: string) {
return function (proto: any, key: string): void {
let resolve = () => {
return getContainer().getNamed(serviceIdentifier, named);
};
_proxyGetter(proto, key, resolve, doCache);
};
};
return getContainer().getNamed(serviceIdentifier, named)
}
_proxyGetter(proto, key, resolve, doCache)
}
}
}
function makePropertyInjectTaggedDecorator(doCache: boolean) {
return function(serviceIdentifier: interfaces.ServiceIdentifier<any>, key: string, value: any) {
return function(proto: any, propertyName: string): void {
return function (serviceIdentifier: interfaces.ServiceIdentifier<any>, key: string, value: any) {
return function (proto: any, propertyName: string): void {
let resolve = () => {
return getContainer().getTagged(serviceIdentifier, key, value);
};
_proxyGetter(proto, propertyName, resolve, doCache);
};
};
return getContainer().getTagged(serviceIdentifier, key, value)
}
_proxyGetter(proto, propertyName, resolve, doCache)
}
}
}
function makePropertyMultiInjectDecorator(doCache: boolean) {
return function(serviceIdentifier: interfaces.ServiceIdentifier<any>) {
return function(proto: any, key: string): void {
return function (serviceIdentifier: interfaces.ServiceIdentifier<any>) {
return function (proto: any, key: string): void {
let resolve = () => {
return getContainer().getAll(serviceIdentifier);
};
_proxyGetter(proto, key, resolve, doCache);
};
};
return getContainer().getAll(serviceIdentifier)
}
_proxyGetter(proto, key, resolve, doCache)
}
}
}
let doCache = true;
let doCache = true
let lazyInject = makePropertyInjectDecorator(doCache)
let lazyInjectNamed = makePropertyInjectNamedDecorator(doCache)
@ -97,8 +97,9 @@ let lazyMultiInject = makePropertyMultiInjectDecorator(doCache)
export {
initContainer,
getContainer,
ContainerInstance,
lazyInject,
lazyInjectNamed,
lazyInjectTagged,
lazyMultiInject
};
}

View File

@ -1,23 +1,91 @@
import "reflect-metadata";
import { interfaces, Container } from 'inversify';
import { fluentProvide } from 'inversify-binding-decorators';
/// <reference types="@ccms/nashorn" />
const provideNamed = (identifier: interfaces.ServiceIdentifier<any>, name: string) => {
return fluentProvide(identifier).whenTargetNamed(name).done();
};
import "reflect-metadata"
import { initContainer, getContainer } from './decorators'
import { interfaces, Container } from 'inversify'
import { fluentProvide } from 'inversify-binding-decorators'
import { ioc } from "./constants"
const provideSingleton = (identifier: interfaces.ServiceIdentifier<any>) => {
return fluentProvide(identifier).inSingletonScope().done();
};
/**
*
* @param identifier
* @param name
*/
export const provideNamed = (identifier: interfaces.ServiceIdentifier<any>, name: string) => {
return fluentProvide(identifier).whenTargetNamed(name).done()
}
const DefaultContainer = new Container();
/**
*
* @param identifier
*/
export const provideSingleton = (identifier: interfaces.ServiceIdentifier<any>) => {
return fluentProvide(identifier).inSingletonScope().done()
}
/**
*
* @param identifier
*/
export const provideSingletonNamed = (identifier: interfaces.ServiceIdentifier<any>, name: string) => {
return fluentProvide(identifier).inSingletonScope().whenTargetNamed(name).done()
}
/**
* java.lang.Class
* @param className Java
*/
export const JavaClass = (className: string) => {
return function (target: any, propertyKey: string, index?: number) {
try { target[propertyKey] = Java.type(className).class; return } catch (error) { }
try { target[propertyKey] = base.getClass(className); return } catch (error) { }
console.warn('JavaClass Inject target', target, 'propertyKey', propertyKey, 'failed!')
}
}
/**
* JSJava
* @param className Java
*/
export const JSClass = (className: string) => {
return function (target: any, propertyKey: string, index?: number) {
try { target[propertyKey] = Java.type(className); return } catch (error) { }
try { target[propertyKey] = base.getClass(className).static; return } catch (error) { }
console.warn('JSClass Inject target', target, 'propertyKey', propertyKey, 'failed!')
}
}
/**
*
* @param className
*/
export const Autowired = (className?: string | any) => {
return function (target: any, propertyKey: string) {
target[propertyKey] = getContainer().getNamed(ioc.Autowired, className || propertyKey)
}
}
/**
*
* @param className
*/
export const Resource = (resourceName?: string | any) => {
return function (target: any, propertyKey: string) {
target[propertyKey] = getContainer().getNamed(ioc.Resource, resourceName || propertyKey)
}
}
export const reduceMetadata = (ctx: interfaces.Context): any => {
return ctx.currentRequest.target.metadata.reduce((result, entry, index) => {
result[entry.key] = entry.value
return result
}, {})
}
export const DefaultContainer = new Container()
initContainer(DefaultContainer)
export * from 'inversify'
export * from './constants'
export * from './decorators'
export * from 'inversify-binding-decorators'
export {
fluentProvide,
provideNamed,
provideSingleton,
DefaultContainer
};

View File

@ -1,4 +0,0 @@
/node_modules
/dist
/package-lock.json
/yarn.lock

View File

@ -1,22 +0,0 @@
src
test
typings
bundled
build
coverage
docs
wiki
gulpfile.js
bower.json
karma.conf.js
tsconfig.json
typings.json
CONTRIBUTING.md
ISSUE_TEMPLATE.md
PULL_REQUEST_TEMPLATE.md
tslint.json
wallaby.js
.travis.yml
.gitignore
.vscode
type_definitions

1
packages/core/.npmignore Symbolic link
View File

@ -0,0 +1 @@
../../.npmignore

Some files were not shown because too many files have changed in this diff Show More