├── .gitignore ├── .gitmodules ├── .vscode └── settings.json ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── additions ├── README.md ├── biconsumer_new.rs_ ├── biomeprovider_new.rs ├── blockpopulator_new.rs ├── chunkgenerator_new.rs ├── commandexecutor_new.rs ├── configserializable_new.rs ├── consumer_new.rs ├── conversationcanceller_new.rs ├── conversationprefix_new.rs ├── helptopic_new.rs ├── helptopicfactory_new.rs ├── maprenderer_new.rs ├── metadatavalue_new.rs ├── noisegenerator_new.rs ├── persistentdatatype_new.rs ├── plugin_base_new.rs ├── plugin_loader_new.rs ├── plugin_new.rs ├── plugin_new_extendable.rs ├── prompt_new.rs ├── runnable_new.rs ├── tabcompleter_new.rs └── tabexecutor_new.rs ├── blackboxmc-rs-bukkit ├── Cargo.toml ├── README.md └── src │ ├── advancement │ └── mod.rs │ ├── attribute │ └── mod.rs │ ├── ban │ └── mod.rs │ ├── block │ ├── banner │ │ └── mod.rs │ ├── data │ │ ├── mod.rs │ │ └── mod_type │ │ │ └── mod.rs │ ├── mod.rs │ ├── sign │ │ └── mod.rs │ ├── spawner │ │ └── mod.rs │ └── structure │ │ └── mod.rs │ ├── boss │ └── mod.rs │ ├── command │ ├── defaults │ │ └── mod.rs │ └── mod.rs │ ├── configuration │ ├── file │ │ └── mod.rs │ ├── mod.rs │ └── serialization │ │ └── mod.rs │ ├── conversations │ └── mod.rs │ ├── damage │ └── mod.rs │ ├── enchantments │ └── mod.rs │ ├── entity │ ├── memory │ │ └── mod.rs │ ├── minecart │ │ └── mod.rs │ └── mod.rs │ ├── event │ ├── block │ │ └── mod.rs │ ├── enchantment │ │ └── mod.rs │ ├── entity │ │ └── mod.rs │ ├── hanging │ │ └── mod.rs │ ├── inventory │ │ └── mod.rs │ ├── mod.rs │ ├── player │ │ └── mod.rs │ ├── raid │ │ └── mod.rs │ ├── server │ │ └── mod.rs │ ├── vehicle │ │ └── mod.rs │ ├── weather │ │ └── mod.rs │ └── world │ │ └── mod.rs │ ├── generator │ ├── mod.rs │ └── structure │ │ └── mod.rs │ ├── help │ └── mod.rs │ ├── inventory │ ├── meta │ │ ├── components │ │ │ └── mod.rs │ │ ├── mod.rs │ │ ├── tags │ │ │ └── mod.rs │ │ └── trim │ │ │ └── mod.rs │ ├── mod.rs │ ├── recipe │ │ └── mod.rs │ └── view │ │ └── mod.rs │ ├── lib.rs │ ├── loot │ └── mod.rs │ ├── map │ └── mod.rs │ ├── material │ ├── mod.rs │ └── types │ │ └── mod.rs │ ├── metadata │ └── mod.rs │ ├── packs │ └── mod.rs │ ├── permissions │ └── mod.rs │ ├── persistence │ └── mod.rs │ ├── plugin │ ├── java │ │ └── mod.rs │ ├── messaging │ │ └── mod.rs │ └── mod.rs │ ├── potion │ └── mod.rs │ ├── profile │ └── mod.rs │ ├── projectiles │ └── mod.rs │ ├── scheduler │ └── mod.rs │ ├── scoreboard │ └── mod.rs │ ├── spawner │ └── mod.rs │ ├── structure │ └── mod.rs │ └── util │ ├── io │ └── mod.rs │ ├── mod.rs │ ├── noise │ └── mod.rs │ └── permissions │ └── mod.rs ├── blackboxmc-rs-bungee ├── Cargo.toml └── src │ ├── bungee │ ├── api │ │ ├── chat │ │ │ ├── hover │ │ │ │ ├── content │ │ │ │ │ └── mod.rs │ │ │ │ └── mod.rs │ │ │ └── mod.rs │ │ └── mod.rs │ ├── chat │ │ └── mod.rs │ └── mod.rs │ └── lib.rs ├── blackboxmc-rs-general ├── Cargo.toml └── src │ ├── lib.rs │ └── macros │ ├── memory.rs │ └── mod.rs ├── blackboxmc-rs-java ├── Cargo.toml └── src │ ├── lang │ ├── lib.rs │ └── mod.rs │ ├── lib.rs │ ├── security │ └── mod.rs │ └── util │ ├── function │ └── mod.rs │ ├── lib.rs │ ├── logging │ └── mod.rs │ ├── mod.rs │ ├── random │ └── mod.rs │ └── regex │ └── mod.rs ├── blackboxmc-rs-proc ├── Cargo.lock ├── Cargo.toml ├── README.md └── src │ └── lib.rs ├── examples ├── block-break-event │ ├── .gitignore │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── lib.rs └── name-printer │ ├── .gitignore │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ └── lib.rs ├── generate.py ├── pprint.py └── src ├── lib.rs └── mod.rs /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | *.json 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackBoxMC/blackboxmc-rs/7faecca02864dd5612cbeba1db5805a9987b59ac/.gitmodules -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "rust-analyzer.linkedProjects": [ 3 | "./Cargo.toml", 4 | "./blackboxmc-rs-proc/Cargo.toml", 5 | "./examples/block-break-event/Cargo.toml", 6 | "./examples/mc-classic-mode/Cargo.toml", 7 | ], 8 | "rust-analyzer.experimental.procAttrMacros" :false 9 | } -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "blackbox_rs" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [workspace] 9 | members = ["blackboxmc-rs-general", "blackboxmc-rs-proc", "blackboxmc-rs-bukkit", "blackboxmc-rs-bungee", "blackboxmc-rs-java", "examples/name-printer", "examples/block-break-event"] 10 | 11 | [dependencies] 12 | eyre = "0.6.8" 13 | jni = "0.21.1" 14 | blackboxmc_proc = {path = "./blackboxmc-rs-proc"} 15 | parking_lot = "0.12.1" 16 | syn = { version = "2.0.27", features = ["full"] } 17 | once_cell = "1.18.0" 18 | color-eyre = "0.6.2" 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # blackbox-rs 2 | 3 | blackbox-rs is a series of Rust crates that is to be paired with [BlackBox](https://github.com/BlackboxMC/Blackbox), which allows you to create Bukkit compatible plugins using compiled langauges such as Rust. 4 | 5 | # Versioning 6 | 7 | Four of the crates are frozen at `0.4.0` due to no longer needing updates. The only one that gets updates is `blackboxmc-rs-bukkit`, which uses semantic versioning but places the patch version at the equivalant Minecraft version. For example, `1.2.21` is version 1.2 of the plugin, with compatibility for 1.21. 8 | 9 | # Contributing 10 | 11 | Due to the massive scale of Spigot's API, BlackBox is automatically generated by the `generate.py` script. There is a system for hand written code to be added via the `additions` folder. I am adverse to using macros or anything that would have the code generated at compile time, because I am a believer that if you are debugging a library, you should be able to go to the repo and have a good idea of what the code is doing. 12 | 13 | A `spigot.json` file is required; it is not in the repo, you have to generate it via [this repo](https://github.com/BlackBoxMC/SpigotJSON). 14 | -------------------------------------------------------------------------------- /additions/README.md: -------------------------------------------------------------------------------- 1 | This folder contains many files consisting of manually written code that gets injected into the generated code. 2 | 3 | The format for this is as follows: 4 | 5 | ``` 6 | //[file_path]#[struct] 7 | [code] 8 | ``` 9 | 10 | The struct part is optional, but if you put it in, your code will be appended to the relevant struct instead of just the bottom of the file. 11 | 12 | Simply type the code into appropriately named files, and make sure the first line starts with two slashes and the path (relative to `generate.py`) where the code should be injected -------------------------------------------------------------------------------- /additions/biconsumer_new.rs_: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-java/src/util/function/mod.rs#JavaBiConsumer 2 | 3 | #[cfg(not(target_arch = "wasm32"))] 4 | pub fn from_rust_fn<'mc2, A, B, C>( 5 | env: &'mc2 blackboxmc_general::SharedJNIEnv<'mc>, 6 | f: A, 7 | ) -> Result> 8 | where 9 | A: Fn(&'mc2 blackboxmc_general::SharedJNIEnv<'mc>, B, C), 10 | B: blackboxmc_general::JNIInstantiatable<'mc>, 11 | C: blackboxmc_general::JNIInstantiatable<'mc>, 12 | { 13 | // Create the closure. 14 | let closure: &_ = Box::leak(Box::new( 15 | move |a: *mut jni::sys::_jobject, b: *mut jni::sys::_jobject| unsafe { 16 | f( 17 | env, 18 | B::from_raw(&env, jni::objects::JObject::from_raw(a)).unwrap(), 19 | C::from_raw(&env, jni::objects::JObject::from_raw(b)).unwrap(), 20 | ); 21 | }, 22 | )); 23 | let callback = libffi::high::Closure2::new(closure); 24 | let &code = callback.code_ptr(); 25 | let ptr: unsafe extern "C" fn(*const jni::sys::jobject) = unsafe { std::mem::transmute(code) }; 26 | std::mem::forget(callback); 27 | 28 | // Create the java object. 29 | let obj = env.new_object( 30 | "net/ioixd/blackbox/BiConsumerLink", 31 | "(J)V", 32 | vec![(ptr as i64).into()], 33 | ); 34 | let obj = env.translate_error_no_gen(obj)?; 35 | 36 | Self::from_raw(&env, obj) 37 | } 38 | -------------------------------------------------------------------------------- /additions/biomeprovider_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/generator/mod.rs#BiomeProvider 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "BiomeProvider", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/blockpopulator_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/generator/mod.rs#BlockPopulator 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "BlockPopulator", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/chunkgenerator_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/generator/mod.rs#ChunkGenerator 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "ChunkGenerator", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/commandexecutor_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/command/mod.rs#CommandExecutor 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "CommandExecutor", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/configserializable_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/configuration/serialization/mod.rs#ConfigurationSerializable 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "ConfigSerializable", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/consumer_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/util/mod.rs#Consumer 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "Consumer", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/conversationcanceller_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/conversations/mod.rs#ConversationCanceller 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "ConversationCanceller", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/conversationprefix_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/conversations/mod.rs#ConversationPrefix 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "ConversationPrefix", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/helptopic_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/help/mod.rs#HelpTopic 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "HelpTopic", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/helptopicfactory_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/help/mod.rs#HelpTopicFactory 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "HelpTopicFactory", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/maprenderer_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/map/mod.rs#MapRenderer 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "MapRenderer", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/metadatavalue_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/metadata/mod.rs#MetadataValue 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "MetadataValue", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/noisegenerator_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/util/noise/mod.rs#NoiseGenerator 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "NoiseGenerator", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/persistentdatatype_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/persistence/mod.rs#PersistentDataType 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "PersistentDataType", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/plugin_base_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/plugin/mod.rs#PluginBase 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "PluginBase", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/plugin_loader_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/plugin/mod.rs#PluginLoader 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "PluginLoader", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/plugin_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/plugin/mod.rs#Plugin 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "Plugin", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/plugin_new_extendable.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/plugin/mod.rs#Plugin 2 | /// Return one of the extendable classes that BlackBox supports, based on the value given. 3 | /// 4 | /// ## Safety 5 | /// - It returns a Java Object that you must then cast into the proper object via JNI. You are responsible for the checks yourself. 6 | /// - This function is specific to the BlackboxPlugin class supplied within the plugin, and will error out if you pass a regular JavaPlugin. 7 | pub unsafe fn new_extendable( 8 | &self, 9 | address: i32, 10 | class_name: impl Into 11 | + std::convert::AsRef 12 | + std::convert::AsRef 13 | + std::convert::AsRef, 14 | name: impl Into + std::convert::AsRef + std::convert::AsRef, 15 | lib_name: impl Into + std::convert::AsRef + std::convert::AsRef, 16 | ) -> Result> { 17 | let obj = self.jni_ref().call_method( 18 | &self.1, 19 | "newExtendable", 20 | "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/Object;", 21 | vec![ 22 | jni::objects::JValueGen::Int(address), 23 | jni::objects::JValueGen::from(jni::objects::JObject::from( 24 | self.jni_ref().new_string(class_name).unwrap(), 25 | )), 26 | jni::objects::JValueGen::from(jni::objects::JObject::from( 27 | self.jni_ref().new_string(name).unwrap(), 28 | )), 29 | jni::objects::JValueGen::from(jni::objects::JObject::from( 30 | self.jni_ref().new_string(lib_name).unwrap(), 31 | )), 32 | #[cfg(target_arch = "wasm32")] 33 | jni::objects::JValueGen::Bool(true.into()), 34 | #[cfg(not(target_arch = "wasm32"))] 35 | jni::objects::JValueGen::Bool(false.into()), 36 | ], 37 | ); 38 | let obj = self.jni_ref().translate_error(obj)?; 39 | Ok(jni::objects::JObject::from_raw(*obj.l()?)) 40 | } 41 | -------------------------------------------------------------------------------- /additions/prompt_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/conversations/mod.rs#Prompt 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "Prompt", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/runnable_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/scheduler/mod.rs#BukkitRunnable 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "BukkitRunnable", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/tabcompleter_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/command/mod.rs#TabCompleter 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "TabCompleter", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /additions/tabexecutor_new.rs: -------------------------------------------------------------------------------- 1 | // blackboxmc-rs-bukkit/src/command/mod.rs#TabExecutor 2 | pub fn from_extendable( 3 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 4 | plugin: &'mc crate::plugin::Plugin, 5 | address: i32, 6 | lib_name: String, 7 | name: String, 8 | ) -> Result> { 9 | let obj = unsafe { plugin.new_extendable(address, "TabExecutor", name, lib_name) }?; 10 | Self::from_raw(env, obj) 11 | } 12 | -------------------------------------------------------------------------------- /blackboxmc-rs-bukkit/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "blackboxmc_bukkit" 3 | version = "1.0.21" 4 | edition = "2021" 5 | license = "LGPL-2.0-or-later" 6 | description = "BlackboxMC bindings for org.bukkit" 7 | 8 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 9 | 10 | [dependencies] 11 | color-eyre = "0.6.2" 12 | eyre = "0.6.8" 13 | jni = "0.21.1" 14 | blackboxmc_general = { version = "0.4.0", path = "../blackboxmc-rs-general" } 15 | blackboxmc_bungee = { version = "0.4.0", path = "../blackboxmc-rs-bungee" } 16 | blackboxmc_java = { version = "0.4.0", path = "../blackboxmc-rs-java" } 17 | 18 | [build-dependencies] 19 | lazy_static = "1.4.0" 20 | quote = "1.0.35" 21 | regex = "1.10.4" 22 | serde = "1.0.197" 23 | serde_derive = "1.0.197" 24 | serde_json = "1.0.115" 25 | -------------------------------------------------------------------------------- /blackboxmc-rs-bukkit/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackBoxMC/blackboxmc-rs/7faecca02864dd5612cbeba1db5805a9987b59ac/blackboxmc-rs-bukkit/README.md -------------------------------------------------------------------------------- /blackboxmc-rs-bukkit/src/ban/mod.rs: -------------------------------------------------------------------------------- 1 | #![allow(deprecated)] 2 | use blackboxmc_general::JNIInstantiatable; 3 | use blackboxmc_general::JNIRaw; 4 | use color_eyre::eyre::Result; 5 | #[repr(C)] 6 | pub struct IpBanList<'mc>( 7 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 8 | pub(crate) jni::objects::JObject<'mc>, 9 | ); 10 | 11 | impl<'mc> JNIRaw<'mc> for IpBanList<'mc> { 12 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 13 | self.0.clone() 14 | } 15 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 16 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 17 | } 18 | } 19 | impl<'mc> JNIInstantiatable<'mc> for IpBanList<'mc> { 20 | fn from_raw( 21 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 22 | obj: jni::objects::JObject<'mc>, 23 | ) -> Result> { 24 | if obj.is_null() { 25 | return Err(eyre::eyre!("Tried to instantiate IpBanList from null object.").into()); 26 | } 27 | let (valid, name) = env.validate_name(&obj, "org/bukkit/ban/IpBanList")?; 28 | if !valid { 29 | Err(eyre::eyre!( 30 | "Invalid argument passed. Expected a IpBanList object, got {}", 31 | name 32 | ) 33 | .into()) 34 | } else { 35 | Ok(Self(env.clone(), obj)) 36 | } 37 | } 38 | } 39 | 40 | impl<'mc> IpBanList<'mc> { 41 | /// Gets a {@link BanEntry} by target. 42 | pub fn get_ban_entry( 43 | &self, 44 | target: jni::objects::JObject<'mc>, 45 | ) -> Result>, Box> { 46 | let mut args = Vec::new(); 47 | let mut sig = String::from("("); 48 | sig += "LT;"; 49 | let val_1 = jni::objects::JValueGen::Object(target); 50 | args.push(val_1); 51 | sig += ")Lorg/bukkit/BanEntry;"; 52 | let res = self 53 | .jni_ref() 54 | .call_method(&self.jni_object(), "getBanEntry", sig.as_str(), args); 55 | let res = self.jni_ref().translate_error(res)?; 56 | if unsafe { jni::objects::JObject::from_raw(res.as_jni().l) }.is_null() { 57 | return Ok(None); 58 | } 59 | Ok(Some(crate::BanEntry::from_raw(&self.jni_ref(), unsafe { 60 | jni::objects::JObject::from_raw(res.l()?.clone()) 61 | })?)) 62 | } 63 | /// Adds a ban to this list. If a previous ban exists, this will 64 | /// update the previous entry. 65 | pub fn add_ban( 66 | &self, 67 | target: jni::objects::JObject<'mc>, 68 | reason: impl Into, 69 | duration: jni::objects::JObject<'mc>, 70 | source: impl Into, 71 | ) -> Result>, Box> { 72 | let mut args = Vec::new(); 73 | let mut sig = String::from("("); 74 | sig += "LT;"; 75 | let val_1 = jni::objects::JValueGen::Object(target); 76 | args.push(val_1); 77 | sig += "Ljava/lang/String;"; 78 | let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from( 79 | self.jni_ref().new_string(reason.into())?, 80 | )); 81 | args.push(val_2); 82 | sig += "Ljava/time/Duration;"; 83 | let val_3 = jni::objects::JValueGen::Object(duration); 84 | args.push(val_3); 85 | sig += "Ljava/lang/String;"; 86 | let val_4 = jni::objects::JValueGen::Object(jni::objects::JObject::from( 87 | self.jni_ref().new_string(source.into())?, 88 | )); 89 | args.push(val_4); 90 | sig += ")Lorg/bukkit/BanEntry;"; 91 | let res = self 92 | .jni_ref() 93 | .call_method(&self.jni_object(), "addBan", sig.as_str(), args); 94 | let res = self.jni_ref().translate_error(res)?; 95 | if unsafe { jni::objects::JObject::from_raw(res.as_jni().l) }.is_null() { 96 | return Ok(None); 97 | } 98 | Ok(Some(crate::BanEntry::from_raw(&self.jni_ref(), unsafe { 99 | jni::objects::JObject::from_raw(res.l()?.clone()) 100 | })?)) 101 | } 102 | #[deprecated] 103 | /// Gets a set containing every {@link BanEntry} in this list. 104 | pub fn ban_entries( 105 | &self, 106 | ) -> Result, Box> { 107 | let sig = String::from("()Ljava/util/Set;"); 108 | let res = 109 | self.jni_ref() 110 | .call_method(&self.jni_object(), "getBanEntries", sig.as_str(), vec![]); 111 | let res = self.jni_ref().translate_error(res)?; 112 | blackboxmc_java::util::JavaSet::from_raw(&self.jni_ref(), unsafe { 113 | jni::objects::JObject::from_raw(res.l()?.clone()) 114 | }) 115 | } 116 | /// Gets a set containing every {@link BanEntry} in this list. 117 | pub fn entries( 118 | &self, 119 | ) -> Result, Box> { 120 | let sig = String::from("()Ljava/util/Set;"); 121 | let res = 122 | self.jni_ref() 123 | .call_method(&self.jni_object(), "getEntries", sig.as_str(), vec![]); 124 | let res = self.jni_ref().translate_error(res)?; 125 | blackboxmc_java::util::JavaSet::from_raw(&self.jni_ref(), unsafe { 126 | jni::objects::JObject::from_raw(res.l()?.clone()) 127 | }) 128 | } 129 | #[deprecated] 130 | /// Gets if a {@link BanEntry} exists for the target, indicating an active ban status. 131 | pub fn is_banned(&self, target: impl Into) -> Result> { 132 | let mut args = Vec::new(); 133 | let mut sig = String::from("("); 134 | sig += "Ljava/lang/String;"; 135 | let val_1 = jni::objects::JValueGen::Object(jni::objects::JObject::from( 136 | self.jni_ref().new_string(target.into())?, 137 | )); 138 | args.push(val_1); 139 | sig += ")Z"; 140 | let res = self 141 | .jni_ref() 142 | .call_method(&self.jni_object(), "isBanned", sig.as_str(), args); 143 | let res = self.jni_ref().translate_error(res)?; 144 | Ok(res.z()?) 145 | } 146 | #[deprecated] 147 | /// Removes the specified target from this list, therefore indicating a "not banned" status. 148 | pub fn pardon(&self, target: impl Into) -> Result<(), Box> { 149 | let mut args = Vec::new(); 150 | let mut sig = String::from("("); 151 | sig += "Ljava/lang/String;"; 152 | let val_1 = jni::objects::JValueGen::Object(jni::objects::JObject::from( 153 | self.jni_ref().new_string(target.into())?, 154 | )); 155 | args.push(val_1); 156 | sig += ")V"; 157 | let res = self 158 | .jni_ref() 159 | .call_method(&self.jni_object(), "pardon", sig.as_str(), args); 160 | self.jni_ref().translate_error(res)?; 161 | Ok(()) 162 | } 163 | 164 | pub fn instance_of(&self, other: impl Into) -> Result { 165 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 166 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 167 | } 168 | } 169 | impl<'mc> Into> for IpBanList<'mc> { 170 | fn into(self) -> crate::BanList<'mc> { 171 | crate::BanList::from_raw(&self.jni_ref(), self.1) 172 | .expect("Error converting IpBanList into crate::BanList") 173 | } 174 | } 175 | #[repr(C)] 176 | pub struct ProfileBanList<'mc>( 177 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 178 | pub(crate) jni::objects::JObject<'mc>, 179 | ); 180 | 181 | impl<'mc> JNIRaw<'mc> for ProfileBanList<'mc> { 182 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 183 | self.0.clone() 184 | } 185 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 186 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 187 | } 188 | } 189 | impl<'mc> JNIInstantiatable<'mc> for ProfileBanList<'mc> { 190 | fn from_raw( 191 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 192 | obj: jni::objects::JObject<'mc>, 193 | ) -> Result> { 194 | if obj.is_null() { 195 | return Err( 196 | eyre::eyre!("Tried to instantiate ProfileBanList from null object.").into(), 197 | ); 198 | } 199 | let (valid, name) = env.validate_name(&obj, "org/bukkit/ban/ProfileBanList")?; 200 | if !valid { 201 | Err(eyre::eyre!( 202 | "Invalid argument passed. Expected a ProfileBanList object, got {}", 203 | name 204 | ) 205 | .into()) 206 | } else { 207 | Ok(Self(env.clone(), obj)) 208 | } 209 | } 210 | } 211 | 212 | impl<'mc> ProfileBanList<'mc> { 213 | /// Adds a ban to this list. If a previous ban exists, this will 214 | /// update the previous entry. 215 | pub fn add_ban( 216 | &self, 217 | target: jni::objects::JObject<'mc>, 218 | reason: impl Into, 219 | duration: jni::objects::JObject<'mc>, 220 | source: impl Into, 221 | ) -> Result>, Box> { 222 | let mut args = Vec::new(); 223 | let mut sig = String::from("("); 224 | sig += "LT;"; 225 | let val_1 = jni::objects::JValueGen::Object(target); 226 | args.push(val_1); 227 | sig += "Ljava/lang/String;"; 228 | let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from( 229 | self.jni_ref().new_string(reason.into())?, 230 | )); 231 | args.push(val_2); 232 | sig += "Ljava/time/Duration;"; 233 | let val_3 = jni::objects::JValueGen::Object(duration); 234 | args.push(val_3); 235 | sig += "Ljava/lang/String;"; 236 | let val_4 = jni::objects::JValueGen::Object(jni::objects::JObject::from( 237 | self.jni_ref().new_string(source.into())?, 238 | )); 239 | args.push(val_4); 240 | sig += ")Lorg/bukkit/BanEntry;"; 241 | let res = self 242 | .jni_ref() 243 | .call_method(&self.jni_object(), "addBan", sig.as_str(), args); 244 | let res = self.jni_ref().translate_error(res)?; 245 | if unsafe { jni::objects::JObject::from_raw(res.as_jni().l) }.is_null() { 246 | return Ok(None); 247 | } 248 | Ok(Some(crate::BanEntry::from_raw(&self.jni_ref(), unsafe { 249 | jni::objects::JObject::from_raw(res.l()?.clone()) 250 | })?)) 251 | } 252 | /// Gets a {@link BanEntry} by target. 253 | pub fn get_ban_entry( 254 | &self, 255 | target: jni::objects::JObject<'mc>, 256 | ) -> Result>, Box> { 257 | let mut args = Vec::new(); 258 | let mut sig = String::from("("); 259 | sig += "LT;"; 260 | let val_1 = jni::objects::JValueGen::Object(target); 261 | args.push(val_1); 262 | sig += ")Lorg/bukkit/BanEntry;"; 263 | let res = self 264 | .jni_ref() 265 | .call_method(&self.jni_object(), "getBanEntry", sig.as_str(), args); 266 | let res = self.jni_ref().translate_error(res)?; 267 | if unsafe { jni::objects::JObject::from_raw(res.as_jni().l) }.is_null() { 268 | return Ok(None); 269 | } 270 | Ok(Some(crate::BanEntry::from_raw(&self.jni_ref(), unsafe { 271 | jni::objects::JObject::from_raw(res.l()?.clone()) 272 | })?)) 273 | } 274 | #[deprecated] 275 | /// Gets a set containing every {@link BanEntry} in this list. 276 | pub fn ban_entries( 277 | &self, 278 | ) -> Result, Box> { 279 | let sig = String::from("()Ljava/util/Set;"); 280 | let res = 281 | self.jni_ref() 282 | .call_method(&self.jni_object(), "getBanEntries", sig.as_str(), vec![]); 283 | let res = self.jni_ref().translate_error(res)?; 284 | blackboxmc_java::util::JavaSet::from_raw(&self.jni_ref(), unsafe { 285 | jni::objects::JObject::from_raw(res.l()?.clone()) 286 | }) 287 | } 288 | /// Gets a set containing every {@link BanEntry} in this list. 289 | pub fn entries( 290 | &self, 291 | ) -> Result, Box> { 292 | let sig = String::from("()Ljava/util/Set;"); 293 | let res = 294 | self.jni_ref() 295 | .call_method(&self.jni_object(), "getEntries", sig.as_str(), vec![]); 296 | let res = self.jni_ref().translate_error(res)?; 297 | blackboxmc_java::util::JavaSet::from_raw(&self.jni_ref(), unsafe { 298 | jni::objects::JObject::from_raw(res.l()?.clone()) 299 | }) 300 | } 301 | #[deprecated] 302 | /// Gets if a {@link BanEntry} exists for the target, indicating an active ban status. 303 | pub fn is_banned(&self, target: impl Into) -> Result> { 304 | let mut args = Vec::new(); 305 | let mut sig = String::from("("); 306 | sig += "Ljava/lang/String;"; 307 | let val_1 = jni::objects::JValueGen::Object(jni::objects::JObject::from( 308 | self.jni_ref().new_string(target.into())?, 309 | )); 310 | args.push(val_1); 311 | sig += ")Z"; 312 | let res = self 313 | .jni_ref() 314 | .call_method(&self.jni_object(), "isBanned", sig.as_str(), args); 315 | let res = self.jni_ref().translate_error(res)?; 316 | Ok(res.z()?) 317 | } 318 | #[deprecated] 319 | /// Removes the specified target from this list, therefore indicating a "not banned" status. 320 | pub fn pardon(&self, target: impl Into) -> Result<(), Box> { 321 | let mut args = Vec::new(); 322 | let mut sig = String::from("("); 323 | sig += "Ljava/lang/String;"; 324 | let val_1 = jni::objects::JValueGen::Object(jni::objects::JObject::from( 325 | self.jni_ref().new_string(target.into())?, 326 | )); 327 | args.push(val_1); 328 | sig += ")V"; 329 | let res = self 330 | .jni_ref() 331 | .call_method(&self.jni_object(), "pardon", sig.as_str(), args); 332 | self.jni_ref().translate_error(res)?; 333 | Ok(()) 334 | } 335 | 336 | pub fn instance_of(&self, other: impl Into) -> Result { 337 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 338 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 339 | } 340 | } 341 | impl<'mc> Into> for ProfileBanList<'mc> { 342 | fn into(self) -> crate::BanList<'mc> { 343 | crate::BanList::from_raw(&self.jni_ref(), self.1) 344 | .expect("Error converting ProfileBanList into crate::BanList") 345 | } 346 | } 347 | -------------------------------------------------------------------------------- /blackboxmc-rs-bukkit/src/block/banner/mod.rs: -------------------------------------------------------------------------------- 1 | #![allow(deprecated)] 2 | use blackboxmc_general::JNIInstantiatable; 3 | use blackboxmc_general::JNIRaw; 4 | use color_eyre::eyre::Result; 5 | #[repr(C)] 6 | pub struct PatternType<'mc>( 7 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 8 | pub(crate) jni::objects::JObject<'mc>, 9 | ); 10 | 11 | impl<'mc> JNIRaw<'mc> for PatternType<'mc> { 12 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 13 | self.0.clone() 14 | } 15 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 16 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 17 | } 18 | } 19 | impl<'mc> JNIInstantiatable<'mc> for PatternType<'mc> { 20 | fn from_raw( 21 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 22 | obj: jni::objects::JObject<'mc>, 23 | ) -> Result> { 24 | if obj.is_null() { 25 | return Err(eyre::eyre!("Tried to instantiate PatternType from null object.").into()); 26 | } 27 | let (valid, name) = env.validate_name(&obj, "org/bukkit/block/banner/PatternType")?; 28 | if !valid { 29 | Err(eyre::eyre!( 30 | "Invalid argument passed. Expected a PatternType object, got {}", 31 | name 32 | ) 33 | .into()) 34 | } else { 35 | Ok(Self(env.clone(), obj)) 36 | } 37 | } 38 | } 39 | 40 | impl<'mc> PatternType<'mc> { 41 | pub fn key(&self) -> Result, Box> { 42 | let sig = String::from("()Lorg/bukkit/NamespacedKey;"); 43 | let res = self 44 | .jni_ref() 45 | .call_method(&self.jni_object(), "getKey", sig.as_str(), vec![]); 46 | let res = self.jni_ref().translate_error(res)?; 47 | crate::NamespacedKey::from_raw(&self.jni_ref(), unsafe { 48 | jni::objects::JObject::from_raw(res.l()?.clone()) 49 | }) 50 | } 51 | #[deprecated] 52 | /// Returns the identifier used to represent this pattern type 53 | pub fn identifier(&self) -> Result> { 54 | let sig = String::from("()Ljava/lang/String;"); 55 | let res = 56 | self.jni_ref() 57 | .call_method(&self.jni_object(), "getIdentifier", sig.as_str(), vec![]); 58 | let res = self.jni_ref().translate_error(res)?; 59 | Ok(self 60 | .jni_ref() 61 | .get_string(unsafe { &jni::objects::JString::from_raw(res.as_jni().l) })? 62 | .to_string_lossy() 63 | .to_string()) 64 | } 65 | #[deprecated] 66 | /// Returns the pattern type which matches the passed identifier or null if no matches are found 67 | pub fn get_by_identifier( 68 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 69 | identifier: impl Into, 70 | ) -> Result>, Box> { 71 | let sig = String::from("(Ljava/lang/String;)Lorg/bukkit/block/banner/PatternType;"); 72 | let val_1 = jni::objects::JValueGen::Object(jni::objects::JObject::from( 73 | jni.new_string(identifier.into())?, 74 | )); 75 | let cls = jni.find_class("org/bukkit/block/banner/PatternType"); 76 | let cls = jni.translate_error_with_class(cls)?; 77 | let res = jni.call_static_method( 78 | cls, 79 | "getByIdentifier", 80 | sig.as_str(), 81 | vec![jni::objects::JValueGen::from(val_1)], 82 | ); 83 | let res = jni.translate_error(res)?; 84 | if unsafe { jni::objects::JObject::from_raw(res.as_jni().l) }.is_null() { 85 | return Ok(None); 86 | } 87 | let obj = res.l()?; 88 | Ok(Some(crate::block::banner::PatternType::from_raw( 89 | &jni, obj, 90 | )?)) 91 | } 92 | #[deprecated] 93 | 94 | pub fn values( 95 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 96 | ) -> Result, Box> { 97 | let sig = String::from("()Lorg/bukkit/block/banner/PatternType;"); 98 | let cls = jni.find_class("org/bukkit/block/banner/PatternType"); 99 | let cls = jni.translate_error_with_class(cls)?; 100 | let res = jni.call_static_method(cls, "values", sig.as_str(), vec![]); 101 | let res = jni.translate_error(res)?; 102 | let obj = res.l()?; 103 | crate::block::banner::PatternType::from_raw(&jni, obj) 104 | } 105 | #[deprecated] 106 | 107 | pub fn compare_to( 108 | &self, 109 | other: jni::objects::JObject<'mc>, 110 | ) -> Result> { 111 | let sig = String::from("(LT;)I"); 112 | let val_1 = jni::objects::JValueGen::Object(other); 113 | let res = self.jni_ref().call_method( 114 | &self.jni_object(), 115 | "compareTo", 116 | sig.as_str(), 117 | vec![jni::objects::JValueGen::from(val_1)], 118 | ); 119 | let res = self.jni_ref().translate_error(res)?; 120 | Ok(res.i()?) 121 | } 122 | #[deprecated] 123 | 124 | pub fn name(&self) -> Result> { 125 | let sig = String::from("()Ljava/lang/String;"); 126 | let res = self 127 | .jni_ref() 128 | .call_method(&self.jni_object(), "name", sig.as_str(), vec![]); 129 | let res = self.jni_ref().translate_error(res)?; 130 | Ok(self 131 | .jni_ref() 132 | .get_string(unsafe { &jni::objects::JString::from_raw(res.as_jni().l) })? 133 | .to_string_lossy() 134 | .to_string()) 135 | } 136 | #[deprecated] 137 | 138 | pub fn ordinal(&self) -> Result> { 139 | let sig = String::from("()I"); 140 | let res = self 141 | .jni_ref() 142 | .call_method(&self.jni_object(), "ordinal", sig.as_str(), vec![]); 143 | let res = self.jni_ref().translate_error(res)?; 144 | Ok(res.i()?) 145 | } 146 | 147 | pub fn instance_of(&self, other: impl Into) -> Result { 148 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 149 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 150 | } 151 | } 152 | impl<'mc> Into> for PatternType<'mc> { 153 | fn into(self) -> crate::util::OldEnum<'mc> { 154 | crate::util::OldEnum::from_raw(&self.jni_ref(), self.1) 155 | .expect("Error converting PatternType into crate::util::OldEnum") 156 | } 157 | } 158 | impl<'mc> Into> for PatternType<'mc> { 159 | fn into(self) -> crate::Keyed<'mc> { 160 | crate::Keyed::from_raw(&self.jni_ref(), self.1) 161 | .expect("Error converting PatternType into crate::Keyed") 162 | } 163 | } 164 | #[repr(C)] 165 | pub struct Pattern<'mc>( 166 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 167 | pub(crate) jni::objects::JObject<'mc>, 168 | ); 169 | 170 | impl<'mc> JNIRaw<'mc> for Pattern<'mc> { 171 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 172 | self.0.clone() 173 | } 174 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 175 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 176 | } 177 | } 178 | impl<'mc> JNIInstantiatable<'mc> for Pattern<'mc> { 179 | fn from_raw( 180 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 181 | obj: jni::objects::JObject<'mc>, 182 | ) -> Result> { 183 | if obj.is_null() { 184 | return Err(eyre::eyre!("Tried to instantiate Pattern from null object.").into()); 185 | } 186 | let (valid, name) = env.validate_name(&obj, "org/bukkit/block/banner/Pattern")?; 187 | if !valid { 188 | Err(eyre::eyre!( 189 | "Invalid argument passed. Expected a Pattern object, got {}", 190 | name 191 | ) 192 | .into()) 193 | } else { 194 | Ok(Self(env.clone(), obj)) 195 | } 196 | } 197 | } 198 | 199 | impl<'mc> Pattern<'mc> { 200 | /// Creates a new pattern from the specified color and 201 | /// pattern type 202 | pub fn new( 203 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 204 | color: impl Into>, 205 | pattern: std::option::Option>>, 206 | ) -> Result, Box> { 207 | let mut args = Vec::new(); 208 | let mut sig = String::from("("); 209 | sig += "Lorg/bukkit/DyeColor;"; 210 | let val_1 = jni::objects::JValueGen::Object(unsafe { 211 | jni::objects::JObject::from_raw(color.into().jni_object().clone()) 212 | }); 213 | args.push(val_1); 214 | if let Some(a) = pattern { 215 | sig += "Lorg/bukkit/block/banner/PatternType;"; 216 | let val_2 = jni::objects::JValueGen::Object(unsafe { 217 | jni::objects::JObject::from_raw(a.into().jni_object().clone()) 218 | }); 219 | args.push(val_2); 220 | } 221 | sig += ")V"; 222 | let cls = jni.find_class("org/bukkit/block/banner/Pattern"); 223 | let cls = jni.translate_error_with_class(cls)?; 224 | let res = jni.new_object(cls, sig.as_str(), args); 225 | let res = jni.translate_error_no_gen(res)?; 226 | crate::block::banner::Pattern::from_raw(&jni, res) 227 | } 228 | 229 | pub fn serialize( 230 | &self, 231 | ) -> Result, Box> { 232 | let sig = String::from("()Ljava/util/Map;"); 233 | let res = self 234 | .jni_ref() 235 | .call_method(&self.jni_object(), "serialize", sig.as_str(), vec![]); 236 | let res = self.jni_ref().translate_error(res)?; 237 | blackboxmc_java::util::JavaMap::from_raw(&self.jni_ref(), unsafe { 238 | jni::objects::JObject::from_raw(res.l()?.clone()) 239 | }) 240 | } 241 | /// Returns the color of the pattern 242 | pub fn color(&self) -> Result, Box> { 243 | let sig = String::from("()Lorg/bukkit/DyeColor;"); 244 | let res = self 245 | .jni_ref() 246 | .call_method(&self.jni_object(), "getColor", sig.as_str(), vec![]); 247 | let res = self.jni_ref().translate_error(res)?; 248 | crate::DyeColor::from_raw(&self.jni_ref(), unsafe { 249 | jni::objects::JObject::from_raw(res.l()?.clone()) 250 | }) 251 | } 252 | /// Returns the type of pattern 253 | pub fn pattern( 254 | &self, 255 | ) -> Result, Box> { 256 | let sig = String::from("()Lorg/bukkit/block/banner/PatternType;"); 257 | let res = 258 | self.jni_ref() 259 | .call_method(&self.jni_object(), "getPattern", sig.as_str(), vec![]); 260 | let res = self.jni_ref().translate_error(res)?; 261 | crate::block::banner::PatternType::from_raw(&self.jni_ref(), unsafe { 262 | jni::objects::JObject::from_raw(res.l()?.clone()) 263 | }) 264 | } 265 | 266 | pub fn hash_code(&self) -> Result> { 267 | let sig = String::from("()I"); 268 | let res = self 269 | .jni_ref() 270 | .call_method(&self.jni_object(), "hashCode", sig.as_str(), vec![]); 271 | let res = self.jni_ref().translate_error(res)?; 272 | Ok(res.i()?) 273 | } 274 | 275 | pub fn equals( 276 | &self, 277 | obj: jni::objects::JObject<'mc>, 278 | ) -> Result> { 279 | let sig = String::from("(Ljava/lang/Object;)Z"); 280 | let val_1 = jni::objects::JValueGen::Object(obj); 281 | let res = self.jni_ref().call_method( 282 | &self.jni_object(), 283 | "equals", 284 | sig.as_str(), 285 | vec![jni::objects::JValueGen::from(val_1)], 286 | ); 287 | let res = self.jni_ref().translate_error(res)?; 288 | Ok(res.z()?) 289 | } 290 | 291 | pub fn instance_of(&self, other: impl Into) -> Result { 292 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 293 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 294 | } 295 | } 296 | impl<'mc> Into> 297 | for Pattern<'mc> 298 | { 299 | fn into(self) -> crate::configuration::serialization::ConfigurationSerializable<'mc> { 300 | crate::configuration::serialization::ConfigurationSerializable::from_raw(&self.jni_ref(), self.1).expect("Error converting Pattern into crate::configuration::serialization::ConfigurationSerializable") 301 | } 302 | } 303 | -------------------------------------------------------------------------------- /blackboxmc-rs-bukkit/src/block/sign/mod.rs: -------------------------------------------------------------------------------- 1 | #![allow(deprecated)] 2 | use blackboxmc_general::JNIInstantiatable; 3 | use blackboxmc_general::JNIRaw; 4 | use color_eyre::eyre::Result; 5 | pub enum Side<'mc> { 6 | Front { inner: SideStruct<'mc> }, 7 | Back { inner: SideStruct<'mc> }, 8 | } 9 | impl<'mc> std::fmt::Display for Side<'mc> { 10 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 11 | match self { 12 | Side::Front { .. } => f.write_str("FRONT"), 13 | Side::Back { .. } => f.write_str("BACK"), 14 | } 15 | } 16 | } 17 | impl<'mc> std::ops::Deref for Side<'mc> { 18 | type Target = SideStruct<'mc>; 19 | fn deref(&self) -> & as std::ops::Deref>::Target { 20 | match self { 21 | Side::Front { inner } => inner, 22 | Side::Back { inner } => inner, 23 | } 24 | } 25 | } 26 | 27 | impl<'mc> Side<'mc> { 28 | pub fn value_of( 29 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 30 | arg0: impl Into, 31 | ) -> Result, Box> { 32 | let val_1 = jni::objects::JObject::from(env.new_string(arg0.into())?); 33 | let cls = env.find_class("org/bukkit/block/sign/Side"); 34 | let cls = env.translate_error_with_class(cls)?; 35 | let res = env.call_static_method( 36 | cls, 37 | "valueOf", 38 | "(Ljava/lang/String;)Lorg/bukkit/block/sign/Side;", 39 | vec![jni::objects::JValueGen::from(val_1)], 40 | ); 41 | let res = env.translate_error(res)?; 42 | let obj = res.l()?; 43 | let variant = env.call_method(&obj, "toString", "()Ljava/lang/String;", vec![]); 44 | let variant = env.translate_error(variant)?; 45 | let variant_str = env 46 | .get_string(unsafe { &jni::objects::JString::from_raw(variant.as_jni().l) })? 47 | .to_string_lossy() 48 | .to_string(); 49 | match variant_str.as_str() { 50 | "FRONT" => Ok(Side::Front { 51 | inner: SideStruct::from_raw(env, obj)?, 52 | }), 53 | "BACK" => Ok(Side::Back { 54 | inner: SideStruct::from_raw(env, obj)?, 55 | }), 56 | 57 | _ => Err(eyre::eyre!("String gaven for variant was invalid").into()), 58 | } 59 | } 60 | } 61 | 62 | #[repr(C)] 63 | pub struct SideStruct<'mc>( 64 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 65 | pub(crate) jni::objects::JObject<'mc>, 66 | ); 67 | 68 | impl<'mc> JNIRaw<'mc> for Side<'mc> { 69 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 70 | match self { 71 | Self::Front { inner } => inner.0.clone(), 72 | Self::Back { inner } => inner.0.clone(), 73 | } 74 | } 75 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 76 | match self { 77 | Self::Front { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) }, 78 | Self::Back { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) }, 79 | } 80 | } 81 | } 82 | impl<'mc> JNIInstantiatable<'mc> for Side<'mc> { 83 | fn from_raw( 84 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 85 | obj: jni::objects::JObject<'mc>, 86 | ) -> Result> { 87 | if obj.is_null() { 88 | return Err(eyre::eyre!("Tried to instantiate Side from null object.").into()); 89 | } 90 | let (valid, name) = env.validate_name(&obj, "org/bukkit/block/sign/Side")?; 91 | if !valid { 92 | Err(eyre::eyre!( 93 | "Invalid argument passed. Expected a Side object, got {}", 94 | name 95 | ) 96 | .into()) 97 | } else { 98 | let variant = env.call_method(&obj, "toString", "()Ljava/lang/String;", vec![]); 99 | let variant = env.translate_error(variant)?; 100 | let variant_str = env 101 | .get_string(unsafe { &jni::objects::JString::from_raw(variant.as_jni().l) })? 102 | .to_string_lossy() 103 | .to_string(); 104 | match variant_str.as_str() { 105 | "FRONT" => Ok(Side::Front { 106 | inner: SideStruct::from_raw(env, obj)?, 107 | }), 108 | "BACK" => Ok(Side::Back { 109 | inner: SideStruct::from_raw(env, obj)?, 110 | }), 111 | _ => Err(eyre::eyre!("String gaven for variant was invalid").into()), 112 | } 113 | } 114 | } 115 | } 116 | 117 | impl<'mc> JNIRaw<'mc> for SideStruct<'mc> { 118 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 119 | self.0.clone() 120 | } 121 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 122 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 123 | } 124 | } 125 | impl<'mc> JNIInstantiatable<'mc> for SideStruct<'mc> { 126 | fn from_raw( 127 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 128 | obj: jni::objects::JObject<'mc>, 129 | ) -> Result> { 130 | if obj.is_null() { 131 | return Err(eyre::eyre!("Tried to instantiate SideStruct from null object.").into()); 132 | } 133 | let (valid, name) = env.validate_name(&obj, "org/bukkit/block/sign/Side")?; 134 | if !valid { 135 | Err(eyre::eyre!( 136 | "Invalid argument passed. Expected a SideStruct object, got {}", 137 | name 138 | ) 139 | .into()) 140 | } else { 141 | Ok(Self(env.clone(), obj)) 142 | } 143 | } 144 | } 145 | 146 | impl<'mc> SideStruct<'mc> { 147 | pub fn values( 148 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 149 | ) -> Result, Box> { 150 | let sig = String::from("()Lorg/bukkit/block/sign/Side;"); 151 | let cls = jni.find_class("org/bukkit/block/sign/Side"); 152 | let cls = jni.translate_error_with_class(cls)?; 153 | let res = jni.call_static_method(cls, "values", sig.as_str(), vec![]); 154 | let res = jni.translate_error(res)?; 155 | let obj = res.l()?; 156 | crate::block::sign::Side::from_raw(&jni, obj) 157 | } 158 | 159 | pub fn instance_of(&self, other: impl Into) -> Result { 160 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 161 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 162 | } 163 | } 164 | #[repr(C)] 165 | pub struct SignSide<'mc>( 166 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 167 | pub(crate) jni::objects::JObject<'mc>, 168 | ); 169 | 170 | impl<'mc> JNIRaw<'mc> for SignSide<'mc> { 171 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 172 | self.0.clone() 173 | } 174 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 175 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 176 | } 177 | } 178 | impl<'mc> JNIInstantiatable<'mc> for SignSide<'mc> { 179 | fn from_raw( 180 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 181 | obj: jni::objects::JObject<'mc>, 182 | ) -> Result> { 183 | if obj.is_null() { 184 | return Err(eyre::eyre!("Tried to instantiate SignSide from null object.").into()); 185 | } 186 | let (valid, name) = env.validate_name(&obj, "org/bukkit/block/sign/SignSide")?; 187 | if !valid { 188 | Err(eyre::eyre!( 189 | "Invalid argument passed. Expected a SignSide object, got {}", 190 | name 191 | ) 192 | .into()) 193 | } else { 194 | Ok(Self(env.clone(), obj)) 195 | } 196 | } 197 | } 198 | 199 | impl<'mc> SignSide<'mc> { 200 | /// Gets all the lines of text currently on this side of the sign. 201 | pub fn lines(&self) -> Result> { 202 | let sig = String::from("()Ljava/lang/String;"); 203 | let res = self 204 | .jni_ref() 205 | .call_method(&self.jni_object(), "getLines", sig.as_str(), vec![]); 206 | let res = self.jni_ref().translate_error(res)?; 207 | Ok(self 208 | .jni_ref() 209 | .get_string(unsafe { &jni::objects::JString::from_raw(res.as_jni().l) })? 210 | .to_string_lossy() 211 | .to_string()) 212 | } 213 | /// Gets the line of text at the specified index on this side of the sign. 214 | /// 215 | /// For example, getLine(0) will return the first line of text. 216 | pub fn get_line(&self, index: i32) -> Result> { 217 | let sig = String::from("(I)Ljava/lang/String;"); 218 | let val_1 = jni::objects::JValueGen::Int(index); 219 | let res = self.jni_ref().call_method( 220 | &self.jni_object(), 221 | "getLine", 222 | sig.as_str(), 223 | vec![jni::objects::JValueGen::from(val_1)], 224 | ); 225 | let res = self.jni_ref().translate_error(res)?; 226 | Ok(self 227 | .jni_ref() 228 | .get_string(unsafe { &jni::objects::JString::from_raw(res.as_jni().l) })? 229 | .to_string_lossy() 230 | .to_string()) 231 | } 232 | /// Sets the line of text at the specified index on this side of the sign. 233 | /// 234 | /// For example, setLine(0, "Line One") will set the first line of text to 235 | /// "Line One". 236 | pub fn set_line( 237 | &self, 238 | index: i32, 239 | line: impl Into, 240 | ) -> Result<(), Box> { 241 | let sig = String::from("(ILjava/lang/String;)V"); 242 | let val_1 = jni::objects::JValueGen::Int(index); 243 | let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from( 244 | self.jni_ref().new_string(line.into())?, 245 | )); 246 | let res = self.jni_ref().call_method( 247 | &self.jni_object(), 248 | "setLine", 249 | sig.as_str(), 250 | vec![ 251 | jni::objects::JValueGen::from(val_1), 252 | jni::objects::JValueGen::from(val_2), 253 | ], 254 | ); 255 | self.jni_ref().translate_error(res)?; 256 | Ok(()) 257 | } 258 | /// Gets whether this side of the sign has glowing text. 259 | pub fn is_glowing_text(&self) -> Result> { 260 | let sig = String::from("()Z"); 261 | let res = 262 | self.jni_ref() 263 | .call_method(&self.jni_object(), "isGlowingText", sig.as_str(), vec![]); 264 | let res = self.jni_ref().translate_error(res)?; 265 | Ok(res.z()?) 266 | } 267 | /// Sets whether this side of the sign has glowing text. 268 | pub fn set_glowing_text(&self, glowing: bool) -> Result<(), Box> { 269 | let sig = String::from("(Z)V"); 270 | let val_1 = jni::objects::JValueGen::Bool(glowing.into()); 271 | let res = self.jni_ref().call_method( 272 | &self.jni_object(), 273 | "setGlowingText", 274 | sig.as_str(), 275 | vec![jni::objects::JValueGen::from(val_1)], 276 | ); 277 | self.jni_ref().translate_error(res)?; 278 | Ok(()) 279 | } 280 | /// Gets the color of this object. 281 | /// 282 | /// This may be null to represent the default color of an object, if the 283 | /// object has a special default color (e.g Shulkers). 284 | pub fn color(&self) -> Result>, Box> { 285 | let sig = String::from("()Lorg/bukkit/DyeColor;"); 286 | let res = self 287 | .jni_ref() 288 | .call_method(&self.jni_object(), "getColor", sig.as_str(), vec![]); 289 | let res = self.jni_ref().translate_error(res)?; 290 | if unsafe { jni::objects::JObject::from_raw(res.as_jni().l) }.is_null() { 291 | return Ok(None); 292 | } 293 | Ok(Some(crate::DyeColor::from_raw(&self.jni_ref(), unsafe { 294 | jni::objects::JObject::from_raw(res.l()?.clone()) 295 | })?)) 296 | } 297 | /// Sets the color of this object to the specified DyeColor. 298 | /// 299 | /// This may be null to represent the default color of an object, if the 300 | /// object has a special default color (e.g Shulkers). 301 | pub fn set_color( 302 | &self, 303 | color: impl Into>, 304 | ) -> Result<(), Box> { 305 | let sig = String::from("(Lorg/bukkit/DyeColor;)V"); 306 | let val_1 = jni::objects::JValueGen::Object(unsafe { 307 | jni::objects::JObject::from_raw(color.into().jni_object().clone()) 308 | }); 309 | let res = self.jni_ref().call_method( 310 | &self.jni_object(), 311 | "setColor", 312 | sig.as_str(), 313 | vec![jni::objects::JValueGen::from(val_1)], 314 | ); 315 | self.jni_ref().translate_error(res)?; 316 | Ok(()) 317 | } 318 | 319 | pub fn instance_of(&self, other: impl Into) -> Result { 320 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 321 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 322 | } 323 | } 324 | impl<'mc> Into> for SignSide<'mc> { 325 | fn into(self) -> crate::material::Colorable<'mc> { 326 | crate::material::Colorable::from_raw(&self.jni_ref(), self.1) 327 | .expect("Error converting SignSide into crate::material::Colorable") 328 | } 329 | } 330 | -------------------------------------------------------------------------------- /blackboxmc-rs-bukkit/src/configuration/serialization/mod.rs: -------------------------------------------------------------------------------- 1 | #![allow(deprecated)] 2 | use blackboxmc_general::JNIInstantiatable; 3 | use blackboxmc_general::JNIRaw; 4 | use color_eyre::eyre::Result; 5 | #[repr(C)] 6 | pub struct ConfigurationSerialization<'mc>( 7 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 8 | pub(crate) jni::objects::JObject<'mc>, 9 | ); 10 | 11 | impl<'mc> JNIRaw<'mc> for ConfigurationSerialization<'mc> { 12 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 13 | self.0.clone() 14 | } 15 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 16 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 17 | } 18 | } 19 | impl<'mc> JNIInstantiatable<'mc> for ConfigurationSerialization<'mc> { 20 | fn from_raw( 21 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 22 | obj: jni::objects::JObject<'mc>, 23 | ) -> Result> { 24 | if obj.is_null() { 25 | return Err(eyre::eyre!( 26 | "Tried to instantiate ConfigurationSerialization from null object." 27 | ) 28 | .into()); 29 | } 30 | let (valid, name) = env.validate_name( 31 | &obj, 32 | "org/bukkit/configuration/serialization/ConfigurationSerialization", 33 | )?; 34 | if !valid { 35 | Err(eyre::eyre!( 36 | "Invalid argument passed. Expected a ConfigurationSerialization object, got {}", 37 | name 38 | ) 39 | .into()) 40 | } else { 41 | Ok(Self(env.clone(), obj)) 42 | } 43 | } 44 | } 45 | 46 | impl<'mc> ConfigurationSerialization<'mc> { 47 | pub fn deserialize( 48 | &self, 49 | val_args: impl Into>, 50 | ) -> Result< 51 | Option>, 52 | Box, 53 | > { 54 | let sig = String::from( 55 | "(Ljava/util/Map;)Lorg/bukkit/configuration/serialization/ConfigurationSerializable;", 56 | ); 57 | let val_1 = jni::objects::JValueGen::Object(unsafe { 58 | jni::objects::JObject::from_raw(val_args.into().jni_object().clone()) 59 | }); 60 | let res = self.jni_ref().call_method( 61 | &self.jni_object(), 62 | "deserialize", 63 | sig.as_str(), 64 | vec![jni::objects::JValueGen::from(val_1)], 65 | ); 66 | let res = self.jni_ref().translate_error(res)?; 67 | if unsafe { jni::objects::JObject::from_raw(res.as_jni().l) }.is_null() { 68 | return Ok(None); 69 | } 70 | Ok(Some( 71 | crate::configuration::serialization::ConfigurationSerializable::from_raw( 72 | &self.jni_ref(), 73 | unsafe { jni::objects::JObject::from_raw(res.l()?.clone()) }, 74 | )?, 75 | )) 76 | } 77 | /// Attempts to deserialize the given arguments into a new instance of the 78 | /// given class. 79 | /// 80 | /// The class must implement {@link ConfigurationSerializable}, including 81 | /// the extra methods as specified in the javadoc of 82 | /// ConfigurationSerializable. 83 | /// 84 | /// If a new instance could not be made, an example being the class not 85 | /// fully implementing the interface, null will be returned. 86 | pub fn deserialize_object( 87 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 88 | val_args: impl Into>, 89 | clazz: std::option::Option>, 90 | ) -> Result< 91 | Option>, 92 | Box, 93 | > { 94 | let mut args = Vec::new(); 95 | let mut sig = String::from("("); 96 | sig += "Ljava/util/Map;"; 97 | let val_1 = jni::objects::JValueGen::Object(unsafe { 98 | jni::objects::JObject::from_raw(val_args.into().jni_object().clone()) 99 | }); 100 | args.push(val_1); 101 | if let Some(a) = clazz { 102 | sig += "Ljava/lang/Class;"; 103 | let val_2 = jni::objects::JValueGen::Object(a.into()); 104 | args.push(val_2); 105 | } 106 | sig += ")Lorg/bukkit/configuration/serialization/ConfigurationSerializable;"; 107 | let cls = 108 | jni.find_class("org/bukkit/configuration/serialization/ConfigurationSerialization"); 109 | let cls = jni.translate_error_with_class(cls)?; 110 | let res = jni.call_static_method(cls, "deserializeObject", sig.as_str(), args); 111 | let res = jni.translate_error(res)?; 112 | if unsafe { jni::objects::JObject::from_raw(res.as_jni().l) }.is_null() { 113 | return Ok(None); 114 | } 115 | let obj = res.l()?; 116 | Ok(Some( 117 | crate::configuration::serialization::ConfigurationSerializable::from_raw(&jni, obj)?, 118 | )) 119 | } 120 | /// Registers the given alias to the specified {@link 121 | /// ConfigurationSerializable} class 122 | pub fn register_class( 123 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 124 | clazz: jni::objects::JClass<'mc>, 125 | alias: std::option::Option>, 126 | ) -> Result<(), Box> { 127 | let mut args = Vec::new(); 128 | let mut sig = String::from("("); 129 | sig += "Ljava/lang/Class;"; 130 | let val_1 = jni::objects::JValueGen::Object(clazz.into()); 131 | args.push(val_1); 132 | if let Some(a) = alias { 133 | sig += "Ljava/lang/String;"; 134 | let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from( 135 | jni.new_string(a.into())?, 136 | )); 137 | args.push(val_2); 138 | } 139 | sig += ")V"; 140 | let cls = 141 | jni.find_class("org/bukkit/configuration/serialization/ConfigurationSerialization"); 142 | let cls = jni.translate_error_with_class(cls)?; 143 | let res = jni.call_static_method(cls, "registerClass", sig.as_str(), args); 144 | jni.translate_error(res)?; 145 | Ok(()) 146 | } 147 | /// Unregisters any aliases for the specified {@link 148 | /// ConfigurationSerializable} class 149 | pub fn unregister_class( 150 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 151 | clazz: jni::objects::JClass<'mc>, 152 | ) -> Result<(), Box> { 153 | let mut args = Vec::new(); 154 | let mut sig = String::from("("); 155 | sig += "Ljava/lang/Class;"; 156 | let val_1 = jni::objects::JValueGen::Object(clazz.into()); 157 | args.push(val_1); 158 | sig += ")V"; 159 | let cls = 160 | jni.find_class("org/bukkit/configuration/serialization/ConfigurationSerialization"); 161 | let cls = jni.translate_error_with_class(cls)?; 162 | let res = jni.call_static_method(cls, "unregisterClass", sig.as_str(), args); 163 | jni.translate_error(res)?; 164 | Ok(()) 165 | } 166 | /// Attempts to get a registered {@link ConfigurationSerializable} class by 167 | /// its alias 168 | pub fn get_class_by_alias( 169 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 170 | alias: impl Into, 171 | ) -> Result>, Box> { 172 | let sig = String::from("(Ljava/lang/String;)Ljava/lang/Class;"); 173 | let val_1 = jni::objects::JValueGen::Object(jni::objects::JObject::from( 174 | jni.new_string(alias.into())?, 175 | )); 176 | let cls = 177 | jni.find_class("org/bukkit/configuration/serialization/ConfigurationSerialization"); 178 | let cls = jni.translate_error_with_class(cls)?; 179 | let res = jni.call_static_method( 180 | cls, 181 | "getClassByAlias", 182 | sig.as_str(), 183 | vec![jni::objects::JValueGen::from(val_1)], 184 | ); 185 | let res = jni.translate_error(res)?; 186 | if unsafe { jni::objects::JObject::from_raw(res.as_jni().l) }.is_null() { 187 | return Ok(None); 188 | } 189 | Ok(Some(unsafe { 190 | jni::objects::JClass::from_raw(res.as_jni().l) 191 | })) 192 | } 193 | /// Gets the correct alias for the given {@link ConfigurationSerializable} 194 | /// class 195 | pub fn get_alias( 196 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 197 | clazz: jni::objects::JClass<'mc>, 198 | ) -> Result> { 199 | let sig = String::from("(Ljava/lang/Class;)Ljava/lang/String;"); 200 | let val_1 = jni::objects::JValueGen::Object(clazz.into()); 201 | let cls = 202 | jni.find_class("org/bukkit/configuration/serialization/ConfigurationSerialization"); 203 | let cls = jni.translate_error_with_class(cls)?; 204 | let res = jni.call_static_method( 205 | cls, 206 | "getAlias", 207 | sig.as_str(), 208 | vec![jni::objects::JValueGen::from(val_1)], 209 | ); 210 | let res = jni.translate_error(res)?; 211 | Ok(jni 212 | .get_string(unsafe { &jni::objects::JString::from_raw(res.as_jni().l) })? 213 | .to_string_lossy() 214 | .to_string()) 215 | } 216 | 217 | pub fn instance_of(&self, other: impl Into) -> Result { 218 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 219 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 220 | } 221 | } 222 | #[repr(C)] 223 | pub struct ConfigurationSerializable<'mc>( 224 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 225 | pub(crate) jni::objects::JObject<'mc>, 226 | ); 227 | 228 | impl<'mc> JNIRaw<'mc> for ConfigurationSerializable<'mc> { 229 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 230 | self.0.clone() 231 | } 232 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 233 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 234 | } 235 | } 236 | impl<'mc> JNIInstantiatable<'mc> for ConfigurationSerializable<'mc> { 237 | fn from_raw( 238 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 239 | obj: jni::objects::JObject<'mc>, 240 | ) -> Result> { 241 | if obj.is_null() { 242 | return Err(eyre::eyre!( 243 | "Tried to instantiate ConfigurationSerializable from null object." 244 | ) 245 | .into()); 246 | } 247 | let (valid, name) = env.validate_name( 248 | &obj, 249 | "org/bukkit/configuration/serialization/ConfigurationSerializable", 250 | )?; 251 | if !valid { 252 | Err(eyre::eyre!( 253 | "Invalid argument passed. Expected a ConfigurationSerializable object, got {}", 254 | name 255 | ) 256 | .into()) 257 | } else { 258 | Ok(Self(env.clone(), obj)) 259 | } 260 | } 261 | } 262 | 263 | impl<'mc> ConfigurationSerializable<'mc> { 264 | pub fn from_extendable( 265 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 266 | plugin: &'mc crate::plugin::Plugin, 267 | address: i32, 268 | lib_name: String, 269 | name: String, 270 | ) -> Result> { 271 | let obj = unsafe { plugin.new_extendable(address, "ConfigSerializable", name, lib_name) }?; 272 | Self::from_raw(env, obj) 273 | } 274 | /// Creates a Map representation of this class. 275 | /// 276 | /// This class must provide a method to restore this class, as defined in 277 | /// the {@link ConfigurationSerializable} interface javadocs. 278 | pub fn serialize( 279 | &self, 280 | ) -> Result, Box> { 281 | let sig = String::from("()Ljava/util/Map;"); 282 | let res = self 283 | .jni_ref() 284 | .call_method(&self.jni_object(), "serialize", sig.as_str(), vec![]); 285 | let res = self.jni_ref().translate_error(res)?; 286 | blackboxmc_java::util::JavaMap::from_raw(&self.jni_ref(), unsafe { 287 | jni::objects::JObject::from_raw(res.l()?.clone()) 288 | }) 289 | } 290 | 291 | pub fn instance_of(&self, other: impl Into) -> Result { 292 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 293 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 294 | } 295 | } 296 | #[repr(C)] 297 | pub struct SerializableAs<'mc>( 298 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 299 | pub(crate) jni::objects::JObject<'mc>, 300 | ); 301 | 302 | impl<'mc> JNIRaw<'mc> for SerializableAs<'mc> { 303 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 304 | self.0.clone() 305 | } 306 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 307 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 308 | } 309 | } 310 | impl<'mc> JNIInstantiatable<'mc> for SerializableAs<'mc> { 311 | fn from_raw( 312 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 313 | obj: jni::objects::JObject<'mc>, 314 | ) -> Result> { 315 | if obj.is_null() { 316 | return Err( 317 | eyre::eyre!("Tried to instantiate SerializableAs from null object.").into(), 318 | ); 319 | } 320 | let (valid, name) = env.validate_name( 321 | &obj, 322 | "org/bukkit/configuration/serialization/SerializableAs", 323 | )?; 324 | if !valid { 325 | Err(eyre::eyre!( 326 | "Invalid argument passed. Expected a SerializableAs object, got {}", 327 | name 328 | ) 329 | .into()) 330 | } else { 331 | Ok(Self(env.clone(), obj)) 332 | } 333 | } 334 | } 335 | 336 | impl<'mc> SerializableAs<'mc> { 337 | pub fn instance_of(&self, other: impl Into) -> Result { 338 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 339 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 340 | } 341 | } 342 | #[repr(C)] 343 | pub struct DelegateDeserialization<'mc>( 344 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 345 | pub(crate) jni::objects::JObject<'mc>, 346 | ); 347 | 348 | impl<'mc> JNIRaw<'mc> for DelegateDeserialization<'mc> { 349 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 350 | self.0.clone() 351 | } 352 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 353 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 354 | } 355 | } 356 | impl<'mc> JNIInstantiatable<'mc> for DelegateDeserialization<'mc> { 357 | fn from_raw( 358 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 359 | obj: jni::objects::JObject<'mc>, 360 | ) -> Result> { 361 | if obj.is_null() { 362 | return Err(eyre::eyre!( 363 | "Tried to instantiate DelegateDeserialization from null object." 364 | ) 365 | .into()); 366 | } 367 | let (valid, name) = env.validate_name( 368 | &obj, 369 | "org/bukkit/configuration/serialization/DelegateDeserialization", 370 | )?; 371 | if !valid { 372 | Err(eyre::eyre!( 373 | "Invalid argument passed. Expected a DelegateDeserialization object, got {}", 374 | name 375 | ) 376 | .into()) 377 | } else { 378 | Ok(Self(env.clone(), obj)) 379 | } 380 | } 381 | } 382 | 383 | impl<'mc> DelegateDeserialization<'mc> { 384 | pub fn instance_of(&self, other: impl Into) -> Result { 385 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 386 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 387 | } 388 | } 389 | -------------------------------------------------------------------------------- /blackboxmc-rs-bukkit/src/generator/structure/mod.rs: -------------------------------------------------------------------------------- 1 | #![allow(deprecated)] 2 | use blackboxmc_general::JNIInstantiatable; 3 | use blackboxmc_general::JNIRaw; 4 | use color_eyre::eyre::Result; 5 | #[repr(C)] 6 | pub struct Structure<'mc>( 7 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 8 | pub(crate) jni::objects::JObject<'mc>, 9 | ); 10 | 11 | impl<'mc> JNIRaw<'mc> for Structure<'mc> { 12 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 13 | self.0.clone() 14 | } 15 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 16 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 17 | } 18 | } 19 | impl<'mc> JNIInstantiatable<'mc> for Structure<'mc> { 20 | fn from_raw( 21 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 22 | obj: jni::objects::JObject<'mc>, 23 | ) -> Result> { 24 | if obj.is_null() { 25 | return Err(eyre::eyre!("Tried to instantiate Structure from null object.").into()); 26 | } 27 | let (valid, name) = env.validate_name(&obj, "org/bukkit/generator/structure/Structure")?; 28 | if !valid { 29 | Err(eyre::eyre!( 30 | "Invalid argument passed. Expected a Structure object, got {}", 31 | name 32 | ) 33 | .into()) 34 | } else { 35 | Ok(Self(env.clone(), obj)) 36 | } 37 | } 38 | } 39 | 40 | impl<'mc> Structure<'mc> { 41 | pub fn new( 42 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 43 | ) -> Result, Box> { 44 | let sig = String::from("()V"); 45 | let cls = jni.find_class("org/bukkit/generator/structure/Structure"); 46 | let cls = jni.translate_error_with_class(cls)?; 47 | let res = jni.new_object(cls, sig.as_str(), vec![]); 48 | let res = jni.translate_error_no_gen(res)?; 49 | crate::generator::structure::Structure::from_raw(&jni, res) 50 | } 51 | /// Return the namespaced identifier for this object. 52 | pub fn key(&self) -> Result, Box> { 53 | let sig = String::from("()Lorg/bukkit/NamespacedKey;"); 54 | let res = self 55 | .jni_ref() 56 | .call_method(&self.jni_object(), "getKey", sig.as_str(), vec![]); 57 | let res = self.jni_ref().translate_error(res)?; 58 | crate::NamespacedKey::from_raw(&self.jni_ref(), unsafe { 59 | jni::objects::JObject::from_raw(res.l()?.clone()) 60 | }) 61 | } 62 | 63 | pub fn instance_of(&self, other: impl Into) -> Result { 64 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 65 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 66 | } 67 | } 68 | impl<'mc> Into> for Structure<'mc> { 69 | fn into(self) -> crate::Keyed<'mc> { 70 | crate::Keyed::from_raw(&self.jni_ref(), self.1) 71 | .expect("Error converting Structure into crate::Keyed") 72 | } 73 | } 74 | #[repr(C)] 75 | pub struct StructurePiece<'mc>( 76 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 77 | pub(crate) jni::objects::JObject<'mc>, 78 | ); 79 | 80 | impl<'mc> JNIRaw<'mc> for StructurePiece<'mc> { 81 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 82 | self.0.clone() 83 | } 84 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 85 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 86 | } 87 | } 88 | impl<'mc> JNIInstantiatable<'mc> for StructurePiece<'mc> { 89 | fn from_raw( 90 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 91 | obj: jni::objects::JObject<'mc>, 92 | ) -> Result> { 93 | if obj.is_null() { 94 | return Err( 95 | eyre::eyre!("Tried to instantiate StructurePiece from null object.").into(), 96 | ); 97 | } 98 | let (valid, name) = 99 | env.validate_name(&obj, "org/bukkit/generator/structure/StructurePiece")?; 100 | if !valid { 101 | Err(eyre::eyre!( 102 | "Invalid argument passed. Expected a StructurePiece object, got {}", 103 | name 104 | ) 105 | .into()) 106 | } else { 107 | Ok(Self(env.clone(), obj)) 108 | } 109 | } 110 | } 111 | 112 | impl<'mc> StructurePiece<'mc> { 113 | /// Gets the bounding box of this structure piece. 114 | pub fn bounding_box( 115 | &self, 116 | ) -> Result, Box> { 117 | let sig = String::from("()Lorg/bukkit/util/BoundingBox;"); 118 | let res = 119 | self.jni_ref() 120 | .call_method(&self.jni_object(), "getBoundingBox", sig.as_str(), vec![]); 121 | let res = self.jni_ref().translate_error(res)?; 122 | crate::util::BoundingBox::from_raw(&self.jni_ref(), unsafe { 123 | jni::objects::JObject::from_raw(res.l()?.clone()) 124 | }) 125 | } 126 | 127 | pub fn instance_of(&self, other: impl Into) -> Result { 128 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 129 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 130 | } 131 | } 132 | #[repr(C)] 133 | pub struct GeneratedStructure<'mc>( 134 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 135 | pub(crate) jni::objects::JObject<'mc>, 136 | ); 137 | 138 | impl<'mc> JNIRaw<'mc> for GeneratedStructure<'mc> { 139 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 140 | self.0.clone() 141 | } 142 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 143 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 144 | } 145 | } 146 | impl<'mc> JNIInstantiatable<'mc> for GeneratedStructure<'mc> { 147 | fn from_raw( 148 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 149 | obj: jni::objects::JObject<'mc>, 150 | ) -> Result> { 151 | if obj.is_null() { 152 | return Err( 153 | eyre::eyre!("Tried to instantiate GeneratedStructure from null object.").into(), 154 | ); 155 | } 156 | let (valid, name) = 157 | env.validate_name(&obj, "org/bukkit/generator/structure/GeneratedStructure")?; 158 | if !valid { 159 | Err(eyre::eyre!( 160 | "Invalid argument passed. Expected a GeneratedStructure object, got {}", 161 | name 162 | ) 163 | .into()) 164 | } else { 165 | Ok(Self(env.clone(), obj)) 166 | } 167 | } 168 | } 169 | 170 | impl<'mc> GeneratedStructure<'mc> { 171 | /// Gets the bounding box of this placed structure. 172 | pub fn bounding_box( 173 | &self, 174 | ) -> Result, Box> { 175 | let sig = String::from("()Lorg/bukkit/util/BoundingBox;"); 176 | let res = 177 | self.jni_ref() 178 | .call_method(&self.jni_object(), "getBoundingBox", sig.as_str(), vec![]); 179 | let res = self.jni_ref().translate_error(res)?; 180 | crate::util::BoundingBox::from_raw(&self.jni_ref(), unsafe { 181 | jni::objects::JObject::from_raw(res.l()?.clone()) 182 | }) 183 | } 184 | /// Gets the structure that this PlacedStructure represents. 185 | pub fn structure( 186 | &self, 187 | ) -> Result, Box> { 188 | let sig = String::from("()Lorg/bukkit/generator/structure/Structure;"); 189 | let res = 190 | self.jni_ref() 191 | .call_method(&self.jni_object(), "getStructure", sig.as_str(), vec![]); 192 | let res = self.jni_ref().translate_error(res)?; 193 | crate::generator::structure::Structure::from_raw(&self.jni_ref(), unsafe { 194 | jni::objects::JObject::from_raw(res.l()?.clone()) 195 | }) 196 | } 197 | /// Gets all the {@link StructurePiece} that make up this PlacedStructure. 198 | pub fn pieces( 199 | &self, 200 | ) -> Result>, Box> 201 | { 202 | let sig = String::from("()Ljava/util/Collection;"); 203 | let res = self 204 | .jni_ref() 205 | .call_method(&self.jni_object(), "getPieces", sig.as_str(), vec![]); 206 | let res = self.jni_ref().translate_error(res)?; 207 | let mut new_vec = Vec::new(); 208 | let col = blackboxmc_java::util::JavaCollection::from_raw(&self.jni_ref(), res.l()?)?; 209 | let iter = col.iterator()?; 210 | while iter.has_next()? { 211 | let obj = iter.next()?; 212 | new_vec.push(crate::generator::structure::StructurePiece::from_raw( 213 | &self.jni_ref(), 214 | obj, 215 | )?); 216 | } 217 | Ok(new_vec) 218 | } 219 | /// Returns a custom tag container capable of storing tags on the object. 220 | /// Note that the tags stored on this container are all stored under their 221 | /// own custom namespace therefore modifying default tags using this 222 | /// {@link PersistentDataHolder} is impossible. 223 | pub fn persistent_data_container( 224 | &self, 225 | ) -> Result, Box> { 226 | let args = Vec::new(); 227 | let mut sig = String::from("("); 228 | sig += ")Lorg/bukkit/persistence/PersistentDataContainer;"; 229 | let res = self.jni_ref().call_method( 230 | &self.jni_object(), 231 | "getPersistentDataContainer", 232 | sig.as_str(), 233 | args, 234 | ); 235 | let res = self.jni_ref().translate_error(res)?; 236 | crate::persistence::PersistentDataContainer::from_raw(&self.jni_ref(), unsafe { 237 | jni::objects::JObject::from_raw(res.l()?.clone()) 238 | }) 239 | } 240 | 241 | pub fn instance_of(&self, other: impl Into) -> Result { 242 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 243 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 244 | } 245 | } 246 | impl<'mc> Into> for GeneratedStructure<'mc> { 247 | fn into(self) -> crate::persistence::PersistentDataHolder<'mc> { 248 | crate::persistence::PersistentDataHolder::from_raw(&self.jni_ref(), self.1).expect( 249 | "Error converting GeneratedStructure into crate::persistence::PersistentDataHolder", 250 | ) 251 | } 252 | } 253 | #[repr(C)] 254 | pub struct StructureType<'mc>( 255 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 256 | pub(crate) jni::objects::JObject<'mc>, 257 | ); 258 | 259 | impl<'mc> JNIRaw<'mc> for StructureType<'mc> { 260 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 261 | self.0.clone() 262 | } 263 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 264 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 265 | } 266 | } 267 | impl<'mc> JNIInstantiatable<'mc> for StructureType<'mc> { 268 | fn from_raw( 269 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 270 | obj: jni::objects::JObject<'mc>, 271 | ) -> Result> { 272 | if obj.is_null() { 273 | return Err(eyre::eyre!("Tried to instantiate StructureType from null object.").into()); 274 | } 275 | let (valid, name) = 276 | env.validate_name(&obj, "org/bukkit/generator/structure/StructureType")?; 277 | if !valid { 278 | Err(eyre::eyre!( 279 | "Invalid argument passed. Expected a StructureType object, got {}", 280 | name 281 | ) 282 | .into()) 283 | } else { 284 | Ok(Self(env.clone(), obj)) 285 | } 286 | } 287 | } 288 | 289 | impl<'mc> StructureType<'mc> { 290 | pub fn new( 291 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 292 | ) -> Result, Box> { 293 | let sig = String::from("()V"); 294 | let cls = jni.find_class("org/bukkit/generator/structure/StructureType"); 295 | let cls = jni.translate_error_with_class(cls)?; 296 | let res = jni.new_object(cls, sig.as_str(), vec![]); 297 | let res = jni.translate_error_no_gen(res)?; 298 | crate::generator::structure::StructureType::from_raw(&jni, res) 299 | } 300 | /// Return the namespaced identifier for this object. 301 | pub fn key(&self) -> Result, Box> { 302 | let sig = String::from("()Lorg/bukkit/NamespacedKey;"); 303 | let res = self 304 | .jni_ref() 305 | .call_method(&self.jni_object(), "getKey", sig.as_str(), vec![]); 306 | let res = self.jni_ref().translate_error(res)?; 307 | crate::NamespacedKey::from_raw(&self.jni_ref(), unsafe { 308 | jni::objects::JObject::from_raw(res.l()?.clone()) 309 | }) 310 | } 311 | 312 | pub fn instance_of(&self, other: impl Into) -> Result { 313 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 314 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 315 | } 316 | } 317 | impl<'mc> Into> for StructureType<'mc> { 318 | fn into(self) -> crate::Keyed<'mc> { 319 | crate::Keyed::from_raw(&self.jni_ref(), self.1) 320 | .expect("Error converting StructureType into crate::Keyed") 321 | } 322 | } 323 | -------------------------------------------------------------------------------- /blackboxmc-rs-bukkit/src/inventory/meta/trim/mod.rs: -------------------------------------------------------------------------------- 1 | #![allow(deprecated)] 2 | use blackboxmc_general::JNIInstantiatable; 3 | use blackboxmc_general::JNIRaw; 4 | use color_eyre::eyre::Result; 5 | #[repr(C)] 6 | pub struct ArmorTrim<'mc>( 7 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 8 | pub(crate) jni::objects::JObject<'mc>, 9 | ); 10 | 11 | impl<'mc> JNIRaw<'mc> for ArmorTrim<'mc> { 12 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 13 | self.0.clone() 14 | } 15 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 16 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 17 | } 18 | } 19 | impl<'mc> JNIInstantiatable<'mc> for ArmorTrim<'mc> { 20 | fn from_raw( 21 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 22 | obj: jni::objects::JObject<'mc>, 23 | ) -> Result> { 24 | if obj.is_null() { 25 | return Err(eyre::eyre!("Tried to instantiate ArmorTrim from null object.").into()); 26 | } 27 | let (valid, name) = env.validate_name(&obj, "org/bukkit/inventory/meta/trim/ArmorTrim")?; 28 | if !valid { 29 | Err(eyre::eyre!( 30 | "Invalid argument passed. Expected a ArmorTrim object, got {}", 31 | name 32 | ) 33 | .into()) 34 | } else { 35 | Ok(Self(env.clone(), obj)) 36 | } 37 | } 38 | } 39 | 40 | impl<'mc> ArmorTrim<'mc> { 41 | /// Create a new {@link ArmorTrim} given a {@link TrimMaterial} and 42 | /// {@link TrimPattern}. 43 | pub fn new( 44 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 45 | material: impl Into>, 46 | pattern: impl Into>, 47 | ) -> Result, Box> { 48 | let sig = String::from("(Lorg/bukkit/inventory/meta/trim/TrimMaterial;Lorg/bukkit/inventory/meta/trim/TrimPattern;)V"); 49 | let val_1 = jni::objects::JValueGen::Object(unsafe { 50 | jni::objects::JObject::from_raw(material.into().jni_object().clone()) 51 | }); 52 | let val_2 = jni::objects::JValueGen::Object(unsafe { 53 | jni::objects::JObject::from_raw(pattern.into().jni_object().clone()) 54 | }); 55 | let cls = jni.find_class("org/bukkit/inventory/meta/trim/ArmorTrim"); 56 | let cls = jni.translate_error_with_class(cls)?; 57 | let res = jni.new_object( 58 | cls, 59 | sig.as_str(), 60 | vec![ 61 | jni::objects::JValueGen::from(val_1), 62 | jni::objects::JValueGen::from(val_2), 63 | ], 64 | ); 65 | let res = jni.translate_error_no_gen(res)?; 66 | crate::inventory::meta::trim::ArmorTrim::from_raw(&jni, res) 67 | } 68 | /// Get the {@link TrimMaterial} for this armor trim. 69 | pub fn material( 70 | &self, 71 | ) -> Result, Box> { 72 | let sig = String::from("()Lorg/bukkit/inventory/meta/trim/TrimMaterial;"); 73 | let res = 74 | self.jni_ref() 75 | .call_method(&self.jni_object(), "getMaterial", sig.as_str(), vec![]); 76 | let res = self.jni_ref().translate_error(res)?; 77 | crate::inventory::meta::trim::TrimMaterial::from_raw(&self.jni_ref(), unsafe { 78 | jni::objects::JObject::from_raw(res.l()?.clone()) 79 | }) 80 | } 81 | /// Get the {@link TrimPattern} for this armor trim. 82 | pub fn pattern( 83 | &self, 84 | ) -> Result, Box> { 85 | let sig = String::from("()Lorg/bukkit/inventory/meta/trim/TrimPattern;"); 86 | let res = 87 | self.jni_ref() 88 | .call_method(&self.jni_object(), "getPattern", sig.as_str(), vec![]); 89 | let res = self.jni_ref().translate_error(res)?; 90 | crate::inventory::meta::trim::TrimPattern::from_raw(&self.jni_ref(), unsafe { 91 | jni::objects::JObject::from_raw(res.l()?.clone()) 92 | }) 93 | } 94 | 95 | pub fn hash_code(&self) -> Result> { 96 | let sig = String::from("()I"); 97 | let res = self 98 | .jni_ref() 99 | .call_method(&self.jni_object(), "hashCode", sig.as_str(), vec![]); 100 | let res = self.jni_ref().translate_error(res)?; 101 | Ok(res.i()?) 102 | } 103 | 104 | pub fn equals( 105 | &self, 106 | obj: jni::objects::JObject<'mc>, 107 | ) -> Result> { 108 | let sig = String::from("(Ljava/lang/Object;)Z"); 109 | let val_1 = jni::objects::JValueGen::Object(obj); 110 | let res = self.jni_ref().call_method( 111 | &self.jni_object(), 112 | "equals", 113 | sig.as_str(), 114 | vec![jni::objects::JValueGen::from(val_1)], 115 | ); 116 | let res = self.jni_ref().translate_error(res)?; 117 | Ok(res.z()?) 118 | } 119 | 120 | pub fn instance_of(&self, other: impl Into) -> Result { 121 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 122 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 123 | } 124 | } 125 | #[repr(C)] 126 | pub struct TrimPattern<'mc>( 127 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 128 | pub(crate) jni::objects::JObject<'mc>, 129 | ); 130 | 131 | impl<'mc> JNIRaw<'mc> for TrimPattern<'mc> { 132 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 133 | self.0.clone() 134 | } 135 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 136 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 137 | } 138 | } 139 | impl<'mc> JNIInstantiatable<'mc> for TrimPattern<'mc> { 140 | fn from_raw( 141 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 142 | obj: jni::objects::JObject<'mc>, 143 | ) -> Result> { 144 | if obj.is_null() { 145 | return Err(eyre::eyre!("Tried to instantiate TrimPattern from null object.").into()); 146 | } 147 | let (valid, name) = 148 | env.validate_name(&obj, "org/bukkit/inventory/meta/trim/TrimPattern")?; 149 | if !valid { 150 | Err(eyre::eyre!( 151 | "Invalid argument passed. Expected a TrimPattern object, got {}", 152 | name 153 | ) 154 | .into()) 155 | } else { 156 | Ok(Self(env.clone(), obj)) 157 | } 158 | } 159 | } 160 | 161 | impl<'mc> TrimPattern<'mc> { 162 | /// Return the namespaced identifier for this object. 163 | pub fn key(&self) -> Result, Box> { 164 | let sig = String::from("()Lorg/bukkit/NamespacedKey;"); 165 | let res = self 166 | .jni_ref() 167 | .call_method(&self.jni_object(), "getKey", sig.as_str(), vec![]); 168 | let res = self.jni_ref().translate_error(res)?; 169 | crate::NamespacedKey::from_raw(&self.jni_ref(), unsafe { 170 | jni::objects::JObject::from_raw(res.l()?.clone()) 171 | }) 172 | } 173 | /// Get the translation key, suitable for use in a translation component. 174 | pub fn translation_key(&self) -> Result> { 175 | let sig = String::from("()Ljava/lang/String;"); 176 | let res = self.jni_ref().call_method( 177 | &self.jni_object(), 178 | "getTranslationKey", 179 | sig.as_str(), 180 | vec![], 181 | ); 182 | let res = self.jni_ref().translate_error(res)?; 183 | Ok(self 184 | .jni_ref() 185 | .get_string(unsafe { &jni::objects::JString::from_raw(res.as_jni().l) })? 186 | .to_string_lossy() 187 | .to_string()) 188 | } 189 | 190 | pub fn instance_of(&self, other: impl Into) -> Result { 191 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 192 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 193 | } 194 | } 195 | impl<'mc> Into> for TrimPattern<'mc> { 196 | fn into(self) -> crate::Keyed<'mc> { 197 | crate::Keyed::from_raw(&self.jni_ref(), self.1) 198 | .expect("Error converting TrimPattern into crate::Keyed") 199 | } 200 | } 201 | impl<'mc> Into> for TrimPattern<'mc> { 202 | fn into(self) -> crate::Translatable<'mc> { 203 | crate::Translatable::from_raw(&self.jni_ref(), self.1) 204 | .expect("Error converting TrimPattern into crate::Translatable") 205 | } 206 | } 207 | #[repr(C)] 208 | pub struct TrimMaterial<'mc>( 209 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 210 | pub(crate) jni::objects::JObject<'mc>, 211 | ); 212 | 213 | impl<'mc> JNIRaw<'mc> for TrimMaterial<'mc> { 214 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 215 | self.0.clone() 216 | } 217 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 218 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 219 | } 220 | } 221 | impl<'mc> JNIInstantiatable<'mc> for TrimMaterial<'mc> { 222 | fn from_raw( 223 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 224 | obj: jni::objects::JObject<'mc>, 225 | ) -> Result> { 226 | if obj.is_null() { 227 | return Err(eyre::eyre!("Tried to instantiate TrimMaterial from null object.").into()); 228 | } 229 | let (valid, name) = 230 | env.validate_name(&obj, "org/bukkit/inventory/meta/trim/TrimMaterial")?; 231 | if !valid { 232 | Err(eyre::eyre!( 233 | "Invalid argument passed. Expected a TrimMaterial object, got {}", 234 | name 235 | ) 236 | .into()) 237 | } else { 238 | Ok(Self(env.clone(), obj)) 239 | } 240 | } 241 | } 242 | 243 | impl<'mc> TrimMaterial<'mc> { 244 | /// Return the namespaced identifier for this object. 245 | pub fn key(&self) -> Result, Box> { 246 | let sig = String::from("()Lorg/bukkit/NamespacedKey;"); 247 | let res = self 248 | .jni_ref() 249 | .call_method(&self.jni_object(), "getKey", sig.as_str(), vec![]); 250 | let res = self.jni_ref().translate_error(res)?; 251 | crate::NamespacedKey::from_raw(&self.jni_ref(), unsafe { 252 | jni::objects::JObject::from_raw(res.l()?.clone()) 253 | }) 254 | } 255 | /// Get the translation key, suitable for use in a translation component. 256 | pub fn translation_key(&self) -> Result> { 257 | let sig = String::from("()Ljava/lang/String;"); 258 | let res = self.jni_ref().call_method( 259 | &self.jni_object(), 260 | "getTranslationKey", 261 | sig.as_str(), 262 | vec![], 263 | ); 264 | let res = self.jni_ref().translate_error(res)?; 265 | Ok(self 266 | .jni_ref() 267 | .get_string(unsafe { &jni::objects::JString::from_raw(res.as_jni().l) })? 268 | .to_string_lossy() 269 | .to_string()) 270 | } 271 | 272 | pub fn instance_of(&self, other: impl Into) -> Result { 273 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 274 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 275 | } 276 | } 277 | impl<'mc> Into> for TrimMaterial<'mc> { 278 | fn into(self) -> crate::Keyed<'mc> { 279 | crate::Keyed::from_raw(&self.jni_ref(), self.1) 280 | .expect("Error converting TrimMaterial into crate::Keyed") 281 | } 282 | } 283 | impl<'mc> Into> for TrimMaterial<'mc> { 284 | fn into(self) -> crate::Translatable<'mc> { 285 | crate::Translatable::from_raw(&self.jni_ref(), self.1) 286 | .expect("Error converting TrimMaterial into crate::Translatable") 287 | } 288 | } 289 | -------------------------------------------------------------------------------- /blackboxmc-rs-bukkit/src/inventory/recipe/mod.rs: -------------------------------------------------------------------------------- 1 | #![allow(deprecated)] 2 | use blackboxmc_general::JNIInstantiatable; 3 | use blackboxmc_general::JNIRaw; 4 | use color_eyre::eyre::Result; 5 | pub enum CraftingBookCategory<'mc> { 6 | Building { 7 | inner: CraftingBookCategoryStruct<'mc>, 8 | }, 9 | Redstone { 10 | inner: CraftingBookCategoryStruct<'mc>, 11 | }, 12 | Equipment { 13 | inner: CraftingBookCategoryStruct<'mc>, 14 | }, 15 | Misc { 16 | inner: CraftingBookCategoryStruct<'mc>, 17 | }, 18 | } 19 | impl<'mc> std::fmt::Display for CraftingBookCategory<'mc> { 20 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 21 | match self { 22 | CraftingBookCategory::Building { .. } => f.write_str("BUILDING"), 23 | CraftingBookCategory::Redstone { .. } => f.write_str("REDSTONE"), 24 | CraftingBookCategory::Equipment { .. } => f.write_str("EQUIPMENT"), 25 | CraftingBookCategory::Misc { .. } => f.write_str("MISC"), 26 | } 27 | } 28 | } 29 | impl<'mc> std::ops::Deref for CraftingBookCategory<'mc> { 30 | type Target = CraftingBookCategoryStruct<'mc>; 31 | fn deref(&self) -> & as std::ops::Deref>::Target { 32 | match self { 33 | CraftingBookCategory::Building { inner } => inner, 34 | CraftingBookCategory::Redstone { inner } => inner, 35 | CraftingBookCategory::Equipment { inner } => inner, 36 | CraftingBookCategory::Misc { inner } => inner, 37 | } 38 | } 39 | } 40 | 41 | impl<'mc> CraftingBookCategory<'mc> { 42 | pub fn value_of( 43 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 44 | arg0: impl Into, 45 | ) -> Result, Box> { 46 | let val_1 = jni::objects::JObject::from(env.new_string(arg0.into())?); 47 | let cls = env.find_class("org/bukkit/inventory/recipe/CraftingBookCategory"); 48 | let cls = env.translate_error_with_class(cls)?; 49 | let res = env.call_static_method( 50 | cls, 51 | "valueOf", 52 | "(Ljava/lang/String;)Lorg/bukkit/inventory/recipe/CraftingBookCategory;", 53 | vec![jni::objects::JValueGen::from(val_1)], 54 | ); 55 | let res = env.translate_error(res)?; 56 | let obj = res.l()?; 57 | let variant = env.call_method(&obj, "toString", "()Ljava/lang/String;", vec![]); 58 | let variant = env.translate_error(variant)?; 59 | let variant_str = env 60 | .get_string(unsafe { &jni::objects::JString::from_raw(variant.as_jni().l) })? 61 | .to_string_lossy() 62 | .to_string(); 63 | match variant_str.as_str() { 64 | "BUILDING" => Ok(CraftingBookCategory::Building { 65 | inner: CraftingBookCategoryStruct::from_raw(env, obj)?, 66 | }), 67 | "REDSTONE" => Ok(CraftingBookCategory::Redstone { 68 | inner: CraftingBookCategoryStruct::from_raw(env, obj)?, 69 | }), 70 | "EQUIPMENT" => Ok(CraftingBookCategory::Equipment { 71 | inner: CraftingBookCategoryStruct::from_raw(env, obj)?, 72 | }), 73 | "MISC" => Ok(CraftingBookCategory::Misc { 74 | inner: CraftingBookCategoryStruct::from_raw(env, obj)?, 75 | }), 76 | 77 | _ => Err(eyre::eyre!("String gaven for variant was invalid").into()), 78 | } 79 | } 80 | } 81 | 82 | #[repr(C)] 83 | pub struct CraftingBookCategoryStruct<'mc>( 84 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 85 | pub(crate) jni::objects::JObject<'mc>, 86 | ); 87 | 88 | impl<'mc> JNIRaw<'mc> for CraftingBookCategory<'mc> { 89 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 90 | match self { 91 | Self::Building { inner } => inner.0.clone(), 92 | Self::Redstone { inner } => inner.0.clone(), 93 | Self::Equipment { inner } => inner.0.clone(), 94 | Self::Misc { inner } => inner.0.clone(), 95 | } 96 | } 97 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 98 | match self { 99 | Self::Building { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) }, 100 | Self::Redstone { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) }, 101 | Self::Equipment { inner } => unsafe { 102 | jni::objects::JObject::from_raw(inner.1.clone()) 103 | }, 104 | Self::Misc { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) }, 105 | } 106 | } 107 | } 108 | impl<'mc> JNIInstantiatable<'mc> for CraftingBookCategory<'mc> { 109 | fn from_raw( 110 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 111 | obj: jni::objects::JObject<'mc>, 112 | ) -> Result> { 113 | if obj.is_null() { 114 | return Err( 115 | eyre::eyre!("Tried to instantiate CraftingBookCategory from null object.").into(), 116 | ); 117 | } 118 | let (valid, name) = 119 | env.validate_name(&obj, "org/bukkit/inventory/recipe/CraftingBookCategory")?; 120 | if !valid { 121 | Err(eyre::eyre!( 122 | "Invalid argument passed. Expected a CraftingBookCategory object, got {}", 123 | name 124 | ) 125 | .into()) 126 | } else { 127 | let variant = env.call_method(&obj, "toString", "()Ljava/lang/String;", vec![]); 128 | let variant = env.translate_error(variant)?; 129 | let variant_str = env 130 | .get_string(unsafe { &jni::objects::JString::from_raw(variant.as_jni().l) })? 131 | .to_string_lossy() 132 | .to_string(); 133 | match variant_str.as_str() { 134 | "BUILDING" => Ok(CraftingBookCategory::Building { 135 | inner: CraftingBookCategoryStruct::from_raw(env, obj)?, 136 | }), 137 | "REDSTONE" => Ok(CraftingBookCategory::Redstone { 138 | inner: CraftingBookCategoryStruct::from_raw(env, obj)?, 139 | }), 140 | "EQUIPMENT" => Ok(CraftingBookCategory::Equipment { 141 | inner: CraftingBookCategoryStruct::from_raw(env, obj)?, 142 | }), 143 | "MISC" => Ok(CraftingBookCategory::Misc { 144 | inner: CraftingBookCategoryStruct::from_raw(env, obj)?, 145 | }), 146 | _ => Err(eyre::eyre!("String gaven for variant was invalid").into()), 147 | } 148 | } 149 | } 150 | } 151 | 152 | impl<'mc> JNIRaw<'mc> for CraftingBookCategoryStruct<'mc> { 153 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 154 | self.0.clone() 155 | } 156 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 157 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 158 | } 159 | } 160 | impl<'mc> JNIInstantiatable<'mc> for CraftingBookCategoryStruct<'mc> { 161 | fn from_raw( 162 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 163 | obj: jni::objects::JObject<'mc>, 164 | ) -> Result> { 165 | if obj.is_null() { 166 | return Err(eyre::eyre!( 167 | "Tried to instantiate CraftingBookCategoryStruct from null object." 168 | ) 169 | .into()); 170 | } 171 | let (valid, name) = 172 | env.validate_name(&obj, "org/bukkit/inventory/recipe/CraftingBookCategory")?; 173 | if !valid { 174 | Err(eyre::eyre!( 175 | "Invalid argument passed. Expected a CraftingBookCategoryStruct object, got {}", 176 | name 177 | ) 178 | .into()) 179 | } else { 180 | Ok(Self(env.clone(), obj)) 181 | } 182 | } 183 | } 184 | 185 | impl<'mc> CraftingBookCategoryStruct<'mc> { 186 | pub fn values( 187 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 188 | ) -> Result, Box> 189 | { 190 | let sig = String::from("()Lorg/bukkit/inventory/recipe/CraftingBookCategory;"); 191 | let cls = jni.find_class("org/bukkit/inventory/recipe/CraftingBookCategory"); 192 | let cls = jni.translate_error_with_class(cls)?; 193 | let res = jni.call_static_method(cls, "values", sig.as_str(), vec![]); 194 | let res = jni.translate_error(res)?; 195 | let obj = res.l()?; 196 | crate::inventory::recipe::CraftingBookCategory::from_raw(&jni, obj) 197 | } 198 | 199 | pub fn instance_of(&self, other: impl Into) -> Result { 200 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 201 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 202 | } 203 | } 204 | pub enum CookingBookCategory<'mc> { 205 | Food { 206 | inner: CookingBookCategoryStruct<'mc>, 207 | }, 208 | Blocks { 209 | inner: CookingBookCategoryStruct<'mc>, 210 | }, 211 | Misc { 212 | inner: CookingBookCategoryStruct<'mc>, 213 | }, 214 | } 215 | impl<'mc> std::fmt::Display for CookingBookCategory<'mc> { 216 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 217 | match self { 218 | CookingBookCategory::Food { .. } => f.write_str("FOOD"), 219 | CookingBookCategory::Blocks { .. } => f.write_str("BLOCKS"), 220 | CookingBookCategory::Misc { .. } => f.write_str("MISC"), 221 | } 222 | } 223 | } 224 | impl<'mc> std::ops::Deref for CookingBookCategory<'mc> { 225 | type Target = CookingBookCategoryStruct<'mc>; 226 | fn deref(&self) -> & as std::ops::Deref>::Target { 227 | match self { 228 | CookingBookCategory::Food { inner } => inner, 229 | CookingBookCategory::Blocks { inner } => inner, 230 | CookingBookCategory::Misc { inner } => inner, 231 | } 232 | } 233 | } 234 | 235 | impl<'mc> CookingBookCategory<'mc> { 236 | pub fn value_of( 237 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 238 | arg0: impl Into, 239 | ) -> Result, Box> { 240 | let val_1 = jni::objects::JObject::from(env.new_string(arg0.into())?); 241 | let cls = env.find_class("org/bukkit/inventory/recipe/CookingBookCategory"); 242 | let cls = env.translate_error_with_class(cls)?; 243 | let res = env.call_static_method( 244 | cls, 245 | "valueOf", 246 | "(Ljava/lang/String;)Lorg/bukkit/inventory/recipe/CookingBookCategory;", 247 | vec![jni::objects::JValueGen::from(val_1)], 248 | ); 249 | let res = env.translate_error(res)?; 250 | let obj = res.l()?; 251 | let variant = env.call_method(&obj, "toString", "()Ljava/lang/String;", vec![]); 252 | let variant = env.translate_error(variant)?; 253 | let variant_str = env 254 | .get_string(unsafe { &jni::objects::JString::from_raw(variant.as_jni().l) })? 255 | .to_string_lossy() 256 | .to_string(); 257 | match variant_str.as_str() { 258 | "FOOD" => Ok(CookingBookCategory::Food { 259 | inner: CookingBookCategoryStruct::from_raw(env, obj)?, 260 | }), 261 | "BLOCKS" => Ok(CookingBookCategory::Blocks { 262 | inner: CookingBookCategoryStruct::from_raw(env, obj)?, 263 | }), 264 | "MISC" => Ok(CookingBookCategory::Misc { 265 | inner: CookingBookCategoryStruct::from_raw(env, obj)?, 266 | }), 267 | 268 | _ => Err(eyre::eyre!("String gaven for variant was invalid").into()), 269 | } 270 | } 271 | } 272 | 273 | #[repr(C)] 274 | pub struct CookingBookCategoryStruct<'mc>( 275 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 276 | pub(crate) jni::objects::JObject<'mc>, 277 | ); 278 | 279 | impl<'mc> JNIRaw<'mc> for CookingBookCategory<'mc> { 280 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 281 | match self { 282 | Self::Food { inner } => inner.0.clone(), 283 | Self::Blocks { inner } => inner.0.clone(), 284 | Self::Misc { inner } => inner.0.clone(), 285 | } 286 | } 287 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 288 | match self { 289 | Self::Food { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) }, 290 | Self::Blocks { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) }, 291 | Self::Misc { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) }, 292 | } 293 | } 294 | } 295 | impl<'mc> JNIInstantiatable<'mc> for CookingBookCategory<'mc> { 296 | fn from_raw( 297 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 298 | obj: jni::objects::JObject<'mc>, 299 | ) -> Result> { 300 | if obj.is_null() { 301 | return Err( 302 | eyre::eyre!("Tried to instantiate CookingBookCategory from null object.").into(), 303 | ); 304 | } 305 | let (valid, name) = 306 | env.validate_name(&obj, "org/bukkit/inventory/recipe/CookingBookCategory")?; 307 | if !valid { 308 | Err(eyre::eyre!( 309 | "Invalid argument passed. Expected a CookingBookCategory object, got {}", 310 | name 311 | ) 312 | .into()) 313 | } else { 314 | let variant = env.call_method(&obj, "toString", "()Ljava/lang/String;", vec![]); 315 | let variant = env.translate_error(variant)?; 316 | let variant_str = env 317 | .get_string(unsafe { &jni::objects::JString::from_raw(variant.as_jni().l) })? 318 | .to_string_lossy() 319 | .to_string(); 320 | match variant_str.as_str() { 321 | "FOOD" => Ok(CookingBookCategory::Food { 322 | inner: CookingBookCategoryStruct::from_raw(env, obj)?, 323 | }), 324 | "BLOCKS" => Ok(CookingBookCategory::Blocks { 325 | inner: CookingBookCategoryStruct::from_raw(env, obj)?, 326 | }), 327 | "MISC" => Ok(CookingBookCategory::Misc { 328 | inner: CookingBookCategoryStruct::from_raw(env, obj)?, 329 | }), 330 | _ => Err(eyre::eyre!("String gaven for variant was invalid").into()), 331 | } 332 | } 333 | } 334 | } 335 | 336 | impl<'mc> JNIRaw<'mc> for CookingBookCategoryStruct<'mc> { 337 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 338 | self.0.clone() 339 | } 340 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 341 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 342 | } 343 | } 344 | impl<'mc> JNIInstantiatable<'mc> for CookingBookCategoryStruct<'mc> { 345 | fn from_raw( 346 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 347 | obj: jni::objects::JObject<'mc>, 348 | ) -> Result> { 349 | if obj.is_null() { 350 | return Err(eyre::eyre!( 351 | "Tried to instantiate CookingBookCategoryStruct from null object." 352 | ) 353 | .into()); 354 | } 355 | let (valid, name) = 356 | env.validate_name(&obj, "org/bukkit/inventory/recipe/CookingBookCategory")?; 357 | if !valid { 358 | Err(eyre::eyre!( 359 | "Invalid argument passed. Expected a CookingBookCategoryStruct object, got {}", 360 | name 361 | ) 362 | .into()) 363 | } else { 364 | Ok(Self(env.clone(), obj)) 365 | } 366 | } 367 | } 368 | 369 | impl<'mc> CookingBookCategoryStruct<'mc> { 370 | pub fn values( 371 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 372 | ) -> Result, Box> 373 | { 374 | let sig = String::from("()Lorg/bukkit/inventory/recipe/CookingBookCategory;"); 375 | let cls = jni.find_class("org/bukkit/inventory/recipe/CookingBookCategory"); 376 | let cls = jni.translate_error_with_class(cls)?; 377 | let res = jni.call_static_method(cls, "values", sig.as_str(), vec![]); 378 | let res = jni.translate_error(res)?; 379 | let obj = res.l()?; 380 | crate::inventory::recipe::CookingBookCategory::from_raw(&jni, obj) 381 | } 382 | 383 | pub fn instance_of(&self, other: impl Into) -> Result { 384 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 385 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 386 | } 387 | } 388 | -------------------------------------------------------------------------------- /blackboxmc-rs-bukkit/src/material/types/mod.rs: -------------------------------------------------------------------------------- 1 | #![allow(deprecated)] 2 | use blackboxmc_general::JNIInstantiatable; 3 | use blackboxmc_general::JNIRaw; 4 | use color_eyre::eyre::Result; 5 | pub enum MushroomBlockTexture<'mc> { 6 | AllPores { 7 | inner: MushroomBlockTextureStruct<'mc>, 8 | }, 9 | CapNorthWest { 10 | inner: MushroomBlockTextureStruct<'mc>, 11 | }, 12 | CapNorth { 13 | inner: MushroomBlockTextureStruct<'mc>, 14 | }, 15 | CapNorthEast { 16 | inner: MushroomBlockTextureStruct<'mc>, 17 | }, 18 | CapWest { 19 | inner: MushroomBlockTextureStruct<'mc>, 20 | }, 21 | CapTop { 22 | inner: MushroomBlockTextureStruct<'mc>, 23 | }, 24 | CapEast { 25 | inner: MushroomBlockTextureStruct<'mc>, 26 | }, 27 | CapSouthWest { 28 | inner: MushroomBlockTextureStruct<'mc>, 29 | }, 30 | CapSouth { 31 | inner: MushroomBlockTextureStruct<'mc>, 32 | }, 33 | CapSouthEast { 34 | inner: MushroomBlockTextureStruct<'mc>, 35 | }, 36 | StemSides { 37 | inner: MushroomBlockTextureStruct<'mc>, 38 | }, 39 | AllCap { 40 | inner: MushroomBlockTextureStruct<'mc>, 41 | }, 42 | AllStem { 43 | inner: MushroomBlockTextureStruct<'mc>, 44 | }, 45 | } 46 | impl<'mc> std::fmt::Display for MushroomBlockTexture<'mc> { 47 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 48 | match self { 49 | MushroomBlockTexture::AllPores { .. } => f.write_str("ALL_PORES"), 50 | MushroomBlockTexture::CapNorthWest { .. } => f.write_str("CAP_NORTH_WEST"), 51 | MushroomBlockTexture::CapNorth { .. } => f.write_str("CAP_NORTH"), 52 | MushroomBlockTexture::CapNorthEast { .. } => f.write_str("CAP_NORTH_EAST"), 53 | MushroomBlockTexture::CapWest { .. } => f.write_str("CAP_WEST"), 54 | MushroomBlockTexture::CapTop { .. } => f.write_str("CAP_TOP"), 55 | MushroomBlockTexture::CapEast { .. } => f.write_str("CAP_EAST"), 56 | MushroomBlockTexture::CapSouthWest { .. } => f.write_str("CAP_SOUTH_WEST"), 57 | MushroomBlockTexture::CapSouth { .. } => f.write_str("CAP_SOUTH"), 58 | MushroomBlockTexture::CapSouthEast { .. } => f.write_str("CAP_SOUTH_EAST"), 59 | MushroomBlockTexture::StemSides { .. } => f.write_str("STEM_SIDES"), 60 | MushroomBlockTexture::AllCap { .. } => f.write_str("ALL_CAP"), 61 | MushroomBlockTexture::AllStem { .. } => f.write_str("ALL_STEM"), 62 | } 63 | } 64 | } 65 | impl<'mc> std::ops::Deref for MushroomBlockTexture<'mc> { 66 | type Target = MushroomBlockTextureStruct<'mc>; 67 | fn deref(&self) -> & as std::ops::Deref>::Target { 68 | match self { 69 | MushroomBlockTexture::AllPores { inner } => inner, 70 | MushroomBlockTexture::CapNorthWest { inner } => inner, 71 | MushroomBlockTexture::CapNorth { inner } => inner, 72 | MushroomBlockTexture::CapNorthEast { inner } => inner, 73 | MushroomBlockTexture::CapWest { inner } => inner, 74 | MushroomBlockTexture::CapTop { inner } => inner, 75 | MushroomBlockTexture::CapEast { inner } => inner, 76 | MushroomBlockTexture::CapSouthWest { inner } => inner, 77 | MushroomBlockTexture::CapSouth { inner } => inner, 78 | MushroomBlockTexture::CapSouthEast { inner } => inner, 79 | MushroomBlockTexture::StemSides { inner } => inner, 80 | MushroomBlockTexture::AllCap { inner } => inner, 81 | MushroomBlockTexture::AllStem { inner } => inner, 82 | } 83 | } 84 | } 85 | 86 | impl<'mc> MushroomBlockTexture<'mc> { 87 | pub fn value_of( 88 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 89 | arg0: impl Into, 90 | ) -> Result, Box> { 91 | let val_1 = jni::objects::JObject::from(env.new_string(arg0.into())?); 92 | let cls = env.find_class("org/bukkit/material/types/MushroomBlockTexture"); 93 | let cls = env.translate_error_with_class(cls)?; 94 | let res = env.call_static_method( 95 | cls, 96 | "valueOf", 97 | "(Ljava/lang/String;)Lorg/bukkit/material/types/MushroomBlockTexture;", 98 | vec![jni::objects::JValueGen::from(val_1)], 99 | ); 100 | let res = env.translate_error(res)?; 101 | let obj = res.l()?; 102 | let variant = env.call_method(&obj, "toString", "()Ljava/lang/String;", vec![]); 103 | let variant = env.translate_error(variant)?; 104 | let variant_str = env 105 | .get_string(unsafe { &jni::objects::JString::from_raw(variant.as_jni().l) })? 106 | .to_string_lossy() 107 | .to_string(); 108 | match variant_str.as_str() { 109 | "ALL_PORES" => Ok(MushroomBlockTexture::AllPores { 110 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 111 | }), 112 | "CAP_NORTH_WEST" => Ok(MushroomBlockTexture::CapNorthWest { 113 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 114 | }), 115 | "CAP_NORTH" => Ok(MushroomBlockTexture::CapNorth { 116 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 117 | }), 118 | "CAP_NORTH_EAST" => Ok(MushroomBlockTexture::CapNorthEast { 119 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 120 | }), 121 | "CAP_WEST" => Ok(MushroomBlockTexture::CapWest { 122 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 123 | }), 124 | "CAP_TOP" => Ok(MushroomBlockTexture::CapTop { 125 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 126 | }), 127 | "CAP_EAST" => Ok(MushroomBlockTexture::CapEast { 128 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 129 | }), 130 | "CAP_SOUTH_WEST" => Ok(MushroomBlockTexture::CapSouthWest { 131 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 132 | }), 133 | "CAP_SOUTH" => Ok(MushroomBlockTexture::CapSouth { 134 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 135 | }), 136 | "CAP_SOUTH_EAST" => Ok(MushroomBlockTexture::CapSouthEast { 137 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 138 | }), 139 | "STEM_SIDES" => Ok(MushroomBlockTexture::StemSides { 140 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 141 | }), 142 | "ALL_CAP" => Ok(MushroomBlockTexture::AllCap { 143 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 144 | }), 145 | "ALL_STEM" => Ok(MushroomBlockTexture::AllStem { 146 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 147 | }), 148 | 149 | _ => Err(eyre::eyre!("String gaven for variant was invalid").into()), 150 | } 151 | } 152 | } 153 | 154 | #[repr(C)] 155 | pub struct MushroomBlockTextureStruct<'mc>( 156 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 157 | pub(crate) jni::objects::JObject<'mc>, 158 | ); 159 | 160 | impl<'mc> JNIRaw<'mc> for MushroomBlockTexture<'mc> { 161 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 162 | match self { 163 | Self::AllPores { inner } => inner.0.clone(), 164 | Self::CapNorthWest { inner } => inner.0.clone(), 165 | Self::CapNorth { inner } => inner.0.clone(), 166 | Self::CapNorthEast { inner } => inner.0.clone(), 167 | Self::CapWest { inner } => inner.0.clone(), 168 | Self::CapTop { inner } => inner.0.clone(), 169 | Self::CapEast { inner } => inner.0.clone(), 170 | Self::CapSouthWest { inner } => inner.0.clone(), 171 | Self::CapSouth { inner } => inner.0.clone(), 172 | Self::CapSouthEast { inner } => inner.0.clone(), 173 | Self::StemSides { inner } => inner.0.clone(), 174 | Self::AllCap { inner } => inner.0.clone(), 175 | Self::AllStem { inner } => inner.0.clone(), 176 | } 177 | } 178 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 179 | match self { 180 | Self::AllPores { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) }, 181 | Self::CapNorthWest { inner } => unsafe { 182 | jni::objects::JObject::from_raw(inner.1.clone()) 183 | }, 184 | Self::CapNorth { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) }, 185 | Self::CapNorthEast { inner } => unsafe { 186 | jni::objects::JObject::from_raw(inner.1.clone()) 187 | }, 188 | Self::CapWest { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) }, 189 | Self::CapTop { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) }, 190 | Self::CapEast { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) }, 191 | Self::CapSouthWest { inner } => unsafe { 192 | jni::objects::JObject::from_raw(inner.1.clone()) 193 | }, 194 | Self::CapSouth { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) }, 195 | Self::CapSouthEast { inner } => unsafe { 196 | jni::objects::JObject::from_raw(inner.1.clone()) 197 | }, 198 | Self::StemSides { inner } => unsafe { 199 | jni::objects::JObject::from_raw(inner.1.clone()) 200 | }, 201 | Self::AllCap { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) }, 202 | Self::AllStem { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) }, 203 | } 204 | } 205 | } 206 | impl<'mc> JNIInstantiatable<'mc> for MushroomBlockTexture<'mc> { 207 | fn from_raw( 208 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 209 | obj: jni::objects::JObject<'mc>, 210 | ) -> Result> { 211 | if obj.is_null() { 212 | return Err( 213 | eyre::eyre!("Tried to instantiate MushroomBlockTexture from null object.").into(), 214 | ); 215 | } 216 | let (valid, name) = 217 | env.validate_name(&obj, "org/bukkit/material/types/MushroomBlockTexture")?; 218 | if !valid { 219 | Err(eyre::eyre!( 220 | "Invalid argument passed. Expected a MushroomBlockTexture object, got {}", 221 | name 222 | ) 223 | .into()) 224 | } else { 225 | let variant = env.call_method(&obj, "toString", "()Ljava/lang/String;", vec![]); 226 | let variant = env.translate_error(variant)?; 227 | let variant_str = env 228 | .get_string(unsafe { &jni::objects::JString::from_raw(variant.as_jni().l) })? 229 | .to_string_lossy() 230 | .to_string(); 231 | match variant_str.as_str() { 232 | "ALL_PORES" => Ok(MushroomBlockTexture::AllPores { 233 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 234 | }), 235 | "CAP_NORTH_WEST" => Ok(MushroomBlockTexture::CapNorthWest { 236 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 237 | }), 238 | "CAP_NORTH" => Ok(MushroomBlockTexture::CapNorth { 239 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 240 | }), 241 | "CAP_NORTH_EAST" => Ok(MushroomBlockTexture::CapNorthEast { 242 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 243 | }), 244 | "CAP_WEST" => Ok(MushroomBlockTexture::CapWest { 245 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 246 | }), 247 | "CAP_TOP" => Ok(MushroomBlockTexture::CapTop { 248 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 249 | }), 250 | "CAP_EAST" => Ok(MushroomBlockTexture::CapEast { 251 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 252 | }), 253 | "CAP_SOUTH_WEST" => Ok(MushroomBlockTexture::CapSouthWest { 254 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 255 | }), 256 | "CAP_SOUTH" => Ok(MushroomBlockTexture::CapSouth { 257 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 258 | }), 259 | "CAP_SOUTH_EAST" => Ok(MushroomBlockTexture::CapSouthEast { 260 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 261 | }), 262 | "STEM_SIDES" => Ok(MushroomBlockTexture::StemSides { 263 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 264 | }), 265 | "ALL_CAP" => Ok(MushroomBlockTexture::AllCap { 266 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 267 | }), 268 | "ALL_STEM" => Ok(MushroomBlockTexture::AllStem { 269 | inner: MushroomBlockTextureStruct::from_raw(env, obj)?, 270 | }), 271 | _ => Err(eyre::eyre!("String gaven for variant was invalid").into()), 272 | } 273 | } 274 | } 275 | } 276 | 277 | impl<'mc> JNIRaw<'mc> for MushroomBlockTextureStruct<'mc> { 278 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 279 | self.0.clone() 280 | } 281 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 282 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 283 | } 284 | } 285 | impl<'mc> JNIInstantiatable<'mc> for MushroomBlockTextureStruct<'mc> { 286 | fn from_raw( 287 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 288 | obj: jni::objects::JObject<'mc>, 289 | ) -> Result> { 290 | if obj.is_null() { 291 | return Err(eyre::eyre!( 292 | "Tried to instantiate MushroomBlockTextureStruct from null object." 293 | ) 294 | .into()); 295 | } 296 | let (valid, name) = 297 | env.validate_name(&obj, "org/bukkit/material/types/MushroomBlockTexture")?; 298 | if !valid { 299 | Err(eyre::eyre!( 300 | "Invalid argument passed. Expected a MushroomBlockTextureStruct object, got {}", 301 | name 302 | ) 303 | .into()) 304 | } else { 305 | Ok(Self(env.clone(), obj)) 306 | } 307 | } 308 | } 309 | 310 | impl<'mc> MushroomBlockTextureStruct<'mc> { 311 | pub fn values( 312 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 313 | ) -> Result, Box> { 314 | let sig = String::from("()Lorg/bukkit/material/types/MushroomBlockTexture;"); 315 | let cls = jni.find_class("org/bukkit/material/types/MushroomBlockTexture"); 316 | let cls = jni.translate_error_with_class(cls)?; 317 | let res = jni.call_static_method(cls, "values", sig.as_str(), vec![]); 318 | let res = jni.translate_error(res)?; 319 | let obj = res.l()?; 320 | crate::material::types::MushroomBlockTexture::from_raw(&jni, obj) 321 | } 322 | #[deprecated] 323 | /// Gets the associated data value representing this mushroom block face. 324 | pub fn data(&self) -> Result> { 325 | let sig = String::from("()B"); 326 | let res = self 327 | .jni_ref() 328 | .call_method(&self.jni_object(), "getData", sig.as_str(), vec![]); 329 | let res = self.jni_ref().translate_error(res)?; 330 | Ok(res.b()?) 331 | } 332 | /// Gets the face that has cap texture. 333 | pub fn cap_face( 334 | &self, 335 | ) -> Result>, Box> { 336 | let sig = String::from("()Lorg/bukkit/block/BlockFace;"); 337 | let res = 338 | self.jni_ref() 339 | .call_method(&self.jni_object(), "getCapFace", sig.as_str(), vec![]); 340 | let res = self.jni_ref().translate_error(res)?; 341 | if unsafe { jni::objects::JObject::from_raw(res.as_jni().l) }.is_null() { 342 | return Ok(None); 343 | } 344 | Ok(Some(crate::block::BlockFace::from_raw( 345 | &self.jni_ref(), 346 | unsafe { jni::objects::JObject::from_raw(res.l()?.clone()) }, 347 | )?)) 348 | } 349 | #[deprecated] 350 | /// Gets the MushroomBlockType with the given data value. 351 | pub fn get_by_data( 352 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 353 | data: i8, 354 | ) -> Result>, Box> 355 | { 356 | let sig = String::from("(B)Lorg/bukkit/material/types/MushroomBlockTexture;"); 357 | let val_1 = jni::objects::JValueGen::Byte(data); 358 | let cls = jni.find_class("org/bukkit/material/types/MushroomBlockTexture"); 359 | let cls = jni.translate_error_with_class(cls)?; 360 | let res = jni.call_static_method( 361 | cls, 362 | "getByData", 363 | sig.as_str(), 364 | vec![jni::objects::JValueGen::from(val_1)], 365 | ); 366 | let res = jni.translate_error(res)?; 367 | if unsafe { jni::objects::JObject::from_raw(res.as_jni().l) }.is_null() { 368 | return Ok(None); 369 | } 370 | let obj = res.l()?; 371 | Ok(Some( 372 | crate::material::types::MushroomBlockTexture::from_raw(&jni, obj)?, 373 | )) 374 | } 375 | /// Gets the MushroomBlockType with cap texture on the given block face. 376 | pub fn get_cap_by_face( 377 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 378 | face: impl Into>, 379 | ) -> Result>, Box> 380 | { 381 | let sig = String::from( 382 | "(Lorg/bukkit/block/BlockFace;)Lorg/bukkit/material/types/MushroomBlockTexture;", 383 | ); 384 | let val_1 = jni::objects::JValueGen::Object(unsafe { 385 | jni::objects::JObject::from_raw(face.into().jni_object().clone()) 386 | }); 387 | let cls = jni.find_class("org/bukkit/material/types/MushroomBlockTexture"); 388 | let cls = jni.translate_error_with_class(cls)?; 389 | let res = jni.call_static_method( 390 | cls, 391 | "getCapByFace", 392 | sig.as_str(), 393 | vec![jni::objects::JValueGen::from(val_1)], 394 | ); 395 | let res = jni.translate_error(res)?; 396 | if unsafe { jni::objects::JObject::from_raw(res.as_jni().l) }.is_null() { 397 | return Ok(None); 398 | } 399 | let obj = res.l()?; 400 | Ok(Some( 401 | crate::material::types::MushroomBlockTexture::from_raw(&jni, obj)?, 402 | )) 403 | } 404 | 405 | pub fn instance_of(&self, other: impl Into) -> Result { 406 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 407 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 408 | } 409 | } 410 | -------------------------------------------------------------------------------- /blackboxmc-rs-bukkit/src/projectiles/mod.rs: -------------------------------------------------------------------------------- 1 | #![allow(deprecated)] 2 | use blackboxmc_general::JNIInstantiatable; 3 | use blackboxmc_general::JNIRaw; 4 | use color_eyre::eyre::Result; 5 | #[repr(C)] 6 | pub struct BlockProjectileSource<'mc>( 7 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 8 | pub(crate) jni::objects::JObject<'mc>, 9 | ); 10 | 11 | impl<'mc> JNIRaw<'mc> for BlockProjectileSource<'mc> { 12 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 13 | self.0.clone() 14 | } 15 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 16 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 17 | } 18 | } 19 | impl<'mc> JNIInstantiatable<'mc> for BlockProjectileSource<'mc> { 20 | fn from_raw( 21 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 22 | obj: jni::objects::JObject<'mc>, 23 | ) -> Result> { 24 | if obj.is_null() { 25 | return Err(eyre::eyre!( 26 | "Tried to instantiate BlockProjectileSource from null object." 27 | ) 28 | .into()); 29 | } 30 | let (valid, name) = 31 | env.validate_name(&obj, "org/bukkit/projectiles/BlockProjectileSource")?; 32 | if !valid { 33 | Err(eyre::eyre!( 34 | "Invalid argument passed. Expected a BlockProjectileSource object, got {}", 35 | name 36 | ) 37 | .into()) 38 | } else { 39 | Ok(Self(env.clone(), obj)) 40 | } 41 | } 42 | } 43 | 44 | impl<'mc> BlockProjectileSource<'mc> { 45 | /// Gets the block this projectile source belongs to. 46 | pub fn block(&self) -> Result, Box> { 47 | let sig = String::from("()Lorg/bukkit/block/Block;"); 48 | let res = self 49 | .jni_ref() 50 | .call_method(&self.jni_object(), "getBlock", sig.as_str(), vec![]); 51 | let res = self.jni_ref().translate_error(res)?; 52 | crate::block::Block::from_raw(&self.jni_ref(), unsafe { 53 | jni::objects::JObject::from_raw(res.l()?.clone()) 54 | }) 55 | } 56 | /// Launches a {@link Projectile} from the ProjectileSource with an 57 | /// initial velocity. 58 | pub fn launch_projectile( 59 | &self, 60 | projectile: jni::objects::JClass<'mc>, 61 | velocity: std::option::Option>>, 62 | ) -> Result, Box> { 63 | let mut args = Vec::new(); 64 | let mut sig = String::from("("); 65 | sig += "Ljava/lang/Class;"; 66 | let val_1 = jni::objects::JValueGen::Object(projectile.into()); 67 | args.push(val_1); 68 | if let Some(a) = velocity { 69 | sig += "Lorg/bukkit/util/Vector;"; 70 | let val_2 = jni::objects::JValueGen::Object(unsafe { 71 | jni::objects::JObject::from_raw(a.into().jni_object().clone()) 72 | }); 73 | args.push(val_2); 74 | } 75 | sig += ")LT;"; 76 | let res = 77 | self.jni_ref() 78 | .call_method(&self.jni_object(), "launchProjectile", sig.as_str(), args); 79 | let res = self.jni_ref().translate_error(res)?; 80 | Ok(res.l()?) 81 | } 82 | 83 | pub fn instance_of(&self, other: impl Into) -> Result { 84 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 85 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 86 | } 87 | } 88 | impl<'mc> Into> for BlockProjectileSource<'mc> { 89 | fn into(self) -> crate::projectiles::ProjectileSource<'mc> { 90 | crate::projectiles::ProjectileSource::from_raw(&self.jni_ref(), self.1).expect( 91 | "Error converting BlockProjectileSource into crate::projectiles::ProjectileSource", 92 | ) 93 | } 94 | } 95 | #[repr(C)] 96 | pub struct ProjectileSource<'mc>( 97 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 98 | pub(crate) jni::objects::JObject<'mc>, 99 | ); 100 | 101 | impl<'mc> JNIRaw<'mc> for ProjectileSource<'mc> { 102 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 103 | self.0.clone() 104 | } 105 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 106 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 107 | } 108 | } 109 | impl<'mc> JNIInstantiatable<'mc> for ProjectileSource<'mc> { 110 | fn from_raw( 111 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 112 | obj: jni::objects::JObject<'mc>, 113 | ) -> Result> { 114 | if obj.is_null() { 115 | return Err( 116 | eyre::eyre!("Tried to instantiate ProjectileSource from null object.").into(), 117 | ); 118 | } 119 | let (valid, name) = env.validate_name(&obj, "org/bukkit/projectiles/ProjectileSource")?; 120 | if !valid { 121 | Err(eyre::eyre!( 122 | "Invalid argument passed. Expected a ProjectileSource object, got {}", 123 | name 124 | ) 125 | .into()) 126 | } else { 127 | Ok(Self(env.clone(), obj)) 128 | } 129 | } 130 | } 131 | 132 | impl<'mc> ProjectileSource<'mc> { 133 | /// Launches a {@link Projectile} from the ProjectileSource with an 134 | /// initial velocity. 135 | pub fn launch_projectile( 136 | &self, 137 | projectile: jni::objects::JClass<'mc>, 138 | velocity: std::option::Option>>, 139 | ) -> Result, Box> { 140 | let mut args = Vec::new(); 141 | let mut sig = String::from("("); 142 | sig += "Ljava/lang/Class;"; 143 | let val_1 = jni::objects::JValueGen::Object(projectile.into()); 144 | args.push(val_1); 145 | if let Some(a) = velocity { 146 | sig += "Lorg/bukkit/util/Vector;"; 147 | let val_2 = jni::objects::JValueGen::Object(unsafe { 148 | jni::objects::JObject::from_raw(a.into().jni_object().clone()) 149 | }); 150 | args.push(val_2); 151 | } 152 | sig += ")LT;"; 153 | let res = 154 | self.jni_ref() 155 | .call_method(&self.jni_object(), "launchProjectile", sig.as_str(), args); 156 | let res = self.jni_ref().translate_error(res)?; 157 | Ok(res.l()?) 158 | } 159 | 160 | pub fn instance_of(&self, other: impl Into) -> Result { 161 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 162 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /blackboxmc-rs-bukkit/src/util/io/mod.rs: -------------------------------------------------------------------------------- 1 | #![allow(deprecated)] 2 | use blackboxmc_general::JNIInstantiatable; 3 | use blackboxmc_general::JNIRaw; 4 | use color_eyre::eyre::Result; 5 | #[repr(C)] 6 | pub struct BukkitObjectOutputStream<'mc>( 7 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 8 | pub(crate) jni::objects::JObject<'mc>, 9 | ); 10 | 11 | impl<'mc> JNIRaw<'mc> for BukkitObjectOutputStream<'mc> { 12 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 13 | self.0.clone() 14 | } 15 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 16 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 17 | } 18 | } 19 | impl<'mc> JNIInstantiatable<'mc> for BukkitObjectOutputStream<'mc> { 20 | fn from_raw( 21 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 22 | obj: jni::objects::JObject<'mc>, 23 | ) -> Result> { 24 | if obj.is_null() { 25 | return Err(eyre::eyre!( 26 | "Tried to instantiate BukkitObjectOutputStream from null object." 27 | ) 28 | .into()); 29 | } 30 | let (valid, name) = 31 | env.validate_name(&obj, "org/bukkit/util/io/BukkitObjectOutputStream")?; 32 | if !valid { 33 | Err(eyre::eyre!( 34 | "Invalid argument passed. Expected a BukkitObjectOutputStream object, got {}", 35 | name 36 | ) 37 | .into()) 38 | } else { 39 | Ok(Self(env.clone(), obj)) 40 | } 41 | } 42 | } 43 | 44 | impl<'mc> BukkitObjectOutputStream<'mc> { 45 | pub fn instance_of(&self, other: impl Into) -> Result { 46 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 47 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 48 | } 49 | } 50 | #[repr(C)] 51 | pub struct BukkitObjectInputStream<'mc>( 52 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 53 | pub(crate) jni::objects::JObject<'mc>, 54 | ); 55 | 56 | impl<'mc> JNIRaw<'mc> for BukkitObjectInputStream<'mc> { 57 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 58 | self.0.clone() 59 | } 60 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 61 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 62 | } 63 | } 64 | impl<'mc> JNIInstantiatable<'mc> for BukkitObjectInputStream<'mc> { 65 | fn from_raw( 66 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 67 | obj: jni::objects::JObject<'mc>, 68 | ) -> Result> { 69 | if obj.is_null() { 70 | return Err(eyre::eyre!( 71 | "Tried to instantiate BukkitObjectInputStream from null object." 72 | ) 73 | .into()); 74 | } 75 | let (valid, name) = 76 | env.validate_name(&obj, "org/bukkit/util/io/BukkitObjectInputStream")?; 77 | if !valid { 78 | Err(eyre::eyre!( 79 | "Invalid argument passed. Expected a BukkitObjectInputStream object, got {}", 80 | name 81 | ) 82 | .into()) 83 | } else { 84 | Ok(Self(env.clone(), obj)) 85 | } 86 | } 87 | } 88 | 89 | impl<'mc> BukkitObjectInputStream<'mc> { 90 | pub fn instance_of(&self, other: impl Into) -> Result { 91 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 92 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /blackboxmc-rs-bukkit/src/util/permissions/mod.rs: -------------------------------------------------------------------------------- 1 | #![allow(deprecated)] 2 | use blackboxmc_general::JNIInstantiatable; 3 | use blackboxmc_general::JNIRaw; 4 | use color_eyre::eyre::Result; 5 | #[repr(C)] 6 | pub struct DefaultPermissions<'mc>( 7 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 8 | pub(crate) jni::objects::JObject<'mc>, 9 | ); 10 | 11 | impl<'mc> JNIRaw<'mc> for DefaultPermissions<'mc> { 12 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 13 | self.0.clone() 14 | } 15 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 16 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 17 | } 18 | } 19 | impl<'mc> JNIInstantiatable<'mc> for DefaultPermissions<'mc> { 20 | fn from_raw( 21 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 22 | obj: jni::objects::JObject<'mc>, 23 | ) -> Result> { 24 | if obj.is_null() { 25 | return Err( 26 | eyre::eyre!("Tried to instantiate DefaultPermissions from null object.").into(), 27 | ); 28 | } 29 | let (valid, name) = 30 | env.validate_name(&obj, "org/bukkit/util/permissions/DefaultPermissions")?; 31 | if !valid { 32 | Err(eyre::eyre!( 33 | "Invalid argument passed. Expected a DefaultPermissions object, got {}", 34 | name 35 | ) 36 | .into()) 37 | } else { 38 | Ok(Self(env.clone(), obj)) 39 | } 40 | } 41 | } 42 | 43 | impl<'mc> DefaultPermissions<'mc> { 44 | pub fn register_permission( 45 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 46 | name: impl Into, 47 | desc: std::option::Option>, 48 | def: std::option::Option>>, 49 | children: std::option::Option>>, 50 | parent: std::option::Option>>, 51 | ) -> Result, Box> { 52 | let mut args = Vec::new(); 53 | let mut sig = String::from("("); 54 | sig += "Ljava/lang/String;"; 55 | let val_1 = jni::objects::JValueGen::Object(jni::objects::JObject::from( 56 | jni.new_string(name.into())?, 57 | )); 58 | args.push(val_1); 59 | if let Some(a) = desc { 60 | sig += "Ljava/lang/String;"; 61 | let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from( 62 | jni.new_string(a.into())?, 63 | )); 64 | args.push(val_2); 65 | } 66 | if let Some(a) = def { 67 | sig += "Lorg/bukkit/permissions/PermissionDefault;"; 68 | let val_3 = jni::objects::JValueGen::Object(unsafe { 69 | jni::objects::JObject::from_raw(a.into().jni_object().clone()) 70 | }); 71 | args.push(val_3); 72 | } 73 | if let Some(a) = children { 74 | sig += "Ljava/util/Map;"; 75 | let val_4 = jni::objects::JValueGen::Object(unsafe { 76 | jni::objects::JObject::from_raw(a.into().jni_object().clone()) 77 | }); 78 | args.push(val_4); 79 | } 80 | if let Some(a) = parent { 81 | sig += "Lorg/bukkit/permissions/Permission;"; 82 | let val_5 = jni::objects::JValueGen::Object(unsafe { 83 | jni::objects::JObject::from_raw(a.into().jni_object().clone()) 84 | }); 85 | args.push(val_5); 86 | } 87 | sig += ")Lorg/bukkit/permissions/Permission;"; 88 | let cls = jni.find_class("org/bukkit/util/permissions/DefaultPermissions"); 89 | let cls = jni.translate_error_with_class(cls)?; 90 | let res = jni.call_static_method(cls, "registerPermission", sig.as_str(), args); 91 | let res = jni.translate_error(res)?; 92 | let obj = res.l()?; 93 | crate::permissions::Permission::from_raw(&jni, obj) 94 | } 95 | 96 | pub fn register_core_permissions( 97 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 98 | ) -> Result<(), Box> { 99 | let sig = String::from("()V"); 100 | let cls = jni.find_class("org/bukkit/util/permissions/DefaultPermissions"); 101 | let cls = jni.translate_error_with_class(cls)?; 102 | let res = jni.call_static_method(cls, "registerCorePermissions", sig.as_str(), vec![]); 103 | jni.translate_error(res)?; 104 | Ok(()) 105 | } 106 | 107 | pub fn instance_of(&self, other: impl Into) -> Result { 108 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 109 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 110 | } 111 | } 112 | #[repr(C)] 113 | pub struct CommandPermissions<'mc>( 114 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 115 | pub(crate) jni::objects::JObject<'mc>, 116 | ); 117 | 118 | impl<'mc> JNIRaw<'mc> for CommandPermissions<'mc> { 119 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 120 | self.0.clone() 121 | } 122 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 123 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 124 | } 125 | } 126 | impl<'mc> JNIInstantiatable<'mc> for CommandPermissions<'mc> { 127 | fn from_raw( 128 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 129 | obj: jni::objects::JObject<'mc>, 130 | ) -> Result> { 131 | if obj.is_null() { 132 | return Err( 133 | eyre::eyre!("Tried to instantiate CommandPermissions from null object.").into(), 134 | ); 135 | } 136 | let (valid, name) = 137 | env.validate_name(&obj, "org/bukkit/util/permissions/CommandPermissions")?; 138 | if !valid { 139 | Err(eyre::eyre!( 140 | "Invalid argument passed. Expected a CommandPermissions object, got {}", 141 | name 142 | ) 143 | .into()) 144 | } else { 145 | Ok(Self(env.clone(), obj)) 146 | } 147 | } 148 | } 149 | 150 | impl<'mc> CommandPermissions<'mc> { 151 | pub fn register_permissions( 152 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 153 | parent: impl Into>, 154 | ) -> Result, Box> { 155 | let sig = String::from( 156 | "(Lorg/bukkit/permissions/Permission;)Lorg/bukkit/permissions/Permission;", 157 | ); 158 | let val_1 = jni::objects::JValueGen::Object(unsafe { 159 | jni::objects::JObject::from_raw(parent.into().jni_object().clone()) 160 | }); 161 | let cls = jni.find_class("org/bukkit/util/permissions/CommandPermissions"); 162 | let cls = jni.translate_error_with_class(cls)?; 163 | let res = jni.call_static_method( 164 | cls, 165 | "registerPermissions", 166 | sig.as_str(), 167 | vec![jni::objects::JValueGen::from(val_1)], 168 | ); 169 | let res = jni.translate_error(res)?; 170 | let obj = res.l()?; 171 | crate::permissions::Permission::from_raw(&jni, obj) 172 | } 173 | 174 | pub fn instance_of(&self, other: impl Into) -> Result { 175 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 176 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 177 | } 178 | } 179 | #[repr(C)] 180 | pub struct BroadcastPermissions<'mc>( 181 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 182 | pub(crate) jni::objects::JObject<'mc>, 183 | ); 184 | 185 | impl<'mc> JNIRaw<'mc> for BroadcastPermissions<'mc> { 186 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 187 | self.0.clone() 188 | } 189 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 190 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 191 | } 192 | } 193 | impl<'mc> JNIInstantiatable<'mc> for BroadcastPermissions<'mc> { 194 | fn from_raw( 195 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 196 | obj: jni::objects::JObject<'mc>, 197 | ) -> Result> { 198 | if obj.is_null() { 199 | return Err( 200 | eyre::eyre!("Tried to instantiate BroadcastPermissions from null object.").into(), 201 | ); 202 | } 203 | let (valid, name) = 204 | env.validate_name(&obj, "org/bukkit/util/permissions/BroadcastPermissions")?; 205 | if !valid { 206 | Err(eyre::eyre!( 207 | "Invalid argument passed. Expected a BroadcastPermissions object, got {}", 208 | name 209 | ) 210 | .into()) 211 | } else { 212 | Ok(Self(env.clone(), obj)) 213 | } 214 | } 215 | } 216 | 217 | impl<'mc> BroadcastPermissions<'mc> { 218 | pub fn register_permissions( 219 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 220 | parent: impl Into>, 221 | ) -> Result, Box> { 222 | let sig = String::from( 223 | "(Lorg/bukkit/permissions/Permission;)Lorg/bukkit/permissions/Permission;", 224 | ); 225 | let val_1 = jni::objects::JValueGen::Object(unsafe { 226 | jni::objects::JObject::from_raw(parent.into().jni_object().clone()) 227 | }); 228 | let cls = jni.find_class("org/bukkit/util/permissions/BroadcastPermissions"); 229 | let cls = jni.translate_error_with_class(cls)?; 230 | let res = jni.call_static_method( 231 | cls, 232 | "registerPermissions", 233 | sig.as_str(), 234 | vec![jni::objects::JValueGen::from(val_1)], 235 | ); 236 | let res = jni.translate_error(res)?; 237 | let obj = res.l()?; 238 | crate::permissions::Permission::from_raw(&jni, obj) 239 | } 240 | 241 | pub fn instance_of(&self, other: impl Into) -> Result { 242 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 243 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 244 | } 245 | } 246 | -------------------------------------------------------------------------------- /blackboxmc-rs-bungee/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "blackboxmc_bungee" 3 | version = "0.4.0" 4 | edition = "2021" 5 | license = "LGPL-2.0-or-later" 6 | description = "BlackboxMC bindings for net.md_5.bungee" 7 | 8 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 9 | 10 | [dependencies] 11 | color-eyre = "0.6.2" 12 | eyre = "0.6.8" 13 | jni = "0.21.1" 14 | blackboxmc_general = {version = "0.4.0", path = "../blackboxmc-rs-general"} 15 | blackboxmc_java = {version = "0.4.0", path = "../blackboxmc-rs-java"} 16 | -------------------------------------------------------------------------------- /blackboxmc-rs-bungee/src/bungee/api/chat/hover/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod content; 2 | -------------------------------------------------------------------------------- /blackboxmc-rs-bungee/src/bungee/api/mod.rs: -------------------------------------------------------------------------------- 1 | #![allow(deprecated)] 2 | use blackboxmc_general::JNIInstantiatable; 3 | use blackboxmc_general::JNIRaw; 4 | use color_eyre::eyre::Result; 5 | pub enum ChatMessageType<'mc> { 6 | Chat { inner: ChatMessageTypeStruct<'mc> }, 7 | System { inner: ChatMessageTypeStruct<'mc> }, 8 | ActionBar { inner: ChatMessageTypeStruct<'mc> }, 9 | } 10 | impl<'mc> std::fmt::Display for ChatMessageType<'mc> { 11 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 12 | match self { 13 | ChatMessageType::Chat { .. } => f.write_str("CHAT"), 14 | ChatMessageType::System { .. } => f.write_str("SYSTEM"), 15 | ChatMessageType::ActionBar { .. } => f.write_str("ACTION_BAR"), 16 | } 17 | } 18 | } 19 | 20 | impl<'mc> ChatMessageType<'mc> { 21 | pub fn value_of( 22 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 23 | arg0: impl Into, 24 | ) -> Result, Box> { 25 | let val_1 = jni::objects::JObject::from(env.new_string(arg0.into())?); 26 | let cls = env.find_class("net/md_5/bungee/api/ChatMessageType"); 27 | let cls = env.translate_error_with_class(cls)?; 28 | let res = env.call_static_method( 29 | cls, 30 | "valueOf", 31 | "(Ljava/lang/String;)Lnet/md_5/bungee/api/ChatMessageType;", 32 | vec![jni::objects::JValueGen::from(val_1)], 33 | ); 34 | let res = env.translate_error(res)?; 35 | let obj = res.l()?; 36 | let variant = env.call_method(&obj, "toString", "()Ljava/lang/String;", vec![]); 37 | let variant = env.translate_error(variant)?; 38 | let variant_str = env 39 | .get_string(unsafe { &jni::objects::JString::from_raw(variant.as_jni().l) })? 40 | .to_string_lossy() 41 | .to_string(); 42 | match variant_str.as_str() { 43 | "CHAT" => Ok(ChatMessageType::Chat { 44 | inner: ChatMessageTypeStruct::from_raw(env, obj)?, 45 | }), 46 | "SYSTEM" => Ok(ChatMessageType::System { 47 | inner: ChatMessageTypeStruct::from_raw(env, obj)?, 48 | }), 49 | "ACTION_BAR" => Ok(ChatMessageType::ActionBar { 50 | inner: ChatMessageTypeStruct::from_raw(env, obj)?, 51 | }), 52 | 53 | _ => Err(eyre::eyre!("String gaven for variant was invalid").into()), 54 | } 55 | } 56 | } 57 | 58 | #[repr(C)] 59 | pub struct ChatMessageTypeStruct<'mc>( 60 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 61 | pub(crate) jni::objects::JObject<'mc>, 62 | ); 63 | 64 | impl<'mc> JNIRaw<'mc> for ChatMessageType<'mc> { 65 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 66 | match self { 67 | Self::Chat { inner } => inner.0.clone(), 68 | Self::System { inner } => inner.0.clone(), 69 | Self::ActionBar { inner } => inner.0.clone(), 70 | } 71 | } 72 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 73 | match self { 74 | Self::Chat { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) }, 75 | Self::System { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) }, 76 | Self::ActionBar { inner } => unsafe { 77 | jni::objects::JObject::from_raw(inner.1.clone()) 78 | }, 79 | } 80 | } 81 | } 82 | impl<'mc> JNIInstantiatable<'mc> for ChatMessageType<'mc> { 83 | fn from_raw( 84 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 85 | obj: jni::objects::JObject<'mc>, 86 | ) -> Result> { 87 | if obj.is_null() { 88 | return Err( 89 | eyre::eyre!("Tried to instantiate ChatMessageType from null object.").into(), 90 | ); 91 | } 92 | let (valid, name) = env.validate_name(&obj, "net/md_5/bungee/api/ChatMessageType")?; 93 | if !valid { 94 | Err(eyre::eyre!( 95 | "Invalid argument passed. Expected a ChatMessageType object, got {}", 96 | name 97 | ) 98 | .into()) 99 | } else { 100 | let variant = env.call_method(&obj, "toString", "()Ljava/lang/String;", vec![]); 101 | let variant = env.translate_error(variant)?; 102 | let variant_str = env 103 | .get_string(unsafe { &jni::objects::JString::from_raw(variant.as_jni().l) })? 104 | .to_string_lossy() 105 | .to_string(); 106 | match variant_str.as_str() { 107 | "CHAT" => Ok(ChatMessageType::Chat { 108 | inner: ChatMessageTypeStruct::from_raw(env, obj)?, 109 | }), 110 | "SYSTEM" => Ok(ChatMessageType::System { 111 | inner: ChatMessageTypeStruct::from_raw(env, obj)?, 112 | }), 113 | "ACTION_BAR" => Ok(ChatMessageType::ActionBar { 114 | inner: ChatMessageTypeStruct::from_raw(env, obj)?, 115 | }), 116 | _ => Err(eyre::eyre!("String gaven for variant was invalid").into()), 117 | } 118 | } 119 | } 120 | } 121 | 122 | impl<'mc> JNIRaw<'mc> for ChatMessageTypeStruct<'mc> { 123 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 124 | self.0.clone() 125 | } 126 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 127 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 128 | } 129 | } 130 | impl<'mc> JNIInstantiatable<'mc> for ChatMessageTypeStruct<'mc> { 131 | fn from_raw( 132 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 133 | obj: jni::objects::JObject<'mc>, 134 | ) -> Result> { 135 | if obj.is_null() { 136 | return Err(eyre::eyre!( 137 | "Tried to instantiate ChatMessageTypeStruct from null object." 138 | ) 139 | .into()); 140 | } 141 | let (valid, name) = env.validate_name(&obj, "net/md_5/bungee/api/ChatMessageType")?; 142 | if !valid { 143 | Err(eyre::eyre!( 144 | "Invalid argument passed. Expected a ChatMessageTypeStruct object, got {}", 145 | name 146 | ) 147 | .into()) 148 | } else { 149 | Ok(Self(env.clone(), obj)) 150 | } 151 | } 152 | } 153 | 154 | impl<'mc> ChatMessageTypeStruct<'mc> { 155 | pub fn instance_of(&self, other: impl Into) -> Result { 156 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 157 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 158 | } 159 | } 160 | 161 | #[repr(C)] 162 | pub struct ChatColor<'mc>( 163 | pub(crate) blackboxmc_general::SharedJNIEnv<'mc>, 164 | pub(crate) jni::objects::JObject<'mc>, 165 | ); 166 | 167 | impl<'mc> JNIRaw<'mc> for ChatColor<'mc> { 168 | fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> { 169 | self.0.clone() 170 | } 171 | fn jni_object(&self) -> jni::objects::JObject<'mc> { 172 | unsafe { jni::objects::JObject::from_raw(self.1.clone()) } 173 | } 174 | } 175 | impl<'mc> JNIInstantiatable<'mc> for ChatColor<'mc> { 176 | fn from_raw( 177 | env: &blackboxmc_general::SharedJNIEnv<'mc>, 178 | obj: jni::objects::JObject<'mc>, 179 | ) -> Result> { 180 | if obj.is_null() { 181 | return Err(eyre::eyre!("Tried to instantiate ChatColor from null object.").into()); 182 | } 183 | let (valid, name) = env.validate_name(&obj, "net/md_5/bungee/api/ChatColor")?; 184 | if !valid { 185 | Err(eyre::eyre!( 186 | "Invalid argument passed. Expected a ChatColor object, got {}", 187 | name 188 | ) 189 | .into()) 190 | } else { 191 | Ok(Self(env.clone(), obj)) 192 | } 193 | } 194 | } 195 | 196 | impl<'mc> ChatColor<'mc> { 197 | pub fn color(&self) -> Result<(u8, u8, u8), Box> { 198 | let sig = String::from("()Ljava/awt/Color;"); 199 | let res = self 200 | .jni_ref() 201 | .call_method(&self.jni_object(), "getColor", sig.as_str(), vec![]); 202 | let res = self.jni_ref().translate_error(res)?; 203 | let r = self.jni_ref().call_method( 204 | unsafe { jni::objects::JObject::from_raw(res.as_jni().l) }, 205 | "getRed", 206 | "(V)I", 207 | vec![], 208 | ); 209 | let r = self.jni_ref().translate_error(r)?.i()? as u8; 210 | let g = self.jni_ref().call_method( 211 | unsafe { jni::objects::JObject::from_raw(res.as_jni().l) }, 212 | "getGreen", 213 | "(V)I", 214 | vec![], 215 | ); 216 | let g = self.jni_ref().translate_error(g)?.i()? as u8; 217 | let b = self.jni_ref().call_method( 218 | unsafe { jni::objects::JObject::from_raw(res.as_jni().l) }, 219 | "getBlue", 220 | "(V)I", 221 | vec![], 222 | ); 223 | let b = self.jni_ref().translate_error(b)?.i()? as u8; 224 | Ok((r, g, b)) 225 | } 226 | 227 | pub fn get_by_char( 228 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 229 | arg0: u16, 230 | ) -> Result, Box> { 231 | let sig = String::from("(C)Lnet/md_5/bungee/api/ChatColor;"); 232 | let val_1 = jni::objects::JValueGen::Char(arg0); 233 | let cls = jni.find_class("net/md_5/bungee/api/ChatColor"); 234 | let cls = jni.translate_error_with_class(cls)?; 235 | let res = jni.call_static_method( 236 | cls, 237 | "getByChar", 238 | sig.as_str(), 239 | vec![jni::objects::JValueGen::from(val_1)], 240 | ); 241 | let res = jni.translate_error(res)?; 242 | let obj = res.l()?; 243 | crate::bungee::api::ChatColor::from_raw(&jni, obj) 244 | } 245 | 246 | pub fn strip_color( 247 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 248 | arg0: impl Into, 249 | ) -> Result> { 250 | let sig = String::from("(Ljava/lang/String;)Ljava/lang/String;"); 251 | let val_1 = jni::objects::JValueGen::Object(jni::objects::JObject::from( 252 | jni.new_string(arg0.into())?, 253 | )); 254 | let cls = jni.find_class("java/lang/String"); 255 | let cls = jni.translate_error_with_class(cls)?; 256 | let res = jni.call_static_method( 257 | cls, 258 | "stripColor", 259 | sig.as_str(), 260 | vec![jni::objects::JValueGen::from(val_1)], 261 | ); 262 | let res = jni.translate_error(res)?; 263 | Ok(jni 264 | .get_string(unsafe { &jni::objects::JString::from_raw(res.as_jni().l) })? 265 | .to_string_lossy() 266 | .to_string()) 267 | } 268 | 269 | pub fn translate_alternate_color_codes( 270 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 271 | arg0: u16, 272 | arg1: impl Into, 273 | ) -> Result> { 274 | let sig = String::from("(CLjava/lang/String;)Ljava/lang/String;"); 275 | let val_1 = jni::objects::JValueGen::Char(arg0); 276 | let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from( 277 | jni.new_string(arg1.into())?, 278 | )); 279 | let cls = jni.find_class("java/lang/String"); 280 | let cls = jni.translate_error_with_class(cls)?; 281 | let res = jni.call_static_method( 282 | cls, 283 | "translateAlternateColorCodes", 284 | sig.as_str(), 285 | vec![ 286 | jni::objects::JValueGen::from(val_1), 287 | jni::objects::JValueGen::from(val_2), 288 | ], 289 | ); 290 | let res = jni.translate_error(res)?; 291 | Ok(jni 292 | .get_string(unsafe { &jni::objects::JString::from_raw(res.as_jni().l) })? 293 | .to_string_lossy() 294 | .to_string()) 295 | } 296 | 297 | pub fn name(&self) -> Result> { 298 | let args = Vec::new(); 299 | let mut sig = String::from("("); 300 | sig += ")Ljava/lang/String;"; 301 | let res = self 302 | .jni_ref() 303 | .call_method(&self.jni_object(), "name", sig.as_str(), args); 304 | let res = self.jni_ref().translate_error(res)?; 305 | Ok(self 306 | .jni_ref() 307 | .get_string(unsafe { &jni::objects::JString::from_raw(res.as_jni().l) })? 308 | .to_string_lossy() 309 | .to_string()) 310 | } 311 | 312 | pub fn equals( 313 | &self, 314 | arg0: jni::objects::JObject<'mc>, 315 | ) -> Result> { 316 | let sig = String::from("(Ljava/lang/Object;)Z"); 317 | let val_1 = jni::objects::JValueGen::Object(arg0); 318 | let res = self.jni_ref().call_method( 319 | &self.jni_object(), 320 | "equals", 321 | sig.as_str(), 322 | vec![jni::objects::JValueGen::from(val_1)], 323 | ); 324 | let res = self.jni_ref().translate_error(res)?; 325 | Ok(res.z()?) 326 | } 327 | 328 | #[doc(hidden)] 329 | pub fn internal_to_string(&self) -> Result> { 330 | let sig = String::from("()Ljava/lang/String;"); 331 | let res = self 332 | .jni_ref() 333 | .call_method(&self.jni_object(), "toString", sig.as_str(), vec![]); 334 | let res = self.jni_ref().translate_error(res)?; 335 | Ok(self 336 | .jni_ref() 337 | .get_string(unsafe { &jni::objects::JString::from_raw(res.as_jni().l) })? 338 | .to_string_lossy() 339 | .to_string()) 340 | } 341 | 342 | pub fn values( 343 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 344 | ) -> Result>, Box> { 345 | let sig = String::from("()[Lnet/md_5/bungee/api/ChatColor;"); 346 | let cls = jni.find_class("net/md_5/bungee/api/ChatColor"); 347 | let cls = jni.translate_error_with_class(cls)?; 348 | let res = jni.call_static_method(cls, "values", sig.as_str(), vec![]); 349 | let res = jni.translate_error(res)?; 350 | let arr = Into::::into(res.l()?); 351 | let len = jni.get_array_length(&arr)?; 352 | let mut vec = Vec::new(); 353 | for i in 0..len { 354 | let res = jni.get_object_array_element(&arr, i)?; 355 | vec.push({ crate::bungee::api::ChatColor::from_raw(&jni, res)? }); 356 | } 357 | Ok(vec) 358 | } 359 | 360 | pub fn hash_code(&self) -> Result> { 361 | let sig = String::from("()I"); 362 | let res = self 363 | .jni_ref() 364 | .call_method(&self.jni_object(), "hashCode", sig.as_str(), vec![]); 365 | let res = self.jni_ref().translate_error(res)?; 366 | Ok(res.i()?) 367 | } 368 | 369 | pub fn of_with_string( 370 | jni: &blackboxmc_general::SharedJNIEnv<'mc>, 371 | arg0: impl Into, 372 | ) -> Result, Box> { 373 | let mut args = Vec::new(); 374 | let mut sig = String::from("("); 375 | sig += "Ljava/lang/String;"; 376 | let val_1 = jni::objects::JValueGen::Object(jni::objects::JObject::from( 377 | jni.new_string(arg0.into())?, 378 | )); 379 | args.push(val_1); 380 | sig += ")Lnet/md_5/bungee/api/ChatColor;"; 381 | let cls = jni.find_class("net/md_5/bungee/api/ChatColor"); 382 | let cls = jni.translate_error_with_class(cls)?; 383 | let res = jni.call_static_method(cls, "of", sig.as_str(), args); 384 | let res = jni.translate_error(res)?; 385 | let obj = res.l()?; 386 | crate::bungee::api::ChatColor::from_raw(&jni, obj) 387 | } 388 | 389 | pub fn ordinal(&self) -> Result> { 390 | let sig = String::from("()I"); 391 | let res = self 392 | .jni_ref() 393 | .call_method(&self.jni_object(), "ordinal", sig.as_str(), vec![]); 394 | let res = self.jni_ref().translate_error(res)?; 395 | Ok(res.i()?) 396 | } 397 | // SUPER CLASS: Object 398 | 399 | pub fn instance_of(&self, other: impl Into) -> Result { 400 | let cls = &self.jni_ref().find_class(other.into().as_str())?; 401 | self.jni_ref().is_instance_of(&self.jni_object(), cls) 402 | } 403 | } 404 | 405 | impl<'mc> std::string::ToString for ChatColor<'mc> { 406 | fn to_string(&self) -> String { 407 | match &self.internal_to_string() { 408 | Ok(a) => a.clone(), 409 | Err(err) => format!("Error calling ChatColor.toString: {}", err), 410 | } 411 | } 412 | } 413 | 414 | pub mod chat; 415 | -------------------------------------------------------------------------------- /blackboxmc-rs-bungee/src/bungee/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod api; 2 | pub mod chat; 3 | -------------------------------------------------------------------------------- /blackboxmc-rs-bungee/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod bungee; 2 | -------------------------------------------------------------------------------- /blackboxmc-rs-general/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "blackboxmc_general" 3 | version = "0.4.0" 4 | edition = "2021" 5 | license = "LGPL-2.0-or-later" 6 | description = "Helper functions for BlackboxMC" 7 | 8 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 9 | 10 | [dependencies] 11 | color-eyre = "0.6.2" 12 | eyre = "0.6.8" 13 | jni = "0.21.1" 14 | blackboxmc_proc = {version = "0.4.0", path="../blackboxmc-rs-proc"} 15 | once_cell = "1.18.0" 16 | parking_lot = "0.12.1" 17 | 18 | [features] 19 | allow_release_build = [] 20 | -------------------------------------------------------------------------------- /blackboxmc-rs-general/src/macros/memory.rs: -------------------------------------------------------------------------------- 1 | use std::ops::{Deref, DerefMut}; 2 | 3 | use once_cell::sync::Lazy; 4 | use parking_lot::{Mutex, MutexGuard}; 5 | 6 | /// Thread-safe wrapper of [Vec](std::vec::Vec) that lasts for the lifetime of the program. Used by the [extends_blackbox](blackbox_rs::macros::extends_blackbox) macros to allow for dynamic structs that extend Java classes. 7 | pub struct MemoryMap { 8 | parts: Lazy>>>, 9 | } 10 | 11 | impl MemoryMap { 12 | pub const fn new() -> Self { 13 | Self { 14 | parts: Lazy::new(|| Vec::new()), 15 | } 16 | } 17 | pub fn get(&self, index: usize) -> Option> { 18 | match self.parts.get(index) { 19 | Some(a) => match a { 20 | Some(a) => Some(a.lock()), 21 | None => None, 22 | }, 23 | None => None, 24 | } 25 | } 26 | pub fn push(&mut self, item: T) { 27 | self.parts.push(Some(Mutex::new(item))) 28 | } 29 | 30 | // we have to override remove because we cannot allow the vec to be modified, 31 | // because java will always count on the indexes it has bound to structs to be bound to said structs. 32 | pub fn remove(&mut self, index: usize) { 33 | self.parts[index] = None; 34 | } 35 | } 36 | impl Deref for MemoryMap { 37 | type Target = Lazy>>>; 38 | 39 | fn deref(&self) -> &Self::Target { 40 | &self.parts 41 | } 42 | } 43 | impl DerefMut for MemoryMap { 44 | fn deref_mut(&mut self) -> &mut Self::Target { 45 | &mut self.parts 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /blackboxmc-rs-general/src/macros/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod memory; 2 | pub use blackboxmc_proc::*; 3 | -------------------------------------------------------------------------------- /blackboxmc-rs-java/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "blackboxmc_java" 3 | version = "0.4.0" 4 | edition = "2021" 5 | license = "LGPL-2.0-or-later" 6 | description = "BlackboxMC bindings for java.util" 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | blackboxmc_general = {version = "0.4.0", path = "../blackboxmc-rs-general"} 11 | color-eyre = "0.6.2" 12 | eyre = "0.6.8" 13 | jni = "0.21.1" 14 | 15 | [target.'cfg(not(target_arch = "wasm32"))'.dependencies] 16 | libffi = "3.2.0" 17 | -------------------------------------------------------------------------------- /blackboxmc-rs-java/src/lang/lib.rs: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /blackboxmc-rs-java/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod util; 2 | pub mod lang; 3 | -------------------------------------------------------------------------------- /blackboxmc-rs-java/src/security/mod.rs: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /blackboxmc-rs-java/src/util/lib.rs: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /blackboxmc-rs-proc/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "blackbox_rs_proc" 7 | version = "0.1.0" 8 | dependencies = [ 9 | "proc-macro2", 10 | "proc-macro2-diagnostics", 11 | "quote", 12 | "rustc_version", 13 | "syn", 14 | ] 15 | 16 | [[package]] 17 | name = "proc-macro2" 18 | version = "1.0.66" 19 | source = "registry+https://github.com/rust-lang/crates.io-index" 20 | checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" 21 | dependencies = [ 22 | "unicode-ident", 23 | ] 24 | 25 | [[package]] 26 | name = "proc-macro2-diagnostics" 27 | version = "0.10.1" 28 | source = "registry+https://github.com/rust-lang/crates.io-index" 29 | checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" 30 | dependencies = [ 31 | "proc-macro2", 32 | "quote", 33 | "syn", 34 | "version_check", 35 | "yansi", 36 | ] 37 | 38 | [[package]] 39 | name = "quote" 40 | version = "1.0.31" 41 | source = "registry+https://github.com/rust-lang/crates.io-index" 42 | checksum = "5fe8a65d69dd0808184ebb5f836ab526bb259db23c657efa38711b1072ee47f0" 43 | dependencies = [ 44 | "proc-macro2", 45 | ] 46 | 47 | [[package]] 48 | name = "rustc_version" 49 | version = "0.4.0" 50 | source = "registry+https://github.com/rust-lang/crates.io-index" 51 | checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" 52 | dependencies = [ 53 | "semver", 54 | ] 55 | 56 | [[package]] 57 | name = "semver" 58 | version = "1.0.18" 59 | source = "registry+https://github.com/rust-lang/crates.io-index" 60 | checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" 61 | 62 | [[package]] 63 | name = "syn" 64 | version = "2.0.27" 65 | source = "registry+https://github.com/rust-lang/crates.io-index" 66 | checksum = "b60f673f44a8255b9c8c657daf66a596d435f2da81a555b06dc644d080ba45e0" 67 | dependencies = [ 68 | "proc-macro2", 69 | "quote", 70 | "unicode-ident", 71 | ] 72 | 73 | [[package]] 74 | name = "unicode-ident" 75 | version = "1.0.11" 76 | source = "registry+https://github.com/rust-lang/crates.io-index" 77 | checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" 78 | 79 | [[package]] 80 | name = "version_check" 81 | version = "0.9.4" 82 | source = "registry+https://github.com/rust-lang/crates.io-index" 83 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" 84 | 85 | [[package]] 86 | name = "yansi" 87 | version = "1.0.0-rc" 88 | source = "registry+https://github.com/rust-lang/crates.io-index" 89 | checksum = "9ee746ad3851dd3bc40e4a028ab3b00b99278d929e48957bcb2d111874a7e43e" 90 | -------------------------------------------------------------------------------- /blackboxmc-rs-proc/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "blackboxmc_proc" 3 | version = "0.4.0" 4 | edition = "2021" 5 | license = "LGPL-2.0-or-later" 6 | description = "Procedrual macros for the BlackboxMC crates." 7 | 8 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 9 | 10 | [dependencies] 11 | proc-macro2 = "1.0.66" 12 | quote = "1.0.31" 13 | syn = { version = "2.0.27", features = ["full"] } 14 | proc-macro2-diagnostics = "0.10.1" 15 | rustc_version = "0.4.0" 16 | 17 | [lib] 18 | proc-macro = true 19 | -------------------------------------------------------------------------------- /blackboxmc-rs-proc/README.md: -------------------------------------------------------------------------------- 1 | **Currently not useful, was pushed to crates.io in it's state because I forgot to finish it.** 2 | 3 | When at 1.0, this will be a proc macro for automating the process of making classes that inherit ones from Spigot. 4 | -------------------------------------------------------------------------------- /examples/block-break-event/.gitignore: -------------------------------------------------------------------------------- 1 | /target -------------------------------------------------------------------------------- /examples/block-break-event/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "addr2line" 7 | version = "0.20.0" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" 10 | dependencies = [ 11 | "gimli", 12 | ] 13 | 14 | [[package]] 15 | name = "adler" 16 | version = "1.0.2" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" 19 | 20 | [[package]] 21 | name = "autocfg" 22 | version = "1.1.0" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 25 | 26 | [[package]] 27 | name = "backtrace" 28 | version = "0.3.68" 29 | source = "registry+https://github.com/rust-lang/crates.io-index" 30 | checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" 31 | dependencies = [ 32 | "addr2line", 33 | "cc", 34 | "cfg-if", 35 | "libc", 36 | "miniz_oxide", 37 | "object", 38 | "rustc-demangle", 39 | ] 40 | 41 | [[package]] 42 | name = "bitflags" 43 | version = "1.3.2" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 46 | 47 | [[package]] 48 | name = "blackbox_rs" 49 | version = "0.1.0" 50 | dependencies = [ 51 | "blackbox_rs_proc", 52 | "color-eyre", 53 | "eyre", 54 | "jni", 55 | "once_cell", 56 | "parking_lot", 57 | "syn", 58 | ] 59 | 60 | [[package]] 61 | name = "blackbox_rs_proc" 62 | version = "0.1.0" 63 | dependencies = [ 64 | "proc-macro2", 65 | "proc-macro2-diagnostics", 66 | "quote", 67 | "rustc_version", 68 | "syn", 69 | ] 70 | 71 | [[package]] 72 | name = "block-break-event" 73 | version = "0.1.0" 74 | dependencies = [ 75 | "blackbox_rs", 76 | "jni", 77 | ] 78 | 79 | [[package]] 80 | name = "bytes" 81 | version = "1.4.0" 82 | source = "registry+https://github.com/rust-lang/crates.io-index" 83 | checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" 84 | 85 | [[package]] 86 | name = "cc" 87 | version = "1.0.79" 88 | source = "registry+https://github.com/rust-lang/crates.io-index" 89 | checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" 90 | 91 | [[package]] 92 | name = "cesu8" 93 | version = "1.1.0" 94 | source = "registry+https://github.com/rust-lang/crates.io-index" 95 | checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" 96 | 97 | [[package]] 98 | name = "cfg-if" 99 | version = "1.0.0" 100 | source = "registry+https://github.com/rust-lang/crates.io-index" 101 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 102 | 103 | [[package]] 104 | name = "color-eyre" 105 | version = "0.6.2" 106 | source = "registry+https://github.com/rust-lang/crates.io-index" 107 | checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204" 108 | dependencies = [ 109 | "backtrace", 110 | "color-spantrace", 111 | "eyre", 112 | "indenter", 113 | "once_cell", 114 | "owo-colors", 115 | "tracing-error", 116 | ] 117 | 118 | [[package]] 119 | name = "color-spantrace" 120 | version = "0.2.0" 121 | source = "registry+https://github.com/rust-lang/crates.io-index" 122 | checksum = "1ba75b3d9449ecdccb27ecbc479fdc0b87fa2dd43d2f8298f9bf0e59aacc8dce" 123 | dependencies = [ 124 | "once_cell", 125 | "owo-colors", 126 | "tracing-core", 127 | "tracing-error", 128 | ] 129 | 130 | [[package]] 131 | name = "combine" 132 | version = "4.6.6" 133 | source = "registry+https://github.com/rust-lang/crates.io-index" 134 | checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4" 135 | dependencies = [ 136 | "bytes", 137 | "memchr", 138 | ] 139 | 140 | [[package]] 141 | name = "eyre" 142 | version = "0.6.8" 143 | source = "registry+https://github.com/rust-lang/crates.io-index" 144 | checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb" 145 | dependencies = [ 146 | "indenter", 147 | "once_cell", 148 | ] 149 | 150 | [[package]] 151 | name = "gimli" 152 | version = "0.27.3" 153 | source = "registry+https://github.com/rust-lang/crates.io-index" 154 | checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" 155 | 156 | [[package]] 157 | name = "indenter" 158 | version = "0.3.3" 159 | source = "registry+https://github.com/rust-lang/crates.io-index" 160 | checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" 161 | 162 | [[package]] 163 | name = "jni" 164 | version = "0.21.1" 165 | source = "registry+https://github.com/rust-lang/crates.io-index" 166 | checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" 167 | dependencies = [ 168 | "cesu8", 169 | "cfg-if", 170 | "combine", 171 | "jni-sys", 172 | "log", 173 | "thiserror", 174 | "walkdir", 175 | "windows-sys", 176 | ] 177 | 178 | [[package]] 179 | name = "jni-sys" 180 | version = "0.3.0" 181 | source = "registry+https://github.com/rust-lang/crates.io-index" 182 | checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" 183 | 184 | [[package]] 185 | name = "lazy_static" 186 | version = "1.4.0" 187 | source = "registry+https://github.com/rust-lang/crates.io-index" 188 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 189 | 190 | [[package]] 191 | name = "libc" 192 | version = "0.2.147" 193 | source = "registry+https://github.com/rust-lang/crates.io-index" 194 | checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" 195 | 196 | [[package]] 197 | name = "lock_api" 198 | version = "0.4.10" 199 | source = "registry+https://github.com/rust-lang/crates.io-index" 200 | checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" 201 | dependencies = [ 202 | "autocfg", 203 | "scopeguard", 204 | ] 205 | 206 | [[package]] 207 | name = "log" 208 | version = "0.4.19" 209 | source = "registry+https://github.com/rust-lang/crates.io-index" 210 | checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" 211 | 212 | [[package]] 213 | name = "memchr" 214 | version = "2.5.0" 215 | source = "registry+https://github.com/rust-lang/crates.io-index" 216 | checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" 217 | 218 | [[package]] 219 | name = "miniz_oxide" 220 | version = "0.7.1" 221 | source = "registry+https://github.com/rust-lang/crates.io-index" 222 | checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" 223 | dependencies = [ 224 | "adler", 225 | ] 226 | 227 | [[package]] 228 | name = "object" 229 | version = "0.31.1" 230 | source = "registry+https://github.com/rust-lang/crates.io-index" 231 | checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" 232 | dependencies = [ 233 | "memchr", 234 | ] 235 | 236 | [[package]] 237 | name = "once_cell" 238 | version = "1.18.0" 239 | source = "registry+https://github.com/rust-lang/crates.io-index" 240 | checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" 241 | 242 | [[package]] 243 | name = "owo-colors" 244 | version = "3.5.0" 245 | source = "registry+https://github.com/rust-lang/crates.io-index" 246 | checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" 247 | 248 | [[package]] 249 | name = "parking_lot" 250 | version = "0.12.1" 251 | source = "registry+https://github.com/rust-lang/crates.io-index" 252 | checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" 253 | dependencies = [ 254 | "lock_api", 255 | "parking_lot_core", 256 | ] 257 | 258 | [[package]] 259 | name = "parking_lot_core" 260 | version = "0.9.8" 261 | source = "registry+https://github.com/rust-lang/crates.io-index" 262 | checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" 263 | dependencies = [ 264 | "cfg-if", 265 | "libc", 266 | "redox_syscall", 267 | "smallvec", 268 | "windows-targets 0.48.1", 269 | ] 270 | 271 | [[package]] 272 | name = "pin-project-lite" 273 | version = "0.2.10" 274 | source = "registry+https://github.com/rust-lang/crates.io-index" 275 | checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57" 276 | 277 | [[package]] 278 | name = "proc-macro2" 279 | version = "1.0.66" 280 | source = "registry+https://github.com/rust-lang/crates.io-index" 281 | checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" 282 | dependencies = [ 283 | "unicode-ident", 284 | ] 285 | 286 | [[package]] 287 | name = "proc-macro2-diagnostics" 288 | version = "0.10.1" 289 | source = "registry+https://github.com/rust-lang/crates.io-index" 290 | checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" 291 | dependencies = [ 292 | "proc-macro2", 293 | "quote", 294 | "syn", 295 | "version_check", 296 | "yansi", 297 | ] 298 | 299 | [[package]] 300 | name = "quote" 301 | version = "1.0.31" 302 | source = "registry+https://github.com/rust-lang/crates.io-index" 303 | checksum = "5fe8a65d69dd0808184ebb5f836ab526bb259db23c657efa38711b1072ee47f0" 304 | dependencies = [ 305 | "proc-macro2", 306 | ] 307 | 308 | [[package]] 309 | name = "redox_syscall" 310 | version = "0.3.5" 311 | source = "registry+https://github.com/rust-lang/crates.io-index" 312 | checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" 313 | dependencies = [ 314 | "bitflags", 315 | ] 316 | 317 | [[package]] 318 | name = "rustc-demangle" 319 | version = "0.1.23" 320 | source = "registry+https://github.com/rust-lang/crates.io-index" 321 | checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" 322 | 323 | [[package]] 324 | name = "rustc_version" 325 | version = "0.4.0" 326 | source = "registry+https://github.com/rust-lang/crates.io-index" 327 | checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" 328 | dependencies = [ 329 | "semver", 330 | ] 331 | 332 | [[package]] 333 | name = "same-file" 334 | version = "1.0.6" 335 | source = "registry+https://github.com/rust-lang/crates.io-index" 336 | checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" 337 | dependencies = [ 338 | "winapi-util", 339 | ] 340 | 341 | [[package]] 342 | name = "scopeguard" 343 | version = "1.2.0" 344 | source = "registry+https://github.com/rust-lang/crates.io-index" 345 | checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" 346 | 347 | [[package]] 348 | name = "semver" 349 | version = "1.0.18" 350 | source = "registry+https://github.com/rust-lang/crates.io-index" 351 | checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" 352 | 353 | [[package]] 354 | name = "sharded-slab" 355 | version = "0.1.4" 356 | source = "registry+https://github.com/rust-lang/crates.io-index" 357 | checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" 358 | dependencies = [ 359 | "lazy_static", 360 | ] 361 | 362 | [[package]] 363 | name = "smallvec" 364 | version = "1.11.0" 365 | source = "registry+https://github.com/rust-lang/crates.io-index" 366 | checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" 367 | 368 | [[package]] 369 | name = "syn" 370 | version = "2.0.27" 371 | source = "registry+https://github.com/rust-lang/crates.io-index" 372 | checksum = "b60f673f44a8255b9c8c657daf66a596d435f2da81a555b06dc644d080ba45e0" 373 | dependencies = [ 374 | "proc-macro2", 375 | "quote", 376 | "unicode-ident", 377 | ] 378 | 379 | [[package]] 380 | name = "thiserror" 381 | version = "1.0.40" 382 | source = "registry+https://github.com/rust-lang/crates.io-index" 383 | checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" 384 | dependencies = [ 385 | "thiserror-impl", 386 | ] 387 | 388 | [[package]] 389 | name = "thiserror-impl" 390 | version = "1.0.40" 391 | source = "registry+https://github.com/rust-lang/crates.io-index" 392 | checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" 393 | dependencies = [ 394 | "proc-macro2", 395 | "quote", 396 | "syn", 397 | ] 398 | 399 | [[package]] 400 | name = "thread_local" 401 | version = "1.1.7" 402 | source = "registry+https://github.com/rust-lang/crates.io-index" 403 | checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" 404 | dependencies = [ 405 | "cfg-if", 406 | "once_cell", 407 | ] 408 | 409 | [[package]] 410 | name = "tracing" 411 | version = "0.1.37" 412 | source = "registry+https://github.com/rust-lang/crates.io-index" 413 | checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" 414 | dependencies = [ 415 | "cfg-if", 416 | "pin-project-lite", 417 | "tracing-core", 418 | ] 419 | 420 | [[package]] 421 | name = "tracing-core" 422 | version = "0.1.31" 423 | source = "registry+https://github.com/rust-lang/crates.io-index" 424 | checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" 425 | dependencies = [ 426 | "once_cell", 427 | "valuable", 428 | ] 429 | 430 | [[package]] 431 | name = "tracing-error" 432 | version = "0.2.0" 433 | source = "registry+https://github.com/rust-lang/crates.io-index" 434 | checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" 435 | dependencies = [ 436 | "tracing", 437 | "tracing-subscriber", 438 | ] 439 | 440 | [[package]] 441 | name = "tracing-subscriber" 442 | version = "0.3.17" 443 | source = "registry+https://github.com/rust-lang/crates.io-index" 444 | checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" 445 | dependencies = [ 446 | "sharded-slab", 447 | "thread_local", 448 | "tracing-core", 449 | ] 450 | 451 | [[package]] 452 | name = "unicode-ident" 453 | version = "1.0.9" 454 | source = "registry+https://github.com/rust-lang/crates.io-index" 455 | checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" 456 | 457 | [[package]] 458 | name = "valuable" 459 | version = "0.1.0" 460 | source = "registry+https://github.com/rust-lang/crates.io-index" 461 | checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" 462 | 463 | [[package]] 464 | name = "version_check" 465 | version = "0.9.4" 466 | source = "registry+https://github.com/rust-lang/crates.io-index" 467 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" 468 | 469 | [[package]] 470 | name = "walkdir" 471 | version = "2.3.3" 472 | source = "registry+https://github.com/rust-lang/crates.io-index" 473 | checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" 474 | dependencies = [ 475 | "same-file", 476 | "winapi-util", 477 | ] 478 | 479 | [[package]] 480 | name = "winapi" 481 | version = "0.3.9" 482 | source = "registry+https://github.com/rust-lang/crates.io-index" 483 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 484 | dependencies = [ 485 | "winapi-i686-pc-windows-gnu", 486 | "winapi-x86_64-pc-windows-gnu", 487 | ] 488 | 489 | [[package]] 490 | name = "winapi-i686-pc-windows-gnu" 491 | version = "0.4.0" 492 | source = "registry+https://github.com/rust-lang/crates.io-index" 493 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 494 | 495 | [[package]] 496 | name = "winapi-util" 497 | version = "0.1.5" 498 | source = "registry+https://github.com/rust-lang/crates.io-index" 499 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" 500 | dependencies = [ 501 | "winapi", 502 | ] 503 | 504 | [[package]] 505 | name = "winapi-x86_64-pc-windows-gnu" 506 | version = "0.4.0" 507 | source = "registry+https://github.com/rust-lang/crates.io-index" 508 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 509 | 510 | [[package]] 511 | name = "windows-sys" 512 | version = "0.45.0" 513 | source = "registry+https://github.com/rust-lang/crates.io-index" 514 | checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" 515 | dependencies = [ 516 | "windows-targets 0.42.2", 517 | ] 518 | 519 | [[package]] 520 | name = "windows-targets" 521 | version = "0.42.2" 522 | source = "registry+https://github.com/rust-lang/crates.io-index" 523 | checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" 524 | dependencies = [ 525 | "windows_aarch64_gnullvm 0.42.2", 526 | "windows_aarch64_msvc 0.42.2", 527 | "windows_i686_gnu 0.42.2", 528 | "windows_i686_msvc 0.42.2", 529 | "windows_x86_64_gnu 0.42.2", 530 | "windows_x86_64_gnullvm 0.42.2", 531 | "windows_x86_64_msvc 0.42.2", 532 | ] 533 | 534 | [[package]] 535 | name = "windows-targets" 536 | version = "0.48.1" 537 | source = "registry+https://github.com/rust-lang/crates.io-index" 538 | checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" 539 | dependencies = [ 540 | "windows_aarch64_gnullvm 0.48.0", 541 | "windows_aarch64_msvc 0.48.0", 542 | "windows_i686_gnu 0.48.0", 543 | "windows_i686_msvc 0.48.0", 544 | "windows_x86_64_gnu 0.48.0", 545 | "windows_x86_64_gnullvm 0.48.0", 546 | "windows_x86_64_msvc 0.48.0", 547 | ] 548 | 549 | [[package]] 550 | name = "windows_aarch64_gnullvm" 551 | version = "0.42.2" 552 | source = "registry+https://github.com/rust-lang/crates.io-index" 553 | checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" 554 | 555 | [[package]] 556 | name = "windows_aarch64_gnullvm" 557 | version = "0.48.0" 558 | source = "registry+https://github.com/rust-lang/crates.io-index" 559 | checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" 560 | 561 | [[package]] 562 | name = "windows_aarch64_msvc" 563 | version = "0.42.2" 564 | source = "registry+https://github.com/rust-lang/crates.io-index" 565 | checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" 566 | 567 | [[package]] 568 | name = "windows_aarch64_msvc" 569 | version = "0.48.0" 570 | source = "registry+https://github.com/rust-lang/crates.io-index" 571 | checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" 572 | 573 | [[package]] 574 | name = "windows_i686_gnu" 575 | version = "0.42.2" 576 | source = "registry+https://github.com/rust-lang/crates.io-index" 577 | checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" 578 | 579 | [[package]] 580 | name = "windows_i686_gnu" 581 | version = "0.48.0" 582 | source = "registry+https://github.com/rust-lang/crates.io-index" 583 | checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" 584 | 585 | [[package]] 586 | name = "windows_i686_msvc" 587 | version = "0.42.2" 588 | source = "registry+https://github.com/rust-lang/crates.io-index" 589 | checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" 590 | 591 | [[package]] 592 | name = "windows_i686_msvc" 593 | version = "0.48.0" 594 | source = "registry+https://github.com/rust-lang/crates.io-index" 595 | checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" 596 | 597 | [[package]] 598 | name = "windows_x86_64_gnu" 599 | version = "0.42.2" 600 | source = "registry+https://github.com/rust-lang/crates.io-index" 601 | checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" 602 | 603 | [[package]] 604 | name = "windows_x86_64_gnu" 605 | version = "0.48.0" 606 | source = "registry+https://github.com/rust-lang/crates.io-index" 607 | checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" 608 | 609 | [[package]] 610 | name = "windows_x86_64_gnullvm" 611 | version = "0.42.2" 612 | source = "registry+https://github.com/rust-lang/crates.io-index" 613 | checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" 614 | 615 | [[package]] 616 | name = "windows_x86_64_gnullvm" 617 | version = "0.48.0" 618 | source = "registry+https://github.com/rust-lang/crates.io-index" 619 | checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" 620 | 621 | [[package]] 622 | name = "windows_x86_64_msvc" 623 | version = "0.42.2" 624 | source = "registry+https://github.com/rust-lang/crates.io-index" 625 | checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" 626 | 627 | [[package]] 628 | name = "windows_x86_64_msvc" 629 | version = "0.48.0" 630 | source = "registry+https://github.com/rust-lang/crates.io-index" 631 | checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" 632 | 633 | [[package]] 634 | name = "yansi" 635 | version = "1.0.0-rc" 636 | source = "registry+https://github.com/rust-lang/crates.io-index" 637 | checksum = "9ee746ad3851dd3bc40e4a028ab3b00b99278d929e48957bcb2d111874a7e43e" 638 | -------------------------------------------------------------------------------- /examples/block-break-event/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "block-break-event" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | blackboxmc_bukkit = {path="../../blackboxmc-rs-bukkit"} 10 | blackboxmc_general = {path="../../blackboxmc-rs-general"} 11 | jni = "0.21.1" 12 | 13 | [lib] 14 | crate_type = ["cdylib"] 15 | 16 | [profile.release] 17 | opt-level = "z" 18 | lto = true -------------------------------------------------------------------------------- /examples/block-break-event/src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::error::Error; 2 | 3 | use blackboxmc_bukkit::inventory::PlayerInventory; 4 | use blackboxmc_general::JNIInstantiatable; 5 | use blackboxmc_general::SharedJNIEnv; 6 | use jni::{objects::JObject, JNIEnv}; 7 | 8 | #[no_mangle] 9 | pub extern "system" fn __on__BlockBreakEvent(env: JNIEnv<'_>, obj: JObject<'_>) { 10 | let res = || -> Result<(), Box> { 11 | let e = SharedJNIEnv::new(env); 12 | let event = blackboxmc_bukkit::event::block::BlockBreakEvent::from_raw(&e, obj)?; 13 | 14 | // Cancel the event. 15 | event.set_cancelled(true)?; 16 | 17 | let player = event.player()?; 18 | let inv: PlayerInventory = player.inventory()?; 19 | println!("{}", inv.item_in_main_hand()?.get_type()?); 20 | Ok(()) 21 | }(); 22 | if let Err(err) = res { 23 | println!("BlockBreakEvent error: {}", err); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/name-printer/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /examples/name-printer/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "name-printer" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | blackboxmc_bukkit = {path="../../blackboxmc-rs-bukkit"} 10 | blackboxmc_general = {path="../../blackboxmc-rs-general"} 11 | color-eyre = "0.6.2" 12 | jni = "0.21.1" 13 | 14 | [lib] 15 | crate_type = ["cdylib"] 16 | 17 | [profile.release] 18 | opt-level = "z" 19 | lto = true 20 | -------------------------------------------------------------------------------- /examples/name-printer/src/lib.rs: -------------------------------------------------------------------------------- 1 | use blackboxmc_general::JNIInstantiatable; 2 | use std::error::Error; 3 | 4 | use blackboxmc_bukkit::{ 5 | event::server::PluginEnableEvent, plugin::Plugin, scheduler::BukkitRunnable, 6 | }; 7 | use blackboxmc_general::SharedJNIEnv; 8 | use jni::{objects::JObject, sys::jint, JNIEnv}; 9 | 10 | pub struct NamePrinter {} 11 | 12 | impl NamePrinter { 13 | pub fn new<'mc>( 14 | env: &'mc SharedJNIEnv<'mc>, 15 | plugin: &'mc Plugin<'mc>, 16 | ) -> Result, Box> { 17 | BukkitRunnable::from_extendable( 18 | env, 19 | plugin, 20 | 0, 21 | format!("lib{}", std::env!("CARGO_CRATE_NAME")), 22 | "NamePrinter".to_string(), 23 | ) 24 | } 25 | pub fn run(plug: &mut Plugin) -> Result<(), Box> { 26 | let server = plug.server()?; 27 | println!("srever"); 28 | 29 | let players = server.online_players()?; 30 | println!("players"); 31 | 32 | for player in players { 33 | println!("{:?}", player.name()?); 34 | } 35 | Ok(()) 36 | } 37 | } 38 | 39 | #[no_mangle] 40 | pub extern "system" fn __extends__BukkitRunnable__NamePrinter__run<'mc>( 41 | env: JNIEnv<'mc>, 42 | _address: jint, 43 | plugin: JObject<'mc>, 44 | _objs: JObject<'mc>, 45 | ) { 46 | println!("executing...?"); 47 | let e = SharedJNIEnv::new(env); 48 | let mut plug = Plugin::from_raw(&e, plugin).unwrap(); 49 | NamePrinter::run(&mut plug).unwrap(); 50 | println!("executed"); 51 | } 52 | 53 | #[no_mangle] 54 | pub extern "system" fn __on__PluginEnableEvent(env: JNIEnv<'_>, obj: JObject<'_>) { 55 | println!("plugin enable?"); 56 | color_eyre::install().expect("Java exception"); 57 | let e = SharedJNIEnv::new(env); 58 | let ev1 = PluginEnableEvent::from_raw(&e, unsafe { JObject::from_raw(obj.clone()) }) 59 | .expect("Java exception"); 60 | let ev2 = PluginEnableEvent::from_raw(&e, obj).expect("Java exception"); 61 | 62 | let plug1 = ev1.plugin().expect("Java exception"); 63 | let plug2 = ev2.plugin().expect("Java exception"); 64 | // New runnable 65 | println!("run task timer"); 66 | let runnable = NamePrinter::new(&e, &plug1).expect("Java exception"); 67 | runnable 68 | .run_task_timer(plug2, 0, 20) 69 | .expect("Java exception"); 70 | } 71 | -------------------------------------------------------------------------------- /pprint.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import json 3 | 4 | f = open("./spigot.json","r") 5 | print(json.dumps(json.loads("".join(f.readlines())), sort_keys=True, indent=4)) 6 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | // 2 | -------------------------------------------------------------------------------- /src/mod.rs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackBoxMC/blackboxmc-rs/7faecca02864dd5612cbeba1db5805a9987b59ac/src/mod.rs --------------------------------------------------------------------------------