blackboxmc_bukkit/plugin/messaging/
mod.rs

1#![allow(deprecated)]
2use blackboxmc_general::JNIInstantiatable;
3use blackboxmc_general::JNIRaw;
4use color_eyre::eyre::Result;
5#[repr(C)]
6pub struct StandardMessenger<'mc>(
7    pub(crate) blackboxmc_general::SharedJNIEnv<'mc>,
8    pub(crate) jni::objects::JObject<'mc>,
9);
10
11impl<'mc> JNIRaw<'mc> for StandardMessenger<'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}
19impl<'mc> JNIInstantiatable<'mc> for StandardMessenger<'mc> {
20    fn from_raw(
21        env: &blackboxmc_general::SharedJNIEnv<'mc>,
22        obj: jni::objects::JObject<'mc>,
23    ) -> Result<Self, Box<dyn std::error::Error>> {
24        if obj.is_null() {
25            return Err(
26                eyre::eyre!("Tried to instantiate StandardMessenger from null object.").into(),
27            );
28        }
29        let (valid, name) =
30            env.validate_name(&obj, "org/bukkit/plugin/messaging/StandardMessenger")?;
31        if !valid {
32            Err(eyre::eyre!(
33                "Invalid argument passed. Expected a StandardMessenger object, got {}",
34                name
35            )
36            .into())
37        } else {
38            Ok(Self(env.clone(), obj))
39        }
40    }
41}
42
43impl<'mc> StandardMessenger<'mc> {
44    pub fn new(
45        jni: &blackboxmc_general::SharedJNIEnv<'mc>,
46    ) -> Result<crate::plugin::messaging::StandardMessenger<'mc>, Box<dyn std::error::Error>> {
47        let sig = String::from("()V");
48        let cls = jni.find_class("org/bukkit/plugin/messaging/StandardMessenger");
49        let cls = jni.translate_error_with_class(cls)?;
50        let res = jni.new_object(cls, sig.as_str(), vec![]);
51        let res = jni.translate_error_no_gen(res)?;
52        crate::plugin::messaging::StandardMessenger::from_raw(&jni, res)
53    }
54
55    pub fn is_reserved_channel(
56        &self,
57        channel: impl Into<String>,
58    ) -> Result<bool, Box<dyn std::error::Error>> {
59        let sig = String::from("(Ljava/lang/String;)Z");
60        let val_1 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
61            self.jni_ref().new_string(channel.into())?,
62        ));
63        let res = self.jni_ref().call_method(
64            &self.jni_object(),
65            "isReservedChannel",
66            sig.as_str(),
67            vec![jni::objects::JValueGen::from(val_1)],
68        );
69        let res = self.jni_ref().translate_error(res)?;
70        Ok(res.z()?)
71    }
72
73    pub fn register_outgoing_plugin_channel(
74        &self,
75        plugin: impl Into<crate::plugin::Plugin<'mc>>,
76        channel: impl Into<String>,
77    ) -> Result<(), Box<dyn std::error::Error>> {
78        let sig = String::from("(Lorg/bukkit/plugin/Plugin;Ljava/lang/String;)V");
79        let val_1 = jni::objects::JValueGen::Object(unsafe {
80            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
81        });
82        let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
83            self.jni_ref().new_string(channel.into())?,
84        ));
85        let res = self.jni_ref().call_method(
86            &self.jni_object(),
87            "registerOutgoingPluginChannel",
88            sig.as_str(),
89            vec![
90                jni::objects::JValueGen::from(val_1),
91                jni::objects::JValueGen::from(val_2),
92            ],
93        );
94        self.jni_ref().translate_error(res)?;
95        Ok(())
96    }
97
98    pub fn unregister_outgoing_plugin_channel(
99        &self,
100        plugin: impl Into<crate::plugin::Plugin<'mc>>,
101        channel: std::option::Option<impl Into<String>>,
102    ) -> Result<(), Box<dyn std::error::Error>> {
103        let mut args = Vec::new();
104        let mut sig = String::from("(");
105        sig += "Lorg/bukkit/plugin/Plugin;";
106        let val_1 = jni::objects::JValueGen::Object(unsafe {
107            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
108        });
109        args.push(val_1);
110        if let Some(a) = channel {
111            sig += "Ljava/lang/String;";
112            let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
113                self.jni_ref().new_string(a.into())?,
114            ));
115            args.push(val_2);
116        }
117        sig += ")V";
118        let res = self.jni_ref().call_method(
119            &self.jni_object(),
120            "unregisterOutgoingPluginChannel",
121            sig.as_str(),
122            args,
123        );
124        self.jni_ref().translate_error(res)?;
125        Ok(())
126    }
127
128    pub fn register_incoming_plugin_channel(
129        &self,
130        plugin: impl Into<crate::plugin::Plugin<'mc>>,
131        channel: impl Into<String>,
132        listener: impl Into<crate::plugin::messaging::PluginMessageListener<'mc>>,
133    ) -> Result<
134        crate::plugin::messaging::PluginMessageListenerRegistration<'mc>,
135        Box<dyn std::error::Error>,
136    > {
137        let sig = String::from("(Lorg/bukkit/plugin/Plugin;Ljava/lang/String;Lorg/bukkit/plugin/messaging/PluginMessageListener;)Lorg/bukkit/plugin/messaging/PluginMessageListenerRegistration;");
138        let val_1 = jni::objects::JValueGen::Object(unsafe {
139            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
140        });
141        let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
142            self.jni_ref().new_string(channel.into())?,
143        ));
144        let val_3 = jni::objects::JValueGen::Object(unsafe {
145            jni::objects::JObject::from_raw(listener.into().jni_object().clone())
146        });
147        let res = self.jni_ref().call_method(
148            &self.jni_object(),
149            "registerIncomingPluginChannel",
150            sig.as_str(),
151            vec![
152                jni::objects::JValueGen::from(val_1),
153                jni::objects::JValueGen::from(val_2),
154                jni::objects::JValueGen::from(val_3),
155            ],
156        );
157        let res = self.jni_ref().translate_error(res)?;
158        crate::plugin::messaging::PluginMessageListenerRegistration::from_raw(
159            &self.jni_ref(),
160            unsafe { jni::objects::JObject::from_raw(res.l()?.clone()) },
161        )
162    }
163
164    pub fn unregister_incoming_plugin_channel(
165        &self,
166        plugin: impl Into<crate::plugin::Plugin<'mc>>,
167        channel: std::option::Option<impl Into<String>>,
168        listener: std::option::Option<
169            impl Into<crate::plugin::messaging::PluginMessageListener<'mc>>,
170        >,
171    ) -> Result<(), Box<dyn std::error::Error>> {
172        let mut args = Vec::new();
173        let mut sig = String::from("(");
174        sig += "Lorg/bukkit/plugin/Plugin;";
175        let val_1 = jni::objects::JValueGen::Object(unsafe {
176            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
177        });
178        args.push(val_1);
179        if let Some(a) = channel {
180            sig += "Ljava/lang/String;";
181            let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
182                self.jni_ref().new_string(a.into())?,
183            ));
184            args.push(val_2);
185        }
186        if let Some(a) = listener {
187            sig += "Lorg/bukkit/plugin/messaging/PluginMessageListener;";
188            let val_3 = jni::objects::JValueGen::Object(unsafe {
189                jni::objects::JObject::from_raw(a.into().jni_object().clone())
190            });
191            args.push(val_3);
192        }
193        sig += ")V";
194        let res = self.jni_ref().call_method(
195            &self.jni_object(),
196            "unregisterIncomingPluginChannel",
197            sig.as_str(),
198            args,
199        );
200        self.jni_ref().translate_error(res)?;
201        Ok(())
202    }
203
204    pub fn get_outgoing_channels(
205        &self,
206        plugin: impl Into<crate::plugin::Plugin<'mc>>,
207    ) -> Result<blackboxmc_java::util::JavaSet<'mc>, Box<dyn std::error::Error>> {
208        let sig = String::from("(Lorg/bukkit/plugin/Plugin;)Ljava/util/Set;");
209        let val_1 = jni::objects::JValueGen::Object(unsafe {
210            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
211        });
212        let res = self.jni_ref().call_method(
213            &self.jni_object(),
214            "getOutgoingChannels",
215            sig.as_str(),
216            vec![jni::objects::JValueGen::from(val_1)],
217        );
218        let res = self.jni_ref().translate_error(res)?;
219        blackboxmc_java::util::JavaSet::from_raw(&self.jni_ref(), unsafe {
220            jni::objects::JObject::from_raw(res.l()?.clone())
221        })
222    }
223
224    pub fn get_incoming_channels(
225        &self,
226        plugin: impl Into<crate::plugin::Plugin<'mc>>,
227    ) -> Result<blackboxmc_java::util::JavaSet<'mc>, Box<dyn std::error::Error>> {
228        let sig = String::from("(Lorg/bukkit/plugin/Plugin;)Ljava/util/Set;");
229        let val_1 = jni::objects::JValueGen::Object(unsafe {
230            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
231        });
232        let res = self.jni_ref().call_method(
233            &self.jni_object(),
234            "getIncomingChannels",
235            sig.as_str(),
236            vec![jni::objects::JValueGen::from(val_1)],
237        );
238        let res = self.jni_ref().translate_error(res)?;
239        blackboxmc_java::util::JavaSet::from_raw(&self.jni_ref(), unsafe {
240            jni::objects::JObject::from_raw(res.l()?.clone())
241        })
242    }
243
244    pub fn get_incoming_channel_registrations(
245        &self,
246        plugin: impl Into<crate::plugin::Plugin<'mc>>,
247        channel: std::option::Option<impl Into<String>>,
248    ) -> Result<blackboxmc_java::util::JavaSet<'mc>, Box<dyn std::error::Error>> {
249        let mut args = Vec::new();
250        let mut sig = String::from("(");
251        sig += "Lorg/bukkit/plugin/Plugin;";
252        let val_1 = jni::objects::JValueGen::Object(unsafe {
253            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
254        });
255        args.push(val_1);
256        if let Some(a) = channel {
257            sig += "Ljava/lang/String;";
258            let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
259                self.jni_ref().new_string(a.into())?,
260            ));
261            args.push(val_2);
262        }
263        sig += ")Ljava/util/Set;";
264        let res = self.jni_ref().call_method(
265            &self.jni_object(),
266            "getIncomingChannelRegistrations",
267            sig.as_str(),
268            args,
269        );
270        let res = self.jni_ref().translate_error(res)?;
271        blackboxmc_java::util::JavaSet::from_raw(&self.jni_ref(), unsafe {
272            jni::objects::JObject::from_raw(res.l()?.clone())
273        })
274    }
275
276    pub fn is_registration_valid(
277        &self,
278        registration: impl Into<crate::plugin::messaging::PluginMessageListenerRegistration<'mc>>,
279    ) -> Result<bool, Box<dyn std::error::Error>> {
280        let sig =
281            String::from("(Lorg/bukkit/plugin/messaging/PluginMessageListenerRegistration;)Z");
282        let val_1 = jni::objects::JValueGen::Object(unsafe {
283            jni::objects::JObject::from_raw(registration.into().jni_object().clone())
284        });
285        let res = self.jni_ref().call_method(
286            &self.jni_object(),
287            "isRegistrationValid",
288            sig.as_str(),
289            vec![jni::objects::JValueGen::from(val_1)],
290        );
291        let res = self.jni_ref().translate_error(res)?;
292        Ok(res.z()?)
293    }
294
295    pub fn is_incoming_channel_registered(
296        &self,
297        plugin: impl Into<crate::plugin::Plugin<'mc>>,
298        channel: impl Into<String>,
299    ) -> Result<bool, Box<dyn std::error::Error>> {
300        let sig = String::from("(Lorg/bukkit/plugin/Plugin;Ljava/lang/String;)Z");
301        let val_1 = jni::objects::JValueGen::Object(unsafe {
302            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
303        });
304        let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
305            self.jni_ref().new_string(channel.into())?,
306        ));
307        let res = self.jni_ref().call_method(
308            &self.jni_object(),
309            "isIncomingChannelRegistered",
310            sig.as_str(),
311            vec![
312                jni::objects::JValueGen::from(val_1),
313                jni::objects::JValueGen::from(val_2),
314            ],
315        );
316        let res = self.jni_ref().translate_error(res)?;
317        Ok(res.z()?)
318    }
319
320    pub fn is_outgoing_channel_registered(
321        &self,
322        plugin: impl Into<crate::plugin::Plugin<'mc>>,
323        channel: impl Into<String>,
324    ) -> Result<bool, Box<dyn std::error::Error>> {
325        let sig = String::from("(Lorg/bukkit/plugin/Plugin;Ljava/lang/String;)Z");
326        let val_1 = jni::objects::JValueGen::Object(unsafe {
327            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
328        });
329        let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
330            self.jni_ref().new_string(channel.into())?,
331        ));
332        let res = self.jni_ref().call_method(
333            &self.jni_object(),
334            "isOutgoingChannelRegistered",
335            sig.as_str(),
336            vec![
337                jni::objects::JValueGen::from(val_1),
338                jni::objects::JValueGen::from(val_2),
339            ],
340        );
341        let res = self.jni_ref().translate_error(res)?;
342        Ok(res.z()?)
343    }
344
345    pub fn dispatch_incoming_message(
346        &self,
347        source: impl Into<crate::entity::Player<'mc>>,
348        channel: impl Into<String>,
349        message: i8,
350    ) -> Result<(), Box<dyn std::error::Error>> {
351        let sig = String::from("(Lorg/bukkit/entity/Player;Ljava/lang/String;B)V");
352        let val_1 = jni::objects::JValueGen::Object(unsafe {
353            jni::objects::JObject::from_raw(source.into().jni_object().clone())
354        });
355        let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
356            self.jni_ref().new_string(channel.into())?,
357        ));
358        let val_3 = jni::objects::JValueGen::Byte(message);
359        let res = self.jni_ref().call_method(
360            &self.jni_object(),
361            "dispatchIncomingMessage",
362            sig.as_str(),
363            vec![
364                jni::objects::JValueGen::from(val_1),
365                jni::objects::JValueGen::from(val_2),
366                jni::objects::JValueGen::from(val_3),
367            ],
368        );
369        self.jni_ref().translate_error(res)?;
370        Ok(())
371    }
372    #[deprecated]
373    /// Validates a Plugin Channel name.
374    pub fn validate_channel(
375        jni: &blackboxmc_general::SharedJNIEnv<'mc>,
376        channel: impl Into<String>,
377    ) -> Result<(), Box<dyn std::error::Error>> {
378        let sig = String::from("(Ljava/lang/String;)V");
379        let val_1 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
380            jni.new_string(channel.into())?,
381        ));
382        let cls = jni.find_class("org/bukkit/plugin/messaging/StandardMessenger");
383        let cls = jni.translate_error_with_class(cls)?;
384        let res = jni.call_static_method(
385            cls,
386            "validateChannel",
387            sig.as_str(),
388            vec![jni::objects::JValueGen::from(val_1)],
389        );
390        jni.translate_error(res)?;
391        Ok(())
392    }
393    #[deprecated]
394    /// Validates and corrects a Plugin Channel name. Method is not reentrant / idempotent.
395    pub fn validate_and_correct_channel(
396        jni: &blackboxmc_general::SharedJNIEnv<'mc>,
397        channel: impl Into<String>,
398    ) -> Result<String, Box<dyn std::error::Error>> {
399        let sig = String::from("(Ljava/lang/String;)Ljava/lang/String;");
400        let val_1 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
401            jni.new_string(channel.into())?,
402        ));
403        let cls = jni.find_class("org/bukkit/plugin/messaging/StandardMessenger");
404        let cls = jni.translate_error_with_class(cls)?;
405        let res = jni.call_static_method(
406            cls,
407            "validateAndCorrectChannel",
408            sig.as_str(),
409            vec![jni::objects::JValueGen::from(val_1)],
410        );
411        let res = jni.translate_error(res)?;
412        Ok(jni
413            .get_string(unsafe { &jni::objects::JString::from_raw(res.as_jni().l) })?
414            .to_string_lossy()
415            .to_string())
416    }
417    /// Validates the input of a Plugin Message, ensuring the arguments are all
418    /// valid.
419    pub fn validate_plugin_message(
420        jni: &blackboxmc_general::SharedJNIEnv<'mc>,
421        messenger: impl Into<crate::plugin::messaging::Messenger<'mc>>,
422        source: impl Into<crate::plugin::Plugin<'mc>>,
423        channel: impl Into<String>,
424        message: i8,
425    ) -> Result<(), Box<dyn std::error::Error>> {
426        let sig = String::from("(Lorg/bukkit/plugin/messaging/Messenger;Lorg/bukkit/plugin/Plugin;Ljava/lang/String;B)V");
427        let val_1 = jni::objects::JValueGen::Object(unsafe {
428            jni::objects::JObject::from_raw(messenger.into().jni_object().clone())
429        });
430        let val_2 = jni::objects::JValueGen::Object(unsafe {
431            jni::objects::JObject::from_raw(source.into().jni_object().clone())
432        });
433        let val_3 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
434            jni.new_string(channel.into())?,
435        ));
436        let val_4 = jni::objects::JValueGen::Byte(message);
437        let cls = jni.find_class("org/bukkit/plugin/messaging/StandardMessenger");
438        let cls = jni.translate_error_with_class(cls)?;
439        let res = jni.call_static_method(
440            cls,
441            "validatePluginMessage",
442            sig.as_str(),
443            vec![
444                jni::objects::JValueGen::from(val_1),
445                jni::objects::JValueGen::from(val_2),
446                jni::objects::JValueGen::from(val_3),
447                jni::objects::JValueGen::from(val_4),
448            ],
449        );
450        jni.translate_error(res)?;
451        Ok(())
452    }
453
454    pub fn instance_of(&self, other: impl Into<String>) -> Result<bool, jni::errors::Error> {
455        let cls = &self.jni_ref().find_class(other.into().as_str())?;
456        self.jni_ref().is_instance_of(&self.jni_object(), cls)
457    }
458}
459impl<'mc> Into<crate::plugin::messaging::Messenger<'mc>> for StandardMessenger<'mc> {
460    fn into(self) -> crate::plugin::messaging::Messenger<'mc> {
461        crate::plugin::messaging::Messenger::from_raw(&self.jni_ref(), self.1)
462            .expect("Error converting StandardMessenger into crate::plugin::messaging::Messenger")
463    }
464}
465#[repr(C)]
466pub struct PluginMessageListenerRegistration<'mc>(
467    pub(crate) blackboxmc_general::SharedJNIEnv<'mc>,
468    pub(crate) jni::objects::JObject<'mc>,
469);
470
471impl<'mc> JNIRaw<'mc> for PluginMessageListenerRegistration<'mc> {
472    fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> {
473        self.0.clone()
474    }
475    fn jni_object(&self) -> jni::objects::JObject<'mc> {
476        unsafe { jni::objects::JObject::from_raw(self.1.clone()) }
477    }
478}
479impl<'mc> JNIInstantiatable<'mc> for PluginMessageListenerRegistration<'mc> {
480    fn from_raw(
481        env: &blackboxmc_general::SharedJNIEnv<'mc>,
482        obj: jni::objects::JObject<'mc>,
483    ) -> Result<Self, Box<dyn std::error::Error>> {
484        if obj.is_null() {
485            return Err(eyre::eyre!(
486                "Tried to instantiate PluginMessageListenerRegistration from null object."
487            )
488            .into());
489        }
490        let (valid, name) = env.validate_name(
491            &obj,
492            "org/bukkit/plugin/messaging/PluginMessageListenerRegistration",
493        )?;
494        if !valid {
495            Err(eyre::eyre!(
496                    "Invalid argument passed. Expected a PluginMessageListenerRegistration object, got {}",
497                    name
498                )
499                .into())
500        } else {
501            Ok(Self(env.clone(), obj))
502        }
503    }
504}
505
506impl<'mc> PluginMessageListenerRegistration<'mc> {
507    pub fn new(
508        jni: &blackboxmc_general::SharedJNIEnv<'mc>,
509        messenger: impl Into<crate::plugin::messaging::Messenger<'mc>>,
510        plugin: impl Into<crate::plugin::Plugin<'mc>>,
511        channel: impl Into<String>,
512        listener: impl Into<crate::plugin::messaging::PluginMessageListener<'mc>>,
513    ) -> Result<
514        crate::plugin::messaging::PluginMessageListenerRegistration<'mc>,
515        Box<dyn std::error::Error>,
516    > {
517        let sig = String::from("(Lorg/bukkit/plugin/messaging/Messenger;Lorg/bukkit/plugin/Plugin;Ljava/lang/String;Lorg/bukkit/plugin/messaging/PluginMessageListener;)V");
518        let val_1 = jni::objects::JValueGen::Object(unsafe {
519            jni::objects::JObject::from_raw(messenger.into().jni_object().clone())
520        });
521        let val_2 = jni::objects::JValueGen::Object(unsafe {
522            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
523        });
524        let val_3 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
525            jni.new_string(channel.into())?,
526        ));
527        let val_4 = jni::objects::JValueGen::Object(unsafe {
528            jni::objects::JObject::from_raw(listener.into().jni_object().clone())
529        });
530        let cls = jni.find_class("org/bukkit/plugin/messaging/PluginMessageListenerRegistration");
531        let cls = jni.translate_error_with_class(cls)?;
532        let res = jni.new_object(
533            cls,
534            sig.as_str(),
535            vec![
536                jni::objects::JValueGen::from(val_1),
537                jni::objects::JValueGen::from(val_2),
538                jni::objects::JValueGen::from(val_3),
539                jni::objects::JValueGen::from(val_4),
540            ],
541        );
542        let res = jni.translate_error_no_gen(res)?;
543        crate::plugin::messaging::PluginMessageListenerRegistration::from_raw(&jni, res)
544    }
545    /// Gets the plugin channel that this registration is about.
546    pub fn channel(&self) -> Result<String, Box<dyn std::error::Error>> {
547        let sig = String::from("()Ljava/lang/String;");
548        let res =
549            self.jni_ref()
550                .call_method(&self.jni_object(), "getChannel", sig.as_str(), vec![]);
551        let res = self.jni_ref().translate_error(res)?;
552        Ok(self
553            .jni_ref()
554            .get_string(unsafe { &jni::objects::JString::from_raw(res.as_jni().l) })?
555            .to_string_lossy()
556            .to_string())
557    }
558    /// Gets the registered listener described by this registration.
559    pub fn listener(
560        &self,
561    ) -> Result<crate::plugin::messaging::PluginMessageListener<'mc>, Box<dyn std::error::Error>>
562    {
563        let sig = String::from("()Lorg/bukkit/plugin/messaging/PluginMessageListener;");
564        let res =
565            self.jni_ref()
566                .call_method(&self.jni_object(), "getListener", sig.as_str(), vec![]);
567        let res = self.jni_ref().translate_error(res)?;
568        crate::plugin::messaging::PluginMessageListener::from_raw(&self.jni_ref(), unsafe {
569            jni::objects::JObject::from_raw(res.l()?.clone())
570        })
571    }
572    /// Gets the plugin that this registration is for.
573    pub fn plugin(&self) -> Result<crate::plugin::Plugin<'mc>, Box<dyn std::error::Error>> {
574        let sig = String::from("()Lorg/bukkit/plugin/Plugin;");
575        let res = self
576            .jni_ref()
577            .call_method(&self.jni_object(), "getPlugin", sig.as_str(), vec![]);
578        let res = self.jni_ref().translate_error(res)?;
579        crate::plugin::Plugin::from_raw(&self.jni_ref(), unsafe {
580            jni::objects::JObject::from_raw(res.l()?.clone())
581        })
582    }
583    /// Checks if this registration is still valid.
584    pub fn is_valid(&self) -> Result<bool, Box<dyn std::error::Error>> {
585        let sig = String::from("()Z");
586        let res = self
587            .jni_ref()
588            .call_method(&self.jni_object(), "isValid", sig.as_str(), vec![]);
589        let res = self.jni_ref().translate_error(res)?;
590        Ok(res.z()?)
591    }
592
593    pub fn equals(
594        &self,
595        obj: jni::objects::JObject<'mc>,
596    ) -> Result<bool, Box<dyn std::error::Error>> {
597        let sig = String::from("(Ljava/lang/Object;)Z");
598        let val_1 = jni::objects::JValueGen::Object(obj);
599        let res = self.jni_ref().call_method(
600            &self.jni_object(),
601            "equals",
602            sig.as_str(),
603            vec![jni::objects::JValueGen::from(val_1)],
604        );
605        let res = self.jni_ref().translate_error(res)?;
606        Ok(res.z()?)
607    }
608
609    pub fn hash_code(&self) -> Result<i32, Box<dyn std::error::Error>> {
610        let sig = String::from("()I");
611        let res = self
612            .jni_ref()
613            .call_method(&self.jni_object(), "hashCode", sig.as_str(), vec![]);
614        let res = self.jni_ref().translate_error(res)?;
615        Ok(res.i()?)
616    }
617
618    pub fn instance_of(&self, other: impl Into<String>) -> Result<bool, jni::errors::Error> {
619        let cls = &self.jni_ref().find_class(other.into().as_str())?;
620        self.jni_ref().is_instance_of(&self.jni_object(), cls)
621    }
622}
623#[repr(C)]
624pub struct PluginMessageRecipient<'mc>(
625    pub(crate) blackboxmc_general::SharedJNIEnv<'mc>,
626    pub(crate) jni::objects::JObject<'mc>,
627);
628
629impl<'mc> JNIRaw<'mc> for PluginMessageRecipient<'mc> {
630    fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> {
631        self.0.clone()
632    }
633    fn jni_object(&self) -> jni::objects::JObject<'mc> {
634        unsafe { jni::objects::JObject::from_raw(self.1.clone()) }
635    }
636}
637impl<'mc> JNIInstantiatable<'mc> for PluginMessageRecipient<'mc> {
638    fn from_raw(
639        env: &blackboxmc_general::SharedJNIEnv<'mc>,
640        obj: jni::objects::JObject<'mc>,
641    ) -> Result<Self, Box<dyn std::error::Error>> {
642        if obj.is_null() {
643            return Err(eyre::eyre!(
644                "Tried to instantiate PluginMessageRecipient from null object."
645            )
646            .into());
647        }
648        let (valid, name) =
649            env.validate_name(&obj, "org/bukkit/plugin/messaging/PluginMessageRecipient")?;
650        if !valid {
651            Err(eyre::eyre!(
652                "Invalid argument passed. Expected a PluginMessageRecipient object, got {}",
653                name
654            )
655            .into())
656        } else {
657            Ok(Self(env.clone(), obj))
658        }
659    }
660}
661
662impl<'mc> PluginMessageRecipient<'mc> {
663    /// Sends this recipient a Plugin Message on the specified outgoing
664    /// channel.
665    ///
666    /// The message may not be larger than {@link Messenger#MAX_MESSAGE_SIZE}
667    /// bytes, and the plugin must be registered to send messages on the
668    /// specified channel.
669    pub fn send_plugin_message(
670        &self,
671        source: impl Into<crate::plugin::Plugin<'mc>>,
672        channel: impl Into<String>,
673        message: i8,
674    ) -> Result<(), Box<dyn std::error::Error>> {
675        let sig = String::from("(Lorg/bukkit/plugin/Plugin;Ljava/lang/String;B)V");
676        let val_1 = jni::objects::JValueGen::Object(unsafe {
677            jni::objects::JObject::from_raw(source.into().jni_object().clone())
678        });
679        let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
680            self.jni_ref().new_string(channel.into())?,
681        ));
682        let val_3 = jni::objects::JValueGen::Byte(message);
683        let res = self.jni_ref().call_method(
684            &self.jni_object(),
685            "sendPluginMessage",
686            sig.as_str(),
687            vec![
688                jni::objects::JValueGen::from(val_1),
689                jni::objects::JValueGen::from(val_2),
690                jni::objects::JValueGen::from(val_3),
691            ],
692        );
693        self.jni_ref().translate_error(res)?;
694        Ok(())
695    }
696    /// Gets a set containing all the Plugin Channels that this client is
697    /// listening on.
698    pub fn listening_plugin_channels(
699        &self,
700    ) -> Result<blackboxmc_java::util::JavaSet<'mc>, Box<dyn std::error::Error>> {
701        let sig = String::from("()Ljava/util/Set;");
702        let res = self.jni_ref().call_method(
703            &self.jni_object(),
704            "getListeningPluginChannels",
705            sig.as_str(),
706            vec![],
707        );
708        let res = self.jni_ref().translate_error(res)?;
709        blackboxmc_java::util::JavaSet::from_raw(&self.jni_ref(), unsafe {
710            jni::objects::JObject::from_raw(res.l()?.clone())
711        })
712    }
713
714    pub fn instance_of(&self, other: impl Into<String>) -> Result<bool, jni::errors::Error> {
715        let cls = &self.jni_ref().find_class(other.into().as_str())?;
716        self.jni_ref().is_instance_of(&self.jni_object(), cls)
717    }
718}
719#[repr(C)]
720pub struct PluginMessageListener<'mc>(
721    pub(crate) blackboxmc_general::SharedJNIEnv<'mc>,
722    pub(crate) jni::objects::JObject<'mc>,
723);
724
725impl<'mc> JNIRaw<'mc> for PluginMessageListener<'mc> {
726    fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> {
727        self.0.clone()
728    }
729    fn jni_object(&self) -> jni::objects::JObject<'mc> {
730        unsafe { jni::objects::JObject::from_raw(self.1.clone()) }
731    }
732}
733impl<'mc> JNIInstantiatable<'mc> for PluginMessageListener<'mc> {
734    fn from_raw(
735        env: &blackboxmc_general::SharedJNIEnv<'mc>,
736        obj: jni::objects::JObject<'mc>,
737    ) -> Result<Self, Box<dyn std::error::Error>> {
738        if obj.is_null() {
739            return Err(eyre::eyre!(
740                "Tried to instantiate PluginMessageListener from null object."
741            )
742            .into());
743        }
744        let (valid, name) =
745            env.validate_name(&obj, "org/bukkit/plugin/messaging/PluginMessageListener")?;
746        if !valid {
747            Err(eyre::eyre!(
748                "Invalid argument passed. Expected a PluginMessageListener object, got {}",
749                name
750            )
751            .into())
752        } else {
753            Ok(Self(env.clone(), obj))
754        }
755    }
756}
757
758impl<'mc> PluginMessageListener<'mc> {
759    /// A method that will be thrown when a PluginMessageSource sends a plugin
760    /// message on a registered channel.
761    pub fn on_plugin_message_received(
762        &self,
763        channel: impl Into<String>,
764        player: impl Into<crate::entity::Player<'mc>>,
765        message: i8,
766    ) -> Result<(), Box<dyn std::error::Error>> {
767        let sig = String::from("(Ljava/lang/String;Lorg/bukkit/entity/Player;B)V");
768        let val_1 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
769            self.jni_ref().new_string(channel.into())?,
770        ));
771        let val_2 = jni::objects::JValueGen::Object(unsafe {
772            jni::objects::JObject::from_raw(player.into().jni_object().clone())
773        });
774        let val_3 = jni::objects::JValueGen::Byte(message);
775        let res = self.jni_ref().call_method(
776            &self.jni_object(),
777            "onPluginMessageReceived",
778            sig.as_str(),
779            vec![
780                jni::objects::JValueGen::from(val_1),
781                jni::objects::JValueGen::from(val_2),
782                jni::objects::JValueGen::from(val_3),
783            ],
784        );
785        self.jni_ref().translate_error(res)?;
786        Ok(())
787    }
788
789    pub fn instance_of(&self, other: impl Into<String>) -> Result<bool, jni::errors::Error> {
790        let cls = &self.jni_ref().find_class(other.into().as_str())?;
791        self.jni_ref().is_instance_of(&self.jni_object(), cls)
792    }
793}
794#[repr(C)]
795pub struct Messenger<'mc>(
796    pub(crate) blackboxmc_general::SharedJNIEnv<'mc>,
797    pub(crate) jni::objects::JObject<'mc>,
798);
799
800impl<'mc> JNIRaw<'mc> for Messenger<'mc> {
801    fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> {
802        self.0.clone()
803    }
804    fn jni_object(&self) -> jni::objects::JObject<'mc> {
805        unsafe { jni::objects::JObject::from_raw(self.1.clone()) }
806    }
807}
808impl<'mc> JNIInstantiatable<'mc> for Messenger<'mc> {
809    fn from_raw(
810        env: &blackboxmc_general::SharedJNIEnv<'mc>,
811        obj: jni::objects::JObject<'mc>,
812    ) -> Result<Self, Box<dyn std::error::Error>> {
813        if obj.is_null() {
814            return Err(eyre::eyre!("Tried to instantiate Messenger from null object.").into());
815        }
816        let (valid, name) = env.validate_name(&obj, "org/bukkit/plugin/messaging/Messenger")?;
817        if !valid {
818            Err(eyre::eyre!(
819                "Invalid argument passed. Expected a Messenger object, got {}",
820                name
821            )
822            .into())
823        } else {
824            Ok(Self(env.clone(), obj))
825        }
826    }
827}
828
829impl<'mc> Messenger<'mc> {
830    /// Checks if the specified channel is a reserved name.
831    ///
832    /// All channels within the "minecraft" namespace except for
833    /// "minecraft:brand" are reserved.
834    pub fn is_reserved_channel(
835        &self,
836        channel: impl Into<String>,
837    ) -> Result<bool, Box<dyn std::error::Error>> {
838        let sig = String::from("(Ljava/lang/String;)Z");
839        let val_1 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
840            self.jni_ref().new_string(channel.into())?,
841        ));
842        let res = self.jni_ref().call_method(
843            &self.jni_object(),
844            "isReservedChannel",
845            sig.as_str(),
846            vec![jni::objects::JValueGen::from(val_1)],
847        );
848        let res = self.jni_ref().translate_error(res)?;
849        Ok(res.z()?)
850    }
851    /// Registers the specific plugin to the requested outgoing plugin channel,
852    /// allowing it to send messages through that channel to any clients.
853    pub fn register_outgoing_plugin_channel(
854        &self,
855        plugin: impl Into<crate::plugin::Plugin<'mc>>,
856        channel: impl Into<String>,
857    ) -> Result<(), Box<dyn std::error::Error>> {
858        let sig = String::from("(Lorg/bukkit/plugin/Plugin;Ljava/lang/String;)V");
859        let val_1 = jni::objects::JValueGen::Object(unsafe {
860            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
861        });
862        let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
863            self.jni_ref().new_string(channel.into())?,
864        ));
865        let res = self.jni_ref().call_method(
866            &self.jni_object(),
867            "registerOutgoingPluginChannel",
868            sig.as_str(),
869            vec![
870                jni::objects::JValueGen::from(val_1),
871                jni::objects::JValueGen::from(val_2),
872            ],
873        );
874        self.jni_ref().translate_error(res)?;
875        Ok(())
876    }
877    /// Unregisters the specific plugin from the requested outgoing plugin
878    /// channel, no longer allowing it to send messages through that channel to
879    /// any clients.
880    pub fn unregister_outgoing_plugin_channel(
881        &self,
882        plugin: impl Into<crate::plugin::Plugin<'mc>>,
883        channel: std::option::Option<impl Into<String>>,
884    ) -> Result<(), Box<dyn std::error::Error>> {
885        let mut args = Vec::new();
886        let mut sig = String::from("(");
887        sig += "Lorg/bukkit/plugin/Plugin;";
888        let val_1 = jni::objects::JValueGen::Object(unsafe {
889            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
890        });
891        args.push(val_1);
892        if let Some(a) = channel {
893            sig += "Ljava/lang/String;";
894            let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
895                self.jni_ref().new_string(a.into())?,
896            ));
897            args.push(val_2);
898        }
899        sig += ")V";
900        let res = self.jni_ref().call_method(
901            &self.jni_object(),
902            "unregisterOutgoingPluginChannel",
903            sig.as_str(),
904            args,
905        );
906        self.jni_ref().translate_error(res)?;
907        Ok(())
908    }
909    /// Registers the specific plugin for listening on the requested incoming
910    /// plugin channel, allowing it to act upon any plugin messages.
911    pub fn register_incoming_plugin_channel(
912        &self,
913        plugin: impl Into<crate::plugin::Plugin<'mc>>,
914        channel: impl Into<String>,
915        listener: impl Into<crate::plugin::messaging::PluginMessageListener<'mc>>,
916    ) -> Result<
917        crate::plugin::messaging::PluginMessageListenerRegistration<'mc>,
918        Box<dyn std::error::Error>,
919    > {
920        let sig = String::from("(Lorg/bukkit/plugin/Plugin;Ljava/lang/String;Lorg/bukkit/plugin/messaging/PluginMessageListener;)Lorg/bukkit/plugin/messaging/PluginMessageListenerRegistration;");
921        let val_1 = jni::objects::JValueGen::Object(unsafe {
922            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
923        });
924        let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
925            self.jni_ref().new_string(channel.into())?,
926        ));
927        let val_3 = jni::objects::JValueGen::Object(unsafe {
928            jni::objects::JObject::from_raw(listener.into().jni_object().clone())
929        });
930        let res = self.jni_ref().call_method(
931            &self.jni_object(),
932            "registerIncomingPluginChannel",
933            sig.as_str(),
934            vec![
935                jni::objects::JValueGen::from(val_1),
936                jni::objects::JValueGen::from(val_2),
937                jni::objects::JValueGen::from(val_3),
938            ],
939        );
940        let res = self.jni_ref().translate_error(res)?;
941        crate::plugin::messaging::PluginMessageListenerRegistration::from_raw(
942            &self.jni_ref(),
943            unsafe { jni::objects::JObject::from_raw(res.l()?.clone()) },
944        )
945    }
946    /// Unregisters the specific plugin's listener from listening on the
947    /// requested incoming plugin channel, no longer allowing it to act upon
948    /// any plugin messages.
949    pub fn unregister_incoming_plugin_channel(
950        &self,
951        plugin: impl Into<crate::plugin::Plugin<'mc>>,
952        channel: std::option::Option<impl Into<String>>,
953        listener: std::option::Option<
954            impl Into<crate::plugin::messaging::PluginMessageListener<'mc>>,
955        >,
956    ) -> Result<(), Box<dyn std::error::Error>> {
957        let mut args = Vec::new();
958        let mut sig = String::from("(");
959        sig += "Lorg/bukkit/plugin/Plugin;";
960        let val_1 = jni::objects::JValueGen::Object(unsafe {
961            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
962        });
963        args.push(val_1);
964        if let Some(a) = channel {
965            sig += "Ljava/lang/String;";
966            let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
967                self.jni_ref().new_string(a.into())?,
968            ));
969            args.push(val_2);
970        }
971        if let Some(a) = listener {
972            sig += "Lorg/bukkit/plugin/messaging/PluginMessageListener;";
973            let val_3 = jni::objects::JValueGen::Object(unsafe {
974                jni::objects::JObject::from_raw(a.into().jni_object().clone())
975            });
976            args.push(val_3);
977        }
978        sig += ")V";
979        let res = self.jni_ref().call_method(
980            &self.jni_object(),
981            "unregisterIncomingPluginChannel",
982            sig.as_str(),
983            args,
984        );
985        self.jni_ref().translate_error(res)?;
986        Ok(())
987    }
988    /// Gets a set containing all the outgoing plugin channels that the
989    /// specified plugin is registered to.
990    pub fn get_outgoing_channels(
991        &self,
992        plugin: impl Into<crate::plugin::Plugin<'mc>>,
993    ) -> Result<blackboxmc_java::util::JavaSet<'mc>, Box<dyn std::error::Error>> {
994        let sig = String::from("(Lorg/bukkit/plugin/Plugin;)Ljava/util/Set;");
995        let val_1 = jni::objects::JValueGen::Object(unsafe {
996            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
997        });
998        let res = self.jni_ref().call_method(
999            &self.jni_object(),
1000            "getOutgoingChannels",
1001            sig.as_str(),
1002            vec![jni::objects::JValueGen::from(val_1)],
1003        );
1004        let res = self.jni_ref().translate_error(res)?;
1005        blackboxmc_java::util::JavaSet::from_raw(&self.jni_ref(), unsafe {
1006            jni::objects::JObject::from_raw(res.l()?.clone())
1007        })
1008    }
1009    /// Gets a set containing all the incoming plugin channels that the
1010    /// specified plugin is registered for.
1011    pub fn get_incoming_channels(
1012        &self,
1013        plugin: impl Into<crate::plugin::Plugin<'mc>>,
1014    ) -> Result<blackboxmc_java::util::JavaSet<'mc>, Box<dyn std::error::Error>> {
1015        let sig = String::from("(Lorg/bukkit/plugin/Plugin;)Ljava/util/Set;");
1016        let val_1 = jni::objects::JValueGen::Object(unsafe {
1017            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
1018        });
1019        let res = self.jni_ref().call_method(
1020            &self.jni_object(),
1021            "getIncomingChannels",
1022            sig.as_str(),
1023            vec![jni::objects::JValueGen::from(val_1)],
1024        );
1025        let res = self.jni_ref().translate_error(res)?;
1026        blackboxmc_java::util::JavaSet::from_raw(&self.jni_ref(), unsafe {
1027            jni::objects::JObject::from_raw(res.l()?.clone())
1028        })
1029    }
1030    /// Gets a set containing all the incoming plugin channel registrations
1031    /// that the specified plugin has on the requested channel.
1032    pub fn get_incoming_channel_registrations(
1033        &self,
1034        plugin: impl Into<crate::plugin::Plugin<'mc>>,
1035        channel: std::option::Option<impl Into<String>>,
1036    ) -> Result<blackboxmc_java::util::JavaSet<'mc>, Box<dyn std::error::Error>> {
1037        let mut args = Vec::new();
1038        let mut sig = String::from("(");
1039        sig += "Lorg/bukkit/plugin/Plugin;";
1040        let val_1 = jni::objects::JValueGen::Object(unsafe {
1041            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
1042        });
1043        args.push(val_1);
1044        if let Some(a) = channel {
1045            sig += "Ljava/lang/String;";
1046            let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
1047                self.jni_ref().new_string(a.into())?,
1048            ));
1049            args.push(val_2);
1050        }
1051        sig += ")Ljava/util/Set;";
1052        let res = self.jni_ref().call_method(
1053            &self.jni_object(),
1054            "getIncomingChannelRegistrations",
1055            sig.as_str(),
1056            args,
1057        );
1058        let res = self.jni_ref().translate_error(res)?;
1059        blackboxmc_java::util::JavaSet::from_raw(&self.jni_ref(), unsafe {
1060            jni::objects::JObject::from_raw(res.l()?.clone())
1061        })
1062    }
1063    /// Checks if the specified plugin message listener registration is valid.
1064    ///
1065    /// A registration is considered valid if it has not be unregistered and
1066    /// that the plugin is still enabled.
1067    pub fn is_registration_valid(
1068        &self,
1069        registration: impl Into<crate::plugin::messaging::PluginMessageListenerRegistration<'mc>>,
1070    ) -> Result<bool, Box<dyn std::error::Error>> {
1071        let sig =
1072            String::from("(Lorg/bukkit/plugin/messaging/PluginMessageListenerRegistration;)Z");
1073        let val_1 = jni::objects::JValueGen::Object(unsafe {
1074            jni::objects::JObject::from_raw(registration.into().jni_object().clone())
1075        });
1076        let res = self.jni_ref().call_method(
1077            &self.jni_object(),
1078            "isRegistrationValid",
1079            sig.as_str(),
1080            vec![jni::objects::JValueGen::from(val_1)],
1081        );
1082        let res = self.jni_ref().translate_error(res)?;
1083        Ok(res.z()?)
1084    }
1085    /// Checks if the specified plugin has registered to receive incoming
1086    /// messages through the requested channel.
1087    pub fn is_incoming_channel_registered(
1088        &self,
1089        plugin: impl Into<crate::plugin::Plugin<'mc>>,
1090        channel: impl Into<String>,
1091    ) -> Result<bool, Box<dyn std::error::Error>> {
1092        let sig = String::from("(Lorg/bukkit/plugin/Plugin;Ljava/lang/String;)Z");
1093        let val_1 = jni::objects::JValueGen::Object(unsafe {
1094            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
1095        });
1096        let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
1097            self.jni_ref().new_string(channel.into())?,
1098        ));
1099        let res = self.jni_ref().call_method(
1100            &self.jni_object(),
1101            "isIncomingChannelRegistered",
1102            sig.as_str(),
1103            vec![
1104                jni::objects::JValueGen::from(val_1),
1105                jni::objects::JValueGen::from(val_2),
1106            ],
1107        );
1108        let res = self.jni_ref().translate_error(res)?;
1109        Ok(res.z()?)
1110    }
1111    /// Checks if the specified plugin has registered to send outgoing messages
1112    /// through the requested channel.
1113    pub fn is_outgoing_channel_registered(
1114        &self,
1115        plugin: impl Into<crate::plugin::Plugin<'mc>>,
1116        channel: impl Into<String>,
1117    ) -> Result<bool, Box<dyn std::error::Error>> {
1118        let sig = String::from("(Lorg/bukkit/plugin/Plugin;Ljava/lang/String;)Z");
1119        let val_1 = jni::objects::JValueGen::Object(unsafe {
1120            jni::objects::JObject::from_raw(plugin.into().jni_object().clone())
1121        });
1122        let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
1123            self.jni_ref().new_string(channel.into())?,
1124        ));
1125        let res = self.jni_ref().call_method(
1126            &self.jni_object(),
1127            "isOutgoingChannelRegistered",
1128            sig.as_str(),
1129            vec![
1130                jni::objects::JValueGen::from(val_1),
1131                jni::objects::JValueGen::from(val_2),
1132            ],
1133        );
1134        let res = self.jni_ref().translate_error(res)?;
1135        Ok(res.z()?)
1136    }
1137    /// Dispatches the specified incoming message to any registered listeners.
1138    pub fn dispatch_incoming_message(
1139        &self,
1140        source: impl Into<crate::entity::Player<'mc>>,
1141        channel: impl Into<String>,
1142        message: i8,
1143    ) -> Result<(), Box<dyn std::error::Error>> {
1144        let sig = String::from("(Lorg/bukkit/entity/Player;Ljava/lang/String;B)V");
1145        let val_1 = jni::objects::JValueGen::Object(unsafe {
1146            jni::objects::JObject::from_raw(source.into().jni_object().clone())
1147        });
1148        let val_2 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
1149            self.jni_ref().new_string(channel.into())?,
1150        ));
1151        let val_3 = jni::objects::JValueGen::Byte(message);
1152        let res = self.jni_ref().call_method(
1153            &self.jni_object(),
1154            "dispatchIncomingMessage",
1155            sig.as_str(),
1156            vec![
1157                jni::objects::JValueGen::from(val_1),
1158                jni::objects::JValueGen::from(val_2),
1159                jni::objects::JValueGen::from(val_3),
1160            ],
1161        );
1162        self.jni_ref().translate_error(res)?;
1163        Ok(())
1164    }
1165
1166    pub fn instance_of(&self, other: impl Into<String>) -> Result<bool, jni::errors::Error> {
1167        let cls = &self.jni_ref().find_class(other.into().as_str())?;
1168        self.jni_ref().is_instance_of(&self.jni_object(), cls)
1169    }
1170}
1171#[repr(C)]
1172pub struct MessageTooLargeException<'mc>(
1173    pub(crate) blackboxmc_general::SharedJNIEnv<'mc>,
1174    pub(crate) jni::objects::JObject<'mc>,
1175);
1176
1177impl<'mc> JNIRaw<'mc> for MessageTooLargeException<'mc> {
1178    fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> {
1179        self.0.clone()
1180    }
1181    fn jni_object(&self) -> jni::objects::JObject<'mc> {
1182        unsafe { jni::objects::JObject::from_raw(self.1.clone()) }
1183    }
1184}
1185impl<'mc> JNIInstantiatable<'mc> for MessageTooLargeException<'mc> {
1186    fn from_raw(
1187        env: &blackboxmc_general::SharedJNIEnv<'mc>,
1188        obj: jni::objects::JObject<'mc>,
1189    ) -> Result<Self, Box<dyn std::error::Error>> {
1190        if obj.is_null() {
1191            return Err(eyre::eyre!(
1192                "Tried to instantiate MessageTooLargeException from null object."
1193            )
1194            .into());
1195        }
1196        let (valid, name) =
1197            env.validate_name(&obj, "org/bukkit/plugin/messaging/MessageTooLargeException")?;
1198        if !valid {
1199            Err(eyre::eyre!(
1200                "Invalid argument passed. Expected a MessageTooLargeException object, got {}",
1201                name
1202            )
1203            .into())
1204        } else {
1205            Ok(Self(env.clone(), obj))
1206        }
1207    }
1208}
1209
1210impl<'mc> MessageTooLargeException<'mc> {
1211    pub fn new(
1212        jni: &blackboxmc_general::SharedJNIEnv<'mc>,
1213        msg: std::option::Option<impl Into<String>>,
1214    ) -> Result<crate::plugin::messaging::MessageTooLargeException<'mc>, Box<dyn std::error::Error>>
1215    {
1216        let mut args = Vec::new();
1217        let mut sig = String::from("(");
1218        if let Some(a) = msg {
1219            sig += "Ljava/lang/String;";
1220            let val_1 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
1221                jni.new_string(a.into())?,
1222            ));
1223            args.push(val_1);
1224        }
1225        sig += ")V";
1226        let cls = jni.find_class("org/bukkit/plugin/messaging/MessageTooLargeException");
1227        let cls = jni.translate_error_with_class(cls)?;
1228        let res = jni.new_object(cls, sig.as_str(), args);
1229        let res = jni.translate_error_no_gen(res)?;
1230        crate::plugin::messaging::MessageTooLargeException::from_raw(&jni, res)
1231    }
1232
1233    pub fn instance_of(&self, other: impl Into<String>) -> Result<bool, jni::errors::Error> {
1234        let cls = &self.jni_ref().find_class(other.into().as_str())?;
1235        self.jni_ref().is_instance_of(&self.jni_object(), cls)
1236    }
1237}
1238#[repr(C)]
1239pub struct ChannelNameTooLongException<'mc>(
1240    pub(crate) blackboxmc_general::SharedJNIEnv<'mc>,
1241    pub(crate) jni::objects::JObject<'mc>,
1242);
1243
1244impl<'mc> JNIRaw<'mc> for ChannelNameTooLongException<'mc> {
1245    fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> {
1246        self.0.clone()
1247    }
1248    fn jni_object(&self) -> jni::objects::JObject<'mc> {
1249        unsafe { jni::objects::JObject::from_raw(self.1.clone()) }
1250    }
1251}
1252impl<'mc> JNIInstantiatable<'mc> for ChannelNameTooLongException<'mc> {
1253    fn from_raw(
1254        env: &blackboxmc_general::SharedJNIEnv<'mc>,
1255        obj: jni::objects::JObject<'mc>,
1256    ) -> Result<Self, Box<dyn std::error::Error>> {
1257        if obj.is_null() {
1258            return Err(eyre::eyre!(
1259                "Tried to instantiate ChannelNameTooLongException from null object."
1260            )
1261            .into());
1262        }
1263        let (valid, name) = env.validate_name(
1264            &obj,
1265            "org/bukkit/plugin/messaging/ChannelNameTooLongException",
1266        )?;
1267        if !valid {
1268            Err(eyre::eyre!(
1269                "Invalid argument passed. Expected a ChannelNameTooLongException object, got {}",
1270                name
1271            )
1272            .into())
1273        } else {
1274            Ok(Self(env.clone(), obj))
1275        }
1276    }
1277}
1278
1279impl<'mc> ChannelNameTooLongException<'mc> {
1280    pub fn new(
1281        jni: &blackboxmc_general::SharedJNIEnv<'mc>,
1282        channel: std::option::Option<impl Into<String>>,
1283    ) -> Result<
1284        crate::plugin::messaging::ChannelNameTooLongException<'mc>,
1285        Box<dyn std::error::Error>,
1286    > {
1287        let mut args = Vec::new();
1288        let mut sig = String::from("(");
1289        if let Some(a) = channel {
1290            sig += "Ljava/lang/String;";
1291            let val_1 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
1292                jni.new_string(a.into())?,
1293            ));
1294            args.push(val_1);
1295        }
1296        sig += ")V";
1297        let cls = jni.find_class("org/bukkit/plugin/messaging/ChannelNameTooLongException");
1298        let cls = jni.translate_error_with_class(cls)?;
1299        let res = jni.new_object(cls, sig.as_str(), args);
1300        let res = jni.translate_error_no_gen(res)?;
1301        crate::plugin::messaging::ChannelNameTooLongException::from_raw(&jni, res)
1302    }
1303
1304    pub fn instance_of(&self, other: impl Into<String>) -> Result<bool, jni::errors::Error> {
1305        let cls = &self.jni_ref().find_class(other.into().as_str())?;
1306        self.jni_ref().is_instance_of(&self.jni_object(), cls)
1307    }
1308}
1309pub enum PluginChannelDirection<'mc> {
1310    Incoming {
1311        inner: PluginChannelDirectionStruct<'mc>,
1312    },
1313    Outgoing {
1314        inner: PluginChannelDirectionStruct<'mc>,
1315    },
1316}
1317impl<'mc> std::fmt::Display for PluginChannelDirection<'mc> {
1318    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1319        match self {
1320            PluginChannelDirection::Incoming { .. } => f.write_str("INCOMING"),
1321            PluginChannelDirection::Outgoing { .. } => f.write_str("OUTGOING"),
1322        }
1323    }
1324}
1325impl<'mc> std::ops::Deref for PluginChannelDirection<'mc> {
1326    type Target = PluginChannelDirectionStruct<'mc>;
1327    fn deref(&self) -> &<PluginChannelDirection<'mc> as std::ops::Deref>::Target {
1328        match self {
1329            PluginChannelDirection::Incoming { inner } => inner,
1330            PluginChannelDirection::Outgoing { inner } => inner,
1331        }
1332    }
1333}
1334
1335impl<'mc> PluginChannelDirection<'mc> {
1336    pub fn value_of(
1337        env: &blackboxmc_general::SharedJNIEnv<'mc>,
1338        arg0: impl Into<String>,
1339    ) -> Result<PluginChannelDirection<'mc>, Box<dyn std::error::Error>> {
1340        let val_1 = jni::objects::JObject::from(env.new_string(arg0.into())?);
1341        let cls = env.find_class("org/bukkit/plugin/messaging/PluginChannelDirection");
1342        let cls = env.translate_error_with_class(cls)?;
1343        let res = env.call_static_method(
1344            cls,
1345            "valueOf",
1346            "(Ljava/lang/String;)Lorg/bukkit/plugin/messaging/PluginChannelDirection;",
1347            vec![jni::objects::JValueGen::from(val_1)],
1348        );
1349        let res = env.translate_error(res)?;
1350        let obj = res.l()?;
1351        let variant = env.call_method(&obj, "toString", "()Ljava/lang/String;", vec![]);
1352        let variant = env.translate_error(variant)?;
1353        let variant_str = env
1354            .get_string(unsafe { &jni::objects::JString::from_raw(variant.as_jni().l) })?
1355            .to_string_lossy()
1356            .to_string();
1357        match variant_str.as_str() {
1358            "INCOMING" => Ok(PluginChannelDirection::Incoming {
1359                inner: PluginChannelDirectionStruct::from_raw(env, obj)?,
1360            }),
1361            "OUTGOING" => Ok(PluginChannelDirection::Outgoing {
1362                inner: PluginChannelDirectionStruct::from_raw(env, obj)?,
1363            }),
1364
1365            _ => Err(eyre::eyre!("String gaven for variant was invalid").into()),
1366        }
1367    }
1368}
1369
1370#[repr(C)]
1371pub struct PluginChannelDirectionStruct<'mc>(
1372    pub(crate) blackboxmc_general::SharedJNIEnv<'mc>,
1373    pub(crate) jni::objects::JObject<'mc>,
1374);
1375
1376impl<'mc> JNIRaw<'mc> for PluginChannelDirection<'mc> {
1377    fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> {
1378        match self {
1379            Self::Incoming { inner } => inner.0.clone(),
1380            Self::Outgoing { inner } => inner.0.clone(),
1381        }
1382    }
1383    fn jni_object(&self) -> jni::objects::JObject<'mc> {
1384        match self {
1385            Self::Incoming { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) },
1386            Self::Outgoing { inner } => unsafe { jni::objects::JObject::from_raw(inner.1.clone()) },
1387        }
1388    }
1389}
1390impl<'mc> JNIInstantiatable<'mc> for PluginChannelDirection<'mc> {
1391    fn from_raw(
1392        env: &blackboxmc_general::SharedJNIEnv<'mc>,
1393        obj: jni::objects::JObject<'mc>,
1394    ) -> Result<Self, Box<dyn std::error::Error>> {
1395        if obj.is_null() {
1396            return Err(eyre::eyre!(
1397                "Tried to instantiate PluginChannelDirection from null object."
1398            )
1399            .into());
1400        }
1401        let (valid, name) =
1402            env.validate_name(&obj, "org/bukkit/plugin/messaging/PluginChannelDirection")?;
1403        if !valid {
1404            Err(eyre::eyre!(
1405                "Invalid argument passed. Expected a PluginChannelDirection object, got {}",
1406                name
1407            )
1408            .into())
1409        } else {
1410            let variant = env.call_method(&obj, "toString", "()Ljava/lang/String;", vec![]);
1411            let variant = env.translate_error(variant)?;
1412            let variant_str = env
1413                .get_string(unsafe { &jni::objects::JString::from_raw(variant.as_jni().l) })?
1414                .to_string_lossy()
1415                .to_string();
1416            match variant_str.as_str() {
1417                "INCOMING" => Ok(PluginChannelDirection::Incoming {
1418                    inner: PluginChannelDirectionStruct::from_raw(env, obj)?,
1419                }),
1420                "OUTGOING" => Ok(PluginChannelDirection::Outgoing {
1421                    inner: PluginChannelDirectionStruct::from_raw(env, obj)?,
1422                }),
1423                _ => Err(eyre::eyre!("String gaven for variant was invalid").into()),
1424            }
1425        }
1426    }
1427}
1428
1429impl<'mc> JNIRaw<'mc> for PluginChannelDirectionStruct<'mc> {
1430    fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> {
1431        self.0.clone()
1432    }
1433    fn jni_object(&self) -> jni::objects::JObject<'mc> {
1434        unsafe { jni::objects::JObject::from_raw(self.1.clone()) }
1435    }
1436}
1437impl<'mc> JNIInstantiatable<'mc> for PluginChannelDirectionStruct<'mc> {
1438    fn from_raw(
1439        env: &blackboxmc_general::SharedJNIEnv<'mc>,
1440        obj: jni::objects::JObject<'mc>,
1441    ) -> Result<Self, Box<dyn std::error::Error>> {
1442        if obj.is_null() {
1443            return Err(eyre::eyre!(
1444                "Tried to instantiate PluginChannelDirectionStruct from null object."
1445            )
1446            .into());
1447        }
1448        let (valid, name) =
1449            env.validate_name(&obj, "org/bukkit/plugin/messaging/PluginChannelDirection")?;
1450        if !valid {
1451            Err(eyre::eyre!(
1452                "Invalid argument passed. Expected a PluginChannelDirectionStruct object, got {}",
1453                name
1454            )
1455            .into())
1456        } else {
1457            Ok(Self(env.clone(), obj))
1458        }
1459    }
1460}
1461
1462impl<'mc> PluginChannelDirectionStruct<'mc> {
1463    pub fn values(
1464        jni: &blackboxmc_general::SharedJNIEnv<'mc>,
1465    ) -> Result<crate::plugin::messaging::PluginChannelDirection<'mc>, Box<dyn std::error::Error>>
1466    {
1467        let sig = String::from("()Lorg/bukkit/plugin/messaging/PluginChannelDirection;");
1468        let cls = jni.find_class("org/bukkit/plugin/messaging/PluginChannelDirection");
1469        let cls = jni.translate_error_with_class(cls)?;
1470        let res = jni.call_static_method(cls, "values", sig.as_str(), vec![]);
1471        let res = jni.translate_error(res)?;
1472        let obj = res.l()?;
1473        crate::plugin::messaging::PluginChannelDirection::from_raw(&jni, obj)
1474    }
1475
1476    pub fn instance_of(&self, other: impl Into<String>) -> Result<bool, jni::errors::Error> {
1477        let cls = &self.jni_ref().find_class(other.into().as_str())?;
1478        self.jni_ref().is_instance_of(&self.jni_object(), cls)
1479    }
1480}
1481#[repr(C)]
1482pub struct ReservedChannelException<'mc>(
1483    pub(crate) blackboxmc_general::SharedJNIEnv<'mc>,
1484    pub(crate) jni::objects::JObject<'mc>,
1485);
1486
1487impl<'mc> JNIRaw<'mc> for ReservedChannelException<'mc> {
1488    fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> {
1489        self.0.clone()
1490    }
1491    fn jni_object(&self) -> jni::objects::JObject<'mc> {
1492        unsafe { jni::objects::JObject::from_raw(self.1.clone()) }
1493    }
1494}
1495impl<'mc> JNIInstantiatable<'mc> for ReservedChannelException<'mc> {
1496    fn from_raw(
1497        env: &blackboxmc_general::SharedJNIEnv<'mc>,
1498        obj: jni::objects::JObject<'mc>,
1499    ) -> Result<Self, Box<dyn std::error::Error>> {
1500        if obj.is_null() {
1501            return Err(eyre::eyre!(
1502                "Tried to instantiate ReservedChannelException from null object."
1503            )
1504            .into());
1505        }
1506        let (valid, name) =
1507            env.validate_name(&obj, "org/bukkit/plugin/messaging/ReservedChannelException")?;
1508        if !valid {
1509            Err(eyre::eyre!(
1510                "Invalid argument passed. Expected a ReservedChannelException object, got {}",
1511                name
1512            )
1513            .into())
1514        } else {
1515            Ok(Self(env.clone(), obj))
1516        }
1517    }
1518}
1519
1520impl<'mc> ReservedChannelException<'mc> {
1521    pub fn new(
1522        jni: &blackboxmc_general::SharedJNIEnv<'mc>,
1523        name: std::option::Option<impl Into<String>>,
1524    ) -> Result<crate::plugin::messaging::ReservedChannelException<'mc>, Box<dyn std::error::Error>>
1525    {
1526        let mut args = Vec::new();
1527        let mut sig = String::from("(");
1528        if let Some(a) = name {
1529            sig += "Ljava/lang/String;";
1530            let val_1 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
1531                jni.new_string(a.into())?,
1532            ));
1533            args.push(val_1);
1534        }
1535        sig += ")V";
1536        let cls = jni.find_class("org/bukkit/plugin/messaging/ReservedChannelException");
1537        let cls = jni.translate_error_with_class(cls)?;
1538        let res = jni.new_object(cls, sig.as_str(), args);
1539        let res = jni.translate_error_no_gen(res)?;
1540        crate::plugin::messaging::ReservedChannelException::from_raw(&jni, res)
1541    }
1542
1543    pub fn instance_of(&self, other: impl Into<String>) -> Result<bool, jni::errors::Error> {
1544        let cls = &self.jni_ref().find_class(other.into().as_str())?;
1545        self.jni_ref().is_instance_of(&self.jni_object(), cls)
1546    }
1547}
1548#[repr(C)]
1549pub struct ChannelNotRegisteredException<'mc>(
1550    pub(crate) blackboxmc_general::SharedJNIEnv<'mc>,
1551    pub(crate) jni::objects::JObject<'mc>,
1552);
1553
1554impl<'mc> JNIRaw<'mc> for ChannelNotRegisteredException<'mc> {
1555    fn jni_ref(&self) -> blackboxmc_general::SharedJNIEnv<'mc> {
1556        self.0.clone()
1557    }
1558    fn jni_object(&self) -> jni::objects::JObject<'mc> {
1559        unsafe { jni::objects::JObject::from_raw(self.1.clone()) }
1560    }
1561}
1562impl<'mc> JNIInstantiatable<'mc> for ChannelNotRegisteredException<'mc> {
1563    fn from_raw(
1564        env: &blackboxmc_general::SharedJNIEnv<'mc>,
1565        obj: jni::objects::JObject<'mc>,
1566    ) -> Result<Self, Box<dyn std::error::Error>> {
1567        if obj.is_null() {
1568            return Err(eyre::eyre!(
1569                "Tried to instantiate ChannelNotRegisteredException from null object."
1570            )
1571            .into());
1572        }
1573        let (valid, name) = env.validate_name(
1574            &obj,
1575            "org/bukkit/plugin/messaging/ChannelNotRegisteredException",
1576        )?;
1577        if !valid {
1578            Err(eyre::eyre!(
1579                "Invalid argument passed. Expected a ChannelNotRegisteredException object, got {}",
1580                name
1581            )
1582            .into())
1583        } else {
1584            Ok(Self(env.clone(), obj))
1585        }
1586    }
1587}
1588
1589impl<'mc> ChannelNotRegisteredException<'mc> {
1590    pub fn new(
1591        jni: &blackboxmc_general::SharedJNIEnv<'mc>,
1592        channel: std::option::Option<impl Into<String>>,
1593    ) -> Result<
1594        crate::plugin::messaging::ChannelNotRegisteredException<'mc>,
1595        Box<dyn std::error::Error>,
1596    > {
1597        let mut args = Vec::new();
1598        let mut sig = String::from("(");
1599        if let Some(a) = channel {
1600            sig += "Ljava/lang/String;";
1601            let val_1 = jni::objects::JValueGen::Object(jni::objects::JObject::from(
1602                jni.new_string(a.into())?,
1603            ));
1604            args.push(val_1);
1605        }
1606        sig += ")V";
1607        let cls = jni.find_class("org/bukkit/plugin/messaging/ChannelNotRegisteredException");
1608        let cls = jni.translate_error_with_class(cls)?;
1609        let res = jni.new_object(cls, sig.as_str(), args);
1610        let res = jni.translate_error_no_gen(res)?;
1611        crate::plugin::messaging::ChannelNotRegisteredException::from_raw(&jni, res)
1612    }
1613
1614    pub fn instance_of(&self, other: impl Into<String>) -> Result<bool, jni::errors::Error> {
1615        let cls = &self.jni_ref().find_class(other.into().as_str())?;
1616        self.jni_ref().is_instance_of(&self.jni_object(), cls)
1617    }
1618}