{"id":19009815,"url":"https://github.com/0tii/s0nar","last_synced_at":"2025-10-11T23:36:29.643Z","repository":{"id":109849044,"uuid":"376545339","full_name":"0tii/s0nar","owner":"0tii","description":"📡 Lightweight but powerful event system to create and process source code hooks","archived":false,"fork":false,"pushed_at":"2021-10-20T11:49:59.000Z","size":42,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-10-11T23:36:28.285Z","etag":null,"topics":["event","java","priority","system"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0tii.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-06-13T13:02:16.000Z","updated_at":"2022-05-23T07:46:15.000Z","dependencies_parsed_at":"2023-06-12T05:15:43.558Z","dependency_job_id":null,"html_url":"https://github.com/0tii/s0nar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/0tii/s0nar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0tii%2Fs0nar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0tii%2Fs0nar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0tii%2Fs0nar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0tii%2Fs0nar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0tii","download_url":"https://codeload.github.com/0tii/s0nar/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0tii%2Fs0nar/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279009393,"owners_count":26084580,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["event","java","priority","system"],"created_at":"2024-11-08T19:08:59.442Z","updated_at":"2025-10-11T23:36:29.638Z","avatar_url":"https://github.com/0tii.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# 📡 S0nar Event System \n![](https://i.imgur.com/FcMKY9H.png)\n\n\u003csup\u003e\u003csub\u003eXc0n Client is discontinued due to market oversaturation\u003c/sub\u003e\u003c/sup\u003e\n\n*\"A whale can speak to another whale across sixty miles of ocean\"* ... how does he do it? 🐳\n\nLightweight event system, shipped as individual open-source project for aspiring client-developers to use.\n\nS0nar can be used as a base event system in any environment where event-injection is of use or a necessity.\n\n\n## How to use\nAdd the package hierarchy to your project and instantiate a single instance of EventBus, preferably in your main Mod class (if developing a Minecraft mod).\n\n```java\npublic static final EventBus EVENT_BUS = new EventBus();\n```\n or if you do not plan on using priority staging\n ```java\npublic static final EventBus EVENT_BUS = new EventBus(false);\n```\n\n### Creating Events\nIts as simple as extending ``Event`` for single-state events or ``CancelableEvent`` for dual-state events. If more intrinsic event types are needed, extending either of both base classes shipped with *s0nar* will be valid.\n\n**Example event:**\n```java\npublic class ExampleEvent extends CancelableEvent \n{\n\tprivate String value;\n\t\n\tpublic ExampleEvent(String val)\n\t{\n\t\tvalue = val;\n\t}\n\t\n\tpublic String getValue() { return value; }\n}\n```\n### Posting Events\nIn order to post events from inside a source block, inject a call to `EventBus#post(Event event)` using whatever method you are most comfortable with. In a Minecraft context, Mixins have gained increasing popularity, however ASM is a valid option, too. Of course with the appearance of MCP Reborn you might want to choose just to edit source directly (which you should not lol).\n\nExample 1:\n```java\n//In this case GenericEvent extends Event, Main is where you instantiated the event bus\nMain.EVENT_BUS.post(new GenericEvent());\n```\nExample 2:\n```java\n//WalkEvent extends CancelableEvent and if setCanceled(true) anywhere in the event raise chain, the resulting event instance will cause a return.\nWalkEvent event = (WalkEvent) Main.EVENT_BUS.post(new WalkEvent());\nif(event.isCanceled())\n{\n\treturn; \n}\n```\n### Registering Event Listeners\nIn order to register event listeners, simply annotate subscriber methods with the `S0narEventListener` @ interface and register the instance of the owner class to the `EventBus`. If you wish to use priority staging, you can optionally supply the @ interface with a `priority` parameter, which takes a value from `EventPriority` enum. Do not forget to unregister your subscriber object from the `EventBus` at destruction.\n\n**Note: Your event listener methods may not have more than one parameter, that being the event.** They should never need additional parameters anyways. Additional data should be parsed through event class attributes.\n\nExample:\n\n```java\npublic class Subscriber\n{\n\t//example call to register the subscriber object to the event bus\t\n\tpublic void enable()\n\t{\n\t\tMain.EVENT_BUS.register(this);\n\t}\n\t//example call to unregister the subscriber object from the event bus\n\tpublic void disable()\n\t{\n\t\tMain.EVENT_BUS.unregister(this);\n\t}\n\t\n\t@S0narEventListener(priority = EventPriority.HIGH)\n\tpublic void onWalkEvent(WalkEvent event)\n\t{\n\t\tif(/*condition*/)\n\t\t{\n\t\t\tevent.setCanceled(true);\n\t\t}\n\t}\n}\n```\n## Event Staging\nS0nar gives you full flexibility over the execution order of your event listeners. Using the `priority` argument of the `S0narEventListener` annotation, you can specify the execution priority preference. Listeners assigned a higher priority will be executed first. Listeners within the same priority segment will be executed in order of registration. *Order of same-priority listeners is not guaranteed.*\n\n**If no priority argument is specified on decorated methods, the default fallback is `EventPriority.LOW`.**\n\nThe `EventPriority` enum that is used to represent the `priority` value has 4 pre-configured priority-segments\n```\nTOP\nHIGH\nMEDIUM\nLOW\n```\nbut can easily be expanded at will, as internally only the index values are used to determine execution order. \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0tii%2Fs0nar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0tii%2Fs0nar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0tii%2Fs0nar/lists"}