Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

LiquidBounce Forum

  1. Home
  2. General
  3. BlockBBEvent in scripts?

BlockBBEvent in scripts?

Scheduled Pinned Locked Moved Solved General
27 Posts 5 Posters 5.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    commandblock2
    wrote on last edited by commandblock2
    #9

    @idk-my-name
    Indeed something like that.

    val eventClass = method.parameterTypes[0] as Class<out Event>
    val eventTarget = method.getAnnotation(EventTarget::class.java)
    

    Unfortunately, nashorn/reflection does not have any capability of adding annotations.
    method.getAnnotation(EventTarget::class.java)
    and we will have to make our own registerListener().

    The 3 lines actually does the work is here.

    val invokableEventTargets = registry.getOrDefault(eventClass, ArrayList())
    invokableEventTargets.add(EventHook(listener, method, eventTarget))
    registry[eventClass] = invokableEventTargets
    

    You only need to convert this 3 line to js and it would be fine.
    Note the second line
    EventHook(listener, method, eventTarget)
    the listener is just the listener,
    the method is accept acquired using reflection
    but for the eventTarget, I borrowed it with reflection from a function in other class that extends Listener already presented in LB.

    As for the performance issue, it's true, in my case, putting a print every time it is called makes the frame rate goes from 80(limited) to less than 1.

    I 1 Reply Last reply
    3
    • C commandblock2

      @idk-my-name
      Indeed something like that.

      val eventClass = method.parameterTypes[0] as Class<out Event>
      val eventTarget = method.getAnnotation(EventTarget::class.java)
      

      Unfortunately, nashorn/reflection does not have any capability of adding annotations.
      method.getAnnotation(EventTarget::class.java)
      and we will have to make our own registerListener().

      The 3 lines actually does the work is here.

      val invokableEventTargets = registry.getOrDefault(eventClass, ArrayList())
      invokableEventTargets.add(EventHook(listener, method, eventTarget))
      registry[eventClass] = invokableEventTargets
      

      You only need to convert this 3 line to js and it would be fine.
      Note the second line
      EventHook(listener, method, eventTarget)
      the listener is just the listener,
      the method is accept acquired using reflection
      but for the eventTarget, I borrowed it with reflection from a function in other class that extends Listener already presented in LB.

      As for the performance issue, it's true, in my case, putting a print every time it is called makes the frame rate goes from 80(limited) to less than 1.

      I Offline
      I Offline
      idk my name
      wrote on last edited by idk my name
      #10

      @commandblock2 I currently did this:

      ///api_version=2
      (script = registerScript({
          name: "BlockBBEvent",
          authors: ["xWhitey"],
          version: "1.337"
      })).import("Core.lib");
      
      module = {
          category: "Core",
          onLoad: function() {
              registerListener(Java.extend((Java.type('net.ccbluex.liquidbounce.event.Listenable')), (Java.type('java.util.function.Consumer')), {
                  handleEvents: function() { return true },
                  accept: function(e) {
                      e instanceof BlockBBEvent && print("Hello from BlockBBEvent!")
                  }
              }))
          }
      }
      
      function registerListener(listener) {
          for each(method in listener.class.getDeclaredMethods()) {
              if (method.getParameterTypes().length == 1) {
                  if (!method.isAccessible())
                      method.setAccessible(true);
      			
                  var eventClass = method.getParameterTypes()[0];
      
                  var adaptedEventManager = new Reflector(LiquidBounce.INSTANCE.eventManager);
      
                  var invokableEventTargets = adaptedEventManager.registry.getOrDefault(eventClass, new ArrayList());
                  var onTickMethod = (Java.type('net.ccbluex.liquidbounce.utils.RotationUtils')).class.getDeclaredMethod("onTick", TickEvent.class);
                  var annotations = onTickMethod.getDeclaredAnnotations();
                  var annotation = null;
                  for each(a in annotations) {
                      annotation = a;
                  }
                  invokableEventTargets.add(new EventHook(listener, method, annotation));
                  adaptedEventManager.registry.put(eventClass, invokableEventTargets);
              }
          }
      }
      
      var TickEvent = Java.type('net.ccbluex.liquidbounce.event.TickEvent'), BlockBBEvent = Java.type('net.ccbluex.liquidbounce.event.BlockBBEvent'), EventHook = Java.type('net.ccbluex.liquidbounce.event.EventHook'), ArrayList = Java.type('java.util.ArrayList');
      

      but it throws an error:

      [23:01:10] [Client thread/ERROR] [LiquidBounce]: [ScriptAPI] Exception in script 'BlockBBEvent'!
      java.lang.ClassCastException: Cannot cast jdk.internal.dynalink.beans.StaticClass to net.ccbluex.liquidbounce.event.Listenable
      	at java.lang.invoke.MethodHandleImpl.newClassCastException(Unknown Source) ~[?:1.8.0_144]
      	at java.lang.invoke.MethodHandleImpl.castReference(Unknown Source) ~[?:1.8.0_144]
      	at jdk.nashorn.internal.scripts.Script$Recompilation$6736$598A$\^eval\_.registerListener(<eval>:37) ~[?:?]
      	at jdk.nashorn.internal.scripts.Script$Recompilation$6733$207$\^eval\_.onLoad(<eval>:11) ~[?:?]
      	at jdk.nashorn.internal.scripts.Script$Recompilation$6546$\^eval\_.L:611#L:629(<eval>:631) ~[?:?]
      	at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:628) ~[ScriptFunctionData.class:?]
      	at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494) ~[ScriptFunction.class:?]
      	at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) ~[ScriptRuntime.class:?]
      	at jdk.nashorn.api.scripting.ScriptObjectMirror.call(ScriptObjectMirror.java:117) ~[ScriptObjectMirror.class:?]
      	at net.ccbluex.liquidbounce.script.Script.callEvent(Script.kt:203) [Script.class:?]
      	at net.ccbluex.liquidbounce.script.Script.onEnable(Script.kt:171) [Script.class:?]
      	at net.ccbluex.liquidbounce.script.ScriptManager.enableScripts(ScriptManager.kt:53) [ScriptManager.class:?]
      	at net.ccbluex.liquidbounce.LiquidBounce.startClient(LiquidBounce.kt:130) [LiquidBounce.class:?]
      	at net.minecraft.client.Minecraft.handler$zze000$startGame(Minecraft.java:3428) [bib.class:?]
      	at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:536) [bib.class:?]
      	at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:378) [bib.class:?]
      	at net.minecraft.client.main.Main.main(SourceFile:123) [Main.class:?]
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_144]
      	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144]
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144]
      	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_144]
      	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [game.jar:?]
      	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [game.jar:?]
      
      ? C 2 Replies Last reply
      0
      • I idk my name

        @commandblock2 I currently did this:

        ///api_version=2
        (script = registerScript({
            name: "BlockBBEvent",
            authors: ["xWhitey"],
            version: "1.337"
        })).import("Core.lib");
        
        module = {
            category: "Core",
            onLoad: function() {
                registerListener(Java.extend((Java.type('net.ccbluex.liquidbounce.event.Listenable')), (Java.type('java.util.function.Consumer')), {
                    handleEvents: function() { return true },
                    accept: function(e) {
                        e instanceof BlockBBEvent && print("Hello from BlockBBEvent!")
                    }
                }))
            }
        }
        
        function registerListener(listener) {
            for each(method in listener.class.getDeclaredMethods()) {
                if (method.getParameterTypes().length == 1) {
                    if (!method.isAccessible())
                        method.setAccessible(true);
        			
                    var eventClass = method.getParameterTypes()[0];
        
                    var adaptedEventManager = new Reflector(LiquidBounce.INSTANCE.eventManager);
        
                    var invokableEventTargets = adaptedEventManager.registry.getOrDefault(eventClass, new ArrayList());
                    var onTickMethod = (Java.type('net.ccbluex.liquidbounce.utils.RotationUtils')).class.getDeclaredMethod("onTick", TickEvent.class);
                    var annotations = onTickMethod.getDeclaredAnnotations();
                    var annotation = null;
                    for each(a in annotations) {
                        annotation = a;
                    }
                    invokableEventTargets.add(new EventHook(listener, method, annotation));
                    adaptedEventManager.registry.put(eventClass, invokableEventTargets);
                }
            }
        }
        
        var TickEvent = Java.type('net.ccbluex.liquidbounce.event.TickEvent'), BlockBBEvent = Java.type('net.ccbluex.liquidbounce.event.BlockBBEvent'), EventHook = Java.type('net.ccbluex.liquidbounce.event.EventHook'), ArrayList = Java.type('java.util.ArrayList');
        

        but it throws an error:

        [23:01:10] [Client thread/ERROR] [LiquidBounce]: [ScriptAPI] Exception in script 'BlockBBEvent'!
        java.lang.ClassCastException: Cannot cast jdk.internal.dynalink.beans.StaticClass to net.ccbluex.liquidbounce.event.Listenable
        	at java.lang.invoke.MethodHandleImpl.newClassCastException(Unknown Source) ~[?:1.8.0_144]
        	at java.lang.invoke.MethodHandleImpl.castReference(Unknown Source) ~[?:1.8.0_144]
        	at jdk.nashorn.internal.scripts.Script$Recompilation$6736$598A$\^eval\_.registerListener(<eval>:37) ~[?:?]
        	at jdk.nashorn.internal.scripts.Script$Recompilation$6733$207$\^eval\_.onLoad(<eval>:11) ~[?:?]
        	at jdk.nashorn.internal.scripts.Script$Recompilation$6546$\^eval\_.L:611#L:629(<eval>:631) ~[?:?]
        	at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:628) ~[ScriptFunctionData.class:?]
        	at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494) ~[ScriptFunction.class:?]
        	at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) ~[ScriptRuntime.class:?]
        	at jdk.nashorn.api.scripting.ScriptObjectMirror.call(ScriptObjectMirror.java:117) ~[ScriptObjectMirror.class:?]
        	at net.ccbluex.liquidbounce.script.Script.callEvent(Script.kt:203) [Script.class:?]
        	at net.ccbluex.liquidbounce.script.Script.onEnable(Script.kt:171) [Script.class:?]
        	at net.ccbluex.liquidbounce.script.ScriptManager.enableScripts(ScriptManager.kt:53) [ScriptManager.class:?]
        	at net.ccbluex.liquidbounce.LiquidBounce.startClient(LiquidBounce.kt:130) [LiquidBounce.class:?]
        	at net.minecraft.client.Minecraft.handler$zze000$startGame(Minecraft.java:3428) [bib.class:?]
        	at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:536) [bib.class:?]
        	at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:378) [bib.class:?]
        	at net.minecraft.client.main.Main.main(SourceFile:123) [Main.class:?]
        	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_144]
        	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144]
        	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144]
        	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_144]
        	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [game.jar:?]
        	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [game.jar:?]
        
        ? Offline
        ? Offline
        A Former User
        wrote on last edited by A Former User
        #11

        @idk-my-name said in BlockBBEvent in scripts?:

        authors: ["xWhitey"],

        I 1 Reply Last reply
        0
        • ? A Former User

          @idk-my-name said in BlockBBEvent in scripts?:

          authors: ["xWhitey"],

          I Offline
          I Offline
          idk my name
          wrote on last edited by
          #12

          @fartcheese and? who asked?

          ? 1 Reply Last reply
          0
          • I idk my name

            @fartcheese and? who asked?

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #13

            @idk-my-name who did

            I 1 Reply Last reply
            0
            • ? A Former User

              @idk-my-name who did

              I Offline
              I Offline
              idk my name
              wrote on last edited by
              #14

              @fartcheese wdym

              ? 1 Reply Last reply
              0
              • I idk my name

                @fartcheese wdym

                ? Offline
                ? Offline
                A Former User
                wrote on last edited by A Former User
                #15

                @idk-my-name WHO asked

                the guy named WHO asked

                I 1 Reply Last reply
                0
                • ? A Former User

                  @idk-my-name WHO asked

                  the guy named WHO asked

                  I Offline
                  I Offline
                  idk my name
                  wrote on last edited by
                  #16

                  @fartcheese lmao

                  ? 1 Reply Last reply
                  0
                  • I idk my name

                    @fartcheese lmao

                    ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #17

                    @idk-my-name 💀💀💀💀

                    1 Reply Last reply
                    0
                    • I idk my name

                      @commandblock2 I currently did this:

                      ///api_version=2
                      (script = registerScript({
                          name: "BlockBBEvent",
                          authors: ["xWhitey"],
                          version: "1.337"
                      })).import("Core.lib");
                      
                      module = {
                          category: "Core",
                          onLoad: function() {
                              registerListener(Java.extend((Java.type('net.ccbluex.liquidbounce.event.Listenable')), (Java.type('java.util.function.Consumer')), {
                                  handleEvents: function() { return true },
                                  accept: function(e) {
                                      e instanceof BlockBBEvent && print("Hello from BlockBBEvent!")
                                  }
                              }))
                          }
                      }
                      
                      function registerListener(listener) {
                          for each(method in listener.class.getDeclaredMethods()) {
                              if (method.getParameterTypes().length == 1) {
                                  if (!method.isAccessible())
                                      method.setAccessible(true);
                      			
                                  var eventClass = method.getParameterTypes()[0];
                      
                                  var adaptedEventManager = new Reflector(LiquidBounce.INSTANCE.eventManager);
                      
                                  var invokableEventTargets = adaptedEventManager.registry.getOrDefault(eventClass, new ArrayList());
                                  var onTickMethod = (Java.type('net.ccbluex.liquidbounce.utils.RotationUtils')).class.getDeclaredMethod("onTick", TickEvent.class);
                                  var annotations = onTickMethod.getDeclaredAnnotations();
                                  var annotation = null;
                                  for each(a in annotations) {
                                      annotation = a;
                                  }
                                  invokableEventTargets.add(new EventHook(listener, method, annotation));
                                  adaptedEventManager.registry.put(eventClass, invokableEventTargets);
                              }
                          }
                      }
                      
                      var TickEvent = Java.type('net.ccbluex.liquidbounce.event.TickEvent'), BlockBBEvent = Java.type('net.ccbluex.liquidbounce.event.BlockBBEvent'), EventHook = Java.type('net.ccbluex.liquidbounce.event.EventHook'), ArrayList = Java.type('java.util.ArrayList');
                      

                      but it throws an error:

                      [23:01:10] [Client thread/ERROR] [LiquidBounce]: [ScriptAPI] Exception in script 'BlockBBEvent'!
                      java.lang.ClassCastException: Cannot cast jdk.internal.dynalink.beans.StaticClass to net.ccbluex.liquidbounce.event.Listenable
                      	at java.lang.invoke.MethodHandleImpl.newClassCastException(Unknown Source) ~[?:1.8.0_144]
                      	at java.lang.invoke.MethodHandleImpl.castReference(Unknown Source) ~[?:1.8.0_144]
                      	at jdk.nashorn.internal.scripts.Script$Recompilation$6736$598A$\^eval\_.registerListener(<eval>:37) ~[?:?]
                      	at jdk.nashorn.internal.scripts.Script$Recompilation$6733$207$\^eval\_.onLoad(<eval>:11) ~[?:?]
                      	at jdk.nashorn.internal.scripts.Script$Recompilation$6546$\^eval\_.L:611#L:629(<eval>:631) ~[?:?]
                      	at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:628) ~[ScriptFunctionData.class:?]
                      	at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494) ~[ScriptFunction.class:?]
                      	at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) ~[ScriptRuntime.class:?]
                      	at jdk.nashorn.api.scripting.ScriptObjectMirror.call(ScriptObjectMirror.java:117) ~[ScriptObjectMirror.class:?]
                      	at net.ccbluex.liquidbounce.script.Script.callEvent(Script.kt:203) [Script.class:?]
                      	at net.ccbluex.liquidbounce.script.Script.onEnable(Script.kt:171) [Script.class:?]
                      	at net.ccbluex.liquidbounce.script.ScriptManager.enableScripts(ScriptManager.kt:53) [ScriptManager.class:?]
                      	at net.ccbluex.liquidbounce.LiquidBounce.startClient(LiquidBounce.kt:130) [LiquidBounce.class:?]
                      	at net.minecraft.client.Minecraft.handler$zze000$startGame(Minecraft.java:3428) [bib.class:?]
                      	at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:536) [bib.class:?]
                      	at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:378) [bib.class:?]
                      	at net.minecraft.client.main.Main.main(SourceFile:123) [Main.class:?]
                      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_144]
                      	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144]
                      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144]
                      	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_144]
                      	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [game.jar:?]
                      	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [game.jar:?]
                      
                      C Offline
                      C Offline
                      commandblock2
                      wrote on last edited by commandblock2
                      #18

                      @idk-my-name
                      What Java.extend() returns is something that behaves like a type (Forgot what it really is, probably a JSAdaptor or something).
                      Similar to what you will get from using Java.type().

                      ArrayList = Java.type("java.util.ArrayList")
                      arrayList = new ArrayList()
                      
                      BBConsumer = Java.extend(Listenable, Consumer, {
                          handleEvents: function() { return true},
                          accept: function(e) {
                              // onBlockBB here
                              
                          }
                      })
                      
                      consumer = new BBConsumer()
                      registerListener(consumer)
                      // not registerListener(BBConsumer)
                      /* I am sure there would be a better name for BBConsumer
                      And if you want to use it like a anonymous class in Java you could just read the BlockAnimations.js or better,  nashorn document
                      https://github.com/CzechHek/Core/blob/879f36d7e41ccc7868285b0a808866b360f30822/Scripts/BlockAnimations.js#L35
                      */  
                      

                      Not sure if the type from Java.extend would have other unexpected methods that only takes 1 parameters, you might want to check if the parameter's super class is Event.

                      Or you could just explicitly specify the accept method in it.
                      method = consumer.class.getMethod("accept", java.lang.Object.class)

                      Edit:
                      Nvm, I forgot that this was scriptAPI, the Consumer here is a Consumer<?>, not Consumer<BlockBBEvent> which means the accepct() takes an java.lang.Object, and it will register a Listener that listens to any event that is an java.lang.Object, which probably means all events.'

                      Here is what I did

                      registry = getField(LiquidBounce.eventManager, "registry").get(LiquidBounce.eventManager)
                      BBs = registry.getOrDefault(BlockBBEvent.class, new ArrayList())
                      BBs.add(new EventHook(consumer, 
                              consumer.class.getMethod("accept", java.lang.Object.class), 
                              LiquidBounce.moduleManager.class
                                      .getDeclaredMethod("onKey", KeyEvent.class)
                                      .getAnnotation(EventTarget.class)))
                      registry[BlockBBEvent.class] = BBs
                      
                      I 1 Reply Last reply
                      4
                      • C commandblock2

                        @idk-my-name
                        What Java.extend() returns is something that behaves like a type (Forgot what it really is, probably a JSAdaptor or something).
                        Similar to what you will get from using Java.type().

                        ArrayList = Java.type("java.util.ArrayList")
                        arrayList = new ArrayList()
                        
                        BBConsumer = Java.extend(Listenable, Consumer, {
                            handleEvents: function() { return true},
                            accept: function(e) {
                                // onBlockBB here
                                
                            }
                        })
                        
                        consumer = new BBConsumer()
                        registerListener(consumer)
                        // not registerListener(BBConsumer)
                        /* I am sure there would be a better name for BBConsumer
                        And if you want to use it like a anonymous class in Java you could just read the BlockAnimations.js or better,  nashorn document
                        https://github.com/CzechHek/Core/blob/879f36d7e41ccc7868285b0a808866b360f30822/Scripts/BlockAnimations.js#L35
                        */  
                        

                        Not sure if the type from Java.extend would have other unexpected methods that only takes 1 parameters, you might want to check if the parameter's super class is Event.

                        Or you could just explicitly specify the accept method in it.
                        method = consumer.class.getMethod("accept", java.lang.Object.class)

                        Edit:
                        Nvm, I forgot that this was scriptAPI, the Consumer here is a Consumer<?>, not Consumer<BlockBBEvent> which means the accepct() takes an java.lang.Object, and it will register a Listener that listens to any event that is an java.lang.Object, which probably means all events.'

                        Here is what I did

                        registry = getField(LiquidBounce.eventManager, "registry").get(LiquidBounce.eventManager)
                        BBs = registry.getOrDefault(BlockBBEvent.class, new ArrayList())
                        BBs.add(new EventHook(consumer, 
                                consumer.class.getMethod("accept", java.lang.Object.class), 
                                LiquidBounce.moduleManager.class
                                        .getDeclaredMethod("onKey", KeyEvent.class)
                                        .getAnnotation(EventTarget.class)))
                        registry[BlockBBEvent.class] = BBs
                        
                        I Offline
                        I Offline
                        idk my name
                        wrote on last edited by
                        #19

                        @commandblock2 Thank you

                        CzechHekC 1 Reply Last reply
                        0
                        • I idk my name has marked this topic as solved on
                        • I idk my name

                          @commandblock2 Thank you

                          CzechHekC Offline
                          CzechHekC Offline
                          CzechHek
                          wrote on last edited by CzechHek
                          #20

                          @idk-my-name

                          This is what I came up with without seeing @commandblock2's solution.
                          I had to reverse engineer a bunch of stuff and then put all together and it worked.

                          I was wondering what the hell was annotation in Nashorn and it turns out that

                          print(annotation.class)

                          literally returns
                          d828c6df-270d-452a-8db2-b751195f7d54-image.png

                          I'll try to simplify it and automize it via Core.

                          ///api_version=2
                          (script = registerScript({
                              name: "Test",
                              authors: ["CzechHek"],
                              version: "1.0"
                          })).import("Core.lib");
                          
                          module = {
                              onClickGuiLoaded: function () {
                                  listener = new (Java.extend(Listenable, Consumer, { 
                                      handleEvents: function() { return TestModule.state }, 
                                      accept: function(e) { 
                                          print(e)
                                      }
                                  }));
                          
                                  method = getMethod(listener, "accept");
                                  annotation = getMethod(TestModule, "onUpdate").getDeclaredAnnotations()[0];
                                  
                                  AeventManager = new Reflector(LiquidBounce.eventManager)
                                  invocableEventTargets = AeventManager.registry.getOrDefault(BlockBBEvent.class, new ArrayList());
                                  invocableEventTargets.add(new EventHook(listener, method, annotation));
                                  AeventManager.registry[BlockBBEvent.class] = invocableEventTargets;
                              }
                          }
                          
                          Listenable = Java.type("net.ccbluex.liquidbounce.event.Listenable");
                          Consumer = Java.type("java.util.function.Consumer");
                          BlockBBEvent = Java.type("net.ccbluex.liquidbounce.event.BlockBBEvent");
                          EventHook = Java.type("net.ccbluex.liquidbounce.event.EventHook");
                          ArrayList = Java.type("java.util.ArrayList")
                          
                          I 1 Reply Last reply
                          0
                          • CzechHekC CzechHek

                            @idk-my-name

                            This is what I came up with without seeing @commandblock2's solution.
                            I had to reverse engineer a bunch of stuff and then put all together and it worked.

                            I was wondering what the hell was annotation in Nashorn and it turns out that

                            print(annotation.class)

                            literally returns
                            d828c6df-270d-452a-8db2-b751195f7d54-image.png

                            I'll try to simplify it and automize it via Core.

                            ///api_version=2
                            (script = registerScript({
                                name: "Test",
                                authors: ["CzechHek"],
                                version: "1.0"
                            })).import("Core.lib");
                            
                            module = {
                                onClickGuiLoaded: function () {
                                    listener = new (Java.extend(Listenable, Consumer, { 
                                        handleEvents: function() { return TestModule.state }, 
                                        accept: function(e) { 
                                            print(e)
                                        }
                                    }));
                            
                                    method = getMethod(listener, "accept");
                                    annotation = getMethod(TestModule, "onUpdate").getDeclaredAnnotations()[0];
                                    
                                    AeventManager = new Reflector(LiquidBounce.eventManager)
                                    invocableEventTargets = AeventManager.registry.getOrDefault(BlockBBEvent.class, new ArrayList());
                                    invocableEventTargets.add(new EventHook(listener, method, annotation));
                                    AeventManager.registry[BlockBBEvent.class] = invocableEventTargets;
                                }
                            }
                            
                            Listenable = Java.type("net.ccbluex.liquidbounce.event.Listenable");
                            Consumer = Java.type("java.util.function.Consumer");
                            BlockBBEvent = Java.type("net.ccbluex.liquidbounce.event.BlockBBEvent");
                            EventHook = Java.type("net.ccbluex.liquidbounce.event.EventHook");
                            ArrayList = Java.type("java.util.ArrayList")
                            
                            I Offline
                            I Offline
                            idk my name
                            wrote on last edited by idk my name
                            #21

                            @czechhek my problem was too stupid: i forgot to create new instance of my listener (and i had some shitcode in listener prob)

                            ? CzechHekC 2 Replies Last reply
                            0
                            • I idk my name

                              @czechhek my problem was too stupid: i forgot to create new instance of my listener (and i had some shitcode in listener prob)

                              ? Offline
                              ? Offline
                              A Former User
                              wrote on last edited by
                              #22

                              @idk-my-name you forgor 💀

                              I 1 Reply Last reply
                              0
                              • ? A Former User

                                @idk-my-name you forgor 💀

                                I Offline
                                I Offline
                                idk my name
                                wrote on last edited by
                                #23

                                @fartcheese i forgor 💀

                                ? 1 Reply Last reply
                                0
                                • I idk my name

                                  @fartcheese i forgor 💀

                                  ? Offline
                                  ? Offline
                                  A Former User
                                  wrote on last edited by
                                  #24

                                  @idk-my-name we forgor 💀

                                  I 1 Reply Last reply
                                  0
                                  • ? A Former User

                                    @idk-my-name we forgor 💀

                                    I Offline
                                    I Offline
                                    idk my name
                                    wrote on last edited by
                                    #25

                                    @fartcheese Wait... I rember😀

                                    ? 1 Reply Last reply
                                    0
                                    • I idk my name

                                      @fartcheese Wait... I rember😀

                                      ? Offline
                                      ? Offline
                                      A Former User
                                      wrote on last edited by
                                      #26

                                      @idk-my-name same

                                      i rember 😳😳😳

                                      1 Reply Last reply
                                      0
                                      • I idk my name

                                        @czechhek my problem was too stupid: i forgot to create new instance of my listener (and i had some shitcode in listener prob)

                                        CzechHekC Offline
                                        CzechHekC Offline
                                        CzechHek
                                        wrote on last edited by CzechHek
                                        #27

                                        @czechhek said in BlockBBEvent in scripts?:

                                        I'll try to simplify it and automize it via Core.

                                        @idk-my-name https://forums.ccbluex.net/topic/94/script-base-core-3-28-simple-yet-powerful-scriptapi-base/30 and here it is

                                        You can use all events if you import Core base, no need to do any of this stuff.
                                        For more info, look at my comment on Core post.

                                        1 Reply Last reply
                                        0
                                        Reply
                                        • Reply as topic
                                        Log in to reply
                                        • Oldest to Newest
                                        • Newest to Oldest
                                        • Most Votes


                                        About
                                        • Terms of Service
                                        • Privacy Policy
                                        • Status
                                        • Contact Us
                                        Downloads
                                        • Releases
                                        • Source code
                                        • License
                                        Docs
                                        • Tutorials
                                        • CustomHUD
                                        • AutoSettings
                                        • ScriptAPI
                                        Community
                                        • Forum
                                        • Guilded
                                        • YouTube
                                        • Twitter
                                        • D.Tube
                                        • Login

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Users
                                        • Groups