You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 20, 2020. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+4-7Lines changed: 4 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -164,20 +164,17 @@ the former Overcast Network.
164
164
* We use Guice everywhere. You will need to [understand it thoroughly](https://github.com/google/guice/wiki/Motivation).
165
165
* Follow the Guice [best practices](https://github.com/google/guice/wiki/InjectOnlyDirectDependencies) (especially that one).
166
166
* We sometimes use the term "manifest" in place of "module", to avoid confusion with PGM modules.
167
-
* Using Guice in a Bukkit plugin environment has proven to be [somewhat complex](https://github.com/OvercastNetwork/Plugins/blob/master/Util/core/src/main/java/tc/oc/commons/core/plugin/InjectedPluginLoader.java).
168
-
You don't have to understand all of that, but there are a few things you should know:
169
-
* Each plugin has its own [private module](https://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/PrivateModule.html)
167
+
* We make good use of SportBukkit's built-in Guice support:
168
+
* Each plugin has its own [private environment](https://github.com/OvercastNetwork/minecraft-api/blob/master/src/main/java/tc/oc/inject/ProtectedModule.java)
170
169
in which most of its bindings live.
171
170
* Each plugin instance is bound to `org.bukkit.plugin.Plugin` inside its private module.
172
171
* Anything that indirectly depends on `Plugin` will need to be bound in some plugin's private module.
173
172
* If other plugins need access to that thing, it needs to be [exposed](https://google.github.io/guice/api-docs/latest/javadoc/com/google/inject/PrivateModule.html#expose-com.google.inject.Key-).
174
173
* Avoid depending on `Plugin` directly. There are specific bindings for most Bukkit service types (e.g. `Configuration`)
175
174
and several interfaces of our own that wrap small parts of the Bukkit API (e.g. `BukkitEventBus`).
176
175
* If you really need a `Plugin`, always inject the base interface, never a specific plugin's class. This makes it easy to move things between plugins.
177
-
* If the same `@Singleton` type is provisioned in multiple plugins, we will detect it and throw an exception.
178
-
If you actually want a per-plugin singleton, make it `@PluginScoped`.
179
-
*`PluginFacet`s are service objects registered with a specific plugin to share its lifecycle callbacks (i.e. enable() and disable()).
180
-
They are also registered automatically in the appropriate way if they implement various interfaces such as `Listener` (see the javadocs for details).
176
+
* A `@Singleton` bound in a private environment (e.g. a plugin's private environment) will only be unique within that environment,
177
+
not the entire process, so be careful not to accidentally duplicate a singleton in multiple private environments.
181
178
* Exceptions
182
179
* Detect errors as early as possible, ideally at server startup. This applies to both user errors and internal assertions.
183
180
* Only catch specific exceptions that you are expecting and can handle thoroughly. Don't hide exceptions that other handlers need to know about.
0 commit comments